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