aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/routing.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/batman-adv/routing.c')
-rw-r--r--net/batman-adv/routing.c118
1 files changed, 63 insertions, 55 deletions
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 19499281b695..6efd1d0da54a 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -130,7 +130,7 @@ out:
130 130
131static int is_bidirectional_neigh(struct orig_node *orig_node, 131static int is_bidirectional_neigh(struct orig_node *orig_node,
132 struct orig_node *orig_neigh_node, 132 struct orig_node *orig_neigh_node,
133 struct batman_packet *batman_packet, 133 struct batman_ogm_packet *batman_ogm_packet,
134 struct hard_iface *if_incoming) 134 struct hard_iface *if_incoming)
135{ 135{
136 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 136 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
@@ -209,7 +209,8 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
209 TQ_LOCAL_WINDOW_SIZE * 209 TQ_LOCAL_WINDOW_SIZE *
210 TQ_LOCAL_WINDOW_SIZE); 210 TQ_LOCAL_WINDOW_SIZE);
211 211
212 batman_packet->tq = ((batman_packet->tq * tq_own * tq_asym_penalty) / 212 batman_ogm_packet->tq = ((batman_ogm_packet->tq * tq_own
213 * tq_asym_penalty) /
213 (TQ_MAX_VALUE * TQ_MAX_VALUE)); 214 (TQ_MAX_VALUE * TQ_MAX_VALUE));
214 215
215 bat_dbg(DBG_BATMAN, bat_priv, 216 bat_dbg(DBG_BATMAN, bat_priv,
@@ -218,11 +219,11 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
218 "real recv = %2i, local tq: %3i, asym_penalty: %3i, " 219 "real recv = %2i, local tq: %3i, asym_penalty: %3i, "
219 "total tq: %3i\n", 220 "total tq: %3i\n",
220 orig_node->orig, orig_neigh_node->orig, total_count, 221 orig_node->orig, orig_neigh_node->orig, total_count,
221 neigh_rq_count, tq_own, tq_asym_penalty, batman_packet->tq); 222 neigh_rq_count, tq_own, tq_asym_penalty, batman_ogm_packet->tq);
222 223
223 /* if link has the minimum required transmission quality 224 /* if link has the minimum required transmission quality
224 * consider it bidirectional */ 225 * consider it bidirectional */
225 if (batman_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT) 226 if (batman_ogm_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT)
226 ret = 1; 227 ret = 1;
227 228
228out: 229out:
@@ -321,9 +322,10 @@ out:
321/* copy primary address for bonding */ 322/* copy primary address for bonding */
322static void bonding_save_primary(const struct orig_node *orig_node, 323static void bonding_save_primary(const struct orig_node *orig_node,
323 struct orig_node *orig_neigh_node, 324 struct orig_node *orig_neigh_node,
324 const struct batman_packet *batman_packet) 325 const struct batman_ogm_packet
326 *batman_ogm_packet)
325{ 327{
326 if (!(batman_packet->flags & PRIMARIES_FIRST_HOP)) 328 if (!(batman_ogm_packet->flags & PRIMARIES_FIRST_HOP))
327 return; 329 return;
328 330
329 memcpy(orig_neigh_node->primary_addr, orig_node->orig, ETH_ALEN); 331 memcpy(orig_neigh_node->primary_addr, orig_node->orig, ETH_ALEN);
@@ -331,7 +333,7 @@ static void bonding_save_primary(const struct orig_node *orig_node,
331 333
332static void update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node, 334static void update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
333 const struct ethhdr *ethhdr, 335 const struct ethhdr *ethhdr,
334 const struct batman_packet *batman_packet, 336 const struct batman_ogm_packet *batman_ogm_packet,
335 struct hard_iface *if_incoming, 337 struct hard_iface *if_incoming,
336 const unsigned char *tt_buff, int is_duplicate) 338 const unsigned char *tt_buff, int is_duplicate)
337{ 339{
@@ -386,19 +388,19 @@ static void update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
386 388
387 rcu_read_unlock(); 389 rcu_read_unlock();
388 390
389 orig_node->flags = batman_packet->flags; 391 orig_node->flags = batman_ogm_packet->flags;
390 neigh_node->last_valid = jiffies; 392 neigh_node->last_valid = jiffies;
391 393
392 spin_lock_bh(&neigh_node->tq_lock); 394 spin_lock_bh(&neigh_node->tq_lock);
393 ring_buffer_set(neigh_node->tq_recv, 395 ring_buffer_set(neigh_node->tq_recv,
394 &neigh_node->tq_index, 396 &neigh_node->tq_index,
395 batman_packet->tq); 397 batman_ogm_packet->tq);
396 neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv); 398 neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);
397 spin_unlock_bh(&neigh_node->tq_lock); 399 spin_unlock_bh(&neigh_node->tq_lock);
398 400
399 if (!is_duplicate) { 401 if (!is_duplicate) {
400 orig_node->last_ttl = batman_packet->ttl; 402 orig_node->last_ttl = batman_ogm_packet->ttl;
401 neigh_node->last_ttl = batman_packet->ttl; 403 neigh_node->last_ttl = batman_ogm_packet->ttl;
402 } 404 }
403 405
404 bonding_candidate_add(orig_node, neigh_node); 406 bonding_candidate_add(orig_node, neigh_node);
@@ -437,17 +439,19 @@ static void update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
437update_tt: 439update_tt:
438 /* I have to check for transtable changes only if the OGM has been 440 /* I have to check for transtable changes only if the OGM has been
439 * sent through a primary interface */ 441 * sent through a primary interface */
440 if (((batman_packet->orig != ethhdr->h_source) && 442 if (((batman_ogm_packet->orig != ethhdr->h_source) &&
441 (batman_packet->ttl > 2)) || 443 (batman_ogm_packet->ttl > 2)) ||
442 (batman_packet->flags & PRIMARIES_FIRST_HOP)) 444 (batman_ogm_packet->flags & PRIMARIES_FIRST_HOP))
443 tt_update_orig(bat_priv, orig_node, tt_buff, 445 tt_update_orig(bat_priv, orig_node, tt_buff,
444 batman_packet->tt_num_changes, 446 batman_ogm_packet->tt_num_changes,
445 batman_packet->ttvn, batman_packet->tt_crc); 447 batman_ogm_packet->ttvn,
448 batman_ogm_packet->tt_crc);
446 449
447 if (orig_node->gw_flags != batman_packet->gw_flags) 450 if (orig_node->gw_flags != batman_ogm_packet->gw_flags)
448 gw_node_update(bat_priv, orig_node, batman_packet->gw_flags); 451 gw_node_update(bat_priv, orig_node,
452 batman_ogm_packet->gw_flags);
449 453
450 orig_node->gw_flags = batman_packet->gw_flags; 454 orig_node->gw_flags = batman_ogm_packet->gw_flags;
451 455
452 /* restart gateway selection if fast or late switching was enabled */ 456 /* restart gateway selection if fast or late switching was enabled */
453 if ((orig_node->gw_flags) && 457 if ((orig_node->gw_flags) &&
@@ -500,8 +504,8 @@ static int window_protected(struct bat_priv *bat_priv,
500 * was protected. Caller should drop it. 504 * was protected. Caller should drop it.
501 */ 505 */
502static int count_real_packets(const struct ethhdr *ethhdr, 506static int count_real_packets(const struct ethhdr *ethhdr,
503 const struct batman_packet *batman_packet, 507 const struct batman_ogm_packet *batman_ogm_packet,
504 const struct hard_iface *if_incoming) 508 const struct hard_iface *if_incoming)
505{ 509{
506 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 510 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
507 struct orig_node *orig_node; 511 struct orig_node *orig_node;
@@ -512,12 +516,12 @@ static int count_real_packets(const struct ethhdr *ethhdr,
512 int need_update = 0; 516 int need_update = 0;
513 int set_mark, ret = -1; 517 int set_mark, ret = -1;
514 518
515 orig_node = get_orig_node(bat_priv, batman_packet->orig); 519 orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig);
516 if (!orig_node) 520 if (!orig_node)
517 return 0; 521 return 0;
518 522
519 spin_lock_bh(&orig_node->ogm_cnt_lock); 523 spin_lock_bh(&orig_node->ogm_cnt_lock);
520 seq_diff = batman_packet->seqno - orig_node->last_real_seqno; 524 seq_diff = batman_ogm_packet->seqno - orig_node->last_real_seqno;
521 525
522 /* signalize caller that the packet is to be dropped. */ 526 /* signalize caller that the packet is to be dropped. */
523 if (window_protected(bat_priv, seq_diff, 527 if (window_protected(bat_priv, seq_diff,
@@ -530,7 +534,7 @@ static int count_real_packets(const struct ethhdr *ethhdr,
530 534
531 is_duplicate |= get_bit_status(tmp_neigh_node->real_bits, 535 is_duplicate |= get_bit_status(tmp_neigh_node->real_bits,
532 orig_node->last_real_seqno, 536 orig_node->last_real_seqno,
533 batman_packet->seqno); 537 batman_ogm_packet->seqno);
534 538
535 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) && 539 if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
536 (tmp_neigh_node->if_incoming == if_incoming)) 540 (tmp_neigh_node->if_incoming == if_incoming))
@@ -551,8 +555,8 @@ static int count_real_packets(const struct ethhdr *ethhdr,
551 if (need_update) { 555 if (need_update) {
552 bat_dbg(DBG_BATMAN, bat_priv, 556 bat_dbg(DBG_BATMAN, bat_priv,
553 "updating last_seqno: old %d, new %d\n", 557 "updating last_seqno: old %d, new %d\n",
554 orig_node->last_real_seqno, batman_packet->seqno); 558 orig_node->last_real_seqno, batman_ogm_packet->seqno);
555 orig_node->last_real_seqno = batman_packet->seqno; 559 orig_node->last_real_seqno = batman_ogm_packet->seqno;
556 } 560 }
557 561
558 ret = is_duplicate; 562 ret = is_duplicate;
@@ -564,7 +568,7 @@ out:
564} 568}
565 569
566void receive_bat_packet(const struct ethhdr *ethhdr, 570void receive_bat_packet(const struct ethhdr *ethhdr,
567 struct batman_packet *batman_packet, 571 struct batman_ogm_packet *batman_ogm_packet,
568 const unsigned char *tt_buff, 572 const unsigned char *tt_buff,
569 struct hard_iface *if_incoming) 573 struct hard_iface *if_incoming)
570{ 574{
@@ -587,31 +591,31 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
587 * it as an additional length. 591 * it as an additional length.
588 * 592 *
589 * TODO: A more sane solution would be to have a bit in the 593 * TODO: A more sane solution would be to have a bit in the
590 * batman_packet to detect whether the packet is the last 594 * batman_ogm_packet to detect whether the packet is the last
591 * packet in an aggregation. Here we expect that the padding 595 * packet in an aggregation. Here we expect that the padding
592 * is always zero (or not 0x01) 596 * is always zero (or not 0x01)
593 */ 597 */
594 if (batman_packet->packet_type != BAT_PACKET) 598 if (batman_ogm_packet->packet_type != BAT_OGM)
595 return; 599 return;
596 600
597 /* could be changed by schedule_own_packet() */ 601 /* could be changed by schedule_own_packet() */
598 if_incoming_seqno = atomic_read(&if_incoming->seqno); 602 if_incoming_seqno = atomic_read(&if_incoming->seqno);
599 603
600 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0); 604 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
601 605
602 is_single_hop_neigh = (compare_eth(ethhdr->h_source, 606 is_single_hop_neigh = (compare_eth(ethhdr->h_source,
603 batman_packet->orig) ? 1 : 0); 607 batman_ogm_packet->orig) ? 1 : 0);
604 608
605 bat_dbg(DBG_BATMAN, bat_priv, 609 bat_dbg(DBG_BATMAN, bat_priv,
606 "Received BATMAN packet via NB: %pM, IF: %s [%pM] " 610 "Received BATMAN packet via NB: %pM, IF: %s [%pM] "
607 "(from OG: %pM, via prev OG: %pM, seqno %d, ttvn %u, " 611 "(from OG: %pM, via prev OG: %pM, seqno %d, ttvn %u, "
608 "crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n", 612 "crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n",
609 ethhdr->h_source, if_incoming->net_dev->name, 613 ethhdr->h_source, if_incoming->net_dev->name,
610 if_incoming->net_dev->dev_addr, batman_packet->orig, 614 if_incoming->net_dev->dev_addr, batman_ogm_packet->orig,
611 batman_packet->prev_sender, batman_packet->seqno, 615 batman_ogm_packet->prev_sender, batman_ogm_packet->seqno,
612 batman_packet->ttvn, batman_packet->tt_crc, 616 batman_ogm_packet->ttvn, batman_ogm_packet->tt_crc,
613 batman_packet->tt_num_changes, batman_packet->tq, 617 batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq,
614 batman_packet->ttl, batman_packet->version, 618 batman_ogm_packet->ttl, batman_ogm_packet->version,
615 has_directlink_flag); 619 has_directlink_flag);
616 620
617 rcu_read_lock(); 621 rcu_read_lock();
@@ -626,11 +630,11 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
626 hard_iface->net_dev->dev_addr)) 630 hard_iface->net_dev->dev_addr))
627 is_my_addr = 1; 631 is_my_addr = 1;
628 632
629 if (compare_eth(batman_packet->orig, 633 if (compare_eth(batman_ogm_packet->orig,
630 hard_iface->net_dev->dev_addr)) 634 hard_iface->net_dev->dev_addr))
631 is_my_orig = 1; 635 is_my_orig = 1;
632 636
633 if (compare_eth(batman_packet->prev_sender, 637 if (compare_eth(batman_ogm_packet->prev_sender,
634 hard_iface->net_dev->dev_addr)) 638 hard_iface->net_dev->dev_addr))
635 is_my_oldorig = 1; 639 is_my_oldorig = 1;
636 640
@@ -639,10 +643,10 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
639 } 643 }
640 rcu_read_unlock(); 644 rcu_read_unlock();
641 645
642 if (batman_packet->version != COMPAT_VERSION) { 646 if (batman_ogm_packet->version != COMPAT_VERSION) {
643 bat_dbg(DBG_BATMAN, bat_priv, 647 bat_dbg(DBG_BATMAN, bat_priv,
644 "Drop packet: incompatible batman version (%i)\n", 648 "Drop packet: incompatible batman version (%i)\n",
645 batman_packet->version); 649 batman_ogm_packet->version);
646 return; 650 return;
647 } 651 }
648 652
@@ -674,13 +678,14 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
674 /* save packet seqno for bidirectional check */ 678 /* save packet seqno for bidirectional check */
675 if (has_directlink_flag && 679 if (has_directlink_flag &&
676 compare_eth(if_incoming->net_dev->dev_addr, 680 compare_eth(if_incoming->net_dev->dev_addr,
677 batman_packet->orig)) { 681 batman_ogm_packet->orig)) {
678 offset = if_incoming->if_num * NUM_WORDS; 682 offset = if_incoming->if_num * NUM_WORDS;
679 683
680 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock); 684 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock);
681 word = &(orig_neigh_node->bcast_own[offset]); 685 word = &(orig_neigh_node->bcast_own[offset]);
682 bit_mark(word, 686 bit_mark(word,
683 if_incoming_seqno - batman_packet->seqno - 2); 687 if_incoming_seqno -
688 batman_ogm_packet->seqno - 2);
684 orig_neigh_node->bcast_own_sum[if_incoming->if_num] = 689 orig_neigh_node->bcast_own_sum[if_incoming->if_num] =
685 bit_packet_count(word); 690 bit_packet_count(word);
686 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock); 691 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock);
@@ -699,11 +704,12 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
699 return; 704 return;
700 } 705 }
701 706
702 orig_node = get_orig_node(bat_priv, batman_packet->orig); 707 orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig);
703 if (!orig_node) 708 if (!orig_node)
704 return; 709 return;
705 710
706 is_duplicate = count_real_packets(ethhdr, batman_packet, if_incoming); 711 is_duplicate = count_real_packets(ethhdr, batman_ogm_packet,
712 if_incoming);
707 713
708 if (is_duplicate == -1) { 714 if (is_duplicate == -1) {
709 bat_dbg(DBG_BATMAN, bat_priv, 715 bat_dbg(DBG_BATMAN, bat_priv,
@@ -712,7 +718,7 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
712 goto out; 718 goto out;
713 } 719 }
714 720
715 if (batman_packet->tq == 0) { 721 if (batman_ogm_packet->tq == 0) {
716 bat_dbg(DBG_BATMAN, bat_priv, 722 bat_dbg(DBG_BATMAN, bat_priv,
717 "Drop packet: originator packet with tq equal 0\n"); 723 "Drop packet: originator packet with tq equal 0\n");
718 goto out; 724 goto out;
@@ -724,8 +730,9 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
724 730
725 /* avoid temporary routing loops */ 731 /* avoid temporary routing loops */
726 if (router && router_router && 732 if (router && router_router &&
727 (compare_eth(router->addr, batman_packet->prev_sender)) && 733 (compare_eth(router->addr, batman_ogm_packet->prev_sender)) &&
728 !(compare_eth(batman_packet->orig, batman_packet->prev_sender)) && 734 !(compare_eth(batman_ogm_packet->orig,
735 batman_ogm_packet->prev_sender)) &&
729 (compare_eth(router->addr, router_router->addr))) { 736 (compare_eth(router->addr, router_router->addr))) {
730 bat_dbg(DBG_BATMAN, bat_priv, 737 bat_dbg(DBG_BATMAN, bat_priv,
731 "Drop packet: ignoring all rebroadcast packets that " 738 "Drop packet: ignoring all rebroadcast packets that "
@@ -752,24 +759,25 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
752 } 759 }
753 760
754 is_bidirectional = is_bidirectional_neigh(orig_node, orig_neigh_node, 761 is_bidirectional = is_bidirectional_neigh(orig_node, orig_neigh_node,
755 batman_packet, if_incoming); 762 batman_ogm_packet,
763 if_incoming);
756 764
757 bonding_save_primary(orig_node, orig_neigh_node, batman_packet); 765 bonding_save_primary(orig_node, orig_neigh_node, batman_ogm_packet);
758 766
759 /* update ranking if it is not a duplicate or has the same 767 /* update ranking if it is not a duplicate or has the same
760 * seqno and similar ttl as the non-duplicate */ 768 * seqno and similar ttl as the non-duplicate */
761 if (is_bidirectional && 769 if (is_bidirectional &&
762 (!is_duplicate || 770 (!is_duplicate ||
763 ((orig_node->last_real_seqno == batman_packet->seqno) && 771 ((orig_node->last_real_seqno == batman_ogm_packet->seqno) &&
764 (orig_node->last_ttl - 3 <= batman_packet->ttl)))) 772 (orig_node->last_ttl - 3 <= batman_ogm_packet->ttl))))
765 update_orig(bat_priv, orig_node, ethhdr, batman_packet, 773 update_orig(bat_priv, orig_node, ethhdr, batman_ogm_packet,
766 if_incoming, tt_buff, is_duplicate); 774 if_incoming, tt_buff, is_duplicate);
767 775
768 /* is single hop (direct) neighbor */ 776 /* is single hop (direct) neighbor */
769 if (is_single_hop_neigh) { 777 if (is_single_hop_neigh) {
770 778
771 /* mark direct link on incoming interface */ 779 /* mark direct link on incoming interface */
772 schedule_forward_packet(orig_node, ethhdr, batman_packet, 780 schedule_forward_packet(orig_node, ethhdr, batman_ogm_packet,
773 1, if_incoming); 781 1, if_incoming);
774 782
775 bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: " 783 bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: "
@@ -792,7 +800,7 @@ void receive_bat_packet(const struct ethhdr *ethhdr,
792 800
793 bat_dbg(DBG_BATMAN, bat_priv, 801 bat_dbg(DBG_BATMAN, bat_priv,
794 "Forwarding packet: rebroadcast originator packet\n"); 802 "Forwarding packet: rebroadcast originator packet\n");
795 schedule_forward_packet(orig_node, ethhdr, batman_packet, 803 schedule_forward_packet(orig_node, ethhdr, batman_ogm_packet,
796 0, if_incoming); 804 0, if_incoming);
797 805
798out_neigh: 806out_neigh:
@@ -814,7 +822,7 @@ int recv_bat_packet(struct sk_buff *skb, struct hard_iface *hard_iface)
814 struct ethhdr *ethhdr; 822 struct ethhdr *ethhdr;
815 823
816 /* drop packet if it has not necessary minimum size */ 824 /* drop packet if it has not necessary minimum size */
817 if (unlikely(!pskb_may_pull(skb, sizeof(struct batman_packet)))) 825 if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_LEN)))
818 return NET_RX_DROP; 826 return NET_RX_DROP;
819 827
820 ethhdr = (struct ethhdr *)skb_mac_header(skb); 828 ethhdr = (struct ethhdr *)skb_mac_header(skb);