Antonio Quartulli | 0b87393 | 2013-01-04 03:05:31 +0100 | [diff] [blame] | 1 | /* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 2 | * |
Antonio Quartulli | 35c133a | 2012-03-14 13:03:01 +0100 | [diff] [blame] | 3 | * Marek Lindner, Simon Wunderlich, Antonio Quartulli |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of version 2 of the GNU General Public |
| 7 | * License as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 | * 02110-1301, USA |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "main.h" |
| 21 | #include "translation-table.h" |
| 22 | #include "soft-interface.h" |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 23 | #include "hard-interface.h" |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 24 | #include "send.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 25 | #include "hash.h" |
| 26 | #include "originator.h" |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 27 | #include "routing.h" |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 28 | #include "bridge_loop_avoidance.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 29 | |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 30 | #include <linux/crc32c.h> |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 31 | |
Antonio Quartulli | dec0507 | 2012-11-10 11:00:32 +0100 | [diff] [blame] | 32 | /* hash class keys */ |
| 33 | static struct lock_class_key batadv_tt_local_hash_lock_class_key; |
| 34 | static struct lock_class_key batadv_tt_global_hash_lock_class_key; |
| 35 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 36 | static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 37 | unsigned short vid, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 38 | struct batadv_orig_node *orig_node); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 39 | static void batadv_tt_purge(struct work_struct *work); |
| 40 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 41 | batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry); |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 42 | static void batadv_tt_global_del(struct batadv_priv *bat_priv, |
| 43 | struct batadv_orig_node *orig_node, |
| 44 | const unsigned char *addr, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 45 | unsigned short vid, const char *message, |
| 46 | bool roaming); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 47 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 48 | /* returns 1 if they are the same mac addr */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 49 | static int batadv_compare_tt(const struct hlist_node *node, const void *data2) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 50 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 51 | const void *data1 = container_of(node, struct batadv_tt_common_entry, |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 52 | hash_entry); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 53 | |
| 54 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
| 55 | } |
| 56 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 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 | */ |
| 65 | static 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 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 90 | static struct batadv_tt_common_entry * |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 91 | batadv_tt_hash_find(struct batadv_hashtable *hash, const uint8_t *addr, |
| 92 | unsigned short vid) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 93 | { |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 94 | struct hlist_head *head; |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 95 | struct batadv_tt_common_entry to_search, *tt, *tt_tmp = NULL; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 96 | uint32_t index; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 97 | |
| 98 | if (!hash) |
| 99 | return NULL; |
| 100 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 101 | memcpy(to_search.addr, addr, ETH_ALEN); |
| 102 | to_search.vid = vid; |
| 103 | |
| 104 | index = batadv_choose_tt(&to_search, hash->size); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 105 | head = &hash->table[index]; |
| 106 | |
| 107 | rcu_read_lock(); |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 108 | hlist_for_each_entry_rcu(tt, head, hash_entry) { |
| 109 | if (!batadv_compare_eth(tt, addr)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 110 | continue; |
| 111 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 112 | if (tt->vid != vid) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 113 | continue; |
| 114 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 115 | if (!atomic_inc_not_zero(&tt->refcount)) |
| 116 | continue; |
| 117 | |
| 118 | tt_tmp = tt; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 119 | break; |
| 120 | } |
| 121 | rcu_read_unlock(); |
| 122 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 123 | return tt_tmp; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 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 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 135 | static struct batadv_tt_local_entry * |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 136 | batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const uint8_t *addr, |
| 137 | unsigned short vid) |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 138 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 139 | struct batadv_tt_common_entry *tt_common_entry; |
| 140 | struct batadv_tt_local_entry *tt_local_entry = NULL; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 141 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 142 | tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, addr, |
| 143 | vid); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 144 | if (tt_common_entry) |
| 145 | tt_local_entry = container_of(tt_common_entry, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 146 | struct batadv_tt_local_entry, |
| 147 | common); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 148 | return tt_local_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 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 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 160 | static struct batadv_tt_global_entry * |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 161 | batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const uint8_t *addr, |
| 162 | unsigned short vid) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 163 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 164 | struct batadv_tt_common_entry *tt_common_entry; |
| 165 | struct batadv_tt_global_entry *tt_global_entry = NULL; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 166 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 167 | tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, addr, |
| 168 | vid); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 169 | if (tt_common_entry) |
| 170 | tt_global_entry = container_of(tt_common_entry, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 171 | struct batadv_tt_global_entry, |
| 172 | common); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 173 | return tt_global_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 176 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 177 | batadv_tt_local_entry_free_ref(struct batadv_tt_local_entry *tt_local_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 178 | { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 179 | if (atomic_dec_and_test(&tt_local_entry->common.refcount)) |
| 180 | kfree_rcu(tt_local_entry, common.rcu); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Antonio Quartulli | 2102605 | 2013-05-07 00:29:22 +0200 | [diff] [blame] | 183 | /** |
| 184 | * batadv_tt_global_entry_free_ref - decrement the refcounter for a |
| 185 | * tt_global_entry and possibly free it |
| 186 | * @tt_global_entry: the object to free |
| 187 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 188 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 189 | batadv_tt_global_entry_free_ref(struct batadv_tt_global_entry *tt_global_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 190 | { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 191 | if (atomic_dec_and_test(&tt_global_entry->common.refcount)) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 192 | batadv_tt_global_del_orig_list(tt_global_entry); |
Antonio Quartulli | 2102605 | 2013-05-07 00:29:22 +0200 | [diff] [blame] | 193 | kfree_rcu(tt_global_entry, common.rcu); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 197 | static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 198 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 199 | struct batadv_tt_orig_list_entry *orig_entry; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 200 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 201 | orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu); |
Linus Lüssing | 7282222 | 2013-04-15 21:43:29 +0800 | [diff] [blame] | 202 | |
| 203 | /* We are in an rcu callback here, therefore we cannot use |
| 204 | * batadv_orig_node_free_ref() and its call_rcu(): |
| 205 | * An rcu_barrier() wouldn't wait for that to finish |
| 206 | */ |
| 207 | batadv_orig_node_free_ref_now(orig_entry->orig_node); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 208 | kfree(orig_entry); |
| 209 | } |
| 210 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 211 | /** |
| 212 | * batadv_tt_local_size_mod - change the size by v of the local table identified |
| 213 | * by vid |
| 214 | * @bat_priv: the bat priv with all the soft interface information |
| 215 | * @vid: the VLAN identifier of the sub-table to change |
| 216 | * @v: the amount to sum to the local table size |
| 217 | */ |
| 218 | static void batadv_tt_local_size_mod(struct batadv_priv *bat_priv, |
| 219 | unsigned short vid, int v) |
| 220 | { |
| 221 | struct batadv_softif_vlan *vlan; |
| 222 | |
| 223 | vlan = batadv_softif_vlan_get(bat_priv, vid); |
| 224 | if (!vlan) |
| 225 | return; |
| 226 | |
| 227 | atomic_add(v, &vlan->tt.num_entries); |
| 228 | |
| 229 | batadv_softif_vlan_free_ref(vlan); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * batadv_tt_local_size_inc - increase by one the local table size for the given |
| 234 | * vid |
| 235 | * @bat_priv: the bat priv with all the soft interface information |
| 236 | * @vid: the VLAN identifier |
| 237 | */ |
| 238 | static void batadv_tt_local_size_inc(struct batadv_priv *bat_priv, |
| 239 | unsigned short vid) |
| 240 | { |
| 241 | batadv_tt_local_size_mod(bat_priv, vid, 1); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * batadv_tt_local_size_dec - decrease by one the local table size for the given |
| 246 | * vid |
| 247 | * @bat_priv: the bat priv with all the soft interface information |
| 248 | * @vid: the VLAN identifier |
| 249 | */ |
| 250 | static void batadv_tt_local_size_dec(struct batadv_priv *bat_priv, |
| 251 | unsigned short vid) |
| 252 | { |
| 253 | batadv_tt_local_size_mod(bat_priv, vid, -1); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * batadv_tt_global_size_mod - change the size by v of the local table |
| 258 | * identified by vid |
| 259 | * @bat_priv: the bat priv with all the soft interface information |
| 260 | * @vid: the VLAN identifier |
| 261 | * @v: the amount to sum to the global table size |
| 262 | */ |
| 263 | static void batadv_tt_global_size_mod(struct batadv_orig_node *orig_node, |
| 264 | unsigned short vid, int v) |
| 265 | { |
| 266 | struct batadv_orig_node_vlan *vlan; |
| 267 | |
| 268 | vlan = batadv_orig_node_vlan_new(orig_node, vid); |
| 269 | if (!vlan) |
| 270 | return; |
| 271 | |
| 272 | if (atomic_add_return(v, &vlan->tt.num_entries) == 0) { |
| 273 | spin_lock_bh(&orig_node->vlan_list_lock); |
| 274 | list_del_rcu(&vlan->list); |
| 275 | spin_unlock_bh(&orig_node->vlan_list_lock); |
| 276 | batadv_orig_node_vlan_free_ref(vlan); |
| 277 | } |
| 278 | |
| 279 | batadv_orig_node_vlan_free_ref(vlan); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * batadv_tt_global_size_inc - increase by one the global table size for the |
| 284 | * given vid |
| 285 | * @orig_node: the originator which global table size has to be decreased |
| 286 | * @vid: the vlan identifier |
| 287 | */ |
| 288 | static void batadv_tt_global_size_inc(struct batadv_orig_node *orig_node, |
| 289 | unsigned short vid) |
| 290 | { |
| 291 | batadv_tt_global_size_mod(orig_node, vid, 1); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * batadv_tt_global_size_dec - decrease by one the global table size for the |
| 296 | * given vid |
| 297 | * @orig_node: the originator which global table size has to be decreased |
| 298 | * @vid: the vlan identifier |
| 299 | */ |
| 300 | static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node, |
| 301 | unsigned short vid) |
| 302 | { |
| 303 | batadv_tt_global_size_mod(orig_node, vid, -1); |
| 304 | } |
| 305 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 306 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 307 | batadv_tt_orig_list_entry_free_ref(struct batadv_tt_orig_list_entry *orig_entry) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 308 | { |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 309 | if (!atomic_dec_and_test(&orig_entry->refcount)) |
| 310 | return; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 311 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 312 | call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Antonio Quartulli | 3abe4ad | 2013-04-03 11:15:33 +0200 | [diff] [blame] | 315 | /** |
| 316 | * batadv_tt_local_event - store a local TT event (ADD/DEL) |
| 317 | * @bat_priv: the bat priv with all the soft interface information |
| 318 | * @tt_local_entry: the TT entry involved in the event |
| 319 | * @event_flags: flags to store in the event structure |
| 320 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 321 | static void batadv_tt_local_event(struct batadv_priv *bat_priv, |
Antonio Quartulli | 3abe4ad | 2013-04-03 11:15:33 +0200 | [diff] [blame] | 322 | struct batadv_tt_local_entry *tt_local_entry, |
| 323 | uint8_t event_flags) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 324 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 325 | struct batadv_tt_change_node *tt_change_node, *entry, *safe; |
Antonio Quartulli | 3abe4ad | 2013-04-03 11:15:33 +0200 | [diff] [blame] | 326 | struct batadv_tt_common_entry *common = &tt_local_entry->common; |
| 327 | uint8_t flags = common->flags | event_flags; |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 328 | bool event_removed = false; |
| 329 | bool del_op_requested, del_op_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 330 | |
| 331 | tt_change_node = kmalloc(sizeof(*tt_change_node), GFP_ATOMIC); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 332 | if (!tt_change_node) |
| 333 | return; |
| 334 | |
Antonio Quartulli | ff66c97 | 2011-06-30 01:14:00 +0200 | [diff] [blame] | 335 | tt_change_node->change.flags = flags; |
Antonio Quartulli | ca66304 | 2013-12-15 13:26:55 +0100 | [diff] [blame] | 336 | memset(tt_change_node->change.reserved, 0, |
| 337 | sizeof(tt_change_node->change.reserved)); |
Antonio Quartulli | 3abe4ad | 2013-04-03 11:15:33 +0200 | [diff] [blame] | 338 | memcpy(tt_change_node->change.addr, common->addr, ETH_ALEN); |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 339 | tt_change_node->change.vid = htons(common->vid); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 340 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 341 | del_op_requested = flags & BATADV_TT_CLIENT_DEL; |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 342 | |
| 343 | /* check for ADD+DEL or DEL+ADD events */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 344 | spin_lock_bh(&bat_priv->tt.changes_list_lock); |
| 345 | list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 346 | list) { |
Antonio Quartulli | 3abe4ad | 2013-04-03 11:15:33 +0200 | [diff] [blame] | 347 | if (!batadv_compare_eth(entry->change.addr, common->addr)) |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 348 | continue; |
| 349 | |
| 350 | /* DEL+ADD in the same orig interval have no effect and can be |
| 351 | * removed to avoid silly behaviour on the receiver side. The |
| 352 | * other way around (ADD+DEL) can happen in case of roaming of |
| 353 | * a client still in the NEW state. Roaming of NEW clients is |
| 354 | * now possible due to automatically recognition of "temporary" |
| 355 | * clients |
| 356 | */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 357 | del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL; |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 358 | if (!del_op_requested && del_op_entry) |
| 359 | goto del; |
| 360 | if (del_op_requested && !del_op_entry) |
| 361 | goto del; |
Antonio Quartulli | 3c4f7ab | 2013-10-13 02:50:19 +0200 | [diff] [blame] | 362 | |
| 363 | /* this is a second add in the same originator interval. It |
| 364 | * means that flags have been changed: update them! |
| 365 | */ |
| 366 | if (!del_op_requested && !del_op_entry) |
| 367 | entry->change.flags = flags; |
| 368 | |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 369 | continue; |
| 370 | del: |
| 371 | list_del(&entry->list); |
| 372 | kfree(entry); |
Jesper Juhl | 155e4e1 | 2012-08-07 08:32:34 +0000 | [diff] [blame] | 373 | kfree(tt_change_node); |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 374 | event_removed = true; |
| 375 | goto unlock; |
| 376 | } |
| 377 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 378 | /* track the change in the OGMinterval list */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 379 | list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list); |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 380 | |
| 381 | unlock: |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 382 | spin_unlock_bh(&bat_priv->tt.changes_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 383 | |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 384 | if (event_removed) |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 385 | atomic_dec(&bat_priv->tt.local_changes); |
Antonio Quartulli | 3b643de | 2012-05-25 00:00:42 +0200 | [diff] [blame] | 386 | else |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 387 | atomic_inc(&bat_priv->tt.local_changes); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 388 | } |
| 389 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 390 | /** |
| 391 | * batadv_tt_len - compute length in bytes of given number of tt changes |
| 392 | * @changes_num: number of tt changes |
| 393 | * |
| 394 | * Returns computed length in bytes. |
| 395 | */ |
| 396 | static int batadv_tt_len(int changes_num) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 397 | { |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 398 | return changes_num * sizeof(struct batadv_tvlv_tt_change); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Antonio Quartulli | 298e6e6 | 2013-05-28 13:14:27 +0200 | [diff] [blame] | 401 | /** |
| 402 | * batadv_tt_entries - compute the number of entries fitting in tt_len bytes |
| 403 | * @tt_len: available space |
| 404 | * |
| 405 | * Returns the number of entries. |
| 406 | */ |
| 407 | static uint16_t batadv_tt_entries(uint16_t tt_len) |
| 408 | { |
| 409 | return tt_len / batadv_tt_len(1); |
| 410 | } |
| 411 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 412 | /** |
| 413 | * batadv_tt_local_table_transmit_size - calculates the local translation table |
| 414 | * size when transmitted over the air |
| 415 | * @bat_priv: the bat priv with all the soft interface information |
| 416 | * |
| 417 | * Returns local translation table size in bytes. |
| 418 | */ |
| 419 | static int batadv_tt_local_table_transmit_size(struct batadv_priv *bat_priv) |
| 420 | { |
| 421 | uint16_t num_vlan = 0, tt_local_entries = 0; |
| 422 | struct batadv_softif_vlan *vlan; |
| 423 | int hdr_size; |
| 424 | |
| 425 | rcu_read_lock(); |
| 426 | hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) { |
| 427 | num_vlan++; |
| 428 | tt_local_entries += atomic_read(&vlan->tt.num_entries); |
| 429 | } |
| 430 | rcu_read_unlock(); |
| 431 | |
| 432 | /* header size of tvlv encapsulated tt response payload */ |
| 433 | hdr_size = sizeof(struct batadv_unicast_tvlv_packet); |
| 434 | hdr_size += sizeof(struct batadv_tvlv_hdr); |
| 435 | hdr_size += sizeof(struct batadv_tvlv_tt_data); |
| 436 | hdr_size += num_vlan * sizeof(struct batadv_tvlv_tt_vlan_data); |
| 437 | |
| 438 | return hdr_size + batadv_tt_len(tt_local_entries); |
| 439 | } |
| 440 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 441 | static int batadv_tt_local_init(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 442 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 443 | if (bat_priv->tt.local_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 444 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 445 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 446 | bat_priv->tt.local_hash = batadv_hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 447 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 448 | if (!bat_priv->tt.local_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 449 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 450 | |
Antonio Quartulli | dec0507 | 2012-11-10 11:00:32 +0100 | [diff] [blame] | 451 | batadv_hash_set_lock_class(bat_priv->tt.local_hash, |
| 452 | &batadv_tt_local_hash_lock_class_key); |
| 453 | |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 454 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 457 | static void batadv_tt_global_free(struct batadv_priv *bat_priv, |
| 458 | struct batadv_tt_global_entry *tt_global, |
| 459 | const char *message) |
| 460 | { |
| 461 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 462 | "Deleting global tt entry %pM (vid: %d): %s\n", |
| 463 | tt_global->common.addr, |
| 464 | BATADV_PRINT_VID(tt_global->common.vid), message); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 465 | |
| 466 | batadv_hash_remove(bat_priv->tt.global_hash, batadv_compare_tt, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 467 | batadv_choose_tt, &tt_global->common); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 468 | batadv_tt_global_entry_free_ref(tt_global); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 471 | /** |
| 472 | * batadv_tt_local_add - add a new client to the local table or update an |
| 473 | * existing client |
| 474 | * @soft_iface: netdev struct of the mesh interface |
| 475 | * @addr: the mac address of the client to add |
| 476 | * @vid: VLAN identifier |
| 477 | * @ifindex: index of the interface where the client is connected to (useful to |
| 478 | * identify wireless clients) |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 479 | * |
| 480 | * Returns true if the client was successfully added, false otherwise. |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 481 | */ |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 482 | bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 483 | unsigned short vid, int ifindex) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 484 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 485 | struct batadv_priv *bat_priv = netdev_priv(soft_iface); |
Sven Eckelmann | 170173b | 2012-10-07 12:02:22 +0200 | [diff] [blame] | 486 | struct batadv_tt_local_entry *tt_local; |
| 487 | struct batadv_tt_global_entry *tt_global; |
Antonio Quartulli | 0c69aec | 2013-10-13 02:50:18 +0200 | [diff] [blame] | 488 | struct net_device *in_dev = NULL; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 489 | struct hlist_head *head; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 490 | struct batadv_tt_orig_list_entry *orig_entry; |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 491 | int hash_added, table_size, packet_size_max; |
| 492 | bool ret = false, roamed_back = false; |
Antonio Quartulli | 3c4f7ab | 2013-10-13 02:50:19 +0200 | [diff] [blame] | 493 | uint8_t remote_flags; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 494 | |
Antonio Quartulli | 0c69aec | 2013-10-13 02:50:18 +0200 | [diff] [blame] | 495 | if (ifindex != BATADV_NULL_IFINDEX) |
| 496 | in_dev = dev_get_by_index(&init_net, ifindex); |
| 497 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 498 | tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid); |
| 499 | tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 500 | |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 501 | if (tt_local) { |
| 502 | tt_local->last_seen = jiffies; |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 503 | if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) { |
| 504 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 505 | "Re-adding pending client %pM (vid: %d)\n", |
| 506 | addr, BATADV_PRINT_VID(vid)); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 507 | /* whatever the reason why the PENDING flag was set, |
| 508 | * this is a client which was enqueued to be removed in |
| 509 | * this orig_interval. Since it popped up again, the |
| 510 | * flag can be reset like it was never enqueued |
| 511 | */ |
| 512 | tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING; |
| 513 | goto add_event; |
| 514 | } |
| 515 | |
| 516 | if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) { |
| 517 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 518 | "Roaming client %pM (vid: %d) came back to its original location\n", |
| 519 | addr, BATADV_PRINT_VID(vid)); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 520 | /* the ROAM flag is set because this client roamed away |
| 521 | * and the node got a roaming_advertisement message. Now |
| 522 | * that the client popped up again at its original |
| 523 | * location such flag can be unset |
| 524 | */ |
| 525 | tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM; |
| 526 | roamed_back = true; |
| 527 | } |
| 528 | goto check_roaming; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 531 | /* Ignore the client if we cannot send it in a full table response. */ |
| 532 | table_size = batadv_tt_local_table_transmit_size(bat_priv); |
| 533 | table_size += batadv_tt_len(1); |
| 534 | packet_size_max = atomic_read(&bat_priv->packet_size_max); |
| 535 | if (table_size > packet_size_max) { |
| 536 | net_ratelimited_function(batadv_info, soft_iface, |
| 537 | "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n", |
| 538 | table_size, packet_size_max, addr); |
| 539 | goto out; |
| 540 | } |
| 541 | |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 542 | tt_local = kmalloc(sizeof(*tt_local), GFP_ATOMIC); |
| 543 | if (!tt_local) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 544 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 545 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 546 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 547 | "Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n", |
| 548 | addr, BATADV_PRINT_VID(vid), |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 549 | (uint8_t)atomic_read(&bat_priv->tt.vn)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 550 | |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 551 | memcpy(tt_local->common.addr, addr, ETH_ALEN); |
Antonio Quartulli | 8425ec6 | 2012-11-19 09:01:44 +0100 | [diff] [blame] | 552 | /* The local entry has to be marked as NEW to avoid to send it in |
| 553 | * a full table response going out before the next ttvn increment |
| 554 | * (consistency check) |
| 555 | */ |
| 556 | tt_local->common.flags = BATADV_TT_CLIENT_NEW; |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 557 | tt_local->common.vid = vid; |
Antonio Quartulli | 0c69aec | 2013-10-13 02:50:18 +0200 | [diff] [blame] | 558 | if (batadv_is_wifi_netdev(in_dev)) |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 559 | tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; |
| 560 | atomic_set(&tt_local->common.refcount, 2); |
| 561 | tt_local->last_seen = jiffies; |
| 562 | tt_local->common.added_at = tt_local->last_seen; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 563 | |
| 564 | /* the batman interface mac address should never be purged */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 565 | if (batadv_compare_eth(addr, soft_iface->dev_addr)) |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 566 | tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 567 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 568 | hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 569 | batadv_choose_tt, &tt_local->common, |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 570 | &tt_local->common.hash_entry); |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 571 | |
| 572 | if (unlikely(hash_added != 0)) { |
| 573 | /* remove the reference for the hash */ |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 574 | batadv_tt_local_entry_free_ref(tt_local); |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 575 | goto out; |
| 576 | } |
| 577 | |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 578 | add_event: |
Antonio Quartulli | 3abe4ad | 2013-04-03 11:15:33 +0200 | [diff] [blame] | 579 | batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); |
Antonio Quartulli | ff66c97 | 2011-06-30 01:14:00 +0200 | [diff] [blame] | 580 | |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 581 | check_roaming: |
| 582 | /* Check whether it is a roaming, but don't do anything if the roaming |
| 583 | * process has already been handled |
| 584 | */ |
| 585 | if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 586 | /* These node are probably going to update their tt table */ |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 587 | head = &tt_global->orig_list; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 588 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 589 | hlist_for_each_entry_rcu(orig_entry, head, list) { |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 590 | batadv_send_roam_adv(bat_priv, tt_global->common.addr, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 591 | tt_global->common.vid, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 592 | orig_entry->orig_node); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 593 | } |
| 594 | rcu_read_unlock(); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 595 | if (roamed_back) { |
| 596 | batadv_tt_global_free(bat_priv, tt_global, |
| 597 | "Roaming canceled"); |
| 598 | tt_global = NULL; |
| 599 | } else { |
| 600 | /* The global entry has to be marked as ROAMING and |
| 601 | * has to be kept for consistency purpose |
| 602 | */ |
| 603 | tt_global->common.flags |= BATADV_TT_CLIENT_ROAM; |
| 604 | tt_global->roam_at = jiffies; |
| 605 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 606 | } |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 607 | |
Antonio Quartulli | 3c4f7ab | 2013-10-13 02:50:19 +0200 | [diff] [blame] | 608 | /* store the current remote flags before altering them. This helps |
| 609 | * understanding is flags are changing or not |
| 610 | */ |
| 611 | remote_flags = tt_local->common.flags & BATADV_TT_REMOTE_MASK; |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 612 | |
Antonio Quartulli | 3c4f7ab | 2013-10-13 02:50:19 +0200 | [diff] [blame] | 613 | if (batadv_is_wifi_netdev(in_dev)) |
| 614 | tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; |
| 615 | else |
| 616 | tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI; |
| 617 | |
| 618 | /* if any "dynamic" flag has been modified, resend an ADD event for this |
| 619 | * entry so that all the nodes can get the new flags |
| 620 | */ |
| 621 | if (remote_flags ^ (tt_local->common.flags & BATADV_TT_REMOTE_MASK)) |
| 622 | batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS); |
| 623 | |
| 624 | ret = true; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 625 | out: |
Antonio Quartulli | 0c69aec | 2013-10-13 02:50:18 +0200 | [diff] [blame] | 626 | if (in_dev) |
| 627 | dev_put(in_dev); |
Antonio Quartulli | 47c9465 | 2012-09-23 22:38:35 +0200 | [diff] [blame] | 628 | if (tt_local) |
| 629 | batadv_tt_local_entry_free_ref(tt_local); |
| 630 | if (tt_global) |
| 631 | batadv_tt_global_entry_free_ref(tt_global); |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 632 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 635 | /** |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 636 | * batadv_tt_prepare_tvlv_global_data - prepare the TVLV TT header to send |
| 637 | * within a TT Response directed to another node |
| 638 | * @orig_node: originator for which the TT data has to be prepared |
| 639 | * @tt_data: uninitialised pointer to the address of the TVLV buffer |
| 640 | * @tt_change: uninitialised pointer to the address of the area where the TT |
| 641 | * changed can be stored |
| 642 | * @tt_len: pointer to the length to reserve to the tt_change. if -1 this |
| 643 | * function reserves the amount of space needed to send the entire global TT |
| 644 | * table. In case of success the value is updated with the real amount of |
| 645 | * reserved bytes |
| 646 | |
| 647 | * Allocate the needed amount of memory for the entire TT TVLV and write its |
| 648 | * header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data |
| 649 | * objects, one per active VLAN served by the originator node. |
| 650 | * |
| 651 | * Return the size of the allocated buffer or 0 in case of failure. |
| 652 | */ |
| 653 | static uint16_t |
| 654 | batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node, |
| 655 | struct batadv_tvlv_tt_data **tt_data, |
| 656 | struct batadv_tvlv_tt_change **tt_change, |
| 657 | int32_t *tt_len) |
| 658 | { |
| 659 | uint16_t num_vlan = 0, num_entries = 0, change_offset, tvlv_len; |
| 660 | struct batadv_tvlv_tt_vlan_data *tt_vlan; |
| 661 | struct batadv_orig_node_vlan *vlan; |
| 662 | uint8_t *tt_change_ptr; |
| 663 | |
| 664 | rcu_read_lock(); |
| 665 | list_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) { |
| 666 | num_vlan++; |
| 667 | num_entries += atomic_read(&vlan->tt.num_entries); |
| 668 | } |
| 669 | |
| 670 | change_offset = sizeof(**tt_data); |
| 671 | change_offset += num_vlan * sizeof(*tt_vlan); |
| 672 | |
| 673 | /* if tt_len is negative, allocate the space needed by the full table */ |
| 674 | if (*tt_len < 0) |
| 675 | *tt_len = batadv_tt_len(num_entries); |
| 676 | |
| 677 | tvlv_len = *tt_len; |
| 678 | tvlv_len += change_offset; |
| 679 | |
| 680 | *tt_data = kmalloc(tvlv_len, GFP_ATOMIC); |
| 681 | if (!*tt_data) { |
| 682 | *tt_len = 0; |
| 683 | goto out; |
| 684 | } |
| 685 | |
| 686 | (*tt_data)->flags = BATADV_NO_FLAGS; |
| 687 | (*tt_data)->ttvn = atomic_read(&orig_node->last_ttvn); |
| 688 | (*tt_data)->num_vlan = htons(num_vlan); |
| 689 | |
| 690 | tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1); |
| 691 | list_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) { |
| 692 | tt_vlan->vid = htons(vlan->vid); |
| 693 | tt_vlan->crc = htonl(vlan->tt.crc); |
| 694 | |
| 695 | tt_vlan++; |
| 696 | } |
| 697 | |
| 698 | tt_change_ptr = (uint8_t *)*tt_data + change_offset; |
| 699 | *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; |
| 700 | |
| 701 | out: |
| 702 | rcu_read_unlock(); |
| 703 | return tvlv_len; |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * batadv_tt_prepare_tvlv_local_data - allocate and prepare the TT TVLV for this |
| 708 | * node |
| 709 | * @bat_priv: the bat priv with all the soft interface information |
| 710 | * @tt_data: uninitialised pointer to the address of the TVLV buffer |
| 711 | * @tt_change: uninitialised pointer to the address of the area where the TT |
| 712 | * changes can be stored |
| 713 | * @tt_len: pointer to the length to reserve to the tt_change. if -1 this |
| 714 | * function reserves the amount of space needed to send the entire local TT |
| 715 | * table. In case of success the value is updated with the real amount of |
| 716 | * reserved bytes |
| 717 | * |
| 718 | * Allocate the needed amount of memory for the entire TT TVLV and write its |
| 719 | * header made up by one tvlv_tt_data object and a series of tvlv_tt_vlan_data |
| 720 | * objects, one per active VLAN. |
| 721 | * |
| 722 | * Return the size of the allocated buffer or 0 in case of failure. |
| 723 | */ |
| 724 | static uint16_t |
| 725 | batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, |
| 726 | struct batadv_tvlv_tt_data **tt_data, |
| 727 | struct batadv_tvlv_tt_change **tt_change, |
| 728 | int32_t *tt_len) |
| 729 | { |
| 730 | struct batadv_tvlv_tt_vlan_data *tt_vlan; |
| 731 | struct batadv_softif_vlan *vlan; |
| 732 | uint16_t num_vlan = 0, num_entries = 0, tvlv_len; |
| 733 | uint8_t *tt_change_ptr; |
| 734 | int change_offset; |
| 735 | |
| 736 | rcu_read_lock(); |
| 737 | hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) { |
| 738 | num_vlan++; |
| 739 | num_entries += atomic_read(&vlan->tt.num_entries); |
| 740 | } |
| 741 | |
| 742 | change_offset = sizeof(**tt_data); |
| 743 | change_offset += num_vlan * sizeof(*tt_vlan); |
| 744 | |
| 745 | /* if tt_len is negative, allocate the space needed by the full table */ |
| 746 | if (*tt_len < 0) |
| 747 | *tt_len = batadv_tt_len(num_entries); |
| 748 | |
| 749 | tvlv_len = *tt_len; |
| 750 | tvlv_len += change_offset; |
| 751 | |
| 752 | *tt_data = kmalloc(tvlv_len, GFP_ATOMIC); |
| 753 | if (!*tt_data) { |
| 754 | tvlv_len = 0; |
| 755 | goto out; |
| 756 | } |
| 757 | |
| 758 | (*tt_data)->flags = BATADV_NO_FLAGS; |
| 759 | (*tt_data)->ttvn = atomic_read(&bat_priv->tt.vn); |
| 760 | (*tt_data)->num_vlan = htons(num_vlan); |
| 761 | |
| 762 | tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1); |
| 763 | hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) { |
| 764 | tt_vlan->vid = htons(vlan->vid); |
| 765 | tt_vlan->crc = htonl(vlan->tt.crc); |
| 766 | |
| 767 | tt_vlan++; |
| 768 | } |
| 769 | |
| 770 | tt_change_ptr = (uint8_t *)*tt_data + change_offset; |
| 771 | *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; |
| 772 | |
| 773 | out: |
| 774 | rcu_read_unlock(); |
| 775 | return tvlv_len; |
| 776 | } |
| 777 | |
| 778 | /** |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 779 | * batadv_tt_tvlv_container_update - update the translation table tvlv container |
| 780 | * after local tt changes have been committed |
| 781 | * @bat_priv: the bat priv with all the soft interface information |
| 782 | */ |
| 783 | static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 784 | { |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 785 | struct batadv_tt_change_node *entry, *safe; |
| 786 | struct batadv_tvlv_tt_data *tt_data; |
| 787 | struct batadv_tvlv_tt_change *tt_change; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 788 | int tt_diff_len, tt_change_len = 0; |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 789 | int tt_diff_entries_num = 0, tt_diff_entries_count = 0; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 790 | uint16_t tvlv_len; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 791 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 792 | tt_diff_entries_num = atomic_read(&bat_priv->tt.local_changes); |
| 793 | tt_diff_len = batadv_tt_len(tt_diff_entries_num); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 794 | |
| 795 | /* if we have too many changes for one packet don't send any |
| 796 | * and wait for the tt table request which will be fragmented |
| 797 | */ |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 798 | if (tt_diff_len > bat_priv->soft_iface->mtu) |
| 799 | tt_diff_len = 0; |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 800 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 801 | tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv, &tt_data, |
| 802 | &tt_change, &tt_diff_len); |
| 803 | if (!tvlv_len) |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 804 | return; |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 805 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 806 | tt_data->flags = BATADV_TT_OGM_DIFF; |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 807 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 808 | if (tt_diff_len == 0) |
| 809 | goto container_register; |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 810 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 811 | spin_lock_bh(&bat_priv->tt.changes_list_lock); |
| 812 | atomic_set(&bat_priv->tt.local_changes, 0); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 813 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 814 | list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 815 | list) { |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 816 | if (tt_diff_entries_count < tt_diff_entries_num) { |
| 817 | memcpy(tt_change + tt_diff_entries_count, |
| 818 | &entry->change, |
| 819 | sizeof(struct batadv_tvlv_tt_change)); |
| 820 | tt_diff_entries_count++; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 821 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 822 | list_del(&entry->list); |
| 823 | kfree(entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 824 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 825 | spin_unlock_bh(&bat_priv->tt.changes_list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 826 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 827 | /* Keep the buffer for possible tt_request */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 828 | spin_lock_bh(&bat_priv->tt.last_changeset_lock); |
| 829 | kfree(bat_priv->tt.last_changeset); |
| 830 | bat_priv->tt.last_changeset_len = 0; |
| 831 | bat_priv->tt.last_changeset = NULL; |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 832 | tt_change_len = batadv_tt_len(tt_diff_entries_count); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 833 | /* check whether this new OGM has no changes due to size problems */ |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 834 | if (tt_diff_entries_count > 0) { |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 835 | /* if kmalloc() fails we will reply with the full table |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 836 | * instead of providing the diff |
| 837 | */ |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 838 | bat_priv->tt.last_changeset = kzalloc(tt_diff_len, GFP_ATOMIC); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 839 | if (bat_priv->tt.last_changeset) { |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 840 | memcpy(bat_priv->tt.last_changeset, |
| 841 | tt_change, tt_change_len); |
| 842 | bat_priv->tt.last_changeset_len = tt_diff_len; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 843 | } |
| 844 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 845 | spin_unlock_bh(&bat_priv->tt.last_changeset_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 846 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 847 | container_register: |
| 848 | batadv_tvlv_container_register(bat_priv, BATADV_TVLV_TT, 1, tt_data, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 849 | tvlv_len); |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 850 | kfree(tt_data); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 853 | int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 854 | { |
| 855 | struct net_device *net_dev = (struct net_device *)seq->private; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 856 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 857 | struct batadv_hashtable *hash = bat_priv->tt.local_hash; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 858 | struct batadv_tt_common_entry *tt_common_entry; |
Antonio Quartulli | 85766a8 | 2012-11-08 22:16:16 +0100 | [diff] [blame] | 859 | struct batadv_tt_local_entry *tt_local; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 860 | struct batadv_hard_iface *primary_if; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 861 | struct batadv_softif_vlan *vlan; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 862 | struct hlist_head *head; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 863 | unsigned short vid; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 864 | uint32_t i; |
Antonio Quartulli | 85766a8 | 2012-11-08 22:16:16 +0100 | [diff] [blame] | 865 | int last_seen_secs; |
| 866 | int last_seen_msecs; |
| 867 | unsigned long last_seen_jiffies; |
| 868 | bool no_purge; |
| 869 | uint16_t np_flag = BATADV_TT_CLIENT_NOPURGE; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 870 | |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 871 | primary_if = batadv_seq_print_text_primary_if_get(seq); |
| 872 | if (!primary_if) |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 873 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 874 | |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 875 | seq_printf(seq, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 876 | "Locally retrieved addresses (from %s) announced via TT (TTVN: %u):\n", |
| 877 | net_dev->name, (uint8_t)atomic_read(&bat_priv->tt.vn)); |
| 878 | seq_printf(seq, " %-13s %s %-7s %-9s (%-10s)\n", "Client", "VID", |
| 879 | "Flags", "Last seen", "CRC"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 880 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 881 | for (i = 0; i < hash->size; i++) { |
| 882 | head = &hash->table[i]; |
| 883 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 884 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 885 | hlist_for_each_entry_rcu(tt_common_entry, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 886 | head, hash_entry) { |
Antonio Quartulli | 85766a8 | 2012-11-08 22:16:16 +0100 | [diff] [blame] | 887 | tt_local = container_of(tt_common_entry, |
| 888 | struct batadv_tt_local_entry, |
| 889 | common); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 890 | vid = tt_common_entry->vid; |
Antonio Quartulli | 85766a8 | 2012-11-08 22:16:16 +0100 | [diff] [blame] | 891 | last_seen_jiffies = jiffies - tt_local->last_seen; |
| 892 | last_seen_msecs = jiffies_to_msecs(last_seen_jiffies); |
| 893 | last_seen_secs = last_seen_msecs / 1000; |
| 894 | last_seen_msecs = last_seen_msecs % 1000; |
| 895 | |
| 896 | no_purge = tt_common_entry->flags & np_flag; |
| 897 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 898 | vlan = batadv_softif_vlan_get(bat_priv, vid); |
| 899 | if (!vlan) { |
| 900 | seq_printf(seq, "Cannot retrieve VLAN %d\n", |
| 901 | BATADV_PRINT_VID(vid)); |
| 902 | continue; |
| 903 | } |
| 904 | |
| 905 | seq_printf(seq, |
| 906 | " * %pM %4i [%c%c%c%c%c] %3u.%03u (%#.8x)\n", |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 907 | tt_common_entry->addr, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 908 | BATADV_PRINT_VID(tt_common_entry->vid), |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 909 | (tt_common_entry->flags & |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 910 | BATADV_TT_CLIENT_ROAM ? 'R' : '.'), |
Antonio Quartulli | 85766a8 | 2012-11-08 22:16:16 +0100 | [diff] [blame] | 911 | no_purge ? 'P' : '.', |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 912 | (tt_common_entry->flags & |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 913 | BATADV_TT_CLIENT_NEW ? 'N' : '.'), |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 914 | (tt_common_entry->flags & |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 915 | BATADV_TT_CLIENT_PENDING ? 'X' : '.'), |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 916 | (tt_common_entry->flags & |
Antonio Quartulli | 85766a8 | 2012-11-08 22:16:16 +0100 | [diff] [blame] | 917 | BATADV_TT_CLIENT_WIFI ? 'W' : '.'), |
Antonio Quartulli | a7966d9 | 2013-01-24 11:41:39 +0100 | [diff] [blame] | 918 | no_purge ? 0 : last_seen_secs, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 919 | no_purge ? 0 : last_seen_msecs, |
| 920 | vlan->tt.crc); |
| 921 | |
| 922 | batadv_softif_vlan_free_ref(vlan); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 923 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 924 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 925 | } |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 926 | out: |
| 927 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 928 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 929 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 932 | static void |
| 933 | batadv_tt_local_set_pending(struct batadv_priv *bat_priv, |
| 934 | struct batadv_tt_local_entry *tt_local_entry, |
| 935 | uint16_t flags, const char *message) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 936 | { |
Antonio Quartulli | 3abe4ad | 2013-04-03 11:15:33 +0200 | [diff] [blame] | 937 | batadv_tt_local_event(bat_priv, tt_local_entry, flags); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 938 | |
Antonio Quartulli | 015758d | 2011-07-09 17:52:13 +0200 | [diff] [blame] | 939 | /* The local client has to be marked as "pending to be removed" but has |
| 940 | * to be kept in the table in order to send it in a full table |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 941 | * response issued before the net ttvn increment (consistency check) |
| 942 | */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 943 | tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING; |
Antonio Quartulli | c566dbb | 2012-01-06 21:31:34 +0100 | [diff] [blame] | 944 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 945 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 946 | "Local tt entry (%pM, vid: %d) pending to be removed: %s\n", |
| 947 | tt_local_entry->common.addr, |
| 948 | BATADV_PRINT_VID(tt_local_entry->common.vid), message); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 951 | /** |
| 952 | * batadv_tt_local_remove - logically remove an entry from the local table |
| 953 | * @bat_priv: the bat priv with all the soft interface information |
| 954 | * @addr: the MAC address of the client to remove |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 955 | * @vid: VLAN identifier |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 956 | * @message: message to append to the log on deletion |
| 957 | * @roaming: true if the deletion is due to a roaming event |
| 958 | * |
| 959 | * Returns the flags assigned to the local entry before being deleted |
| 960 | */ |
| 961 | uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 962 | const uint8_t *addr, unsigned short vid, |
| 963 | const char *message, bool roaming) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 964 | { |
Sven Eckelmann | 170173b | 2012-10-07 12:02:22 +0200 | [diff] [blame] | 965 | struct batadv_tt_local_entry *tt_local_entry; |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 966 | uint16_t flags, curr_flags = BATADV_NO_FLAGS; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 967 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 968 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 969 | if (!tt_local_entry) |
| 970 | goto out; |
| 971 | |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 972 | curr_flags = tt_local_entry->common.flags; |
| 973 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 974 | flags = BATADV_TT_CLIENT_DEL; |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 975 | /* if this global entry addition is due to a roaming, the node has to |
| 976 | * mark the local entry as "roamed" in order to correctly reroute |
| 977 | * packets later |
| 978 | */ |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 979 | if (roaming) { |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 980 | flags |= BATADV_TT_CLIENT_ROAM; |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 981 | /* mark the local client as ROAMed */ |
| 982 | tt_local_entry->common.flags |= BATADV_TT_CLIENT_ROAM; |
| 983 | } |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 984 | |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 985 | if (!(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) { |
| 986 | batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags, |
| 987 | message); |
| 988 | goto out; |
| 989 | } |
| 990 | /* if this client has been added right now, it is possible to |
| 991 | * immediately purge it |
| 992 | */ |
Antonio Quartulli | 3abe4ad | 2013-04-03 11:15:33 +0200 | [diff] [blame] | 993 | batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 994 | hlist_del_rcu(&tt_local_entry->common.hash_entry); |
| 995 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 996 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 997 | out: |
| 998 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 999 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 1000 | |
| 1001 | return curr_flags; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 1004 | /** |
| 1005 | * batadv_tt_local_purge_list - purge inactive tt local entries |
| 1006 | * @bat_priv: the bat priv with all the soft interface information |
| 1007 | * @head: pointer to the list containing the local tt entries |
| 1008 | * @timeout: parameter deciding whether a given tt local entry is considered |
| 1009 | * inactive or not |
| 1010 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1011 | static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv, |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 1012 | struct hlist_head *head, |
| 1013 | int timeout) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1014 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1015 | struct batadv_tt_local_entry *tt_local_entry; |
| 1016 | struct batadv_tt_common_entry *tt_common_entry; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1017 | struct hlist_node *node_tmp; |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1018 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1019 | hlist_for_each_entry_safe(tt_common_entry, node_tmp, head, |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1020 | hash_entry) { |
| 1021 | tt_local_entry = container_of(tt_common_entry, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1022 | struct batadv_tt_local_entry, |
| 1023 | common); |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1024 | if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE) |
| 1025 | continue; |
| 1026 | |
| 1027 | /* entry already marked for deletion */ |
| 1028 | if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) |
| 1029 | continue; |
| 1030 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 1031 | if (!batadv_has_timed_out(tt_local_entry->last_seen, timeout)) |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1032 | continue; |
| 1033 | |
| 1034 | batadv_tt_local_set_pending(bat_priv, tt_local_entry, |
| 1035 | BATADV_TT_CLIENT_DEL, "timed out"); |
| 1036 | } |
| 1037 | } |
| 1038 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 1039 | /** |
| 1040 | * batadv_tt_local_purge - purge inactive tt local entries |
| 1041 | * @bat_priv: the bat priv with all the soft interface information |
| 1042 | * @timeout: parameter deciding whether a given tt local entry is considered |
| 1043 | * inactive or not |
| 1044 | */ |
| 1045 | static void batadv_tt_local_purge(struct batadv_priv *bat_priv, |
| 1046 | int timeout) |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1047 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1048 | struct batadv_hashtable *hash = bat_priv->tt.local_hash; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1049 | struct hlist_head *head; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1050 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1051 | uint32_t i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1052 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1053 | for (i = 0; i < hash->size; i++) { |
| 1054 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1055 | list_lock = &hash->list_locks[i]; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1056 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1057 | spin_lock_bh(list_lock); |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 1058 | batadv_tt_local_purge_list(bat_priv, head, timeout); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1059 | spin_unlock_bh(list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1060 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1063 | static void batadv_tt_local_table_free(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1064 | { |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 1065 | struct batadv_hashtable *hash; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1066 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1067 | struct batadv_tt_common_entry *tt_common_entry; |
| 1068 | struct batadv_tt_local_entry *tt_local; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1069 | struct hlist_node *node_tmp; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1070 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1071 | uint32_t i; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1072 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1073 | if (!bat_priv->tt.local_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1074 | return; |
| 1075 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1076 | hash = bat_priv->tt.local_hash; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1077 | |
| 1078 | for (i = 0; i < hash->size; i++) { |
| 1079 | head = &hash->table[i]; |
| 1080 | list_lock = &hash->list_locks[i]; |
| 1081 | |
| 1082 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1083 | hlist_for_each_entry_safe(tt_common_entry, node_tmp, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1084 | head, hash_entry) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1085 | hlist_del_rcu(&tt_common_entry->hash_entry); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1086 | tt_local = container_of(tt_common_entry, |
| 1087 | struct batadv_tt_local_entry, |
| 1088 | common); |
| 1089 | batadv_tt_local_entry_free_ref(tt_local); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1090 | } |
| 1091 | spin_unlock_bh(list_lock); |
| 1092 | } |
| 1093 | |
Sven Eckelmann | 1a8eaf0 | 2012-05-12 02:09:32 +0200 | [diff] [blame] | 1094 | batadv_hash_destroy(hash); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1095 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1096 | bat_priv->tt.local_hash = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1099 | static int batadv_tt_global_init(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1100 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1101 | if (bat_priv->tt.global_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1102 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1103 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1104 | bat_priv->tt.global_hash = batadv_hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1105 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1106 | if (!bat_priv->tt.global_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1107 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1108 | |
Antonio Quartulli | dec0507 | 2012-11-10 11:00:32 +0100 | [diff] [blame] | 1109 | batadv_hash_set_lock_class(bat_priv->tt.global_hash, |
| 1110 | &batadv_tt_global_hash_lock_class_key); |
| 1111 | |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1112 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1115 | static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1116 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1117 | struct batadv_tt_change_node *entry, *safe; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1118 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1119 | spin_lock_bh(&bat_priv->tt.changes_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1120 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1121 | list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1122 | list) { |
| 1123 | list_del(&entry->list); |
| 1124 | kfree(entry); |
| 1125 | } |
| 1126 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1127 | atomic_set(&bat_priv->tt.local_changes, 0); |
| 1128 | spin_unlock_bh(&bat_priv->tt.changes_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1129 | } |
| 1130 | |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1131 | /* retrieves the orig_tt_list_entry belonging to orig_node from the |
| 1132 | * batadv_tt_global_entry list |
| 1133 | * |
| 1134 | * returns it with an increased refcounter, NULL if not found |
| 1135 | */ |
| 1136 | static struct batadv_tt_orig_list_entry * |
| 1137 | batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry, |
| 1138 | const struct batadv_orig_node *orig_node) |
| 1139 | { |
| 1140 | struct batadv_tt_orig_list_entry *tmp_orig_entry, *orig_entry = NULL; |
| 1141 | const struct hlist_head *head; |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1142 | |
| 1143 | rcu_read_lock(); |
| 1144 | head = &entry->orig_list; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1145 | hlist_for_each_entry_rcu(tmp_orig_entry, head, list) { |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1146 | if (tmp_orig_entry->orig_node != orig_node) |
| 1147 | continue; |
| 1148 | if (!atomic_inc_not_zero(&tmp_orig_entry->refcount)) |
| 1149 | continue; |
| 1150 | |
| 1151 | orig_entry = tmp_orig_entry; |
| 1152 | break; |
| 1153 | } |
| 1154 | rcu_read_unlock(); |
| 1155 | |
| 1156 | return orig_entry; |
| 1157 | } |
| 1158 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1159 | /* find out if an orig_node is already in the list of a tt_global_entry. |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1160 | * returns true if found, false otherwise |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1161 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1162 | static bool |
| 1163 | batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry, |
| 1164 | const struct batadv_orig_node *orig_node) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1165 | { |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1166 | struct batadv_tt_orig_list_entry *orig_entry; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1167 | bool found = false; |
| 1168 | |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1169 | orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node); |
| 1170 | if (orig_entry) { |
| 1171 | found = true; |
| 1172 | batadv_tt_orig_list_entry_free_ref(orig_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1173 | } |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1174 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1175 | return found; |
| 1176 | } |
| 1177 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1178 | static void |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1179 | batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1180 | struct batadv_orig_node *orig_node, int ttvn) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1181 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1182 | struct batadv_tt_orig_list_entry *orig_entry; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1183 | |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1184 | orig_entry = batadv_tt_global_orig_entry_find(tt_global, orig_node); |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1185 | if (orig_entry) { |
| 1186 | /* refresh the ttvn: the current value could be a bogus one that |
| 1187 | * was added during a "temporary client detection" |
| 1188 | */ |
| 1189 | orig_entry->ttvn = ttvn; |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1190 | goto out; |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1191 | } |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1192 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1193 | orig_entry = kzalloc(sizeof(*orig_entry), GFP_ATOMIC); |
| 1194 | if (!orig_entry) |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1195 | goto out; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1196 | |
| 1197 | INIT_HLIST_NODE(&orig_entry->list); |
| 1198 | atomic_inc(&orig_node->refcount); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1199 | batadv_tt_global_size_inc(orig_node, tt_global->common.vid); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1200 | orig_entry->orig_node = orig_node; |
| 1201 | orig_entry->ttvn = ttvn; |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1202 | atomic_set(&orig_entry->refcount, 2); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1203 | |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1204 | spin_lock_bh(&tt_global->list_lock); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1205 | hlist_add_head_rcu(&orig_entry->list, |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1206 | &tt_global->orig_list); |
| 1207 | spin_unlock_bh(&tt_global->list_lock); |
| 1208 | out: |
| 1209 | if (orig_entry) |
| 1210 | batadv_tt_orig_list_entry_free_ref(orig_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1211 | } |
| 1212 | |
Antonio Quartulli | d4ff40f | 2013-04-18 15:13:01 +0200 | [diff] [blame] | 1213 | /** |
| 1214 | * batadv_tt_global_add - add a new TT global entry or update an existing one |
| 1215 | * @bat_priv: the bat priv with all the soft interface information |
| 1216 | * @orig_node: the originator announcing the client |
| 1217 | * @tt_addr: the mac address of the non-mesh client |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1218 | * @vid: VLAN identifier |
Antonio Quartulli | d4ff40f | 2013-04-18 15:13:01 +0200 | [diff] [blame] | 1219 | * @flags: TT flags that have to be set for this non-mesh client |
| 1220 | * @ttvn: the tt version number ever announcing this non-mesh client |
| 1221 | * |
| 1222 | * Add a new TT global entry for the given originator. If the entry already |
| 1223 | * exists add a new reference to the given originator (a global entry can have |
| 1224 | * references to multiple originators) and adjust the flags attribute to reflect |
| 1225 | * the function argument. |
| 1226 | * If a TT local entry exists for this non-mesh client remove it. |
| 1227 | * |
| 1228 | * The caller must hold orig_node refcount. |
Antonio Quartulli | 1e5d49f | 2013-05-05 19:32:38 +0200 | [diff] [blame] | 1229 | * |
| 1230 | * Return true if the new entry has been added, false otherwise |
Antonio Quartulli | d4ff40f | 2013-04-18 15:13:01 +0200 | [diff] [blame] | 1231 | */ |
Antonio Quartulli | 1e5d49f | 2013-05-05 19:32:38 +0200 | [diff] [blame] | 1232 | static bool batadv_tt_global_add(struct batadv_priv *bat_priv, |
| 1233 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1234 | const unsigned char *tt_addr, |
| 1235 | unsigned short vid, uint16_t flags, |
Antonio Quartulli | 1e5d49f | 2013-05-05 19:32:38 +0200 | [diff] [blame] | 1236 | uint8_t ttvn) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1237 | { |
Sven Eckelmann | 170173b | 2012-10-07 12:02:22 +0200 | [diff] [blame] | 1238 | struct batadv_tt_global_entry *tt_global_entry; |
| 1239 | struct batadv_tt_local_entry *tt_local_entry; |
Antonio Quartulli | 1e5d49f | 2013-05-05 19:32:38 +0200 | [diff] [blame] | 1240 | bool ret = false; |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 1241 | int hash_added; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1242 | struct batadv_tt_common_entry *common; |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 1243 | uint16_t local_flags; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1244 | |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1245 | /* ignore global entries from backbone nodes */ |
| 1246 | if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig, vid)) |
| 1247 | return true; |
| 1248 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1249 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, tt_addr, vid); |
| 1250 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, tt_addr, vid); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1251 | |
| 1252 | /* if the node already has a local client for this entry, it has to wait |
| 1253 | * for a roaming advertisement instead of manually messing up the global |
| 1254 | * table |
| 1255 | */ |
| 1256 | if ((flags & BATADV_TT_CLIENT_TEMP) && tt_local_entry && |
| 1257 | !(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) |
| 1258 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1259 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1260 | if (!tt_global_entry) { |
Antonio Quartulli | d4f4469 | 2012-05-25 00:00:54 +0200 | [diff] [blame] | 1261 | tt_global_entry = kzalloc(sizeof(*tt_global_entry), GFP_ATOMIC); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1262 | if (!tt_global_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1263 | goto out; |
| 1264 | |
Sven Eckelmann | c0a5592 | 2012-05-12 13:48:55 +0200 | [diff] [blame] | 1265 | common = &tt_global_entry->common; |
| 1266 | memcpy(common->addr, tt_addr, ETH_ALEN); |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1267 | common->vid = vid; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1268 | |
Antonio Quartulli | d4f4469 | 2012-05-25 00:00:54 +0200 | [diff] [blame] | 1269 | common->flags = flags; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1270 | tt_global_entry->roam_at = 0; |
Antonio Quartulli | fdf7932 | 2012-08-24 17:54:07 +0200 | [diff] [blame] | 1271 | /* node must store current time in case of roaming. This is |
| 1272 | * needed to purge this entry out on timeout (if nobody claims |
| 1273 | * it) |
| 1274 | */ |
| 1275 | if (flags & BATADV_TT_CLIENT_ROAM) |
| 1276 | tt_global_entry->roam_at = jiffies; |
Sven Eckelmann | c0a5592 | 2012-05-12 13:48:55 +0200 | [diff] [blame] | 1277 | atomic_set(&common->refcount, 2); |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1278 | common->added_at = jiffies; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1279 | |
| 1280 | INIT_HLIST_HEAD(&tt_global_entry->orig_list); |
| 1281 | spin_lock_init(&tt_global_entry->list_lock); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1282 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1283 | hash_added = batadv_hash_add(bat_priv->tt.global_hash, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1284 | batadv_compare_tt, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1285 | batadv_choose_tt, common, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1286 | &common->hash_entry); |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 1287 | |
| 1288 | if (unlikely(hash_added != 0)) { |
| 1289 | /* remove the reference for the hash */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1290 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 1291 | goto out_remove; |
| 1292 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1293 | } else { |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1294 | common = &tt_global_entry->common; |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1295 | /* If there is already a global entry, we can use this one for |
| 1296 | * our processing. |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1297 | * But if we are trying to add a temporary client then here are |
| 1298 | * two options at this point: |
| 1299 | * 1) the global client is not a temporary client: the global |
| 1300 | * client has to be left as it is, temporary information |
| 1301 | * should never override any already known client state |
| 1302 | * 2) the global client is a temporary client: purge the |
| 1303 | * originator list and add the new one orig_entry |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1304 | */ |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1305 | if (flags & BATADV_TT_CLIENT_TEMP) { |
| 1306 | if (!(common->flags & BATADV_TT_CLIENT_TEMP)) |
| 1307 | goto out; |
| 1308 | if (batadv_tt_global_entry_has_orig(tt_global_entry, |
| 1309 | orig_node)) |
| 1310 | goto out_remove; |
| 1311 | batadv_tt_global_del_orig_list(tt_global_entry); |
| 1312 | goto add_orig_entry; |
| 1313 | } |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1314 | |
| 1315 | /* if the client was temporary added before receiving the first |
| 1316 | * OGM announcing it, we have to clear the TEMP flag |
| 1317 | */ |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1318 | common->flags &= ~BATADV_TT_CLIENT_TEMP; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1319 | |
Antonio Quartulli | e9c00136 | 2012-11-07 15:05:33 +0100 | [diff] [blame] | 1320 | /* the change can carry possible "attribute" flags like the |
| 1321 | * TT_CLIENT_WIFI, therefore they have to be copied in the |
| 1322 | * client entry |
| 1323 | */ |
| 1324 | tt_global_entry->common.flags |= flags; |
| 1325 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1326 | /* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only |
| 1327 | * one originator left in the list and we previously received a |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1328 | * delete + roaming change for this originator. |
| 1329 | * |
| 1330 | * We should first delete the old originator before adding the |
| 1331 | * new one. |
| 1332 | */ |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1333 | if (common->flags & BATADV_TT_CLIENT_ROAM) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1334 | batadv_tt_global_del_orig_list(tt_global_entry); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1335 | common->flags &= ~BATADV_TT_CLIENT_ROAM; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1336 | tt_global_entry->roam_at = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1337 | } |
| 1338 | } |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1339 | add_orig_entry: |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1340 | /* add the new orig_entry (if needed) or update it */ |
Antonio Quartulli | d657e62 | 2012-07-01 14:09:12 +0200 | [diff] [blame] | 1341 | batadv_tt_global_orig_entry_add(tt_global_entry, orig_node, ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1342 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1343 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1344 | "Creating new global tt entry: %pM (vid: %d, via %pM)\n", |
| 1345 | common->addr, BATADV_PRINT_VID(common->vid), |
| 1346 | orig_node->orig); |
Antonio Quartulli | 1e5d49f | 2013-05-05 19:32:38 +0200 | [diff] [blame] | 1347 | ret = true; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1348 | |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 1349 | out_remove: |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 1350 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1351 | /* remove address from local hash if present */ |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1352 | local_flags = batadv_tt_local_remove(bat_priv, tt_addr, vid, |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 1353 | "global tt received", |
Antonio Quartulli | c1d0743 | 2013-01-15 22:17:19 +1000 | [diff] [blame] | 1354 | flags & BATADV_TT_CLIENT_ROAM); |
Antonio Quartulli | 7f91d06 | 2012-08-27 11:44:43 +0200 | [diff] [blame] | 1355 | tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI; |
| 1356 | |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1357 | if (!(flags & BATADV_TT_CLIENT_ROAM)) |
| 1358 | /* this is a normal global add. Therefore the client is not in a |
| 1359 | * roaming state anymore. |
| 1360 | */ |
| 1361 | tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM; |
| 1362 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1363 | out: |
| 1364 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1365 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1366 | if (tt_local_entry) |
| 1367 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1368 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1371 | /* batadv_transtable_best_orig - Get best originator list entry from tt entry |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1372 | * @bat_priv: the bat priv with all the soft interface information |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1373 | * @tt_global_entry: global translation table entry to be analyzed |
| 1374 | * |
| 1375 | * This functon assumes the caller holds rcu_read_lock(). |
| 1376 | * Returns best originator list entry or NULL on errors. |
| 1377 | */ |
| 1378 | static struct batadv_tt_orig_list_entry * |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1379 | batadv_transtable_best_orig(struct batadv_priv *bat_priv, |
| 1380 | struct batadv_tt_global_entry *tt_global_entry) |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1381 | { |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1382 | struct batadv_neigh_node *router, *best_router = NULL; |
| 1383 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1384 | struct hlist_head *head; |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1385 | struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL; |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1386 | |
| 1387 | head = &tt_global_entry->orig_list; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1388 | hlist_for_each_entry_rcu(orig_entry, head, list) { |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1389 | router = batadv_orig_node_get_router(orig_entry->orig_node); |
| 1390 | if (!router) |
| 1391 | continue; |
| 1392 | |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1393 | if (best_router && |
| 1394 | bao->bat_neigh_cmp(router, best_router) <= 0) { |
| 1395 | batadv_neigh_node_free_ref(router); |
| 1396 | continue; |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1399 | /* release the refcount for the "old" best */ |
| 1400 | if (best_router) |
| 1401 | batadv_neigh_node_free_ref(best_router); |
| 1402 | |
| 1403 | best_entry = orig_entry; |
| 1404 | best_router = router; |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1405 | } |
| 1406 | |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1407 | if (best_router) |
| 1408 | batadv_neigh_node_free_ref(best_router); |
| 1409 | |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1410 | return best_entry; |
| 1411 | } |
| 1412 | |
| 1413 | /* batadv_tt_global_print_entry - print all orig nodes who announce the address |
| 1414 | * for this global entry |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1415 | * @bat_priv: the bat priv with all the soft interface information |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1416 | * @tt_global_entry: global translation table entry to be printed |
| 1417 | * @seq: debugfs table seq_file struct |
| 1418 | * |
| 1419 | * This functon assumes the caller holds rcu_read_lock(). |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1420 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1421 | static void |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1422 | batadv_tt_global_print_entry(struct batadv_priv *bat_priv, |
| 1423 | struct batadv_tt_global_entry *tt_global_entry, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1424 | struct seq_file *seq) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1425 | { |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1426 | struct batadv_tt_orig_list_entry *orig_entry, *best_entry; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1427 | struct batadv_tt_common_entry *tt_common_entry; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1428 | struct batadv_orig_node_vlan *vlan; |
| 1429 | struct hlist_head *head; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1430 | uint8_t last_ttvn; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1431 | uint16_t flags; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1432 | |
| 1433 | tt_common_entry = &tt_global_entry->common; |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1434 | flags = tt_common_entry->flags; |
| 1435 | |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1436 | best_entry = batadv_transtable_best_orig(bat_priv, tt_global_entry); |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1437 | if (best_entry) { |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1438 | vlan = batadv_orig_node_vlan_get(best_entry->orig_node, |
| 1439 | tt_common_entry->vid); |
| 1440 | if (!vlan) { |
| 1441 | seq_printf(seq, |
| 1442 | " * Cannot retrieve VLAN %d for originator %pM\n", |
| 1443 | BATADV_PRINT_VID(tt_common_entry->vid), |
| 1444 | best_entry->orig_node->orig); |
| 1445 | goto print_list; |
| 1446 | } |
| 1447 | |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1448 | last_ttvn = atomic_read(&best_entry->orig_node->last_ttvn); |
Antonio Quartulli | f9d8a53 | 2012-11-19 09:01:42 +0100 | [diff] [blame] | 1449 | seq_printf(seq, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1450 | " %c %pM %4i (%3u) via %pM (%3u) (%#.8x) [%c%c%c]\n", |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1451 | '*', tt_global_entry->common.addr, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1452 | BATADV_PRINT_VID(tt_global_entry->common.vid), |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1453 | best_entry->ttvn, best_entry->orig_node->orig, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1454 | last_ttvn, vlan->tt.crc, |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1455 | (flags & BATADV_TT_CLIENT_ROAM ? 'R' : '.'), |
| 1456 | (flags & BATADV_TT_CLIENT_WIFI ? 'W' : '.'), |
| 1457 | (flags & BATADV_TT_CLIENT_TEMP ? 'T' : '.')); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1458 | |
| 1459 | batadv_orig_node_vlan_free_ref(vlan); |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1460 | } |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1461 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1462 | print_list: |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1463 | head = &tt_global_entry->orig_list; |
| 1464 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1465 | hlist_for_each_entry_rcu(orig_entry, head, list) { |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1466 | if (best_entry == orig_entry) |
| 1467 | continue; |
| 1468 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1469 | vlan = batadv_orig_node_vlan_get(orig_entry->orig_node, |
| 1470 | tt_common_entry->vid); |
| 1471 | if (!vlan) { |
| 1472 | seq_printf(seq, |
| 1473 | " + Cannot retrieve VLAN %d for originator %pM\n", |
| 1474 | BATADV_PRINT_VID(tt_common_entry->vid), |
| 1475 | orig_entry->orig_node->orig); |
| 1476 | continue; |
| 1477 | } |
| 1478 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1479 | last_ttvn = atomic_read(&orig_entry->orig_node->last_ttvn); |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1480 | seq_printf(seq, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1481 | " %c %pM %4d (%3u) via %pM (%3u) (%#.8x) [%c%c%c]\n", |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1482 | '+', tt_global_entry->common.addr, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1483 | BATADV_PRINT_VID(tt_global_entry->common.vid), |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1484 | orig_entry->ttvn, orig_entry->orig_node->orig, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1485 | last_ttvn, vlan->tt.crc, |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1486 | (flags & BATADV_TT_CLIENT_ROAM ? 'R' : '.'), |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1487 | (flags & BATADV_TT_CLIENT_WIFI ? 'W' : '.'), |
| 1488 | (flags & BATADV_TT_CLIENT_TEMP ? 'T' : '.')); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1489 | |
| 1490 | batadv_orig_node_vlan_free_ref(vlan); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1494 | int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1495 | { |
| 1496 | struct net_device *net_dev = (struct net_device *)seq->private; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1497 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1498 | struct batadv_hashtable *hash = bat_priv->tt.global_hash; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1499 | struct batadv_tt_common_entry *tt_common_entry; |
| 1500 | struct batadv_tt_global_entry *tt_global; |
| 1501 | struct batadv_hard_iface *primary_if; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1502 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1503 | uint32_t i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1504 | |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 1505 | primary_if = batadv_seq_print_text_primary_if_get(seq); |
| 1506 | if (!primary_if) |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 1507 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1508 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 1509 | seq_printf(seq, |
| 1510 | "Globally announced TT entries received via the mesh %s\n", |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1511 | net_dev->name); |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1512 | seq_printf(seq, " %-13s %s %s %-15s %s (%-10s) %s\n", |
| 1513 | "Client", "VID", "(TTVN)", "Originator", "(Curr TTVN)", |
| 1514 | "CRC", "Flags"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1515 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1516 | for (i = 0; i < hash->size; i++) { |
| 1517 | head = &hash->table[i]; |
| 1518 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 1519 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1520 | hlist_for_each_entry_rcu(tt_common_entry, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 1521 | head, hash_entry) { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1522 | tt_global = container_of(tt_common_entry, |
| 1523 | struct batadv_tt_global_entry, |
| 1524 | common); |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1525 | batadv_tt_global_print_entry(bat_priv, tt_global, seq); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1526 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 1527 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1528 | } |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 1529 | out: |
| 1530 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1531 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 1532 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1535 | /* deletes the orig list of a tt_global_entry */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1536 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1537 | batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1538 | { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1539 | struct hlist_head *head; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1540 | struct hlist_node *safe; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1541 | struct batadv_tt_orig_list_entry *orig_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1542 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1543 | spin_lock_bh(&tt_global_entry->list_lock); |
| 1544 | head = &tt_global_entry->orig_list; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1545 | hlist_for_each_entry_safe(orig_entry, safe, head, list) { |
| 1546 | hlist_del_rcu(&orig_entry->list); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1547 | batadv_tt_global_size_dec(orig_entry->orig_node, |
| 1548 | tt_global_entry->common.vid); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1549 | batadv_tt_orig_list_entry_free_ref(orig_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1550 | } |
| 1551 | spin_unlock_bh(&tt_global_entry->list_lock); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1552 | } |
| 1553 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1554 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1555 | batadv_tt_global_del_orig_entry(struct batadv_priv *bat_priv, |
| 1556 | struct batadv_tt_global_entry *tt_global_entry, |
| 1557 | struct batadv_orig_node *orig_node, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1558 | const char *message) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1559 | { |
| 1560 | struct hlist_head *head; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1561 | struct hlist_node *safe; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1562 | struct batadv_tt_orig_list_entry *orig_entry; |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1563 | unsigned short vid; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1564 | |
| 1565 | spin_lock_bh(&tt_global_entry->list_lock); |
| 1566 | head = &tt_global_entry->orig_list; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1567 | hlist_for_each_entry_safe(orig_entry, safe, head, list) { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1568 | if (orig_entry->orig_node == orig_node) { |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1569 | vid = tt_global_entry->common.vid; |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1570 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1571 | "Deleting %pM from global tt entry %pM (vid: %d): %s\n", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1572 | orig_node->orig, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1573 | tt_global_entry->common.addr, |
| 1574 | BATADV_PRINT_VID(vid), message); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1575 | hlist_del_rcu(&orig_entry->list); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1576 | batadv_tt_global_size_dec(orig_node, |
| 1577 | tt_global_entry->common.vid); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1578 | batadv_tt_orig_list_entry_free_ref(orig_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1579 | } |
| 1580 | } |
| 1581 | spin_unlock_bh(&tt_global_entry->list_lock); |
| 1582 | } |
| 1583 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1584 | /* If the client is to be deleted, we check if it is the last origantor entry |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1585 | * within tt_global entry. If yes, we set the BATADV_TT_CLIENT_ROAM flag and the |
| 1586 | * timer, otherwise we simply remove the originator scheduled for deletion. |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1587 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1588 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1589 | batadv_tt_global_del_roaming(struct batadv_priv *bat_priv, |
| 1590 | struct batadv_tt_global_entry *tt_global_entry, |
| 1591 | struct batadv_orig_node *orig_node, |
| 1592 | const char *message) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1593 | { |
| 1594 | bool last_entry = true; |
| 1595 | struct hlist_head *head; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1596 | struct batadv_tt_orig_list_entry *orig_entry; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1597 | |
| 1598 | /* no local entry exists, case 1: |
| 1599 | * Check if this is the last one or if other entries exist. |
| 1600 | */ |
| 1601 | |
| 1602 | rcu_read_lock(); |
| 1603 | head = &tt_global_entry->orig_list; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1604 | hlist_for_each_entry_rcu(orig_entry, head, list) { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1605 | if (orig_entry->orig_node != orig_node) { |
| 1606 | last_entry = false; |
| 1607 | break; |
| 1608 | } |
| 1609 | } |
| 1610 | rcu_read_unlock(); |
| 1611 | |
| 1612 | if (last_entry) { |
| 1613 | /* its the last one, mark for roaming. */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1614 | tt_global_entry->common.flags |= BATADV_TT_CLIENT_ROAM; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1615 | tt_global_entry->roam_at = jiffies; |
| 1616 | } else |
| 1617 | /* there is another entry, we can simply delete this |
| 1618 | * one and can still use the other one. |
| 1619 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1620 | batadv_tt_global_del_orig_entry(bat_priv, tt_global_entry, |
| 1621 | orig_node, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1622 | } |
| 1623 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1624 | /** |
| 1625 | * batadv_tt_global_del - remove a client from the global table |
| 1626 | * @bat_priv: the bat priv with all the soft interface information |
| 1627 | * @orig_node: an originator serving this client |
| 1628 | * @addr: the mac address of the client |
| 1629 | * @vid: VLAN identifier |
| 1630 | * @message: a message explaining the reason for deleting the client to print |
| 1631 | * for debugging purpose |
| 1632 | * @roaming: true if the deletion has been triggered by a roaming event |
| 1633 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1634 | static void batadv_tt_global_del(struct batadv_priv *bat_priv, |
| 1635 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1636 | const unsigned char *addr, unsigned short vid, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1637 | const char *message, bool roaming) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1638 | { |
Sven Eckelmann | 170173b | 2012-10-07 12:02:22 +0200 | [diff] [blame] | 1639 | struct batadv_tt_global_entry *tt_global_entry; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1640 | struct batadv_tt_local_entry *local_entry = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1641 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1642 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1643 | if (!tt_global_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1644 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1645 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1646 | if (!roaming) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1647 | batadv_tt_global_del_orig_entry(bat_priv, tt_global_entry, |
| 1648 | orig_node, message); |
Sven Eckelmann | 92f90f5 | 2011-12-22 20:31:12 +0800 | [diff] [blame] | 1649 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1650 | if (hlist_empty(&tt_global_entry->orig_list)) |
Antonio Quartulli | be73b48 | 2012-09-23 22:38:36 +0200 | [diff] [blame] | 1651 | batadv_tt_global_free(bat_priv, tt_global_entry, |
| 1652 | message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1653 | |
Sven Eckelmann | 92f90f5 | 2011-12-22 20:31:12 +0800 | [diff] [blame] | 1654 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1655 | } |
Sven Eckelmann | 92f90f5 | 2011-12-22 20:31:12 +0800 | [diff] [blame] | 1656 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1657 | /* if we are deleting a global entry due to a roam |
| 1658 | * event, there are two possibilities: |
| 1659 | * 1) the client roamed from node A to node B => if there |
| 1660 | * is only one originator left for this client, we mark |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1661 | * it with BATADV_TT_CLIENT_ROAM, we start a timer and we |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1662 | * wait for node B to claim it. In case of timeout |
| 1663 | * the entry is purged. |
| 1664 | * |
| 1665 | * If there are other originators left, we directly delete |
| 1666 | * the originator. |
| 1667 | * 2) the client roamed to us => we can directly delete |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1668 | * the global entry, since it is useless now. |
| 1669 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1670 | local_entry = batadv_tt_local_hash_find(bat_priv, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1671 | tt_global_entry->common.addr, |
| 1672 | vid); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1673 | if (local_entry) { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1674 | /* local entry exists, case 2: client roamed to us. */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1675 | batadv_tt_global_del_orig_list(tt_global_entry); |
Antonio Quartulli | be73b48 | 2012-09-23 22:38:36 +0200 | [diff] [blame] | 1676 | batadv_tt_global_free(bat_priv, tt_global_entry, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1677 | } else |
| 1678 | /* no local entry exists, case 1: check for roaming */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1679 | batadv_tt_global_del_roaming(bat_priv, tt_global_entry, |
| 1680 | orig_node, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1681 | |
Sven Eckelmann | 92f90f5 | 2011-12-22 20:31:12 +0800 | [diff] [blame] | 1682 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1683 | out: |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1684 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1685 | batadv_tt_global_entry_free_ref(tt_global_entry); |
| 1686 | if (local_entry) |
| 1687 | batadv_tt_local_entry_free_ref(local_entry); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
Antonio Quartulli | 95fb130 | 2013-08-07 18:28:55 +0200 | [diff] [blame] | 1690 | /** |
| 1691 | * batadv_tt_global_del_orig - remove all the TT global entries belonging to the |
| 1692 | * given originator matching the provided vid |
| 1693 | * @bat_priv: the bat priv with all the soft interface information |
| 1694 | * @orig_node: the originator owning the entries to remove |
| 1695 | * @match_vid: the VLAN identifier to match. If negative all the entries will be |
| 1696 | * removed |
| 1697 | * @message: debug message to print as "reason" |
| 1698 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1699 | void batadv_tt_global_del_orig(struct batadv_priv *bat_priv, |
| 1700 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | 95fb130 | 2013-08-07 18:28:55 +0200 | [diff] [blame] | 1701 | int32_t match_vid, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1702 | const char *message) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1703 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1704 | struct batadv_tt_global_entry *tt_global; |
| 1705 | struct batadv_tt_common_entry *tt_common_entry; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1706 | uint32_t i; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1707 | struct batadv_hashtable *hash = bat_priv->tt.global_hash; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1708 | struct hlist_node *safe; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1709 | struct hlist_head *head; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1710 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1711 | unsigned short vid; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1712 | |
Simon Wunderlich | 6e80149 | 2011-10-19 10:28:26 +0200 | [diff] [blame] | 1713 | if (!hash) |
| 1714 | return; |
| 1715 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1716 | for (i = 0; i < hash->size; i++) { |
| 1717 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1718 | list_lock = &hash->list_locks[i]; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1719 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1720 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1721 | hlist_for_each_entry_safe(tt_common_entry, safe, |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 1722 | head, hash_entry) { |
Antonio Quartulli | 95fb130 | 2013-08-07 18:28:55 +0200 | [diff] [blame] | 1723 | /* remove only matching entries */ |
| 1724 | if (match_vid >= 0 && tt_common_entry->vid != match_vid) |
| 1725 | continue; |
| 1726 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1727 | tt_global = container_of(tt_common_entry, |
| 1728 | struct batadv_tt_global_entry, |
| 1729 | common); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1730 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1731 | batadv_tt_global_del_orig_entry(bat_priv, tt_global, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1732 | orig_node, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1733 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1734 | if (hlist_empty(&tt_global->orig_list)) { |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1735 | vid = tt_global->common.vid; |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1736 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1737 | "Deleting global tt entry %pM (vid: %d): %s\n", |
| 1738 | tt_global->common.addr, |
| 1739 | BATADV_PRINT_VID(vid), message); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1740 | hlist_del_rcu(&tt_common_entry->hash_entry); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1741 | batadv_tt_global_entry_free_ref(tt_global); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1742 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1743 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1744 | spin_unlock_bh(list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1745 | } |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 1746 | orig_node->tt_initialised = false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1749 | static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global, |
| 1750 | char **msg) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1751 | { |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1752 | bool purge = false; |
| 1753 | unsigned long roam_timeout = BATADV_TT_CLIENT_ROAM_TIMEOUT; |
| 1754 | unsigned long temp_timeout = BATADV_TT_CLIENT_TEMP_TIMEOUT; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1755 | |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1756 | if ((tt_global->common.flags & BATADV_TT_CLIENT_ROAM) && |
| 1757 | batadv_has_timed_out(tt_global->roam_at, roam_timeout)) { |
| 1758 | purge = true; |
| 1759 | *msg = "Roaming timeout\n"; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1760 | } |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1761 | |
| 1762 | if ((tt_global->common.flags & BATADV_TT_CLIENT_TEMP) && |
| 1763 | batadv_has_timed_out(tt_global->common.added_at, temp_timeout)) { |
| 1764 | purge = true; |
| 1765 | *msg = "Temporary client timeout\n"; |
| 1766 | } |
| 1767 | |
| 1768 | return purge; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1769 | } |
| 1770 | |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1771 | static void batadv_tt_global_purge(struct batadv_priv *bat_priv) |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1772 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1773 | struct batadv_hashtable *hash = bat_priv->tt.global_hash; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1774 | struct hlist_head *head; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1775 | struct hlist_node *node_tmp; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1776 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1777 | uint32_t i; |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1778 | char *msg = NULL; |
| 1779 | struct batadv_tt_common_entry *tt_common; |
| 1780 | struct batadv_tt_global_entry *tt_global; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1781 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1782 | for (i = 0; i < hash->size; i++) { |
| 1783 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1784 | list_lock = &hash->list_locks[i]; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1785 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1786 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1787 | hlist_for_each_entry_safe(tt_common, node_tmp, head, |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1788 | hash_entry) { |
| 1789 | tt_global = container_of(tt_common, |
| 1790 | struct batadv_tt_global_entry, |
| 1791 | common); |
| 1792 | |
| 1793 | if (!batadv_tt_global_to_purge(tt_global, &msg)) |
| 1794 | continue; |
| 1795 | |
| 1796 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 1797 | "Deleting global tt entry %pM (vid: %d): %s\n", |
| 1798 | tt_global->common.addr, |
| 1799 | BATADV_PRINT_VID(tt_global->common.vid), |
| 1800 | msg); |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1801 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1802 | hlist_del_rcu(&tt_common->hash_entry); |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1803 | |
| 1804 | batadv_tt_global_entry_free_ref(tt_global); |
| 1805 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1806 | spin_unlock_bh(list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1807 | } |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1808 | } |
| 1809 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1810 | static void batadv_tt_global_table_free(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1811 | { |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 1812 | struct batadv_hashtable *hash; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1813 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1814 | struct batadv_tt_common_entry *tt_common_entry; |
| 1815 | struct batadv_tt_global_entry *tt_global; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1816 | struct hlist_node *node_tmp; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1817 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1818 | uint32_t i; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1819 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1820 | if (!bat_priv->tt.global_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1821 | return; |
| 1822 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1823 | hash = bat_priv->tt.global_hash; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1824 | |
| 1825 | for (i = 0; i < hash->size; i++) { |
| 1826 | head = &hash->table[i]; |
| 1827 | list_lock = &hash->list_locks[i]; |
| 1828 | |
| 1829 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1830 | hlist_for_each_entry_safe(tt_common_entry, node_tmp, |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1831 | head, hash_entry) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1832 | hlist_del_rcu(&tt_common_entry->hash_entry); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1833 | tt_global = container_of(tt_common_entry, |
| 1834 | struct batadv_tt_global_entry, |
| 1835 | common); |
| 1836 | batadv_tt_global_entry_free_ref(tt_global); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1837 | } |
| 1838 | spin_unlock_bh(list_lock); |
| 1839 | } |
| 1840 | |
Sven Eckelmann | 1a8eaf0 | 2012-05-12 02:09:32 +0200 | [diff] [blame] | 1841 | batadv_hash_destroy(hash); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1842 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1843 | bat_priv->tt.global_hash = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1846 | static bool |
| 1847 | _batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry, |
| 1848 | struct batadv_tt_global_entry *tt_global_entry) |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 1849 | { |
| 1850 | bool ret = false; |
| 1851 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1852 | if (tt_local_entry->common.flags & BATADV_TT_CLIENT_WIFI && |
| 1853 | tt_global_entry->common.flags & BATADV_TT_CLIENT_WIFI) |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 1854 | ret = true; |
| 1855 | |
| 1856 | return ret; |
| 1857 | } |
| 1858 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1859 | /** |
| 1860 | * batadv_transtable_search - get the mesh destination for a given client |
| 1861 | * @bat_priv: the bat priv with all the soft interface information |
| 1862 | * @src: mac address of the source client |
| 1863 | * @addr: mac address of the destination client |
| 1864 | * @vid: VLAN identifier |
| 1865 | * |
| 1866 | * Returns a pointer to the originator that was selected as destination in the |
| 1867 | * mesh for contacting the client 'addr', NULL otherwise. |
| 1868 | * In case of multiple originators serving the same client, the function returns |
| 1869 | * the best one (best in terms of metric towards the destination node). |
| 1870 | * |
| 1871 | * If the two clients are AP isolated the function returns NULL. |
| 1872 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1873 | struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv, |
| 1874 | const uint8_t *src, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1875 | const uint8_t *addr, |
| 1876 | unsigned short vid) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1877 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1878 | struct batadv_tt_local_entry *tt_local_entry = NULL; |
| 1879 | struct batadv_tt_global_entry *tt_global_entry = NULL; |
| 1880 | struct batadv_orig_node *orig_node = NULL; |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1881 | struct batadv_tt_orig_list_entry *best_entry; |
Antonio Quartulli | b8cbd81 | 2013-07-02 11:04:36 +0200 | [diff] [blame] | 1882 | bool ap_isolation_enabled = false; |
| 1883 | struct batadv_softif_vlan *vlan; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1884 | |
Antonio Quartulli | b8cbd81 | 2013-07-02 11:04:36 +0200 | [diff] [blame] | 1885 | /* if the AP isolation is requested on a VLAN, then check for its |
| 1886 | * setting in the proper VLAN private data structure |
| 1887 | */ |
| 1888 | vlan = batadv_softif_vlan_get(bat_priv, vid); |
| 1889 | if (vlan) { |
| 1890 | ap_isolation_enabled = atomic_read(&vlan->ap_isolation); |
| 1891 | batadv_softif_vlan_free_ref(vlan); |
| 1892 | } |
| 1893 | |
| 1894 | if (src && ap_isolation_enabled) { |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1895 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid); |
Antonio Quartulli | 068ee6e | 2012-09-23 22:38:37 +0200 | [diff] [blame] | 1896 | if (!tt_local_entry || |
| 1897 | (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)) |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1898 | goto out; |
| 1899 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 1900 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1901 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 1902 | if (!tt_global_entry) |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1903 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1904 | |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1905 | /* check whether the clients should not communicate due to AP |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1906 | * isolation |
| 1907 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1908 | if (tt_local_entry && |
| 1909 | _batadv_is_ap_isolated(tt_local_entry, tt_global_entry)) |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1910 | goto out; |
| 1911 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1912 | rcu_read_lock(); |
Antonio Quartulli | 4627456 | 2013-09-03 11:10:24 +0200 | [diff] [blame] | 1913 | best_entry = batadv_transtable_best_orig(bat_priv, tt_global_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1914 | /* found anything? */ |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1915 | if (best_entry) |
| 1916 | orig_node = best_entry->orig_node; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1917 | if (orig_node && !atomic_inc_not_zero(&orig_node->refcount)) |
| 1918 | orig_node = NULL; |
| 1919 | rcu_read_unlock(); |
Sven Eckelmann | 981d890 | 2012-10-07 13:34:15 +0200 | [diff] [blame] | 1920 | |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1921 | out: |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1922 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1923 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1924 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1925 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1926 | |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1927 | return orig_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1928 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1929 | |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 1930 | /** |
| 1931 | * batadv_tt_global_crc - calculates the checksum of the local table belonging |
| 1932 | * to the given orig_node |
| 1933 | * @bat_priv: the bat priv with all the soft interface information |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 1934 | * @orig_node: originator for which the CRC should be computed |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1935 | * @vid: VLAN identifier for which the CRC32 has to be computed |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 1936 | * |
| 1937 | * This function computes the checksum for the global table corresponding to a |
| 1938 | * specific originator. In particular, the checksum is computed as follows: For |
| 1939 | * each client connected to the originator the CRC32C of the MAC address and the |
| 1940 | * VID is computed and then all the CRC32Cs of the various clients are xor'ed |
| 1941 | * together. |
| 1942 | * |
| 1943 | * The idea behind is that CRC32C should be used as much as possible in order to |
| 1944 | * produce a unique hash of the table, but since the order which is used to feed |
| 1945 | * the CRC32C function affects the result and since every node in the network |
| 1946 | * probably sorts the clients differently, the hash function cannot be directly |
| 1947 | * computed over the entire table. Hence the CRC32C is used only on |
| 1948 | * the single client entry, while all the results are then xor'ed together |
| 1949 | * because the XOR operation can combine them all while trying to reduce the |
| 1950 | * noise as much as possible. |
| 1951 | * |
| 1952 | * Returns the checksum of the global table of a given originator. |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 1953 | */ |
| 1954 | static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1955 | struct batadv_orig_node *orig_node, |
| 1956 | unsigned short vid) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1957 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1958 | struct batadv_hashtable *hash = bat_priv->tt.global_hash; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1959 | struct batadv_tt_common_entry *tt_common; |
| 1960 | struct batadv_tt_global_entry *tt_global; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1961 | struct hlist_head *head; |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 1962 | uint32_t i, crc_tmp, crc = 0; |
Antonio Quartulli | 0eb01568 | 2013-10-13 02:50:20 +0200 | [diff] [blame] | 1963 | uint8_t flags; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1964 | |
| 1965 | for (i = 0; i < hash->size; i++) { |
| 1966 | head = &hash->table[i]; |
| 1967 | |
| 1968 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1969 | hlist_for_each_entry_rcu(tt_common, head, hash_entry) { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1970 | tt_global = container_of(tt_common, |
| 1971 | struct batadv_tt_global_entry, |
| 1972 | common); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 1973 | /* compute the CRC only for entries belonging to the |
| 1974 | * VLAN identified by the vid passed as parameter |
| 1975 | */ |
| 1976 | if (tt_common->vid != vid) |
| 1977 | continue; |
| 1978 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1979 | /* Roaming clients are in the global table for |
| 1980 | * consistency only. They don't have to be |
| 1981 | * taken into account while computing the |
| 1982 | * global crc |
| 1983 | */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1984 | if (tt_common->flags & BATADV_TT_CLIENT_ROAM) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1985 | continue; |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 1986 | /* Temporary clients have not been announced yet, so |
| 1987 | * they have to be skipped while computing the global |
| 1988 | * crc |
| 1989 | */ |
| 1990 | if (tt_common->flags & BATADV_TT_CLIENT_TEMP) |
| 1991 | continue; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1992 | |
| 1993 | /* find out if this global entry is announced by this |
| 1994 | * originator |
| 1995 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1996 | if (!batadv_tt_global_entry_has_orig(tt_global, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 1997 | orig_node)) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1998 | continue; |
| 1999 | |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 2000 | crc_tmp = crc32c(0, &tt_common->vid, |
| 2001 | sizeof(tt_common->vid)); |
Antonio Quartulli | 0eb01568 | 2013-10-13 02:50:20 +0200 | [diff] [blame] | 2002 | |
| 2003 | /* compute the CRC on flags that have to be kept in sync |
| 2004 | * among nodes |
| 2005 | */ |
| 2006 | flags = tt_common->flags & BATADV_TT_SYNC_MASK; |
| 2007 | crc_tmp = crc32c(crc_tmp, &flags, sizeof(flags)); |
| 2008 | |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 2009 | crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2010 | } |
| 2011 | rcu_read_unlock(); |
| 2012 | } |
| 2013 | |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 2014 | return crc; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2015 | } |
| 2016 | |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 2017 | /** |
| 2018 | * batadv_tt_local_crc - calculates the checksum of the local table |
| 2019 | * @bat_priv: the bat priv with all the soft interface information |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2020 | * @vid: VLAN identifier for which the CRC32 has to be computed |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 2021 | * |
| 2022 | * For details about the computation, please refer to the documentation for |
| 2023 | * batadv_tt_global_crc(). |
| 2024 | * |
| 2025 | * Returns the checksum of the local table |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 2026 | */ |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2027 | static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv, |
| 2028 | unsigned short vid) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2029 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2030 | struct batadv_hashtable *hash = bat_priv->tt.local_hash; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2031 | struct batadv_tt_common_entry *tt_common; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2032 | struct hlist_head *head; |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 2033 | uint32_t i, crc_tmp, crc = 0; |
Antonio Quartulli | 0eb01568 | 2013-10-13 02:50:20 +0200 | [diff] [blame] | 2034 | uint8_t flags; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2035 | |
| 2036 | for (i = 0; i < hash->size; i++) { |
| 2037 | head = &hash->table[i]; |
| 2038 | |
| 2039 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2040 | hlist_for_each_entry_rcu(tt_common, head, hash_entry) { |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2041 | /* compute the CRC only for entries belonging to the |
| 2042 | * VLAN identified by vid |
| 2043 | */ |
| 2044 | if (tt_common->vid != vid) |
| 2045 | continue; |
| 2046 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2047 | /* not yet committed clients have not to be taken into |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2048 | * account while computing the CRC |
| 2049 | */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 2050 | if (tt_common->flags & BATADV_TT_CLIENT_NEW) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2051 | continue; |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 2052 | |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 2053 | crc_tmp = crc32c(0, &tt_common->vid, |
| 2054 | sizeof(tt_common->vid)); |
Antonio Quartulli | 0eb01568 | 2013-10-13 02:50:20 +0200 | [diff] [blame] | 2055 | |
| 2056 | /* compute the CRC on flags that have to be kept in sync |
| 2057 | * among nodes |
| 2058 | */ |
| 2059 | flags = tt_common->flags & BATADV_TT_SYNC_MASK; |
| 2060 | crc_tmp = crc32c(crc_tmp, &flags, sizeof(flags)); |
| 2061 | |
Antonio Quartulli | 0ffa9e8 | 2013-06-04 12:11:40 +0200 | [diff] [blame] | 2062 | crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2063 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2064 | rcu_read_unlock(); |
| 2065 | } |
| 2066 | |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 2067 | return crc; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2068 | } |
| 2069 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2070 | static void batadv_tt_req_list_free(struct batadv_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2071 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2072 | struct batadv_tt_req_node *node, *safe; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2073 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2074 | spin_lock_bh(&bat_priv->tt.req_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2075 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2076 | list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2077 | list_del(&node->list); |
| 2078 | kfree(node); |
| 2079 | } |
| 2080 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2081 | spin_unlock_bh(&bat_priv->tt.req_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2082 | } |
| 2083 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2084 | static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv, |
| 2085 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | e8cf234 | 2013-05-28 13:14:28 +0200 | [diff] [blame] | 2086 | const void *tt_buff, |
| 2087 | uint16_t tt_buff_len) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2088 | { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2089 | /* Replace the old buffer only if I received something in the |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2090 | * last OGM (the OGM could carry no changes) |
| 2091 | */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2092 | spin_lock_bh(&orig_node->tt_buff_lock); |
| 2093 | if (tt_buff_len > 0) { |
| 2094 | kfree(orig_node->tt_buff); |
| 2095 | orig_node->tt_buff_len = 0; |
| 2096 | orig_node->tt_buff = kmalloc(tt_buff_len, GFP_ATOMIC); |
| 2097 | if (orig_node->tt_buff) { |
| 2098 | memcpy(orig_node->tt_buff, tt_buff, tt_buff_len); |
| 2099 | orig_node->tt_buff_len = tt_buff_len; |
| 2100 | } |
| 2101 | } |
| 2102 | spin_unlock_bh(&orig_node->tt_buff_lock); |
| 2103 | } |
| 2104 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2105 | static void batadv_tt_req_purge(struct batadv_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2106 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2107 | struct batadv_tt_req_node *node, *safe; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2108 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2109 | spin_lock_bh(&bat_priv->tt.req_list_lock); |
| 2110 | list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) { |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 2111 | if (batadv_has_timed_out(node->issued_at, |
| 2112 | BATADV_TT_REQUEST_TIMEOUT)) { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2113 | list_del(&node->list); |
| 2114 | kfree(node); |
| 2115 | } |
| 2116 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2117 | spin_unlock_bh(&bat_priv->tt.req_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | /* returns the pointer to the new tt_req_node struct if no request |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2121 | * has already been issued for this orig_node, NULL otherwise |
| 2122 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2123 | static struct batadv_tt_req_node * |
| 2124 | batadv_new_tt_req_node(struct batadv_priv *bat_priv, |
| 2125 | struct batadv_orig_node *orig_node) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2126 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2127 | struct batadv_tt_req_node *tt_req_node_tmp, *tt_req_node = NULL; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2128 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2129 | spin_lock_bh(&bat_priv->tt.req_list_lock); |
| 2130 | list_for_each_entry(tt_req_node_tmp, &bat_priv->tt.req_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2131 | if (batadv_compare_eth(tt_req_node_tmp, orig_node) && |
| 2132 | !batadv_has_timed_out(tt_req_node_tmp->issued_at, |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 2133 | BATADV_TT_REQUEST_TIMEOUT)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2134 | goto unlock; |
| 2135 | } |
| 2136 | |
| 2137 | tt_req_node = kmalloc(sizeof(*tt_req_node), GFP_ATOMIC); |
| 2138 | if (!tt_req_node) |
| 2139 | goto unlock; |
| 2140 | |
| 2141 | memcpy(tt_req_node->addr, orig_node->orig, ETH_ALEN); |
| 2142 | tt_req_node->issued_at = jiffies; |
| 2143 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2144 | list_add(&tt_req_node->list, &bat_priv->tt.req_list); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2145 | unlock: |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2146 | spin_unlock_bh(&bat_priv->tt.req_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2147 | return tt_req_node; |
| 2148 | } |
| 2149 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2150 | /** |
| 2151 | * batadv_tt_local_valid - verify that given tt entry is a valid one |
| 2152 | * @entry_ptr: to be checked local tt entry |
| 2153 | * @data_ptr: not used but definition required to satisfy the callback prototype |
| 2154 | * |
| 2155 | * Returns 1 if the entry is a valid, 0 otherwise. |
| 2156 | */ |
| 2157 | static int batadv_tt_local_valid(const void *entry_ptr, const void *data_ptr) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2158 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2159 | const struct batadv_tt_common_entry *tt_common_entry = entry_ptr; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2160 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 2161 | if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2162 | return 0; |
| 2163 | return 1; |
| 2164 | } |
| 2165 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2166 | static int batadv_tt_global_valid(const void *entry_ptr, |
| 2167 | const void *data_ptr) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2168 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2169 | const struct batadv_tt_common_entry *tt_common_entry = entry_ptr; |
| 2170 | const struct batadv_tt_global_entry *tt_global_entry; |
| 2171 | const struct batadv_orig_node *orig_node = data_ptr; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2172 | |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 2173 | if (tt_common_entry->flags & BATADV_TT_CLIENT_ROAM || |
| 2174 | tt_common_entry->flags & BATADV_TT_CLIENT_TEMP) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2175 | return 0; |
| 2176 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2177 | tt_global_entry = container_of(tt_common_entry, |
| 2178 | struct batadv_tt_global_entry, |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2179 | common); |
| 2180 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2181 | return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2182 | } |
| 2183 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2184 | /** |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2185 | * batadv_tt_tvlv_generate - fill the tvlv buff with the tt entries from the |
| 2186 | * specified tt hash |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2187 | * @bat_priv: the bat priv with all the soft interface information |
| 2188 | * @hash: hash table containing the tt entries |
| 2189 | * @tt_len: expected tvlv tt data buffer length in number of bytes |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2190 | * @tvlv_buff: pointer to the buffer to fill with the TT data |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2191 | * @valid_cb: function to filter tt change entries |
| 2192 | * @cb_data: data passed to the filter function as argument |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2193 | */ |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2194 | static void batadv_tt_tvlv_generate(struct batadv_priv *bat_priv, |
| 2195 | struct batadv_hashtable *hash, |
| 2196 | void *tvlv_buff, uint16_t tt_len, |
| 2197 | int (*valid_cb)(const void *, const void *), |
| 2198 | void *cb_data) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2199 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2200 | struct batadv_tt_common_entry *tt_common_entry; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2201 | struct batadv_tvlv_tt_change *tt_change; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2202 | struct hlist_head *head; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2203 | uint16_t tt_tot, tt_num_entries = 0; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 2204 | uint32_t i; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2205 | |
Antonio Quartulli | 298e6e6 | 2013-05-28 13:14:27 +0200 | [diff] [blame] | 2206 | tt_tot = batadv_tt_entries(tt_len); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2207 | tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2208 | |
| 2209 | rcu_read_lock(); |
| 2210 | for (i = 0; i < hash->size; i++) { |
| 2211 | head = &hash->table[i]; |
| 2212 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2213 | hlist_for_each_entry_rcu(tt_common_entry, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2214 | head, hash_entry) { |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2215 | if (tt_tot == tt_num_entries) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2216 | break; |
| 2217 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2218 | if ((valid_cb) && (!valid_cb(tt_common_entry, cb_data))) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2219 | continue; |
| 2220 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2221 | memcpy(tt_change->addr, tt_common_entry->addr, |
| 2222 | ETH_ALEN); |
Antonio Quartulli | 27b37eb | 2012-11-08 14:21:11 +0100 | [diff] [blame] | 2223 | tt_change->flags = tt_common_entry->flags; |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 2224 | tt_change->vid = htons(tt_common_entry->vid); |
Antonio Quartulli | ca66304 | 2013-12-15 13:26:55 +0100 | [diff] [blame] | 2225 | memset(tt_change->reserved, 0, |
| 2226 | sizeof(tt_change->reserved)); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2227 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2228 | tt_num_entries++; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2229 | tt_change++; |
| 2230 | } |
| 2231 | } |
| 2232 | rcu_read_unlock(); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2233 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2234 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2235 | /** |
| 2236 | * batadv_tt_global_check_crc - check if all the CRCs are correct |
| 2237 | * @orig_node: originator for which the CRCs have to be checked |
| 2238 | * @tt_vlan: pointer to the first tvlv VLAN entry |
| 2239 | * @num_vlan: number of tvlv VLAN entries |
| 2240 | * @create: if true, create VLAN objects if not found |
| 2241 | * |
| 2242 | * Return true if all the received CRCs match the locally stored ones, false |
| 2243 | * otherwise |
| 2244 | */ |
| 2245 | static bool batadv_tt_global_check_crc(struct batadv_orig_node *orig_node, |
| 2246 | struct batadv_tvlv_tt_vlan_data *tt_vlan, |
| 2247 | uint16_t num_vlan) |
| 2248 | { |
| 2249 | struct batadv_tvlv_tt_vlan_data *tt_vlan_tmp; |
| 2250 | struct batadv_orig_node_vlan *vlan; |
| 2251 | int i; |
| 2252 | |
| 2253 | /* check if each received CRC matches the locally stored one */ |
| 2254 | for (i = 0; i < num_vlan; i++) { |
| 2255 | tt_vlan_tmp = tt_vlan + i; |
| 2256 | |
| 2257 | /* if orig_node is a backbone node for this VLAN, don't check |
| 2258 | * the CRC as we ignore all the global entries over it |
| 2259 | */ |
| 2260 | if (batadv_bla_is_backbone_gw_orig(orig_node->bat_priv, |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 2261 | orig_node->orig, |
| 2262 | ntohs(tt_vlan_tmp->vid))) |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2263 | continue; |
| 2264 | |
| 2265 | vlan = batadv_orig_node_vlan_get(orig_node, |
| 2266 | ntohs(tt_vlan_tmp->vid)); |
| 2267 | if (!vlan) |
| 2268 | return false; |
| 2269 | |
| 2270 | if (vlan->tt.crc != ntohl(tt_vlan_tmp->crc)) |
| 2271 | return false; |
| 2272 | } |
| 2273 | |
| 2274 | return true; |
| 2275 | } |
| 2276 | |
| 2277 | /** |
| 2278 | * batadv_tt_local_update_crc - update all the local CRCs |
| 2279 | * @bat_priv: the bat priv with all the soft interface information |
| 2280 | */ |
| 2281 | static void batadv_tt_local_update_crc(struct batadv_priv *bat_priv) |
| 2282 | { |
| 2283 | struct batadv_softif_vlan *vlan; |
| 2284 | |
| 2285 | /* recompute the global CRC for each VLAN */ |
| 2286 | rcu_read_lock(); |
| 2287 | hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) { |
| 2288 | vlan->tt.crc = batadv_tt_local_crc(bat_priv, vlan->vid); |
| 2289 | } |
| 2290 | rcu_read_unlock(); |
| 2291 | } |
| 2292 | |
| 2293 | /** |
| 2294 | * batadv_tt_global_update_crc - update all the global CRCs for this orig_node |
| 2295 | * @bat_priv: the bat priv with all the soft interface information |
| 2296 | * @orig_node: the orig_node for which the CRCs have to be updated |
| 2297 | */ |
| 2298 | static void batadv_tt_global_update_crc(struct batadv_priv *bat_priv, |
| 2299 | struct batadv_orig_node *orig_node) |
| 2300 | { |
| 2301 | struct batadv_orig_node_vlan *vlan; |
| 2302 | uint32_t crc; |
| 2303 | |
| 2304 | /* recompute the global CRC for each VLAN */ |
| 2305 | rcu_read_lock(); |
| 2306 | list_for_each_entry_rcu(vlan, &orig_node->vlan_list, list) { |
| 2307 | /* if orig_node is a backbone node for this VLAN, don't compute |
| 2308 | * the CRC as we ignore all the global entries over it |
| 2309 | */ |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 2310 | if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig, |
| 2311 | vlan->vid)) |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2312 | continue; |
| 2313 | |
| 2314 | crc = batadv_tt_global_crc(bat_priv, orig_node, vlan->vid); |
| 2315 | vlan->tt.crc = crc; |
| 2316 | } |
| 2317 | rcu_read_unlock(); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2318 | } |
| 2319 | |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 2320 | /** |
| 2321 | * batadv_send_tt_request - send a TT Request message to a given node |
| 2322 | * @bat_priv: the bat priv with all the soft interface information |
| 2323 | * @dst_orig_node: the destination of the message |
| 2324 | * @ttvn: the version number that the source of the message is looking for |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2325 | * @tt_vlan: pointer to the first tvlv VLAN object to request |
| 2326 | * @num_vlan: number of tvlv VLAN entries |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 2327 | * @full_table: ask for the entire translation table if true, while only for the |
| 2328 | * last TT diff otherwise |
| 2329 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2330 | static int batadv_send_tt_request(struct batadv_priv *bat_priv, |
| 2331 | struct batadv_orig_node *dst_orig_node, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2332 | uint8_t ttvn, |
| 2333 | struct batadv_tvlv_tt_vlan_data *tt_vlan, |
| 2334 | uint16_t num_vlan, bool full_table) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2335 | { |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2336 | struct batadv_tvlv_tt_data *tvlv_tt_data = NULL; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2337 | struct batadv_tt_req_node *tt_req_node = NULL; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2338 | struct batadv_tvlv_tt_vlan_data *tt_vlan_req; |
| 2339 | struct batadv_hard_iface *primary_if; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2340 | bool ret = false; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2341 | int i, size; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2342 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 2343 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2344 | if (!primary_if) |
| 2345 | goto out; |
| 2346 | |
| 2347 | /* The new tt_req will be issued only if I'm not waiting for a |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2348 | * reply from the same orig_node yet |
| 2349 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2350 | tt_req_node = batadv_new_tt_req_node(bat_priv, dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2351 | if (!tt_req_node) |
| 2352 | goto out; |
| 2353 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2354 | size = sizeof(*tvlv_tt_data) + sizeof(*tt_vlan_req) * num_vlan; |
| 2355 | tvlv_tt_data = kzalloc(size, GFP_ATOMIC); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2356 | if (!tvlv_tt_data) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2357 | goto out; |
| 2358 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2359 | tvlv_tt_data->flags = BATADV_TT_REQUEST; |
| 2360 | tvlv_tt_data->ttvn = ttvn; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2361 | tvlv_tt_data->num_vlan = htons(num_vlan); |
| 2362 | |
| 2363 | /* send all the CRCs within the request. This is needed by intermediate |
| 2364 | * nodes to ensure they have the correct table before replying |
| 2365 | */ |
| 2366 | tt_vlan_req = (struct batadv_tvlv_tt_vlan_data *)(tvlv_tt_data + 1); |
| 2367 | for (i = 0; i < num_vlan; i++) { |
| 2368 | tt_vlan_req->vid = tt_vlan->vid; |
| 2369 | tt_vlan_req->crc = tt_vlan->crc; |
| 2370 | |
| 2371 | tt_vlan_req++; |
| 2372 | tt_vlan++; |
| 2373 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2374 | |
| 2375 | if (full_table) |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2376 | tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2377 | |
Martin Hundebøll | bb351ba | 2012-10-16 16:13:48 +0200 | [diff] [blame] | 2378 | batadv_dbg(BATADV_DBG_TT, bat_priv, "Sending TT_REQUEST to %pM [%c]\n", |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2379 | dst_orig_node->orig, full_table ? 'F' : '.'); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2380 | |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 2381 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_TX); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2382 | batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr, |
| 2383 | dst_orig_node->orig, BATADV_TVLV_TT, 1, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2384 | tvlv_tt_data, size); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2385 | ret = true; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2386 | |
| 2387 | out: |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2388 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 2389 | batadv_hardif_free_ref(primary_if); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2390 | if (ret && tt_req_node) { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2391 | spin_lock_bh(&bat_priv->tt.req_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2392 | list_del(&tt_req_node->list); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2393 | spin_unlock_bh(&bat_priv->tt.req_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2394 | kfree(tt_req_node); |
| 2395 | } |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2396 | kfree(tvlv_tt_data); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2397 | return ret; |
| 2398 | } |
| 2399 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2400 | /** |
| 2401 | * batadv_send_other_tt_response - send reply to tt request concerning another |
| 2402 | * node's translation table |
| 2403 | * @bat_priv: the bat priv with all the soft interface information |
| 2404 | * @tt_data: tt data containing the tt request information |
| 2405 | * @req_src: mac address of tt request sender |
| 2406 | * @req_dst: mac address of tt request recipient |
| 2407 | * |
| 2408 | * Returns true if tt request reply was sent, false otherwise. |
| 2409 | */ |
| 2410 | static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv, |
| 2411 | struct batadv_tvlv_tt_data *tt_data, |
| 2412 | uint8_t *req_src, uint8_t *req_dst) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2413 | { |
Sven Eckelmann | 170173b | 2012-10-07 12:02:22 +0200 | [diff] [blame] | 2414 | struct batadv_orig_node *req_dst_orig_node; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2415 | struct batadv_orig_node *res_dst_orig_node = NULL; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2416 | struct batadv_tvlv_tt_change *tt_change; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2417 | struct batadv_tvlv_tt_data *tvlv_tt_data = NULL; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2418 | struct batadv_tvlv_tt_vlan_data *tt_vlan; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2419 | bool ret = false, full_table; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2420 | uint8_t orig_ttvn, req_ttvn; |
| 2421 | uint16_t tvlv_len; |
| 2422 | int32_t tt_len; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2423 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 2424 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2425 | "Received TT_REQUEST from %pM for ttvn: %u (%pM) [%c]\n", |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2426 | req_src, tt_data->ttvn, req_dst, |
| 2427 | (tt_data->flags & BATADV_TT_FULL_TABLE ? 'F' : '.')); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2428 | |
| 2429 | /* Let's get the orig node of the REAL destination */ |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2430 | req_dst_orig_node = batadv_orig_hash_find(bat_priv, req_dst); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2431 | if (!req_dst_orig_node) |
| 2432 | goto out; |
| 2433 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2434 | res_dst_orig_node = batadv_orig_hash_find(bat_priv, req_src); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2435 | if (!res_dst_orig_node) |
| 2436 | goto out; |
| 2437 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2438 | orig_ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2439 | req_ttvn = tt_data->ttvn; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2440 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2441 | tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2442 | /* this node doesn't have the requested data */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2443 | if (orig_ttvn != req_ttvn || |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2444 | !batadv_tt_global_check_crc(req_dst_orig_node, tt_vlan, |
| 2445 | ntohs(tt_data->num_vlan))) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2446 | goto out; |
| 2447 | |
Antonio Quartulli | 015758d | 2011-07-09 17:52:13 +0200 | [diff] [blame] | 2448 | /* If the full table has been explicitly requested */ |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2449 | if (tt_data->flags & BATADV_TT_FULL_TABLE || |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2450 | !req_dst_orig_node->tt_buff) |
| 2451 | full_table = true; |
| 2452 | else |
| 2453 | full_table = false; |
| 2454 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2455 | /* TT fragmentation hasn't been implemented yet, so send as many |
| 2456 | * TT entries fit a single packet as possible only |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2457 | */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2458 | if (!full_table) { |
| 2459 | spin_lock_bh(&req_dst_orig_node->tt_buff_lock); |
| 2460 | tt_len = req_dst_orig_node->tt_buff_len; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2461 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2462 | tvlv_len = batadv_tt_prepare_tvlv_global_data(req_dst_orig_node, |
| 2463 | &tvlv_tt_data, |
| 2464 | &tt_change, |
| 2465 | &tt_len); |
| 2466 | if (!tt_len) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2467 | goto unlock; |
| 2468 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2469 | /* Copy the last orig_node's OGM buffer */ |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2470 | memcpy(tt_change, req_dst_orig_node->tt_buff, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2471 | req_dst_orig_node->tt_buff_len); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2472 | spin_unlock_bh(&req_dst_orig_node->tt_buff_lock); |
| 2473 | } else { |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2474 | /* allocate the tvlv, put the tt_data and all the tt_vlan_data |
| 2475 | * in the initial part |
| 2476 | */ |
| 2477 | tt_len = -1; |
| 2478 | tvlv_len = batadv_tt_prepare_tvlv_global_data(req_dst_orig_node, |
| 2479 | &tvlv_tt_data, |
| 2480 | &tt_change, |
| 2481 | &tt_len); |
| 2482 | if (!tt_len) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2483 | goto out; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2484 | |
| 2485 | /* fill the rest of the tvlv with the real TT entries */ |
| 2486 | batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.global_hash, |
| 2487 | tt_change, tt_len, |
| 2488 | batadv_tt_global_valid, |
| 2489 | req_dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2490 | } |
| 2491 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 2492 | /* Don't send the response, if larger than fragmented packet. */ |
| 2493 | tt_len = sizeof(struct batadv_unicast_tvlv_packet) + tvlv_len; |
| 2494 | if (tt_len > atomic_read(&bat_priv->packet_size_max)) { |
| 2495 | net_ratelimited_function(batadv_info, bat_priv->soft_iface, |
| 2496 | "Ignoring TT_REQUEST from %pM; Response size exceeds max packet size.\n", |
| 2497 | res_dst_orig_node->orig); |
| 2498 | goto out; |
| 2499 | } |
| 2500 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2501 | tvlv_tt_data->flags = BATADV_TT_RESPONSE; |
| 2502 | tvlv_tt_data->ttvn = req_ttvn; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2503 | |
| 2504 | if (full_table) |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2505 | tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2506 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 2507 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2508 | "Sending TT_RESPONSE %pM for %pM [%c] (ttvn: %u)\n", |
| 2509 | res_dst_orig_node->orig, req_dst_orig_node->orig, |
| 2510 | full_table ? 'F' : '.', req_ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2511 | |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 2512 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 2513 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2514 | batadv_tvlv_unicast_send(bat_priv, req_dst_orig_node->orig, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2515 | req_src, BATADV_TVLV_TT, 1, tvlv_tt_data, |
| 2516 | tvlv_len); |
Martin Hundebøll | e91ecfc | 2013-04-20 13:54:39 +0200 | [diff] [blame] | 2517 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2518 | ret = true; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2519 | goto out; |
| 2520 | |
| 2521 | unlock: |
| 2522 | spin_unlock_bh(&req_dst_orig_node->tt_buff_lock); |
| 2523 | |
| 2524 | out: |
| 2525 | if (res_dst_orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 2526 | batadv_orig_node_free_ref(res_dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2527 | if (req_dst_orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 2528 | batadv_orig_node_free_ref(req_dst_orig_node); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2529 | kfree(tvlv_tt_data); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2530 | return ret; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2531 | } |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 2532 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2533 | /** |
| 2534 | * batadv_send_my_tt_response - send reply to tt request concerning this node's |
| 2535 | * translation table |
| 2536 | * @bat_priv: the bat priv with all the soft interface information |
| 2537 | * @tt_data: tt data containing the tt request information |
| 2538 | * @req_src: mac address of tt request sender |
| 2539 | * |
| 2540 | * Returns true if tt request reply was sent, false otherwise. |
| 2541 | */ |
| 2542 | static bool batadv_send_my_tt_response(struct batadv_priv *bat_priv, |
| 2543 | struct batadv_tvlv_tt_data *tt_data, |
| 2544 | uint8_t *req_src) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2545 | { |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2546 | struct batadv_tvlv_tt_data *tvlv_tt_data = NULL; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2547 | struct batadv_hard_iface *primary_if = NULL; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2548 | struct batadv_tvlv_tt_change *tt_change; |
| 2549 | struct batadv_orig_node *orig_node; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2550 | uint8_t my_ttvn, req_ttvn; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2551 | uint16_t tvlv_len; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2552 | bool full_table; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2553 | int32_t tt_len; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2554 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 2555 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2556 | "Received TT_REQUEST from %pM for ttvn: %u (me) [%c]\n", |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2557 | req_src, tt_data->ttvn, |
| 2558 | (tt_data->flags & BATADV_TT_FULL_TABLE ? 'F' : '.')); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2559 | |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 2560 | spin_lock_bh(&bat_priv->tt.commit_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2561 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2562 | my_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2563 | req_ttvn = tt_data->ttvn; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2564 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2565 | orig_node = batadv_orig_hash_find(bat_priv, req_src); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2566 | if (!orig_node) |
| 2567 | goto out; |
| 2568 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 2569 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2570 | if (!primary_if) |
| 2571 | goto out; |
| 2572 | |
| 2573 | /* If the full table has been explicitly requested or the gap |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2574 | * is too big send the whole local translation table |
| 2575 | */ |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2576 | if (tt_data->flags & BATADV_TT_FULL_TABLE || my_ttvn != req_ttvn || |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2577 | !bat_priv->tt.last_changeset) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2578 | full_table = true; |
| 2579 | else |
| 2580 | full_table = false; |
| 2581 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2582 | /* TT fragmentation hasn't been implemented yet, so send as many |
| 2583 | * TT entries fit a single packet as possible only |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2584 | */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2585 | if (!full_table) { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2586 | spin_lock_bh(&bat_priv->tt.last_changeset_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2587 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2588 | tt_len = bat_priv->tt.last_changeset_len; |
| 2589 | tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv, |
| 2590 | &tvlv_tt_data, |
| 2591 | &tt_change, |
| 2592 | &tt_len); |
| 2593 | if (!tt_len) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2594 | goto unlock; |
| 2595 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2596 | /* Copy the last orig_node's OGM buffer */ |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2597 | memcpy(tt_change, bat_priv->tt.last_changeset, |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2598 | bat_priv->tt.last_changeset_len); |
| 2599 | spin_unlock_bh(&bat_priv->tt.last_changeset_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2600 | } else { |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2601 | req_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2602 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2603 | /* allocate the tvlv, put the tt_data and all the tt_vlan_data |
| 2604 | * in the initial part |
| 2605 | */ |
| 2606 | tt_len = -1; |
| 2607 | tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv, |
| 2608 | &tvlv_tt_data, |
| 2609 | &tt_change, |
| 2610 | &tt_len); |
| 2611 | if (!tt_len) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2612 | goto out; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2613 | |
| 2614 | /* fill the rest of the tvlv with the real TT entries */ |
| 2615 | batadv_tt_tvlv_generate(bat_priv, bat_priv->tt.local_hash, |
| 2616 | tt_change, tt_len, |
| 2617 | batadv_tt_local_valid, NULL); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2618 | } |
| 2619 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2620 | tvlv_tt_data->flags = BATADV_TT_RESPONSE; |
| 2621 | tvlv_tt_data->ttvn = req_ttvn; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2622 | |
| 2623 | if (full_table) |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2624 | tvlv_tt_data->flags |= BATADV_TT_FULL_TABLE; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2625 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 2626 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2627 | "Sending TT_RESPONSE to %pM [%c] (ttvn: %u)\n", |
| 2628 | orig_node->orig, full_table ? 'F' : '.', req_ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2629 | |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 2630 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 2631 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2632 | batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2633 | req_src, BATADV_TVLV_TT, 1, tvlv_tt_data, |
| 2634 | tvlv_len); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2635 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2636 | goto out; |
| 2637 | |
| 2638 | unlock: |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2639 | spin_unlock_bh(&bat_priv->tt.last_changeset_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2640 | out: |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 2641 | spin_unlock_bh(&bat_priv->tt.commit_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2642 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 2643 | batadv_orig_node_free_ref(orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2644 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 2645 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2646 | kfree(tvlv_tt_data); |
| 2647 | /* The packet was for this host, so it doesn't need to be re-routed */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2648 | return true; |
| 2649 | } |
| 2650 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2651 | /** |
| 2652 | * batadv_send_tt_response - send reply to tt request |
| 2653 | * @bat_priv: the bat priv with all the soft interface information |
| 2654 | * @tt_data: tt data containing the tt request information |
| 2655 | * @req_src: mac address of tt request sender |
| 2656 | * @req_dst: mac address of tt request recipient |
| 2657 | * |
| 2658 | * Returns true if tt request reply was sent, false otherwise. |
| 2659 | */ |
| 2660 | static bool batadv_send_tt_response(struct batadv_priv *bat_priv, |
| 2661 | struct batadv_tvlv_tt_data *tt_data, |
| 2662 | uint8_t *req_src, uint8_t *req_dst) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2663 | { |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 2664 | if (batadv_is_my_mac(bat_priv, req_dst)) |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2665 | return batadv_send_my_tt_response(bat_priv, tt_data, req_src); |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 2666 | else |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2667 | return batadv_send_other_tt_response(bat_priv, tt_data, |
| 2668 | req_src, req_dst); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2669 | } |
| 2670 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2671 | static void _batadv_tt_update_changes(struct batadv_priv *bat_priv, |
| 2672 | struct batadv_orig_node *orig_node, |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2673 | struct batadv_tvlv_tt_change *tt_change, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2674 | uint16_t tt_num_changes, uint8_t ttvn) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2675 | { |
| 2676 | int i; |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2677 | int roams; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2678 | |
| 2679 | for (i = 0; i < tt_num_changes; i++) { |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 2680 | if ((tt_change + i)->flags & BATADV_TT_CLIENT_DEL) { |
| 2681 | roams = (tt_change + i)->flags & BATADV_TT_CLIENT_ROAM; |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2682 | batadv_tt_global_del(bat_priv, orig_node, |
| 2683 | (tt_change + i)->addr, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 2684 | ntohs((tt_change + i)->vid), |
Antonio Quartulli | d4f4469 | 2012-05-25 00:00:54 +0200 | [diff] [blame] | 2685 | "tt removed by changes", |
| 2686 | roams); |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 2687 | } else { |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 2688 | if (!batadv_tt_global_add(bat_priv, orig_node, |
Antonio Quartulli | d4f4469 | 2012-05-25 00:00:54 +0200 | [diff] [blame] | 2689 | (tt_change + i)->addr, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 2690 | ntohs((tt_change + i)->vid), |
Antonio Quartulli | d4f4469 | 2012-05-25 00:00:54 +0200 | [diff] [blame] | 2691 | (tt_change + i)->flags, ttvn)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2692 | /* In case of problem while storing a |
| 2693 | * global_entry, we stop the updating |
| 2694 | * procedure without committing the |
| 2695 | * ttvn change. This will avoid to send |
| 2696 | * corrupted data on tt_request |
| 2697 | */ |
| 2698 | return; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 2699 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2700 | } |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 2701 | orig_node->tt_initialised = true; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2702 | } |
| 2703 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2704 | static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2705 | struct batadv_tvlv_tt_change *tt_change, |
| 2706 | uint8_t ttvn, uint8_t *resp_src, |
| 2707 | uint16_t num_entries) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2708 | { |
Sven Eckelmann | 170173b | 2012-10-07 12:02:22 +0200 | [diff] [blame] | 2709 | struct batadv_orig_node *orig_node; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2710 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2711 | orig_node = batadv_orig_hash_find(bat_priv, resp_src); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2712 | if (!orig_node) |
| 2713 | goto out; |
| 2714 | |
| 2715 | /* Purge the old table first.. */ |
Antonio Quartulli | 95fb130 | 2013-08-07 18:28:55 +0200 | [diff] [blame] | 2716 | batadv_tt_global_del_orig(bat_priv, orig_node, -1, |
| 2717 | "Received full table"); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2718 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2719 | _batadv_tt_update_changes(bat_priv, orig_node, tt_change, num_entries, |
| 2720 | ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2721 | |
| 2722 | spin_lock_bh(&orig_node->tt_buff_lock); |
| 2723 | kfree(orig_node->tt_buff); |
| 2724 | orig_node->tt_buff_len = 0; |
| 2725 | orig_node->tt_buff = NULL; |
| 2726 | spin_unlock_bh(&orig_node->tt_buff_lock); |
| 2727 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2728 | atomic_set(&orig_node->last_ttvn, ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2729 | |
| 2730 | out: |
| 2731 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 2732 | batadv_orig_node_free_ref(orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2733 | } |
| 2734 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2735 | static void batadv_tt_update_changes(struct batadv_priv *bat_priv, |
| 2736 | struct batadv_orig_node *orig_node, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2737 | uint16_t tt_num_changes, uint8_t ttvn, |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2738 | struct batadv_tvlv_tt_change *tt_change) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2739 | { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2740 | _batadv_tt_update_changes(bat_priv, orig_node, tt_change, |
| 2741 | tt_num_changes, ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2742 | |
Antonio Quartulli | e8cf234 | 2013-05-28 13:14:28 +0200 | [diff] [blame] | 2743 | batadv_tt_save_orig_buffer(bat_priv, orig_node, tt_change, |
| 2744 | batadv_tt_len(tt_num_changes)); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2745 | atomic_set(&orig_node->last_ttvn, ttvn); |
| 2746 | } |
| 2747 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 2748 | /** |
| 2749 | * batadv_is_my_client - check if a client is served by the local node |
| 2750 | * @bat_priv: the bat priv with all the soft interface information |
| 2751 | * @addr: the mac adress of the client to check |
| 2752 | * @vid: VLAN identifier |
| 2753 | * |
| 2754 | * Returns true if the client is served by this node, false otherwise. |
| 2755 | */ |
| 2756 | bool batadv_is_my_client(struct batadv_priv *bat_priv, const uint8_t *addr, |
| 2757 | unsigned short vid) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2758 | { |
Sven Eckelmann | 170173b | 2012-10-07 12:02:22 +0200 | [diff] [blame] | 2759 | struct batadv_tt_local_entry *tt_local_entry; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 2760 | bool ret = false; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2761 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 2762 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 2763 | if (!tt_local_entry) |
| 2764 | goto out; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2765 | /* Check if the client has been logically deleted (but is kept for |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2766 | * consistency purpose) |
| 2767 | */ |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 2768 | if ((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) || |
| 2769 | (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM)) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2770 | goto out; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 2771 | ret = true; |
| 2772 | out: |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2773 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2774 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 2775 | return ret; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2776 | } |
| 2777 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2778 | /** |
| 2779 | * batadv_handle_tt_response - process incoming tt reply |
| 2780 | * @bat_priv: the bat priv with all the soft interface information |
| 2781 | * @tt_data: tt data containing the tt request information |
| 2782 | * @resp_src: mac address of tt reply sender |
| 2783 | * @num_entries: number of tt change entries appended to the tt data |
| 2784 | */ |
| 2785 | static void batadv_handle_tt_response(struct batadv_priv *bat_priv, |
| 2786 | struct batadv_tvlv_tt_data *tt_data, |
| 2787 | uint8_t *resp_src, uint16_t num_entries) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2788 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2789 | struct batadv_tt_req_node *node, *safe; |
| 2790 | struct batadv_orig_node *orig_node = NULL; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2791 | struct batadv_tvlv_tt_change *tt_change; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2792 | uint8_t *tvlv_ptr = (uint8_t *)tt_data; |
| 2793 | uint16_t change_offset; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2794 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 2795 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2796 | "Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n", |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2797 | resp_src, tt_data->ttvn, num_entries, |
| 2798 | (tt_data->flags & BATADV_TT_FULL_TABLE ? 'F' : '.')); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2799 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2800 | orig_node = batadv_orig_hash_find(bat_priv, resp_src); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2801 | if (!orig_node) |
| 2802 | goto out; |
| 2803 | |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 2804 | spin_lock_bh(&orig_node->tt_lock); |
| 2805 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2806 | change_offset = sizeof(struct batadv_tvlv_tt_vlan_data); |
| 2807 | change_offset *= ntohs(tt_data->num_vlan); |
| 2808 | change_offset += sizeof(*tt_data); |
| 2809 | tvlv_ptr += change_offset; |
| 2810 | |
| 2811 | tt_change = (struct batadv_tvlv_tt_change *)tvlv_ptr; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2812 | if (tt_data->flags & BATADV_TT_FULL_TABLE) { |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2813 | batadv_tt_fill_gtable(bat_priv, tt_change, tt_data->ttvn, |
| 2814 | resp_src, num_entries); |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 2815 | } else { |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2816 | batadv_tt_update_changes(bat_priv, orig_node, num_entries, |
| 2817 | tt_data->ttvn, tt_change); |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 2818 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2819 | |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 2820 | /* Recalculate the CRC for this orig_node and store it */ |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2821 | batadv_tt_global_update_crc(bat_priv, orig_node); |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 2822 | |
| 2823 | spin_unlock_bh(&orig_node->tt_lock); |
| 2824 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2825 | /* Delete the tt_req_node from pending tt_requests list */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2826 | spin_lock_bh(&bat_priv->tt.req_list_lock); |
| 2827 | list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) { |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 2828 | if (!batadv_compare_eth(node->addr, resp_src)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2829 | continue; |
| 2830 | list_del(&node->list); |
| 2831 | kfree(node); |
| 2832 | } |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 2833 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2834 | spin_unlock_bh(&bat_priv->tt.req_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2835 | out: |
| 2836 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 2837 | batadv_orig_node_free_ref(orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2838 | } |
| 2839 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2840 | static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2841 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2842 | struct batadv_tt_roam_node *node, *safe; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2843 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2844 | spin_lock_bh(&bat_priv->tt.roam_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2845 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2846 | list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) { |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2847 | list_del(&node->list); |
| 2848 | kfree(node); |
| 2849 | } |
| 2850 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2851 | spin_unlock_bh(&bat_priv->tt.roam_list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2852 | } |
| 2853 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2854 | static void batadv_tt_roam_purge(struct batadv_priv *bat_priv) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2855 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2856 | struct batadv_tt_roam_node *node, *safe; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2857 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2858 | spin_lock_bh(&bat_priv->tt.roam_list_lock); |
| 2859 | list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) { |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 2860 | if (!batadv_has_timed_out(node->first_time, |
| 2861 | BATADV_ROAMING_MAX_TIME)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2862 | continue; |
| 2863 | |
| 2864 | list_del(&node->list); |
| 2865 | kfree(node); |
| 2866 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2867 | spin_unlock_bh(&bat_priv->tt.roam_list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | /* This function checks whether the client already reached the |
| 2871 | * maximum number of possible roaming phases. In this case the ROAMING_ADV |
| 2872 | * will not be sent. |
| 2873 | * |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2874 | * returns true if the ROAMING_ADV can be sent, false otherwise |
| 2875 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2876 | static bool batadv_tt_check_roam_count(struct batadv_priv *bat_priv, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2877 | uint8_t *client) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2878 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2879 | struct batadv_tt_roam_node *tt_roam_node; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2880 | bool ret = false; |
| 2881 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2882 | spin_lock_bh(&bat_priv->tt.roam_list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2883 | /* The new tt_req will be issued only if I'm not waiting for a |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2884 | * reply from the same orig_node yet |
| 2885 | */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2886 | list_for_each_entry(tt_roam_node, &bat_priv->tt.roam_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2887 | if (!batadv_compare_eth(tt_roam_node->addr, client)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2888 | continue; |
| 2889 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2890 | if (batadv_has_timed_out(tt_roam_node->first_time, |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 2891 | BATADV_ROAMING_MAX_TIME)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2892 | continue; |
| 2893 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 2894 | if (!batadv_atomic_dec_not_zero(&tt_roam_node->counter)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2895 | /* Sorry, you roamed too many times! */ |
| 2896 | goto unlock; |
| 2897 | ret = true; |
| 2898 | break; |
| 2899 | } |
| 2900 | |
| 2901 | if (!ret) { |
| 2902 | tt_roam_node = kmalloc(sizeof(*tt_roam_node), GFP_ATOMIC); |
| 2903 | if (!tt_roam_node) |
| 2904 | goto unlock; |
| 2905 | |
| 2906 | tt_roam_node->first_time = jiffies; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 2907 | atomic_set(&tt_roam_node->counter, |
| 2908 | BATADV_ROAMING_MAX_COUNT - 1); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2909 | memcpy(tt_roam_node->addr, client, ETH_ALEN); |
| 2910 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2911 | list_add(&tt_roam_node->list, &bat_priv->tt.roam_list); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2912 | ret = true; |
| 2913 | } |
| 2914 | |
| 2915 | unlock: |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2916 | spin_unlock_bh(&bat_priv->tt.roam_list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2917 | return ret; |
| 2918 | } |
| 2919 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 2920 | /** |
| 2921 | * batadv_send_roam_adv - send a roaming advertisement message |
| 2922 | * @bat_priv: the bat priv with all the soft interface information |
| 2923 | * @client: mac address of the roaming client |
| 2924 | * @vid: VLAN identifier |
| 2925 | * @orig_node: message destination |
| 2926 | * |
| 2927 | * Send a ROAMING_ADV message to the node which was previously serving this |
| 2928 | * client. This is done to inform the node that from now on all traffic destined |
| 2929 | * for this particular roamed client has to be forwarded to the sender of the |
| 2930 | * roaming message. |
| 2931 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2932 | static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 2933 | unsigned short vid, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2934 | struct batadv_orig_node *orig_node) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2935 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2936 | struct batadv_hard_iface *primary_if; |
Marek Lindner | 122edaa | 2013-04-23 21:40:03 +0800 | [diff] [blame] | 2937 | struct batadv_tvlv_roam_adv tvlv_roam; |
| 2938 | |
| 2939 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 2940 | if (!primary_if) |
| 2941 | goto out; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2942 | |
| 2943 | /* before going on we have to check whether the client has |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2944 | * already roamed to us too many times |
| 2945 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2946 | if (!batadv_tt_check_roam_count(bat_priv, client)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2947 | goto out; |
| 2948 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 2949 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 2950 | "Sending ROAMING_ADV to %pM (client %pM, vid: %d)\n", |
| 2951 | orig_node->orig, client, BATADV_PRINT_VID(vid)); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2952 | |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 2953 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 2954 | |
Marek Lindner | 122edaa | 2013-04-23 21:40:03 +0800 | [diff] [blame] | 2955 | memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client)); |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 2956 | tvlv_roam.vid = htons(vid); |
Marek Lindner | 122edaa | 2013-04-23 21:40:03 +0800 | [diff] [blame] | 2957 | |
| 2958 | batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr, |
| 2959 | orig_node->orig, BATADV_TVLV_ROAM, 1, |
| 2960 | &tvlv_roam, sizeof(tvlv_roam)); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2961 | |
| 2962 | out: |
Marek Lindner | 122edaa | 2013-04-23 21:40:03 +0800 | [diff] [blame] | 2963 | if (primary_if) |
| 2964 | batadv_hardif_free_ref(primary_if); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2965 | } |
| 2966 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2967 | static void batadv_tt_purge(struct work_struct *work) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2968 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2969 | struct delayed_work *delayed_work; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2970 | struct batadv_priv_tt *priv_tt; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2971 | struct batadv_priv *bat_priv; |
| 2972 | |
| 2973 | delayed_work = container_of(work, struct delayed_work, work); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2974 | priv_tt = container_of(delayed_work, struct batadv_priv_tt, work); |
| 2975 | bat_priv = container_of(priv_tt, struct batadv_priv, tt); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2976 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 2977 | batadv_tt_local_purge(bat_priv, BATADV_TT_LOCAL_TIMEOUT); |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 2978 | batadv_tt_global_purge(bat_priv); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2979 | batadv_tt_req_purge(bat_priv); |
| 2980 | batadv_tt_roam_purge(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2981 | |
Antonio Quartulli | 7241444 | 2012-12-25 13:14:37 +0100 | [diff] [blame] | 2982 | queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work, |
| 2983 | msecs_to_jiffies(BATADV_TT_WORK_PERIOD)); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2984 | } |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2985 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 2986 | void batadv_tt_free(struct batadv_priv *bat_priv) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2987 | { |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 2988 | batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_TT, 1); |
| 2989 | batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_TT, 1); |
| 2990 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2991 | cancel_delayed_work_sync(&bat_priv->tt.work); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2992 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 2993 | batadv_tt_local_table_free(bat_priv); |
| 2994 | batadv_tt_global_table_free(bat_priv); |
| 2995 | batadv_tt_req_list_free(bat_priv); |
| 2996 | batadv_tt_changes_list_free(bat_priv); |
| 2997 | batadv_tt_roam_list_free(bat_priv); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2998 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 2999 | kfree(bat_priv->tt.last_changeset); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 3000 | } |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3001 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3002 | /** |
| 3003 | * batadv_tt_local_set_flags - set or unset the specified flags on the local |
| 3004 | * table and possibly count them in the TT size |
| 3005 | * @bat_priv: the bat priv with all the soft interface information |
| 3006 | * @flags: the flag to switch |
| 3007 | * @enable: whether to set or unset the flag |
| 3008 | * @count: whether to increase the TT size by the number of changed entries |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 3009 | */ |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3010 | static void batadv_tt_local_set_flags(struct batadv_priv *bat_priv, |
| 3011 | uint16_t flags, bool enable, bool count) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3012 | { |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3013 | struct batadv_hashtable *hash = bat_priv->tt.local_hash; |
| 3014 | struct batadv_tt_common_entry *tt_common_entry; |
Antonio Quartulli | 697f253 | 2011-11-07 16:47:01 +0100 | [diff] [blame] | 3015 | uint16_t changed_num = 0; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3016 | struct hlist_head *head; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3017 | uint32_t i; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3018 | |
| 3019 | if (!hash) |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3020 | return; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3021 | |
| 3022 | for (i = 0; i < hash->size; i++) { |
| 3023 | head = &hash->table[i]; |
| 3024 | |
| 3025 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3026 | hlist_for_each_entry_rcu(tt_common_entry, |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3027 | head, hash_entry) { |
Antonio Quartulli | 697f253 | 2011-11-07 16:47:01 +0100 | [diff] [blame] | 3028 | if (enable) { |
| 3029 | if ((tt_common_entry->flags & flags) == flags) |
| 3030 | continue; |
| 3031 | tt_common_entry->flags |= flags; |
| 3032 | } else { |
| 3033 | if (!(tt_common_entry->flags & flags)) |
| 3034 | continue; |
| 3035 | tt_common_entry->flags &= ~flags; |
| 3036 | } |
| 3037 | changed_num++; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3038 | |
| 3039 | if (!count) |
| 3040 | continue; |
| 3041 | |
| 3042 | batadv_tt_local_size_inc(bat_priv, |
| 3043 | tt_common_entry->vid); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3044 | } |
| 3045 | rcu_read_unlock(); |
| 3046 | } |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3047 | } |
| 3048 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 3049 | /* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 3050 | static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3051 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 3052 | struct batadv_hashtable *hash = bat_priv->tt.local_hash; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 3053 | struct batadv_tt_common_entry *tt_common; |
| 3054 | struct batadv_tt_local_entry *tt_local; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3055 | struct hlist_node *node_tmp; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3056 | struct hlist_head *head; |
| 3057 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 3058 | uint32_t i; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3059 | |
| 3060 | if (!hash) |
| 3061 | return; |
| 3062 | |
| 3063 | for (i = 0; i < hash->size; i++) { |
| 3064 | head = &hash->table[i]; |
| 3065 | list_lock = &hash->list_locks[i]; |
| 3066 | |
| 3067 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3068 | hlist_for_each_entry_safe(tt_common, node_tmp, head, |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 3069 | hash_entry) { |
| 3070 | if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING)) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3071 | continue; |
| 3072 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 3073 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 3074 | "Deleting local tt entry (%pM, vid: %d): pending\n", |
| 3075 | tt_common->addr, |
| 3076 | BATADV_PRINT_VID(tt_common->vid)); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3077 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3078 | batadv_tt_local_size_dec(bat_priv, tt_common->vid); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3079 | hlist_del_rcu(&tt_common->hash_entry); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 3080 | tt_local = container_of(tt_common, |
| 3081 | struct batadv_tt_local_entry, |
| 3082 | common); |
| 3083 | batadv_tt_local_entry_free_ref(tt_local); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3084 | } |
| 3085 | spin_unlock_bh(list_lock); |
| 3086 | } |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3087 | } |
| 3088 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3089 | /** |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 3090 | * batadv_tt_local_commit_changes_nolock - commit all pending local tt changes |
| 3091 | * which have been queued in the time since the last commit |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3092 | * @bat_priv: the bat priv with all the soft interface information |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 3093 | * |
| 3094 | * Caller must hold tt->commit_lock. |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3095 | */ |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 3096 | static void batadv_tt_local_commit_changes_nolock(struct batadv_priv *bat_priv) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3097 | { |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3098 | if (atomic_read(&bat_priv->tt.local_changes) < 1) { |
| 3099 | if (!batadv_atomic_dec_not_zero(&bat_priv->tt.ogm_append_cnt)) |
| 3100 | batadv_tt_tvlv_container_update(bat_priv); |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 3101 | return; |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3102 | } |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 3103 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3104 | batadv_tt_local_set_flags(bat_priv, BATADV_TT_CLIENT_NEW, false, true); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 3105 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 3106 | batadv_tt_local_purge_pending_clients(bat_priv); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3107 | batadv_tt_local_update_crc(bat_priv); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3108 | |
| 3109 | /* Increment the TTVN only once per OGM interval */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 3110 | atomic_inc(&bat_priv->tt.vn); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 3111 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 3112 | "Local changes committed, updating to ttvn %u\n", |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 3113 | (uint8_t)atomic_read(&bat_priv->tt.vn)); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 3114 | |
| 3115 | /* reset the sending counter */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 3116 | atomic_set(&bat_priv->tt.ogm_append_cnt, BATADV_TT_OGM_APPEND_MAX); |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3117 | batadv_tt_tvlv_container_update(bat_priv); |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 3118 | } |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 3119 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 3120 | /** |
| 3121 | * batadv_tt_local_commit_changes - commit all pending local tt changes which |
| 3122 | * have been queued in the time since the last commit |
| 3123 | * @bat_priv: the bat priv with all the soft interface information |
| 3124 | */ |
| 3125 | void batadv_tt_local_commit_changes(struct batadv_priv *bat_priv) |
| 3126 | { |
| 3127 | spin_lock_bh(&bat_priv->tt.commit_lock); |
| 3128 | batadv_tt_local_commit_changes_nolock(bat_priv); |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 3129 | spin_unlock_bh(&bat_priv->tt.commit_lock); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 3130 | } |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3131 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 3132 | bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, uint8_t *src, |
Antonio Quartulli | b8cbd81 | 2013-07-02 11:04:36 +0200 | [diff] [blame] | 3133 | uint8_t *dst, unsigned short vid) |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3134 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 3135 | struct batadv_tt_local_entry *tt_local_entry = NULL; |
| 3136 | struct batadv_tt_global_entry *tt_global_entry = NULL; |
Antonio Quartulli | b8cbd81 | 2013-07-02 11:04:36 +0200 | [diff] [blame] | 3137 | struct batadv_softif_vlan *vlan; |
Marek Lindner | 5870adc | 2012-06-20 17:16:05 +0200 | [diff] [blame] | 3138 | bool ret = false; |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3139 | |
Antonio Quartulli | b8cbd81 | 2013-07-02 11:04:36 +0200 | [diff] [blame] | 3140 | vlan = batadv_softif_vlan_get(bat_priv, vid); |
| 3141 | if (!vlan || !atomic_read(&vlan->ap_isolation)) |
Marek Lindner | 5870adc | 2012-06-20 17:16:05 +0200 | [diff] [blame] | 3142 | goto out; |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3143 | |
Antonio Quartulli | b8cbd81 | 2013-07-02 11:04:36 +0200 | [diff] [blame] | 3144 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst, vid); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3145 | if (!tt_local_entry) |
| 3146 | goto out; |
| 3147 | |
Antonio Quartulli | b8cbd81 | 2013-07-02 11:04:36 +0200 | [diff] [blame] | 3148 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, src, vid); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3149 | if (!tt_global_entry) |
| 3150 | goto out; |
| 3151 | |
Antonio Quartulli | 1f129fe | 2012-06-25 20:49:50 +0000 | [diff] [blame] | 3152 | if (!_batadv_is_ap_isolated(tt_local_entry, tt_global_entry)) |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3153 | goto out; |
| 3154 | |
Marek Lindner | 5870adc | 2012-06-20 17:16:05 +0200 | [diff] [blame] | 3155 | ret = true; |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3156 | |
| 3157 | out: |
Antonio Quartulli | b8cbd81 | 2013-07-02 11:04:36 +0200 | [diff] [blame] | 3158 | if (vlan) |
| 3159 | batadv_softif_vlan_free_ref(vlan); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3160 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 3161 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3162 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 3163 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 3164 | return ret; |
| 3165 | } |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3166 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3167 | /** |
| 3168 | * batadv_tt_update_orig - update global translation table with new tt |
| 3169 | * information received via ogms |
| 3170 | * @bat_priv: the bat priv with all the soft interface information |
| 3171 | * @orig: the orig_node of the ogm |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3172 | * @tt_vlan: pointer to the first tvlv VLAN entry |
| 3173 | * @tt_num_vlan: number of tvlv VLAN entries |
| 3174 | * @tt_change: pointer to the first entry in the TT buffer |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3175 | * @tt_num_changes: number of tt changes inside the tt buffer |
| 3176 | * @ttvn: translation table version number of this changeset |
Antonio Quartulli | ced7293 | 2013-04-24 16:37:51 +0200 | [diff] [blame] | 3177 | * @tt_crc: crc32 checksum of orig node's translation table |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3178 | */ |
| 3179 | static void batadv_tt_update_orig(struct batadv_priv *bat_priv, |
| 3180 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3181 | const void *tt_buff, uint16_t tt_num_vlan, |
| 3182 | struct batadv_tvlv_tt_change *tt_change, |
| 3183 | uint16_t tt_num_changes, uint8_t ttvn) |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3184 | { |
| 3185 | uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn); |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3186 | struct batadv_tvlv_tt_vlan_data *tt_vlan; |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3187 | bool full_table = true; |
| 3188 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3189 | tt_vlan = (struct batadv_tvlv_tt_vlan_data *)tt_buff; |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 3190 | /* orig table not initialised AND first diff is in the OGM OR the ttvn |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 3191 | * increased by one -> we can apply the attached changes |
| 3192 | */ |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 3193 | if ((!orig_node->tt_initialised && ttvn == 1) || |
| 3194 | ttvn - orig_ttvn == 1) { |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3195 | /* the OGM could not contain the changes due to their size or |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 3196 | * because they have already been sent BATADV_TT_OGM_APPEND_MAX |
| 3197 | * times. |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 3198 | * In this case send a tt request |
| 3199 | */ |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3200 | if (!tt_num_changes) { |
| 3201 | full_table = false; |
| 3202 | goto request_table; |
| 3203 | } |
| 3204 | |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 3205 | spin_lock_bh(&orig_node->tt_lock); |
| 3206 | |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 3207 | tt_change = (struct batadv_tvlv_tt_change *)tt_buff; |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 3208 | batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 3209 | ttvn, tt_change); |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3210 | |
| 3211 | /* Even if we received the precomputed crc with the OGM, we |
| 3212 | * prefer to recompute it to spot any possible inconsistency |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 3213 | * in the global table |
| 3214 | */ |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3215 | batadv_tt_global_update_crc(bat_priv, orig_node); |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3216 | |
Antonio Quartulli | a70a9aa | 2013-07-30 22:16:24 +0200 | [diff] [blame] | 3217 | spin_unlock_bh(&orig_node->tt_lock); |
| 3218 | |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3219 | /* The ttvn alone is not enough to guarantee consistency |
| 3220 | * because a single value could represent different states |
| 3221 | * (due to the wrap around). Thus a node has to check whether |
| 3222 | * the resulting table (after applying the changes) is still |
| 3223 | * consistent or not. E.g. a node could disconnect while its |
| 3224 | * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case |
| 3225 | * checking the CRC value is mandatory to detect the |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 3226 | * inconsistency |
| 3227 | */ |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3228 | if (!batadv_tt_global_check_crc(orig_node, tt_vlan, |
| 3229 | tt_num_vlan)) |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3230 | goto request_table; |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3231 | } else { |
| 3232 | /* if we missed more than one change or our tables are not |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 3233 | * in sync anymore -> request fresh tt data |
| 3234 | */ |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 3235 | if (!orig_node->tt_initialised || ttvn != orig_ttvn || |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3236 | !batadv_tt_global_check_crc(orig_node, tt_vlan, |
| 3237 | tt_num_vlan)) { |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3238 | request_table: |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 3239 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3240 | "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u num_changes: %u)\n", |
| 3241 | orig_node->orig, ttvn, orig_ttvn, |
| 3242 | tt_num_changes); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 3243 | batadv_send_tt_request(bat_priv, orig_node, ttvn, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3244 | tt_vlan, tt_num_vlan, |
| 3245 | full_table); |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 3246 | return; |
| 3247 | } |
| 3248 | } |
| 3249 | } |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 3250 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 3251 | /** |
| 3252 | * batadv_tt_global_client_is_roaming - check if a client is marked as roaming |
| 3253 | * @bat_priv: the bat priv with all the soft interface information |
| 3254 | * @addr: the mac address of the client to check |
| 3255 | * @vid: VLAN identifier |
| 3256 | * |
| 3257 | * Returns true if we know that the client has moved from its old originator |
| 3258 | * to another one. This entry is still kept for consistency purposes and will be |
| 3259 | * deleted later by a DEL or because of timeout |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 3260 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 3261 | bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 3262 | uint8_t *addr, unsigned short vid) |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 3263 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 3264 | struct batadv_tt_global_entry *tt_global_entry; |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 3265 | bool ret = false; |
| 3266 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 3267 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr, vid); |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 3268 | if (!tt_global_entry) |
| 3269 | goto out; |
| 3270 | |
Antonio Quartulli | c1d0743 | 2013-01-15 22:17:19 +1000 | [diff] [blame] | 3271 | ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM; |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame] | 3272 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 3273 | out: |
| 3274 | return ret; |
| 3275 | } |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 3276 | |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 3277 | /** |
| 3278 | * batadv_tt_local_client_is_roaming - tells whether the client is roaming |
| 3279 | * @bat_priv: the bat priv with all the soft interface information |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 3280 | * @addr: the mac address of the local client to query |
| 3281 | * @vid: VLAN identifier |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 3282 | * |
| 3283 | * Returns true if the local client is known to be roaming (it is not served by |
| 3284 | * this node anymore) or not. If yes, the client is still present in the table |
| 3285 | * to keep the latter consistent with the node TTVN |
| 3286 | */ |
| 3287 | bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 3288 | uint8_t *addr, unsigned short vid) |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 3289 | { |
| 3290 | struct batadv_tt_local_entry *tt_local_entry; |
| 3291 | bool ret = false; |
| 3292 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 3293 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr, vid); |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 3294 | if (!tt_local_entry) |
| 3295 | goto out; |
| 3296 | |
| 3297 | ret = tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM; |
| 3298 | batadv_tt_local_entry_free_ref(tt_local_entry); |
| 3299 | out: |
| 3300 | return ret; |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 3301 | } |
| 3302 | |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 3303 | bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv, |
| 3304 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 3305 | const unsigned char *addr, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 3306 | unsigned short vid) |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 3307 | { |
| 3308 | bool ret = false; |
| 3309 | |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 3310 | if (!batadv_tt_global_add(bat_priv, orig_node, addr, vid, |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 3311 | BATADV_TT_CLIENT_TEMP, |
| 3312 | atomic_read(&orig_node->last_ttvn))) |
| 3313 | goto out; |
| 3314 | |
| 3315 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
Antonio Quartulli | 1605278 | 2013-06-04 12:11:41 +0200 | [diff] [blame] | 3316 | "Added temporary global client (addr: %pM, vid: %d, orig: %pM)\n", |
| 3317 | addr, BATADV_PRINT_VID(vid), orig_node->orig); |
Antonio Quartulli | 30cfd02 | 2012-07-05 23:38:29 +0200 | [diff] [blame] | 3318 | ret = true; |
| 3319 | out: |
| 3320 | return ret; |
| 3321 | } |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3322 | |
| 3323 | /** |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 3324 | * batadv_tt_local_resize_to_mtu - resize the local translation table fit the |
| 3325 | * maximum packet size that can be transported through the mesh |
| 3326 | * @soft_iface: netdev struct of the mesh interface |
| 3327 | * |
| 3328 | * Remove entries older than 'timeout' and half timeout if more entries need |
| 3329 | * to be removed. |
| 3330 | */ |
| 3331 | void batadv_tt_local_resize_to_mtu(struct net_device *soft_iface) |
| 3332 | { |
| 3333 | struct batadv_priv *bat_priv = netdev_priv(soft_iface); |
| 3334 | int packet_size_max = atomic_read(&bat_priv->packet_size_max); |
| 3335 | int table_size, timeout = BATADV_TT_LOCAL_TIMEOUT / 2; |
| 3336 | bool reduced = false; |
| 3337 | |
| 3338 | spin_lock_bh(&bat_priv->tt.commit_lock); |
| 3339 | |
| 3340 | while (true) { |
| 3341 | table_size = batadv_tt_local_table_transmit_size(bat_priv); |
| 3342 | if (packet_size_max >= table_size) |
| 3343 | break; |
| 3344 | |
| 3345 | batadv_tt_local_purge(bat_priv, timeout); |
| 3346 | batadv_tt_local_purge_pending_clients(bat_priv); |
| 3347 | |
| 3348 | timeout /= 2; |
| 3349 | reduced = true; |
| 3350 | net_ratelimited_function(batadv_info, soft_iface, |
| 3351 | "Forced to purge local tt entries to fit new maximum fragment MTU (%i)\n", |
| 3352 | packet_size_max); |
| 3353 | } |
| 3354 | |
| 3355 | /* commit these changes immediately, to avoid synchronization problem |
| 3356 | * with the TTVN |
| 3357 | */ |
| 3358 | if (reduced) |
| 3359 | batadv_tt_local_commit_changes_nolock(bat_priv); |
| 3360 | |
| 3361 | spin_unlock_bh(&bat_priv->tt.commit_lock); |
| 3362 | } |
| 3363 | |
| 3364 | /** |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3365 | * batadv_tt_tvlv_ogm_handler_v1 - process incoming tt tvlv container |
| 3366 | * @bat_priv: the bat priv with all the soft interface information |
| 3367 | * @orig: the orig_node of the ogm |
| 3368 | * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags) |
| 3369 | * @tvlv_value: tvlv buffer containing the gateway data |
| 3370 | * @tvlv_value_len: tvlv buffer length |
| 3371 | */ |
| 3372 | static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv, |
| 3373 | struct batadv_orig_node *orig, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3374 | uint8_t flags, void *tvlv_value, |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3375 | uint16_t tvlv_value_len) |
| 3376 | { |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3377 | struct batadv_tvlv_tt_vlan_data *tt_vlan; |
| 3378 | struct batadv_tvlv_tt_change *tt_change; |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3379 | struct batadv_tvlv_tt_data *tt_data; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3380 | uint16_t num_entries, num_vlan; |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3381 | |
| 3382 | if (tvlv_value_len < sizeof(*tt_data)) |
| 3383 | return; |
| 3384 | |
| 3385 | tt_data = (struct batadv_tvlv_tt_data *)tvlv_value; |
| 3386 | tvlv_value_len -= sizeof(*tt_data); |
| 3387 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3388 | num_vlan = ntohs(tt_data->num_vlan); |
| 3389 | |
| 3390 | if (tvlv_value_len < sizeof(*tt_vlan) * num_vlan) |
| 3391 | return; |
| 3392 | |
| 3393 | tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1); |
| 3394 | tt_change = (struct batadv_tvlv_tt_change *)(tt_vlan + num_vlan); |
| 3395 | tvlv_value_len -= sizeof(*tt_vlan) * num_vlan; |
| 3396 | |
Antonio Quartulli | 298e6e6 | 2013-05-28 13:14:27 +0200 | [diff] [blame] | 3397 | num_entries = batadv_tt_entries(tvlv_value_len); |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3398 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3399 | batadv_tt_update_orig(bat_priv, orig, tt_vlan, num_vlan, tt_change, |
| 3400 | num_entries, tt_data->ttvn); |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | /** |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 3404 | * batadv_tt_tvlv_unicast_handler_v1 - process incoming (unicast) tt tvlv |
| 3405 | * container |
| 3406 | * @bat_priv: the bat priv with all the soft interface information |
| 3407 | * @src: mac address of tt tvlv sender |
| 3408 | * @dst: mac address of tt tvlv recipient |
| 3409 | * @tvlv_value: tvlv buffer containing the tt data |
| 3410 | * @tvlv_value_len: tvlv buffer length |
| 3411 | * |
| 3412 | * Returns NET_RX_DROP if the tt tvlv is to be re-routed, NET_RX_SUCCESS |
| 3413 | * otherwise. |
| 3414 | */ |
| 3415 | static int batadv_tt_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv, |
| 3416 | uint8_t *src, uint8_t *dst, |
| 3417 | void *tvlv_value, |
| 3418 | uint16_t tvlv_value_len) |
| 3419 | { |
| 3420 | struct batadv_tvlv_tt_data *tt_data; |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3421 | uint16_t tt_vlan_len, tt_num_entries; |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 3422 | char tt_flag; |
| 3423 | bool ret; |
| 3424 | |
| 3425 | if (tvlv_value_len < sizeof(*tt_data)) |
| 3426 | return NET_RX_SUCCESS; |
| 3427 | |
| 3428 | tt_data = (struct batadv_tvlv_tt_data *)tvlv_value; |
| 3429 | tvlv_value_len -= sizeof(*tt_data); |
| 3430 | |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3431 | tt_vlan_len = sizeof(struct batadv_tvlv_tt_vlan_data); |
| 3432 | tt_vlan_len *= ntohs(tt_data->num_vlan); |
| 3433 | |
| 3434 | if (tvlv_value_len < tt_vlan_len) |
| 3435 | return NET_RX_SUCCESS; |
| 3436 | |
| 3437 | tvlv_value_len -= tt_vlan_len; |
| 3438 | tt_num_entries = batadv_tt_entries(tvlv_value_len); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 3439 | |
| 3440 | switch (tt_data->flags & BATADV_TT_DATA_TYPE_MASK) { |
| 3441 | case BATADV_TT_REQUEST: |
| 3442 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_RX); |
| 3443 | |
| 3444 | /* If this node cannot provide a TT response the tt_request is |
| 3445 | * forwarded |
| 3446 | */ |
| 3447 | ret = batadv_send_tt_response(bat_priv, tt_data, src, dst); |
| 3448 | if (!ret) { |
| 3449 | if (tt_data->flags & BATADV_TT_FULL_TABLE) |
| 3450 | tt_flag = 'F'; |
| 3451 | else |
| 3452 | tt_flag = '.'; |
| 3453 | |
| 3454 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
| 3455 | "Routing TT_REQUEST to %pM [%c]\n", |
| 3456 | dst, tt_flag); |
| 3457 | /* tvlv API will re-route the packet */ |
| 3458 | return NET_RX_DROP; |
| 3459 | } |
| 3460 | break; |
| 3461 | case BATADV_TT_RESPONSE: |
| 3462 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_RX); |
| 3463 | |
| 3464 | if (batadv_is_my_mac(bat_priv, dst)) { |
| 3465 | batadv_handle_tt_response(bat_priv, tt_data, |
Antonio Quartulli | 7ea7b4a | 2013-07-30 22:16:25 +0200 | [diff] [blame] | 3466 | src, tt_num_entries); |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 3467 | return NET_RX_SUCCESS; |
| 3468 | } |
| 3469 | |
| 3470 | if (tt_data->flags & BATADV_TT_FULL_TABLE) |
| 3471 | tt_flag = 'F'; |
| 3472 | else |
| 3473 | tt_flag = '.'; |
| 3474 | |
| 3475 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
| 3476 | "Routing TT_RESPONSE to %pM [%c]\n", dst, tt_flag); |
| 3477 | |
| 3478 | /* tvlv API will re-route the packet */ |
| 3479 | return NET_RX_DROP; |
| 3480 | } |
| 3481 | |
| 3482 | return NET_RX_SUCCESS; |
| 3483 | } |
| 3484 | |
| 3485 | /** |
Marek Lindner | 122edaa | 2013-04-23 21:40:03 +0800 | [diff] [blame] | 3486 | * batadv_roam_tvlv_unicast_handler_v1 - process incoming tt roam tvlv container |
| 3487 | * @bat_priv: the bat priv with all the soft interface information |
| 3488 | * @src: mac address of tt tvlv sender |
| 3489 | * @dst: mac address of tt tvlv recipient |
| 3490 | * @tvlv_value: tvlv buffer containing the tt data |
| 3491 | * @tvlv_value_len: tvlv buffer length |
| 3492 | * |
| 3493 | * Returns NET_RX_DROP if the tt roam tvlv is to be re-routed, NET_RX_SUCCESS |
| 3494 | * otherwise. |
| 3495 | */ |
| 3496 | static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv, |
| 3497 | uint8_t *src, uint8_t *dst, |
| 3498 | void *tvlv_value, |
| 3499 | uint16_t tvlv_value_len) |
| 3500 | { |
| 3501 | struct batadv_tvlv_roam_adv *roaming_adv; |
| 3502 | struct batadv_orig_node *orig_node = NULL; |
| 3503 | |
| 3504 | /* If this node is not the intended recipient of the |
| 3505 | * roaming advertisement the packet is forwarded |
| 3506 | * (the tvlv API will re-route the packet). |
| 3507 | */ |
| 3508 | if (!batadv_is_my_mac(bat_priv, dst)) |
| 3509 | return NET_RX_DROP; |
| 3510 | |
Marek Lindner | 122edaa | 2013-04-23 21:40:03 +0800 | [diff] [blame] | 3511 | if (tvlv_value_len < sizeof(*roaming_adv)) |
| 3512 | goto out; |
| 3513 | |
| 3514 | orig_node = batadv_orig_hash_find(bat_priv, src); |
| 3515 | if (!orig_node) |
| 3516 | goto out; |
| 3517 | |
| 3518 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX); |
| 3519 | roaming_adv = (struct batadv_tvlv_roam_adv *)tvlv_value; |
| 3520 | |
| 3521 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
| 3522 | "Received ROAMING_ADV from %pM (client %pM)\n", |
| 3523 | src, roaming_adv->client); |
| 3524 | |
| 3525 | batadv_tt_global_add(bat_priv, orig_node, roaming_adv->client, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 3526 | ntohs(roaming_adv->vid), BATADV_TT_CLIENT_ROAM, |
Marek Lindner | 122edaa | 2013-04-23 21:40:03 +0800 | [diff] [blame] | 3527 | atomic_read(&orig_node->last_ttvn) + 1); |
| 3528 | |
| 3529 | out: |
| 3530 | if (orig_node) |
| 3531 | batadv_orig_node_free_ref(orig_node); |
| 3532 | return NET_RX_SUCCESS; |
| 3533 | } |
| 3534 | |
| 3535 | /** |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3536 | * batadv_tt_init - initialise the translation table internals |
| 3537 | * @bat_priv: the bat priv with all the soft interface information |
| 3538 | * |
| 3539 | * Return 0 on success or negative error number in case of failure. |
| 3540 | */ |
| 3541 | int batadv_tt_init(struct batadv_priv *bat_priv) |
| 3542 | { |
| 3543 | int ret; |
| 3544 | |
Antonio Quartulli | 0eb01568 | 2013-10-13 02:50:20 +0200 | [diff] [blame] | 3545 | /* synchronized flags must be remote */ |
| 3546 | BUILD_BUG_ON(!(BATADV_TT_SYNC_MASK & BATADV_TT_REMOTE_MASK)); |
| 3547 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3548 | ret = batadv_tt_local_init(bat_priv); |
| 3549 | if (ret < 0) |
| 3550 | return ret; |
| 3551 | |
| 3552 | ret = batadv_tt_global_init(bat_priv); |
| 3553 | if (ret < 0) |
| 3554 | return ret; |
| 3555 | |
| 3556 | batadv_tvlv_handler_register(bat_priv, batadv_tt_tvlv_ogm_handler_v1, |
Marek Lindner | 335fbe0 | 2013-04-23 21:40:02 +0800 | [diff] [blame] | 3557 | batadv_tt_tvlv_unicast_handler_v1, |
| 3558 | BATADV_TVLV_TT, 1, BATADV_NO_FLAGS); |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3559 | |
Marek Lindner | 122edaa | 2013-04-23 21:40:03 +0800 | [diff] [blame] | 3560 | batadv_tvlv_handler_register(bat_priv, NULL, |
| 3561 | batadv_roam_tvlv_unicast_handler_v1, |
| 3562 | BATADV_TVLV_ROAM, 1, BATADV_NO_FLAGS); |
| 3563 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 3564 | INIT_DELAYED_WORK(&bat_priv->tt.work, batadv_tt_purge); |
| 3565 | queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work, |
| 3566 | msecs_to_jiffies(BATADV_TT_WORK_PERIOD)); |
| 3567 | |
| 3568 | return 1; |
| 3569 | } |