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