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