routing.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. /* Copyright (C) 2007-2016 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. if (res == NET_XMIT_SUCCESS)
  602. ret = NET_RX_SUCCESS;
  603. /* skb was consumed */
  604. skb = NULL;
  605. /* translate transmit result into receive result */
  606. if (res == NET_XMIT_SUCCESS) {
  607. /* skb was transmitted and consumed */
  608. batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
  609. batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
  610. len + ETH_HLEN);
  611. }
  612. put_orig_node:
  613. batadv_orig_node_put(orig_node);
  614. free_skb:
  615. kfree_skb(skb);
  616. return ret;
  617. }
  618. /**
  619. * batadv_reroute_unicast_packet - update the unicast header for re-routing
  620. * @bat_priv: the bat priv with all the soft interface information
  621. * @unicast_packet: the unicast header to be updated
  622. * @dst_addr: the payload destination
  623. * @vid: VLAN identifier
  624. *
  625. * Search the translation table for dst_addr and update the unicast header with
  626. * the new corresponding information (originator address where the destination
  627. * client currently is and its known TTVN)
  628. *
  629. * Return: true if the packet header has been updated, false otherwise
  630. */
  631. static bool
  632. batadv_reroute_unicast_packet(struct batadv_priv *bat_priv,
  633. struct batadv_unicast_packet *unicast_packet,
  634. u8 *dst_addr, unsigned short vid)
  635. {
  636. struct batadv_orig_node *orig_node = NULL;
  637. struct batadv_hard_iface *primary_if = NULL;
  638. bool ret = false;
  639. u8 *orig_addr, orig_ttvn;
  640. if (batadv_is_my_client(bat_priv, dst_addr, vid)) {
  641. primary_if = batadv_primary_if_get_selected(bat_priv);
  642. if (!primary_if)
  643. goto out;
  644. orig_addr = primary_if->net_dev->dev_addr;
  645. orig_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
  646. } else {
  647. orig_node = batadv_transtable_search(bat_priv, NULL, dst_addr,
  648. vid);
  649. if (!orig_node)
  650. goto out;
  651. if (batadv_compare_eth(orig_node->orig, unicast_packet->dest))
  652. goto out;
  653. orig_addr = orig_node->orig;
  654. orig_ttvn = (u8)atomic_read(&orig_node->last_ttvn);
  655. }
  656. /* update the packet header */
  657. ether_addr_copy(unicast_packet->dest, orig_addr);
  658. unicast_packet->ttvn = orig_ttvn;
  659. ret = true;
  660. out:
  661. if (primary_if)
  662. batadv_hardif_put(primary_if);
  663. if (orig_node)
  664. batadv_orig_node_put(orig_node);
  665. return ret;
  666. }
  667. static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
  668. struct sk_buff *skb, int hdr_len)
  669. {
  670. struct batadv_unicast_packet *unicast_packet;
  671. struct batadv_hard_iface *primary_if;
  672. struct batadv_orig_node *orig_node;
  673. u8 curr_ttvn, old_ttvn;
  674. struct ethhdr *ethhdr;
  675. unsigned short vid;
  676. int is_old_ttvn;
  677. /* check if there is enough data before accessing it */
  678. if (!pskb_may_pull(skb, hdr_len + ETH_HLEN))
  679. return false;
  680. /* create a copy of the skb (in case of for re-routing) to modify it. */
  681. if (skb_cow(skb, sizeof(*unicast_packet)) < 0)
  682. return false;
  683. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  684. vid = batadv_get_vid(skb, hdr_len);
  685. ethhdr = (struct ethhdr *)(skb->data + hdr_len);
  686. /* check if the destination client was served by this node and it is now
  687. * roaming. In this case, it means that the node has got a ROAM_ADV
  688. * message and that it knows the new destination in the mesh to re-route
  689. * the packet to
  690. */
  691. if (batadv_tt_local_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) {
  692. if (batadv_reroute_unicast_packet(bat_priv, unicast_packet,
  693. ethhdr->h_dest, vid))
  694. batadv_dbg_ratelimited(BATADV_DBG_TT,
  695. bat_priv,
  696. "Rerouting unicast packet to %pM (dst=%pM): Local Roaming\n",
  697. unicast_packet->dest,
  698. ethhdr->h_dest);
  699. /* at this point the mesh destination should have been
  700. * substituted with the originator address found in the global
  701. * table. If not, let the packet go untouched anyway because
  702. * there is nothing the node can do
  703. */
  704. return true;
  705. }
  706. /* retrieve the TTVN known by this node for the packet destination. This
  707. * value is used later to check if the node which sent (or re-routed
  708. * last time) the packet had an updated information or not
  709. */
  710. curr_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
  711. if (!batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
  712. orig_node = batadv_orig_hash_find(bat_priv,
  713. unicast_packet->dest);
  714. /* if it is not possible to find the orig_node representing the
  715. * destination, the packet can immediately be dropped as it will
  716. * not be possible to deliver it
  717. */
  718. if (!orig_node)
  719. return false;
  720. curr_ttvn = (u8)atomic_read(&orig_node->last_ttvn);
  721. batadv_orig_node_put(orig_node);
  722. }
  723. /* check if the TTVN contained in the packet is fresher than what the
  724. * node knows
  725. */
  726. is_old_ttvn = batadv_seq_before(unicast_packet->ttvn, curr_ttvn);
  727. if (!is_old_ttvn)
  728. return true;
  729. old_ttvn = unicast_packet->ttvn;
  730. /* the packet was forged based on outdated network information. Its
  731. * destination can possibly be updated and forwarded towards the new
  732. * target host
  733. */
  734. if (batadv_reroute_unicast_packet(bat_priv, unicast_packet,
  735. ethhdr->h_dest, vid)) {
  736. batadv_dbg_ratelimited(BATADV_DBG_TT, bat_priv,
  737. "Rerouting unicast packet to %pM (dst=%pM): TTVN mismatch old_ttvn=%u new_ttvn=%u\n",
  738. unicast_packet->dest, ethhdr->h_dest,
  739. old_ttvn, curr_ttvn);
  740. return true;
  741. }
  742. /* the packet has not been re-routed: either the destination is
  743. * currently served by this node or there is no destination at all and
  744. * it is possible to drop the packet
  745. */
  746. if (!batadv_is_my_client(bat_priv, ethhdr->h_dest, vid))
  747. return false;
  748. /* update the header in order to let the packet be delivered to this
  749. * node's soft interface
  750. */
  751. primary_if = batadv_primary_if_get_selected(bat_priv);
  752. if (!primary_if)
  753. return false;
  754. ether_addr_copy(unicast_packet->dest, primary_if->net_dev->dev_addr);
  755. batadv_hardif_put(primary_if);
  756. unicast_packet->ttvn = curr_ttvn;
  757. return true;
  758. }
  759. /**
  760. * batadv_recv_unhandled_unicast_packet - receive and process packets which
  761. * are in the unicast number space but not yet known to the implementation
  762. * @skb: unicast tvlv packet to process
  763. * @recv_if: pointer to interface this packet was received on
  764. *
  765. * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
  766. * otherwise.
  767. */
  768. int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
  769. struct batadv_hard_iface *recv_if)
  770. {
  771. struct batadv_unicast_packet *unicast_packet;
  772. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  773. int check, hdr_size = sizeof(*unicast_packet);
  774. check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
  775. if (check < 0)
  776. goto free_skb;
  777. /* we don't know about this type, drop it. */
  778. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  779. if (batadv_is_my_mac(bat_priv, unicast_packet->dest))
  780. goto free_skb;
  781. return batadv_route_unicast_packet(skb, recv_if);
  782. free_skb:
  783. kfree_skb(skb);
  784. return NET_RX_DROP;
  785. }
  786. int batadv_recv_unicast_packet(struct sk_buff *skb,
  787. struct batadv_hard_iface *recv_if)
  788. {
  789. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  790. struct batadv_unicast_packet *unicast_packet;
  791. struct batadv_unicast_4addr_packet *unicast_4addr_packet;
  792. u8 *orig_addr;
  793. struct batadv_orig_node *orig_node = NULL;
  794. int check, hdr_size = sizeof(*unicast_packet);
  795. enum batadv_subtype subtype;
  796. bool is4addr;
  797. int ret = NET_RX_DROP;
  798. unicast_packet = (struct batadv_unicast_packet *)skb->data;
  799. unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
  800. is4addr = unicast_packet->packet_type == BATADV_UNICAST_4ADDR;
  801. /* the caller function should have already pulled 2 bytes */
  802. if (is4addr)
  803. hdr_size = sizeof(*unicast_4addr_packet);
  804. /* function returns -EREMOTE for promiscuous packets */
  805. check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
  806. /* Even though the packet is not for us, we might save it to use for
  807. * decoding a later received coded packet
  808. */
  809. if (check == -EREMOTE)
  810. batadv_nc_skb_store_sniffed_unicast(bat_priv, skb);
  811. if (check < 0)
  812. goto free_skb;
  813. if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size))
  814. goto free_skb;
  815. /* packet for me */
  816. if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
  817. if (is4addr) {
  818. subtype = unicast_4addr_packet->subtype;
  819. batadv_dat_inc_counter(bat_priv, subtype);
  820. /* Only payload data should be considered for speedy
  821. * join. For example, DAT also uses unicast 4addr
  822. * types, but those packets should not be considered
  823. * for speedy join, since the clients do not actually
  824. * reside at the sending originator.
  825. */
  826. if (subtype == BATADV_P_DATA) {
  827. orig_addr = unicast_4addr_packet->src;
  828. orig_node = batadv_orig_hash_find(bat_priv,
  829. orig_addr);
  830. }
  831. }
  832. if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb,
  833. hdr_size))
  834. goto rx_success;
  835. if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb,
  836. hdr_size))
  837. goto rx_success;
  838. batadv_interface_rx(recv_if->soft_iface, skb, hdr_size,
  839. orig_node);
  840. rx_success:
  841. if (orig_node)
  842. batadv_orig_node_put(orig_node);
  843. return NET_RX_SUCCESS;
  844. }
  845. ret = batadv_route_unicast_packet(skb, recv_if);
  846. /* skb was consumed */
  847. skb = NULL;
  848. free_skb:
  849. kfree_skb(skb);
  850. return ret;
  851. }
  852. /**
  853. * batadv_recv_unicast_tvlv - receive and process unicast tvlv packets
  854. * @skb: unicast tvlv packet to process
  855. * @recv_if: pointer to interface this packet was received on
  856. *
  857. * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
  858. * otherwise.
  859. */
  860. int batadv_recv_unicast_tvlv(struct sk_buff *skb,
  861. struct batadv_hard_iface *recv_if)
  862. {
  863. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  864. struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
  865. unsigned char *tvlv_buff;
  866. u16 tvlv_buff_len;
  867. int hdr_size = sizeof(*unicast_tvlv_packet);
  868. int ret = NET_RX_DROP;
  869. if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
  870. goto free_skb;
  871. /* the header is likely to be modified while forwarding */
  872. if (skb_cow(skb, hdr_size) < 0)
  873. goto free_skb;
  874. /* packet needs to be linearized to access the tvlv content */
  875. if (skb_linearize(skb) < 0)
  876. goto free_skb;
  877. unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)skb->data;
  878. tvlv_buff = (unsigned char *)(skb->data + hdr_size);
  879. tvlv_buff_len = ntohs(unicast_tvlv_packet->tvlv_len);
  880. if (tvlv_buff_len > skb->len - hdr_size)
  881. goto free_skb;
  882. ret = batadv_tvlv_containers_process(bat_priv, false, NULL,
  883. unicast_tvlv_packet->src,
  884. unicast_tvlv_packet->dst,
  885. tvlv_buff, tvlv_buff_len);
  886. if (ret != NET_RX_SUCCESS) {
  887. ret = batadv_route_unicast_packet(skb, recv_if);
  888. /* skb was consumed */
  889. skb = NULL;
  890. }
  891. free_skb:
  892. kfree_skb(skb);
  893. return ret;
  894. }
  895. /**
  896. * batadv_recv_frag_packet - process received fragment
  897. * @skb: the received fragment
  898. * @recv_if: interface that the skb is received on
  899. *
  900. * This function does one of the three following things: 1) Forward fragment, if
  901. * the assembled packet will exceed our MTU; 2) Buffer fragment, if we till
  902. * lack further fragments; 3) Merge fragments, if we have all needed parts.
  903. *
  904. * Return: NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise.
  905. */
  906. int batadv_recv_frag_packet(struct sk_buff *skb,
  907. struct batadv_hard_iface *recv_if)
  908. {
  909. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  910. struct batadv_orig_node *orig_node_src = NULL;
  911. struct batadv_frag_packet *frag_packet;
  912. int ret = NET_RX_DROP;
  913. if (batadv_check_unicast_packet(bat_priv, skb,
  914. sizeof(*frag_packet)) < 0)
  915. goto free_skb;
  916. frag_packet = (struct batadv_frag_packet *)skb->data;
  917. orig_node_src = batadv_orig_hash_find(bat_priv, frag_packet->orig);
  918. if (!orig_node_src)
  919. goto free_skb;
  920. skb->priority = frag_packet->priority + 256;
  921. /* Route the fragment if it is not for us and too big to be merged. */
  922. if (!batadv_is_my_mac(bat_priv, frag_packet->dest) &&
  923. batadv_frag_skb_fwd(skb, recv_if, orig_node_src)) {
  924. /* skb was consumed */
  925. skb = NULL;
  926. ret = NET_RX_SUCCESS;
  927. goto put_orig_node;
  928. }
  929. batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_RX);
  930. batadv_add_counter(bat_priv, BATADV_CNT_FRAG_RX_BYTES, skb->len);
  931. /* Add fragment to buffer and merge if possible. */
  932. if (!batadv_frag_skb_buffer(&skb, orig_node_src))
  933. goto put_orig_node;
  934. /* Deliver merged packet to the appropriate handler, if it was
  935. * merged
  936. */
  937. if (skb) {
  938. batadv_batman_skb_recv(skb, recv_if->net_dev,
  939. &recv_if->batman_adv_ptype, NULL);
  940. /* skb was consumed */
  941. skb = NULL;
  942. }
  943. ret = NET_RX_SUCCESS;
  944. put_orig_node:
  945. batadv_orig_node_put(orig_node_src);
  946. free_skb:
  947. kfree_skb(skb);
  948. return ret;
  949. }
  950. int batadv_recv_bcast_packet(struct sk_buff *skb,
  951. struct batadv_hard_iface *recv_if)
  952. {
  953. struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
  954. struct batadv_orig_node *orig_node = NULL;
  955. struct batadv_bcast_packet *bcast_packet;
  956. struct ethhdr *ethhdr;
  957. int hdr_size = sizeof(*bcast_packet);
  958. int ret = NET_RX_DROP;
  959. s32 seq_diff;
  960. u32 seqno;
  961. /* drop packet if it has not necessary minimum size */
  962. if (unlikely(!pskb_may_pull(skb, hdr_size)))
  963. goto free_skb;
  964. ethhdr = eth_hdr(skb);
  965. /* packet with broadcast indication but unicast recipient */
  966. if (!is_broadcast_ether_addr(ethhdr->h_dest))
  967. goto free_skb;
  968. /* packet with broadcast/multicast sender address */
  969. if (is_multicast_ether_addr(ethhdr->h_source))
  970. goto free_skb;
  971. /* ignore broadcasts sent by myself */
  972. if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
  973. goto free_skb;
  974. bcast_packet = (struct batadv_bcast_packet *)skb->data;
  975. /* ignore broadcasts originated by myself */
  976. if (batadv_is_my_mac(bat_priv, bcast_packet->orig))
  977. goto free_skb;
  978. if (bcast_packet->ttl < 2)
  979. goto free_skb;
  980. orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->orig);
  981. if (!orig_node)
  982. goto free_skb;
  983. spin_lock_bh(&orig_node->bcast_seqno_lock);
  984. seqno = ntohl(bcast_packet->seqno);
  985. /* check whether the packet is a duplicate */
  986. if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno,
  987. seqno))
  988. goto spin_unlock;
  989. seq_diff = seqno - orig_node->last_bcast_seqno;
  990. /* check whether the packet is old and the host just restarted. */
  991. if (batadv_window_protected(bat_priv, seq_diff,
  992. BATADV_BCAST_MAX_AGE,
  993. &orig_node->bcast_seqno_reset, NULL))
  994. goto spin_unlock;
  995. /* mark broadcast in flood history, update window position
  996. * if required.
  997. */
  998. if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1))
  999. orig_node->last_bcast_seqno = seqno;
  1000. spin_unlock_bh(&orig_node->bcast_seqno_lock);
  1001. /* check whether this has been sent by another originator before */
  1002. if (batadv_bla_check_bcast_duplist(bat_priv, skb))
  1003. goto free_skb;
  1004. batadv_skb_set_priority(skb, sizeof(struct batadv_bcast_packet));
  1005. /* rebroadcast packet */
  1006. batadv_add_bcast_packet_to_list(bat_priv, skb, 1, false);
  1007. /* don't hand the broadcast up if it is from an originator
  1008. * from the same backbone.
  1009. */
  1010. if (batadv_bla_is_backbone_gw(skb, orig_node, hdr_size))
  1011. goto free_skb;
  1012. if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size))
  1013. goto rx_success;
  1014. if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size))
  1015. goto rx_success;
  1016. /* broadcast for me */
  1017. batadv_interface_rx(recv_if->soft_iface, skb, hdr_size, orig_node);
  1018. rx_success:
  1019. ret = NET_RX_SUCCESS;
  1020. goto out;
  1021. spin_unlock:
  1022. spin_unlock_bh(&orig_node->bcast_seqno_lock);
  1023. free_skb:
  1024. kfree_skb(skb);
  1025. out:
  1026. if (orig_node)
  1027. batadv_orig_node_put(orig_node);
  1028. return ret;
  1029. }