aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/translation-table.c
diff options
context:
space:
mode:
authorAntonio Quartulli <antonio@open-mesh.com>2013-06-04 06:11:39 -0400
committerAntonio Quartulli <antonio@meshcoding.com>2013-10-19 09:11:21 -0400
commitc018ad3de61a1dc4194879a53e5559e094aa7b1a (patch)
tree4edb9c156b618dae46d38249a5c817e0d1f1e2b0 /net/batman-adv/translation-table.c
parentbc58eeef744df93e141678ef44452f0869cd563d (diff)
batman-adv: add the VLAN ID attribute to the TT entry
To make the translation table code VLAN-aware, each entry must carry the VLAN ID which it belongs to. This patch adds such attribute to the related TT structures. Signed-off-by: Antonio Quartulli <antonio@open-mesh.com> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/translation-table.c')
-rw-r--r--net/batman-adv/translation-table.c240
1 files changed, 189 insertions, 51 deletions
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index b521afb186d4..63adb97a7677 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -34,6 +34,7 @@ static struct lock_class_key batadv_tt_local_hash_lock_class_key;
34static struct lock_class_key batadv_tt_global_hash_lock_class_key; 34static struct lock_class_key batadv_tt_global_hash_lock_class_key;
35 35
36static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, 36static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client,
37 unsigned short vid,
37 struct batadv_orig_node *orig_node); 38 struct batadv_orig_node *orig_node);
38static void batadv_tt_purge(struct work_struct *work); 39static void batadv_tt_purge(struct work_struct *work);
39static void 40static void
@@ -41,7 +42,8 @@ batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry);
41static void batadv_tt_global_del(struct batadv_priv *bat_priv, 42static void batadv_tt_global_del(struct batadv_priv *bat_priv,
42 struct batadv_orig_node *orig_node, 43 struct batadv_orig_node *orig_node,
43 const unsigned char *addr, 44 const unsigned char *addr,
44 const char *message, bool roaming); 45 unsigned short vid, const char *message,
46 bool roaming);
45 47
46/* returns 1 if they are the same mac addr */ 48/* returns 1 if they are the same mac addr */
47static int batadv_compare_tt(const struct hlist_node *node, const void *data2) 49static int batadv_compare_tt(const struct hlist_node *node, const void *data2)
@@ -52,43 +54,93 @@ static int batadv_compare_tt(const struct hlist_node *node, const void *data2)
52 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); 54 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
53} 55}
54 56
57/**
58 * batadv_choose_tt - return the index of the tt entry in the hash table
59 * @data: pointer to the tt_common_entry object to map
60 * @size: the size of the hash table
61 *
62 * Returns the hash index where the object represented by 'data' should be
63 * stored at.
64 */
65static inline uint32_t batadv_choose_tt(const void *data, uint32_t size)
66{
67 struct batadv_tt_common_entry *tt;
68 uint32_t hash = 0;
69
70 tt = (struct batadv_tt_common_entry *)data;
71 hash = batadv_hash_bytes(hash, &tt->addr, ETH_ALEN);
72 hash = batadv_hash_bytes(hash, &tt->vid, sizeof(tt->vid));
73
74 hash += (hash << 3);
75 hash ^= (hash >> 11);
76 hash += (hash << 15);
77
78 return hash % size;
79}
80
81/**
82 * batadv_tt_hash_find - look for a client in the given hash table
83 * @hash: the hash table to search
84 * @addr: the mac address of the client to look for
85 * @vid: VLAN identifier
86 *
87 * Returns a pointer to the tt_common struct belonging to the searched client if
88 * found, NULL otherwise.
89 */
55static struct batadv_tt_common_entry * 90static struct batadv_tt_common_entry *
56batadv_tt_hash_find(struct batadv_hashtable *hash, const void *data) 91batadv_tt_hash_find(struct batadv_hashtable *hash, const uint8_t *addr,
92 unsigned short vid)
57{ 93{
58 struct hlist_head *head; 94 struct hlist_head *head;
59 struct batadv_tt_common_entry *tt_common_entry; 95 struct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL;
60 struct batadv_tt_common_entry *tt_common_entry_tmp = NULL;
61 uint32_t index; 96 uint32_t index;
62 97
63 if (!hash) 98 if (!hash)
64 return NULL; 99 return NULL;
65 100
66 index = batadv_choose_orig(data, hash->size); 101 memcpy(to_search.addr, addr, ETH_ALEN);
102 to_search.vid = vid;
103
104 index = batadv_choose_tt(&to_search, hash->size);
67 head = &hash->table[index]; 105 head = &hash->table[index];
68 106
69 rcu_read_lock(); 107 rcu_read_lock();
70 hlist_for_each_entry_rcu(tt_common_entry, head, hash_entry) { 108 hlist_for_each_entry_rcu(tt, head, hash_entry) {
71 if (!batadv_compare_eth(tt_common_entry, data)) 109 if (!batadv_compare_eth(tt, addr))
110 continue;
111
112 if (tt->vid != vid)
72 continue; 113 continue;
73 114
74 if (!atomic_inc_not_zero(&tt_common_entry->refcount)) 115 if (!atomic_inc_not_zero(&tt->refcount))
75 continue; 116 continue;
76 117
77 tt_common_entry_tmp = tt_common_entry; 118 tt_tmp = tt;
78 break; 119 break;
79 } 120 }
80 rcu_read_unlock(); 121 rcu_read_unlock();
81 122
82 return tt_common_entry_tmp; 123 return tt_tmp;
83} 124}
84 125
126/**
127 * batadv_tt_local_hash_find - search the local table for a given client
128 * @bat_priv: the bat priv with all the soft interface information
129 * @addr: the mac address of the client to look for
130 * @vid: VLAN identifier
131 *
132 * Returns a pointer to the corresponding tt_local_entry struct if the client is
133 * found, NULL otherwise.
134 */
85static struct batadv_tt_local_entry * 135static struct batadv_tt_local_entry *
86batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const void *data) 136batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const uint8_t *addr,
137 unsigned short vid)
87{ 138{
88 struct batadv_tt_common_entry *tt_common_entry; 139 struct batadv_tt_common_entry *tt_common_entry;
89 struct batadv_tt_local_entry *tt_local_entry = NULL; 140 struct batadv_tt_local_entry *tt_local_entry = NULL;
90 141
91 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, data); 142 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, addr,
143 vid);
92 if (tt_common_entry) 144 if (tt_common_entry)
93 tt_local_entry = container_of(tt_common_entry, 145 tt_local_entry = container_of(tt_common_entry,
94 struct batadv_tt_local_entry, 146 struct batadv_tt_local_entry,
@@ -96,13 +148,24 @@ batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const void *data)
96 return tt_local_entry; 148 return tt_local_entry;
97} 149}
98 150
151/**
152 * batadv_tt_global_hash_find - search the global table for a given client
153 * @bat_priv: the bat priv with all the soft interface information
154 * @addr: the mac address of the client to look for
155 * @vid: VLAN identifier
156 *
157 * Returns a pointer to the corresponding tt_global_entry struct if the client
158 * is found, NULL otherwise.
159 */
99static struct batadv_tt_global_entry * 160static struct batadv_tt_global_entry *
100batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const void *data) 161batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const uint8_t *addr,
162 unsigned short vid)
101{ 163{
102 struct batadv_tt_common_entry *tt_common_entry; 164 struct batadv_tt_common_entry *tt_common_entry;
103 struct batadv_tt_global_entry *tt_global_entry = NULL; 165 struct batadv_tt_global_entry *tt_global_entry = NULL;
104 166
105 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, data); 167 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, addr,
168 vid);
106 if (tt_common_entry) 169 if (tt_common_entry)
107 tt_global_entry = container_of(tt_common_entry, 170 tt_global_entry = container_of(tt_common_entry,
108 struct batadv_tt_global_entry, 171 struct batadv_tt_global_entry,
@@ -178,6 +241,7 @@ static void batadv_tt_local_event(struct batadv_priv *bat_priv,
178 tt_change_node->change.flags = flags; 241 tt_change_node->change.flags = flags;
179 tt_change_node->change.reserved = 0; 242 tt_change_node->change.reserved = 0;
180 memcpy(tt_change_node->change.addr, common->addr, ETH_ALEN); 243 memcpy(tt_change_node->change.addr, common->addr, ETH_ALEN);
244 tt_change_node->change.vid = htons(common->vid);
181 245
182 del_op_requested = flags & BATADV_TT_CLIENT_DEL; 246 del_op_requested = flags & BATADV_TT_CLIENT_DEL;
183 247
@@ -268,12 +332,21 @@ static void batadv_tt_global_free(struct batadv_priv *bat_priv,
268 tt_global->common.addr, message); 332 tt_global->common.addr, message);
269 333
270 batadv_hash_remove(bat_priv->tt.global_hash, batadv_compare_tt, 334 batadv_hash_remove(bat_priv->tt.global_hash, batadv_compare_tt,
271 batadv_choose_orig, tt_global->common.addr); 335 batadv_choose_tt, &tt_global->common);
272 batadv_tt_global_entry_free_ref(tt_global); 336 batadv_tt_global_entry_free_ref(tt_global);
273} 337}
274 338
339/**
340 * batadv_tt_local_add - add a new client to the local table or update an
341 * existing client
342 * @soft_iface: netdev struct of the mesh interface
343 * @addr: the mac address of the client to add
344 * @vid: VLAN identifier
345 * @ifindex: index of the interface where the client is connected to (useful to
346 * identify wireless clients)
347 */
275void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, 348void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
276 int ifindex) 349 unsigned short vid, int ifindex)
277{ 350{
278 struct batadv_priv *bat_priv = netdev_priv(soft_iface); 351 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
279 struct batadv_tt_local_entry *tt_local; 352 struct batadv_tt_local_entry *tt_local;
@@ -283,8 +356,8 @@ void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
283 int hash_added; 356 int hash_added;
284 bool roamed_back = false; 357 bool roamed_back = false;
285 358
286 tt_local = batadv_tt_local_hash_find(bat_priv, addr); 359 tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid);
287 tt_global = batadv_tt_global_hash_find(bat_priv, addr); 360 tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
288 361
289 if (tt_local) { 362 if (tt_local) {
290 tt_local->last_seen = jiffies; 363 tt_local->last_seen = jiffies;
@@ -329,6 +402,7 @@ void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
329 * (consistency check) 402 * (consistency check)
330 */ 403 */
331 tt_local->common.flags = BATADV_TT_CLIENT_NEW; 404 tt_local->common.flags = BATADV_TT_CLIENT_NEW;
405 tt_local->common.vid = vid;
332 if (batadv_is_wifi_iface(ifindex)) 406 if (batadv_is_wifi_iface(ifindex))
333 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; 407 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
334 atomic_set(&tt_local->common.refcount, 2); 408 atomic_set(&tt_local->common.refcount, 2);
@@ -340,7 +414,7 @@ void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
340 tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE; 414 tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
341 415
342 hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt, 416 hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
343 batadv_choose_orig, &tt_local->common, 417 batadv_choose_tt, &tt_local->common,
344 &tt_local->common.hash_entry); 418 &tt_local->common.hash_entry);
345 419
346 if (unlikely(hash_added != 0)) { 420 if (unlikely(hash_added != 0)) {
@@ -362,6 +436,7 @@ check_roaming:
362 rcu_read_lock(); 436 rcu_read_lock();
363 hlist_for_each_entry_rcu(orig_entry, head, list) { 437 hlist_for_each_entry_rcu(orig_entry, head, list) {
364 batadv_send_roam_adv(bat_priv, tt_global->common.addr, 438 batadv_send_roam_adv(bat_priv, tt_global->common.addr,
439 tt_global->common.vid,
365 orig_entry->orig_node); 440 orig_entry->orig_node);
366 } 441 }
367 rcu_read_unlock(); 442 rcu_read_unlock();
@@ -550,19 +625,20 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
550 * batadv_tt_local_remove - logically remove an entry from the local table 625 * batadv_tt_local_remove - logically remove an entry from the local table
551 * @bat_priv: the bat priv with all the soft interface information 626 * @bat_priv: the bat priv with all the soft interface information
552 * @addr: the MAC address of the client to remove 627 * @addr: the MAC address of the client to remove
628 * @vid: VLAN identifier
553 * @message: message to append to the log on deletion 629 * @message: message to append to the log on deletion
554 * @roaming: true if the deletion is due to a roaming event 630 * @roaming: true if the deletion is due to a roaming event
555 * 631 *
556 * Returns the flags assigned to the local entry before being deleted 632 * Returns the flags assigned to the local entry before being deleted
557 */ 633 */
558uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv, 634uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv,
559 const uint8_t *addr, const char *message, 635 const uint8_t *addr, unsigned short vid,
560 bool roaming) 636 const char *message, bool roaming)
561{ 637{
562 struct batadv_tt_local_entry *tt_local_entry; 638 struct batadv_tt_local_entry *tt_local_entry;
563 uint16_t flags, curr_flags = BATADV_NO_FLAGS; 639 uint16_t flags, curr_flags = BATADV_NO_FLAGS;
564 640
565 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr); 641 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
566 if (!tt_local_entry) 642 if (!tt_local_entry)
567 goto out; 643 goto out;
568 644
@@ -798,6 +874,7 @@ out:
798 * @bat_priv: the bat priv with all the soft interface information 874 * @bat_priv: the bat priv with all the soft interface information
799 * @orig_node: the originator announcing the client 875 * @orig_node: the originator announcing the client
800 * @tt_addr: the mac address of the non-mesh client 876 * @tt_addr: the mac address of the non-mesh client
877 * @vid: VLAN identifier
801 * @flags: TT flags that have to be set for this non-mesh client 878 * @flags: TT flags that have to be set for this non-mesh client
802 * @ttvn: the tt version number ever announcing this non-mesh client 879 * @ttvn: the tt version number ever announcing this non-mesh client
803 * 880 *
@@ -813,7 +890,8 @@ out:
813 */ 890 */
814static bool batadv_tt_global_add(struct batadv_priv *bat_priv, 891static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
815 struct batadv_orig_node *orig_node, 892 struct batadv_orig_node *orig_node,
816 const unsigned char *tt_addr, uint16_t flags, 893 const unsigned char *tt_addr,
894 unsigned short vid, uint16_t flags,
817 uint8_t ttvn) 895 uint8_t ttvn)
818{ 896{
819 struct batadv_tt_global_entry *tt_global_entry; 897 struct batadv_tt_global_entry *tt_global_entry;
@@ -823,8 +901,8 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
823 struct batadv_tt_common_entry *common; 901 struct batadv_tt_common_entry *common;
824 uint16_t local_flags; 902 uint16_t local_flags;
825 903
826 tt_global_entry = batadv_tt_global_hash_find(bat_priv, tt_addr); 904 tt_global_entry = batadv_tt_global_hash_find(bat_priv, tt_addr, vid);
827 tt_local_entry = batadv_tt_local_hash_find(bat_priv, tt_addr); 905 tt_local_entry = batadv_tt_local_hash_find(bat_priv, tt_addr, vid);
828 906
829 /* if the node already has a local client for this entry, it has to wait 907 /* if the node already has a local client for this entry, it has to wait
830 * for a roaming advertisement instead of manually messing up the global 908 * for a roaming advertisement instead of manually messing up the global
@@ -841,6 +919,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
841 919
842 common = &tt_global_entry->common; 920 common = &tt_global_entry->common;
843 memcpy(common->addr, tt_addr, ETH_ALEN); 921 memcpy(common->addr, tt_addr, ETH_ALEN);
922 common->vid = vid;
844 923
845 common->flags = flags; 924 common->flags = flags;
846 tt_global_entry->roam_at = 0; 925 tt_global_entry->roam_at = 0;
@@ -858,7 +937,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,
858 937
859 hash_added = batadv_hash_add(bat_priv->tt.global_hash, 938 hash_added = batadv_hash_add(bat_priv->tt.global_hash,
860 batadv_compare_tt, 939 batadv_compare_tt,
861 batadv_choose_orig, common, 940 batadv_choose_tt, common,
862 &common->hash_entry); 941 &common->hash_entry);
863 942
864 if (unlikely(hash_added != 0)) { 943 if (unlikely(hash_added != 0)) {
@@ -924,7 +1003,7 @@ add_orig_entry:
924out_remove: 1003out_remove:
925 1004
926 /* remove address from local hash if present */ 1005 /* remove address from local hash if present */
927 local_flags = batadv_tt_local_remove(bat_priv, tt_addr, 1006 local_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid,
928 "global tt received", 1007 "global tt received",
929 flags & BATADV_TT_CLIENT_ROAM); 1008 flags & BATADV_TT_CLIENT_ROAM);
930 tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI; 1009 tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI;
@@ -1147,17 +1226,25 @@ batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,
1147 orig_node, message); 1226 orig_node, message);
1148} 1227}
1149 1228
1150 1229/**
1151 1230 * batadv_tt_global_del - remove a client from the global table
1231 * @bat_priv: the bat priv with all the soft interface information
1232 * @orig_node: an originator serving this client
1233 * @addr: the mac address of the client
1234 * @vid: VLAN identifier
1235 * @message: a message explaining the reason for deleting the client to print
1236 * for debugging purpose
1237 * @roaming: true if the deletion has been triggered by a roaming event
1238 */
1152static void batadv_tt_global_del(struct batadv_priv *bat_priv, 1239static void batadv_tt_global_del(struct batadv_priv *bat_priv,
1153 struct batadv_orig_node *orig_node, 1240 struct batadv_orig_node *orig_node,
1154 const unsigned char *addr, 1241 const unsigned char *addr, unsigned short vid,
1155 const char *message, bool roaming) 1242 const char *message, bool roaming)
1156{ 1243{
1157 struct batadv_tt_global_entry *tt_global_entry; 1244 struct batadv_tt_global_entry *tt_global_entry;
1158 struct batadv_tt_local_entry *local_entry = NULL; 1245 struct batadv_tt_local_entry *local_entry = NULL;
1159 1246
1160 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr); 1247 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
1161 if (!tt_global_entry) 1248 if (!tt_global_entry)
1162 goto out; 1249 goto out;
1163 1250
@@ -1186,7 +1273,8 @@ static void batadv_tt_global_del(struct batadv_priv *bat_priv,
1186 * the global entry, since it is useless now. 1273 * the global entry, since it is useless now.
1187 */ 1274 */
1188 local_entry = batadv_tt_local_hash_find(bat_priv, 1275 local_entry = batadv_tt_local_hash_find(bat_priv,
1189 tt_global_entry->common.addr); 1276 tt_global_entry->common.addr,
1277 vid);
1190 if (local_entry) { 1278 if (local_entry) {
1191 /* local entry exists, case 2: client roamed to us. */ 1279 /* local entry exists, case 2: client roamed to us. */
1192 batadv_tt_global_del_orig_list(tt_global_entry); 1280 batadv_tt_global_del_orig_list(tt_global_entry);
@@ -1354,9 +1442,24 @@ _batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry,
1354 return ret; 1442 return ret;
1355} 1443}
1356 1444
1445/**
1446 * batadv_transtable_search - get the mesh destination for a given client
1447 * @bat_priv: the bat priv with all the soft interface information
1448 * @src: mac address of the source client
1449 * @addr: mac address of the destination client
1450 * @vid: VLAN identifier
1451 *
1452 * Returns a pointer to the originator that was selected as destination in the
1453 * mesh for contacting the client 'addr', NULL otherwise.
1454 * In case of multiple originators serving the same client, the function returns
1455 * the best one (best in terms of metric towards the destination node).
1456 *
1457 * If the two clients are AP isolated the function returns NULL.
1458 */
1357struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv, 1459struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
1358 const uint8_t *src, 1460 const uint8_t *src,
1359 const uint8_t *addr) 1461 const uint8_t *addr,
1462 unsigned short vid)
1360{ 1463{
1361 struct batadv_tt_local_entry *tt_local_entry = NULL; 1464 struct batadv_tt_local_entry *tt_local_entry = NULL;
1362 struct batadv_tt_global_entry *tt_global_entry = NULL; 1465 struct batadv_tt_global_entry *tt_global_entry = NULL;
@@ -1364,13 +1467,13 @@ struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
1364 struct batadv_tt_orig_list_entry *best_entry; 1467 struct batadv_tt_orig_list_entry *best_entry;
1365 1468
1366 if (src && atomic_read(&bat_priv->ap_isolation)) { 1469 if (src && atomic_read(&bat_priv->ap_isolation)) {
1367 tt_local_entry = batadv_tt_local_hash_find(bat_priv, src); 1470 tt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid);
1368 if (!tt_local_entry || 1471 if (!tt_local_entry ||
1369 (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)) 1472 (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING))
1370 goto out; 1473 goto out;
1371 } 1474 }
1372 1475
1373 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr); 1476 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
1374 if (!tt_global_entry) 1477 if (!tt_global_entry)
1375 goto out; 1478 goto out;
1376 1479
@@ -1649,6 +1752,7 @@ batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
1649 memcpy(tt_change->addr, tt_common_entry->addr, 1752 memcpy(tt_change->addr, tt_common_entry->addr,
1650 ETH_ALEN); 1753 ETH_ALEN);
1651 tt_change->flags = tt_common_entry->flags; 1754 tt_change->flags = tt_common_entry->flags;
1755 tt_change->vid = htons(tt_common_entry->vid);
1652 tt_change->reserved = 0; 1756 tt_change->reserved = 0;
1653 1757
1654 tt_num_entries++; 1758 tt_num_entries++;
@@ -1979,11 +2083,13 @@ static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
1979 roams = (tt_change + i)->flags & BATADV_TT_CLIENT_ROAM; 2083 roams = (tt_change + i)->flags & BATADV_TT_CLIENT_ROAM;
1980 batadv_tt_global_del(bat_priv, orig_node, 2084 batadv_tt_global_del(bat_priv, orig_node,
1981 (tt_change + i)->addr, 2085 (tt_change + i)->addr,
2086 ntohs((tt_change + i)->vid),
1982 "tt removed by changes", 2087 "tt removed by changes",
1983 roams); 2088 roams);
1984 } else { 2089 } else {
1985 if (!batadv_tt_global_add(bat_priv, orig_node, 2090 if (!batadv_tt_global_add(bat_priv, orig_node,
1986 (tt_change + i)->addr, 2091 (tt_change + i)->addr,
2092 ntohs((tt_change + i)->vid),
1987 (tt_change + i)->flags, ttvn)) 2093 (tt_change + i)->flags, ttvn))
1988 /* In case of problem while storing a 2094 /* In case of problem while storing a
1989 * global_entry, we stop the updating 2095 * global_entry, we stop the updating
@@ -2040,12 +2146,21 @@ static void batadv_tt_update_changes(struct batadv_priv *bat_priv,
2040 atomic_set(&orig_node->last_ttvn, ttvn); 2146 atomic_set(&orig_node->last_ttvn, ttvn);
2041} 2147}
2042 2148
2043bool batadv_is_my_client(struct batadv_priv *bat_priv, const uint8_t *addr) 2149/**
2150 * batadv_is_my_client - check if a client is served by the local node
2151 * @bat_priv: the bat priv with all the soft interface information
2152 * @addr: the mac adress of the client to check
2153 * @vid: VLAN identifier
2154 *
2155 * Returns true if the client is served by this node, false otherwise.
2156 */
2157bool batadv_is_my_client(struct batadv_priv *bat_priv, const uint8_t *addr,
2158 unsigned short vid)
2044{ 2159{
2045 struct batadv_tt_local_entry *tt_local_entry; 2160 struct batadv_tt_local_entry *tt_local_entry;
2046 bool ret = false; 2161 bool ret = false;
2047 2162
2048 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr); 2163 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
2049 if (!tt_local_entry) 2164 if (!tt_local_entry)
2050 goto out; 2165 goto out;
2051 /* Check if the client has been logically deleted (but is kept for 2166 /* Check if the client has been logically deleted (but is kept for
@@ -2194,7 +2309,20 @@ unlock:
2194 return ret; 2309 return ret;
2195} 2310}
2196 2311
2312/**
2313 * batadv_send_roam_adv - send a roaming advertisement message
2314 * @bat_priv: the bat priv with all the soft interface information
2315 * @client: mac address of the roaming client
2316 * @vid: VLAN identifier
2317 * @orig_node: message destination
2318 *
2319 * Send a ROAMING_ADV message to the node which was previously serving this
2320 * client. This is done to inform the node that from now on all traffic destined
2321 * for this particular roamed client has to be forwarded to the sender of the
2322 * roaming message.
2323 */
2197static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, 2324static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client,
2325 unsigned short vid,
2198 struct batadv_orig_node *orig_node) 2326 struct batadv_orig_node *orig_node)
2199{ 2327{
2200 struct batadv_hard_iface *primary_if; 2328 struct batadv_hard_iface *primary_if;
@@ -2217,7 +2345,7 @@ static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client,
2217 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX); 2345 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX);
2218 2346
2219 memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client)); 2347 memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client));
2220 tvlv_roam.reserved = 0; 2348 tvlv_roam.vid = htons(vid);
2221 2349
2222 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr, 2350 batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
2223 orig_node->orig, BATADV_TVLV_ROAM, 1, 2351 orig_node->orig, BATADV_TVLV_ROAM, 1,
@@ -2383,11 +2511,13 @@ bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, uint8_t *src,
2383 if (!atomic_read(&bat_priv->ap_isolation)) 2511 if (!atomic_read(&bat_priv->ap_isolation))
2384 goto out; 2512 goto out;
2385 2513
2386 tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst); 2514 tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst,
2515 BATADV_NO_FLAGS);
2387 if (!tt_local_entry) 2516 if (!tt_local_entry)
2388 goto out; 2517 goto out;
2389 2518
2390 tt_global_entry = batadv_tt_global_hash_find(bat_priv, src); 2519 tt_global_entry = batadv_tt_global_hash_find(bat_priv, src,
2520 BATADV_NO_FLAGS);
2391 if (!tt_global_entry) 2521 if (!tt_global_entry)
2392 goto out; 2522 goto out;
2393 2523
@@ -2482,17 +2612,23 @@ request_table:
2482 } 2612 }
2483} 2613}
2484 2614
2485/* returns true whether we know that the client has moved from its old 2615/**
2486 * originator to another one. This entry is kept is still kept for consistency 2616 * batadv_tt_global_client_is_roaming - check if a client is marked as roaming
2487 * purposes 2617 * @bat_priv: the bat priv with all the soft interface information
2618 * @addr: the mac address of the client to check
2619 * @vid: VLAN identifier
2620 *
2621 * Returns true if we know that the client has moved from its old originator
2622 * to another one. This entry is still kept for consistency purposes and will be
2623 * deleted later by a DEL or because of timeout
2488 */ 2624 */
2489bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv, 2625bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,
2490 uint8_t *addr) 2626 uint8_t *addr, unsigned short vid)
2491{ 2627{
2492 struct batadv_tt_global_entry *tt_global_entry; 2628 struct batadv_tt_global_entry *tt_global_entry;
2493 bool ret = false; 2629 bool ret = false;
2494 2630
2495 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr); 2631 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid);
2496 if (!tt_global_entry) 2632 if (!tt_global_entry)
2497 goto out; 2633 goto out;
2498 2634
@@ -2505,19 +2641,20 @@ out:
2505/** 2641/**
2506 * batadv_tt_local_client_is_roaming - tells whether the client is roaming 2642 * batadv_tt_local_client_is_roaming - tells whether the client is roaming
2507 * @bat_priv: the bat priv with all the soft interface information 2643 * @bat_priv: the bat priv with all the soft interface information
2508 * @addr: the MAC address of the local client to query 2644 * @addr: the mac address of the local client to query
2645 * @vid: VLAN identifier
2509 * 2646 *
2510 * Returns true if the local client is known to be roaming (it is not served by 2647 * Returns true if the local client is known to be roaming (it is not served by
2511 * this node anymore) or not. If yes, the client is still present in the table 2648 * this node anymore) or not. If yes, the client is still present in the table
2512 * to keep the latter consistent with the node TTVN 2649 * to keep the latter consistent with the node TTVN
2513 */ 2650 */
2514bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv, 2651bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv,
2515 uint8_t *addr) 2652 uint8_t *addr, unsigned short vid)
2516{ 2653{
2517 struct batadv_tt_local_entry *tt_local_entry; 2654 struct batadv_tt_local_entry *tt_local_entry;
2518 bool ret = false; 2655 bool ret = false;
2519 2656
2520 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr); 2657 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid);
2521 if (!tt_local_entry) 2658 if (!tt_local_entry)
2522 goto out; 2659 goto out;
2523 2660
@@ -2529,7 +2666,8 @@ out:
2529 2666
2530bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv, 2667bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
2531 struct batadv_orig_node *orig_node, 2668 struct batadv_orig_node *orig_node,
2532 const unsigned char *addr) 2669 const unsigned char *addr,
2670 unsigned short vlan)
2533{ 2671{
2534 bool ret = false; 2672 bool ret = false;
2535 2673
@@ -2540,7 +2678,7 @@ bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
2540 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig)) 2678 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig))
2541 goto out; 2679 goto out;
2542 2680
2543 if (!batadv_tt_global_add(bat_priv, orig_node, addr, 2681 if (!batadv_tt_global_add(bat_priv, orig_node, addr, vlan,
2544 BATADV_TT_CLIENT_TEMP, 2682 BATADV_TT_CLIENT_TEMP,
2545 atomic_read(&orig_node->last_ttvn))) 2683 atomic_read(&orig_node->last_ttvn)))
2546 goto out; 2684 goto out;
@@ -2706,7 +2844,7 @@ static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,
2706 src, roaming_adv->client); 2844 src, roaming_adv->client);
2707 2845
2708 batadv_tt_global_add(bat_priv, orig_node, roaming_adv->client, 2846 batadv_tt_global_add(bat_priv, orig_node, roaming_adv->client,
2709 BATADV_TT_CLIENT_ROAM, 2847 ntohs(roaming_adv->vid), BATADV_TT_CLIENT_ROAM,
2710 atomic_read(&orig_node->last_ttvn) + 1); 2848 atomic_read(&orig_node->last_ttvn) + 1);
2711 2849
2712out: 2850out: