batman-adv: Remove old fragmentation code
[deliverable/linux.git] / net / batman-adv / routing.c
CommitLineData
0b873931 1/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
c6c8fea2
SE
2 *
3 * Marek Lindner, Simon Wunderlich
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
c6c8fea2
SE
18 */
19
20#include "main.h"
21#include "routing.h"
22#include "send.h"
c6c8fea2
SE
23#include "soft-interface.h"
24#include "hard-interface.h"
25#include "icmp_socket.h"
26#include "translation-table.h"
27#include "originator.h"
23721387 28#include "bridge_loop_avoidance.h"
c384ea3e 29#include "distributed-arp-table.h"
95332477 30#include "network-coding.h"
c6c8fea2 31
63b01037 32static int batadv_route_unicast_packet(struct sk_buff *skb,
56303d34 33 struct batadv_hard_iface *recv_if);
a7f6ee94 34
56303d34
SE
35static void _batadv_update_route(struct batadv_priv *bat_priv,
36 struct batadv_orig_node *orig_node,
37 struct batadv_neigh_node *neigh_node)
c6c8fea2 38{
56303d34 39 struct batadv_neigh_node *curr_router;
e1a5382f 40
7d211efc 41 curr_router = batadv_orig_node_get_router(orig_node);
a8e7f4bc 42
c6c8fea2 43 /* route deleted */
e1a5382f 44 if ((curr_router) && (!neigh_node)) {
39c75a51
SE
45 batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
46 "Deleting route towards: %pM\n", orig_node->orig);
08c36d3e
SE
47 batadv_tt_global_del_orig(bat_priv, orig_node,
48 "Deleted route towards originator");
c6c8fea2 49
e1a5382f
LL
50 /* route added */
51 } else if ((!curr_router) && (neigh_node)) {
39c75a51 52 batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
1eda58bf
SE
53 "Adding route towards: %pM (via %pM)\n",
54 orig_node->orig, neigh_node->addr);
e1a5382f 55 /* route changed */
bb899b89 56 } else if (neigh_node && curr_router) {
39c75a51 57 batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
1eda58bf
SE
58 "Changing route towards: %pM (now via %pM - was via %pM)\n",
59 orig_node->orig, neigh_node->addr,
60 curr_router->addr);
c6c8fea2
SE
61 }
62
e1a5382f 63 if (curr_router)
7d211efc 64 batadv_neigh_node_free_ref(curr_router);
e1a5382f
LL
65
66 /* increase refcount of new best neighbor */
44524fcd
ML
67 if (neigh_node && !atomic_inc_not_zero(&neigh_node->refcount))
68 neigh_node = NULL;
e1a5382f
LL
69
70 spin_lock_bh(&orig_node->neigh_list_lock);
71 rcu_assign_pointer(orig_node->router, neigh_node);
72 spin_unlock_bh(&orig_node->neigh_list_lock);
73
74 /* decrease refcount of previous best neighbor */
75 if (curr_router)
7d211efc 76 batadv_neigh_node_free_ref(curr_router);
c6c8fea2
SE
77}
78
56303d34
SE
79void batadv_update_route(struct batadv_priv *bat_priv,
80 struct batadv_orig_node *orig_node,
81 struct batadv_neigh_node *neigh_node)
c6c8fea2 82{
56303d34 83 struct batadv_neigh_node *router = NULL;
c6c8fea2
SE
84
85 if (!orig_node)
e1a5382f
LL
86 goto out;
87
7d211efc 88 router = batadv_orig_node_get_router(orig_node);
c6c8fea2 89
e1a5382f 90 if (router != neigh_node)
63b01037 91 _batadv_update_route(bat_priv, orig_node, neigh_node);
e1a5382f
LL
92
93out:
94 if (router)
7d211efc 95 batadv_neigh_node_free_ref(router);
c6c8fea2
SE
96}
97
a4c135c5 98/* caller must hold the neigh_list_lock */
56303d34
SE
99void batadv_bonding_candidate_del(struct batadv_orig_node *orig_node,
100 struct batadv_neigh_node *neigh_node)
a4c135c5
SW
101{
102 /* this neighbor is not part of our candidate list */
103 if (list_empty(&neigh_node->bonding_list))
104 goto out;
105
106 list_del_rcu(&neigh_node->bonding_list);
a4c135c5 107 INIT_LIST_HEAD(&neigh_node->bonding_list);
7d211efc 108 batadv_neigh_node_free_ref(neigh_node);
a4c135c5
SW
109 atomic_dec(&orig_node->bond_candidates);
110
111out:
112 return;
113}
114
56303d34
SE
115void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node,
116 struct batadv_neigh_node *neigh_node)
a4c135c5 117{
56303d34 118 struct batadv_neigh_node *tmp_neigh_node, *router = NULL;
e1a5382f 119 uint8_t interference_candidate = 0;
a4c135c5
SW
120
121 spin_lock_bh(&orig_node->neigh_list_lock);
122
123 /* only consider if it has the same primary address ... */
1eda58bf
SE
124 if (!batadv_compare_eth(orig_node->orig,
125 neigh_node->orig_node->primary_addr))
a4c135c5
SW
126 goto candidate_del;
127
7d211efc 128 router = batadv_orig_node_get_router(orig_node);
e1a5382f 129 if (!router)
a4c135c5
SW
130 goto candidate_del;
131
a4c135c5 132 /* ... and is good enough to be considered */
42d0b044 133 if (neigh_node->tq_avg < router->tq_avg - BATADV_BONDING_TQ_THRESHOLD)
a4c135c5
SW
134 goto candidate_del;
135
9cfc7bd6 136 /* check if we have another candidate with the same mac address or
a4c135c5
SW
137 * interface. If we do, we won't select this candidate because of
138 * possible interference.
139 */
b67bfe0d 140 hlist_for_each_entry_rcu(tmp_neigh_node,
a4c135c5 141 &orig_node->neigh_list, list) {
a4c135c5
SW
142 if (tmp_neigh_node == neigh_node)
143 continue;
144
145 /* we only care if the other candidate is even
9cfc7bd6
SE
146 * considered as candidate.
147 */
a4c135c5
SW
148 if (list_empty(&tmp_neigh_node->bonding_list))
149 continue;
150
151 if ((neigh_node->if_incoming == tmp_neigh_node->if_incoming) ||
1eda58bf
SE
152 (batadv_compare_eth(neigh_node->addr,
153 tmp_neigh_node->addr))) {
a4c135c5
SW
154 interference_candidate = 1;
155 break;
156 }
157 }
158
159 /* don't care further if it is an interference candidate */
160 if (interference_candidate)
161 goto candidate_del;
162
163 /* this neighbor already is part of our candidate list */
164 if (!list_empty(&neigh_node->bonding_list))
165 goto out;
166
44524fcd
ML
167 if (!atomic_inc_not_zero(&neigh_node->refcount))
168 goto out;
169
a4c135c5 170 list_add_rcu(&neigh_node->bonding_list, &orig_node->bond_list);
a4c135c5
SW
171 atomic_inc(&orig_node->bond_candidates);
172 goto out;
173
174candidate_del:
30d3c511 175 batadv_bonding_candidate_del(orig_node, neigh_node);
a4c135c5
SW
176
177out:
178 spin_unlock_bh(&orig_node->neigh_list_lock);
e1a5382f
LL
179
180 if (router)
7d211efc 181 batadv_neigh_node_free_ref(router);
a4c135c5
SW
182}
183
184/* copy primary address for bonding */
30d3c511 185void
56303d34
SE
186batadv_bonding_save_primary(const struct batadv_orig_node *orig_node,
187 struct batadv_orig_node *orig_neigh_node,
96412690 188 const struct batadv_ogm_packet *batman_ogm_packet)
a4c135c5 189{
acd34afa 190 if (!(batman_ogm_packet->flags & BATADV_PRIMARIES_FIRST_HOP))
a4c135c5
SW
191 return;
192
193 memcpy(orig_neigh_node->primary_addr, orig_node->orig, ETH_ALEN);
194}
195
c6c8fea2
SE
196/* checks whether the host restarted and is in the protection time.
197 * returns:
198 * 0 if the packet is to be accepted
199 * 1 if the packet is to be ignored.
200 */
56303d34 201int batadv_window_protected(struct batadv_priv *bat_priv, int32_t seq_num_diff,
30d3c511 202 unsigned long *last_reset)
c6c8fea2 203{
42d0b044
SE
204 if (seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE ||
205 seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE) {
206 if (!batadv_has_timed_out(*last_reset,
207 BATADV_RESET_PROTECTION_MS))
c6c8fea2 208 return 1;
8c7bf248
ML
209
210 *last_reset = jiffies;
39c75a51 211 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
1eda58bf 212 "old packet received, start protection\n");
c6c8fea2 213 }
8c7bf248 214
c6c8fea2
SE
215 return 0;
216}
217
30d3c511 218bool batadv_check_management_packet(struct sk_buff *skb,
56303d34 219 struct batadv_hard_iface *hard_iface,
30d3c511 220 int header_len)
c6c8fea2 221{
c6c8fea2
SE
222 struct ethhdr *ethhdr;
223
224 /* drop packet if it has not necessary minimum size */
c3e29312
ML
225 if (unlikely(!pskb_may_pull(skb, header_len)))
226 return false;
c6c8fea2 227
7ed4be95 228 ethhdr = eth_hdr(skb);
c6c8fea2
SE
229
230 /* packet with broadcast indication but unicast recipient */
231 if (!is_broadcast_ether_addr(ethhdr->h_dest))
c3e29312 232 return false;
c6c8fea2
SE
233
234 /* packet with broadcast sender address */
235 if (is_broadcast_ether_addr(ethhdr->h_source))
c3e29312 236 return false;
c6c8fea2
SE
237
238 /* create a copy of the skb, if needed, to modify it. */
239 if (skb_cow(skb, 0) < 0)
c3e29312 240 return false;
c6c8fea2
SE
241
242 /* keep skb linear */
243 if (skb_linearize(skb) < 0)
c3e29312 244 return false;
c6c8fea2 245
c3e29312 246 return true;
c6c8fea2
SE
247}
248
56303d34 249static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
63b01037 250 struct sk_buff *skb, size_t icmp_len)
c6c8fea2 251{
56303d34
SE
252 struct batadv_hard_iface *primary_if = NULL;
253 struct batadv_orig_node *orig_node = NULL;
96412690 254 struct batadv_icmp_packet_rr *icmp_packet;
44524fcd 255 int ret = NET_RX_DROP;
c6c8fea2 256
96412690 257 icmp_packet = (struct batadv_icmp_packet_rr *)skb->data;
c6c8fea2
SE
258
259 /* add data to device queue */
acd34afa 260 if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) {
9039dc7e 261 batadv_socket_receive_packet(icmp_packet, icmp_len);
44524fcd 262 goto out;
c6c8fea2
SE
263 }
264
e5d89254 265 primary_if = batadv_primary_if_get_selected(bat_priv);
32ae9b22 266 if (!primary_if)
44524fcd 267 goto out;
c6c8fea2
SE
268
269 /* answer echo request (ping) */
270 /* get routing information */
da641193 271 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig);
44524fcd 272 if (!orig_node)
e1a5382f 273 goto out;
c6c8fea2 274
44524fcd 275 /* create a copy of the skb, if needed, to modify it. */
0d125074 276 if (skb_cow(skb, ETH_HLEN) < 0)
44524fcd
ML
277 goto out;
278
96412690 279 icmp_packet = (struct batadv_icmp_packet_rr *)skb->data;
44524fcd
ML
280
281 memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
32ae9b22 282 memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
acd34afa 283 icmp_packet->msg_type = BATADV_ECHO_REPLY;
42d0b044 284 icmp_packet->header.ttl = BATADV_TTL;
44524fcd 285
e91ecfc6 286 if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
bb351ba0 287 ret = NET_RX_SUCCESS;
c6c8fea2 288
44524fcd 289out:
32ae9b22 290 if (primary_if)
e5d89254 291 batadv_hardif_free_ref(primary_if);
44524fcd 292 if (orig_node)
7d211efc 293 batadv_orig_node_free_ref(orig_node);
c6c8fea2
SE
294 return ret;
295}
296
56303d34 297static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
63b01037 298 struct sk_buff *skb)
c6c8fea2 299{
56303d34
SE
300 struct batadv_hard_iface *primary_if = NULL;
301 struct batadv_orig_node *orig_node = NULL;
96412690 302 struct batadv_icmp_packet *icmp_packet;
44524fcd 303 int ret = NET_RX_DROP;
c6c8fea2 304
96412690 305 icmp_packet = (struct batadv_icmp_packet *)skb->data;
c6c8fea2
SE
306
307 /* send TTL exceeded if packet is an echo request (traceroute) */
acd34afa 308 if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) {
86ceb360
SE
309 pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n",
310 icmp_packet->orig, icmp_packet->dst);
44524fcd 311 goto out;
c6c8fea2
SE
312 }
313
e5d89254 314 primary_if = batadv_primary_if_get_selected(bat_priv);
32ae9b22 315 if (!primary_if)
44524fcd 316 goto out;
c6c8fea2
SE
317
318 /* get routing information */
da641193 319 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig);
44524fcd 320 if (!orig_node)
e1a5382f 321 goto out;
c6c8fea2 322
44524fcd 323 /* create a copy of the skb, if needed, to modify it. */
0d125074 324 if (skb_cow(skb, ETH_HLEN) < 0)
44524fcd 325 goto out;
c6c8fea2 326
96412690 327 icmp_packet = (struct batadv_icmp_packet *)skb->data;
c6c8fea2 328
44524fcd 329 memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
32ae9b22 330 memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
acd34afa 331 icmp_packet->msg_type = BATADV_TTL_EXCEEDED;
42d0b044 332 icmp_packet->header.ttl = BATADV_TTL;
44524fcd 333
e91ecfc6 334 if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
bb351ba0 335 ret = NET_RX_SUCCESS;
c6c8fea2 336
44524fcd 337out:
32ae9b22 338 if (primary_if)
e5d89254 339 batadv_hardif_free_ref(primary_if);
44524fcd 340 if (orig_node)
7d211efc 341 batadv_orig_node_free_ref(orig_node);
c6c8fea2
SE
342 return ret;
343}
344
345
56303d34
SE
346int batadv_recv_icmp_packet(struct sk_buff *skb,
347 struct batadv_hard_iface *recv_if)
c6c8fea2 348{
56303d34 349 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
96412690 350 struct batadv_icmp_packet_rr *icmp_packet;
c6c8fea2 351 struct ethhdr *ethhdr;
56303d34 352 struct batadv_orig_node *orig_node = NULL;
96412690 353 int hdr_size = sizeof(struct batadv_icmp_packet);
44524fcd 354 int ret = NET_RX_DROP;
c6c8fea2 355
9cfc7bd6 356 /* we truncate all incoming icmp packets if they don't match our size */
96412690
SE
357 if (skb->len >= sizeof(struct batadv_icmp_packet_rr))
358 hdr_size = sizeof(struct batadv_icmp_packet_rr);
c6c8fea2
SE
359
360 /* drop packet if it has not necessary minimum size */
361 if (unlikely(!pskb_may_pull(skb, hdr_size)))
44524fcd 362 goto out;
c6c8fea2 363
7ed4be95 364 ethhdr = eth_hdr(skb);
c6c8fea2
SE
365
366 /* packet with unicast indication but broadcast recipient */
367 if (is_broadcast_ether_addr(ethhdr->h_dest))
44524fcd 368 goto out;
c6c8fea2
SE
369
370 /* packet with broadcast sender address */
371 if (is_broadcast_ether_addr(ethhdr->h_source))
44524fcd 372 goto out;
c6c8fea2
SE
373
374 /* not for me */
fe8a93b9 375 if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
44524fcd 376 goto out;
c6c8fea2 377
96412690 378 icmp_packet = (struct batadv_icmp_packet_rr *)skb->data;
c6c8fea2
SE
379
380 /* add record route information if not full */
97dbc03b
SW
381 if ((icmp_packet->msg_type == BATADV_ECHO_REPLY ||
382 icmp_packet->msg_type == BATADV_ECHO_REQUEST) &&
383 (hdr_size == sizeof(struct batadv_icmp_packet_rr)) &&
7e071c79 384 (icmp_packet->rr_cur < BATADV_RR_LEN)) {
c6c8fea2 385 memcpy(&(icmp_packet->rr[icmp_packet->rr_cur]),
7c64fd98 386 ethhdr->h_dest, ETH_ALEN);
c6c8fea2
SE
387 icmp_packet->rr_cur++;
388 }
389
390 /* packet for me */
fe8a93b9 391 if (batadv_is_my_mac(bat_priv, icmp_packet->dst))
63b01037 392 return batadv_recv_my_icmp_packet(bat_priv, skb, hdr_size);
c6c8fea2
SE
393
394 /* TTL exceeded */
76543d14 395 if (icmp_packet->header.ttl < 2)
63b01037 396 return batadv_recv_icmp_ttl_exceeded(bat_priv, skb);
c6c8fea2 397
c6c8fea2 398 /* get routing information */
da641193 399 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->dst);
44524fcd 400 if (!orig_node)
e1a5382f 401 goto out;
c6c8fea2 402
44524fcd 403 /* create a copy of the skb, if needed, to modify it. */
0d125074 404 if (skb_cow(skb, ETH_HLEN) < 0)
44524fcd 405 goto out;
c6c8fea2 406
96412690 407 icmp_packet = (struct batadv_icmp_packet_rr *)skb->data;
c6c8fea2 408
44524fcd 409 /* decrement ttl */
76543d14 410 icmp_packet->header.ttl--;
44524fcd
ML
411
412 /* route it */
e91ecfc6 413 if (batadv_send_skb_to_orig(skb, orig_node, recv_if) != NET_XMIT_DROP)
bb351ba0 414 ret = NET_RX_SUCCESS;
c6c8fea2 415
44524fcd 416out:
44524fcd 417 if (orig_node)
7d211efc 418 batadv_orig_node_free_ref(orig_node);
c6c8fea2
SE
419 return ret;
420}
421
55158629
LL
422/* In the bonding case, send the packets in a round
423 * robin fashion over the remaining interfaces.
424 *
425 * This method rotates the bonding list and increases the
9cfc7bd6
SE
426 * returned router's refcount.
427 */
56303d34
SE
428static struct batadv_neigh_node *
429batadv_find_bond_router(struct batadv_orig_node *primary_orig,
430 const struct batadv_hard_iface *recv_if)
55158629 431{
56303d34
SE
432 struct batadv_neigh_node *tmp_neigh_node;
433 struct batadv_neigh_node *router = NULL, *first_candidate = NULL;
55158629
LL
434
435 rcu_read_lock();
436 list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->bond_list,
437 bonding_list) {
438 if (!first_candidate)
439 first_candidate = tmp_neigh_node;
440
441 /* recv_if == NULL on the first node. */
442 if (tmp_neigh_node->if_incoming == recv_if)
443 continue;
444
445 if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
446 continue;
447
448 router = tmp_neigh_node;
449 break;
450 }
451
452 /* use the first candidate if nothing was found. */
453 if (!router && first_candidate &&
454 atomic_inc_not_zero(&first_candidate->refcount))
455 router = first_candidate;
456
457 if (!router)
458 goto out;
459
460 /* selected should point to the next element
9cfc7bd6
SE
461 * after the current router
462 */
55158629
LL
463 spin_lock_bh(&primary_orig->neigh_list_lock);
464 /* this is a list_move(), which unfortunately
9cfc7bd6
SE
465 * does not exist as rcu version
466 */
55158629
LL
467 list_del_rcu(&primary_orig->bond_list);
468 list_add_rcu(&primary_orig->bond_list,
469 &router->bonding_list);
470 spin_unlock_bh(&primary_orig->neigh_list_lock);
471
472out:
473 rcu_read_unlock();
474 return router;
475}
476
477/* Interface Alternating: Use the best of the
478 * remaining candidates which are not using
479 * this interface.
480 *
9cfc7bd6
SE
481 * Increases the returned router's refcount
482 */
56303d34
SE
483static struct batadv_neigh_node *
484batadv_find_ifalter_router(struct batadv_orig_node *primary_orig,
485 const struct batadv_hard_iface *recv_if)
55158629 486{
56303d34
SE
487 struct batadv_neigh_node *tmp_neigh_node;
488 struct batadv_neigh_node *router = NULL, *first_candidate = NULL;
55158629
LL
489
490 rcu_read_lock();
491 list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->bond_list,
492 bonding_list) {
493 if (!first_candidate)
494 first_candidate = tmp_neigh_node;
495
496 /* recv_if == NULL on the first node. */
497 if (tmp_neigh_node->if_incoming == recv_if)
498 continue;
499
fe3f4cfe
SE
500 if (router && tmp_neigh_node->tq_avg <= router->tq_avg)
501 continue;
502
55158629
LL
503 if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
504 continue;
505
fe3f4cfe
SE
506 /* decrement refcount of previously selected router */
507 if (router)
508 batadv_neigh_node_free_ref(router);
55158629 509
fe3f4cfe
SE
510 /* we found a better router (or at least one valid router) */
511 router = tmp_neigh_node;
55158629
LL
512 }
513
514 /* use the first candidate if nothing was found. */
515 if (!router && first_candidate &&
516 atomic_inc_not_zero(&first_candidate->refcount))
517 router = first_candidate;
518
519 rcu_read_unlock();
520 return router;
521}
522
f86ce0ad
MH
523/**
524 * batadv_check_unicast_packet - Check for malformed unicast packets
6e0895c2 525 * @bat_priv: the bat priv with all the soft interface information
f86ce0ad
MH
526 * @skb: packet to check
527 * @hdr_size: size of header to pull
528 *
529 * Check for short header and bad addresses in given packet. Returns negative
530 * value when check fails and 0 otherwise. The negative value depends on the
531 * reason: -ENODATA for bad header, -EBADR for broadcast destination or source,
532 * and -EREMOTE for non-local (other host) destination.
533 */
fe8a93b9
AQ
534static int batadv_check_unicast_packet(struct batadv_priv *bat_priv,
535 struct sk_buff *skb, int hdr_size)
ff51fd70
MH
536{
537 struct ethhdr *ethhdr;
538
539 /* drop packet if it has not necessary minimum size */
540 if (unlikely(!pskb_may_pull(skb, hdr_size)))
f86ce0ad 541 return -ENODATA;
ff51fd70 542
7ed4be95 543 ethhdr = eth_hdr(skb);
ff51fd70
MH
544
545 /* packet with unicast indication but broadcast recipient */
546 if (is_broadcast_ether_addr(ethhdr->h_dest))
f86ce0ad 547 return -EBADR;
ff51fd70
MH
548
549 /* packet with broadcast sender address */
550 if (is_broadcast_ether_addr(ethhdr->h_source))
f86ce0ad 551 return -EBADR;
ff51fd70
MH
552
553 /* not for me */
fe8a93b9 554 if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
f86ce0ad 555 return -EREMOTE;
ff51fd70
MH
556
557 return 0;
558}
559
c6c8fea2 560/* find a suitable router for this originator, and use
a4c135c5 561 * bonding if possible. increases the found neighbors
9cfc7bd6
SE
562 * refcount.
563 */
56303d34
SE
564struct batadv_neigh_node *
565batadv_find_router(struct batadv_priv *bat_priv,
566 struct batadv_orig_node *orig_node,
567 const struct batadv_hard_iface *recv_if)
c6c8fea2 568{
56303d34
SE
569 struct batadv_orig_node *primary_orig_node;
570 struct batadv_orig_node *router_orig;
571 struct batadv_neigh_node *router;
c6c8fea2
SE
572 static uint8_t zero_mac[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
573 int bonding_enabled;
da641193 574 uint8_t *primary_addr;
c6c8fea2
SE
575
576 if (!orig_node)
577 return NULL;
578
7d211efc 579 router = batadv_orig_node_get_router(orig_node);
e1a5382f 580 if (!router)
01df2b65 581 goto err;
c6c8fea2
SE
582
583 /* without bonding, the first node should
9cfc7bd6
SE
584 * always choose the default router.
585 */
c6c8fea2
SE
586 bonding_enabled = atomic_read(&bat_priv->bonding);
587
a4c135c5
SW
588 rcu_read_lock();
589 /* select default router to output */
e1a5382f 590 router_orig = router->orig_node;
01df2b65
ML
591 if (!router_orig)
592 goto err_unlock;
a4c135c5 593
a4c135c5
SW
594 if ((!recv_if) && (!bonding_enabled))
595 goto return_router;
c6c8fea2 596
da641193
SE
597 primary_addr = router_orig->primary_addr;
598
c6c8fea2 599 /* if we have something in the primary_addr, we can search
9cfc7bd6
SE
600 * for a potential bonding candidate.
601 */
1eda58bf 602 if (batadv_compare_eth(primary_addr, zero_mac))
a4c135c5 603 goto return_router;
c6c8fea2
SE
604
605 /* find the orig_node which has the primary interface. might
9cfc7bd6
SE
606 * even be the same as our router_orig in many cases
607 */
1eda58bf 608 if (batadv_compare_eth(primary_addr, router_orig->orig)) {
c6c8fea2
SE
609 primary_orig_node = router_orig;
610 } else {
da641193
SE
611 primary_orig_node = batadv_orig_hash_find(bat_priv,
612 primary_addr);
c6c8fea2 613 if (!primary_orig_node)
a4c135c5 614 goto return_router;
7aadf889 615
7d211efc 616 batadv_orig_node_free_ref(primary_orig_node);
c6c8fea2
SE
617 }
618
619 /* with less than 2 candidates, we can't do any
9cfc7bd6
SE
620 * bonding and prefer the original router.
621 */
a4c135c5
SW
622 if (atomic_read(&primary_orig_node->bond_candidates) < 2)
623 goto return_router;
c6c8fea2 624
c6c8fea2
SE
625 /* all nodes between should choose a candidate which
626 * is is not on the interface where the packet came
9cfc7bd6
SE
627 * in.
628 */
7d211efc 629 batadv_neigh_node_free_ref(router);
c6c8fea2 630
55158629 631 if (bonding_enabled)
63b01037 632 router = batadv_find_bond_router(primary_orig_node, recv_if);
55158629 633 else
63b01037 634 router = batadv_find_ifalter_router(primary_orig_node, recv_if);
c6c8fea2 635
a4c135c5 636return_router:
e9a4f295 637 if (router && router->if_incoming->if_status != BATADV_IF_ACTIVE)
e2cbc11c
AQ
638 goto err_unlock;
639
a4c135c5 640 rcu_read_unlock();
c6c8fea2 641 return router;
01df2b65
ML
642err_unlock:
643 rcu_read_unlock();
644err:
645 if (router)
7d211efc 646 batadv_neigh_node_free_ref(router);
01df2b65 647 return NULL;
c6c8fea2
SE
648}
649
63b01037 650static int batadv_route_unicast_packet(struct sk_buff *skb,
56303d34 651 struct batadv_hard_iface *recv_if)
c6c8fea2 652{
56303d34
SE
653 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
654 struct batadv_orig_node *orig_node = NULL;
96412690 655 struct batadv_unicast_packet *unicast_packet;
7ed4be95 656 struct ethhdr *ethhdr = eth_hdr(skb);
c54f38c9 657 int res, hdr_len, ret = NET_RX_DROP;
c6c8fea2 658
96412690 659 unicast_packet = (struct batadv_unicast_packet *)skb->data;
c6c8fea2
SE
660
661 /* TTL exceeded */
76543d14 662 if (unicast_packet->header.ttl < 2) {
86ceb360
SE
663 pr_debug("Warning - can't forward unicast packet from %pM to %pM: ttl exceeded\n",
664 ethhdr->h_source, unicast_packet->dest);
44524fcd 665 goto out;
c6c8fea2
SE
666 }
667
668 /* get routing information */
da641193 669 orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->dest);
7aadf889 670
44524fcd 671 if (!orig_node)
b5a6f69c 672 goto out;
c6c8fea2 673
c6c8fea2 674 /* create a copy of the skb, if needed, to modify it. */
0d125074 675 if (skb_cow(skb, ETH_HLEN) < 0)
44524fcd 676 goto out;
c6c8fea2 677
c6c8fea2 678 /* decrement ttl */
f097e25d 679 unicast_packet = (struct batadv_unicast_packet *)skb->data;
76543d14 680 unicast_packet->header.ttl--;
c6c8fea2 681
c54f38c9
SW
682 switch (unicast_packet->header.packet_type) {
683 case BATADV_UNICAST_4ADDR:
684 hdr_len = sizeof(struct batadv_unicast_4addr_packet);
685 break;
686 case BATADV_UNICAST:
687 hdr_len = sizeof(struct batadv_unicast_packet);
688 break;
689 default:
690 /* other packet types not supported - yet */
691 hdr_len = -1;
692 break;
693 }
694
695 if (hdr_len > 0)
696 batadv_skb_set_priority(skb, hdr_len);
697
e91ecfc6 698 res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
95332477 699
e91ecfc6
MH
700 /* translate transmit result into receive result */
701 if (res == NET_XMIT_SUCCESS) {
702 /* skb was transmitted and consumed */
95332477
MH
703 batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
704 batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
705 skb->len + ETH_HLEN);
e91ecfc6
MH
706
707 ret = NET_RX_SUCCESS;
708 } else if (res == NET_XMIT_POLICED) {
709 /* skb was buffered and consumed */
710 ret = NET_RX_SUCCESS;
95332477 711 }
c6c8fea2 712
44524fcd 713out:
44524fcd 714 if (orig_node)
7d211efc 715 batadv_orig_node_free_ref(orig_node);
44524fcd 716 return ret;
c6c8fea2
SE
717}
718
7c1fd91d
AQ
719/**
720 * batadv_reroute_unicast_packet - update the unicast header for re-routing
721 * @bat_priv: the bat priv with all the soft interface information
722 * @unicast_packet: the unicast header to be updated
723 * @dst_addr: the payload destination
724 *
725 * Search the translation table for dst_addr and update the unicast header with
726 * the new corresponding information (originator address where the destination
727 * client currently is and its known TTVN)
728 *
729 * Returns true if the packet header has been updated, false otherwise
730 */
731static bool
732batadv_reroute_unicast_packet(struct batadv_priv *bat_priv,
733 struct batadv_unicast_packet *unicast_packet,
734 uint8_t *dst_addr)
735{
736 struct batadv_orig_node *orig_node = NULL;
737 struct batadv_hard_iface *primary_if = NULL;
738 bool ret = false;
739 uint8_t *orig_addr, orig_ttvn;
740
741 if (batadv_is_my_client(bat_priv, dst_addr)) {
742 primary_if = batadv_primary_if_get_selected(bat_priv);
743 if (!primary_if)
744 goto out;
745 orig_addr = primary_if->net_dev->dev_addr;
746 orig_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
747 } else {
748 orig_node = batadv_transtable_search(bat_priv, NULL, dst_addr);
749 if (!orig_node)
750 goto out;
751
752 if (batadv_compare_eth(orig_node->orig, unicast_packet->dest))
753 goto out;
754
755 orig_addr = orig_node->orig;
756 orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
757 }
758
759 /* update the packet header */
760 memcpy(unicast_packet->dest, orig_addr, ETH_ALEN);
761 unicast_packet->ttvn = orig_ttvn;
762
763 ret = true;
764out:
765 if (primary_if)
766 batadv_hardif_free_ref(primary_if);
767 if (orig_node)
768 batadv_orig_node_free_ref(orig_node);
769
770 return ret;
771}
772
56303d34 773static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
dd981ab0 774 struct sk_buff *skb, int hdr_len) {
7c1fd91d 775 uint8_t curr_ttvn, old_ttvn;
56303d34 776 struct batadv_orig_node *orig_node;
a73105b8 777 struct ethhdr *ethhdr;
56303d34 778 struct batadv_hard_iface *primary_if;
96412690 779 struct batadv_unicast_packet *unicast_packet;
3e34819e 780 int is_old_ttvn;
a73105b8 781
b8fcfa42 782 /* check if there is enough data before accessing it */
dd981ab0 783 if (pskb_may_pull(skb, hdr_len + ETH_HLEN) < 0)
b8fcfa42
AQ
784 return 0;
785
786 /* create a copy of the skb (in case of for re-routing) to modify it. */
787 if (skb_cow(skb, sizeof(*unicast_packet)) < 0)
a73105b8
AQ
788 return 0;
789
96412690 790 unicast_packet = (struct batadv_unicast_packet *)skb->data;
dd981ab0 791 ethhdr = (struct ethhdr *)(skb->data + hdr_len);
a73105b8 792
7c1fd91d
AQ
793 /* check if the destination client was served by this node and it is now
794 * roaming. In this case, it means that the node has got a ROAM_ADV
795 * message and that it knows the new destination in the mesh to re-route
796 * the packet to
797 */
798 if (batadv_tt_local_client_is_roaming(bat_priv, ethhdr->h_dest)) {
799 if (batadv_reroute_unicast_packet(bat_priv, unicast_packet,
800 ethhdr->h_dest))
801 net_ratelimited_function(batadv_dbg, BATADV_DBG_TT,
802 bat_priv,
803 "Rerouting unicast packet to %pM (dst=%pM): Local Roaming\n",
804 unicast_packet->dest,
805 ethhdr->h_dest);
806 /* at this point the mesh destination should have been
807 * substituted with the originator address found in the global
808 * table. If not, let the packet go untouched anyway because
809 * there is nothing the node can do
810 */
811 return 1;
812 }
813
814 /* retrieve the TTVN known by this node for the packet destination. This
815 * value is used later to check if the node which sent (or re-routed
816 * last time) the packet had an updated information or not
817 */
818 curr_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
fe8a93b9 819 if (!batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
da641193
SE
820 orig_node = batadv_orig_hash_find(bat_priv,
821 unicast_packet->dest);
7c1fd91d
AQ
822 /* if it is not possible to find the orig_node representing the
823 * destination, the packet can immediately be dropped as it will
824 * not be possible to deliver it
825 */
a73105b8
AQ
826 if (!orig_node)
827 return 0;
828
829 curr_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
7d211efc 830 batadv_orig_node_free_ref(orig_node);
a73105b8
AQ
831 }
832
7c1fd91d
AQ
833 /* check if the TTVN contained in the packet is fresher than what the
834 * node knows
835 */
3e34819e 836 is_old_ttvn = batadv_seq_before(unicast_packet->ttvn, curr_ttvn);
7c1fd91d
AQ
837 if (!is_old_ttvn)
838 return 1;
a73105b8 839
7c1fd91d
AQ
840 old_ttvn = unicast_packet->ttvn;
841 /* the packet was forged based on outdated network information. Its
842 * destination can possibly be updated and forwarded towards the new
843 * target host
844 */
845 if (batadv_reroute_unicast_packet(bat_priv, unicast_packet,
846 ethhdr->h_dest)) {
847 net_ratelimited_function(batadv_dbg, BATADV_DBG_TT, bat_priv,
848 "Rerouting unicast packet to %pM (dst=%pM): TTVN mismatch old_ttvn=%u new_ttvn=%u\n",
849 unicast_packet->dest, ethhdr->h_dest,
850 old_ttvn, curr_ttvn);
851 return 1;
852 }
3275e7cc 853
7c1fd91d
AQ
854 /* the packet has not been re-routed: either the destination is
855 * currently served by this node or there is no destination at all and
856 * it is possible to drop the packet
857 */
858 if (!batadv_is_my_client(bat_priv, ethhdr->h_dest))
859 return 0;
3275e7cc 860
7c1fd91d
AQ
861 /* update the header in order to let the packet be delivered to this
862 * node's soft interface
863 */
864 primary_if = batadv_primary_if_get_selected(bat_priv);
865 if (!primary_if)
866 return 0;
a73105b8 867
7c1fd91d
AQ
868 memcpy(unicast_packet->dest, primary_if->net_dev->dev_addr, ETH_ALEN);
869
870 batadv_hardif_free_ref(primary_if);
871
872 unicast_packet->ttvn = curr_ttvn;
a73105b8 873
a73105b8
AQ
874 return 1;
875}
876
a1f1ac5c
SW
877/**
878 * batadv_recv_unhandled_unicast_packet - receive and process packets which
879 * are in the unicast number space but not yet known to the implementation
880 * @skb: unicast tvlv packet to process
881 * @recv_if: pointer to interface this packet was received on
882 *
883 * Returns NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
884 * otherwise.
885 */
886int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
887 struct batadv_hard_iface *recv_if)
888{
889 struct batadv_unicast_packet *unicast_packet;
890 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
891 int check, hdr_size = sizeof(*unicast_packet);
892
893 check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
894 if (check < 0)
895 return NET_RX_DROP;
896
897 /* we don't know about this type, drop it. */
898 unicast_packet = (struct batadv_unicast_packet *)skb->data;
899 if (batadv_is_my_mac(bat_priv, unicast_packet->dest))
900 return NET_RX_DROP;
901
902 return batadv_route_unicast_packet(skb, recv_if);
903}
904
56303d34
SE
905int batadv_recv_unicast_packet(struct sk_buff *skb,
906 struct batadv_hard_iface *recv_if)
c6c8fea2 907{
56303d34 908 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
96412690 909 struct batadv_unicast_packet *unicast_packet;
4046b24a 910 struct batadv_unicast_4addr_packet *unicast_4addr_packet;
9affec6b
AQ
911 uint8_t *orig_addr;
912 struct batadv_orig_node *orig_node = NULL;
612d2b4f 913 int check, hdr_size = sizeof(*unicast_packet);
c384ea3e 914 bool is4addr;
c6c8fea2 915
7cdcf6dd 916 unicast_packet = (struct batadv_unicast_packet *)skb->data;
4046b24a 917 unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
7cdcf6dd 918
c384ea3e 919 is4addr = unicast_packet->header.packet_type == BATADV_UNICAST_4ADDR;
7cdcf6dd 920 /* the caller function should have already pulled 2 bytes */
c384ea3e 921 if (is4addr)
4046b24a 922 hdr_size = sizeof(*unicast_4addr_packet);
7cdcf6dd 923
612d2b4f 924 /* function returns -EREMOTE for promiscuous packets */
6e0895c2 925 check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
612d2b4f
MH
926
927 /* Even though the packet is not for us, we might save it to use for
928 * decoding a later received coded packet
929 */
930 if (check == -EREMOTE)
931 batadv_nc_skb_store_sniffed_unicast(bat_priv, skb);
932
933 if (check < 0)
c6c8fea2 934 return NET_RX_DROP;
dd981ab0 935 if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size))
a73105b8
AQ
936 return NET_RX_DROP;
937
c6c8fea2 938 /* packet for me */
fe8a93b9 939 if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
9affec6b 940 if (is4addr) {
4046b24a
MH
941 batadv_dat_inc_counter(bat_priv,
942 unicast_4addr_packet->subtype);
9affec6b
AQ
943 orig_addr = unicast_4addr_packet->src;
944 orig_node = batadv_orig_hash_find(bat_priv, orig_addr);
945 }
4046b24a 946
c384ea3e
AQ
947 if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb,
948 hdr_size))
949 goto rx_success;
950 if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb,
951 hdr_size))
952 goto rx_success;
953
37135173 954 batadv_interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size,
9affec6b 955 orig_node);
37135173 956
c384ea3e 957rx_success:
9affec6b
AQ
958 if (orig_node)
959 batadv_orig_node_free_ref(orig_node);
960
c6c8fea2
SE
961 return NET_RX_SUCCESS;
962 }
963
63b01037 964 return batadv_route_unicast_packet(skb, recv_if);
c6c8fea2
SE
965}
966
ef261577
ML
967/**
968 * batadv_recv_unicast_tvlv - receive and process unicast tvlv packets
969 * @skb: unicast tvlv packet to process
970 * @recv_if: pointer to interface this packet was received on
971 * @dst_addr: the payload destination
972 *
973 * Returns NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
974 * otherwise.
975 */
976int batadv_recv_unicast_tvlv(struct sk_buff *skb,
977 struct batadv_hard_iface *recv_if)
978{
979 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
980 struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
981 unsigned char *tvlv_buff;
982 uint16_t tvlv_buff_len;
983 int hdr_size = sizeof(*unicast_tvlv_packet);
984 int ret = NET_RX_DROP;
985
986 if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
987 return NET_RX_DROP;
988
989 /* the header is likely to be modified while forwarding */
990 if (skb_cow(skb, hdr_size) < 0)
991 return NET_RX_DROP;
992
993 /* packet needs to be linearized to access the tvlv content */
994 if (skb_linearize(skb) < 0)
995 return NET_RX_DROP;
996
997 unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)skb->data;
998
999 tvlv_buff = (unsigned char *)(skb->data + hdr_size);
1000 tvlv_buff_len = ntohs(unicast_tvlv_packet->tvlv_len);
1001
1002 if (tvlv_buff_len > skb->len - hdr_size)
1003 return NET_RX_DROP;
1004
1005 ret = batadv_tvlv_containers_process(bat_priv, false, NULL,
1006 unicast_tvlv_packet->src,
1007 unicast_tvlv_packet->dst,
1008 tvlv_buff, tvlv_buff_len);
1009
1010 if (ret != NET_RX_SUCCESS)
1011 ret = batadv_route_unicast_packet(skb, recv_if);
1012
1013 return ret;
1014}
c6c8fea2 1015
56303d34
SE
1016int batadv_recv_bcast_packet(struct sk_buff *skb,
1017 struct batadv_hard_iface *recv_if)
c6c8fea2 1018{
56303d34
SE
1019 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
1020 struct batadv_orig_node *orig_node = NULL;
96412690 1021 struct batadv_bcast_packet *bcast_packet;
c6c8fea2 1022 struct ethhdr *ethhdr;
704509b8 1023 int hdr_size = sizeof(*bcast_packet);
f3e0008f 1024 int ret = NET_RX_DROP;
c6c8fea2
SE
1025 int32_t seq_diff;
1026
1027 /* drop packet if it has not necessary minimum size */
1028 if (unlikely(!pskb_may_pull(skb, hdr_size)))
f3e0008f 1029 goto out;
c6c8fea2 1030
7ed4be95 1031 ethhdr = eth_hdr(skb);
c6c8fea2
SE
1032
1033 /* packet with broadcast indication but unicast recipient */
1034 if (!is_broadcast_ether_addr(ethhdr->h_dest))
f3e0008f 1035 goto out;
c6c8fea2
SE
1036
1037 /* packet with broadcast sender address */
1038 if (is_broadcast_ether_addr(ethhdr->h_source))
f3e0008f 1039 goto out;
c6c8fea2
SE
1040
1041 /* ignore broadcasts sent by myself */
fe8a93b9 1042 if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
f3e0008f 1043 goto out;
c6c8fea2 1044
96412690 1045 bcast_packet = (struct batadv_bcast_packet *)skb->data;
c6c8fea2
SE
1046
1047 /* ignore broadcasts originated by myself */
fe8a93b9 1048 if (batadv_is_my_mac(bat_priv, bcast_packet->orig))
f3e0008f 1049 goto out;
c6c8fea2 1050
76543d14 1051 if (bcast_packet->header.ttl < 2)
f3e0008f 1052 goto out;
c6c8fea2 1053
da641193 1054 orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->orig);
f3e0008f
ML
1055
1056 if (!orig_node)
b5a6f69c 1057 goto out;
c6c8fea2 1058
f3e0008f 1059 spin_lock_bh(&orig_node->bcast_seqno_lock);
c6c8fea2
SE
1060
1061 /* check whether the packet is a duplicate */
9b4a1159
SE
1062 if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno,
1063 ntohl(bcast_packet->seqno)))
f3e0008f 1064 goto spin_unlock;
c6c8fea2
SE
1065
1066 seq_diff = ntohl(bcast_packet->seqno) - orig_node->last_bcast_seqno;
1067
1068 /* check whether the packet is old and the host just restarted. */
30d3c511
SE
1069 if (batadv_window_protected(bat_priv, seq_diff,
1070 &orig_node->bcast_seqno_reset))
f3e0008f 1071 goto spin_unlock;
c6c8fea2
SE
1072
1073 /* mark broadcast in flood history, update window position
9cfc7bd6
SE
1074 * if required.
1075 */
0f5f9322 1076 if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1))
c6c8fea2
SE
1077 orig_node->last_bcast_seqno = ntohl(bcast_packet->seqno);
1078
f3e0008f 1079 spin_unlock_bh(&orig_node->bcast_seqno_lock);
f3e0008f 1080
fe2da6ff 1081 /* check whether this has been sent by another originator before */
004e86fc 1082 if (batadv_bla_check_bcast_duplist(bat_priv, skb))
fe2da6ff
SW
1083 goto out;
1084
c54f38c9
SW
1085 batadv_skb_set_priority(skb, sizeof(struct batadv_bcast_packet));
1086
c6c8fea2 1087 /* rebroadcast packet */
9455e34c 1088 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
c6c8fea2 1089
23721387
SW
1090 /* don't hand the broadcast up if it is from an originator
1091 * from the same backbone.
1092 */
08adf151 1093 if (batadv_bla_is_backbone_gw(skb, orig_node, hdr_size))
23721387
SW
1094 goto out;
1095
c384ea3e
AQ
1096 if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size))
1097 goto rx_success;
1098 if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size))
1099 goto rx_success;
1100
c6c8fea2 1101 /* broadcast for me */
37135173
AQ
1102 batadv_interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size,
1103 orig_node);
c384ea3e
AQ
1104
1105rx_success:
f3e0008f
ML
1106 ret = NET_RX_SUCCESS;
1107 goto out;
c6c8fea2 1108
f3e0008f
ML
1109spin_unlock:
1110 spin_unlock_bh(&orig_node->bcast_seqno_lock);
f3e0008f
ML
1111out:
1112 if (orig_node)
7d211efc 1113 batadv_orig_node_free_ref(orig_node);
f3e0008f 1114 return ret;
c6c8fea2 1115}
This page took 0.247819 seconds and 5 git commands to generate.