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