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