diff options
author | Antonio Quartulli <antonio@open-mesh.com> | 2016-01-16 03:40:13 -0500 |
---|---|---|
committer | Antonio Quartulli <a@unstable.cc> | 2016-02-29 03:05:31 -0500 |
commit | 9323158ef9f49935f0c61509919acd31dda8f11b (patch) | |
tree | aac9dcf3817462f1f0f6b0071123643968ac5052 /net/batman-adv/bat_v_ogm.c | |
parent | 0da0035942d47766c32843143fb5dba7a29cb48c (diff) |
batman-adv: OGMv2 - implement originators logic
Add the support for recognising new originators in the
network and rebroadcast their OGMs.
Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Diffstat (limited to 'net/batman-adv/bat_v_ogm.c')
-rw-r--r-- | net/batman-adv/bat_v_ogm.c | 556 |
1 files changed, 555 insertions, 1 deletions
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c index 23932f9b85ec..22dda0e079a5 100644 --- a/net/batman-adv/bat_v_ogm.c +++ b/net/batman-adv/bat_v_ogm.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/if_ether.h> | 26 | #include <linux/if_ether.h> |
27 | #include <linux/jiffies.h> | 27 | #include <linux/jiffies.h> |
28 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
29 | #include <linux/list.h> | ||
29 | #include <linux/netdevice.h> | 30 | #include <linux/netdevice.h> |
30 | #include <linux/random.h> | 31 | #include <linux/random.h> |
31 | #include <linux/rculist.h> | 32 | #include <linux/rculist.h> |
@@ -38,12 +39,52 @@ | |||
38 | #include <linux/workqueue.h> | 39 | #include <linux/workqueue.h> |
39 | 40 | ||
40 | #include "hard-interface.h" | 41 | #include "hard-interface.h" |
42 | #include "hash.h" | ||
43 | #include "originator.h" | ||
41 | #include "packet.h" | 44 | #include "packet.h" |
42 | #include "routing.h" | 45 | #include "routing.h" |
43 | #include "send.h" | 46 | #include "send.h" |
44 | #include "translation-table.h" | 47 | #include "translation-table.h" |
45 | 48 | ||
46 | /** | 49 | /** |
50 | * batadv_v_ogm_orig_get - retrieve and possibly create an originator node | ||
51 | * @bat_priv: the bat priv with all the soft interface information | ||
52 | * @addr: the address of the originator | ||
53 | * | ||
54 | * Return: the orig_node corresponding to the specified address. If such object | ||
55 | * does not exist it is allocated here. In case of allocation failure returns | ||
56 | * NULL. | ||
57 | */ | ||
58 | struct batadv_orig_node *batadv_v_ogm_orig_get(struct batadv_priv *bat_priv, | ||
59 | const u8 *addr) | ||
60 | { | ||
61 | struct batadv_orig_node *orig_node; | ||
62 | int hash_added; | ||
63 | |||
64 | orig_node = batadv_orig_hash_find(bat_priv, addr); | ||
65 | if (orig_node) | ||
66 | return orig_node; | ||
67 | |||
68 | orig_node = batadv_orig_node_new(bat_priv, addr); | ||
69 | if (!orig_node) | ||
70 | return NULL; | ||
71 | |||
72 | hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig, | ||
73 | batadv_choose_orig, orig_node, | ||
74 | &orig_node->hash_entry); | ||
75 | if (hash_added != 0) { | ||
76 | /* orig_node->refcounter is initialised to 2 by | ||
77 | * batadv_orig_node_new() | ||
78 | */ | ||
79 | batadv_orig_node_put(orig_node); | ||
80 | batadv_orig_node_put(orig_node); | ||
81 | orig_node = NULL; | ||
82 | } | ||
83 | |||
84 | return orig_node; | ||
85 | } | ||
86 | |||
87 | /** | ||
47 | * batadv_v_ogm_start_timer - restart the OGM sending timer | 88 | * batadv_v_ogm_start_timer - restart the OGM sending timer |
48 | * @bat_priv: the bat priv with all the soft interface information | 89 | * @bat_priv: the bat priv with all the soft interface information |
49 | */ | 90 | */ |
@@ -193,6 +234,500 @@ void batadv_v_ogm_primary_iface_set(struct batadv_hard_iface *primary_iface) | |||
193 | } | 234 | } |
194 | 235 | ||
195 | /** | 236 | /** |
237 | * batadv_v_ogm_orig_update - update the originator status based on the received | ||
238 | * OGM | ||
239 | * @bat_priv: the bat priv with all the soft interface information | ||
240 | * @orig_node: the originator to update | ||
241 | * @neigh_node: the neighbour the OGM has been received from (to update) | ||
242 | * @ogm2: the received OGM | ||
243 | * @if_outgoing: the interface where this OGM is going to be forwarded through | ||
244 | */ | ||
245 | static void | ||
246 | batadv_v_ogm_orig_update(struct batadv_priv *bat_priv, | ||
247 | struct batadv_orig_node *orig_node, | ||
248 | struct batadv_neigh_node *neigh_node, | ||
249 | const struct batadv_ogm2_packet *ogm2, | ||
250 | struct batadv_hard_iface *if_outgoing) | ||
251 | { | ||
252 | struct batadv_neigh_ifinfo *router_ifinfo = NULL, *neigh_ifinfo = NULL; | ||
253 | struct batadv_neigh_node *router = NULL; | ||
254 | s32 neigh_seq_diff; | ||
255 | u32 neigh_last_seqno; | ||
256 | u32 router_last_seqno; | ||
257 | u32 router_throughput, neigh_throughput; | ||
258 | |||
259 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
260 | "Searching and updating originator entry of received packet\n"); | ||
261 | |||
262 | /* if this neighbor already is our next hop there is nothing | ||
263 | * to change | ||
264 | */ | ||
265 | router = batadv_orig_router_get(orig_node, if_outgoing); | ||
266 | if (router == neigh_node) | ||
267 | goto out; | ||
268 | |||
269 | /* don't consider neighbours with worse throughput. | ||
270 | * also switch route if this seqno is BATADV_V_MAX_ORIGDIFF newer than | ||
271 | * the last received seqno from our best next hop. | ||
272 | */ | ||
273 | if (router) { | ||
274 | router_ifinfo = batadv_neigh_ifinfo_get(router, if_outgoing); | ||
275 | neigh_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); | ||
276 | |||
277 | /* if these are not allocated, something is wrong. */ | ||
278 | if (!router_ifinfo || !neigh_ifinfo) | ||
279 | goto out; | ||
280 | |||
281 | neigh_last_seqno = neigh_ifinfo->bat_v.last_seqno; | ||
282 | router_last_seqno = router_ifinfo->bat_v.last_seqno; | ||
283 | neigh_seq_diff = neigh_last_seqno - router_last_seqno; | ||
284 | router_throughput = router_ifinfo->bat_v.throughput; | ||
285 | neigh_throughput = neigh_ifinfo->bat_v.throughput; | ||
286 | |||
287 | if ((neigh_seq_diff < BATADV_OGM_MAX_ORIGDIFF) && | ||
288 | (router_throughput >= neigh_throughput)) | ||
289 | goto out; | ||
290 | } | ||
291 | |||
292 | batadv_update_route(bat_priv, orig_node, if_outgoing, neigh_node); | ||
293 | |||
294 | out: | ||
295 | if (router_ifinfo) | ||
296 | batadv_neigh_ifinfo_put(router_ifinfo); | ||
297 | if (neigh_ifinfo) | ||
298 | batadv_neigh_ifinfo_put(neigh_ifinfo); | ||
299 | if (router) | ||
300 | batadv_neigh_node_put(router); | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * batadv_v_forward_penalty - apply a penalty to the throughput metric forwarded | ||
305 | * with B.A.T.M.A.N. V OGMs | ||
306 | * @bat_priv: the bat priv with all the soft interface information | ||
307 | * @if_incoming: the interface where the OGM has been received | ||
308 | * @if_outgoing: the interface where the OGM has to be forwarded to | ||
309 | * @throughput: the current throughput | ||
310 | * | ||
311 | * Apply a penalty on the current throughput metric value based on the | ||
312 | * characteristic of the interface where the OGM has been received. The return | ||
313 | * value is computed as follows: | ||
314 | * - throughput * 50% if the incoming and outgoing interface are the | ||
315 | * same WiFi interface and the throughput is above | ||
316 | * 1MBit/s | ||
317 | * - throughput if the outgoing interface is the default | ||
318 | * interface (i.e. this OGM is processed for the | ||
319 | * internal table and not forwarded) | ||
320 | * - throughput * hop penalty otherwise | ||
321 | * | ||
322 | * Return: the penalised throughput metric. | ||
323 | */ | ||
324 | static u32 batadv_v_forward_penalty(struct batadv_priv *bat_priv, | ||
325 | struct batadv_hard_iface *if_incoming, | ||
326 | struct batadv_hard_iface *if_outgoing, | ||
327 | u32 throughput) | ||
328 | { | ||
329 | int hop_penalty = atomic_read(&bat_priv->hop_penalty); | ||
330 | int hop_penalty_max = BATADV_TQ_MAX_VALUE; | ||
331 | |||
332 | /* Don't apply hop penalty in default originator table. */ | ||
333 | if (if_outgoing == BATADV_IF_DEFAULT) | ||
334 | return throughput; | ||
335 | |||
336 | /* Forwarding on the same WiFi interface cuts the throughput in half | ||
337 | * due to the store & forward characteristics of WIFI. | ||
338 | * Very low throughput values are the exception. | ||
339 | */ | ||
340 | if ((throughput > 10) && | ||
341 | (if_incoming == if_outgoing) && | ||
342 | (batadv_is_wifi_netdev(if_incoming->net_dev))) | ||
343 | return throughput / 2; | ||
344 | |||
345 | /* hop penalty of 255 equals 100% */ | ||
346 | return throughput * (hop_penalty_max - hop_penalty) / hop_penalty_max; | ||
347 | } | ||
348 | |||
349 | /** | ||
350 | * batadv_v_ogm_forward - forward an OGM to the given outgoing interface | ||
351 | * @bat_priv: the bat priv with all the soft interface information | ||
352 | * @ogm_received: previously received OGM to be forwarded | ||
353 | * @throughput: throughput to announce, may vary per outgoing interface | ||
354 | * @if_incoming: the interface on which this OGM was received on | ||
355 | * @if_outgoing: the interface to which the OGM has to be forwarded to | ||
356 | * | ||
357 | * Forward an OGM to an interface after having altered the throughput metric and | ||
358 | * the TTL value contained in it. The original OGM isn't modified. | ||
359 | */ | ||
360 | static void batadv_v_ogm_forward(struct batadv_priv *bat_priv, | ||
361 | const struct batadv_ogm2_packet *ogm_received, | ||
362 | u32 throughput, | ||
363 | struct batadv_hard_iface *if_incoming, | ||
364 | struct batadv_hard_iface *if_outgoing) | ||
365 | { | ||
366 | struct batadv_ogm2_packet *ogm_forward; | ||
367 | unsigned char *skb_buff; | ||
368 | struct sk_buff *skb; | ||
369 | size_t packet_len; | ||
370 | u16 tvlv_len; | ||
371 | |||
372 | if (ogm_received->ttl <= 1) { | ||
373 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n"); | ||
374 | return; | ||
375 | } | ||
376 | |||
377 | tvlv_len = ntohs(ogm_received->tvlv_len); | ||
378 | |||
379 | packet_len = BATADV_OGM2_HLEN + tvlv_len; | ||
380 | skb = netdev_alloc_skb_ip_align(if_outgoing->net_dev, | ||
381 | ETH_HLEN + packet_len); | ||
382 | if (!skb) | ||
383 | return; | ||
384 | |||
385 | skb_reserve(skb, ETH_HLEN); | ||
386 | skb_buff = skb_put(skb, packet_len); | ||
387 | memcpy(skb_buff, ogm_received, packet_len); | ||
388 | |||
389 | /* apply forward penalty */ | ||
390 | ogm_forward = (struct batadv_ogm2_packet *)skb_buff; | ||
391 | ogm_forward->throughput = htonl(throughput); | ||
392 | ogm_forward->ttl--; | ||
393 | |||
394 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
395 | "Forwarding OGM2 packet on %s: throughput %u, ttl %u, received via %s\n", | ||
396 | if_outgoing->net_dev->name, throughput, ogm_forward->ttl, | ||
397 | if_incoming->net_dev->name); | ||
398 | |||
399 | batadv_v_ogm_send_to_if(skb, if_outgoing); | ||
400 | } | ||
401 | |||
402 | /** | ||
403 | * batadv_v_ogm_metric_update - update route metric based on OGM | ||
404 | * @bat_priv: the bat priv with all the soft interface information | ||
405 | * @ogm2: OGM2 structure | ||
406 | * @orig_node: Originator structure for which the OGM has been received | ||
407 | * @neigh_node: the neigh_node through with the OGM has been received | ||
408 | * @if_incoming: the interface where this packet was received | ||
409 | * @if_outgoing: the interface for which the packet should be considered | ||
410 | * | ||
411 | * Return: | ||
412 | * 1 if the OGM is new, | ||
413 | * 0 if it is not new but valid, | ||
414 | * <0 on error (e.g. old OGM) | ||
415 | */ | ||
416 | static int batadv_v_ogm_metric_update(struct batadv_priv *bat_priv, | ||
417 | const struct batadv_ogm2_packet *ogm2, | ||
418 | struct batadv_orig_node *orig_node, | ||
419 | struct batadv_neigh_node *neigh_node, | ||
420 | struct batadv_hard_iface *if_incoming, | ||
421 | struct batadv_hard_iface *if_outgoing) | ||
422 | { | ||
423 | struct batadv_orig_ifinfo *orig_ifinfo = NULL; | ||
424 | struct batadv_neigh_ifinfo *neigh_ifinfo = NULL; | ||
425 | bool protection_started = false; | ||
426 | int ret = -EINVAL; | ||
427 | u32 path_throughput; | ||
428 | s32 seq_diff; | ||
429 | |||
430 | orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing); | ||
431 | if (!orig_ifinfo) | ||
432 | goto out; | ||
433 | |||
434 | seq_diff = ntohl(ogm2->seqno) - orig_ifinfo->last_real_seqno; | ||
435 | |||
436 | if (!hlist_empty(&orig_node->neigh_list) && | ||
437 | batadv_window_protected(bat_priv, seq_diff, | ||
438 | BATADV_OGM_MAX_AGE, | ||
439 | &orig_ifinfo->batman_seqno_reset, | ||
440 | &protection_started)) { | ||
441 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
442 | "Drop packet: packet within window protection time from %pM\n", | ||
443 | ogm2->orig); | ||
444 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
445 | "Last reset: %ld, %ld\n", | ||
446 | orig_ifinfo->batman_seqno_reset, jiffies); | ||
447 | goto out; | ||
448 | } | ||
449 | |||
450 | /* drop packets with old seqnos, however accept the first packet after | ||
451 | * a host has been rebooted. | ||
452 | */ | ||
453 | if ((seq_diff < 0) && !protection_started) | ||
454 | goto out; | ||
455 | |||
456 | neigh_node->last_seen = jiffies; | ||
457 | |||
458 | orig_node->last_seen = jiffies; | ||
459 | |||
460 | orig_ifinfo->last_real_seqno = ntohl(ogm2->seqno); | ||
461 | orig_ifinfo->last_ttl = ogm2->ttl; | ||
462 | |||
463 | neigh_ifinfo = batadv_neigh_ifinfo_new(neigh_node, if_outgoing); | ||
464 | if (!neigh_ifinfo) | ||
465 | goto out; | ||
466 | |||
467 | path_throughput = batadv_v_forward_penalty(bat_priv, if_incoming, | ||
468 | if_outgoing, | ||
469 | ntohl(ogm2->throughput)); | ||
470 | neigh_ifinfo->bat_v.throughput = path_throughput; | ||
471 | neigh_ifinfo->bat_v.last_seqno = ntohl(ogm2->seqno); | ||
472 | neigh_ifinfo->last_ttl = ogm2->ttl; | ||
473 | |||
474 | if (seq_diff > 0 || protection_started) | ||
475 | ret = 1; | ||
476 | else | ||
477 | ret = 0; | ||
478 | out: | ||
479 | if (orig_ifinfo) | ||
480 | batadv_orig_ifinfo_put(orig_ifinfo); | ||
481 | if (neigh_ifinfo) | ||
482 | batadv_neigh_ifinfo_put(neigh_ifinfo); | ||
483 | |||
484 | return ret; | ||
485 | } | ||
486 | |||
487 | /** | ||
488 | * batadv_v_ogm_route_update - update routes based on OGM | ||
489 | * @bat_priv: the bat priv with all the soft interface information | ||
490 | * @ethhdr: the Ethernet header of the OGM2 | ||
491 | * @ogm2: OGM2 structure | ||
492 | * @orig_node: Originator structure for which the OGM has been received | ||
493 | * @neigh_node: the neigh_node through with the OGM has been received | ||
494 | * @if_incoming: the interface where this packet was received | ||
495 | * @if_outgoing: the interface for which the packet should be considered | ||
496 | */ | ||
497 | static void batadv_v_ogm_route_update(struct batadv_priv *bat_priv, | ||
498 | const struct ethhdr *ethhdr, | ||
499 | const struct batadv_ogm2_packet *ogm2, | ||
500 | struct batadv_orig_node *orig_node, | ||
501 | struct batadv_neigh_node *neigh_node, | ||
502 | struct batadv_hard_iface *if_incoming, | ||
503 | struct batadv_hard_iface *if_outgoing) | ||
504 | { | ||
505 | struct batadv_neigh_node *router = NULL; | ||
506 | struct batadv_neigh_ifinfo *neigh_ifinfo = NULL; | ||
507 | struct batadv_orig_node *orig_neigh_node = NULL; | ||
508 | struct batadv_orig_ifinfo *orig_ifinfo = NULL; | ||
509 | struct batadv_neigh_node *orig_neigh_router = NULL; | ||
510 | |||
511 | neigh_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); | ||
512 | if (!neigh_ifinfo) | ||
513 | goto out; | ||
514 | |||
515 | orig_neigh_node = batadv_v_ogm_orig_get(bat_priv, ethhdr->h_source); | ||
516 | if (!orig_neigh_node) | ||
517 | goto out; | ||
518 | |||
519 | orig_neigh_router = batadv_orig_router_get(orig_neigh_node, | ||
520 | if_outgoing); | ||
521 | |||
522 | /* drop packet if sender is not a direct neighbor and if we | ||
523 | * don't route towards it | ||
524 | */ | ||
525 | router = batadv_orig_router_get(orig_node, if_outgoing); | ||
526 | if (router && router->orig_node != orig_node && !orig_neigh_router) { | ||
527 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
528 | "Drop packet: OGM via unknown neighbor!\n"); | ||
529 | goto out; | ||
530 | } | ||
531 | |||
532 | if (router) | ||
533 | batadv_neigh_node_put(router); | ||
534 | |||
535 | /* Update routes, and check if the OGM is from the best next hop */ | ||
536 | batadv_v_ogm_orig_update(bat_priv, orig_node, neigh_node, ogm2, | ||
537 | if_outgoing); | ||
538 | |||
539 | orig_ifinfo = batadv_orig_ifinfo_new(orig_node, if_outgoing); | ||
540 | if (!orig_ifinfo) | ||
541 | goto out; | ||
542 | |||
543 | /* don't forward the same seqno twice on one interface */ | ||
544 | if (orig_ifinfo->last_seqno_forwarded == ntohl(ogm2->seqno)) | ||
545 | goto out; | ||
546 | |||
547 | /* acquire possibly updated router */ | ||
548 | router = batadv_orig_router_get(orig_node, if_outgoing); | ||
549 | |||
550 | /* strict rule: forward packets coming from the best next hop only */ | ||
551 | if (neigh_node != router) | ||
552 | goto out; | ||
553 | |||
554 | /* only forward for specific interface, not for the default one. */ | ||
555 | if (if_outgoing != BATADV_IF_DEFAULT) { | ||
556 | orig_ifinfo->last_seqno_forwarded = ntohl(ogm2->seqno); | ||
557 | batadv_v_ogm_forward(bat_priv, ogm2, | ||
558 | neigh_ifinfo->bat_v.throughput, | ||
559 | if_incoming, if_outgoing); | ||
560 | } | ||
561 | |||
562 | out: | ||
563 | if (orig_ifinfo) | ||
564 | batadv_orig_ifinfo_put(orig_ifinfo); | ||
565 | if (router) | ||
566 | batadv_neigh_node_put(router); | ||
567 | if (orig_neigh_router) | ||
568 | batadv_neigh_node_put(orig_neigh_router); | ||
569 | if (orig_neigh_node) | ||
570 | batadv_orig_node_put(orig_neigh_node); | ||
571 | if (neigh_ifinfo) | ||
572 | batadv_neigh_ifinfo_put(neigh_ifinfo); | ||
573 | } | ||
574 | |||
575 | /** | ||
576 | * batadv_v_ogm_process_per_outif - process a batman v OGM for an outgoing if | ||
577 | * @bat_priv: the bat priv with all the soft interface information | ||
578 | * @ethhdr: the Ethernet header of the OGM2 | ||
579 | * @ogm2: OGM2 structure | ||
580 | * @orig_node: Originator structure for which the OGM has been received | ||
581 | * @neigh_node: the neigh_node through with the OGM has been received | ||
582 | * @if_incoming: the interface where this packet was received | ||
583 | * @if_outgoing: the interface for which the packet should be considered | ||
584 | */ | ||
585 | static void | ||
586 | batadv_v_ogm_process_per_outif(struct batadv_priv *bat_priv, | ||
587 | const struct ethhdr *ethhdr, | ||
588 | const struct batadv_ogm2_packet *ogm2, | ||
589 | struct batadv_orig_node *orig_node, | ||
590 | struct batadv_neigh_node *neigh_node, | ||
591 | struct batadv_hard_iface *if_incoming, | ||
592 | struct batadv_hard_iface *if_outgoing) | ||
593 | { | ||
594 | int seqno_age; | ||
595 | |||
596 | /* first, update the metric with according sanity checks */ | ||
597 | seqno_age = batadv_v_ogm_metric_update(bat_priv, ogm2, orig_node, | ||
598 | neigh_node, if_incoming, | ||
599 | if_outgoing); | ||
600 | |||
601 | /* outdated sequence numbers are to be discarded */ | ||
602 | if (seqno_age < 0) | ||
603 | return; | ||
604 | |||
605 | /* only unknown & newer OGMs contain TVLVs we are interested in */ | ||
606 | if ((seqno_age > 0) && (if_outgoing == BATADV_IF_DEFAULT)) | ||
607 | batadv_tvlv_containers_process(bat_priv, true, orig_node, | ||
608 | NULL, NULL, | ||
609 | (unsigned char *)(ogm2 + 1), | ||
610 | ntohs(ogm2->tvlv_len)); | ||
611 | |||
612 | /* if the metric update went through, update routes if needed */ | ||
613 | batadv_v_ogm_route_update(bat_priv, ethhdr, ogm2, orig_node, | ||
614 | neigh_node, if_incoming, if_outgoing); | ||
615 | } | ||
616 | |||
617 | /** | ||
618 | * batadv_v_ogm_aggr_packet - checks if there is another OGM aggregated | ||
619 | * @buff_pos: current position in the skb | ||
620 | * @packet_len: total length of the skb | ||
621 | * @tvlv_len: tvlv length of the previously considered OGM | ||
622 | * | ||
623 | * Return: true if there is enough space for another OGM, false otherwise. | ||
624 | */ | ||
625 | static bool batadv_v_ogm_aggr_packet(int buff_pos, int packet_len, | ||
626 | __be16 tvlv_len) | ||
627 | { | ||
628 | int next_buff_pos = 0; | ||
629 | |||
630 | next_buff_pos += buff_pos + BATADV_OGM2_HLEN; | ||
631 | next_buff_pos += ntohs(tvlv_len); | ||
632 | |||
633 | return (next_buff_pos <= packet_len) && | ||
634 | (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES); | ||
635 | } | ||
636 | |||
637 | /** | ||
638 | * batadv_v_ogm_process - process an incoming batman v OGM | ||
639 | * @skb: the skb containing the OGM | ||
640 | * @ogm_offset: offset to the OGM which should be processed (for aggregates) | ||
641 | * @if_incoming: the interface where this packet was receved | ||
642 | */ | ||
643 | static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset, | ||
644 | struct batadv_hard_iface *if_incoming) | ||
645 | { | ||
646 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
647 | struct ethhdr *ethhdr; | ||
648 | struct batadv_orig_node *orig_node = NULL; | ||
649 | struct batadv_hardif_neigh_node *hardif_neigh = NULL; | ||
650 | struct batadv_neigh_node *neigh_node = NULL; | ||
651 | struct batadv_hard_iface *hard_iface; | ||
652 | struct batadv_ogm2_packet *ogm_packet; | ||
653 | u32 ogm_throughput, link_throughput, path_throughput; | ||
654 | |||
655 | ethhdr = eth_hdr(skb); | ||
656 | ogm_packet = (struct batadv_ogm2_packet *)(skb->data + ogm_offset); | ||
657 | |||
658 | ogm_throughput = ntohl(ogm_packet->throughput); | ||
659 | |||
660 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
661 | "Received OGM2 packet via NB: %pM, IF: %s [%pM] (from OG: %pM, seqno %u, troughput %u, TTL %u, V %u, tvlv_len %u)\n", | ||
662 | ethhdr->h_source, if_incoming->net_dev->name, | ||
663 | if_incoming->net_dev->dev_addr, ogm_packet->orig, | ||
664 | ntohl(ogm_packet->seqno), ogm_throughput, ogm_packet->ttl, | ||
665 | ogm_packet->version, ntohs(ogm_packet->tvlv_len)); | ||
666 | |||
667 | /* If the troughput metric is 0, immediately drop the packet. No need to | ||
668 | * create orig_node / neigh_node for an unusable route. | ||
669 | */ | ||
670 | if (ogm_throughput == 0) { | ||
671 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
672 | "Drop packet: originator packet with troughput metric of 0\n"); | ||
673 | return; | ||
674 | } | ||
675 | |||
676 | /* require ELP packets be to received from this neighbor first */ | ||
677 | hardif_neigh = batadv_hardif_neigh_get(if_incoming, ethhdr->h_source); | ||
678 | if (!hardif_neigh) { | ||
679 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
680 | "Drop packet: OGM via unknown neighbor!\n"); | ||
681 | goto out; | ||
682 | } | ||
683 | |||
684 | orig_node = batadv_v_ogm_orig_get(bat_priv, ogm_packet->orig); | ||
685 | if (!orig_node) | ||
686 | return; | ||
687 | |||
688 | neigh_node = batadv_neigh_node_new(orig_node, if_incoming, | ||
689 | ethhdr->h_source); | ||
690 | if (!neigh_node) | ||
691 | goto out; | ||
692 | |||
693 | /* Update the received throughput metric to match the link | ||
694 | * characteristic: | ||
695 | * - If this OGM traveled one hop so far (emitted by single hop | ||
696 | * neighbor) the path throughput metric equals the link throughput. | ||
697 | * - For OGMs traversing more than hop the path throughput metric is | ||
698 | * the smaller of the path throughput and the link throughput. | ||
699 | */ | ||
700 | link_throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); | ||
701 | path_throughput = min_t(u32, link_throughput, ogm_throughput); | ||
702 | ogm_packet->throughput = htonl(path_throughput); | ||
703 | |||
704 | batadv_v_ogm_process_per_outif(bat_priv, ethhdr, ogm_packet, orig_node, | ||
705 | neigh_node, if_incoming, | ||
706 | BATADV_IF_DEFAULT); | ||
707 | |||
708 | rcu_read_lock(); | ||
709 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { | ||
710 | if (hard_iface->if_status != BATADV_IF_ACTIVE) | ||
711 | continue; | ||
712 | |||
713 | if (hard_iface->soft_iface != bat_priv->soft_iface) | ||
714 | continue; | ||
715 | |||
716 | batadv_v_ogm_process_per_outif(bat_priv, ethhdr, ogm_packet, | ||
717 | orig_node, neigh_node, | ||
718 | if_incoming, hard_iface); | ||
719 | } | ||
720 | rcu_read_unlock(); | ||
721 | out: | ||
722 | if (orig_node) | ||
723 | batadv_orig_node_put(orig_node); | ||
724 | if (neigh_node) | ||
725 | batadv_neigh_node_put(neigh_node); | ||
726 | if (hardif_neigh) | ||
727 | batadv_hardif_neigh_put(hardif_neigh); | ||
728 | } | ||
729 | |||
730 | /** | ||
196 | * batadv_v_ogm_packet_recv - OGM2 receiving handler | 731 | * batadv_v_ogm_packet_recv - OGM2 receiving handler |
197 | * @skb: the received OGM | 732 | * @skb: the received OGM |
198 | * @if_incoming: the interface where this OGM has been received | 733 | * @if_incoming: the interface where this OGM has been received |
@@ -206,6 +741,9 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb, | |||
206 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | 741 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
207 | struct batadv_ogm2_packet *ogm_packet; | 742 | struct batadv_ogm2_packet *ogm_packet; |
208 | struct ethhdr *ethhdr = eth_hdr(skb); | 743 | struct ethhdr *ethhdr = eth_hdr(skb); |
744 | int ogm_offset; | ||
745 | u8 *packet_pos; | ||
746 | int ret = NET_RX_DROP; | ||
209 | 747 | ||
210 | /* did we receive a OGM2 packet on an interface that does not have | 748 | /* did we receive a OGM2 packet on an interface that does not have |
211 | * B.A.T.M.A.N. V enabled ? | 749 | * B.A.T.M.A.N. V enabled ? |
@@ -228,8 +766,24 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb, | |||
228 | batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES, | 766 | batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES, |
229 | skb->len + ETH_HLEN); | 767 | skb->len + ETH_HLEN); |
230 | 768 | ||
769 | ogm_offset = 0; | ||
770 | ogm_packet = (struct batadv_ogm2_packet *)skb->data; | ||
771 | |||
772 | while (batadv_v_ogm_aggr_packet(ogm_offset, skb_headlen(skb), | ||
773 | ogm_packet->tvlv_len)) { | ||
774 | batadv_v_ogm_process(skb, ogm_offset, if_incoming); | ||
775 | |||
776 | ogm_offset += BATADV_OGM2_HLEN; | ||
777 | ogm_offset += ntohs(ogm_packet->tvlv_len); | ||
778 | |||
779 | packet_pos = skb->data + ogm_offset; | ||
780 | ogm_packet = (struct batadv_ogm2_packet *)packet_pos; | ||
781 | } | ||
782 | |||
783 | ret = NET_RX_SUCCESS; | ||
231 | consume_skb(skb); | 784 | consume_skb(skb); |
232 | return NET_RX_SUCCESS; | 785 | |
786 | return ret; | ||
233 | } | 787 | } |
234 | 788 | ||
235 | /** | 789 | /** |