aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv
diff options
context:
space:
mode:
authorAntonio Quartulli <antonio@open-mesh.com>2013-09-02 06:15:02 -0400
committerAntonio Quartulli <antonio@meshcoding.com>2013-10-23 09:33:09 -0400
commitbbad0a5e3691cb3976d7a4815c47d9b7bb244731 (patch)
treeffd4dc090e76f278ff1c472363ff00293b562511 /net/batman-adv
parent0538f7599157b7bdef1814472048de5351c4fd6d (diff)
batman-adv: make struct batadv_orig_node algorithm agnostic
some of the struct batadv_orig_node members are B.A.T.M.A.N. IV specific and therefore they are moved in a algorithm specific substruct in order to make batadv_orig_node routing algorithm agnostic 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.c108
-rw-r--r--net/batman-adv/originator.c89
-rw-r--r--net/batman-adv/originator.h3
-rw-r--r--net/batman-adv/types.h30
4 files changed, 135 insertions, 95 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index a2a04982a22b..0b1343dde5d2 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -87,6 +87,57 @@ static uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[])
87 return (uint8_t)(sum / count); 87 return (uint8_t)(sum / count);
88} 88}
89 89
90/**
91 * batadv_iv_ogm_orig_get - retrieve or create (if does not exist) an originator
92 * @bat_priv: the bat priv with all the soft interface information
93 * @addr: mac address of the originator
94 *
95 * Returns the originator object corresponding to the passed mac address or NULL
96 * on failure.
97 * If the object does not exists it is created an initialised.
98 */
99static struct batadv_orig_node *
100batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const uint8_t *addr)
101{
102 struct batadv_orig_node *orig_node;
103 int size, hash_added;
104
105 orig_node = batadv_orig_hash_find(bat_priv, addr);
106 if (orig_node)
107 return orig_node;
108
109 orig_node = batadv_orig_node_new(bat_priv, addr);
110 if (!orig_node)
111 return NULL;
112
113 spin_lock_init(&orig_node->bat_iv.ogm_cnt_lock);
114
115 size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS;
116 orig_node->bat_iv.bcast_own = kzalloc(size, GFP_ATOMIC);
117 if (!orig_node->bat_iv.bcast_own)
118 goto free_orig_node;
119
120 size = bat_priv->num_ifaces * sizeof(uint8_t);
121 orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC);
122 if (!orig_node->bat_iv.bcast_own_sum)
123 goto free_bcast_own;
124
125 hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
126 batadv_choose_orig, orig_node,
127 &orig_node->hash_entry);
128 if (hash_added != 0)
129 goto free_bcast_own;
130
131 return orig_node;
132
133free_bcast_own:
134 kfree(orig_node->bat_iv.bcast_own);
135free_orig_node:
136 batadv_orig_node_free_ref(orig_node);
137
138 return NULL;
139}
140
90static struct batadv_neigh_node * 141static struct batadv_neigh_node *
91batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, 142batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
92 const uint8_t *neigh_addr, 143 const uint8_t *neigh_addr,
@@ -663,20 +714,22 @@ batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface)
663 uint32_t i; 714 uint32_t i;
664 size_t word_index; 715 size_t word_index;
665 uint8_t *w; 716 uint8_t *w;
717 int if_num;
666 718
667 for (i = 0; i < hash->size; i++) { 719 for (i = 0; i < hash->size; i++) {
668 head = &hash->table[i]; 720 head = &hash->table[i];
669 721
670 rcu_read_lock(); 722 rcu_read_lock();
671 hlist_for_each_entry_rcu(orig_node, head, hash_entry) { 723 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
672 spin_lock_bh(&orig_node->ogm_cnt_lock); 724 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
673 word_index = hard_iface->if_num * BATADV_NUM_WORDS; 725 word_index = hard_iface->if_num * BATADV_NUM_WORDS;
674 word = &(orig_node->bcast_own[word_index]); 726 word = &(orig_node->bat_iv.bcast_own[word_index]);
675 727
676 batadv_bit_get_packet(bat_priv, word, 1, 0); 728 batadv_bit_get_packet(bat_priv, word, 1, 0);
677 w = &orig_node->bcast_own_sum[hard_iface->if_num]; 729 if_num = hard_iface->if_num;
730 w = &orig_node->bat_iv.bcast_own_sum[if_num];
678 *w = bitmap_weight(word, BATADV_TQ_LOCAL_WINDOW_SIZE); 731 *w = bitmap_weight(word, BATADV_TQ_LOCAL_WINDOW_SIZE);
679 spin_unlock_bh(&orig_node->ogm_cnt_lock); 732 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
680 } 733 }
681 rcu_read_unlock(); 734 rcu_read_unlock();
682 } 735 }
@@ -768,7 +821,7 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
768 if (!neigh_node) { 821 if (!neigh_node) {
769 struct batadv_orig_node *orig_tmp; 822 struct batadv_orig_node *orig_tmp;
770 823
771 orig_tmp = batadv_get_orig_node(bat_priv, ethhdr->h_source); 824 orig_tmp = batadv_iv_ogm_orig_get(bat_priv, ethhdr->h_source);
772 if (!orig_tmp) 825 if (!orig_tmp)
773 goto unlock; 826 goto unlock;
774 827
@@ -818,16 +871,16 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
818 */ 871 */
819 if (router && (neigh_node->bat_iv.tq_avg == router->bat_iv.tq_avg)) { 872 if (router && (neigh_node->bat_iv.tq_avg == router->bat_iv.tq_avg)) {
820 orig_node_tmp = router->orig_node; 873 orig_node_tmp = router->orig_node;
821 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); 874 spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
822 if_num = router->if_incoming->if_num; 875 if_num = router->if_incoming->if_num;
823 sum_orig = orig_node_tmp->bcast_own_sum[if_num]; 876 sum_orig = orig_node_tmp->bat_iv.bcast_own_sum[if_num];
824 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock); 877 spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
825 878
826 orig_node_tmp = neigh_node->orig_node; 879 orig_node_tmp = neigh_node->orig_node;
827 spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); 880 spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
828 if_num = neigh_node->if_incoming->if_num; 881 if_num = neigh_node->if_incoming->if_num;
829 sum_neigh = orig_node_tmp->bcast_own_sum[if_num]; 882 sum_neigh = orig_node_tmp->bat_iv.bcast_own_sum[if_num];
830 spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock); 883 spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock);
831 884
832 if (sum_orig >= sum_neigh) 885 if (sum_orig >= sum_neigh)
833 goto out; 886 goto out;
@@ -855,7 +908,7 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
855 uint8_t total_count; 908 uint8_t total_count;
856 uint8_t orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own; 909 uint8_t orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
857 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube; 910 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
858 int tq_asym_penalty, inv_asym_penalty, ret = 0; 911 int tq_asym_penalty, inv_asym_penalty, if_num, ret = 0;
859 unsigned int combined_tq; 912 unsigned int combined_tq;
860 913
861 /* find corresponding one hop neighbor */ 914 /* find corresponding one hop neighbor */
@@ -893,10 +946,11 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
893 orig_node->last_seen = jiffies; 946 orig_node->last_seen = jiffies;
894 947
895 /* find packet count of corresponding one hop neighbor */ 948 /* find packet count of corresponding one hop neighbor */
896 spin_lock_bh(&orig_node->ogm_cnt_lock); 949 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
897 orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num]; 950 if_num = if_incoming->if_num;
951 orig_eq_count = orig_neigh_node->bat_iv.bcast_own_sum[if_num];
898 neigh_rq_count = neigh_node->bat_iv.real_packet_count; 952 neigh_rq_count = neigh_node->bat_iv.real_packet_count;
899 spin_unlock_bh(&orig_node->ogm_cnt_lock); 953 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
900 954
901 /* pay attention to not get a value bigger than 100 % */ 955 /* pay attention to not get a value bigger than 100 % */
902 if (orig_eq_count > neigh_rq_count) 956 if (orig_eq_count > neigh_rq_count)
@@ -980,11 +1034,11 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
980 uint8_t packet_count; 1034 uint8_t packet_count;
981 unsigned long *bitmap; 1035 unsigned long *bitmap;
982 1036
983 orig_node = batadv_get_orig_node(bat_priv, batadv_ogm_packet->orig); 1037 orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig);
984 if (!orig_node) 1038 if (!orig_node)
985 return BATADV_NO_DUP; 1039 return BATADV_NO_DUP;
986 1040
987 spin_lock_bh(&orig_node->ogm_cnt_lock); 1041 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
988 seq_diff = seqno - orig_node->last_real_seqno; 1042 seq_diff = seqno - orig_node->last_real_seqno;
989 1043
990 /* signalize caller that the packet is to be dropped. */ 1044 /* signalize caller that the packet is to be dropped. */
@@ -1033,7 +1087,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
1033 } 1087 }
1034 1088
1035out: 1089out:
1036 spin_unlock_bh(&orig_node->ogm_cnt_lock); 1090 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
1037 batadv_orig_node_free_ref(orig_node); 1091 batadv_orig_node_free_ref(orig_node);
1038 return ret; 1092 return ret;
1039} 1093}
@@ -1129,8 +1183,8 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
1129 int16_t if_num; 1183 int16_t if_num;
1130 uint8_t *weight; 1184 uint8_t *weight;
1131 1185
1132 orig_neigh_node = batadv_get_orig_node(bat_priv, 1186 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
1133 ethhdr->h_source); 1187 ethhdr->h_source);
1134 if (!orig_neigh_node) 1188 if (!orig_neigh_node)
1135 return; 1189 return;
1136 1190
@@ -1144,15 +1198,15 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
1144 if_num = if_incoming->if_num; 1198 if_num = if_incoming->if_num;
1145 offset = if_num * BATADV_NUM_WORDS; 1199 offset = if_num * BATADV_NUM_WORDS;
1146 1200
1147 spin_lock_bh(&orig_neigh_node->ogm_cnt_lock); 1201 spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1148 word = &(orig_neigh_node->bcast_own[offset]); 1202 word = &(orig_neigh_node->bat_iv.bcast_own[offset]);
1149 bit_pos = if_incoming_seqno - 2; 1203 bit_pos = if_incoming_seqno - 2;
1150 bit_pos -= ntohl(batadv_ogm_packet->seqno); 1204 bit_pos -= ntohl(batadv_ogm_packet->seqno);
1151 batadv_set_bit(word, bit_pos); 1205 batadv_set_bit(word, bit_pos);
1152 weight = &orig_neigh_node->bcast_own_sum[if_num]; 1206 weight = &orig_neigh_node->bat_iv.bcast_own_sum[if_num];
1153 *weight = bitmap_weight(word, 1207 *weight = bitmap_weight(word,
1154 BATADV_TQ_LOCAL_WINDOW_SIZE); 1208 BATADV_TQ_LOCAL_WINDOW_SIZE);
1155 spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock); 1209 spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock);
1156 } 1210 }
1157 1211
1158 batadv_dbg(BATADV_DBG_BATMAN, bat_priv, 1212 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
@@ -1175,7 +1229,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
1175 return; 1229 return;
1176 } 1230 }
1177 1231
1178 orig_node = batadv_get_orig_node(bat_priv, batadv_ogm_packet->orig); 1232 orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig);
1179 if (!orig_node) 1233 if (!orig_node)
1180 return; 1234 return;
1181 1235
@@ -1225,8 +1279,8 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
1225 if (is_single_hop_neigh) 1279 if (is_single_hop_neigh)
1226 orig_neigh_node = orig_node; 1280 orig_neigh_node = orig_node;
1227 else 1281 else
1228 orig_neigh_node = batadv_get_orig_node(bat_priv, 1282 orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv,
1229 ethhdr->h_source); 1283 ethhdr->h_source);
1230 1284
1231 if (!orig_neigh_node) 1285 if (!orig_neigh_node)
1232 goto out; 1286 goto out;
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 50f6d9964780..aa1409467d08 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -36,7 +36,7 @@ static struct lock_class_key batadv_orig_hash_lock_class_key;
36static void batadv_purge_orig(struct work_struct *work); 36static void batadv_purge_orig(struct work_struct *work);
37 37
38/* returns 1 if they are the same originator */ 38/* returns 1 if they are the same originator */
39static int batadv_compare_orig(const struct hlist_node *node, const void *data2) 39int batadv_compare_orig(const struct hlist_node *node, const void *data2)
40{ 40{
41 const void *data1 = container_of(node, struct batadv_orig_node, 41 const void *data1 = container_of(node, struct batadv_orig_node,
42 hash_entry); 42 hash_entry);
@@ -242,8 +242,8 @@ static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
242 "originator timed out"); 242 "originator timed out");
243 243
244 kfree(orig_node->tt_buff); 244 kfree(orig_node->tt_buff);
245 kfree(orig_node->bcast_own); 245 kfree(orig_node->bat_iv.bcast_own);
246 kfree(orig_node->bcast_own_sum); 246 kfree(orig_node->bat_iv.bcast_own_sum);
247 kfree(orig_node); 247 kfree(orig_node);
248} 248}
249 249
@@ -301,21 +301,22 @@ void batadv_originator_free(struct batadv_priv *bat_priv)
301 batadv_hash_destroy(hash); 301 batadv_hash_destroy(hash);
302} 302}
303 303
304/* this function finds or creates an originator entry for the given 304/**
305 * address if it does not exits 305 * batadv_orig_node_new - creates a new orig_node
306 * @bat_priv: the bat priv with all the soft interface information
307 * @addr: the mac address of the originator
308 *
309 * Creates a new originator object and initialise all the generic fields.
310 * The new object is not added to the originator list.
311 * Returns the newly created object or NULL on failure.
306 */ 312 */
307struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv, 313struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
308 const uint8_t *addr) 314 const uint8_t *addr)
309{ 315{
310 struct batadv_orig_node *orig_node; 316 struct batadv_orig_node *orig_node;
311 struct batadv_orig_node_vlan *vlan; 317 struct batadv_orig_node_vlan *vlan;
312 int size, i;
313 int hash_added;
314 unsigned long reset_time; 318 unsigned long reset_time;
315 319 int i;
316 orig_node = batadv_orig_hash_find(bat_priv, addr);
317 if (orig_node)
318 return orig_node;
319 320
320 batadv_dbg(BATADV_DBG_BATMAN, bat_priv, 321 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
321 "Creating new originator: %pM\n", addr); 322 "Creating new originator: %pM\n", addr);
@@ -327,7 +328,6 @@ struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
327 INIT_HLIST_HEAD(&orig_node->neigh_list); 328 INIT_HLIST_HEAD(&orig_node->neigh_list);
328 INIT_LIST_HEAD(&orig_node->bond_list); 329 INIT_LIST_HEAD(&orig_node->bond_list);
329 INIT_LIST_HEAD(&orig_node->vlan_list); 330 INIT_LIST_HEAD(&orig_node->vlan_list);
330 spin_lock_init(&orig_node->ogm_cnt_lock);
331 spin_lock_init(&orig_node->bcast_seqno_lock); 331 spin_lock_init(&orig_node->bcast_seqno_lock);
332 spin_lock_init(&orig_node->neigh_list_lock); 332 spin_lock_init(&orig_node->neigh_list_lock);
333 spin_lock_init(&orig_node->tt_buff_lock); 333 spin_lock_init(&orig_node->tt_buff_lock);
@@ -363,37 +363,13 @@ struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv,
363 */ 363 */
364 batadv_orig_node_vlan_free_ref(vlan); 364 batadv_orig_node_vlan_free_ref(vlan);
365 365
366 size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS;
367
368 orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
369 if (!orig_node->bcast_own)
370 goto free_vlan;
371
372 size = bat_priv->num_ifaces * sizeof(uint8_t);
373 orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
374
375 for (i = 0; i < BATADV_FRAG_BUFFER_COUNT; i++) { 366 for (i = 0; i < BATADV_FRAG_BUFFER_COUNT; i++) {
376 INIT_HLIST_HEAD(&orig_node->fragments[i].head); 367 INIT_HLIST_HEAD(&orig_node->fragments[i].head);
377 spin_lock_init(&orig_node->fragments[i].lock); 368 spin_lock_init(&orig_node->fragments[i].lock);
378 orig_node->fragments[i].size = 0; 369 orig_node->fragments[i].size = 0;
379 } 370 }
380 371
381 if (!orig_node->bcast_own_sum)
382 goto free_bcast_own;
383
384 hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig,
385 batadv_choose_orig, orig_node,
386 &orig_node->hash_entry);
387 if (hash_added != 0)
388 goto free_bcast_own_sum;
389
390 return orig_node; 372 return orig_node;
391free_bcast_own_sum:
392 kfree(orig_node->bcast_own_sum);
393free_bcast_own:
394 kfree(orig_node->bcast_own);
395free_vlan:
396 batadv_orig_node_vlan_free_ref(vlan);
397free_orig_node: 373free_orig_node:
398 kfree(orig_node); 374 kfree(orig_node);
399 return NULL; 375 return NULL;
@@ -619,18 +595,18 @@ static int batadv_orig_node_add_if(struct batadv_orig_node *orig_node,
619 if (!data_ptr) 595 if (!data_ptr)
620 return -ENOMEM; 596 return -ENOMEM;
621 597
622 memcpy(data_ptr, orig_node->bcast_own, old_size); 598 memcpy(data_ptr, orig_node->bat_iv.bcast_own, old_size);
623 kfree(orig_node->bcast_own); 599 kfree(orig_node->bat_iv.bcast_own);
624 orig_node->bcast_own = data_ptr; 600 orig_node->bat_iv.bcast_own = data_ptr;
625 601
626 data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC); 602 data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
627 if (!data_ptr) 603 if (!data_ptr)
628 return -ENOMEM; 604 return -ENOMEM;
629 605
630 memcpy(data_ptr, orig_node->bcast_own_sum, 606 memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum,
631 (max_if_num - 1) * sizeof(uint8_t)); 607 (max_if_num - 1) * sizeof(uint8_t));
632 kfree(orig_node->bcast_own_sum); 608 kfree(orig_node->bat_iv.bcast_own_sum);
633 orig_node->bcast_own_sum = data_ptr; 609 orig_node->bat_iv.bcast_own_sum = data_ptr;
634 610
635 return 0; 611 return 0;
636} 612}
@@ -653,9 +629,9 @@ int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
653 629
654 rcu_read_lock(); 630 rcu_read_lock();
655 hlist_for_each_entry_rcu(orig_node, head, hash_entry) { 631 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
656 spin_lock_bh(&orig_node->ogm_cnt_lock); 632 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
657 ret = batadv_orig_node_add_if(orig_node, max_if_num); 633 ret = batadv_orig_node_add_if(orig_node, max_if_num);
658 spin_unlock_bh(&orig_node->ogm_cnt_lock); 634 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
659 635
660 if (ret == -ENOMEM) 636 if (ret == -ENOMEM)
661 goto err; 637 goto err;
@@ -673,8 +649,8 @@ err:
673static int batadv_orig_node_del_if(struct batadv_orig_node *orig_node, 649static int batadv_orig_node_del_if(struct batadv_orig_node *orig_node,
674 int max_if_num, int del_if_num) 650 int max_if_num, int del_if_num)
675{ 651{
652 int chunk_size, if_offset;
676 void *data_ptr = NULL; 653 void *data_ptr = NULL;
677 int chunk_size;
678 654
679 /* last interface was removed */ 655 /* last interface was removed */
680 if (max_if_num == 0) 656 if (max_if_num == 0)
@@ -686,16 +662,16 @@ static int batadv_orig_node_del_if(struct batadv_orig_node *orig_node,
686 return -ENOMEM; 662 return -ENOMEM;
687 663
688 /* copy first part */ 664 /* copy first part */
689 memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size); 665 memcpy(data_ptr, orig_node->bat_iv.bcast_own, del_if_num * chunk_size);
690 666
691 /* copy second part */ 667 /* copy second part */
692 memcpy((char *)data_ptr + del_if_num * chunk_size, 668 memcpy((char *)data_ptr + del_if_num * chunk_size,
693 orig_node->bcast_own + ((del_if_num + 1) * chunk_size), 669 orig_node->bat_iv.bcast_own + ((del_if_num + 1) * chunk_size),
694 (max_if_num - del_if_num) * chunk_size); 670 (max_if_num - del_if_num) * chunk_size);
695 671
696free_bcast_own: 672free_bcast_own:
697 kfree(orig_node->bcast_own); 673 kfree(orig_node->bat_iv.bcast_own);
698 orig_node->bcast_own = data_ptr; 674 orig_node->bat_iv.bcast_own = data_ptr;
699 675
700 if (max_if_num == 0) 676 if (max_if_num == 0)
701 goto free_own_sum; 677 goto free_own_sum;
@@ -704,16 +680,17 @@ free_bcast_own:
704 if (!data_ptr) 680 if (!data_ptr)
705 return -ENOMEM; 681 return -ENOMEM;
706 682
707 memcpy(data_ptr, orig_node->bcast_own_sum, 683 memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum,
708 del_if_num * sizeof(uint8_t)); 684 del_if_num * sizeof(uint8_t));
709 685
686 if_offset = (del_if_num + 1) * sizeof(uint8_t);
710 memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t), 687 memcpy((char *)data_ptr + del_if_num * sizeof(uint8_t),
711 orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)), 688 orig_node->bat_iv.bcast_own_sum + if_offset,
712 (max_if_num - del_if_num) * sizeof(uint8_t)); 689 (max_if_num - del_if_num) * sizeof(uint8_t));
713 690
714free_own_sum: 691free_own_sum:
715 kfree(orig_node->bcast_own_sum); 692 kfree(orig_node->bat_iv.bcast_own_sum);
716 orig_node->bcast_own_sum = data_ptr; 693 orig_node->bat_iv.bcast_own_sum = data_ptr;
717 694
718 return 0; 695 return 0;
719} 696}
@@ -737,10 +714,10 @@ int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
737 714
738 rcu_read_lock(); 715 rcu_read_lock();
739 hlist_for_each_entry_rcu(orig_node, head, hash_entry) { 716 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
740 spin_lock_bh(&orig_node->ogm_cnt_lock); 717 spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
741 ret = batadv_orig_node_del_if(orig_node, max_if_num, 718 ret = batadv_orig_node_del_if(orig_node, max_if_num,
742 hard_iface->if_num); 719 hard_iface->if_num);
743 spin_unlock_bh(&orig_node->ogm_cnt_lock); 720 spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);
744 721
745 if (ret == -ENOMEM) 722 if (ret == -ENOMEM)
746 goto err; 723 goto err;
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index 06e5a6809dd7..6f77d808a916 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -22,12 +22,13 @@
22 22
23#include "hash.h" 23#include "hash.h"
24 24
25int batadv_compare_orig(const struct hlist_node *node, const void *data2);
25int batadv_originator_init(struct batadv_priv *bat_priv); 26int batadv_originator_init(struct batadv_priv *bat_priv);
26void batadv_originator_free(struct batadv_priv *bat_priv); 27void batadv_originator_free(struct batadv_priv *bat_priv);
27void batadv_purge_orig_ref(struct batadv_priv *bat_priv); 28void batadv_purge_orig_ref(struct batadv_priv *bat_priv);
28void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node); 29void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node);
29void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node); 30void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node);
30struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv, 31struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
31 const uint8_t *addr); 32 const uint8_t *addr);
32struct batadv_neigh_node * 33struct batadv_neigh_node *
33batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, 34batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index a3213343a181..97bde51b6031 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -133,14 +133,28 @@ struct batadv_orig_node_vlan {
133}; 133};
134 134
135/** 135/**
136 * struct batadv_orig_bat_iv - B.A.T.M.A.N. IV private orig_node members
137 * @bcast_own: bitfield containing the number of our OGMs this orig_node
138 * rebroadcasted "back" to us (relative to last_real_seqno)
139 * @bcast_own_sum: counted result of bcast_own
140 * @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
141 * neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count
142 */
143struct batadv_orig_bat_iv {
144 unsigned long *bcast_own;
145 uint8_t *bcast_own_sum;
146 /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
147 * neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count
148 */
149 spinlock_t ogm_cnt_lock;
150};
151
152/**
136 * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh 153 * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
137 * @orig: originator ethernet address 154 * @orig: originator ethernet address
138 * @primary_addr: hosts primary interface address 155 * @primary_addr: hosts primary interface address
139 * @router: router that should be used to reach this originator 156 * @router: router that should be used to reach this originator
140 * @batadv_dat_addr_t: address of the orig node in the distributed hash 157 * @batadv_dat_addr_t: address of the orig node in the distributed hash
141 * @bcast_own: bitfield containing the number of our OGMs this orig_node
142 * rebroadcasted "back" to us (relative to last_real_seqno)
143 * @bcast_own_sum: counted result of bcast_own
144 * @last_seen: time when last packet from this node was received 158 * @last_seen: time when last packet from this node was received
145 * @bcast_seqno_reset: time when the broadcast seqno window was reset 159 * @bcast_seqno_reset: time when the broadcast seqno window was reset
146 * @batman_seqno_reset: time when the batman seqno window was reset 160 * @batman_seqno_reset: time when the batman seqno window was reset
@@ -166,8 +180,6 @@ struct batadv_orig_node_vlan {
166 * @neigh_list_lock: lock protecting neigh_list, router and bonding_list 180 * @neigh_list_lock: lock protecting neigh_list, router and bonding_list
167 * @hash_entry: hlist node for batadv_priv::orig_hash 181 * @hash_entry: hlist node for batadv_priv::orig_hash
168 * @bat_priv: pointer to soft_iface this orig node belongs to 182 * @bat_priv: pointer to soft_iface this orig node belongs to
169 * @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
170 * neigh_node->real_bits & neigh_node->real_packet_count
171 * @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno 183 * @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno
172 * @bond_candidates: how many candidates are available 184 * @bond_candidates: how many candidates are available
173 * @bond_list: list of bonding candidates 185 * @bond_list: list of bonding candidates
@@ -181,6 +193,7 @@ struct batadv_orig_node_vlan {
181 * @vlan_list: a list of orig_node_vlan structs, one per VLAN served by the 193 * @vlan_list: a list of orig_node_vlan structs, one per VLAN served by the
182 * originator represented by this object 194 * originator represented by this object
183 * @vlan_list_lock: lock protecting vlan_list 195 * @vlan_list_lock: lock protecting vlan_list
196 * @bat_iv: B.A.T.M.A.N. IV private structure
184 */ 197 */
185struct batadv_orig_node { 198struct batadv_orig_node {
186 uint8_t orig[ETH_ALEN]; 199 uint8_t orig[ETH_ALEN];
@@ -189,8 +202,6 @@ struct batadv_orig_node {
189#ifdef CONFIG_BATMAN_ADV_DAT 202#ifdef CONFIG_BATMAN_ADV_DAT
190 batadv_dat_addr_t dat_addr; 203 batadv_dat_addr_t dat_addr;
191#endif 204#endif
192 unsigned long *bcast_own;
193 uint8_t *bcast_own_sum;
194 unsigned long last_seen; 205 unsigned long last_seen;
195 unsigned long bcast_seqno_reset; 206 unsigned long bcast_seqno_reset;
196 unsigned long batman_seqno_reset; 207 unsigned long batman_seqno_reset;
@@ -211,10 +222,6 @@ struct batadv_orig_node {
211 spinlock_t neigh_list_lock; 222 spinlock_t neigh_list_lock;
212 struct hlist_node hash_entry; 223 struct hlist_node hash_entry;
213 struct batadv_priv *bat_priv; 224 struct batadv_priv *bat_priv;
214 /* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
215 * neigh_node->real_bits & neigh_node->real_packet_count
216 */
217 spinlock_t ogm_cnt_lock;
218 /* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */ 225 /* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */
219 spinlock_t bcast_seqno_lock; 226 spinlock_t bcast_seqno_lock;
220 atomic_t bond_candidates; 227 atomic_t bond_candidates;
@@ -230,6 +237,7 @@ struct batadv_orig_node {
230 struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT]; 237 struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT];
231 struct list_head vlan_list; 238 struct list_head vlan_list;
232 spinlock_t vlan_list_lock; /* protects vlan_list */ 239 spinlock_t vlan_list_lock; /* protects vlan_list */
240 struct batadv_orig_bat_iv bat_iv;
233}; 241};
234 242
235/** 243/**