diff options
author | Antonio Quartulli <ordex@autistici.org> | 2011-10-30 07:17:33 -0400 |
---|---|---|
committer | Sven Eckelmann <sven@narfation.org> | 2011-11-20 07:08:35 -0500 |
commit | 48100bac89a6161ca53dd65697fe635f77986686 (patch) | |
tree | 369c12a754d2771d1b1fcc11a258b4e9de6567bd /net/batman-adv/translation-table.c | |
parent | ad24431277fc92717084d5b4c451e15982588206 (diff) |
batman-adv: create a common substructure for tt_global/local_entry
Several functions in the translation table management code assume that the
tt_global_entry and tt_local_entry structures have the same initial fields such
as 'addr' and 'hash_entry'. To improve the code readability and to avoid
mistakes in later changes, a common substructure that substitute the shared
fields has been introduced (struct tt_common_entry).
Thanks to this modification, it has also been possible to slightly reduce the
code length by merging some functions like compare_ltt/gtt() and
tt_local/global_hash_find()
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/translation-table.c')
-rw-r--r-- | net/batman-adv/translation-table.c | 287 |
1 files changed, 157 insertions, 130 deletions
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 78b9528bfc2a..76134bc5e513 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c | |||
@@ -36,18 +36,9 @@ static void _tt_global_del(struct bat_priv *bat_priv, | |||
36 | static void tt_purge(struct work_struct *work); | 36 | static void tt_purge(struct work_struct *work); |
37 | 37 | ||
38 | /* returns 1 if they are the same mac addr */ | 38 | /* returns 1 if they are the same mac addr */ |
39 | static int compare_ltt(const struct hlist_node *node, const void *data2) | 39 | static int compare_tt(const struct hlist_node *node, const void *data2) |
40 | { | 40 | { |
41 | const void *data1 = container_of(node, struct tt_local_entry, | 41 | const void *data1 = container_of(node, struct tt_common_entry, |
42 | hash_entry); | ||
43 | |||
44 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); | ||
45 | } | ||
46 | |||
47 | /* returns 1 if they are the same mac addr */ | ||
48 | static int compare_gtt(const struct hlist_node *node, const void *data2) | ||
49 | { | ||
50 | const void *data1 = container_of(node, struct tt_global_entry, | ||
51 | hash_entry); | 42 | hash_entry); |
52 | 43 | ||
53 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); | 44 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
@@ -60,13 +51,12 @@ static void tt_start_timer(struct bat_priv *bat_priv) | |||
60 | msecs_to_jiffies(5000)); | 51 | msecs_to_jiffies(5000)); |
61 | } | 52 | } |
62 | 53 | ||
63 | static struct tt_local_entry *tt_local_hash_find(struct bat_priv *bat_priv, | 54 | static struct tt_common_entry *tt_hash_find(struct hashtable_t *hash, |
64 | const void *data) | 55 | const void *data) |
65 | { | 56 | { |
66 | struct hashtable_t *hash = bat_priv->tt_local_hash; | ||
67 | struct hlist_head *head; | 57 | struct hlist_head *head; |
68 | struct hlist_node *node; | 58 | struct hlist_node *node; |
69 | struct tt_local_entry *tt_local_entry, *tt_local_entry_tmp = NULL; | 59 | struct tt_common_entry *tt_common_entry, *tt_common_entry_tmp = NULL; |
70 | uint32_t index; | 60 | uint32_t index; |
71 | 61 | ||
72 | if (!hash) | 62 | if (!hash) |
@@ -76,51 +66,46 @@ static struct tt_local_entry *tt_local_hash_find(struct bat_priv *bat_priv, | |||
76 | head = &hash->table[index]; | 66 | head = &hash->table[index]; |
77 | 67 | ||
78 | rcu_read_lock(); | 68 | rcu_read_lock(); |
79 | hlist_for_each_entry_rcu(tt_local_entry, node, head, hash_entry) { | 69 | hlist_for_each_entry_rcu(tt_common_entry, node, head, hash_entry) { |
80 | if (!compare_eth(tt_local_entry, data)) | 70 | if (!compare_eth(tt_common_entry, data)) |
81 | continue; | 71 | continue; |
82 | 72 | ||
83 | if (!atomic_inc_not_zero(&tt_local_entry->refcount)) | 73 | if (!atomic_inc_not_zero(&tt_common_entry->refcount)) |
84 | continue; | 74 | continue; |
85 | 75 | ||
86 | tt_local_entry_tmp = tt_local_entry; | 76 | tt_common_entry_tmp = tt_common_entry; |
87 | break; | 77 | break; |
88 | } | 78 | } |
89 | rcu_read_unlock(); | 79 | rcu_read_unlock(); |
90 | 80 | ||
91 | return tt_local_entry_tmp; | 81 | return tt_common_entry_tmp; |
92 | } | 82 | } |
93 | 83 | ||
94 | static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, | 84 | static struct tt_local_entry *tt_local_hash_find(struct bat_priv *bat_priv, |
95 | const void *data) | 85 | const void *data) |
96 | { | 86 | { |
97 | struct hashtable_t *hash = bat_priv->tt_global_hash; | 87 | struct tt_common_entry *tt_common_entry; |
98 | struct hlist_head *head; | 88 | struct tt_local_entry *tt_local_entry = NULL; |
99 | struct hlist_node *node; | ||
100 | struct tt_global_entry *tt_global_entry; | ||
101 | struct tt_global_entry *tt_global_entry_tmp = NULL; | ||
102 | uint32_t index; | ||
103 | |||
104 | if (!hash) | ||
105 | return NULL; | ||
106 | |||
107 | index = choose_orig(data, hash->size); | ||
108 | head = &hash->table[index]; | ||
109 | 89 | ||
110 | rcu_read_lock(); | 90 | tt_common_entry = tt_hash_find(bat_priv->tt_local_hash, data); |
111 | hlist_for_each_entry_rcu(tt_global_entry, node, head, hash_entry) { | 91 | if (tt_common_entry) |
112 | if (!compare_eth(tt_global_entry, data)) | 92 | tt_local_entry = container_of(tt_common_entry, |
113 | continue; | 93 | struct tt_local_entry, common); |
94 | return tt_local_entry; | ||
95 | } | ||
114 | 96 | ||
115 | if (!atomic_inc_not_zero(&tt_global_entry->refcount)) | 97 | static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, |
116 | continue; | 98 | const void *data) |
99 | { | ||
100 | struct tt_common_entry *tt_common_entry; | ||
101 | struct tt_global_entry *tt_global_entry = NULL; | ||
117 | 102 | ||
118 | tt_global_entry_tmp = tt_global_entry; | 103 | tt_common_entry = tt_hash_find(bat_priv->tt_global_hash, data); |
119 | break; | 104 | if (tt_common_entry) |
120 | } | 105 | tt_global_entry = container_of(tt_common_entry, |
121 | rcu_read_unlock(); | 106 | struct tt_global_entry, common); |
107 | return tt_global_entry; | ||
122 | 108 | ||
123 | return tt_global_entry_tmp; | ||
124 | } | 109 | } |
125 | 110 | ||
126 | static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) | 111 | static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) |
@@ -133,15 +118,18 @@ static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) | |||
133 | 118 | ||
134 | static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) | 119 | static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) |
135 | { | 120 | { |
136 | if (atomic_dec_and_test(&tt_local_entry->refcount)) | 121 | if (atomic_dec_and_test(&tt_local_entry->common.refcount)) |
137 | kfree_rcu(tt_local_entry, rcu); | 122 | kfree_rcu(tt_local_entry, common.rcu); |
138 | } | 123 | } |
139 | 124 | ||
140 | static void tt_global_entry_free_rcu(struct rcu_head *rcu) | 125 | static void tt_global_entry_free_rcu(struct rcu_head *rcu) |
141 | { | 126 | { |
127 | struct tt_common_entry *tt_common_entry; | ||
142 | struct tt_global_entry *tt_global_entry; | 128 | struct tt_global_entry *tt_global_entry; |
143 | 129 | ||
144 | tt_global_entry = container_of(rcu, struct tt_global_entry, rcu); | 130 | tt_common_entry = container_of(rcu, struct tt_common_entry, rcu); |
131 | tt_global_entry = container_of(tt_common_entry, struct tt_global_entry, | ||
132 | common); | ||
145 | 133 | ||
146 | if (tt_global_entry->orig_node) | 134 | if (tt_global_entry->orig_node) |
147 | orig_node_free_ref(tt_global_entry->orig_node); | 135 | orig_node_free_ref(tt_global_entry->orig_node); |
@@ -151,8 +139,9 @@ static void tt_global_entry_free_rcu(struct rcu_head *rcu) | |||
151 | 139 | ||
152 | static void tt_global_entry_free_ref(struct tt_global_entry *tt_global_entry) | 140 | static void tt_global_entry_free_ref(struct tt_global_entry *tt_global_entry) |
153 | { | 141 | { |
154 | if (atomic_dec_and_test(&tt_global_entry->refcount)) | 142 | if (atomic_dec_and_test(&tt_global_entry->common.refcount)) |
155 | call_rcu(&tt_global_entry->rcu, tt_global_entry_free_rcu); | 143 | call_rcu(&tt_global_entry->common.rcu, |
144 | tt_global_entry_free_rcu); | ||
156 | } | 145 | } |
157 | 146 | ||
158 | static void tt_local_event(struct bat_priv *bat_priv, const uint8_t *addr, | 147 | static void tt_local_event(struct bat_priv *bat_priv, const uint8_t *addr, |
@@ -217,26 +206,26 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr, | |||
217 | "Creating new local tt entry: %pM (ttvn: %d)\n", addr, | 206 | "Creating new local tt entry: %pM (ttvn: %d)\n", addr, |
218 | (uint8_t)atomic_read(&bat_priv->ttvn)); | 207 | (uint8_t)atomic_read(&bat_priv->ttvn)); |
219 | 208 | ||
220 | memcpy(tt_local_entry->addr, addr, ETH_ALEN); | 209 | memcpy(tt_local_entry->common.addr, addr, ETH_ALEN); |
221 | tt_local_entry->last_seen = jiffies; | 210 | tt_local_entry->common.flags = NO_FLAGS; |
222 | tt_local_entry->flags = NO_FLAGS; | ||
223 | if (is_wifi_iface(ifindex)) | 211 | if (is_wifi_iface(ifindex)) |
224 | tt_local_entry->flags |= TT_CLIENT_WIFI; | 212 | tt_local_entry->common.flags |= TT_CLIENT_WIFI; |
225 | atomic_set(&tt_local_entry->refcount, 2); | 213 | atomic_set(&tt_local_entry->common.refcount, 2); |
214 | tt_local_entry->last_seen = jiffies; | ||
226 | 215 | ||
227 | /* the batman interface mac address should never be purged */ | 216 | /* the batman interface mac address should never be purged */ |
228 | if (compare_eth(addr, soft_iface->dev_addr)) | 217 | if (compare_eth(addr, soft_iface->dev_addr)) |
229 | tt_local_entry->flags |= TT_CLIENT_NOPURGE; | 218 | tt_local_entry->common.flags |= TT_CLIENT_NOPURGE; |
230 | 219 | ||
231 | tt_local_event(bat_priv, addr, tt_local_entry->flags); | 220 | tt_local_event(bat_priv, addr, tt_local_entry->common.flags); |
232 | 221 | ||
233 | /* The local entry has to be marked as NEW to avoid to send it in | 222 | /* The local entry has to be marked as NEW to avoid to send it in |
234 | * a full table response going out before the next ttvn increment | 223 | * a full table response going out before the next ttvn increment |
235 | * (consistency check) */ | 224 | * (consistency check) */ |
236 | tt_local_entry->flags |= TT_CLIENT_NEW; | 225 | tt_local_entry->common.flags |= TT_CLIENT_NEW; |
237 | 226 | ||
238 | hash_add(bat_priv->tt_local_hash, compare_ltt, choose_orig, | 227 | hash_add(bat_priv->tt_local_hash, compare_tt, choose_orig, |
239 | tt_local_entry, &tt_local_entry->hash_entry); | 228 | &tt_local_entry->common, &tt_local_entry->common.hash_entry); |
240 | 229 | ||
241 | /* remove address from global hash if present */ | 230 | /* remove address from global hash if present */ |
242 | tt_global_entry = tt_global_hash_find(bat_priv, addr); | 231 | tt_global_entry = tt_global_hash_find(bat_priv, addr); |
@@ -247,8 +236,8 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr, | |||
247 | tt_global_entry->orig_node->tt_poss_change = true; | 236 | tt_global_entry->orig_node->tt_poss_change = true; |
248 | /* The global entry has to be marked as PENDING and has to be | 237 | /* The global entry has to be marked as PENDING and has to be |
249 | * kept for consistency purpose */ | 238 | * kept for consistency purpose */ |
250 | tt_global_entry->flags |= TT_CLIENT_PENDING; | 239 | tt_global_entry->common.flags |= TT_CLIENT_PENDING; |
251 | send_roam_adv(bat_priv, tt_global_entry->addr, | 240 | send_roam_adv(bat_priv, tt_global_entry->common.addr, |
252 | tt_global_entry->orig_node); | 241 | tt_global_entry->orig_node); |
253 | } | 242 | } |
254 | out: | 243 | out: |
@@ -310,7 +299,7 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset) | |||
310 | struct net_device *net_dev = (struct net_device *)seq->private; | 299 | struct net_device *net_dev = (struct net_device *)seq->private; |
311 | struct bat_priv *bat_priv = netdev_priv(net_dev); | 300 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
312 | struct hashtable_t *hash = bat_priv->tt_local_hash; | 301 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
313 | struct tt_local_entry *tt_local_entry; | 302 | struct tt_common_entry *tt_common_entry; |
314 | struct hard_iface *primary_if; | 303 | struct hard_iface *primary_if; |
315 | struct hlist_node *node; | 304 | struct hlist_node *node; |
316 | struct hlist_head *head; | 305 | struct hlist_head *head; |
@@ -340,19 +329,19 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset) | |||
340 | head = &hash->table[i]; | 329 | head = &hash->table[i]; |
341 | 330 | ||
342 | rcu_read_lock(); | 331 | rcu_read_lock(); |
343 | hlist_for_each_entry_rcu(tt_local_entry, node, | 332 | hlist_for_each_entry_rcu(tt_common_entry, node, |
344 | head, hash_entry) { | 333 | head, hash_entry) { |
345 | seq_printf(seq, " * %pM [%c%c%c%c%c]\n", | 334 | seq_printf(seq, " * %pM [%c%c%c%c%c]\n", |
346 | tt_local_entry->addr, | 335 | tt_common_entry->addr, |
347 | (tt_local_entry->flags & | 336 | (tt_common_entry->flags & |
348 | TT_CLIENT_ROAM ? 'R' : '.'), | 337 | TT_CLIENT_ROAM ? 'R' : '.'), |
349 | (tt_local_entry->flags & | 338 | (tt_common_entry->flags & |
350 | TT_CLIENT_NOPURGE ? 'P' : '.'), | 339 | TT_CLIENT_NOPURGE ? 'P' : '.'), |
351 | (tt_local_entry->flags & | 340 | (tt_common_entry->flags & |
352 | TT_CLIENT_NEW ? 'N' : '.'), | 341 | TT_CLIENT_NEW ? 'N' : '.'), |
353 | (tt_local_entry->flags & | 342 | (tt_common_entry->flags & |
354 | TT_CLIENT_PENDING ? 'X' : '.'), | 343 | TT_CLIENT_PENDING ? 'X' : '.'), |
355 | (tt_local_entry->flags & | 344 | (tt_common_entry->flags & |
356 | TT_CLIENT_WIFI ? 'W' : '.')); | 345 | TT_CLIENT_WIFI ? 'W' : '.')); |
357 | } | 346 | } |
358 | rcu_read_unlock(); | 347 | rcu_read_unlock(); |
@@ -367,13 +356,13 @@ static void tt_local_set_pending(struct bat_priv *bat_priv, | |||
367 | struct tt_local_entry *tt_local_entry, | 356 | struct tt_local_entry *tt_local_entry, |
368 | uint16_t flags) | 357 | uint16_t flags) |
369 | { | 358 | { |
370 | tt_local_event(bat_priv, tt_local_entry->addr, | 359 | tt_local_event(bat_priv, tt_local_entry->common.addr, |
371 | tt_local_entry->flags | flags); | 360 | tt_local_entry->common.flags | flags); |
372 | 361 | ||
373 | /* The local client has to be marked as "pending to be removed" but has | 362 | /* The local client has to be marked as "pending to be removed" but has |
374 | * to be kept in the table in order to send it in a full table | 363 | * to be kept in the table in order to send it in a full table |
375 | * response issued before the net ttvn increment (consistency check) */ | 364 | * response issued before the net ttvn increment (consistency check) */ |
376 | tt_local_entry->flags |= TT_CLIENT_PENDING; | 365 | tt_local_entry->common.flags |= TT_CLIENT_PENDING; |
377 | } | 366 | } |
378 | 367 | ||
379 | void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr, | 368 | void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr, |
@@ -389,7 +378,7 @@ void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr, | |||
389 | (roaming ? TT_CLIENT_ROAM : NO_FLAGS)); | 378 | (roaming ? TT_CLIENT_ROAM : NO_FLAGS)); |
390 | 379 | ||
391 | bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) pending to be removed: " | 380 | bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) pending to be removed: " |
392 | "%s\n", tt_local_entry->addr, message); | 381 | "%s\n", tt_local_entry->common.addr, message); |
393 | out: | 382 | out: |
394 | if (tt_local_entry) | 383 | if (tt_local_entry) |
395 | tt_local_entry_free_ref(tt_local_entry); | 384 | tt_local_entry_free_ref(tt_local_entry); |
@@ -399,6 +388,7 @@ static void tt_local_purge(struct bat_priv *bat_priv) | |||
399 | { | 388 | { |
400 | struct hashtable_t *hash = bat_priv->tt_local_hash; | 389 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
401 | struct tt_local_entry *tt_local_entry; | 390 | struct tt_local_entry *tt_local_entry; |
391 | struct tt_common_entry *tt_common_entry; | ||
402 | struct hlist_node *node, *node_tmp; | 392 | struct hlist_node *node, *node_tmp; |
403 | struct hlist_head *head; | 393 | struct hlist_head *head; |
404 | spinlock_t *list_lock; /* protects write access to the hash lists */ | 394 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
@@ -409,13 +399,16 @@ static void tt_local_purge(struct bat_priv *bat_priv) | |||
409 | list_lock = &hash->list_locks[i]; | 399 | list_lock = &hash->list_locks[i]; |
410 | 400 | ||
411 | spin_lock_bh(list_lock); | 401 | spin_lock_bh(list_lock); |
412 | hlist_for_each_entry_safe(tt_local_entry, node, node_tmp, | 402 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
413 | head, hash_entry) { | 403 | head, hash_entry) { |
414 | if (tt_local_entry->flags & TT_CLIENT_NOPURGE) | 404 | tt_local_entry = container_of(tt_common_entry, |
405 | struct tt_local_entry, | ||
406 | common); | ||
407 | if (tt_local_entry->common.flags & TT_CLIENT_NOPURGE) | ||
415 | continue; | 408 | continue; |
416 | 409 | ||
417 | /* entry already marked for deletion */ | 410 | /* entry already marked for deletion */ |
418 | if (tt_local_entry->flags & TT_CLIENT_PENDING) | 411 | if (tt_local_entry->common.flags & TT_CLIENT_PENDING) |
419 | continue; | 412 | continue; |
420 | 413 | ||
421 | if (!is_out_of_time(tt_local_entry->last_seen, | 414 | if (!is_out_of_time(tt_local_entry->last_seen, |
@@ -426,7 +419,7 @@ static void tt_local_purge(struct bat_priv *bat_priv) | |||
426 | TT_CLIENT_DEL); | 419 | TT_CLIENT_DEL); |
427 | bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) " | 420 | bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) " |
428 | "pending to be removed: timed out\n", | 421 | "pending to be removed: timed out\n", |
429 | tt_local_entry->addr); | 422 | tt_local_entry->common.addr); |
430 | } | 423 | } |
431 | spin_unlock_bh(list_lock); | 424 | spin_unlock_bh(list_lock); |
432 | } | 425 | } |
@@ -437,6 +430,7 @@ static void tt_local_table_free(struct bat_priv *bat_priv) | |||
437 | { | 430 | { |
438 | struct hashtable_t *hash; | 431 | struct hashtable_t *hash; |
439 | spinlock_t *list_lock; /* protects write access to the hash lists */ | 432 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
433 | struct tt_common_entry *tt_common_entry; | ||
440 | struct tt_local_entry *tt_local_entry; | 434 | struct tt_local_entry *tt_local_entry; |
441 | struct hlist_node *node, *node_tmp; | 435 | struct hlist_node *node, *node_tmp; |
442 | struct hlist_head *head; | 436 | struct hlist_head *head; |
@@ -452,9 +446,12 @@ static void tt_local_table_free(struct bat_priv *bat_priv) | |||
452 | list_lock = &hash->list_locks[i]; | 446 | list_lock = &hash->list_locks[i]; |
453 | 447 | ||
454 | spin_lock_bh(list_lock); | 448 | spin_lock_bh(list_lock); |
455 | hlist_for_each_entry_safe(tt_local_entry, node, node_tmp, | 449 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
456 | head, hash_entry) { | 450 | head, hash_entry) { |
457 | hlist_del_rcu(node); | 451 | hlist_del_rcu(node); |
452 | tt_local_entry = container_of(tt_common_entry, | ||
453 | struct tt_local_entry, | ||
454 | common); | ||
458 | tt_local_entry_free_ref(tt_local_entry); | 455 | tt_local_entry_free_ref(tt_local_entry); |
459 | } | 456 | } |
460 | spin_unlock_bh(list_lock); | 457 | spin_unlock_bh(list_lock); |
@@ -512,18 +509,18 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, | |||
512 | if (!tt_global_entry) | 509 | if (!tt_global_entry) |
513 | goto out; | 510 | goto out; |
514 | 511 | ||
515 | memcpy(tt_global_entry->addr, tt_addr, ETH_ALEN); | 512 | memcpy(tt_global_entry->common.addr, tt_addr, ETH_ALEN); |
513 | tt_global_entry->common.flags = NO_FLAGS; | ||
514 | atomic_set(&tt_global_entry->common.refcount, 2); | ||
516 | /* Assign the new orig_node */ | 515 | /* Assign the new orig_node */ |
517 | atomic_inc(&orig_node->refcount); | 516 | atomic_inc(&orig_node->refcount); |
518 | tt_global_entry->orig_node = orig_node; | 517 | tt_global_entry->orig_node = orig_node; |
519 | tt_global_entry->ttvn = ttvn; | 518 | tt_global_entry->ttvn = ttvn; |
520 | tt_global_entry->flags = NO_FLAGS; | ||
521 | tt_global_entry->roam_at = 0; | 519 | tt_global_entry->roam_at = 0; |
522 | atomic_set(&tt_global_entry->refcount, 2); | ||
523 | 520 | ||
524 | hash_add(bat_priv->tt_global_hash, compare_gtt, | 521 | hash_add(bat_priv->tt_global_hash, compare_tt, |
525 | choose_orig, tt_global_entry, | 522 | choose_orig, &tt_global_entry->common, |
526 | &tt_global_entry->hash_entry); | 523 | &tt_global_entry->common.hash_entry); |
527 | atomic_inc(&orig_node->tt_size); | 524 | atomic_inc(&orig_node->tt_size); |
528 | } else { | 525 | } else { |
529 | if (tt_global_entry->orig_node != orig_node) { | 526 | if (tt_global_entry->orig_node != orig_node) { |
@@ -534,20 +531,20 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, | |||
534 | orig_node_free_ref(orig_node_tmp); | 531 | orig_node_free_ref(orig_node_tmp); |
535 | atomic_inc(&orig_node->tt_size); | 532 | atomic_inc(&orig_node->tt_size); |
536 | } | 533 | } |
534 | tt_global_entry->common.flags = NO_FLAGS; | ||
537 | tt_global_entry->ttvn = ttvn; | 535 | tt_global_entry->ttvn = ttvn; |
538 | tt_global_entry->flags = NO_FLAGS; | ||
539 | tt_global_entry->roam_at = 0; | 536 | tt_global_entry->roam_at = 0; |
540 | } | 537 | } |
541 | 538 | ||
542 | if (wifi) | 539 | if (wifi) |
543 | tt_global_entry->flags |= TT_CLIENT_WIFI; | 540 | tt_global_entry->common.flags |= TT_CLIENT_WIFI; |
544 | 541 | ||
545 | bat_dbg(DBG_TT, bat_priv, | 542 | bat_dbg(DBG_TT, bat_priv, |
546 | "Creating new global tt entry: %pM (via %pM)\n", | 543 | "Creating new global tt entry: %pM (via %pM)\n", |
547 | tt_global_entry->addr, orig_node->orig); | 544 | tt_global_entry->common.addr, orig_node->orig); |
548 | 545 | ||
549 | /* remove address from local hash if present */ | 546 | /* remove address from local hash if present */ |
550 | tt_local_remove(bat_priv, tt_global_entry->addr, | 547 | tt_local_remove(bat_priv, tt_global_entry->common.addr, |
551 | "global tt received", roaming); | 548 | "global tt received", roaming); |
552 | ret = 1; | 549 | ret = 1; |
553 | out: | 550 | out: |
@@ -561,6 +558,7 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset) | |||
561 | struct net_device *net_dev = (struct net_device *)seq->private; | 558 | struct net_device *net_dev = (struct net_device *)seq->private; |
562 | struct bat_priv *bat_priv = netdev_priv(net_dev); | 559 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
563 | struct hashtable_t *hash = bat_priv->tt_global_hash; | 560 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
561 | struct tt_common_entry *tt_common_entry; | ||
564 | struct tt_global_entry *tt_global_entry; | 562 | struct tt_global_entry *tt_global_entry; |
565 | struct hard_iface *primary_if; | 563 | struct hard_iface *primary_if; |
566 | struct hlist_node *node; | 564 | struct hlist_node *node; |
@@ -593,20 +591,24 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset) | |||
593 | head = &hash->table[i]; | 591 | head = &hash->table[i]; |
594 | 592 | ||
595 | rcu_read_lock(); | 593 | rcu_read_lock(); |
596 | hlist_for_each_entry_rcu(tt_global_entry, node, | 594 | hlist_for_each_entry_rcu(tt_common_entry, node, |
597 | head, hash_entry) { | 595 | head, hash_entry) { |
596 | tt_global_entry = container_of(tt_common_entry, | ||
597 | struct tt_global_entry, | ||
598 | common); | ||
598 | seq_printf(seq, " * %pM (%3u) via %pM (%3u) " | 599 | seq_printf(seq, " * %pM (%3u) via %pM (%3u) " |
599 | "[%c%c%c]\n", tt_global_entry->addr, | 600 | "[%c%c%c]\n", |
601 | tt_global_entry->common.addr, | ||
600 | tt_global_entry->ttvn, | 602 | tt_global_entry->ttvn, |
601 | tt_global_entry->orig_node->orig, | 603 | tt_global_entry->orig_node->orig, |
602 | (uint8_t) atomic_read( | 604 | (uint8_t) atomic_read( |
603 | &tt_global_entry->orig_node-> | 605 | &tt_global_entry->orig_node-> |
604 | last_ttvn), | 606 | last_ttvn), |
605 | (tt_global_entry->flags & | 607 | (tt_global_entry->common.flags & |
606 | TT_CLIENT_ROAM ? 'R' : '.'), | 608 | TT_CLIENT_ROAM ? 'R' : '.'), |
607 | (tt_global_entry->flags & | 609 | (tt_global_entry->common.flags & |
608 | TT_CLIENT_PENDING ? 'X' : '.'), | 610 | TT_CLIENT_PENDING ? 'X' : '.'), |
609 | (tt_global_entry->flags & | 611 | (tt_global_entry->common.flags & |
610 | TT_CLIENT_WIFI ? 'W' : '.')); | 612 | TT_CLIENT_WIFI ? 'W' : '.')); |
611 | } | 613 | } |
612 | rcu_read_unlock(); | 614 | rcu_read_unlock(); |
@@ -626,13 +628,13 @@ static void _tt_global_del(struct bat_priv *bat_priv, | |||
626 | 628 | ||
627 | bat_dbg(DBG_TT, bat_priv, | 629 | bat_dbg(DBG_TT, bat_priv, |
628 | "Deleting global tt entry %pM (via %pM): %s\n", | 630 | "Deleting global tt entry %pM (via %pM): %s\n", |
629 | tt_global_entry->addr, tt_global_entry->orig_node->orig, | 631 | tt_global_entry->common.addr, tt_global_entry->orig_node->orig, |
630 | message); | 632 | message); |
631 | 633 | ||
632 | atomic_dec(&tt_global_entry->orig_node->tt_size); | 634 | atomic_dec(&tt_global_entry->orig_node->tt_size); |
633 | 635 | ||
634 | hash_remove(bat_priv->tt_global_hash, compare_gtt, choose_orig, | 636 | hash_remove(bat_priv->tt_global_hash, compare_tt, choose_orig, |
635 | tt_global_entry->addr); | 637 | tt_global_entry->common.addr); |
636 | out: | 638 | out: |
637 | if (tt_global_entry) | 639 | if (tt_global_entry) |
638 | tt_global_entry_free_ref(tt_global_entry); | 640 | tt_global_entry_free_ref(tt_global_entry); |
@@ -650,7 +652,7 @@ void tt_global_del(struct bat_priv *bat_priv, | |||
650 | 652 | ||
651 | if (tt_global_entry->orig_node == orig_node) { | 653 | if (tt_global_entry->orig_node == orig_node) { |
652 | if (roaming) { | 654 | if (roaming) { |
653 | tt_global_entry->flags |= TT_CLIENT_ROAM; | 655 | tt_global_entry->common.flags |= TT_CLIENT_ROAM; |
654 | tt_global_entry->roam_at = jiffies; | 656 | tt_global_entry->roam_at = jiffies; |
655 | goto out; | 657 | goto out; |
656 | } | 658 | } |
@@ -665,6 +667,7 @@ void tt_global_del_orig(struct bat_priv *bat_priv, | |||
665 | struct orig_node *orig_node, const char *message) | 667 | struct orig_node *orig_node, const char *message) |
666 | { | 668 | { |
667 | struct tt_global_entry *tt_global_entry; | 669 | struct tt_global_entry *tt_global_entry; |
670 | struct tt_common_entry *tt_common_entry; | ||
668 | uint32_t i; | 671 | uint32_t i; |
669 | struct hashtable_t *hash = bat_priv->tt_global_hash; | 672 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
670 | struct hlist_node *node, *safe; | 673 | struct hlist_node *node, *safe; |
@@ -679,13 +682,16 @@ void tt_global_del_orig(struct bat_priv *bat_priv, | |||
679 | list_lock = &hash->list_locks[i]; | 682 | list_lock = &hash->list_locks[i]; |
680 | 683 | ||
681 | spin_lock_bh(list_lock); | 684 | spin_lock_bh(list_lock); |
682 | hlist_for_each_entry_safe(tt_global_entry, node, safe, | 685 | hlist_for_each_entry_safe(tt_common_entry, node, safe, |
683 | head, hash_entry) { | 686 | head, hash_entry) { |
687 | tt_global_entry = container_of(tt_common_entry, | ||
688 | struct tt_global_entry, | ||
689 | common); | ||
684 | if (tt_global_entry->orig_node == orig_node) { | 690 | if (tt_global_entry->orig_node == orig_node) { |
685 | bat_dbg(DBG_TT, bat_priv, | 691 | bat_dbg(DBG_TT, bat_priv, |
686 | "Deleting global tt entry %pM " | 692 | "Deleting global tt entry %pM " |
687 | "(via %pM): %s\n", | 693 | "(via %pM): %s\n", |
688 | tt_global_entry->addr, | 694 | tt_global_entry->common.addr, |
689 | tt_global_entry->orig_node->orig, | 695 | tt_global_entry->orig_node->orig, |
690 | message); | 696 | message); |
691 | hlist_del_rcu(node); | 697 | hlist_del_rcu(node); |
@@ -700,6 +706,7 @@ void tt_global_del_orig(struct bat_priv *bat_priv, | |||
700 | static void tt_global_roam_purge(struct bat_priv *bat_priv) | 706 | static void tt_global_roam_purge(struct bat_priv *bat_priv) |
701 | { | 707 | { |
702 | struct hashtable_t *hash = bat_priv->tt_global_hash; | 708 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
709 | struct tt_common_entry *tt_common_entry; | ||
703 | struct tt_global_entry *tt_global_entry; | 710 | struct tt_global_entry *tt_global_entry; |
704 | struct hlist_node *node, *node_tmp; | 711 | struct hlist_node *node, *node_tmp; |
705 | struct hlist_head *head; | 712 | struct hlist_head *head; |
@@ -711,9 +718,12 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv) | |||
711 | list_lock = &hash->list_locks[i]; | 718 | list_lock = &hash->list_locks[i]; |
712 | 719 | ||
713 | spin_lock_bh(list_lock); | 720 | spin_lock_bh(list_lock); |
714 | hlist_for_each_entry_safe(tt_global_entry, node, node_tmp, | 721 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
715 | head, hash_entry) { | 722 | head, hash_entry) { |
716 | if (!(tt_global_entry->flags & TT_CLIENT_ROAM)) | 723 | tt_global_entry = container_of(tt_common_entry, |
724 | struct tt_global_entry, | ||
725 | common); | ||
726 | if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM)) | ||
717 | continue; | 727 | continue; |
718 | if (!is_out_of_time(tt_global_entry->roam_at, | 728 | if (!is_out_of_time(tt_global_entry->roam_at, |
719 | TT_CLIENT_ROAM_TIMEOUT * 1000)) | 729 | TT_CLIENT_ROAM_TIMEOUT * 1000)) |
@@ -721,7 +731,7 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv) | |||
721 | 731 | ||
722 | bat_dbg(DBG_TT, bat_priv, "Deleting global " | 732 | bat_dbg(DBG_TT, bat_priv, "Deleting global " |
723 | "tt entry (%pM): Roaming timeout\n", | 733 | "tt entry (%pM): Roaming timeout\n", |
724 | tt_global_entry->addr); | 734 | tt_global_entry->common.addr); |
725 | atomic_dec(&tt_global_entry->orig_node->tt_size); | 735 | atomic_dec(&tt_global_entry->orig_node->tt_size); |
726 | hlist_del_rcu(node); | 736 | hlist_del_rcu(node); |
727 | tt_global_entry_free_ref(tt_global_entry); | 737 | tt_global_entry_free_ref(tt_global_entry); |
@@ -735,6 +745,7 @@ static void tt_global_table_free(struct bat_priv *bat_priv) | |||
735 | { | 745 | { |
736 | struct hashtable_t *hash; | 746 | struct hashtable_t *hash; |
737 | spinlock_t *list_lock; /* protects write access to the hash lists */ | 747 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
748 | struct tt_common_entry *tt_common_entry; | ||
738 | struct tt_global_entry *tt_global_entry; | 749 | struct tt_global_entry *tt_global_entry; |
739 | struct hlist_node *node, *node_tmp; | 750 | struct hlist_node *node, *node_tmp; |
740 | struct hlist_head *head; | 751 | struct hlist_head *head; |
@@ -750,9 +761,12 @@ static void tt_global_table_free(struct bat_priv *bat_priv) | |||
750 | list_lock = &hash->list_locks[i]; | 761 | list_lock = &hash->list_locks[i]; |
751 | 762 | ||
752 | spin_lock_bh(list_lock); | 763 | spin_lock_bh(list_lock); |
753 | hlist_for_each_entry_safe(tt_global_entry, node, node_tmp, | 764 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
754 | head, hash_entry) { | 765 | head, hash_entry) { |
755 | hlist_del_rcu(node); | 766 | hlist_del_rcu(node); |
767 | tt_global_entry = container_of(tt_common_entry, | ||
768 | struct tt_global_entry, | ||
769 | common); | ||
756 | tt_global_entry_free_ref(tt_global_entry); | 770 | tt_global_entry_free_ref(tt_global_entry); |
757 | } | 771 | } |
758 | spin_unlock_bh(list_lock); | 772 | spin_unlock_bh(list_lock); |
@@ -768,8 +782,8 @@ static bool _is_ap_isolated(struct tt_local_entry *tt_local_entry, | |||
768 | { | 782 | { |
769 | bool ret = false; | 783 | bool ret = false; |
770 | 784 | ||
771 | if (tt_local_entry->flags & TT_CLIENT_WIFI && | 785 | if (tt_local_entry->common.flags & TT_CLIENT_WIFI && |
772 | tt_global_entry->flags & TT_CLIENT_WIFI) | 786 | tt_global_entry->common.flags & TT_CLIENT_WIFI) |
773 | ret = true; | 787 | ret = true; |
774 | 788 | ||
775 | return ret; | 789 | return ret; |
@@ -802,7 +816,7 @@ struct orig_node *transtable_search(struct bat_priv *bat_priv, | |||
802 | 816 | ||
803 | /* A global client marked as PENDING has already moved from that | 817 | /* A global client marked as PENDING has already moved from that |
804 | * originator */ | 818 | * originator */ |
805 | if (tt_global_entry->flags & TT_CLIENT_PENDING) | 819 | if (tt_global_entry->common.flags & TT_CLIENT_PENDING) |
806 | goto out; | 820 | goto out; |
807 | 821 | ||
808 | orig_node = tt_global_entry->orig_node; | 822 | orig_node = tt_global_entry->orig_node; |
@@ -821,6 +835,7 @@ uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node) | |||
821 | { | 835 | { |
822 | uint16_t total = 0, total_one; | 836 | uint16_t total = 0, total_one; |
823 | struct hashtable_t *hash = bat_priv->tt_global_hash; | 837 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
838 | struct tt_common_entry *tt_common_entry; | ||
824 | struct tt_global_entry *tt_global_entry; | 839 | struct tt_global_entry *tt_global_entry; |
825 | struct hlist_node *node; | 840 | struct hlist_node *node; |
826 | struct hlist_head *head; | 841 | struct hlist_head *head; |
@@ -831,20 +846,23 @@ uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node) | |||
831 | head = &hash->table[i]; | 846 | head = &hash->table[i]; |
832 | 847 | ||
833 | rcu_read_lock(); | 848 | rcu_read_lock(); |
834 | hlist_for_each_entry_rcu(tt_global_entry, node, | 849 | hlist_for_each_entry_rcu(tt_common_entry, node, |
835 | head, hash_entry) { | 850 | head, hash_entry) { |
851 | tt_global_entry = container_of(tt_common_entry, | ||
852 | struct tt_global_entry, | ||
853 | common); | ||
836 | if (compare_eth(tt_global_entry->orig_node, | 854 | if (compare_eth(tt_global_entry->orig_node, |
837 | orig_node)) { | 855 | orig_node)) { |
838 | /* Roaming clients are in the global table for | 856 | /* Roaming clients are in the global table for |
839 | * consistency only. They don't have to be | 857 | * consistency only. They don't have to be |
840 | * taken into account while computing the | 858 | * taken into account while computing the |
841 | * global crc */ | 859 | * global crc */ |
842 | if (tt_global_entry->flags & TT_CLIENT_ROAM) | 860 | if (tt_common_entry->flags & TT_CLIENT_ROAM) |
843 | continue; | 861 | continue; |
844 | total_one = 0; | 862 | total_one = 0; |
845 | for (j = 0; j < ETH_ALEN; j++) | 863 | for (j = 0; j < ETH_ALEN; j++) |
846 | total_one = crc16_byte(total_one, | 864 | total_one = crc16_byte(total_one, |
847 | tt_global_entry->addr[j]); | 865 | tt_common_entry->addr[j]); |
848 | total ^= total_one; | 866 | total ^= total_one; |
849 | } | 867 | } |
850 | } | 868 | } |
@@ -859,7 +877,7 @@ uint16_t tt_local_crc(struct bat_priv *bat_priv) | |||
859 | { | 877 | { |
860 | uint16_t total = 0, total_one; | 878 | uint16_t total = 0, total_one; |
861 | struct hashtable_t *hash = bat_priv->tt_local_hash; | 879 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
862 | struct tt_local_entry *tt_local_entry; | 880 | struct tt_common_entry *tt_common_entry; |
863 | struct hlist_node *node; | 881 | struct hlist_node *node; |
864 | struct hlist_head *head; | 882 | struct hlist_head *head; |
865 | uint32_t i; | 883 | uint32_t i; |
@@ -869,16 +887,16 @@ uint16_t tt_local_crc(struct bat_priv *bat_priv) | |||
869 | head = &hash->table[i]; | 887 | head = &hash->table[i]; |
870 | 888 | ||
871 | rcu_read_lock(); | 889 | rcu_read_lock(); |
872 | hlist_for_each_entry_rcu(tt_local_entry, node, | 890 | hlist_for_each_entry_rcu(tt_common_entry, node, |
873 | head, hash_entry) { | 891 | head, hash_entry) { |
874 | /* not yet committed clients have not to be taken into | 892 | /* not yet committed clients have not to be taken into |
875 | * account while computing the CRC */ | 893 | * account while computing the CRC */ |
876 | if (tt_local_entry->flags & TT_CLIENT_NEW) | 894 | if (tt_common_entry->flags & TT_CLIENT_NEW) |
877 | continue; | 895 | continue; |
878 | total_one = 0; | 896 | total_one = 0; |
879 | for (j = 0; j < ETH_ALEN; j++) | 897 | for (j = 0; j < ETH_ALEN; j++) |
880 | total_one = crc16_byte(total_one, | 898 | total_one = crc16_byte(total_one, |
881 | tt_local_entry->addr[j]); | 899 | tt_common_entry->addr[j]); |
882 | total ^= total_one; | 900 | total ^= total_one; |
883 | } | 901 | } |
884 | rcu_read_unlock(); | 902 | rcu_read_unlock(); |
@@ -967,21 +985,25 @@ unlock: | |||
967 | /* data_ptr is useless here, but has to be kept to respect the prototype */ | 985 | /* data_ptr is useless here, but has to be kept to respect the prototype */ |
968 | static int tt_local_valid_entry(const void *entry_ptr, const void *data_ptr) | 986 | static int tt_local_valid_entry(const void *entry_ptr, const void *data_ptr) |
969 | { | 987 | { |
970 | const struct tt_local_entry *tt_local_entry = entry_ptr; | 988 | const struct tt_common_entry *tt_common_entry = entry_ptr; |
971 | 989 | ||
972 | if (tt_local_entry->flags & TT_CLIENT_NEW) | 990 | if (tt_common_entry->flags & TT_CLIENT_NEW) |
973 | return 0; | 991 | return 0; |
974 | return 1; | 992 | return 1; |
975 | } | 993 | } |
976 | 994 | ||
977 | static int tt_global_valid_entry(const void *entry_ptr, const void *data_ptr) | 995 | static int tt_global_valid_entry(const void *entry_ptr, const void *data_ptr) |
978 | { | 996 | { |
979 | const struct tt_global_entry *tt_global_entry = entry_ptr; | 997 | const struct tt_common_entry *tt_common_entry = entry_ptr; |
998 | const struct tt_global_entry *tt_global_entry; | ||
980 | const struct orig_node *orig_node = data_ptr; | 999 | const struct orig_node *orig_node = data_ptr; |
981 | 1000 | ||
982 | if (tt_global_entry->flags & TT_CLIENT_ROAM) | 1001 | if (tt_common_entry->flags & TT_CLIENT_ROAM) |
983 | return 0; | 1002 | return 0; |
984 | 1003 | ||
1004 | tt_global_entry = container_of(tt_common_entry, struct tt_global_entry, | ||
1005 | common); | ||
1006 | |||
985 | return (tt_global_entry->orig_node == orig_node); | 1007 | return (tt_global_entry->orig_node == orig_node); |
986 | } | 1008 | } |
987 | 1009 | ||
@@ -992,7 +1014,7 @@ static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn, | |||
992 | const void *), | 1014 | const void *), |
993 | void *cb_data) | 1015 | void *cb_data) |
994 | { | 1016 | { |
995 | struct tt_local_entry *tt_local_entry; | 1017 | struct tt_common_entry *tt_common_entry; |
996 | struct tt_query_packet *tt_response; | 1018 | struct tt_query_packet *tt_response; |
997 | struct tt_change *tt_change; | 1019 | struct tt_change *tt_change; |
998 | struct hlist_node *node; | 1020 | struct hlist_node *node; |
@@ -1024,15 +1046,16 @@ static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn, | |||
1024 | for (i = 0; i < hash->size; i++) { | 1046 | for (i = 0; i < hash->size; i++) { |
1025 | head = &hash->table[i]; | 1047 | head = &hash->table[i]; |
1026 | 1048 | ||
1027 | hlist_for_each_entry_rcu(tt_local_entry, node, | 1049 | hlist_for_each_entry_rcu(tt_common_entry, node, |
1028 | head, hash_entry) { | 1050 | head, hash_entry) { |
1029 | if (tt_count == tt_tot) | 1051 | if (tt_count == tt_tot) |
1030 | break; | 1052 | break; |
1031 | 1053 | ||
1032 | if ((valid_cb) && (!valid_cb(tt_local_entry, cb_data))) | 1054 | if ((valid_cb) && (!valid_cb(tt_common_entry, cb_data))) |
1033 | continue; | 1055 | continue; |
1034 | 1056 | ||
1035 | memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN); | 1057 | memcpy(tt_change->addr, tt_common_entry->addr, |
1058 | ETH_ALEN); | ||
1036 | tt_change->flags = NO_FLAGS; | 1059 | tt_change->flags = NO_FLAGS; |
1037 | 1060 | ||
1038 | tt_count++; | 1061 | tt_count++; |
@@ -1449,7 +1472,7 @@ bool is_my_client(struct bat_priv *bat_priv, const uint8_t *addr) | |||
1449 | goto out; | 1472 | goto out; |
1450 | /* Check if the client has been logically deleted (but is kept for | 1473 | /* Check if the client has been logically deleted (but is kept for |
1451 | * consistency purpose) */ | 1474 | * consistency purpose) */ |
1452 | if (tt_local_entry->flags & TT_CLIENT_PENDING) | 1475 | if (tt_local_entry->common.flags & TT_CLIENT_PENDING) |
1453 | goto out; | 1476 | goto out; |
1454 | ret = true; | 1477 | ret = true; |
1455 | out: | 1478 | out: |
@@ -1681,7 +1704,7 @@ static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags) | |||
1681 | struct hashtable_t *hash = bat_priv->tt_local_hash; | 1704 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
1682 | struct hlist_head *head; | 1705 | struct hlist_head *head; |
1683 | struct hlist_node *node; | 1706 | struct hlist_node *node; |
1684 | struct tt_local_entry *tt_local_entry; | 1707 | struct tt_common_entry *tt_common_entry; |
1685 | 1708 | ||
1686 | if (!hash) | 1709 | if (!hash) |
1687 | return; | 1710 | return; |
@@ -1690,11 +1713,11 @@ static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags) | |||
1690 | head = &hash->table[i]; | 1713 | head = &hash->table[i]; |
1691 | 1714 | ||
1692 | rcu_read_lock(); | 1715 | rcu_read_lock(); |
1693 | hlist_for_each_entry_rcu(tt_local_entry, node, | 1716 | hlist_for_each_entry_rcu(tt_common_entry, node, |
1694 | head, hash_entry) { | 1717 | head, hash_entry) { |
1695 | if (!(tt_local_entry->flags & flags)) | 1718 | if (!(tt_common_entry->flags & flags)) |
1696 | continue; | 1719 | continue; |
1697 | tt_local_entry->flags &= ~flags; | 1720 | tt_common_entry->flags &= ~flags; |
1698 | atomic_inc(&bat_priv->num_local_tt); | 1721 | atomic_inc(&bat_priv->num_local_tt); |
1699 | } | 1722 | } |
1700 | rcu_read_unlock(); | 1723 | rcu_read_unlock(); |
@@ -1706,6 +1729,7 @@ static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags) | |||
1706 | static void tt_local_purge_pending_clients(struct bat_priv *bat_priv) | 1729 | static void tt_local_purge_pending_clients(struct bat_priv *bat_priv) |
1707 | { | 1730 | { |
1708 | struct hashtable_t *hash = bat_priv->tt_local_hash; | 1731 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
1732 | struct tt_common_entry *tt_common_entry; | ||
1709 | struct tt_local_entry *tt_local_entry; | 1733 | struct tt_local_entry *tt_local_entry; |
1710 | struct hlist_node *node, *node_tmp; | 1734 | struct hlist_node *node, *node_tmp; |
1711 | struct hlist_head *head; | 1735 | struct hlist_head *head; |
@@ -1720,16 +1744,19 @@ static void tt_local_purge_pending_clients(struct bat_priv *bat_priv) | |||
1720 | list_lock = &hash->list_locks[i]; | 1744 | list_lock = &hash->list_locks[i]; |
1721 | 1745 | ||
1722 | spin_lock_bh(list_lock); | 1746 | spin_lock_bh(list_lock); |
1723 | hlist_for_each_entry_safe(tt_local_entry, node, node_tmp, | 1747 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
1724 | head, hash_entry) { | 1748 | head, hash_entry) { |
1725 | if (!(tt_local_entry->flags & TT_CLIENT_PENDING)) | 1749 | if (!(tt_common_entry->flags & TT_CLIENT_PENDING)) |
1726 | continue; | 1750 | continue; |
1727 | 1751 | ||
1728 | bat_dbg(DBG_TT, bat_priv, "Deleting local tt entry " | 1752 | bat_dbg(DBG_TT, bat_priv, "Deleting local tt entry " |
1729 | "(%pM): pending\n", tt_local_entry->addr); | 1753 | "(%pM): pending\n", tt_common_entry->addr); |
1730 | 1754 | ||
1731 | atomic_dec(&bat_priv->num_local_tt); | 1755 | atomic_dec(&bat_priv->num_local_tt); |
1732 | hlist_del_rcu(node); | 1756 | hlist_del_rcu(node); |
1757 | tt_local_entry = container_of(tt_common_entry, | ||
1758 | struct tt_local_entry, | ||
1759 | common); | ||
1733 | tt_local_entry_free_ref(tt_local_entry); | 1760 | tt_local_entry_free_ref(tt_local_entry); |
1734 | } | 1761 | } |
1735 | spin_unlock_bh(list_lock); | 1762 | spin_unlock_bh(list_lock); |