diff options
author | Antonio Quartulli <antonio@open-mesh.com> | 2013-09-02 06:15:01 -0400 |
---|---|---|
committer | Antonio Quartulli <antonio@meshcoding.com> | 2013-10-23 09:33:08 -0400 |
commit | 0538f7599157b7bdef1814472048de5351c4fd6d (patch) | |
tree | 993f541259033b13a2d7847a2c735baf653b2130 /net/batman-adv/bat_iv_ogm.c | |
parent | 47d4ab91e4472723f181075c81627374ca86816c (diff) |
batman-adv: make struct batadv_neigh_node algorithm agnostic
some of the fields in struct batadv_neigh_node are strictly
related to the B.A.T.M.A.N. IV algorithm. In order to
make the struct usable by any routing algorithm it has to be
split and made more generic
Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/bat_iv_ogm.c')
-rw-r--r-- | net/batman-adv/bat_iv_ogm.c | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 97b42d3c4bef..a2a04982a22b 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c | |||
@@ -93,16 +93,18 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, | |||
93 | struct batadv_orig_node *orig_node, | 93 | struct batadv_orig_node *orig_node, |
94 | struct batadv_orig_node *orig_neigh) | 94 | struct batadv_orig_node *orig_neigh) |
95 | { | 95 | { |
96 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | ||
96 | struct batadv_neigh_node *neigh_node; | 97 | struct batadv_neigh_node *neigh_node; |
97 | 98 | ||
98 | neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr); | 99 | neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr, orig_node); |
99 | if (!neigh_node) | 100 | if (!neigh_node) |
100 | goto out; | 101 | goto out; |
101 | 102 | ||
102 | INIT_LIST_HEAD(&neigh_node->bonding_list); | 103 | spin_lock_init(&neigh_node->bat_iv.lq_update_lock); |
103 | 104 | ||
104 | neigh_node->orig_node = orig_neigh; | 105 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
105 | neigh_node->if_incoming = hard_iface; | 106 | "Creating new neighbor %pM for orig_node %pM on interface %s\n", |
107 | neigh_addr, orig_node->orig, hard_iface->net_dev->name); | ||
106 | 108 | ||
107 | spin_lock_bh(&orig_node->neigh_list_lock); | 109 | spin_lock_bh(&orig_node->neigh_list_lock); |
108 | hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); | 110 | hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); |
@@ -755,12 +757,12 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, | |||
755 | if (dup_status != BATADV_NO_DUP) | 757 | if (dup_status != BATADV_NO_DUP) |
756 | continue; | 758 | continue; |
757 | 759 | ||
758 | spin_lock_bh(&tmp_neigh_node->lq_update_lock); | 760 | spin_lock_bh(&tmp_neigh_node->bat_iv.lq_update_lock); |
759 | batadv_ring_buffer_set(tmp_neigh_node->tq_recv, | 761 | batadv_ring_buffer_set(tmp_neigh_node->bat_iv.tq_recv, |
760 | &tmp_neigh_node->tq_index, 0); | 762 | &tmp_neigh_node->bat_iv.tq_index, 0); |
761 | tq_avg = batadv_ring_buffer_avg(tmp_neigh_node->tq_recv); | 763 | tq_avg = batadv_ring_buffer_avg(tmp_neigh_node->bat_iv.tq_recv); |
762 | tmp_neigh_node->tq_avg = tq_avg; | 764 | tmp_neigh_node->bat_iv.tq_avg = tq_avg; |
763 | spin_unlock_bh(&tmp_neigh_node->lq_update_lock); | 765 | spin_unlock_bh(&tmp_neigh_node->bat_iv.lq_update_lock); |
764 | } | 766 | } |
765 | 767 | ||
766 | if (!neigh_node) { | 768 | if (!neigh_node) { |
@@ -785,12 +787,13 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, | |||
785 | 787 | ||
786 | neigh_node->last_seen = jiffies; | 788 | neigh_node->last_seen = jiffies; |
787 | 789 | ||
788 | spin_lock_bh(&neigh_node->lq_update_lock); | 790 | spin_lock_bh(&neigh_node->bat_iv.lq_update_lock); |
789 | batadv_ring_buffer_set(neigh_node->tq_recv, | 791 | batadv_ring_buffer_set(neigh_node->bat_iv.tq_recv, |
790 | &neigh_node->tq_index, | 792 | &neigh_node->bat_iv.tq_index, |
791 | batadv_ogm_packet->tq); | 793 | batadv_ogm_packet->tq); |
792 | neigh_node->tq_avg = batadv_ring_buffer_avg(neigh_node->tq_recv); | 794 | tq_avg = batadv_ring_buffer_avg(neigh_node->bat_iv.tq_recv); |
793 | spin_unlock_bh(&neigh_node->lq_update_lock); | 795 | neigh_node->bat_iv.tq_avg = tq_avg; |
796 | spin_unlock_bh(&neigh_node->bat_iv.lq_update_lock); | ||
794 | 797 | ||
795 | if (dup_status == BATADV_NO_DUP) { | 798 | if (dup_status == BATADV_NO_DUP) { |
796 | orig_node->last_ttl = batadv_ogm_packet->header.ttl; | 799 | orig_node->last_ttl = batadv_ogm_packet->header.ttl; |
@@ -807,13 +810,13 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, | |||
807 | goto out; | 810 | goto out; |
808 | 811 | ||
809 | /* if this neighbor does not offer a better TQ we won't consider it */ | 812 | /* if this neighbor does not offer a better TQ we won't consider it */ |
810 | if (router && (router->tq_avg > neigh_node->tq_avg)) | 813 | if (router && (router->bat_iv.tq_avg > neigh_node->bat_iv.tq_avg)) |
811 | goto out; | 814 | goto out; |
812 | 815 | ||
813 | /* if the TQ is the same and the link not more symmetric we | 816 | /* if the TQ is the same and the link not more symmetric we |
814 | * won't consider it either | 817 | * won't consider it either |
815 | */ | 818 | */ |
816 | if (router && (neigh_node->tq_avg == router->tq_avg)) { | 819 | if (router && (neigh_node->bat_iv.tq_avg == router->bat_iv.tq_avg)) { |
817 | orig_node_tmp = router->orig_node; | 820 | orig_node_tmp = router->orig_node; |
818 | spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); | 821 | spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); |
819 | if_num = router->if_incoming->if_num; | 822 | if_num = router->if_incoming->if_num; |
@@ -892,7 +895,7 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node, | |||
892 | /* find packet count of corresponding one hop neighbor */ | 895 | /* find packet count of corresponding one hop neighbor */ |
893 | spin_lock_bh(&orig_node->ogm_cnt_lock); | 896 | spin_lock_bh(&orig_node->ogm_cnt_lock); |
894 | orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num]; | 897 | orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num]; |
895 | neigh_rq_count = neigh_node->real_packet_count; | 898 | neigh_rq_count = neigh_node->bat_iv.real_packet_count; |
896 | spin_unlock_bh(&orig_node->ogm_cnt_lock); | 899 | spin_unlock_bh(&orig_node->ogm_cnt_lock); |
897 | 900 | ||
898 | /* pay attention to not get a value bigger than 100 % */ | 901 | /* pay attention to not get a value bigger than 100 % */ |
@@ -975,6 +978,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, | |||
975 | uint32_t seqno = ntohl(batadv_ogm_packet->seqno); | 978 | uint32_t seqno = ntohl(batadv_ogm_packet->seqno); |
976 | uint8_t *neigh_addr; | 979 | uint8_t *neigh_addr; |
977 | uint8_t packet_count; | 980 | uint8_t packet_count; |
981 | unsigned long *bitmap; | ||
978 | 982 | ||
979 | orig_node = batadv_get_orig_node(bat_priv, batadv_ogm_packet->orig); | 983 | orig_node = batadv_get_orig_node(bat_priv, batadv_ogm_packet->orig); |
980 | if (!orig_node) | 984 | if (!orig_node) |
@@ -995,7 +999,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, | |||
995 | hlist_for_each_entry_rcu(tmp_neigh_node, | 999 | hlist_for_each_entry_rcu(tmp_neigh_node, |
996 | &orig_node->neigh_list, list) { | 1000 | &orig_node->neigh_list, list) { |
997 | neigh_addr = tmp_neigh_node->addr; | 1001 | neigh_addr = tmp_neigh_node->addr; |
998 | is_dup = batadv_test_bit(tmp_neigh_node->real_bits, | 1002 | is_dup = batadv_test_bit(tmp_neigh_node->bat_iv.real_bits, |
999 | orig_node->last_real_seqno, | 1003 | orig_node->last_real_seqno, |
1000 | seqno); | 1004 | seqno); |
1001 | 1005 | ||
@@ -1011,13 +1015,13 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, | |||
1011 | } | 1015 | } |
1012 | 1016 | ||
1013 | /* if the window moved, set the update flag. */ | 1017 | /* if the window moved, set the update flag. */ |
1014 | need_update |= batadv_bit_get_packet(bat_priv, | 1018 | bitmap = tmp_neigh_node->bat_iv.real_bits; |
1015 | tmp_neigh_node->real_bits, | 1019 | need_update |= batadv_bit_get_packet(bat_priv, bitmap, |
1016 | seq_diff, set_mark); | 1020 | seq_diff, set_mark); |
1017 | 1021 | ||
1018 | packet_count = bitmap_weight(tmp_neigh_node->real_bits, | 1022 | packet_count = bitmap_weight(tmp_neigh_node->bat_iv.real_bits, |
1019 | BATADV_TQ_LOCAL_WINDOW_SIZE); | 1023 | BATADV_TQ_LOCAL_WINDOW_SIZE); |
1020 | tmp_neigh_node->real_packet_count = packet_count; | 1024 | tmp_neigh_node->bat_iv.real_packet_count = packet_count; |
1021 | } | 1025 | } |
1022 | rcu_read_unlock(); | 1026 | rcu_read_unlock(); |
1023 | 1027 | ||
@@ -1041,7 +1045,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr, | |||
1041 | { | 1045 | { |
1042 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | 1046 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
1043 | struct batadv_hard_iface *hard_iface; | 1047 | struct batadv_hard_iface *hard_iface; |
1044 | struct batadv_orig_node *orig_neigh_node, *orig_node; | 1048 | struct batadv_orig_node *orig_neigh_node, *orig_node, *orig_node_tmp; |
1045 | struct batadv_neigh_node *router = NULL, *router_router = NULL; | 1049 | struct batadv_neigh_node *router = NULL, *router_router = NULL; |
1046 | struct batadv_neigh_node *orig_neigh_router = NULL; | 1050 | struct batadv_neigh_node *orig_neigh_router = NULL; |
1047 | int has_directlink_flag; | 1051 | int has_directlink_flag; |
@@ -1192,10 +1196,12 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr, | |||
1192 | } | 1196 | } |
1193 | 1197 | ||
1194 | router = batadv_orig_node_get_router(orig_node); | 1198 | router = batadv_orig_node_get_router(orig_node); |
1195 | if (router) | 1199 | if (router) { |
1196 | router_router = batadv_orig_node_get_router(router->orig_node); | 1200 | orig_node_tmp = router->orig_node; |
1201 | router_router = batadv_orig_node_get_router(orig_node_tmp); | ||
1202 | } | ||
1197 | 1203 | ||
1198 | if ((router && router->tq_avg != 0) && | 1204 | if ((router && router->bat_iv.tq_avg != 0) && |
1199 | (batadv_compare_eth(router->addr, ethhdr->h_source))) | 1205 | (batadv_compare_eth(router->addr, ethhdr->h_source))) |
1200 | is_from_best_next_hop = true; | 1206 | is_from_best_next_hop = true; |
1201 | 1207 | ||