send.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
  2. *
  3. * Marek Lindner, Simon Wunderlich
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA
  18. */
  19. #include "main.h"
  20. #include "distributed-arp-table.h"
  21. #include "send.h"
  22. #include "routing.h"
  23. #include "translation-table.h"
  24. #include "soft-interface.h"
  25. #include "hard-interface.h"
  26. #include "gateway_common.h"
  27. #include "gateway_client.h"
  28. #include "originator.h"
  29. #include "network-coding.h"
  30. #include "fragmentation.h"
  31. static void batadv_send_outstanding_bcast_packet(struct work_struct *work);
  32. /* send out an already prepared packet to the given address via the
  33. * specified batman interface
  34. */
  35. int batadv_send_skb_packet(struct sk_buff *skb,
  36. struct batadv_hard_iface *hard_iface,
  37. const uint8_t *dst_addr)
  38. {
  39. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  40. struct ethhdr *ethhdr;
  41. if (hard_iface->if_status != BATADV_IF_ACTIVE)
  42. goto send_skb_err;
  43. if (unlikely(!hard_iface->net_dev))
  44. goto send_skb_err;
  45. if (!(hard_iface->net_dev->flags & IFF_UP)) {
  46. pr_warn("Interface %s is not up - can't send packet via that interface!\n",
  47. hard_iface->net_dev->name);
  48. goto send_skb_err;
  49. }
  50. /* push to the ethernet header. */
  51. if (batadv_skb_head_push(skb, ETH_HLEN) < 0)
  52. goto send_skb_err;
  53. skb_reset_mac_header(skb);
  54. ethhdr = eth_hdr(skb);
  55. memcpy(ethhdr->h_source, hard_iface->net_dev->dev_addr, ETH_ALEN);
  56. memcpy(ethhdr->h_dest, dst_addr, ETH_ALEN);
  57. ethhdr->h_proto = htons(ETH_P_BATMAN);
  58. skb_set_network_header(skb, ETH_HLEN);
  59. skb->protocol = htons(ETH_P_BATMAN);
  60. skb->dev = hard_iface->net_dev;
  61. /* Save a clone of the skb to use when decoding coded packets */
  62. batadv_nc_skb_store_for_decoding(bat_priv, skb);
  63. /* dev_queue_xmit() returns a negative result on error. However on
  64. * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
  65. * (which is > 0). This will not be treated as an error.
  66. */
  67. return dev_queue_xmit(skb);
  68. send_skb_err:
  69. kfree_skb(skb);
  70. return NET_XMIT_DROP;
  71. }
  72. /**
  73. * batadv_send_skb_to_orig - Lookup next-hop and transmit skb.
  74. * @skb: Packet to be transmitted.
  75. * @orig_node: Final destination of the packet.
  76. * @recv_if: Interface used when receiving the packet (can be NULL).
  77. *
  78. * Looks up the best next-hop towards the passed originator and passes the
  79. * skb on for preparation of MAC header. If the packet originated from this
  80. * host, NULL can be passed as recv_if and no interface alternating is
  81. * attempted.
  82. *
  83. * Returns NET_XMIT_SUCCESS on success, NET_XMIT_DROP on failure, or
  84. * NET_XMIT_POLICED if the skb is buffered for later transmit.
  85. */
  86. int batadv_send_skb_to_orig(struct sk_buff *skb,
  87. struct batadv_orig_node *orig_node,
  88. struct batadv_hard_iface *recv_if)
  89. {
  90. struct batadv_priv *bat_priv = orig_node->bat_priv;
  91. struct batadv_neigh_node *neigh_node;
  92. int ret = NET_XMIT_DROP;
  93. /* batadv_find_router() increases neigh_nodes refcount if found. */
  94. neigh_node = batadv_find_router(bat_priv, orig_node, recv_if);
  95. if (!neigh_node)
  96. goto out;
  97. /* Check if the skb is too large to send in one piece and fragment
  98. * it if needed.
  99. */
  100. if (atomic_read(&bat_priv->fragmentation) &&
  101. skb->len > neigh_node->if_incoming->net_dev->mtu) {
  102. /* Fragment and send packet. */
  103. if (batadv_frag_send_packet(skb, orig_node, neigh_node))
  104. ret = NET_XMIT_SUCCESS;
  105. goto out;
  106. }
  107. /* try to network code the packet, if it is received on an interface
  108. * (i.e. being forwarded). If the packet originates from this node or if
  109. * network coding fails, then send the packet as usual.
  110. */
  111. if (recv_if && batadv_nc_skb_forward(skb, neigh_node)) {
  112. ret = NET_XMIT_POLICED;
  113. } else {
  114. batadv_send_skb_packet(skb, neigh_node->if_incoming,
  115. neigh_node->addr);
  116. ret = NET_XMIT_SUCCESS;
  117. }
  118. out:
  119. if (neigh_node)
  120. batadv_neigh_node_free_ref(neigh_node);
  121. return ret;
  122. }
  123. /**
  124. * batadv_send_skb_push_fill_unicast - extend the buffer and initialize the
  125. * common fields for unicast packets
  126. * @skb: the skb carrying the unicast header to initialize
  127. * @hdr_size: amount of bytes to push at the beginning of the skb
  128. * @orig_node: the destination node
  129. *
  130. * Returns false if the buffer extension was not possible or true otherwise.
  131. */
  132. static bool
  133. batadv_send_skb_push_fill_unicast(struct sk_buff *skb, int hdr_size,
  134. struct batadv_orig_node *orig_node)
  135. {
  136. struct batadv_unicast_packet *unicast_packet;
  137. uint8_t ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
  138. if (batadv_skb_head_push(skb, hdr_size) < 0)
  139. return false;
  140. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  141. unicast_packet->header.version = BATADV_COMPAT_VERSION;
  142. /* batman packet type: unicast */
  143. unicast_packet->header.packet_type = BATADV_UNICAST;
  144. /* set unicast ttl */
  145. unicast_packet->header.ttl = BATADV_TTL;
  146. /* copy the destination for faster routing */
  147. memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN);
  148. /* set the destination tt version number */
  149. unicast_packet->ttvn = ttvn;
  150. return true;
  151. }
  152. /**
  153. * batadv_send_skb_prepare_unicast - encapsulate an skb with a unicast header
  154. * @skb: the skb containing the payload to encapsulate
  155. * @orig_node: the destination node
  156. *
  157. * Returns false if the payload could not be encapsulated or true otherwise.
  158. */
  159. static bool batadv_send_skb_prepare_unicast(struct sk_buff *skb,
  160. struct batadv_orig_node *orig_node)
  161. {
  162. size_t uni_size = sizeof(struct batadv_unicast_packet);
  163. return batadv_send_skb_push_fill_unicast(skb, uni_size, orig_node);
  164. }
  165. /**
  166. * batadv_send_skb_prepare_unicast_4addr - encapsulate an skb with a
  167. * unicast 4addr header
  168. * @bat_priv: the bat priv with all the soft interface information
  169. * @skb: the skb containing the payload to encapsulate
  170. * @orig_node: the destination node
  171. * @packet_subtype: the unicast 4addr packet subtype to use
  172. *
  173. * Returns false if the payload could not be encapsulated or true otherwise.
  174. */
  175. bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
  176. struct sk_buff *skb,
  177. struct batadv_orig_node *orig,
  178. int packet_subtype)
  179. {
  180. struct batadv_hard_iface *primary_if;
  181. struct batadv_unicast_4addr_packet *uc_4addr_packet;
  182. bool ret = false;
  183. primary_if = batadv_primary_if_get_selected(bat_priv);
  184. if (!primary_if)
  185. goto out;
  186. /* Pull the header space and fill the unicast_packet substructure.
  187. * We can do that because the first member of the uc_4addr_packet
  188. * is of type struct unicast_packet
  189. */
  190. if (!batadv_send_skb_push_fill_unicast(skb, sizeof(*uc_4addr_packet),
  191. orig))
  192. goto out;
  193. uc_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
  194. uc_4addr_packet->u.header.packet_type = BATADV_UNICAST_4ADDR;
  195. memcpy(uc_4addr_packet->src, primary_if->net_dev->dev_addr, ETH_ALEN);
  196. uc_4addr_packet->subtype = packet_subtype;
  197. uc_4addr_packet->reserved = 0;
  198. ret = true;
  199. out:
  200. if (primary_if)
  201. batadv_hardif_free_ref(primary_if);
  202. return ret;
  203. }
  204. /**
  205. * batadv_send_skb_unicast - encapsulate and send an skb via unicast
  206. * @bat_priv: the bat priv with all the soft interface information
  207. * @skb: payload to send
  208. * @packet_type: the batman unicast packet type to use
  209. * @packet_subtype: the unicast 4addr packet subtype (only relevant for unicast
  210. * 4addr packets)
  211. * @orig_node: the originator to send the packet to
  212. * @vid: the vid to be used to search the translation table
  213. *
  214. * Wrap the given skb into a batman-adv unicast or unicast-4addr header
  215. * depending on whether BATADV_UNICAST or BATADV_UNICAST_4ADDR was supplied
  216. * as packet_type. Then send this frame to the given orig_node and release a
  217. * reference to this orig_node.
  218. *
  219. * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
  220. */
  221. static int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
  222. struct sk_buff *skb, int packet_type,
  223. int packet_subtype,
  224. struct batadv_orig_node *orig_node,
  225. unsigned short vid)
  226. {
  227. struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
  228. struct batadv_unicast_packet *unicast_packet;
  229. int ret = NET_XMIT_DROP;
  230. if (!orig_node)
  231. goto out;
  232. switch (packet_type) {
  233. case BATADV_UNICAST:
  234. if (!batadv_send_skb_prepare_unicast(skb, orig_node))
  235. goto out;
  236. break;
  237. case BATADV_UNICAST_4ADDR:
  238. if (!batadv_send_skb_prepare_unicast_4addr(bat_priv, skb,
  239. orig_node,
  240. packet_subtype))
  241. goto out;
  242. break;
  243. default:
  244. /* this function supports UNICAST and UNICAST_4ADDR only. It
  245. * should never be invoked with any other packet type
  246. */
  247. goto out;
  248. }
  249. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  250. /* inform the destination node that we are still missing a correct route
  251. * for this client. The destination will receive this packet and will
  252. * try to reroute it because the ttvn contained in the header is less
  253. * than the current one
  254. */
  255. if (batadv_tt_global_client_is_roaming(bat_priv, ethhdr->h_dest, vid))
  256. unicast_packet->ttvn = unicast_packet->ttvn - 1;
  257. if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
  258. ret = NET_XMIT_SUCCESS;
  259. out:
  260. if (orig_node)
  261. batadv_orig_node_free_ref(orig_node);
  262. if (ret == NET_XMIT_DROP)
  263. kfree_skb(skb);
  264. return ret;
  265. }
  266. /**
  267. * batadv_send_skb_via_tt_generic - send an skb via TT lookup
  268. * @bat_priv: the bat priv with all the soft interface information
  269. * @skb: payload to send
  270. * @packet_type: the batman unicast packet type to use
  271. * @packet_subtype: the unicast 4addr packet subtype (only relevant for unicast
  272. * 4addr packets)
  273. * @vid: the vid to be used to search the translation table
  274. *
  275. * Look up the recipient node for the destination address in the ethernet
  276. * header via the translation table. Wrap the given skb into a batman-adv
  277. * unicast or unicast-4addr header depending on whether BATADV_UNICAST or
  278. * BATADV_UNICAST_4ADDR was supplied as packet_type. Then send this frame
  279. * to the according destination node.
  280. *
  281. * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
  282. */
  283. int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,
  284. struct sk_buff *skb, int packet_type,
  285. int packet_subtype, unsigned short vid)
  286. {
  287. struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
  288. struct batadv_orig_node *orig_node;
  289. orig_node = batadv_transtable_search(bat_priv, ethhdr->h_source,
  290. ethhdr->h_dest, vid);
  291. return batadv_send_skb_unicast(bat_priv, skb, packet_type,
  292. packet_subtype, orig_node, vid);
  293. }
  294. /**
  295. * batadv_send_skb_via_gw - send an skb via gateway lookup
  296. * @bat_priv: the bat priv with all the soft interface information
  297. * @skb: payload to send
  298. * @vid: the vid to be used to search the translation table
  299. *
  300. * Look up the currently selected gateway. Wrap the given skb into a batman-adv
  301. * unicast header and send this frame to this gateway node.
  302. *
  303. * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
  304. */
  305. int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
  306. unsigned short vid)
  307. {
  308. struct batadv_orig_node *orig_node;
  309. orig_node = batadv_gw_get_selected_orig(bat_priv);
  310. return batadv_send_skb_unicast(bat_priv, skb, BATADV_UNICAST, 0,
  311. orig_node, vid);
  312. }
  313. void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface)
  314. {
  315. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  316. if ((hard_iface->if_status == BATADV_IF_NOT_IN_USE) ||
  317. (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED))
  318. return;
  319. /* the interface gets activated here to avoid race conditions between
  320. * the moment of activating the interface in
  321. * hardif_activate_interface() where the originator mac is set and
  322. * outdated packets (especially uninitialized mac addresses) in the
  323. * packet queue
  324. */
  325. if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED)
  326. hard_iface->if_status = BATADV_IF_ACTIVE;
  327. bat_priv->bat_algo_ops->bat_ogm_schedule(hard_iface);
  328. }
  329. static void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet)
  330. {
  331. if (forw_packet->skb)
  332. kfree_skb(forw_packet->skb);
  333. if (forw_packet->if_incoming)
  334. batadv_hardif_free_ref(forw_packet->if_incoming);
  335. kfree(forw_packet);
  336. }
  337. static void
  338. _batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
  339. struct batadv_forw_packet *forw_packet,
  340. unsigned long send_time)
  341. {
  342. /* add new packet to packet list */
  343. spin_lock_bh(&bat_priv->forw_bcast_list_lock);
  344. hlist_add_head(&forw_packet->list, &bat_priv->forw_bcast_list);
  345. spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
  346. /* start timer for this packet */
  347. queue_delayed_work(batadv_event_workqueue, &forw_packet->delayed_work,
  348. send_time);
  349. }
  350. /* add a broadcast packet to the queue and setup timers. broadcast packets
  351. * are sent multiple times to increase probability for being received.
  352. *
  353. * This function returns NETDEV_TX_OK on success and NETDEV_TX_BUSY on
  354. * errors.
  355. *
  356. * The skb is not consumed, so the caller should make sure that the
  357. * skb is freed.
  358. */
  359. int batadv_add_bcast_packet_to_list(struct batadv_priv *bat_priv,
  360. const struct sk_buff *skb,
  361. unsigned long delay)
  362. {
  363. struct batadv_hard_iface *primary_if = NULL;
  364. struct batadv_forw_packet *forw_packet;
  365. struct batadv_bcast_packet *bcast_packet;
  366. struct sk_buff *newskb;
  367. if (!batadv_atomic_dec_not_zero(&bat_priv->bcast_queue_left)) {
  368. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  369. "bcast packet queue full\n");
  370. goto out;
  371. }
  372. primary_if = batadv_primary_if_get_selected(bat_priv);
  373. if (!primary_if)
  374. goto out_and_inc;
  375. forw_packet = kmalloc(sizeof(*forw_packet), GFP_ATOMIC);
  376. if (!forw_packet)
  377. goto out_and_inc;
  378. newskb = skb_copy(skb, GFP_ATOMIC);
  379. if (!newskb)
  380. goto packet_free;
  381. /* as we have a copy now, it is safe to decrease the TTL */
  382. bcast_packet = (struct batadv_bcast_packet *)newskb->data;
  383. bcast_packet->header.ttl--;
  384. skb_reset_mac_header(newskb);
  385. forw_packet->skb = newskb;
  386. forw_packet->if_incoming = primary_if;
  387. /* how often did we send the bcast packet ? */
  388. forw_packet->num_packets = 0;
  389. INIT_DELAYED_WORK(&forw_packet->delayed_work,
  390. batadv_send_outstanding_bcast_packet);
  391. _batadv_add_bcast_packet_to_list(bat_priv, forw_packet, delay);
  392. return NETDEV_TX_OK;
  393. packet_free:
  394. kfree(forw_packet);
  395. out_and_inc:
  396. atomic_inc(&bat_priv->bcast_queue_left);
  397. out:
  398. if (primary_if)
  399. batadv_hardif_free_ref(primary_if);
  400. return NETDEV_TX_BUSY;
  401. }
  402. static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
  403. {
  404. struct batadv_hard_iface *hard_iface;
  405. struct delayed_work *delayed_work;
  406. struct batadv_forw_packet *forw_packet;
  407. struct sk_buff *skb1;
  408. struct net_device *soft_iface;
  409. struct batadv_priv *bat_priv;
  410. delayed_work = container_of(work, struct delayed_work, work);
  411. forw_packet = container_of(delayed_work, struct batadv_forw_packet,
  412. delayed_work);
  413. soft_iface = forw_packet->if_incoming->soft_iface;
  414. bat_priv = netdev_priv(soft_iface);
  415. spin_lock_bh(&bat_priv->forw_bcast_list_lock);
  416. hlist_del(&forw_packet->list);
  417. spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
  418. if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
  419. goto out;
  420. if (batadv_dat_drop_broadcast_packet(bat_priv, forw_packet))
  421. goto out;
  422. /* rebroadcast packet */
  423. rcu_read_lock();
  424. list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
  425. if (hard_iface->soft_iface != soft_iface)
  426. continue;
  427. if (forw_packet->num_packets >= hard_iface->num_bcasts)
  428. continue;
  429. /* send a copy of the saved skb */
  430. skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC);
  431. if (skb1)
  432. batadv_send_skb_packet(skb1, hard_iface,
  433. batadv_broadcast_addr);
  434. }
  435. rcu_read_unlock();
  436. forw_packet->num_packets++;
  437. /* if we still have some more bcasts to send */
  438. if (forw_packet->num_packets < BATADV_NUM_BCASTS_MAX) {
  439. _batadv_add_bcast_packet_to_list(bat_priv, forw_packet,
  440. msecs_to_jiffies(5));
  441. return;
  442. }
  443. out:
  444. batadv_forw_packet_free(forw_packet);
  445. atomic_inc(&bat_priv->bcast_queue_left);
  446. }
  447. void batadv_send_outstanding_bat_ogm_packet(struct work_struct *work)
  448. {
  449. struct delayed_work *delayed_work;
  450. struct batadv_forw_packet *forw_packet;
  451. struct batadv_priv *bat_priv;
  452. delayed_work = container_of(work, struct delayed_work, work);
  453. forw_packet = container_of(delayed_work, struct batadv_forw_packet,
  454. delayed_work);
  455. bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
  456. spin_lock_bh(&bat_priv->forw_bat_list_lock);
  457. hlist_del(&forw_packet->list);
  458. spin_unlock_bh(&bat_priv->forw_bat_list_lock);
  459. if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
  460. goto out;
  461. bat_priv->bat_algo_ops->bat_ogm_emit(forw_packet);
  462. /* we have to have at least one packet in the queue
  463. * to determine the queues wake up time unless we are
  464. * shutting down
  465. */
  466. if (forw_packet->own)
  467. batadv_schedule_bat_ogm(forw_packet->if_incoming);
  468. out:
  469. /* don't count own packet */
  470. if (!forw_packet->own)
  471. atomic_inc(&bat_priv->batman_queue_left);
  472. batadv_forw_packet_free(forw_packet);
  473. }
  474. void
  475. batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
  476. const struct batadv_hard_iface *hard_iface)
  477. {
  478. struct batadv_forw_packet *forw_packet;
  479. struct hlist_node *safe_tmp_node;
  480. bool pending;
  481. if (hard_iface)
  482. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  483. "purge_outstanding_packets(): %s\n",
  484. hard_iface->net_dev->name);
  485. else
  486. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  487. "purge_outstanding_packets()\n");
  488. /* free bcast list */
  489. spin_lock_bh(&bat_priv->forw_bcast_list_lock);
  490. hlist_for_each_entry_safe(forw_packet, safe_tmp_node,
  491. &bat_priv->forw_bcast_list, list) {
  492. /* if purge_outstanding_packets() was called with an argument
  493. * we delete only packets belonging to the given interface
  494. */
  495. if ((hard_iface) &&
  496. (forw_packet->if_incoming != hard_iface))
  497. continue;
  498. spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
  499. /* batadv_send_outstanding_bcast_packet() will lock the list to
  500. * delete the item from the list
  501. */
  502. pending = cancel_delayed_work_sync(&forw_packet->delayed_work);
  503. spin_lock_bh(&bat_priv->forw_bcast_list_lock);
  504. if (pending) {
  505. hlist_del(&forw_packet->list);
  506. batadv_forw_packet_free(forw_packet);
  507. }
  508. }
  509. spin_unlock_bh(&bat_priv->forw_bcast_list_lock);
  510. /* free batman packet list */
  511. spin_lock_bh(&bat_priv->forw_bat_list_lock);
  512. hlist_for_each_entry_safe(forw_packet, safe_tmp_node,
  513. &bat_priv->forw_bat_list, list) {
  514. /* if purge_outstanding_packets() was called with an argument
  515. * we delete only packets belonging to the given interface
  516. */
  517. if ((hard_iface) &&
  518. (forw_packet->if_incoming != hard_iface))
  519. continue;
  520. spin_unlock_bh(&bat_priv->forw_bat_list_lock);
  521. /* send_outstanding_bat_packet() will lock the list to
  522. * delete the item from the list
  523. */
  524. pending = cancel_delayed_work_sync(&forw_packet->delayed_work);
  525. spin_lock_bh(&bat_priv->forw_bat_list_lock);
  526. if (pending) {
  527. hlist_del(&forw_packet->list);
  528. batadv_forw_packet_free(forw_packet);
  529. }
  530. }
  531. spin_unlock_bh(&bat_priv->forw_bat_list_lock);
  532. }