routing.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /* Copyright (C) 2007-2017 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, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "routing.h"
  18. #include "main.h"
  19. #include <linux/atomic.h>
  20. #include <linux/byteorder/generic.h>
  21. #include <linux/compiler.h>
  22. #include <linux/errno.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/if_ether.h>
  25. #include <linux/jiffies.h>
  26. #include <linux/kref.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/printk.h>
  29. #include <linux/rculist.h>
  30. #include <linux/rcupdate.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/spinlock.h>
  33. #include <linux/stddef.h>
  34. #include "bitarray.h"
  35. #include "bridge_loop_avoidance.h"
  36. #include "distributed-arp-table.h"
  37. #include "fragmentation.h"
  38. #include "hard-interface.h"
  39. #include "icmp_socket.h"
  40. #include "log.h"
  41. #include "network-coding.h"
  42. #include "originator.h"
  43. #include "packet.h"
  44. #include "send.h"
  45. #include "soft-interface.h"
  46. #include "tp_meter.h"
  47. #include "translation-table.h"
  48. #include "tvlv.h"
  49. static int batadv_route_unicast_packet(struct sk_buff *skb,
  50. struct batadv_hard_iface *recv_if);
  51. /**
  52. * _batadv_update_route - set the router for this originator
  53. * @bat_priv: the bat priv with all the soft interface information
  54. * @orig_node: orig node which is to be configured
  55. * @recv_if: the receive interface for which this route is set
  56. * @neigh_node: neighbor which should be the next router
  57. *
  58. * This function does not perform any error checks
  59. */
  60. static void _batadv_update_route(struct batadv_priv *bat_priv,
  61. struct batadv_orig_node *orig_node,
  62. struct batadv_hard_iface *recv_if,
  63. struct batadv_neigh_node *neigh_node)
  64. {
  65. struct batadv_orig_ifinfo *orig_ifinfo;
  66. struct batadv_neigh_node *curr_router;
  67. orig_ifinfo = batadv_orig_ifinfo_get(orig_node, recv_if);
  68. if (!orig_ifinfo)
  69. return;
  70. spin_lock_bh(&orig_node->neigh_list_lock);
  71. /* curr_router used earlier may not be the current orig_ifinfo->router
  72. * anymore because it was dereferenced outside of the neigh_list_lock
  73. * protected region. After the new best neighbor has replace the current
  74. * best neighbor the reference counter needs to decrease. Consequently,
  75. * the code needs to ensure the curr_router variable contains a pointer
  76. * to the replaced best neighbor.
  77. */
  78. curr_router = rcu_dereference_protected(orig_ifinfo->router, true);
  79. /* increase refcount of new best neighbor */
  80. if (neigh_node)
  81. kref_get(&neigh_node->refcount);
  82. rcu_assign_pointer(orig_ifinfo->router, neigh_node);
  83. spin_unlock_bh(&orig_node->neigh_list_lock);
  84. batadv_orig_ifinfo_put(orig_ifinfo);
  85. /* route deleted */
  86. if ((curr_router) && (!neigh_node)) {
  87. batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
  88. "Deleting route towards: %pM\n", orig_node->orig);
  89. batadv_tt_global_del_orig(bat_priv, orig_node, -1,
  90. "Deleted route towards originator");
  91. /* route added */
  92. } else if ((!curr_router) && (neigh_node)) {
  93. batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
  94. "Adding route towards: %pM (via %pM)\n",
  95. orig_node->orig, neigh_node->addr);
  96. /* route changed */
  97. } else if (neigh_node && curr_router) {
  98. batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
  99. "Changing route towards: %pM (now via %pM - was via %pM)\n",
  100. orig_node->orig, neigh_node->addr,
  101. curr_router->addr);
  102. }
  103. /* decrease refcount of previous best neighbor */
  104. if (curr_router)
  105. batadv_neigh_node_put(curr_router);
  106. }
  107. /**
  108. * batadv_update_route - set the router for this originator
  109. * @bat_priv: the bat priv with all the soft interface information
  110. * @orig_node: orig node which is to be configured
  111. * @recv_if: the receive interface for which this route is set
  112. * @neigh_node: neighbor which should be the next router
  113. */
  114. void batadv_update_route(struct batadv_priv *bat_priv,
  115. struct batadv_orig_node *orig_node,
  116. struct batadv_hard_iface *recv_if,
  117. struct batadv_neigh_node *neigh_node)
  118. {
  119. struct batadv_neigh_node *router = NULL;
  120. if (!orig_node)
  121. goto out;
  122. router = batadv_orig_router_get(orig_node, recv_if);
  123. if (router != neigh_node)
  124. _batadv_update_route(bat_priv, orig_node, recv_if, neigh_node);
  125. out:
  126. if (router)
  127. batadv_neigh_node_put(router);
  128. }
  129. /**
  130. * batadv_window_protected - checks whether the host restarted and is in the
  131. * protection time.
  132. * @bat_priv: the bat priv with all the soft interface information
  133. * @seq_num_diff: difference between the current/received sequence number and
  134. * the last sequence number
  135. * @seq_old_max_diff: maximum age of sequence number not considered as restart
  136. * @last_reset: jiffies timestamp of the last reset, will be updated when reset
  137. * is detected
  138. * @protection_started: is set to true if the protection window was started,
  139. * doesn't change otherwise.
  140. *
  141. * Return:
  142. * false if the packet is to be accepted.
  143. * true if the packet is to be ignored.
  144. */
  145. bool batadv_window_protected(struct batadv_priv *bat_priv, s32 seq_num_diff,
  146. s32 seq_old_max_diff, unsigned long *last_reset,
  147. bool *protection_started)
  148. {
  149. if (seq_num_diff <= -seq_old_max_diff ||
  150. seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE) {
  151. if (!batadv_has_timed_out(*last_reset,
  152. BATADV_RESET_PROTECTION_MS))
  153. return true;
  154. *last_reset = jiffies;
  155. if (protection_started)
  156. *protection_started = true;
  157. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  158. "old packet received, start protection\n");
  159. }
  160. return false;
  161. }
  162. bool batadv_check_management_packet(struct sk_buff *skb,
  163. struct batadv_hard_iface *hard_iface,
  164. int header_len)
  165. {
  166. struct ethhdr *ethhdr;
  167. /* drop packet if it has not necessary minimum size */
  168. if (unlikely(!pskb_may_pull(skb, header_len)))
  169. return false;
  170. ethhdr = eth_hdr(skb);
  171. /* packet with broadcast indication but unicast recipient */
  172. if (!is_broadcast_ether_addr(ethhdr->h_dest))
  173. return false;
  174. /* packet with invalid sender address */
  175. if (!is_valid_ether_addr(ethhdr->h_source))
  176. return false;
  177. /* create a copy of the skb, if needed, to modify it. */
  178. if (skb_cow(skb, 0) < 0)
  179. return false;
  180. /* keep skb linear */
  181. if (skb_linearize(skb) < 0)
  182. return false;
  183. return true;
  184. }
  185. /**
  186. * batadv_recv_my_icmp_packet - receive an icmp packet locally
  187. * @bat_priv: the bat priv with all the soft interface information
  188. * @skb: icmp packet to process
  189. *
  190. * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
  191. * otherwise.
  192. */
  193. static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
  194. struct sk_buff *skb)
  195. {
  196. struct batadv_hard_iface *primary_if = NULL;
  197. struct batadv_orig_node *orig_node = NULL;
  198. struct batadv_icmp_header *icmph;
  199. int res, ret = NET_RX_DROP;
  200. icmph = (struct batadv_icmp_header *)skb->data;
  201. switch (icmph->msg_type) {
  202. case BATADV_ECHO_REPLY:
  203. case BATADV_DESTINATION_UNREACHABLE:
  204. case BATADV_TTL_EXCEEDED:
  205. /* receive the packet */
  206. if (skb_linearize(skb) < 0)
  207. break;
  208. batadv_socket_receive_packet(icmph, skb->len);
  209. break;
  210. case BATADV_ECHO_REQUEST:
  211. /* answer echo request (ping) */
  212. primary_if = batadv_primary_if_get_selected(bat_priv);
  213. if (!primary_if)
  214. goto out;
  215. /* get routing information */
  216. orig_node = batadv_orig_hash_find(bat_priv, icmph->orig);
  217. if (!orig_node)
  218. goto out;
  219. /* create a copy of the skb, if needed, to modify it. */
  220. if (skb_cow(skb, ETH_HLEN) < 0)
  221. goto out;
  222. icmph = (struct batadv_icmp_header *)skb->data;
  223. ether_addr_copy(icmph->dst, icmph->orig);
  224. ether_addr_copy(icmph->orig, primary_if->net_dev->dev_addr);
  225. icmph->msg_type = BATADV_ECHO_REPLY;
  226. icmph->ttl = BATADV_TTL;
  227. res = batadv_send_skb_to_orig(skb, orig_node, NULL);
  228. if (res == NET_XMIT_SUCCESS)
  229. ret = NET_RX_SUCCESS;
  230. /* skb was consumed */
  231. skb = NULL;
  232. break;
  233. case BATADV_TP:
  234. if (!pskb_may_pull(skb, sizeof(struct batadv_icmp_tp_packet)))
  235. goto out;
  236. batadv_tp_meter_recv(bat_priv, skb);
  237. ret = NET_RX_SUCCESS;
  238. /* skb was consumed */
  239. skb = NULL;
  240. goto out;
  241. default:
  242. /* drop unknown type */
  243. goto out;
  244. }
  245. out:
  246. if (primary_if)
  247. batadv_hardif_put(primary_if);
  248. if (orig_node)
  249. batadv_orig_node_put(orig_node);
  250. kfree_skb(skb);
  251. return ret;
  252. }
  253. static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
  254. struct sk_buff *skb)
  255. {
  256. struct batadv_hard_iface *primary_if = NULL;
  257. struct batadv_orig_node *orig_node = NULL;
  258. struct batadv_icmp_packet *icmp_packet;
  259. int res, ret = NET_RX_DROP;
  260. icmp_packet = (struct batadv_icmp_packet *)skb->data;
  261. /* send TTL exceeded if packet is an echo request (traceroute) */
  262. if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) {
  263. pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n",
  264. icmp_packet->orig, icmp_packet->dst);
  265. goto out;
  266. }
  267. primary_if = batadv_primary_if_get_selected(bat_priv);
  268. if (!primary_if)
  269. goto out;
  270. /* get routing information */
  271. orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig);
  272. if (!orig_node)
  273. goto out;
  274. /* create a copy of the skb, if needed, to modify it. */
  275. if (skb_cow(skb, ETH_HLEN) < 0)
  276. goto out;
  277. icmp_packet = (struct batadv_icmp_packet *)skb->data;
  278. ether_addr_copy(icmp_packet->dst, icmp_packet->orig);
  279. ether_addr_copy(icmp_packet->orig, primary_if->net_dev->dev_addr);
  280. icmp_packet->msg_type = BATADV_TTL_EXCEEDED;
  281. icmp_packet->ttl = BATADV_TTL;
  282. res = batadv_send_skb_to_orig(skb, orig_node, NULL);
  283. if (res == NET_RX_SUCCESS)
  284. ret = NET_XMIT_SUCCESS;
  285. /* skb was consumed */
  286. skb = NULL;
  287. out:
  288. if (primary_if)
  289. batadv_hardif_put(primary_if);
  290. if (orig_node)
  291. batadv_orig_node_put(orig_node);
  292. kfree_skb(skb);
  293. return ret;
  294. }
  295. int batadv_recv_icmp_packet(struct sk_buff *skb,
  296. struct batadv_hard_iface *recv_if)
  297. {
  298. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  299. struct batadv_icmp_header *icmph;
  300. struct batadv_icmp_packet_rr *icmp_packet_rr;
  301. struct ethhdr *ethhdr;
  302. struct batadv_orig_node *orig_node = NULL;
  303. int hdr_size = sizeof(struct batadv_icmp_header);
  304. int res, ret = NET_RX_DROP;
  305. /* drop packet if it has not necessary minimum size */
  306. if (unlikely(!pskb_may_pull(skb, hdr_size)))
  307. goto free_skb;
  308. ethhdr = eth_hdr(skb);
  309. /* packet with unicast indication but non-unicast recipient */
  310. if (!is_valid_ether_addr(ethhdr->h_dest))
  311. goto free_skb;
  312. /* packet with broadcast/multicast sender address */
  313. if (is_multicast_ether_addr(ethhdr->h_source))
  314. goto free_skb;
  315. /* not for me */
  316. if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
  317. goto free_skb;
  318. icmph = (struct batadv_icmp_header *)skb->data;
  319. /* add record route information if not full */
  320. if ((icmph->msg_type == BATADV_ECHO_REPLY ||
  321. icmph->msg_type == BATADV_ECHO_REQUEST) &&
  322. (skb->len >= sizeof(struct batadv_icmp_packet_rr))) {
  323. if (skb_linearize(skb) < 0)
  324. goto free_skb;
  325. /* create a copy of the skb, if needed, to modify it. */
  326. if (skb_cow(skb, ETH_HLEN) < 0)
  327. goto free_skb;
  328. ethhdr = eth_hdr(skb);
  329. icmph = (struct batadv_icmp_header *)skb->data;
  330. icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmph;
  331. if (icmp_packet_rr->rr_cur >= BATADV_RR_LEN)
  332. goto free_skb;
  333. ether_addr_copy(icmp_packet_rr->rr[icmp_packet_rr->rr_cur],
  334. ethhdr->h_dest);
  335. icmp_packet_rr->rr_cur++;
  336. }
  337. /* packet for me */
  338. if (batadv_is_my_mac(bat_priv, icmph->dst))
  339. return batadv_recv_my_icmp_packet(bat_priv, skb);
  340. /* TTL exceeded */
  341. if (icmph->ttl < 2)
  342. return batadv_recv_icmp_ttl_exceeded(bat_priv, skb);
  343. /* get routing information */
  344. orig_node = batadv_orig_hash_find(bat_priv, icmph->dst);
  345. if (!orig_node)
  346. goto free_skb;
  347. /* create a copy of the skb, if needed, to modify it. */
  348. if (skb_cow(skb, ETH_HLEN) < 0)
  349. goto put_orig_node;
  350. icmph = (struct batadv_icmp_header *)skb->data;
  351. /* decrement ttl */
  352. icmph->ttl--;
  353. /* route it */
  354. res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
  355. if (res == NET_XMIT_SUCCESS)
  356. ret = NET_RX_SUCCESS;
  357. /* skb was consumed */
  358. skb = NULL;
  359. put_orig_node:
  360. if (orig_node)
  361. batadv_orig_node_put(orig_node);
  362. free_skb:
  363. kfree_skb(skb);
  364. return ret;
  365. }
  366. /**
  367. * batadv_check_unicast_packet - Check for malformed unicast packets
  368. * @bat_priv: the bat priv with all the soft interface information
  369. * @skb: packet to check
  370. * @hdr_size: size of header to pull
  371. *
  372. * Check for short header and bad addresses in given packet.
  373. *
  374. * Return: negative value when check fails and 0 otherwise. The negative value
  375. * depends on the reason: -ENODATA for bad header, -EBADR for broadcast
  376. * destination or source, and -EREMOTE for non-local (other host) destination.
  377. */
  378. static int batadv_check_unicast_packet(struct batadv_priv *bat_priv,
  379. struct sk_buff *skb, int hdr_size)
  380. {
  381. struct ethhdr *ethhdr;
  382. /* drop packet if it has not necessary minimum size */
  383. if (unlikely(!pskb_may_pull(skb, hdr_size)))
  384. return -ENODATA;
  385. ethhdr = eth_hdr(skb);
  386. /* packet with unicast indication but non-unicast recipient */
  387. if (!is_valid_ether_addr(ethhdr->h_dest))
  388. return -EBADR;
  389. /* packet with broadcast/multicast sender address */
  390. if (is_multicast_ether_addr(ethhdr->h_source))
  391. return -EBADR;
  392. /* not for me */
  393. if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
  394. return -EREMOTE;
  395. return 0;
  396. }
  397. /**
  398. * batadv_last_bonding_get - Get last_bonding_candidate of orig_node
  399. * @orig_node: originator node whose last bonding candidate should be retrieved
  400. *
  401. * Return: last bonding candidate of router or NULL if not found
  402. *
  403. * The object is returned with refcounter increased by 1.
  404. */
  405. static struct batadv_orig_ifinfo *
  406. batadv_last_bonding_get(struct batadv_orig_node *orig_node)
  407. {
  408. struct batadv_orig_ifinfo *last_bonding_candidate;
  409. spin_lock_bh(&orig_node->neigh_list_lock);
  410. last_bonding_candidate = orig_node->last_bonding_candidate;
  411. if (last_bonding_candidate)
  412. kref_get(&last_bonding_candidate->refcount);
  413. spin_unlock_bh(&orig_node->neigh_list_lock);
  414. return last_bonding_candidate;
  415. }
  416. /**
  417. * batadv_last_bonding_replace - Replace last_bonding_candidate of orig_node
  418. * @orig_node: originator node whose bonding candidates should be replaced
  419. * @new_candidate: new bonding candidate or NULL
  420. */
  421. static void
  422. batadv_last_bonding_replace(struct batadv_orig_node *orig_node,
  423. struct batadv_orig_ifinfo *new_candidate)
  424. {
  425. struct batadv_orig_ifinfo *old_candidate;
  426. spin_lock_bh(&orig_node->neigh_list_lock);
  427. old_candidate = orig_node->last_bonding_candidate;
  428. if (new_candidate)
  429. kref_get(&new_candidate->refcount);
  430. orig_node->last_bonding_candidate = new_candidate;
  431. spin_unlock_bh(&orig_node->neigh_list_lock);
  432. if (old_candidate)
  433. batadv_orig_ifinfo_put(old_candidate);
  434. }
  435. /**
  436. * batadv_find_router - find a suitable router for this originator
  437. * @bat_priv: the bat priv with all the soft interface information
  438. * @orig_node: the destination node
  439. * @recv_if: pointer to interface this packet was received on
  440. *
  441. * Return: the router which should be used for this orig_node on
  442. * this interface, or NULL if not available.
  443. */
  444. struct batadv_neigh_node *
  445. batadv_find_router(struct batadv_priv *bat_priv,
  446. struct batadv_orig_node *orig_node,
  447. struct batadv_hard_iface *recv_if)
  448. {
  449. struct batadv_algo_ops *bao = bat_priv->algo_ops;
  450. struct batadv_neigh_node *first_candidate_router = NULL;
  451. struct batadv_neigh_node *next_candidate_router = NULL;
  452. struct batadv_neigh_node *router, *cand_router = NULL;
  453. struct batadv_neigh_node *last_cand_router = NULL;
  454. struct batadv_orig_ifinfo *cand, *first_candidate = NULL;
  455. struct batadv_orig_ifinfo *next_candidate = NULL;
  456. struct batadv_orig_ifinfo *last_candidate;
  457. bool last_candidate_found = false;
  458. if (!orig_node)
  459. return NULL;
  460. router = batadv_orig_router_get(orig_node, recv_if);
  461. if (!router)
  462. return router;
  463. /* only consider bonding for recv_if == BATADV_IF_DEFAULT (first hop)
  464. * and if activated.
  465. */
  466. if (!(recv_if == BATADV_IF_DEFAULT && atomic_read(&bat_priv->bonding)))
  467. return router;
  468. /* bonding: loop through the list of possible routers found
  469. * for the various outgoing interfaces and find a candidate after
  470. * the last chosen bonding candidate (next_candidate). If no such
  471. * router is found, use the first candidate found (the previously
  472. * chosen bonding candidate might have been the last one in the list).
  473. * If this can't be found either, return the previously chosen
  474. * router - obviously there are no other candidates.
  475. */
  476. rcu_read_lock();
  477. last_candidate = batadv_last_bonding_get(orig_node);
  478. if (last_candidate)
  479. last_cand_router = rcu_dereference(last_candidate->router);
  480. hlist_for_each_entry_rcu(cand, &orig_node->ifinfo_list, list) {
  481. /* acquire some structures and references ... */
  482. if (!kref_get_unless_zero(&cand->refcount))
  483. continue;
  484. cand_router = rcu_dereference(cand->router);
  485. if (!cand_router)
  486. goto next;
  487. if (!kref_get_unless_zero(&cand_router->refcount)) {
  488. cand_router = NULL;
  489. goto next;
  490. }
  491. /* alternative candidate should be good enough to be
  492. * considered
  493. */
  494. if (!bao->neigh.is_similar_or_better(cand_router,
  495. cand->if_outgoing, router,
  496. recv_if))
  497. goto next;
  498. /* don't use the same router twice */
  499. if (last_cand_router == cand_router)
  500. goto next;
  501. /* mark the first possible candidate */
  502. if (!first_candidate) {
  503. kref_get(&cand_router->refcount);
  504. kref_get(&cand->refcount);
  505. first_candidate = cand;
  506. first_candidate_router = cand_router;
  507. }
  508. /* check if the loop has already passed the previously selected
  509. * candidate ... this function should select the next candidate
  510. * AFTER the previously used bonding candidate.
  511. */
  512. if (!last_candidate || last_candidate_found) {
  513. next_candidate = cand;
  514. next_candidate_router = cand_router;
  515. break;
  516. }
  517. if (last_candidate == cand)
  518. last_candidate_found = true;
  519. next:
  520. /* free references */
  521. if (cand_router) {
  522. batadv_neigh_node_put(cand_router);
  523. cand_router = NULL;
  524. }
  525. batadv_orig_ifinfo_put(cand);
  526. }
  527. rcu_read_unlock();
  528. /* After finding candidates, handle the three cases:
  529. * 1) there is a next candidate, use that
  530. * 2) there is no next candidate, use the first of the list
  531. * 3) there is no candidate at all, return the default router
  532. */
  533. if (next_candidate) {
  534. batadv_neigh_node_put(router);
  535. kref_get(&next_candidate_router->refcount);
  536. router = next_candidate_router;
  537. batadv_last_bonding_replace(orig_node, next_candidate);
  538. } else if (first_candidate) {
  539. batadv_neigh_node_put(router);
  540. kref_get(&first_candidate_router->refcount);
  541. router = first_candidate_router;
  542. batadv_last_bonding_replace(orig_node, first_candidate);
  543. } else {
  544. batadv_last_bonding_replace(orig_node, NULL);
  545. }
  546. /* cleanup of candidates */
  547. if (first_candidate) {
  548. batadv_neigh_node_put(first_candidate_router);
  549. batadv_orig_ifinfo_put(first_candidate);
  550. }
  551. if (next_candidate) {
  552. batadv_neigh_node_put(next_candidate_router);
  553. batadv_orig_ifinfo_put(next_candidate);
  554. }
  555. if (last_candidate)
  556. batadv_orig_ifinfo_put(last_candidate);
  557. return router;
  558. }
  559. static int batadv_route_unicast_packet(struct sk_buff *skb,
  560. struct batadv_hard_iface *recv_if)
  561. {
  562. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  563. struct batadv_orig_node *orig_node = NULL;
  564. struct batadv_unicast_packet *unicast_packet;
  565. struct ethhdr *ethhdr = eth_hdr(skb);
  566. int res, hdr_len, ret = NET_RX_DROP;
  567. unsigned int len;
  568. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  569. /* TTL exceeded */
  570. if (unicast_packet->ttl < 2) {
  571. pr_debug("Warning - can't forward unicast packet from %pM to %pM: ttl exceeded\n",
  572. ethhdr->h_source, unicast_packet->dest);
  573. goto free_skb;
  574. }
  575. /* get routing information */
  576. orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->dest);
  577. if (!orig_node)
  578. goto free_skb;
  579. /* create a copy of the skb, if needed, to modify it. */
  580. if (skb_cow(skb, ETH_HLEN) < 0)
  581. goto put_orig_node;
  582. /* decrement ttl */
  583. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  584. unicast_packet->ttl--;
  585. switch (unicast_packet->packet_type) {
  586. case BATADV_UNICAST_4ADDR:
  587. hdr_len = sizeof(struct batadv_unicast_4addr_packet);
  588. break;
  589. case BATADV_UNICAST:
  590. hdr_len = sizeof(struct batadv_unicast_packet);
  591. break;
  592. default:
  593. /* other packet types not supported - yet */
  594. hdr_len = -1;
  595. break;
  596. }
  597. if (hdr_len > 0)
  598. batadv_skb_set_priority(skb, hdr_len);
  599. len = skb->len;
  600. res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
  601. /* translate transmit result into receive result */
  602. if (res == NET_XMIT_SUCCESS) {
  603. ret = NET_RX_SUCCESS;
  604. /* skb was transmitted and consumed */
  605. batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
  606. batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
  607. len + ETH_HLEN);
  608. }
  609. /* skb was consumed */
  610. skb = NULL;
  611. put_orig_node:
  612. batadv_orig_node_put(orig_node);
  613. free_skb:
  614. kfree_skb(skb);
  615. return ret;
  616. }
  617. /**
  618. * batadv_reroute_unicast_packet - update the unicast header for re-routing
  619. * @bat_priv: the bat priv with all the soft interface information
  620. * @unicast_packet: the unicast header to be updated
  621. * @dst_addr: the payload destination
  622. * @vid: VLAN identifier
  623. *
  624. * Search the translation table for dst_addr and update the unicast header with
  625. * the new corresponding information (originator address where the destination
  626. * client currently is and its known TTVN)
  627. *
  628. * Return: true if the packet header has been updated, false otherwise
  629. */
  630. static bool
  631. batadv_reroute_unicast_packet(struct batadv_priv *bat_priv,
  632. struct batadv_unicast_packet *unicast_packet,
  633. u8 *dst_addr, unsigned short vid)
  634. {
  635. struct batadv_orig_node *orig_node = NULL;
  636. struct batadv_hard_iface *primary_if = NULL;
  637. bool ret = false;
  638. u8 *orig_addr, orig_ttvn;
  639. if (batadv_is_my_client(bat_priv, dst_addr, vid)) {
  640. primary_if = batadv_primary_if_get_selected(bat_priv);
  641. if (!primary_if)
  642. goto out;
  643. orig_addr = primary_if->net_dev->dev_addr;
  644. orig_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
  645. } else {
  646. orig_node = batadv_transtable_search(bat_priv, NULL, dst_addr,
  647. vid);
  648. if (!orig_node)
  649. goto out;
  650. if (batadv_compare_eth(orig_node->orig, unicast_packet->dest))
  651. goto out;
  652. orig_addr = orig_node->orig;
  653. orig_ttvn = (u8)atomic_read(&orig_node->last_ttvn);
  654. }
  655. /* update the packet header */
  656. ether_addr_copy(unicast_packet->dest, orig_addr);
  657. unicast_packet->ttvn = orig_ttvn;
  658. ret = true;
  659. out:
  660. if (primary_if)
  661. batadv_hardif_put(primary_if);
  662. if (orig_node)
  663. batadv_orig_node_put(orig_node);
  664. return ret;
  665. }
  666. static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
  667. struct sk_buff *skb, int hdr_len)
  668. {
  669. struct batadv_unicast_packet *unicast_packet;
  670. struct batadv_hard_iface *primary_if;
  671. struct batadv_orig_node *orig_node;
  672. u8 curr_ttvn, old_ttvn;
  673. struct ethhdr *ethhdr;
  674. unsigned short vid;
  675. int is_old_ttvn;
  676. /* check if there is enough data before accessing it */
  677. if (!pskb_may_pull(skb, hdr_len + ETH_HLEN))
  678. return false;
  679. /* create a copy of the skb (in case of for re-routing) to modify it. */
  680. if (skb_cow(skb, sizeof(*unicast_packet)) < 0)
  681. return false;
  682. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  683. vid = batadv_get_vid(skb, hdr_len);
  684. ethhdr = (struct ethhdr *)(skb->data + hdr_len);
  685. /* check if the destination client was served by this node and it is now
  686. * roaming. In this case, it means that the node has got a ROAM_ADV
  687. * message and that it knows the new destination in the mesh to re-route
  688. * the packet to
  689. */
  690. if (batadv_tt_local_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) {
  691. if (batadv_reroute_unicast_packet(bat_priv, unicast_packet,
  692. ethhdr->h_dest, vid))
  693. batadv_dbg_ratelimited(BATADV_DBG_TT,
  694. bat_priv,
  695. "Rerouting unicast packet to %pM (dst=%pM): Local Roaming\n",
  696. unicast_packet->dest,
  697. ethhdr->h_dest);
  698. /* at this point the mesh destination should have been
  699. * substituted with the originator address found in the global
  700. * table. If not, let the packet go untouched anyway because
  701. * there is nothing the node can do
  702. */
  703. return true;
  704. }
  705. /* retrieve the TTVN known by this node for the packet destination. This
  706. * value is used later to check if the node which sent (or re-routed
  707. * last time) the packet had an updated information or not
  708. */
  709. curr_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
  710. if (!batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
  711. orig_node = batadv_orig_hash_find(bat_priv,
  712. unicast_packet->dest);
  713. /* if it is not possible to find the orig_node representing the
  714. * destination, the packet can immediately be dropped as it will
  715. * not be possible to deliver it
  716. */
  717. if (!orig_node)
  718. return false;
  719. curr_ttvn = (u8)atomic_read(&orig_node->last_ttvn);
  720. batadv_orig_node_put(orig_node);
  721. }
  722. /* check if the TTVN contained in the packet is fresher than what the
  723. * node knows
  724. */
  725. is_old_ttvn = batadv_seq_before(unicast_packet->ttvn, curr_ttvn);
  726. if (!is_old_ttvn)
  727. return true;
  728. old_ttvn = unicast_packet->ttvn;
  729. /* the packet was forged based on outdated network information. Its
  730. * destination can possibly be updated and forwarded towards the new
  731. * target host
  732. */
  733. if (batadv_reroute_unicast_packet(bat_priv, unicast_packet,
  734. ethhdr->h_dest, vid)) {
  735. batadv_dbg_ratelimited(BATADV_DBG_TT, bat_priv,
  736. "Rerouting unicast packet to %pM (dst=%pM): TTVN mismatch old_ttvn=%u new_ttvn=%u\n",
  737. unicast_packet->dest, ethhdr->h_dest,
  738. old_ttvn, curr_ttvn);
  739. return true;
  740. }
  741. /* the packet has not been re-routed: either the destination is
  742. * currently served by this node or there is no destination at all and
  743. * it is possible to drop the packet
  744. */
  745. if (!batadv_is_my_client(bat_priv, ethhdr->h_dest, vid))
  746. return false;
  747. /* update the header in order to let the packet be delivered to this
  748. * node's soft interface
  749. */
  750. primary_if = batadv_primary_if_get_selected(bat_priv);
  751. if (!primary_if)
  752. return false;
  753. ether_addr_copy(unicast_packet->dest, primary_if->net_dev->dev_addr);
  754. batadv_hardif_put(primary_if);
  755. unicast_packet->ttvn = curr_ttvn;
  756. return true;
  757. }
  758. /**
  759. * batadv_recv_unhandled_unicast_packet - receive and process packets which
  760. * are in the unicast number space but not yet known to the implementation
  761. * @skb: unicast tvlv packet to process
  762. * @recv_if: pointer to interface this packet was received on
  763. *
  764. * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
  765. * otherwise.
  766. */
  767. int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
  768. struct batadv_hard_iface *recv_if)
  769. {
  770. struct batadv_unicast_packet *unicast_packet;
  771. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  772. int check, hdr_size = sizeof(*unicast_packet);
  773. check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
  774. if (check < 0)
  775. goto free_skb;
  776. /* we don't know about this type, drop it. */
  777. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  778. if (batadv_is_my_mac(bat_priv, unicast_packet->dest))
  779. goto free_skb;
  780. return batadv_route_unicast_packet(skb, recv_if);
  781. free_skb:
  782. kfree_skb(skb);
  783. return NET_RX_DROP;
  784. }
  785. int batadv_recv_unicast_packet(struct sk_buff *skb,
  786. struct batadv_hard_iface *recv_if)
  787. {
  788. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  789. struct batadv_unicast_packet *unicast_packet;
  790. struct batadv_unicast_4addr_packet *unicast_4addr_packet;
  791. u8 *orig_addr, *orig_addr_gw;
  792. struct batadv_orig_node *orig_node = NULL, *orig_node_gw = NULL;
  793. int check, hdr_size = sizeof(*unicast_packet);
  794. enum batadv_subtype subtype;
  795. struct ethhdr *ethhdr;
  796. int ret = NET_RX_DROP;
  797. bool is4addr, is_gw;
  798. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  799. unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
  800. ethhdr = eth_hdr(skb);
  801. is4addr = unicast_packet->packet_type == BATADV_UNICAST_4ADDR;
  802. /* the caller function should have already pulled 2 bytes */
  803. if (is4addr)
  804. hdr_size = sizeof(*unicast_4addr_packet);
  805. /* function returns -EREMOTE for promiscuous packets */
  806. check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
  807. /* Even though the packet is not for us, we might save it to use for
  808. * decoding a later received coded packet
  809. */
  810. if (check == -EREMOTE)
  811. batadv_nc_skb_store_sniffed_unicast(bat_priv, skb);
  812. if (check < 0)
  813. goto free_skb;
  814. if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size))
  815. goto free_skb;
  816. /* packet for me */
  817. if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
  818. /* If this is a unicast packet from another backgone gw,
  819. * drop it.
  820. */
  821. orig_addr_gw = ethhdr->h_source;
  822. orig_node_gw = batadv_orig_hash_find(bat_priv, orig_addr_gw);
  823. if (orig_node_gw) {
  824. is_gw = batadv_bla_is_backbone_gw(skb, orig_node_gw,
  825. hdr_size);
  826. batadv_orig_node_put(orig_node_gw);
  827. if (is_gw) {
  828. batadv_dbg(BATADV_DBG_BLA, bat_priv,
  829. "%s(): Dropped unicast pkt received from another backbone gw %pM.\n",
  830. __func__, orig_addr_gw);
  831. goto free_skb;
  832. }
  833. }
  834. if (is4addr) {
  835. subtype = unicast_4addr_packet->subtype;
  836. batadv_dat_inc_counter(bat_priv, subtype);
  837. /* Only payload data should be considered for speedy
  838. * join. For example, DAT also uses unicast 4addr
  839. * types, but those packets should not be considered
  840. * for speedy join, since the clients do not actually
  841. * reside at the sending originator.
  842. */
  843. if (subtype == BATADV_P_DATA) {
  844. orig_addr = unicast_4addr_packet->src;
  845. orig_node = batadv_orig_hash_find(bat_priv,
  846. orig_addr);
  847. }
  848. }
  849. if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb,
  850. hdr_size))
  851. goto rx_success;
  852. if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb,
  853. hdr_size))
  854. goto rx_success;
  855. batadv_interface_rx(recv_if->soft_iface, skb, hdr_size,
  856. orig_node);
  857. rx_success:
  858. if (orig_node)
  859. batadv_orig_node_put(orig_node);
  860. return NET_RX_SUCCESS;
  861. }
  862. ret = batadv_route_unicast_packet(skb, recv_if);
  863. /* skb was consumed */
  864. skb = NULL;
  865. free_skb:
  866. kfree_skb(skb);
  867. return ret;
  868. }
  869. /**
  870. * batadv_recv_unicast_tvlv - receive and process unicast tvlv packets
  871. * @skb: unicast tvlv packet to process
  872. * @recv_if: pointer to interface this packet was received on
  873. *
  874. * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
  875. * otherwise.
  876. */
  877. int batadv_recv_unicast_tvlv(struct sk_buff *skb,
  878. struct batadv_hard_iface *recv_if)
  879. {
  880. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  881. struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
  882. unsigned char *tvlv_buff;
  883. u16 tvlv_buff_len;
  884. int hdr_size = sizeof(*unicast_tvlv_packet);
  885. int ret = NET_RX_DROP;
  886. if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
  887. goto free_skb;
  888. /* the header is likely to be modified while forwarding */
  889. if (skb_cow(skb, hdr_size) < 0)
  890. goto free_skb;
  891. /* packet needs to be linearized to access the tvlv content */
  892. if (skb_linearize(skb) < 0)
  893. goto free_skb;
  894. unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)skb->data;
  895. tvlv_buff = (unsigned char *)(skb->data + hdr_size);
  896. tvlv_buff_len = ntohs(unicast_tvlv_packet->tvlv_len);
  897. if (tvlv_buff_len > skb->len - hdr_size)
  898. goto free_skb;
  899. ret = batadv_tvlv_containers_process(bat_priv, false, NULL,
  900. unicast_tvlv_packet->src,
  901. unicast_tvlv_packet->dst,
  902. tvlv_buff, tvlv_buff_len);
  903. if (ret != NET_RX_SUCCESS) {
  904. ret = batadv_route_unicast_packet(skb, recv_if);
  905. /* skb was consumed */
  906. skb = NULL;
  907. }
  908. free_skb:
  909. kfree_skb(skb);
  910. return ret;
  911. }
  912. /**
  913. * batadv_recv_frag_packet - process received fragment
  914. * @skb: the received fragment
  915. * @recv_if: interface that the skb is received on
  916. *
  917. * This function does one of the three following things: 1) Forward fragment, if
  918. * the assembled packet will exceed our MTU; 2) Buffer fragment, if we till
  919. * lack further fragments; 3) Merge fragments, if we have all needed parts.
  920. *
  921. * Return: NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise.
  922. */
  923. int batadv_recv_frag_packet(struct sk_buff *skb,
  924. struct batadv_hard_iface *recv_if)
  925. {
  926. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  927. struct batadv_orig_node *orig_node_src = NULL;
  928. struct batadv_frag_packet *frag_packet;
  929. int ret = NET_RX_DROP;
  930. if (batadv_check_unicast_packet(bat_priv, skb,
  931. sizeof(*frag_packet)) < 0)
  932. goto free_skb;
  933. frag_packet = (struct batadv_frag_packet *)skb->data;
  934. orig_node_src = batadv_orig_hash_find(bat_priv, frag_packet->orig);
  935. if (!orig_node_src)
  936. goto free_skb;
  937. skb->priority = frag_packet->priority + 256;
  938. /* Route the fragment if it is not for us and too big to be merged. */
  939. if (!batadv_is_my_mac(bat_priv, frag_packet->dest) &&
  940. batadv_frag_skb_fwd(skb, recv_if, orig_node_src)) {
  941. /* skb was consumed */
  942. skb = NULL;
  943. ret = NET_RX_SUCCESS;
  944. goto put_orig_node;
  945. }
  946. batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_RX);
  947. batadv_add_counter(bat_priv, BATADV_CNT_FRAG_RX_BYTES, skb->len);
  948. /* Add fragment to buffer and merge if possible. */
  949. if (!batadv_frag_skb_buffer(&skb, orig_node_src))
  950. goto put_orig_node;
  951. /* Deliver merged packet to the appropriate handler, if it was
  952. * merged
  953. */
  954. if (skb) {
  955. batadv_batman_skb_recv(skb, recv_if->net_dev,
  956. &recv_if->batman_adv_ptype, NULL);
  957. /* skb was consumed */
  958. skb = NULL;
  959. }
  960. ret = NET_RX_SUCCESS;
  961. put_orig_node:
  962. batadv_orig_node_put(orig_node_src);
  963. free_skb:
  964. kfree_skb(skb);
  965. return ret;
  966. }
  967. int batadv_recv_bcast_packet(struct sk_buff *skb,
  968. struct batadv_hard_iface *recv_if)
  969. {
  970. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  971. struct batadv_orig_node *orig_node = NULL;
  972. struct batadv_bcast_packet *bcast_packet;
  973. struct ethhdr *ethhdr;
  974. int hdr_size = sizeof(*bcast_packet);
  975. int ret = NET_RX_DROP;
  976. s32 seq_diff;
  977. u32 seqno;
  978. /* drop packet if it has not necessary minimum size */
  979. if (unlikely(!pskb_may_pull(skb, hdr_size)))
  980. goto free_skb;
  981. ethhdr = eth_hdr(skb);
  982. /* packet with broadcast indication but unicast recipient */
  983. if (!is_broadcast_ether_addr(ethhdr->h_dest))
  984. goto free_skb;
  985. /* packet with broadcast/multicast sender address */
  986. if (is_multicast_ether_addr(ethhdr->h_source))
  987. goto free_skb;
  988. /* ignore broadcasts sent by myself */
  989. if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
  990. goto free_skb;
  991. bcast_packet = (struct batadv_bcast_packet *)skb->data;
  992. /* ignore broadcasts originated by myself */
  993. if (batadv_is_my_mac(bat_priv, bcast_packet->orig))
  994. goto free_skb;
  995. if (bcast_packet->ttl < 2)
  996. goto free_skb;
  997. orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->orig);
  998. if (!orig_node)
  999. goto free_skb;
  1000. spin_lock_bh(&orig_node->bcast_seqno_lock);
  1001. seqno = ntohl(bcast_packet->seqno);
  1002. /* check whether the packet is a duplicate */
  1003. if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno,
  1004. seqno))
  1005. goto spin_unlock;
  1006. seq_diff = seqno - orig_node->last_bcast_seqno;
  1007. /* check whether the packet is old and the host just restarted. */
  1008. if (batadv_window_protected(bat_priv, seq_diff,
  1009. BATADV_BCAST_MAX_AGE,
  1010. &orig_node->bcast_seqno_reset, NULL))
  1011. goto spin_unlock;
  1012. /* mark broadcast in flood history, update window position
  1013. * if required.
  1014. */
  1015. if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1))
  1016. orig_node->last_bcast_seqno = seqno;
  1017. spin_unlock_bh(&orig_node->bcast_seqno_lock);
  1018. /* check whether this has been sent by another originator before */
  1019. if (batadv_bla_check_bcast_duplist(bat_priv, skb))
  1020. goto free_skb;
  1021. batadv_skb_set_priority(skb, sizeof(struct batadv_bcast_packet));
  1022. /* rebroadcast packet */
  1023. batadv_add_bcast_packet_to_list(bat_priv, skb, 1, false);
  1024. /* don't hand the broadcast up if it is from an originator
  1025. * from the same backbone.
  1026. */
  1027. if (batadv_bla_is_backbone_gw(skb, orig_node, hdr_size))
  1028. goto free_skb;
  1029. if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size))
  1030. goto rx_success;
  1031. if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size))
  1032. goto rx_success;
  1033. /* broadcast for me */
  1034. batadv_interface_rx(recv_if->soft_iface, skb, hdr_size, orig_node);
  1035. rx_success:
  1036. ret = NET_RX_SUCCESS;
  1037. goto out;
  1038. spin_unlock:
  1039. spin_unlock_bh(&orig_node->bcast_seqno_lock);
  1040. free_skb:
  1041. kfree_skb(skb);
  1042. out:
  1043. if (orig_node)
  1044. batadv_orig_node_put(orig_node);
  1045. return ret;
  1046. }