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