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 | |
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')
-rw-r--r-- | net/batman-adv/bat_iv_ogm.c | 60 | ||||
-rw-r--r-- | net/batman-adv/gateway_client.c | 16 | ||||
-rw-r--r-- | net/batman-adv/network-coding.c | 8 | ||||
-rw-r--r-- | net/batman-adv/originator.c | 33 | ||||
-rw-r--r-- | net/batman-adv/originator.h | 3 | ||||
-rw-r--r-- | net/batman-adv/routing.c | 9 | ||||
-rw-r--r-- | net/batman-adv/translation-table.c | 4 | ||||
-rw-r--r-- | net/batman-adv/types.h | 41 |
8 files changed, 103 insertions, 71 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 | ||
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 20fa053b7f57..2449afaa7638 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c | |||
@@ -137,7 +137,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv) | |||
137 | if (!atomic_inc_not_zero(&gw_node->refcount)) | 137 | if (!atomic_inc_not_zero(&gw_node->refcount)) |
138 | goto next; | 138 | goto next; |
139 | 139 | ||
140 | tq_avg = router->tq_avg; | 140 | tq_avg = router->bat_iv.tq_avg; |
141 | 141 | ||
142 | switch (atomic_read(&bat_priv->gw_sel_class)) { | 142 | switch (atomic_read(&bat_priv->gw_sel_class)) { |
143 | case 1: /* fast connection */ | 143 | case 1: /* fast connection */ |
@@ -256,7 +256,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv) | |||
256 | next_gw->bandwidth_down / 10, | 256 | next_gw->bandwidth_down / 10, |
257 | next_gw->bandwidth_down % 10, | 257 | next_gw->bandwidth_down % 10, |
258 | next_gw->bandwidth_up / 10, | 258 | next_gw->bandwidth_up / 10, |
259 | next_gw->bandwidth_up % 10, router->tq_avg); | 259 | next_gw->bandwidth_up % 10, router->bat_iv.tq_avg); |
260 | batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD, | 260 | batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD, |
261 | gw_addr); | 261 | gw_addr); |
262 | } else { | 262 | } else { |
@@ -266,7 +266,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv) | |||
266 | next_gw->bandwidth_down / 10, | 266 | next_gw->bandwidth_down / 10, |
267 | next_gw->bandwidth_down % 10, | 267 | next_gw->bandwidth_down % 10, |
268 | next_gw->bandwidth_up / 10, | 268 | next_gw->bandwidth_up / 10, |
269 | next_gw->bandwidth_up % 10, router->tq_avg); | 269 | next_gw->bandwidth_up % 10, router->bat_iv.tq_avg); |
270 | batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE, | 270 | batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE, |
271 | gw_addr); | 271 | gw_addr); |
272 | } | 272 | } |
@@ -305,8 +305,8 @@ void batadv_gw_check_election(struct batadv_priv *bat_priv, | |||
305 | if (!router_orig) | 305 | if (!router_orig) |
306 | goto out; | 306 | goto out; |
307 | 307 | ||
308 | gw_tq_avg = router_gw->tq_avg; | 308 | gw_tq_avg = router_gw->bat_iv.tq_avg; |
309 | orig_tq_avg = router_orig->tq_avg; | 309 | orig_tq_avg = router_orig->bat_iv.tq_avg; |
310 | 310 | ||
311 | /* the TQ value has to be better */ | 311 | /* the TQ value has to be better */ |
312 | if (orig_tq_avg < gw_tq_avg) | 312 | if (orig_tq_avg < gw_tq_avg) |
@@ -528,7 +528,7 @@ static int batadv_write_buffer_text(struct batadv_priv *bat_priv, | |||
528 | ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n", | 528 | ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n", |
529 | (curr_gw == gw_node ? "=>" : " "), | 529 | (curr_gw == gw_node ? "=>" : " "), |
530 | gw_node->orig_node->orig, | 530 | gw_node->orig_node->orig, |
531 | router->tq_avg, router->addr, | 531 | router->bat_iv.tq_avg, router->addr, |
532 | router->if_incoming->net_dev->name, | 532 | router->if_incoming->net_dev->name, |
533 | gw_node->bandwidth_down / 10, | 533 | gw_node->bandwidth_down / 10, |
534 | gw_node->bandwidth_down % 10, | 534 | gw_node->bandwidth_down % 10, |
@@ -792,7 +792,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, | |||
792 | if (!neigh_curr) | 792 | if (!neigh_curr) |
793 | goto out; | 793 | goto out; |
794 | 794 | ||
795 | curr_tq_avg = neigh_curr->tq_avg; | 795 | curr_tq_avg = neigh_curr->bat_iv.tq_avg; |
796 | break; | 796 | break; |
797 | case BATADV_GW_MODE_OFF: | 797 | case BATADV_GW_MODE_OFF: |
798 | default: | 798 | default: |
@@ -803,7 +803,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, | |||
803 | if (!neigh_old) | 803 | if (!neigh_old) |
804 | goto out; | 804 | goto out; |
805 | 805 | ||
806 | if (curr_tq_avg - neigh_old->tq_avg > BATADV_GW_THRESHOLD) | 806 | if (curr_tq_avg - neigh_old->bat_iv.tq_avg > BATADV_GW_THRESHOLD) |
807 | out_of_range = true; | 807 | out_of_range = true; |
808 | 808 | ||
809 | out: | 809 | out: |
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c index 23f611bedb0f..351e199bc0af 100644 --- a/net/batman-adv/network-coding.c +++ b/net/batman-adv/network-coding.c | |||
@@ -1003,7 +1003,7 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv, | |||
1003 | struct batadv_nc_packet *nc_packet, | 1003 | struct batadv_nc_packet *nc_packet, |
1004 | struct batadv_neigh_node *neigh_node) | 1004 | struct batadv_neigh_node *neigh_node) |
1005 | { | 1005 | { |
1006 | uint8_t tq_weighted_neigh, tq_weighted_coding; | 1006 | uint8_t tq_weighted_neigh, tq_weighted_coding, tq_tmp; |
1007 | struct sk_buff *skb_dest, *skb_src; | 1007 | struct sk_buff *skb_dest, *skb_src; |
1008 | struct batadv_unicast_packet *packet1; | 1008 | struct batadv_unicast_packet *packet1; |
1009 | struct batadv_unicast_packet *packet2; | 1009 | struct batadv_unicast_packet *packet2; |
@@ -1028,8 +1028,10 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv, | |||
1028 | if (!router_coding) | 1028 | if (!router_coding) |
1029 | goto out; | 1029 | goto out; |
1030 | 1030 | ||
1031 | tq_weighted_neigh = batadv_nc_random_weight_tq(router_neigh->tq_avg); | 1031 | tq_tmp = batadv_nc_random_weight_tq(router_neigh->bat_iv.tq_avg); |
1032 | tq_weighted_coding = batadv_nc_random_weight_tq(router_coding->tq_avg); | 1032 | tq_weighted_neigh = tq_tmp; |
1033 | tq_tmp = batadv_nc_random_weight_tq(router_coding->bat_iv.tq_avg); | ||
1034 | tq_weighted_coding = tq_tmp; | ||
1033 | 1035 | ||
1034 | /* Select one destination for the MAC-header dst-field based on | 1036 | /* Select one destination for the MAC-header dst-field based on |
1035 | * weighted TQ-values. | 1037 | * weighted TQ-values. |
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index ee1d84724205..50f6d9964780 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c | |||
@@ -172,11 +172,20 @@ batadv_orig_node_get_router(struct batadv_orig_node *orig_node) | |||
172 | return router; | 172 | return router; |
173 | } | 173 | } |
174 | 174 | ||
175 | /** | ||
176 | * batadv_neigh_node_new - create and init a new neigh_node object | ||
177 | * @hard_iface: the interface where the neighbour is connected to | ||
178 | * @neigh_addr: the mac address of the neighbour interface | ||
179 | * @orig_node: originator object representing the neighbour | ||
180 | * | ||
181 | * Allocates a new neigh_node object and initialises all the generic fields. | ||
182 | * Returns the new object or NULL on failure. | ||
183 | */ | ||
175 | struct batadv_neigh_node * | 184 | struct batadv_neigh_node * |
176 | batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, | 185 | batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, |
177 | const uint8_t *neigh_addr) | 186 | const uint8_t *neigh_addr, |
187 | struct batadv_orig_node *orig_node) | ||
178 | { | 188 | { |
179 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | ||
180 | struct batadv_neigh_node *neigh_node; | 189 | struct batadv_neigh_node *neigh_node; |
181 | 190 | ||
182 | neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC); | 191 | neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC); |
@@ -186,15 +195,14 @@ batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, | |||
186 | INIT_HLIST_NODE(&neigh_node->list); | 195 | INIT_HLIST_NODE(&neigh_node->list); |
187 | 196 | ||
188 | memcpy(neigh_node->addr, neigh_addr, ETH_ALEN); | 197 | memcpy(neigh_node->addr, neigh_addr, ETH_ALEN); |
189 | spin_lock_init(&neigh_node->lq_update_lock); | 198 | neigh_node->if_incoming = hard_iface; |
199 | neigh_node->orig_node = orig_node; | ||
200 | |||
201 | INIT_LIST_HEAD(&neigh_node->bonding_list); | ||
190 | 202 | ||
191 | /* extra reference for return */ | 203 | /* extra reference for return */ |
192 | atomic_set(&neigh_node->refcount, 2); | 204 | atomic_set(&neigh_node->refcount, 2); |
193 | 205 | ||
194 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | ||
195 | "Creating new neighbor %pM on interface %s\n", neigh_addr, | ||
196 | hard_iface->net_dev->name); | ||
197 | |||
198 | out: | 206 | out: |
199 | return neigh_node; | 207 | return neigh_node; |
200 | } | 208 | } |
@@ -401,6 +409,7 @@ batadv_purge_orig_neighbors(struct batadv_priv *bat_priv, | |||
401 | bool neigh_purged = false; | 409 | bool neigh_purged = false; |
402 | unsigned long last_seen; | 410 | unsigned long last_seen; |
403 | struct batadv_hard_iface *if_incoming; | 411 | struct batadv_hard_iface *if_incoming; |
412 | uint8_t best_metric = 0; | ||
404 | 413 | ||
405 | *best_neigh_node = NULL; | 414 | *best_neigh_node = NULL; |
406 | 415 | ||
@@ -436,8 +445,10 @@ batadv_purge_orig_neighbors(struct batadv_priv *bat_priv, | |||
436 | batadv_neigh_node_free_ref(neigh_node); | 445 | batadv_neigh_node_free_ref(neigh_node); |
437 | } else { | 446 | } else { |
438 | if ((!*best_neigh_node) || | 447 | if ((!*best_neigh_node) || |
439 | (neigh_node->tq_avg > (*best_neigh_node)->tq_avg)) | 448 | (neigh_node->bat_iv.tq_avg > best_metric)) { |
440 | *best_neigh_node = neigh_node; | 449 | *best_neigh_node = neigh_node; |
450 | best_metric = neigh_node->bat_iv.tq_avg; | ||
451 | } | ||
441 | } | 452 | } |
442 | } | 453 | } |
443 | 454 | ||
@@ -557,7 +568,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset) | |||
557 | if (!neigh_node) | 568 | if (!neigh_node) |
558 | continue; | 569 | continue; |
559 | 570 | ||
560 | if (neigh_node->tq_avg == 0) | 571 | if (neigh_node->bat_iv.tq_avg == 0) |
561 | goto next; | 572 | goto next; |
562 | 573 | ||
563 | last_seen_jiffies = jiffies - orig_node->last_seen; | 574 | last_seen_jiffies = jiffies - orig_node->last_seen; |
@@ -567,7 +578,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset) | |||
567 | 578 | ||
568 | seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:", | 579 | seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:", |
569 | orig_node->orig, last_seen_secs, | 580 | orig_node->orig, last_seen_secs, |
570 | last_seen_msecs, neigh_node->tq_avg, | 581 | last_seen_msecs, neigh_node->bat_iv.tq_avg, |
571 | neigh_node->addr, | 582 | neigh_node->addr, |
572 | neigh_node->if_incoming->net_dev->name); | 583 | neigh_node->if_incoming->net_dev->name); |
573 | 584 | ||
@@ -575,7 +586,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset) | |||
575 | &orig_node->neigh_list, list) { | 586 | &orig_node->neigh_list, list) { |
576 | seq_printf(seq, " %pM (%3i)", | 587 | seq_printf(seq, " %pM (%3i)", |
577 | neigh_node_tmp->addr, | 588 | neigh_node_tmp->addr, |
578 | neigh_node_tmp->tq_avg); | 589 | neigh_node_tmp->bat_iv.tq_avg); |
579 | } | 590 | } |
580 | 591 | ||
581 | seq_puts(seq, "\n"); | 592 | seq_puts(seq, "\n"); |
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h index cc6d686cfe6d..06e5a6809dd7 100644 --- a/net/batman-adv/originator.h +++ b/net/batman-adv/originator.h | |||
@@ -31,7 +31,8 @@ struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv, | |||
31 | const uint8_t *addr); | 31 | const uint8_t *addr); |
32 | struct batadv_neigh_node * | 32 | struct batadv_neigh_node * |
33 | batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, | 33 | batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, |
34 | const uint8_t *neigh_addr); | 34 | const uint8_t *neigh_addr, |
35 | struct batadv_orig_node *orig_node); | ||
35 | void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node); | 36 | void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node); |
36 | struct batadv_neigh_node * | 37 | struct batadv_neigh_node * |
37 | batadv_orig_node_get_router(struct batadv_orig_node *orig_node); | 38 | batadv_orig_node_get_router(struct batadv_orig_node *orig_node); |
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 4bcf22129ffe..5b78a71c1b02 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
@@ -119,7 +119,7 @@ void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node, | |||
119 | struct batadv_neigh_node *neigh_node) | 119 | struct batadv_neigh_node *neigh_node) |
120 | { | 120 | { |
121 | struct batadv_neigh_node *tmp_neigh_node, *router = NULL; | 121 | struct batadv_neigh_node *tmp_neigh_node, *router = NULL; |
122 | uint8_t interference_candidate = 0; | 122 | uint8_t interference_candidate = 0, tq; |
123 | 123 | ||
124 | spin_lock_bh(&orig_node->neigh_list_lock); | 124 | spin_lock_bh(&orig_node->neigh_list_lock); |
125 | 125 | ||
@@ -132,8 +132,10 @@ void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node, | |||
132 | if (!router) | 132 | if (!router) |
133 | goto candidate_del; | 133 | goto candidate_del; |
134 | 134 | ||
135 | |||
135 | /* ... and is good enough to be considered */ | 136 | /* ... and is good enough to be considered */ |
136 | if (neigh_node->tq_avg < router->tq_avg - BATADV_BONDING_TQ_THRESHOLD) | 137 | tq = router->bat_iv.tq_avg - BATADV_BONDING_TQ_THRESHOLD; |
138 | if (neigh_node->bat_iv.tq_avg < tq) | ||
137 | goto candidate_del; | 139 | goto candidate_del; |
138 | 140 | ||
139 | /* check if we have another candidate with the same mac address or | 141 | /* check if we have another candidate with the same mac address or |
@@ -502,7 +504,8 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig, | |||
502 | if (tmp_neigh_node->if_incoming == recv_if) | 504 | if (tmp_neigh_node->if_incoming == recv_if) |
503 | continue; | 505 | continue; |
504 | 506 | ||
505 | if (router && tmp_neigh_node->tq_avg <= router->tq_avg) | 507 | if (router && |
508 | tmp_neigh_node->bat_iv.tq_avg <= router->bat_iv.tq_avg) | ||
506 | continue; | 509 | continue; |
507 | 510 | ||
508 | if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) | 511 | if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) |
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 7731eaed737d..1d5a4f5be899 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c | |||
@@ -1299,9 +1299,9 @@ batadv_transtable_best_orig(struct batadv_tt_global_entry *tt_global_entry) | |||
1299 | if (!router) | 1299 | if (!router) |
1300 | continue; | 1300 | continue; |
1301 | 1301 | ||
1302 | if (router->tq_avg > best_tq) { | 1302 | if (router->bat_iv.tq_avg > best_tq) { |
1303 | best_entry = orig_entry; | 1303 | best_entry = orig_entry; |
1304 | best_tq = router->tq_avg; | 1304 | best_tq = router->bat_iv.tq_avg; |
1305 | } | 1305 | } |
1306 | 1306 | ||
1307 | batadv_neigh_node_free_ref(router); | 1307 | batadv_neigh_node_free_ref(router); |
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index ff53933b5a59..a3213343a181 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h | |||
@@ -263,40 +263,49 @@ struct batadv_gw_node { | |||
263 | }; | 263 | }; |
264 | 264 | ||
265 | /** | 265 | /** |
266 | * struct batadv_neigh_node - structure for single hop neighbors | 266 | * struct batadv_neigh_bat_iv - B.A.T.M.A.N. IV specific structure for single |
267 | * @list: list node for batadv_orig_node::neigh_list | 267 | * hop neighbors |
268 | * @addr: mac address of neigh node | ||
269 | * @tq_recv: ring buffer of received TQ values from this neigh node | 268 | * @tq_recv: ring buffer of received TQ values from this neigh node |
270 | * @tq_index: ring buffer index | 269 | * @tq_index: ring buffer index |
271 | * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv) | 270 | * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv) |
272 | * @last_ttl: last received ttl from this neigh node | ||
273 | * @bonding_list: list node for batadv_orig_node::bond_list | ||
274 | * @last_seen: when last packet via this neighbor was received | ||
275 | * @real_bits: bitfield containing the number of OGMs received from this neigh | 271 | * @real_bits: bitfield containing the number of OGMs received from this neigh |
276 | * node (relative to orig_node->last_real_seqno) | 272 | * node (relative to orig_node->last_real_seqno) |
277 | * @real_packet_count: counted result of real_bits | 273 | * @real_packet_count: counted result of real_bits |
274 | * @lq_update_lock: lock protecting tq_recv & tq_index | ||
275 | */ | ||
276 | struct batadv_neigh_bat_iv { | ||
277 | uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE]; | ||
278 | uint8_t tq_index; | ||
279 | uint8_t tq_avg; | ||
280 | DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE); | ||
281 | uint8_t real_packet_count; | ||
282 | spinlock_t lq_update_lock; /* protects tq_recv & tq_index */ | ||
283 | }; | ||
284 | |||
285 | /** | ||
286 | * struct batadv_neigh_node - structure for single hops neighbors | ||
287 | * @list: list node for batadv_orig_node::neigh_list | ||
278 | * @orig_node: pointer to corresponding orig_node | 288 | * @orig_node: pointer to corresponding orig_node |
289 | * @addr: the MAC address of the neighboring interface | ||
279 | * @if_incoming: pointer to incoming hard interface | 290 | * @if_incoming: pointer to incoming hard interface |
280 | * @lq_update_lock: lock protecting tq_recv & tq_index | 291 | * @last_seen: when last packet via this neighbor was received |
292 | * @last_ttl: last received ttl from this neigh node | ||
293 | * @bonding_list: list node for batadv_orig_node::bond_list | ||
281 | * @refcount: number of contexts the object is used | 294 | * @refcount: number of contexts the object is used |
282 | * @rcu: struct used for freeing in an RCU-safe manner | 295 | * @rcu: struct used for freeing in an RCU-safe manner |
296 | * @bat_iv: B.A.T.M.A.N. IV private structure | ||
283 | */ | 297 | */ |
284 | struct batadv_neigh_node { | 298 | struct batadv_neigh_node { |
285 | struct hlist_node list; | 299 | struct hlist_node list; |
300 | struct batadv_orig_node *orig_node; | ||
286 | uint8_t addr[ETH_ALEN]; | 301 | uint8_t addr[ETH_ALEN]; |
287 | uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE]; | 302 | struct batadv_hard_iface *if_incoming; |
288 | uint8_t tq_index; | 303 | unsigned long last_seen; |
289 | uint8_t tq_avg; | ||
290 | uint8_t last_ttl; | 304 | uint8_t last_ttl; |
291 | struct list_head bonding_list; | 305 | struct list_head bonding_list; |
292 | unsigned long last_seen; | ||
293 | DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE); | ||
294 | uint8_t real_packet_count; | ||
295 | struct batadv_orig_node *orig_node; | ||
296 | struct batadv_hard_iface *if_incoming; | ||
297 | spinlock_t lq_update_lock; /* protects tq_recv & tq_index */ | ||
298 | atomic_t refcount; | 306 | atomic_t refcount; |
299 | struct rcu_head rcu; | 307 | struct rcu_head rcu; |
308 | struct batadv_neigh_bat_iv bat_iv; | ||
300 | }; | 309 | }; |
301 | 310 | ||
302 | /** | 311 | /** |