1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "main.h"
19#include "routing.h"
20#include "send.h"
21#include "soft-interface.h"
22#include "hard-interface.h"
23#include "icmp_socket.h"
24#include "translation-table.h"
25#include "originator.h"
26#include "bridge_loop_avoidance.h"
27#include "distributed-arp-table.h"
28#include "network-coding.h"
29#include "fragmentation.h"
30
31#include <linux/if_vlan.h>
32
33static int batadv_route_unicast_packet(struct sk_buff *skb,
34 struct batadv_hard_iface *recv_if);
35
36
37
38
39
40
41
42
43
44
45static void _batadv_update_route(struct batadv_priv *bat_priv,
46 struct batadv_orig_node *orig_node,
47 struct batadv_hard_iface *recv_if,
48 struct batadv_neigh_node *neigh_node)
49{
50 struct batadv_orig_ifinfo *orig_ifinfo;
51 struct batadv_neigh_node *curr_router;
52
53 orig_ifinfo = batadv_orig_ifinfo_get(orig_node, recv_if);
54 if (!orig_ifinfo)
55 return;
56
57 rcu_read_lock();
58 curr_router = rcu_dereference(orig_ifinfo->router);
59 if (curr_router && !atomic_inc_not_zero(&curr_router->refcount))
60 curr_router = NULL;
61 rcu_read_unlock();
62
63
64 if ((curr_router) && (!neigh_node)) {
65 batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
66 "Deleting route towards: %pM\n", orig_node->orig);
67 batadv_tt_global_del_orig(bat_priv, orig_node, -1,
68 "Deleted route towards originator");
69
70
71 } else if ((!curr_router) && (neigh_node)) {
72 batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
73 "Adding route towards: %pM (via %pM)\n",
74 orig_node->orig, neigh_node->addr);
75
76 } else if (neigh_node && curr_router) {
77 batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
78 "Changing route towards: %pM (now via %pM - was via %pM)\n",
79 orig_node->orig, neigh_node->addr,
80 curr_router->addr);
81 }
82
83 if (curr_router)
84 batadv_neigh_node_free_ref(curr_router);
85
86
87 if (neigh_node && !atomic_inc_not_zero(&neigh_node->refcount))
88 neigh_node = NULL;
89
90 spin_lock_bh(&orig_node->neigh_list_lock);
91 rcu_assign_pointer(orig_ifinfo->router, neigh_node);
92 spin_unlock_bh(&orig_node->neigh_list_lock);
93 batadv_orig_ifinfo_free_ref(orig_ifinfo);
94
95
96 if (curr_router)
97 batadv_neigh_node_free_ref(curr_router);
98}
99
100
101
102
103
104
105
106
107void batadv_update_route(struct batadv_priv *bat_priv,
108 struct batadv_orig_node *orig_node,
109 struct batadv_hard_iface *recv_if,
110 struct batadv_neigh_node *neigh_node)
111{
112 struct batadv_neigh_node *router = NULL;
113
114 if (!orig_node)
115 goto out;
116
117 router = batadv_orig_router_get(orig_node, recv_if);
118
119 if (router != neigh_node)
120 _batadv_update_route(bat_priv, orig_node, recv_if, neigh_node);
121
122out:
123 if (router)
124 batadv_neigh_node_free_ref(router);
125}
126
127
128
129
130
131
132int batadv_window_protected(struct batadv_priv *bat_priv, int32_t seq_num_diff,
133 unsigned long *last_reset)
134{
135 if (seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE ||
136 seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE) {
137 if (!batadv_has_timed_out(*last_reset,
138 BATADV_RESET_PROTECTION_MS))
139 return 1;
140
141 *last_reset = jiffies;
142 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
143 "old packet received, start protection\n");
144 }
145
146 return 0;
147}
148
149bool batadv_check_management_packet(struct sk_buff *skb,
150 struct batadv_hard_iface *hard_iface,
151 int header_len)
152{
153 struct ethhdr *ethhdr;
154
155
156 if (unlikely(!pskb_may_pull(skb, header_len)))
157 return false;
158
159 ethhdr = eth_hdr(skb);
160
161
162 if (!is_broadcast_ether_addr(ethhdr->h_dest))
163 return false;
164
165
166 if (is_broadcast_ether_addr(ethhdr->h_source))
167 return false;
168
169
170 if (skb_cow(skb, 0) < 0)
171 return false;
172
173
174 if (skb_linearize(skb) < 0)
175 return false;
176
177 return true;
178}
179
180
181
182
183
184
185
186
187
188static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
189 struct sk_buff *skb)
190{
191 struct batadv_hard_iface *primary_if = NULL;
192 struct batadv_orig_node *orig_node = NULL;
193 struct batadv_icmp_header *icmph;
194 int res, ret = NET_RX_DROP;
195
196 icmph = (struct batadv_icmp_header *)skb->data;
197
198 switch (icmph->msg_type) {
199 case BATADV_ECHO_REPLY:
200 case BATADV_DESTINATION_UNREACHABLE:
201 case BATADV_TTL_EXCEEDED:
202
203 if (skb_linearize(skb) < 0)
204 break;
205
206 batadv_socket_receive_packet(icmph, skb->len);
207 break;
208 case BATADV_ECHO_REQUEST:
209
210 primary_if = batadv_primary_if_get_selected(bat_priv);
211 if (!primary_if)
212 goto out;
213
214
215 orig_node = batadv_orig_hash_find(bat_priv, icmph->orig);
216 if (!orig_node)
217 goto out;
218
219
220 if (skb_cow(skb, ETH_HLEN) < 0)
221 goto out;
222
223 icmph = (struct batadv_icmp_header *)skb->data;
224
225 ether_addr_copy(icmph->dst, icmph->orig);
226 ether_addr_copy(icmph->orig, primary_if->net_dev->dev_addr);
227 icmph->msg_type = BATADV_ECHO_REPLY;
228 icmph->ttl = BATADV_TTL;
229
230 res = batadv_send_skb_to_orig(skb, orig_node, NULL);
231 if (res != NET_XMIT_DROP)
232 ret = NET_RX_SUCCESS;
233
234 break;
235 default:
236
237 goto out;
238 }
239out:
240 if (primary_if)
241 batadv_hardif_free_ref(primary_if);
242 if (orig_node)
243 batadv_orig_node_free_ref(orig_node);
244 return ret;
245}
246
247static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
248 struct sk_buff *skb)
249{
250 struct batadv_hard_iface *primary_if = NULL;
251 struct batadv_orig_node *orig_node = NULL;
252 struct batadv_icmp_packet *icmp_packet;
253 int ret = NET_RX_DROP;
254
255 icmp_packet = (struct batadv_icmp_packet *)skb->data;
256
257
258 if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) {
259 pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n",
260 icmp_packet->orig, icmp_packet->dst);
261 goto out;
262 }
263
264 primary_if = batadv_primary_if_get_selected(bat_priv);
265 if (!primary_if)
266 goto out;
267
268
269 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig);
270 if (!orig_node)
271 goto out;
272
273
274 if (skb_cow(skb, ETH_HLEN) < 0)
275 goto out;
276
277 icmp_packet = (struct batadv_icmp_packet *)skb->data;
278
279 ether_addr_copy(icmp_packet->dst, icmp_packet->orig);
280 ether_addr_copy(icmp_packet->orig, primary_if->net_dev->dev_addr);
281 icmp_packet->msg_type = BATADV_TTL_EXCEEDED;
282 icmp_packet->ttl = BATADV_TTL;
283
284 if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
285 ret = NET_RX_SUCCESS;
286
287out:
288 if (primary_if)
289 batadv_hardif_free_ref(primary_if);
290 if (orig_node)
291 batadv_orig_node_free_ref(orig_node);
292 return ret;
293}
294
295
296int batadv_recv_icmp_packet(struct sk_buff *skb,
297 struct batadv_hard_iface *recv_if)
298{
299 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
300 struct batadv_icmp_header *icmph;
301 struct batadv_icmp_packet_rr *icmp_packet_rr;
302 struct ethhdr *ethhdr;
303 struct batadv_orig_node *orig_node = NULL;
304 int hdr_size = sizeof(struct batadv_icmp_header);
305 int ret = NET_RX_DROP;
306
307
308 if (unlikely(!pskb_may_pull(skb, hdr_size)))
309 goto out;
310
311 ethhdr = eth_hdr(skb);
312
313
314 if (is_broadcast_ether_addr(ethhdr->h_dest))
315 goto out;
316
317
318 if (is_broadcast_ether_addr(ethhdr->h_source))
319 goto out;
320
321
322 if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
323 goto out;
324
325 icmph = (struct batadv_icmp_header *)skb->data;
326
327
328 if ((icmph->msg_type == BATADV_ECHO_REPLY ||
329 icmph->msg_type == BATADV_ECHO_REQUEST) &&
330 (skb->len >= sizeof(struct batadv_icmp_packet_rr))) {
331 if (skb_linearize(skb) < 0)
332 goto out;
333
334
335 if (skb_cow(skb, ETH_HLEN) < 0)
336 goto out;
337
338 icmph = (struct batadv_icmp_header *)skb->data;
339 icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmph;
340 if (icmp_packet_rr->rr_cur >= BATADV_RR_LEN)
341 goto out;
342
343 ether_addr_copy(icmp_packet_rr->rr[icmp_packet_rr->rr_cur],
344 ethhdr->h_dest);
345 icmp_packet_rr->rr_cur++;
346 }
347
348
349 if (batadv_is_my_mac(bat_priv, icmph->dst))
350 return batadv_recv_my_icmp_packet(bat_priv, skb);
351
352
353 if (icmph->ttl < 2)
354 return batadv_recv_icmp_ttl_exceeded(bat_priv, skb);
355
356
357 orig_node = batadv_orig_hash_find(bat_priv, icmph->dst);
358 if (!orig_node)
359 goto out;
360
361
362 if (skb_cow(skb, ETH_HLEN) < 0)
363 goto out;
364
365 icmph = (struct batadv_icmp_header *)skb->data;
366
367
368 icmph->ttl--;
369
370
371 if (batadv_send_skb_to_orig(skb, orig_node, recv_if) != NET_XMIT_DROP)
372 ret = NET_RX_SUCCESS;
373
374out:
375 if (orig_node)
376 batadv_orig_node_free_ref(orig_node);
377 return ret;
378}
379
380
381
382
383
384
385
386
387
388
389
390
391static int batadv_check_unicast_packet(struct batadv_priv *bat_priv,
392 struct sk_buff *skb, int hdr_size)
393{
394 struct ethhdr *ethhdr;
395
396
397 if (unlikely(!pskb_may_pull(skb, hdr_size)))
398 return -ENODATA;
399
400 ethhdr = eth_hdr(skb);
401
402
403 if (is_broadcast_ether_addr(ethhdr->h_dest))
404 return -EBADR;
405
406
407 if (is_broadcast_ether_addr(ethhdr->h_source))
408 return -EBADR;
409
410
411 if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
412 return -EREMOTE;
413
414 return 0;
415}
416
417
418
419
420
421
422
423
424
425
426struct batadv_neigh_node *
427batadv_find_router(struct batadv_priv *bat_priv,
428 struct batadv_orig_node *orig_node,
429 struct batadv_hard_iface *recv_if)
430{
431 struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
432 struct batadv_neigh_node *first_candidate_router = NULL;
433 struct batadv_neigh_node *next_candidate_router = NULL;
434 struct batadv_neigh_node *router, *cand_router = NULL;
435 struct batadv_neigh_node *last_cand_router = NULL;
436 struct batadv_orig_ifinfo *cand, *first_candidate = NULL;
437 struct batadv_orig_ifinfo *next_candidate = NULL;
438 struct batadv_orig_ifinfo *last_candidate;
439 bool last_candidate_found = false;
440
441 if (!orig_node)
442 return NULL;
443
444 router = batadv_orig_router_get(orig_node, recv_if);
445
446
447
448
449 if (recv_if == BATADV_IF_DEFAULT || !atomic_read(&bat_priv->bonding) ||
450 !router)
451 return router;
452
453
454
455
456
457
458
459
460
461 rcu_read_lock();
462 last_candidate = orig_node->last_bonding_candidate;
463 if (last_candidate)
464 last_cand_router = rcu_dereference(last_candidate->router);
465
466 hlist_for_each_entry_rcu(cand, &orig_node->ifinfo_list, list) {
467
468 if (!atomic_inc_not_zero(&cand->refcount))
469 continue;
470
471 cand_router = rcu_dereference(cand->router);
472 if (!cand_router)
473 goto next;
474
475 if (!atomic_inc_not_zero(&cand_router->refcount)) {
476 cand_router = NULL;
477 goto next;
478 }
479
480
481
482
483 if (!bao->bat_neigh_is_equiv_or_better(cand_router,
484 cand->if_outgoing,
485 router, recv_if))
486 goto next;
487
488
489 if (last_cand_router == cand_router)
490 goto next;
491
492
493 if (!first_candidate) {
494 atomic_inc(&cand_router->refcount);
495 atomic_inc(&cand->refcount);
496 first_candidate = cand;
497 first_candidate_router = cand_router;
498 }
499
500
501
502
503
504 if (!last_candidate || last_candidate_found) {
505 next_candidate = cand;
506 next_candidate_router = cand_router;
507 break;
508 }
509
510 if (last_candidate == cand)
511 last_candidate_found = true;
512next:
513
514 if (cand_router) {
515 batadv_neigh_node_free_ref(cand_router);
516 cand_router = NULL;
517 }
518 batadv_orig_ifinfo_free_ref(cand);
519 }
520 rcu_read_unlock();
521
522
523 if (orig_node->last_bonding_candidate)
524 batadv_orig_ifinfo_free_ref(orig_node->last_bonding_candidate);
525
526
527
528
529
530
531 if (next_candidate) {
532 batadv_neigh_node_free_ref(router);
533
534
535 if (first_candidate) {
536 batadv_neigh_node_free_ref(first_candidate_router);
537 batadv_orig_ifinfo_free_ref(first_candidate);
538 }
539 router = next_candidate_router;
540 orig_node->last_bonding_candidate = next_candidate;
541 } else if (first_candidate) {
542 batadv_neigh_node_free_ref(router);
543
544
545 router = first_candidate_router;
546 orig_node->last_bonding_candidate = first_candidate;
547 } else {
548 orig_node->last_bonding_candidate = NULL;
549 }
550
551 return router;
552}
553
554static int batadv_route_unicast_packet(struct sk_buff *skb,
555 struct batadv_hard_iface *recv_if)
556{
557 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
558 struct batadv_orig_node *orig_node = NULL;
559 struct batadv_unicast_packet *unicast_packet;
560 struct ethhdr *ethhdr = eth_hdr(skb);
561 int res, hdr_len, ret = NET_RX_DROP;
562
563 unicast_packet = (struct batadv_unicast_packet *)skb->data;
564
565
566 if (unicast_packet->ttl < 2) {
567 pr_debug("Warning - can't forward unicast packet from %pM to %pM: ttl exceeded\n",
568 ethhdr->h_source, unicast_packet->dest);
569 goto out;
570 }
571
572
573 orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->dest);
574
575 if (!orig_node)
576 goto out;
577
578
579 if (skb_cow(skb, ETH_HLEN) < 0)
580 goto out;
581
582
583 unicast_packet = (struct batadv_unicast_packet *)skb->data;
584 unicast_packet->ttl--;
585
586 switch (unicast_packet->packet_type) {
587 case BATADV_UNICAST_4ADDR:
588 hdr_len = sizeof(struct batadv_unicast_4addr_packet);
589 break;
590 case BATADV_UNICAST:
591 hdr_len = sizeof(struct batadv_unicast_packet);
592 break;
593 default:
594
595 hdr_len = -1;
596 break;
597 }
598
599 if (hdr_len > 0)
600 batadv_skb_set_priority(skb, hdr_len);
601
602 res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
603
604
605 if (res == NET_XMIT_SUCCESS) {
606
607 batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
608 batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
609 skb->len + ETH_HLEN);
610
611 ret = NET_RX_SUCCESS;
612 } else if (res == NET_XMIT_POLICED) {
613
614 ret = NET_RX_SUCCESS;
615 }
616
617out:
618 if (orig_node)
619 batadv_orig_node_free_ref(orig_node);
620 return ret;
621}
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636static bool
637batadv_reroute_unicast_packet(struct batadv_priv *bat_priv,
638 struct batadv_unicast_packet *unicast_packet,
639 uint8_t *dst_addr, unsigned short vid)
640{
641 struct batadv_orig_node *orig_node = NULL;
642 struct batadv_hard_iface *primary_if = NULL;
643 bool ret = false;
644 uint8_t *orig_addr, orig_ttvn;
645
646 if (batadv_is_my_client(bat_priv, dst_addr, vid)) {
647 primary_if = batadv_primary_if_get_selected(bat_priv);
648 if (!primary_if)
649 goto out;
650 orig_addr = primary_if->net_dev->dev_addr;
651 orig_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
652 } else {
653 orig_node = batadv_transtable_search(bat_priv, NULL, dst_addr,
654 vid);
655 if (!orig_node)
656 goto out;
657
658 if (batadv_compare_eth(orig_node->orig, unicast_packet->dest))
659 goto out;
660
661 orig_addr = orig_node->orig;
662 orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
663 }
664
665
666 ether_addr_copy(unicast_packet->dest, orig_addr);
667 unicast_packet->ttvn = orig_ttvn;
668
669 ret = true;
670out:
671 if (primary_if)
672 batadv_hardif_free_ref(primary_if);
673 if (orig_node)
674 batadv_orig_node_free_ref(orig_node);
675
676 return ret;
677}
678
679static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
680 struct sk_buff *skb, int hdr_len) {
681 struct batadv_unicast_packet *unicast_packet;
682 struct batadv_hard_iface *primary_if;
683 struct batadv_orig_node *orig_node;
684 uint8_t curr_ttvn, old_ttvn;
685 struct ethhdr *ethhdr;
686 unsigned short vid;
687 int is_old_ttvn;
688
689
690 if (!pskb_may_pull(skb, hdr_len + ETH_HLEN))
691 return 0;
692
693
694 if (skb_cow(skb, sizeof(*unicast_packet)) < 0)
695 return 0;
696
697 unicast_packet = (struct batadv_unicast_packet *)skb->data;
698 vid = batadv_get_vid(skb, hdr_len);
699 ethhdr = (struct ethhdr *)(skb->data + hdr_len);
700
701
702
703
704
705
706 if (batadv_tt_local_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) {
707 if (batadv_reroute_unicast_packet(bat_priv, unicast_packet,
708 ethhdr->h_dest, vid))
709 batadv_dbg_ratelimited(BATADV_DBG_TT,
710 bat_priv,
711 "Rerouting unicast packet to %pM (dst=%pM): Local Roaming\n",
712 unicast_packet->dest,
713 ethhdr->h_dest);
714
715
716
717
718
719 return 1;
720 }
721
722
723
724
725
726 curr_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
727 if (!batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
728 orig_node = batadv_orig_hash_find(bat_priv,
729 unicast_packet->dest);
730
731
732
733
734 if (!orig_node)
735 return 0;
736
737 curr_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
738 batadv_orig_node_free_ref(orig_node);
739 }
740
741
742
743
744 is_old_ttvn = batadv_seq_before(unicast_packet->ttvn, curr_ttvn);
745 if (!is_old_ttvn)
746 return 1;
747
748 old_ttvn = unicast_packet->ttvn;
749
750
751
752
753 if (batadv_reroute_unicast_packet(bat_priv, unicast_packet,
754 ethhdr->h_dest, vid)) {
755 batadv_dbg_ratelimited(BATADV_DBG_TT, bat_priv,
756 "Rerouting unicast packet to %pM (dst=%pM): TTVN mismatch old_ttvn=%u new_ttvn=%u\n",
757 unicast_packet->dest, ethhdr->h_dest,
758 old_ttvn, curr_ttvn);
759 return 1;
760 }
761
762
763
764
765
766 if (!batadv_is_my_client(bat_priv, ethhdr->h_dest, vid))
767 return 0;
768
769
770
771
772 primary_if = batadv_primary_if_get_selected(bat_priv);
773 if (!primary_if)
774 return 0;
775
776 ether_addr_copy(unicast_packet->dest, primary_if->net_dev->dev_addr);
777
778 batadv_hardif_free_ref(primary_if);
779
780 unicast_packet->ttvn = curr_ttvn;
781
782 return 1;
783}
784
785
786
787
788
789
790
791
792
793
794int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
795 struct batadv_hard_iface *recv_if)
796{
797 struct batadv_unicast_packet *unicast_packet;
798 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
799 int check, hdr_size = sizeof(*unicast_packet);
800
801 check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
802 if (check < 0)
803 return NET_RX_DROP;
804
805
806 unicast_packet = (struct batadv_unicast_packet *)skb->data;
807 if (batadv_is_my_mac(bat_priv, unicast_packet->dest))
808 return NET_RX_DROP;
809
810 return batadv_route_unicast_packet(skb, recv_if);
811}
812
813int batadv_recv_unicast_packet(struct sk_buff *skb,
814 struct batadv_hard_iface *recv_if)
815{
816 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
817 struct batadv_unicast_packet *unicast_packet;
818 struct batadv_unicast_4addr_packet *unicast_4addr_packet;
819 uint8_t *orig_addr;
820 struct batadv_orig_node *orig_node = NULL;
821 int check, hdr_size = sizeof(*unicast_packet);
822 bool is4addr;
823
824 unicast_packet = (struct batadv_unicast_packet *)skb->data;
825 unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
826
827 is4addr = unicast_packet->packet_type == BATADV_UNICAST_4ADDR;
828
829 if (is4addr)
830 hdr_size = sizeof(*unicast_4addr_packet);
831
832
833 check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
834
835
836
837
838 if (check == -EREMOTE)
839 batadv_nc_skb_store_sniffed_unicast(bat_priv, skb);
840
841 if (check < 0)
842 return NET_RX_DROP;
843 if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size))
844 return NET_RX_DROP;
845
846
847 if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
848 if (is4addr) {
849 batadv_dat_inc_counter(bat_priv,
850 unicast_4addr_packet->subtype);
851 orig_addr = unicast_4addr_packet->src;
852 orig_node = batadv_orig_hash_find(bat_priv, orig_addr);
853 }
854
855 if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb,
856 hdr_size))
857 goto rx_success;
858 if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb,
859 hdr_size))
860 goto rx_success;
861
862 batadv_interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size,
863 orig_node);
864
865rx_success:
866 if (orig_node)
867 batadv_orig_node_free_ref(orig_node);
868
869 return NET_RX_SUCCESS;
870 }
871
872 return batadv_route_unicast_packet(skb, recv_if);
873}
874
875
876
877
878
879
880
881
882
883
884int batadv_recv_unicast_tvlv(struct sk_buff *skb,
885 struct batadv_hard_iface *recv_if)
886{
887 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
888 struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
889 unsigned char *tvlv_buff;
890 uint16_t tvlv_buff_len;
891 int hdr_size = sizeof(*unicast_tvlv_packet);
892 int ret = NET_RX_DROP;
893
894 if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
895 return NET_RX_DROP;
896
897
898 if (skb_cow(skb, hdr_size) < 0)
899 return NET_RX_DROP;
900
901
902 if (skb_linearize(skb) < 0)
903 return NET_RX_DROP;
904
905 unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)skb->data;
906
907 tvlv_buff = (unsigned char *)(skb->data + hdr_size);
908 tvlv_buff_len = ntohs(unicast_tvlv_packet->tvlv_len);
909
910 if (tvlv_buff_len > skb->len - hdr_size)
911 return NET_RX_DROP;
912
913 ret = batadv_tvlv_containers_process(bat_priv, false, NULL,
914 unicast_tvlv_packet->src,
915 unicast_tvlv_packet->dst,
916 tvlv_buff, tvlv_buff_len);
917
918 if (ret != NET_RX_SUCCESS)
919 ret = batadv_route_unicast_packet(skb, recv_if);
920 else
921 consume_skb(skb);
922
923 return ret;
924}
925
926
927
928
929
930
931
932
933
934
935
936
937int batadv_recv_frag_packet(struct sk_buff *skb,
938 struct batadv_hard_iface *recv_if)
939{
940 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
941 struct batadv_orig_node *orig_node_src = NULL;
942 struct batadv_frag_packet *frag_packet;
943 int ret = NET_RX_DROP;
944
945 if (batadv_check_unicast_packet(bat_priv, skb,
946 sizeof(*frag_packet)) < 0)
947 goto out;
948
949 frag_packet = (struct batadv_frag_packet *)skb->data;
950 orig_node_src = batadv_orig_hash_find(bat_priv, frag_packet->orig);
951 if (!orig_node_src)
952 goto out;
953
954
955 if (!batadv_is_my_mac(bat_priv, frag_packet->dest) &&
956 batadv_frag_skb_fwd(skb, recv_if, orig_node_src)) {
957 ret = NET_RX_SUCCESS;
958 goto out;
959 }
960
961 batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_RX);
962 batadv_add_counter(bat_priv, BATADV_CNT_FRAG_RX_BYTES, skb->len);
963
964
965 if (!batadv_frag_skb_buffer(&skb, orig_node_src))
966 goto out;
967
968
969
970
971 if (skb)
972 batadv_batman_skb_recv(skb, recv_if->net_dev,
973 &recv_if->batman_adv_ptype, NULL);
974
975 ret = NET_RX_SUCCESS;
976
977out:
978 if (orig_node_src)
979 batadv_orig_node_free_ref(orig_node_src);
980
981 return ret;
982}
983
984int batadv_recv_bcast_packet(struct sk_buff *skb,
985 struct batadv_hard_iface *recv_if)
986{
987 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
988 struct batadv_orig_node *orig_node = NULL;
989 struct batadv_bcast_packet *bcast_packet;
990 struct ethhdr *ethhdr;
991 int hdr_size = sizeof(*bcast_packet);
992 int ret = NET_RX_DROP;
993 int32_t seq_diff;
994 uint32_t seqno;
995
996
997 if (unlikely(!pskb_may_pull(skb, hdr_size)))
998 goto out;
999
1000 ethhdr = eth_hdr(skb);
1001
1002
1003 if (!is_broadcast_ether_addr(ethhdr->h_dest))
1004 goto out;
1005
1006
1007 if (is_broadcast_ether_addr(ethhdr->h_source))
1008 goto out;
1009
1010
1011 if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
1012 goto out;
1013
1014 bcast_packet = (struct batadv_bcast_packet *)skb->data;
1015
1016
1017 if (batadv_is_my_mac(bat_priv, bcast_packet->orig))
1018 goto out;
1019
1020 if (bcast_packet->ttl < 2)
1021 goto out;
1022
1023 orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->orig);
1024
1025 if (!orig_node)
1026 goto out;
1027
1028 spin_lock_bh(&orig_node->bcast_seqno_lock);
1029
1030 seqno = ntohl(bcast_packet->seqno);
1031
1032 if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno,
1033 seqno))
1034 goto spin_unlock;
1035
1036 seq_diff = seqno - orig_node->last_bcast_seqno;
1037
1038
1039 if (batadv_window_protected(bat_priv, seq_diff,
1040 &orig_node->bcast_seqno_reset))
1041 goto spin_unlock;
1042
1043
1044
1045
1046 if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1))
1047 orig_node->last_bcast_seqno = seqno;
1048
1049 spin_unlock_bh(&orig_node->bcast_seqno_lock);
1050
1051
1052 if (batadv_bla_check_bcast_duplist(bat_priv, skb))
1053 goto out;
1054
1055 batadv_skb_set_priority(skb, sizeof(struct batadv_bcast_packet));
1056
1057
1058 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
1059
1060
1061
1062
1063 if (batadv_bla_is_backbone_gw(skb, orig_node, hdr_size))
1064 goto out;
1065
1066 if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size))
1067 goto rx_success;
1068 if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size))
1069 goto rx_success;
1070
1071
1072 batadv_interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size,
1073 orig_node);
1074
1075rx_success:
1076 ret = NET_RX_SUCCESS;
1077 goto out;
1078
1079spin_unlock:
1080 spin_unlock_bh(&orig_node->bcast_seqno_lock);
1081out:
1082 if (orig_node)
1083 batadv_orig_node_free_ref(orig_node);
1084 return ret;
1085}
1086