blob: 34510f38708fbd192ac5be8d4911e456c5d8ab50 [file] [log] [blame]
Antonio Quartulli0b873932013-01-04 03:05:31 +01001/* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00002 *
Antonio Quartulli35c133a2012-03-14 13:03:01 +01003 * Marek Lindner, Simon Wunderlich, Antonio Quartulli
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00004 *
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
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000018 */
19
20#include "main.h"
21#include "translation-table.h"
22#include "soft-interface.h"
Marek Lindner32ae9b22011-04-20 15:40:58 +020023#include "hard-interface.h"
Antonio Quartullia73105b2011-04-27 14:27:44 +020024#include "send.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000025#include "hash.h"
26#include "originator.h"
Antonio Quartullia73105b2011-04-27 14:27:44 +020027#include "routing.h"
Simon Wunderlich20ff9d52012-01-22 20:00:23 +010028#include "bridge_loop_avoidance.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000029
Antonio Quartullia73105b2011-04-27 14:27:44 +020030#include <linux/crc16.h>
31
Antonio Quartullidec05072012-11-10 11:00:32 +010032/* hash class keys */
33static struct lock_class_key batadv_tt_local_hash_lock_class_key;
34static struct lock_class_key batadv_tt_global_hash_lock_class_key;
35
Sven Eckelmann56303d32012-06-05 22:31:31 +020036static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client,
37 struct batadv_orig_node *orig_node);
Sven Eckelmanna5130882012-05-16 20:23:16 +020038static void batadv_tt_purge(struct work_struct *work);
39static void
Sven Eckelmann56303d32012-06-05 22:31:31 +020040batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry);
Antonio Quartulli30cfd022012-07-05 23:38:29 +020041static void batadv_tt_global_del(struct batadv_priv *bat_priv,
42 struct batadv_orig_node *orig_node,
43 const unsigned char *addr,
44 const char *message, bool roaming);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000045
Marek Lindner7aadf882011-02-18 12:28:09 +000046/* returns 1 if they are the same mac addr */
Sven Eckelmanna5130882012-05-16 20:23:16 +020047static int batadv_compare_tt(const struct hlist_node *node, const void *data2)
Marek Lindner7aadf882011-02-18 12:28:09 +000048{
Sven Eckelmann56303d32012-06-05 22:31:31 +020049 const void *data1 = container_of(node, struct batadv_tt_common_entry,
Sven Eckelmann747e4222011-05-14 23:14:50 +020050 hash_entry);
Marek Lindner7aadf882011-02-18 12:28:09 +000051
52 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
53}
54
Sven Eckelmann56303d32012-06-05 22:31:31 +020055static struct batadv_tt_common_entry *
Sven Eckelmann5bf74e92012-06-05 22:31:28 +020056batadv_tt_hash_find(struct batadv_hashtable *hash, const void *data)
Marek Lindner7aadf882011-02-18 12:28:09 +000057{
Marek Lindner7aadf882011-02-18 12:28:09 +000058 struct hlist_head *head;
Sven Eckelmann56303d32012-06-05 22:31:31 +020059 struct batadv_tt_common_entry *tt_common_entry;
60 struct batadv_tt_common_entry *tt_common_entry_tmp = NULL;
Antonio Quartullic90681b2011-10-05 17:05:25 +020061 uint32_t index;
Marek Lindner7aadf882011-02-18 12:28:09 +000062
63 if (!hash)
64 return NULL;
65
Sven Eckelmannda641192012-05-12 13:48:56 +020066 index = batadv_choose_orig(data, hash->size);
Marek Lindner7aadf882011-02-18 12:28:09 +000067 head = &hash->table[index];
68
69 rcu_read_lock();
Sasha Levinb67bfe02013-02-27 17:06:00 -080070 hlist_for_each_entry_rcu(tt_common_entry, head, hash_entry) {
Sven Eckelmann1eda58b2012-05-12 13:48:58 +020071 if (!batadv_compare_eth(tt_common_entry, data))
Marek Lindner7aadf882011-02-18 12:28:09 +000072 continue;
73
Antonio Quartulli48100ba2011-10-30 12:17:33 +010074 if (!atomic_inc_not_zero(&tt_common_entry->refcount))
Antonio Quartulli7683fdc2011-04-27 14:28:07 +020075 continue;
76
Antonio Quartulli48100ba2011-10-30 12:17:33 +010077 tt_common_entry_tmp = tt_common_entry;
Marek Lindner7aadf882011-02-18 12:28:09 +000078 break;
79 }
80 rcu_read_unlock();
81
Antonio Quartulli48100ba2011-10-30 12:17:33 +010082 return tt_common_entry_tmp;
83}
84
Sven Eckelmann56303d32012-06-05 22:31:31 +020085static struct batadv_tt_local_entry *
86batadv_tt_local_hash_find(struct batadv_priv *bat_priv, const void *data)
Antonio Quartulli48100ba2011-10-30 12:17:33 +010087{
Sven Eckelmann56303d32012-06-05 22:31:31 +020088 struct batadv_tt_common_entry *tt_common_entry;
89 struct batadv_tt_local_entry *tt_local_entry = NULL;
Antonio Quartulli48100ba2011-10-30 12:17:33 +010090
Sven Eckelmann807736f2012-07-15 22:26:51 +020091 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.local_hash, data);
Antonio Quartulli48100ba2011-10-30 12:17:33 +010092 if (tt_common_entry)
93 tt_local_entry = container_of(tt_common_entry,
Sven Eckelmann56303d32012-06-05 22:31:31 +020094 struct batadv_tt_local_entry,
95 common);
Antonio Quartulli48100ba2011-10-30 12:17:33 +010096 return tt_local_entry;
Marek Lindner7aadf882011-02-18 12:28:09 +000097}
98
Sven Eckelmann56303d32012-06-05 22:31:31 +020099static struct batadv_tt_global_entry *
100batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const void *data)
Marek Lindner7aadf882011-02-18 12:28:09 +0000101{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200102 struct batadv_tt_common_entry *tt_common_entry;
103 struct batadv_tt_global_entry *tt_global_entry = NULL;
Marek Lindner7aadf882011-02-18 12:28:09 +0000104
Sven Eckelmann807736f2012-07-15 22:26:51 +0200105 tt_common_entry = batadv_tt_hash_find(bat_priv->tt.global_hash, data);
Antonio Quartulli48100ba2011-10-30 12:17:33 +0100106 if (tt_common_entry)
107 tt_global_entry = container_of(tt_common_entry,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200108 struct batadv_tt_global_entry,
109 common);
Antonio Quartulli48100ba2011-10-30 12:17:33 +0100110 return tt_global_entry;
Marek Lindner7aadf882011-02-18 12:28:09 +0000111}
112
Sven Eckelmanna5130882012-05-16 20:23:16 +0200113static void
Sven Eckelmann56303d32012-06-05 22:31:31 +0200114batadv_tt_local_entry_free_ref(struct batadv_tt_local_entry *tt_local_entry)
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200115{
Antonio Quartulli48100ba2011-10-30 12:17:33 +0100116 if (atomic_dec_and_test(&tt_local_entry->common.refcount))
117 kfree_rcu(tt_local_entry, common.rcu);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200118}
119
Sven Eckelmanna5130882012-05-16 20:23:16 +0200120static void batadv_tt_global_entry_free_rcu(struct rcu_head *rcu)
Simon Wunderlich531027f2011-10-19 11:02:25 +0200121{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200122 struct batadv_tt_common_entry *tt_common_entry;
123 struct batadv_tt_global_entry *tt_global_entry;
Simon Wunderlich531027f2011-10-19 11:02:25 +0200124
Sven Eckelmann56303d32012-06-05 22:31:31 +0200125 tt_common_entry = container_of(rcu, struct batadv_tt_common_entry, rcu);
126 tt_global_entry = container_of(tt_common_entry,
127 struct batadv_tt_global_entry, common);
Simon Wunderlich531027f2011-10-19 11:02:25 +0200128
Simon Wunderlich531027f2011-10-19 11:02:25 +0200129 kfree(tt_global_entry);
130}
131
Sven Eckelmanna5130882012-05-16 20:23:16 +0200132static void
Sven Eckelmann56303d32012-06-05 22:31:31 +0200133batadv_tt_global_entry_free_ref(struct batadv_tt_global_entry *tt_global_entry)
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200134{
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200135 if (atomic_dec_and_test(&tt_global_entry->common.refcount)) {
Sven Eckelmanna5130882012-05-16 20:23:16 +0200136 batadv_tt_global_del_orig_list(tt_global_entry);
Antonio Quartulli48100ba2011-10-30 12:17:33 +0100137 call_rcu(&tt_global_entry->common.rcu,
Sven Eckelmanna5130882012-05-16 20:23:16 +0200138 batadv_tt_global_entry_free_rcu);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200139 }
140}
141
Sven Eckelmanna5130882012-05-16 20:23:16 +0200142static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu)
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200143{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200144 struct batadv_tt_orig_list_entry *orig_entry;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200145
Sven Eckelmann56303d32012-06-05 22:31:31 +0200146 orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu);
Linus Lüssing72822222013-04-15 21:43:29 +0800147
148 /* We are in an rcu callback here, therefore we cannot use
149 * batadv_orig_node_free_ref() and its call_rcu():
150 * An rcu_barrier() wouldn't wait for that to finish
151 */
152 batadv_orig_node_free_ref_now(orig_entry->orig_node);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200153 kfree(orig_entry);
154}
155
Sven Eckelmanna5130882012-05-16 20:23:16 +0200156static void
Sven Eckelmann56303d32012-06-05 22:31:31 +0200157batadv_tt_orig_list_entry_free_ref(struct batadv_tt_orig_list_entry *orig_entry)
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200158{
Antonio Quartullid657e622012-07-01 14:09:12 +0200159 if (!atomic_dec_and_test(&orig_entry->refcount))
160 return;
Antonio Quartulli29cb99d2012-06-25 20:49:51 +0000161 /* to avoid race conditions, immediately decrease the tt counter */
162 atomic_dec(&orig_entry->orig_node->tt_size);
Sven Eckelmanna5130882012-05-16 20:23:16 +0200163 call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200164}
165
Antonio Quartulli3abe4ad2013-04-03 11:15:33 +0200166/**
167 * batadv_tt_local_event - store a local TT event (ADD/DEL)
168 * @bat_priv: the bat priv with all the soft interface information
169 * @tt_local_entry: the TT entry involved in the event
170 * @event_flags: flags to store in the event structure
171 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200172static void batadv_tt_local_event(struct batadv_priv *bat_priv,
Antonio Quartulli3abe4ad2013-04-03 11:15:33 +0200173 struct batadv_tt_local_entry *tt_local_entry,
174 uint8_t event_flags)
Antonio Quartullia73105b2011-04-27 14:27:44 +0200175{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200176 struct batadv_tt_change_node *tt_change_node, *entry, *safe;
Antonio Quartulli3abe4ad2013-04-03 11:15:33 +0200177 struct batadv_tt_common_entry *common = &tt_local_entry->common;
178 uint8_t flags = common->flags | event_flags;
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200179 bool event_removed = false;
180 bool del_op_requested, del_op_entry;
Antonio Quartullia73105b2011-04-27 14:27:44 +0200181
182 tt_change_node = kmalloc(sizeof(*tt_change_node), GFP_ATOMIC);
183
184 if (!tt_change_node)
185 return;
186
Antonio Quartulliff66c972011-06-30 01:14:00 +0200187 tt_change_node->change.flags = flags;
Antonio Quartulli3abe4ad2013-04-03 11:15:33 +0200188 memcpy(tt_change_node->change.addr, common->addr, ETH_ALEN);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200189
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200190 del_op_requested = flags & BATADV_TT_CLIENT_DEL;
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200191
192 /* check for ADD+DEL or DEL+ADD events */
Sven Eckelmann807736f2012-07-15 22:26:51 +0200193 spin_lock_bh(&bat_priv->tt.changes_list_lock);
194 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200195 list) {
Antonio Quartulli3abe4ad2013-04-03 11:15:33 +0200196 if (!batadv_compare_eth(entry->change.addr, common->addr))
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200197 continue;
198
199 /* DEL+ADD in the same orig interval have no effect and can be
200 * removed to avoid silly behaviour on the receiver side. The
201 * other way around (ADD+DEL) can happen in case of roaming of
202 * a client still in the NEW state. Roaming of NEW clients is
203 * now possible due to automatically recognition of "temporary"
204 * clients
205 */
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200206 del_op_entry = entry->change.flags & BATADV_TT_CLIENT_DEL;
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200207 if (!del_op_requested && del_op_entry)
208 goto del;
209 if (del_op_requested && !del_op_entry)
210 goto del;
211 continue;
212del:
213 list_del(&entry->list);
214 kfree(entry);
Jesper Juhl155e4e12012-08-07 08:32:34 +0000215 kfree(tt_change_node);
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200216 event_removed = true;
217 goto unlock;
218 }
219
Antonio Quartullia73105b2011-04-27 14:27:44 +0200220 /* track the change in the OGMinterval list */
Sven Eckelmann807736f2012-07-15 22:26:51 +0200221 list_add_tail(&tt_change_node->list, &bat_priv->tt.changes_list);
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200222
223unlock:
Sven Eckelmann807736f2012-07-15 22:26:51 +0200224 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200225
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200226 if (event_removed)
Sven Eckelmann807736f2012-07-15 22:26:51 +0200227 atomic_dec(&bat_priv->tt.local_changes);
Antonio Quartulli3b643de2012-05-25 00:00:42 +0200228 else
Sven Eckelmann807736f2012-07-15 22:26:51 +0200229 atomic_inc(&bat_priv->tt.local_changes);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200230}
231
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200232int batadv_tt_len(int changes_num)
Antonio Quartullia73105b2011-04-27 14:27:44 +0200233{
Sven Eckelmann96412692012-06-05 22:31:30 +0200234 return changes_num * sizeof(struct batadv_tt_change);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200235}
236
Sven Eckelmann56303d32012-06-05 22:31:31 +0200237static int batadv_tt_local_init(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000238{
Sven Eckelmann807736f2012-07-15 22:26:51 +0200239 if (bat_priv->tt.local_hash)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200240 return 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000241
Sven Eckelmann807736f2012-07-15 22:26:51 +0200242 bat_priv->tt.local_hash = batadv_hash_new(1024);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000243
Sven Eckelmann807736f2012-07-15 22:26:51 +0200244 if (!bat_priv->tt.local_hash)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200245 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000246
Antonio Quartullidec05072012-11-10 11:00:32 +0100247 batadv_hash_set_lock_class(bat_priv->tt.local_hash,
248 &batadv_tt_local_hash_lock_class_key);
249
Sven Eckelmann5346c352012-05-05 13:27:28 +0200250 return 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000251}
252
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200253static void batadv_tt_global_free(struct batadv_priv *bat_priv,
254 struct batadv_tt_global_entry *tt_global,
255 const char *message)
256{
257 batadv_dbg(BATADV_DBG_TT, bat_priv,
258 "Deleting global tt entry %pM: %s\n",
259 tt_global->common.addr, message);
260
261 batadv_hash_remove(bat_priv->tt.global_hash, batadv_compare_tt,
262 batadv_choose_orig, tt_global->common.addr);
263 batadv_tt_global_entry_free_ref(tt_global);
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200264}
265
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200266void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
267 int ifindex)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000268{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200269 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
Sven Eckelmann170173b2012-10-07 12:02:22 +0200270 struct batadv_tt_local_entry *tt_local;
271 struct batadv_tt_global_entry *tt_global;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200272 struct hlist_head *head;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200273 struct batadv_tt_orig_list_entry *orig_entry;
Simon Wunderlich80b3f582011-11-02 20:26:45 +0100274 int hash_added;
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200275 bool roamed_back = false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000276
Antonio Quartulli47c94652012-09-23 22:38:35 +0200277 tt_local = batadv_tt_local_hash_find(bat_priv, addr);
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200278 tt_global = batadv_tt_global_hash_find(bat_priv, addr);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000279
Antonio Quartulli47c94652012-09-23 22:38:35 +0200280 if (tt_local) {
281 tt_local->last_seen = jiffies;
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200282 if (tt_local->common.flags & BATADV_TT_CLIENT_PENDING) {
283 batadv_dbg(BATADV_DBG_TT, bat_priv,
284 "Re-adding pending client %pM\n", addr);
285 /* whatever the reason why the PENDING flag was set,
286 * this is a client which was enqueued to be removed in
287 * this orig_interval. Since it popped up again, the
288 * flag can be reset like it was never enqueued
289 */
290 tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING;
291 goto add_event;
292 }
293
294 if (tt_local->common.flags & BATADV_TT_CLIENT_ROAM) {
295 batadv_dbg(BATADV_DBG_TT, bat_priv,
296 "Roaming client %pM came back to its original location\n",
297 addr);
298 /* the ROAM flag is set because this client roamed away
299 * and the node got a roaming_advertisement message. Now
300 * that the client popped up again at its original
301 * location such flag can be unset
302 */
303 tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM;
304 roamed_back = true;
305 }
306 goto check_roaming;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000307 }
308
Antonio Quartulli47c94652012-09-23 22:38:35 +0200309 tt_local = kmalloc(sizeof(*tt_local), GFP_ATOMIC);
310 if (!tt_local)
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200311 goto out;
Antonio Quartullia73105b2011-04-27 14:27:44 +0200312
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200313 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200314 "Creating new local tt entry: %pM (ttvn: %d)\n", addr,
Sven Eckelmann807736f2012-07-15 22:26:51 +0200315 (uint8_t)atomic_read(&bat_priv->tt.vn));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000316
Antonio Quartulli47c94652012-09-23 22:38:35 +0200317 memcpy(tt_local->common.addr, addr, ETH_ALEN);
Antonio Quartulli8425ec62012-11-19 09:01:44 +0100318 /* The local entry has to be marked as NEW to avoid to send it in
319 * a full table response going out before the next ttvn increment
320 * (consistency check)
321 */
322 tt_local->common.flags = BATADV_TT_CLIENT_NEW;
Sven Eckelmann95638772012-05-12 02:09:31 +0200323 if (batadv_is_wifi_iface(ifindex))
Antonio Quartulli47c94652012-09-23 22:38:35 +0200324 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
325 atomic_set(&tt_local->common.refcount, 2);
326 tt_local->last_seen = jiffies;
327 tt_local->common.added_at = tt_local->last_seen;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000328
329 /* the batman interface mac address should never be purged */
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200330 if (batadv_compare_eth(addr, soft_iface->dev_addr))
Antonio Quartulli47c94652012-09-23 22:38:35 +0200331 tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000332
Sven Eckelmann807736f2012-07-15 22:26:51 +0200333 hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt,
Antonio Quartulli47c94652012-09-23 22:38:35 +0200334 batadv_choose_orig, &tt_local->common,
335 &tt_local->common.hash_entry);
Simon Wunderlich80b3f582011-11-02 20:26:45 +0100336
337 if (unlikely(hash_added != 0)) {
338 /* remove the reference for the hash */
Antonio Quartulli47c94652012-09-23 22:38:35 +0200339 batadv_tt_local_entry_free_ref(tt_local);
Simon Wunderlich80b3f582011-11-02 20:26:45 +0100340 goto out;
341 }
342
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200343add_event:
Antonio Quartulli3abe4ad2013-04-03 11:15:33 +0200344 batadv_tt_local_event(bat_priv, tt_local, BATADV_NO_FLAGS);
Antonio Quartulliff66c972011-06-30 01:14:00 +0200345
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200346check_roaming:
347 /* Check whether it is a roaming, but don't do anything if the roaming
348 * process has already been handled
349 */
350 if (tt_global && !(tt_global->common.flags & BATADV_TT_CLIENT_ROAM)) {
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200351 /* These node are probably going to update their tt table */
Antonio Quartulli47c94652012-09-23 22:38:35 +0200352 head = &tt_global->orig_list;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200353 rcu_read_lock();
Sasha Levinb67bfe02013-02-27 17:06:00 -0800354 hlist_for_each_entry_rcu(orig_entry, head, list) {
Antonio Quartulli47c94652012-09-23 22:38:35 +0200355 batadv_send_roam_adv(bat_priv, tt_global->common.addr,
Sven Eckelmanna5130882012-05-16 20:23:16 +0200356 orig_entry->orig_node);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200357 }
358 rcu_read_unlock();
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200359 if (roamed_back) {
360 batadv_tt_global_free(bat_priv, tt_global,
361 "Roaming canceled");
362 tt_global = NULL;
363 } else {
364 /* The global entry has to be marked as ROAMING and
365 * has to be kept for consistency purpose
366 */
367 tt_global->common.flags |= BATADV_TT_CLIENT_ROAM;
368 tt_global->roam_at = jiffies;
369 }
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200370 }
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200371
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200372out:
Antonio Quartulli47c94652012-09-23 22:38:35 +0200373 if (tt_local)
374 batadv_tt_local_entry_free_ref(tt_local);
375 if (tt_global)
376 batadv_tt_global_entry_free_ref(tt_global);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000377}
378
Sven Eckelmanna5130882012-05-16 20:23:16 +0200379static void batadv_tt_realloc_packet_buff(unsigned char **packet_buff,
380 int *packet_buff_len,
381 int min_packet_len,
382 int new_packet_len)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000383{
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800384 unsigned char *new_buff;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000385
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800386 new_buff = kmalloc(new_packet_len, GFP_ATOMIC);
387
388 /* keep old buffer if kmalloc should fail */
389 if (new_buff) {
390 memcpy(new_buff, *packet_buff, min_packet_len);
391 kfree(*packet_buff);
392 *packet_buff = new_buff;
393 *packet_buff_len = new_packet_len;
394 }
395}
396
Sven Eckelmann56303d32012-06-05 22:31:31 +0200397static void batadv_tt_prepare_packet_buff(struct batadv_priv *bat_priv,
Sven Eckelmanna5130882012-05-16 20:23:16 +0200398 unsigned char **packet_buff,
399 int *packet_buff_len,
400 int min_packet_len)
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800401{
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800402 int req_len;
403
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800404 req_len = min_packet_len;
Sven Eckelmann807736f2012-07-15 22:26:51 +0200405 req_len += batadv_tt_len(atomic_read(&bat_priv->tt.local_changes));
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800406
407 /* if we have too many changes for one packet don't send any
408 * and wait for the tt table request which will be fragmented
409 */
Marek Lindner736292c2013-01-12 19:19:06 +0800410 if (req_len > bat_priv->soft_iface->mtu)
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800411 req_len = min_packet_len;
412
Sven Eckelmanna5130882012-05-16 20:23:16 +0200413 batadv_tt_realloc_packet_buff(packet_buff, packet_buff_len,
414 min_packet_len, req_len);
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800415}
416
Sven Eckelmann56303d32012-06-05 22:31:31 +0200417static int batadv_tt_changes_fill_buff(struct batadv_priv *bat_priv,
Sven Eckelmanna5130882012-05-16 20:23:16 +0200418 unsigned char **packet_buff,
419 int *packet_buff_len,
420 int min_packet_len)
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800421{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200422 struct batadv_tt_change_node *entry, *safe;
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800423 int count = 0, tot_changes = 0, new_len;
424 unsigned char *tt_buff;
425
Sven Eckelmanna5130882012-05-16 20:23:16 +0200426 batadv_tt_prepare_packet_buff(bat_priv, packet_buff,
427 packet_buff_len, min_packet_len);
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800428
429 new_len = *packet_buff_len - min_packet_len;
430 tt_buff = *packet_buff + min_packet_len;
431
432 if (new_len > 0)
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200433 tot_changes = new_len / batadv_tt_len(1);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000434
Sven Eckelmann807736f2012-07-15 22:26:51 +0200435 spin_lock_bh(&bat_priv->tt.changes_list_lock);
436 atomic_set(&bat_priv->tt.local_changes, 0);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000437
Sven Eckelmann807736f2012-07-15 22:26:51 +0200438 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
Sven Eckelmann7c64fd92012-02-28 10:55:36 +0100439 list) {
Antonio Quartullia73105b2011-04-27 14:27:44 +0200440 if (count < tot_changes) {
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200441 memcpy(tt_buff + batadv_tt_len(count),
Sven Eckelmann96412692012-06-05 22:31:30 +0200442 &entry->change, sizeof(struct batadv_tt_change));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000443 count++;
444 }
Antonio Quartullia73105b2011-04-27 14:27:44 +0200445 list_del(&entry->list);
446 kfree(entry);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000447 }
Sven Eckelmann807736f2012-07-15 22:26:51 +0200448 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000449
Antonio Quartullia73105b2011-04-27 14:27:44 +0200450 /* Keep the buffer for possible tt_request */
Sven Eckelmann807736f2012-07-15 22:26:51 +0200451 spin_lock_bh(&bat_priv->tt.last_changeset_lock);
452 kfree(bat_priv->tt.last_changeset);
453 bat_priv->tt.last_changeset_len = 0;
454 bat_priv->tt.last_changeset = NULL;
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +0800455 /* check whether this new OGM has no changes due to size problems */
456 if (new_len > 0) {
457 /* if kmalloc() fails we will reply with the full table
Antonio Quartullia73105b2011-04-27 14:27:44 +0200458 * instead of providing the diff
459 */
Sven Eckelmann807736f2012-07-15 22:26:51 +0200460 bat_priv->tt.last_changeset = kmalloc(new_len, GFP_ATOMIC);
461 if (bat_priv->tt.last_changeset) {
462 memcpy(bat_priv->tt.last_changeset, tt_buff, new_len);
463 bat_priv->tt.last_changeset_len = new_len;
Antonio Quartullia73105b2011-04-27 14:27:44 +0200464 }
465 }
Sven Eckelmann807736f2012-07-15 22:26:51 +0200466 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000467
Marek Lindner08ad76e2012-04-23 16:32:55 +0800468 return count;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000469}
470
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200471int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000472{
473 struct net_device *net_dev = (struct net_device *)seq->private;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200474 struct batadv_priv *bat_priv = netdev_priv(net_dev);
Sven Eckelmann807736f2012-07-15 22:26:51 +0200475 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200476 struct batadv_tt_common_entry *tt_common_entry;
Antonio Quartulli85766a82012-11-08 22:16:16 +0100477 struct batadv_tt_local_entry *tt_local;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200478 struct batadv_hard_iface *primary_if;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000479 struct hlist_head *head;
Antonio Quartullic90681b2011-10-05 17:05:25 +0200480 uint32_t i;
Antonio Quartulli85766a82012-11-08 22:16:16 +0100481 int last_seen_secs;
482 int last_seen_msecs;
483 unsigned long last_seen_jiffies;
484 bool no_purge;
485 uint16_t np_flag = BATADV_TT_CLIENT_NOPURGE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000486
Marek Lindner30da63a2012-08-03 17:15:46 +0200487 primary_if = batadv_seq_print_text_primary_if_get(seq);
488 if (!primary_if)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200489 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000490
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100491 seq_printf(seq,
Antonio Quartullif9d8a532012-11-19 09:01:42 +0100492 "Locally retrieved addresses (from %s) announced via TT (TTVN: %u CRC: %#.4x):\n",
493 net_dev->name, (uint8_t)atomic_read(&bat_priv->tt.vn),
494 bat_priv->tt.local_crc);
Antonio Quartulli85766a82012-11-08 22:16:16 +0100495 seq_printf(seq, " %-13s %-7s %-10s\n", "Client", "Flags",
496 "Last seen");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000497
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000498 for (i = 0; i < hash->size; i++) {
499 head = &hash->table[i];
500
Marek Lindner7aadf882011-02-18 12:28:09 +0000501 rcu_read_lock();
Sasha Levinb67bfe02013-02-27 17:06:00 -0800502 hlist_for_each_entry_rcu(tt_common_entry,
Marek Lindner7aadf882011-02-18 12:28:09 +0000503 head, hash_entry) {
Antonio Quartulli85766a82012-11-08 22:16:16 +0100504 tt_local = container_of(tt_common_entry,
505 struct batadv_tt_local_entry,
506 common);
507 last_seen_jiffies = jiffies - tt_local->last_seen;
508 last_seen_msecs = jiffies_to_msecs(last_seen_jiffies);
509 last_seen_secs = last_seen_msecs / 1000;
510 last_seen_msecs = last_seen_msecs % 1000;
511
512 no_purge = tt_common_entry->flags & np_flag;
513
514 seq_printf(seq, " * %pM [%c%c%c%c%c] %3u.%03u\n",
Sven Eckelmann7c64fd92012-02-28 10:55:36 +0100515 tt_common_entry->addr,
516 (tt_common_entry->flags &
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200517 BATADV_TT_CLIENT_ROAM ? 'R' : '.'),
Antonio Quartulli85766a82012-11-08 22:16:16 +0100518 no_purge ? 'P' : '.',
Sven Eckelmann7c64fd92012-02-28 10:55:36 +0100519 (tt_common_entry->flags &
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200520 BATADV_TT_CLIENT_NEW ? 'N' : '.'),
Sven Eckelmann7c64fd92012-02-28 10:55:36 +0100521 (tt_common_entry->flags &
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200522 BATADV_TT_CLIENT_PENDING ? 'X' : '.'),
Sven Eckelmann7c64fd92012-02-28 10:55:36 +0100523 (tt_common_entry->flags &
Antonio Quartulli85766a82012-11-08 22:16:16 +0100524 BATADV_TT_CLIENT_WIFI ? 'W' : '.'),
Antonio Quartullia7966d92013-01-24 11:41:39 +0100525 no_purge ? 0 : last_seen_secs,
526 no_purge ? 0 : last_seen_msecs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000527 }
Marek Lindner7aadf882011-02-18 12:28:09 +0000528 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000529 }
Marek Lindner32ae9b22011-04-20 15:40:58 +0200530out:
531 if (primary_if)
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200532 batadv_hardif_free_ref(primary_if);
Marek Lindner30da63a2012-08-03 17:15:46 +0200533 return 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000534}
535
Sven Eckelmann56303d32012-06-05 22:31:31 +0200536static void
537batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
538 struct batadv_tt_local_entry *tt_local_entry,
539 uint16_t flags, const char *message)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000540{
Antonio Quartulli3abe4ad2013-04-03 11:15:33 +0200541 batadv_tt_local_event(bat_priv, tt_local_entry, flags);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000542
Antonio Quartulli015758d2011-07-09 17:52:13 +0200543 /* The local client has to be marked as "pending to be removed" but has
544 * to be kept in the table in order to send it in a full table
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200545 * response issued before the net ttvn increment (consistency check)
546 */
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200547 tt_local_entry->common.flags |= BATADV_TT_CLIENT_PENDING;
Antonio Quartullic566dbb2012-01-06 21:31:34 +0100548
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200549 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200550 "Local tt entry (%pM) pending to be removed: %s\n",
551 tt_local_entry->common.addr, message);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000552}
553
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200554/**
555 * batadv_tt_local_remove - logically remove an entry from the local table
556 * @bat_priv: the bat priv with all the soft interface information
557 * @addr: the MAC address of the client to remove
558 * @message: message to append to the log on deletion
559 * @roaming: true if the deletion is due to a roaming event
560 *
561 * Returns the flags assigned to the local entry before being deleted
562 */
563uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv,
564 const uint8_t *addr, const char *message,
565 bool roaming)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000566{
Sven Eckelmann170173b2012-10-07 12:02:22 +0200567 struct batadv_tt_local_entry *tt_local_entry;
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200568 uint16_t flags, curr_flags = BATADV_NO_FLAGS;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000569
Sven Eckelmanna5130882012-05-16 20:23:16 +0200570 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200571 if (!tt_local_entry)
572 goto out;
573
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200574 curr_flags = tt_local_entry->common.flags;
575
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200576 flags = BATADV_TT_CLIENT_DEL;
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200577 /* if this global entry addition is due to a roaming, the node has to
578 * mark the local entry as "roamed" in order to correctly reroute
579 * packets later
580 */
Antonio Quartulli7c1fd912012-09-23 22:38:34 +0200581 if (roaming) {
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200582 flags |= BATADV_TT_CLIENT_ROAM;
Antonio Quartulli7c1fd912012-09-23 22:38:34 +0200583 /* mark the local client as ROAMed */
584 tt_local_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
585 }
Sven Eckelmann42d0b042012-06-03 22:19:17 +0200586
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200587 if (!(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW)) {
588 batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,
589 message);
590 goto out;
591 }
592 /* if this client has been added right now, it is possible to
593 * immediately purge it
594 */
Antonio Quartulli3abe4ad2013-04-03 11:15:33 +0200595 batadv_tt_local_event(bat_priv, tt_local_entry, BATADV_TT_CLIENT_DEL);
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200596 hlist_del_rcu(&tt_local_entry->common.hash_entry);
597 batadv_tt_local_entry_free_ref(tt_local_entry);
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200598
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200599out:
600 if (tt_local_entry)
Sven Eckelmanna5130882012-05-16 20:23:16 +0200601 batadv_tt_local_entry_free_ref(tt_local_entry);
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200602
603 return curr_flags;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000604}
605
Sven Eckelmann56303d32012-06-05 22:31:31 +0200606static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200607 struct hlist_head *head)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000608{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200609 struct batadv_tt_local_entry *tt_local_entry;
610 struct batadv_tt_common_entry *tt_common_entry;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800611 struct hlist_node *node_tmp;
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200612
Sasha Levinb67bfe02013-02-27 17:06:00 -0800613 hlist_for_each_entry_safe(tt_common_entry, node_tmp, head,
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200614 hash_entry) {
615 tt_local_entry = container_of(tt_common_entry,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200616 struct batadv_tt_local_entry,
617 common);
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200618 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_NOPURGE)
619 continue;
620
621 /* entry already marked for deletion */
622 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)
623 continue;
624
625 if (!batadv_has_timed_out(tt_local_entry->last_seen,
626 BATADV_TT_LOCAL_TIMEOUT))
627 continue;
628
629 batadv_tt_local_set_pending(bat_priv, tt_local_entry,
630 BATADV_TT_CLIENT_DEL, "timed out");
631 }
632}
633
Sven Eckelmann56303d32012-06-05 22:31:31 +0200634static void batadv_tt_local_purge(struct batadv_priv *bat_priv)
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200635{
Sven Eckelmann807736f2012-07-15 22:26:51 +0200636 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000637 struct hlist_head *head;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200638 spinlock_t *list_lock; /* protects write access to the hash lists */
Antonio Quartullic90681b2011-10-05 17:05:25 +0200639 uint32_t i;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000640
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000641 for (i = 0; i < hash->size; i++) {
642 head = &hash->table[i];
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200643 list_lock = &hash->list_locks[i];
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000644
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200645 spin_lock_bh(list_lock);
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200646 batadv_tt_local_purge_list(bat_priv, head);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200647 spin_unlock_bh(list_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000648 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000649}
650
Sven Eckelmann56303d32012-06-05 22:31:31 +0200651static void batadv_tt_local_table_free(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000652{
Sven Eckelmann5bf74e92012-06-05 22:31:28 +0200653 struct batadv_hashtable *hash;
Antonio Quartullia73105b2011-04-27 14:27:44 +0200654 spinlock_t *list_lock; /* protects write access to the hash lists */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200655 struct batadv_tt_common_entry *tt_common_entry;
656 struct batadv_tt_local_entry *tt_local;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800657 struct hlist_node *node_tmp;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200658 struct hlist_head *head;
Antonio Quartullic90681b2011-10-05 17:05:25 +0200659 uint32_t i;
Antonio Quartullia73105b2011-04-27 14:27:44 +0200660
Sven Eckelmann807736f2012-07-15 22:26:51 +0200661 if (!bat_priv->tt.local_hash)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000662 return;
663
Sven Eckelmann807736f2012-07-15 22:26:51 +0200664 hash = bat_priv->tt.local_hash;
Antonio Quartullia73105b2011-04-27 14:27:44 +0200665
666 for (i = 0; i < hash->size; i++) {
667 head = &hash->table[i];
668 list_lock = &hash->list_locks[i];
669
670 spin_lock_bh(list_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800671 hlist_for_each_entry_safe(tt_common_entry, node_tmp,
Antonio Quartullia73105b2011-04-27 14:27:44 +0200672 head, hash_entry) {
Sasha Levinb67bfe02013-02-27 17:06:00 -0800673 hlist_del_rcu(&tt_common_entry->hash_entry);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200674 tt_local = container_of(tt_common_entry,
675 struct batadv_tt_local_entry,
676 common);
677 batadv_tt_local_entry_free_ref(tt_local);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200678 }
679 spin_unlock_bh(list_lock);
680 }
681
Sven Eckelmann1a8eaf02012-05-12 02:09:32 +0200682 batadv_hash_destroy(hash);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200683
Sven Eckelmann807736f2012-07-15 22:26:51 +0200684 bat_priv->tt.local_hash = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000685}
686
Sven Eckelmann56303d32012-06-05 22:31:31 +0200687static int batadv_tt_global_init(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000688{
Sven Eckelmann807736f2012-07-15 22:26:51 +0200689 if (bat_priv->tt.global_hash)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200690 return 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000691
Sven Eckelmann807736f2012-07-15 22:26:51 +0200692 bat_priv->tt.global_hash = batadv_hash_new(1024);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000693
Sven Eckelmann807736f2012-07-15 22:26:51 +0200694 if (!bat_priv->tt.global_hash)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200695 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000696
Antonio Quartullidec05072012-11-10 11:00:32 +0100697 batadv_hash_set_lock_class(bat_priv->tt.global_hash,
698 &batadv_tt_global_hash_lock_class_key);
699
Sven Eckelmann5346c352012-05-05 13:27:28 +0200700 return 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000701}
702
Sven Eckelmann56303d32012-06-05 22:31:31 +0200703static void batadv_tt_changes_list_free(struct batadv_priv *bat_priv)
Antonio Quartullia73105b2011-04-27 14:27:44 +0200704{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200705 struct batadv_tt_change_node *entry, *safe;
Antonio Quartullia73105b2011-04-27 14:27:44 +0200706
Sven Eckelmann807736f2012-07-15 22:26:51 +0200707 spin_lock_bh(&bat_priv->tt.changes_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200708
Sven Eckelmann807736f2012-07-15 22:26:51 +0200709 list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
Antonio Quartullia73105b2011-04-27 14:27:44 +0200710 list) {
711 list_del(&entry->list);
712 kfree(entry);
713 }
714
Sven Eckelmann807736f2012-07-15 22:26:51 +0200715 atomic_set(&bat_priv->tt.local_changes, 0);
716 spin_unlock_bh(&bat_priv->tt.changes_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200717}
718
Antonio Quartullid657e622012-07-01 14:09:12 +0200719/* retrieves the orig_tt_list_entry belonging to orig_node from the
720 * batadv_tt_global_entry list
721 *
722 * returns it with an increased refcounter, NULL if not found
723 */
724static struct batadv_tt_orig_list_entry *
725batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
726 const struct batadv_orig_node *orig_node)
727{
728 struct batadv_tt_orig_list_entry *tmp_orig_entry, *orig_entry = NULL;
729 const struct hlist_head *head;
Antonio Quartullid657e622012-07-01 14:09:12 +0200730
731 rcu_read_lock();
732 head = &entry->orig_list;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800733 hlist_for_each_entry_rcu(tmp_orig_entry, head, list) {
Antonio Quartullid657e622012-07-01 14:09:12 +0200734 if (tmp_orig_entry->orig_node != orig_node)
735 continue;
736 if (!atomic_inc_not_zero(&tmp_orig_entry->refcount))
737 continue;
738
739 orig_entry = tmp_orig_entry;
740 break;
741 }
742 rcu_read_unlock();
743
744 return orig_entry;
745}
746
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200747/* find out if an orig_node is already in the list of a tt_global_entry.
Antonio Quartullid657e622012-07-01 14:09:12 +0200748 * returns true if found, false otherwise
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200749 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200750static bool
751batadv_tt_global_entry_has_orig(const struct batadv_tt_global_entry *entry,
752 const struct batadv_orig_node *orig_node)
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200753{
Antonio Quartullid657e622012-07-01 14:09:12 +0200754 struct batadv_tt_orig_list_entry *orig_entry;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200755 bool found = false;
756
Antonio Quartullid657e622012-07-01 14:09:12 +0200757 orig_entry = batadv_tt_global_orig_entry_find(entry, orig_node);
758 if (orig_entry) {
759 found = true;
760 batadv_tt_orig_list_entry_free_ref(orig_entry);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200761 }
Antonio Quartullid657e622012-07-01 14:09:12 +0200762
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200763 return found;
764}
765
Sven Eckelmanna5130882012-05-16 20:23:16 +0200766static void
Antonio Quartullid657e622012-07-01 14:09:12 +0200767batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
Sven Eckelmann56303d32012-06-05 22:31:31 +0200768 struct batadv_orig_node *orig_node, int ttvn)
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200769{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200770 struct batadv_tt_orig_list_entry *orig_entry;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200771
Antonio Quartullid657e622012-07-01 14:09:12 +0200772 orig_entry = batadv_tt_global_orig_entry_find(tt_global, orig_node);
Antonio Quartulli30cfd022012-07-05 23:38:29 +0200773 if (orig_entry) {
774 /* refresh the ttvn: the current value could be a bogus one that
775 * was added during a "temporary client detection"
776 */
777 orig_entry->ttvn = ttvn;
Antonio Quartullid657e622012-07-01 14:09:12 +0200778 goto out;
Antonio Quartulli30cfd022012-07-05 23:38:29 +0200779 }
Antonio Quartullid657e622012-07-01 14:09:12 +0200780
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200781 orig_entry = kzalloc(sizeof(*orig_entry), GFP_ATOMIC);
782 if (!orig_entry)
Antonio Quartullid657e622012-07-01 14:09:12 +0200783 goto out;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200784
785 INIT_HLIST_NODE(&orig_entry->list);
786 atomic_inc(&orig_node->refcount);
787 atomic_inc(&orig_node->tt_size);
788 orig_entry->orig_node = orig_node;
789 orig_entry->ttvn = ttvn;
Antonio Quartullid657e622012-07-01 14:09:12 +0200790 atomic_set(&orig_entry->refcount, 2);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200791
Antonio Quartullid657e622012-07-01 14:09:12 +0200792 spin_lock_bh(&tt_global->list_lock);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200793 hlist_add_head_rcu(&orig_entry->list,
Antonio Quartullid657e622012-07-01 14:09:12 +0200794 &tt_global->orig_list);
795 spin_unlock_bh(&tt_global->list_lock);
796out:
797 if (orig_entry)
798 batadv_tt_orig_list_entry_free_ref(orig_entry);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200799}
800
Antonio Quartullid4ff40f2013-04-18 15:13:01 +0200801/**
802 * batadv_tt_global_add - add a new TT global entry or update an existing one
803 * @bat_priv: the bat priv with all the soft interface information
804 * @orig_node: the originator announcing the client
805 * @tt_addr: the mac address of the non-mesh client
806 * @flags: TT flags that have to be set for this non-mesh client
807 * @ttvn: the tt version number ever announcing this non-mesh client
808 *
809 * Add a new TT global entry for the given originator. If the entry already
810 * exists add a new reference to the given originator (a global entry can have
811 * references to multiple originators) and adjust the flags attribute to reflect
812 * the function argument.
813 * If a TT local entry exists for this non-mesh client remove it.
814 *
815 * The caller must hold orig_node refcount.
816 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200817int batadv_tt_global_add(struct batadv_priv *bat_priv,
818 struct batadv_orig_node *orig_node,
Antonio Quartullid4ff40f2013-04-18 15:13:01 +0200819 const unsigned char *tt_addr, uint16_t flags,
Antonio Quartullid4f44692012-05-25 00:00:54 +0200820 uint8_t ttvn)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000821{
Sven Eckelmann170173b2012-10-07 12:02:22 +0200822 struct batadv_tt_global_entry *tt_global_entry;
823 struct batadv_tt_local_entry *tt_local_entry;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200824 int ret = 0;
Simon Wunderlich80b3f582011-11-02 20:26:45 +0100825 int hash_added;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200826 struct batadv_tt_common_entry *common;
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200827 uint16_t local_flags;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000828
Sven Eckelmanna5130882012-05-16 20:23:16 +0200829 tt_global_entry = batadv_tt_global_hash_find(bat_priv, tt_addr);
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200830 tt_local_entry = batadv_tt_local_hash_find(bat_priv, tt_addr);
831
832 /* if the node already has a local client for this entry, it has to wait
833 * for a roaming advertisement instead of manually messing up the global
834 * table
835 */
836 if ((flags & BATADV_TT_CLIENT_TEMP) && tt_local_entry &&
837 !(tt_local_entry->common.flags & BATADV_TT_CLIENT_NEW))
838 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000839
Antonio Quartullia73105b2011-04-27 14:27:44 +0200840 if (!tt_global_entry) {
Antonio Quartullid4f44692012-05-25 00:00:54 +0200841 tt_global_entry = kzalloc(sizeof(*tt_global_entry), GFP_ATOMIC);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200842 if (!tt_global_entry)
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200843 goto out;
844
Sven Eckelmannc0a55922012-05-12 13:48:55 +0200845 common = &tt_global_entry->common;
846 memcpy(common->addr, tt_addr, ETH_ALEN);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200847
Antonio Quartullid4f44692012-05-25 00:00:54 +0200848 common->flags = flags;
Antonio Quartullicc47f662011-04-27 14:27:57 +0200849 tt_global_entry->roam_at = 0;
Antonio Quartullifdf79322012-08-24 17:54:07 +0200850 /* node must store current time in case of roaming. This is
851 * needed to purge this entry out on timeout (if nobody claims
852 * it)
853 */
854 if (flags & BATADV_TT_CLIENT_ROAM)
855 tt_global_entry->roam_at = jiffies;
Sven Eckelmannc0a55922012-05-12 13:48:55 +0200856 atomic_set(&common->refcount, 2);
Antonio Quartulli30cfd022012-07-05 23:38:29 +0200857 common->added_at = jiffies;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200858
859 INIT_HLIST_HEAD(&tt_global_entry->orig_list);
860 spin_lock_init(&tt_global_entry->list_lock);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200861
Sven Eckelmann807736f2012-07-15 22:26:51 +0200862 hash_added = batadv_hash_add(bat_priv->tt.global_hash,
Sven Eckelmanna5130882012-05-16 20:23:16 +0200863 batadv_compare_tt,
864 batadv_choose_orig, common,
865 &common->hash_entry);
Simon Wunderlich80b3f582011-11-02 20:26:45 +0100866
867 if (unlikely(hash_added != 0)) {
868 /* remove the reference for the hash */
Sven Eckelmanna5130882012-05-16 20:23:16 +0200869 batadv_tt_global_entry_free_ref(tt_global_entry);
Simon Wunderlich80b3f582011-11-02 20:26:45 +0100870 goto out_remove;
871 }
Antonio Quartullia73105b2011-04-27 14:27:44 +0200872 } else {
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200873 common = &tt_global_entry->common;
Antonio Quartulli30cfd022012-07-05 23:38:29 +0200874 /* If there is already a global entry, we can use this one for
875 * our processing.
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200876 * But if we are trying to add a temporary client then here are
877 * two options at this point:
878 * 1) the global client is not a temporary client: the global
879 * client has to be left as it is, temporary information
880 * should never override any already known client state
881 * 2) the global client is a temporary client: purge the
882 * originator list and add the new one orig_entry
Antonio Quartulli30cfd022012-07-05 23:38:29 +0200883 */
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200884 if (flags & BATADV_TT_CLIENT_TEMP) {
885 if (!(common->flags & BATADV_TT_CLIENT_TEMP))
886 goto out;
887 if (batadv_tt_global_entry_has_orig(tt_global_entry,
888 orig_node))
889 goto out_remove;
890 batadv_tt_global_del_orig_list(tt_global_entry);
891 goto add_orig_entry;
892 }
Antonio Quartulli30cfd022012-07-05 23:38:29 +0200893
894 /* if the client was temporary added before receiving the first
895 * OGM announcing it, we have to clear the TEMP flag
896 */
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200897 common->flags &= ~BATADV_TT_CLIENT_TEMP;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200898
Antonio Quartullie9c001362012-11-07 15:05:33 +0100899 /* the change can carry possible "attribute" flags like the
900 * TT_CLIENT_WIFI, therefore they have to be copied in the
901 * client entry
902 */
903 tt_global_entry->common.flags |= flags;
904
Sven Eckelmannacd34af2012-06-03 22:19:21 +0200905 /* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only
906 * one originator left in the list and we previously received a
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200907 * delete + roaming change for this originator.
908 *
909 * We should first delete the old originator before adding the
910 * new one.
911 */
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200912 if (common->flags & BATADV_TT_CLIENT_ROAM) {
Sven Eckelmanna5130882012-05-16 20:23:16 +0200913 batadv_tt_global_del_orig_list(tt_global_entry);
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200914 common->flags &= ~BATADV_TT_CLIENT_ROAM;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200915 tt_global_entry->roam_at = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000916 }
917 }
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200918add_orig_entry:
Antonio Quartulli30cfd022012-07-05 23:38:29 +0200919 /* add the new orig_entry (if needed) or update it */
Antonio Quartullid657e622012-07-01 14:09:12 +0200920 batadv_tt_global_orig_entry_add(tt_global_entry, orig_node, ttvn);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200921
Sven Eckelmann39c75a52012-06-03 22:19:22 +0200922 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200923 "Creating new global tt entry: %pM (via %pM)\n",
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200924 common->addr, orig_node->orig);
Antonio Quartullic10dba02012-08-11 11:11:00 +0200925 ret = 1;
Antonio Quartullia73105b2011-04-27 14:27:44 +0200926
Simon Wunderlich80b3f582011-11-02 20:26:45 +0100927out_remove:
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200928
Antonio Quartullia73105b2011-04-27 14:27:44 +0200929 /* remove address from local hash if present */
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200930 local_flags = batadv_tt_local_remove(bat_priv, tt_addr,
931 "global tt received",
Antonio Quartullic1d07432013-01-15 22:17:19 +1000932 flags & BATADV_TT_CLIENT_ROAM);
Antonio Quartulli7f91d062012-08-27 11:44:43 +0200933 tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI;
934
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200935 if (!(flags & BATADV_TT_CLIENT_ROAM))
936 /* this is a normal global add. Therefore the client is not in a
937 * roaming state anymore.
938 */
939 tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM;
940
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200941out:
942 if (tt_global_entry)
Sven Eckelmanna5130882012-05-16 20:23:16 +0200943 batadv_tt_global_entry_free_ref(tt_global_entry);
Antonio Quartulli068ee6e2012-09-23 22:38:37 +0200944 if (tt_local_entry)
945 batadv_tt_local_entry_free_ref(tt_local_entry);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +0200946 return ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000947}
948
Sven Eckelmann981d8902012-10-07 13:34:15 +0200949/* batadv_transtable_best_orig - Get best originator list entry from tt entry
950 * @tt_global_entry: global translation table entry to be analyzed
951 *
952 * This functon assumes the caller holds rcu_read_lock().
953 * Returns best originator list entry or NULL on errors.
954 */
955static struct batadv_tt_orig_list_entry *
956batadv_transtable_best_orig(struct batadv_tt_global_entry *tt_global_entry)
957{
958 struct batadv_neigh_node *router = NULL;
959 struct hlist_head *head;
Sven Eckelmann981d8902012-10-07 13:34:15 +0200960 struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL;
961 int best_tq = 0;
962
963 head = &tt_global_entry->orig_list;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800964 hlist_for_each_entry_rcu(orig_entry, head, list) {
Sven Eckelmann981d8902012-10-07 13:34:15 +0200965 router = batadv_orig_node_get_router(orig_entry->orig_node);
966 if (!router)
967 continue;
968
969 if (router->tq_avg > best_tq) {
970 best_entry = orig_entry;
971 best_tq = router->tq_avg;
972 }
973
974 batadv_neigh_node_free_ref(router);
975 }
976
977 return best_entry;
978}
979
980/* batadv_tt_global_print_entry - print all orig nodes who announce the address
981 * for this global entry
982 * @tt_global_entry: global translation table entry to be printed
983 * @seq: debugfs table seq_file struct
984 *
985 * This functon assumes the caller holds rcu_read_lock().
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200986 */
Sven Eckelmanna5130882012-05-16 20:23:16 +0200987static void
Sven Eckelmann56303d32012-06-05 22:31:31 +0200988batadv_tt_global_print_entry(struct batadv_tt_global_entry *tt_global_entry,
Sven Eckelmanna5130882012-05-16 20:23:16 +0200989 struct seq_file *seq)
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200990{
991 struct hlist_head *head;
Sven Eckelmann981d8902012-10-07 13:34:15 +0200992 struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
Sven Eckelmann56303d32012-06-05 22:31:31 +0200993 struct batadv_tt_common_entry *tt_common_entry;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +0200994 uint16_t flags;
995 uint8_t last_ttvn;
996
997 tt_common_entry = &tt_global_entry->common;
Sven Eckelmann981d8902012-10-07 13:34:15 +0200998 flags = tt_common_entry->flags;
999
1000 best_entry = batadv_transtable_best_orig(tt_global_entry);
1001 if (best_entry) {
1002 last_ttvn = atomic_read(&best_entry->orig_node->last_ttvn);
Antonio Quartullif9d8a532012-11-19 09:01:42 +01001003 seq_printf(seq,
1004 " %c %pM (%3u) via %pM (%3u) (%#.4x) [%c%c%c]\n",
Sven Eckelmann981d8902012-10-07 13:34:15 +02001005 '*', tt_global_entry->common.addr,
1006 best_entry->ttvn, best_entry->orig_node->orig,
Antonio Quartullif9d8a532012-11-19 09:01:42 +01001007 last_ttvn, best_entry->orig_node->tt_crc,
Sven Eckelmann981d8902012-10-07 13:34:15 +02001008 (flags & BATADV_TT_CLIENT_ROAM ? 'R' : '.'),
1009 (flags & BATADV_TT_CLIENT_WIFI ? 'W' : '.'),
1010 (flags & BATADV_TT_CLIENT_TEMP ? 'T' : '.'));
1011 }
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001012
1013 head = &tt_global_entry->orig_list;
1014
Sasha Levinb67bfe02013-02-27 17:06:00 -08001015 hlist_for_each_entry_rcu(orig_entry, head, list) {
Sven Eckelmann981d8902012-10-07 13:34:15 +02001016 if (best_entry == orig_entry)
1017 continue;
1018
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001019 last_ttvn = atomic_read(&orig_entry->orig_node->last_ttvn);
Sven Eckelmann981d8902012-10-07 13:34:15 +02001020 seq_printf(seq, " %c %pM (%3u) via %pM (%3u) [%c%c%c]\n",
1021 '+', tt_global_entry->common.addr,
1022 orig_entry->ttvn, orig_entry->orig_node->orig,
1023 last_ttvn,
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001024 (flags & BATADV_TT_CLIENT_ROAM ? 'R' : '.'),
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001025 (flags & BATADV_TT_CLIENT_WIFI ? 'W' : '.'),
1026 (flags & BATADV_TT_CLIENT_TEMP ? 'T' : '.'));
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001027 }
1028}
1029
Sven Eckelmann08c36d32012-05-12 02:09:39 +02001030int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001031{
1032 struct net_device *net_dev = (struct net_device *)seq->private;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001033 struct batadv_priv *bat_priv = netdev_priv(net_dev);
Sven Eckelmann807736f2012-07-15 22:26:51 +02001034 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001035 struct batadv_tt_common_entry *tt_common_entry;
1036 struct batadv_tt_global_entry *tt_global;
1037 struct batadv_hard_iface *primary_if;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001038 struct hlist_head *head;
Antonio Quartullic90681b2011-10-05 17:05:25 +02001039 uint32_t i;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001040
Marek Lindner30da63a2012-08-03 17:15:46 +02001041 primary_if = batadv_seq_print_text_primary_if_get(seq);
1042 if (!primary_if)
Marek Lindner32ae9b22011-04-20 15:40:58 +02001043 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001044
Antonio Quartulli2dafb492011-05-05 08:42:45 +02001045 seq_printf(seq,
1046 "Globally announced TT entries received via the mesh %s\n",
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001047 net_dev->name);
Antonio Quartullif9d8a532012-11-19 09:01:42 +01001048 seq_printf(seq, " %-13s %s %-15s %s (%-6s) %s\n",
1049 "Client", "(TTVN)", "Originator", "(Curr TTVN)", "CRC",
1050 "Flags");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001051
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001052 for (i = 0; i < hash->size; i++) {
1053 head = &hash->table[i];
1054
Marek Lindner7aadf882011-02-18 12:28:09 +00001055 rcu_read_lock();
Sasha Levinb67bfe02013-02-27 17:06:00 -08001056 hlist_for_each_entry_rcu(tt_common_entry,
Marek Lindner7aadf882011-02-18 12:28:09 +00001057 head, hash_entry) {
Sven Eckelmann56303d32012-06-05 22:31:31 +02001058 tt_global = container_of(tt_common_entry,
1059 struct batadv_tt_global_entry,
1060 common);
1061 batadv_tt_global_print_entry(tt_global, seq);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001062 }
Marek Lindner7aadf882011-02-18 12:28:09 +00001063 rcu_read_unlock();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001064 }
Marek Lindner32ae9b22011-04-20 15:40:58 +02001065out:
1066 if (primary_if)
Sven Eckelmanne5d89252012-05-12 13:48:54 +02001067 batadv_hardif_free_ref(primary_if);
Marek Lindner30da63a2012-08-03 17:15:46 +02001068 return 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001069}
1070
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001071/* deletes the orig list of a tt_global_entry */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001072static void
Sven Eckelmann56303d32012-06-05 22:31:31 +02001073batadv_tt_global_del_orig_list(struct batadv_tt_global_entry *tt_global_entry)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001074{
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001075 struct hlist_head *head;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001076 struct hlist_node *safe;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001077 struct batadv_tt_orig_list_entry *orig_entry;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001078
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001079 spin_lock_bh(&tt_global_entry->list_lock);
1080 head = &tt_global_entry->orig_list;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001081 hlist_for_each_entry_safe(orig_entry, safe, head, list) {
1082 hlist_del_rcu(&orig_entry->list);
Sven Eckelmanna5130882012-05-16 20:23:16 +02001083 batadv_tt_orig_list_entry_free_ref(orig_entry);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001084 }
1085 spin_unlock_bh(&tt_global_entry->list_lock);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001086}
1087
Sven Eckelmanna5130882012-05-16 20:23:16 +02001088static void
Sven Eckelmann56303d32012-06-05 22:31:31 +02001089batadv_tt_global_del_orig_entry(struct batadv_priv *bat_priv,
1090 struct batadv_tt_global_entry *tt_global_entry,
1091 struct batadv_orig_node *orig_node,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001092 const char *message)
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001093{
1094 struct hlist_head *head;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001095 struct hlist_node *safe;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001096 struct batadv_tt_orig_list_entry *orig_entry;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001097
1098 spin_lock_bh(&tt_global_entry->list_lock);
1099 head = &tt_global_entry->orig_list;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001100 hlist_for_each_entry_safe(orig_entry, safe, head, list) {
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001101 if (orig_entry->orig_node == orig_node) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001102 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02001103 "Deleting %pM from global tt entry %pM: %s\n",
1104 orig_node->orig,
1105 tt_global_entry->common.addr, message);
Sasha Levinb67bfe02013-02-27 17:06:00 -08001106 hlist_del_rcu(&orig_entry->list);
Sven Eckelmanna5130882012-05-16 20:23:16 +02001107 batadv_tt_orig_list_entry_free_ref(orig_entry);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001108 }
1109 }
1110 spin_unlock_bh(&tt_global_entry->list_lock);
1111}
1112
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001113/* If the client is to be deleted, we check if it is the last origantor entry
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001114 * within tt_global entry. If yes, we set the BATADV_TT_CLIENT_ROAM flag and the
1115 * timer, otherwise we simply remove the originator scheduled for deletion.
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001116 */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001117static void
Sven Eckelmann56303d32012-06-05 22:31:31 +02001118batadv_tt_global_del_roaming(struct batadv_priv *bat_priv,
1119 struct batadv_tt_global_entry *tt_global_entry,
1120 struct batadv_orig_node *orig_node,
1121 const char *message)
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001122{
1123 bool last_entry = true;
1124 struct hlist_head *head;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001125 struct batadv_tt_orig_list_entry *orig_entry;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001126
1127 /* no local entry exists, case 1:
1128 * Check if this is the last one or if other entries exist.
1129 */
1130
1131 rcu_read_lock();
1132 head = &tt_global_entry->orig_list;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001133 hlist_for_each_entry_rcu(orig_entry, head, list) {
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001134 if (orig_entry->orig_node != orig_node) {
1135 last_entry = false;
1136 break;
1137 }
1138 }
1139 rcu_read_unlock();
1140
1141 if (last_entry) {
1142 /* its the last one, mark for roaming. */
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001143 tt_global_entry->common.flags |= BATADV_TT_CLIENT_ROAM;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001144 tt_global_entry->roam_at = jiffies;
1145 } else
1146 /* there is another entry, we can simply delete this
1147 * one and can still use the other one.
1148 */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001149 batadv_tt_global_del_orig_entry(bat_priv, tt_global_entry,
1150 orig_node, message);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001151}
1152
1153
1154
Sven Eckelmann56303d32012-06-05 22:31:31 +02001155static void batadv_tt_global_del(struct batadv_priv *bat_priv,
1156 struct batadv_orig_node *orig_node,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001157 const unsigned char *addr,
1158 const char *message, bool roaming)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001159{
Sven Eckelmann170173b2012-10-07 12:02:22 +02001160 struct batadv_tt_global_entry *tt_global_entry;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001161 struct batadv_tt_local_entry *local_entry = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001162
Sven Eckelmanna5130882012-05-16 20:23:16 +02001163 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001164 if (!tt_global_entry)
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001165 goto out;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001166
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001167 if (!roaming) {
Sven Eckelmanna5130882012-05-16 20:23:16 +02001168 batadv_tt_global_del_orig_entry(bat_priv, tt_global_entry,
1169 orig_node, message);
Sven Eckelmann92f90f52011-12-22 20:31:12 +08001170
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001171 if (hlist_empty(&tt_global_entry->orig_list))
Antonio Quartullibe73b482012-09-23 22:38:36 +02001172 batadv_tt_global_free(bat_priv, tt_global_entry,
1173 message);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001174
Sven Eckelmann92f90f52011-12-22 20:31:12 +08001175 goto out;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001176 }
Sven Eckelmann92f90f52011-12-22 20:31:12 +08001177
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001178 /* if we are deleting a global entry due to a roam
1179 * event, there are two possibilities:
1180 * 1) the client roamed from node A to node B => if there
1181 * is only one originator left for this client, we mark
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001182 * it with BATADV_TT_CLIENT_ROAM, we start a timer and we
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001183 * wait for node B to claim it. In case of timeout
1184 * the entry is purged.
1185 *
1186 * If there are other originators left, we directly delete
1187 * the originator.
1188 * 2) the client roamed to us => we can directly delete
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001189 * the global entry, since it is useless now.
1190 */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001191 local_entry = batadv_tt_local_hash_find(bat_priv,
1192 tt_global_entry->common.addr);
1193 if (local_entry) {
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001194 /* local entry exists, case 2: client roamed to us. */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001195 batadv_tt_global_del_orig_list(tt_global_entry);
Antonio Quartullibe73b482012-09-23 22:38:36 +02001196 batadv_tt_global_free(bat_priv, tt_global_entry, message);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001197 } else
1198 /* no local entry exists, case 1: check for roaming */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001199 batadv_tt_global_del_roaming(bat_priv, tt_global_entry,
1200 orig_node, message);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001201
Sven Eckelmann92f90f52011-12-22 20:31:12 +08001202
Antonio Quartullicc47f662011-04-27 14:27:57 +02001203out:
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001204 if (tt_global_entry)
Sven Eckelmanna5130882012-05-16 20:23:16 +02001205 batadv_tt_global_entry_free_ref(tt_global_entry);
1206 if (local_entry)
1207 batadv_tt_local_entry_free_ref(local_entry);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001208}
1209
Sven Eckelmann56303d32012-06-05 22:31:31 +02001210void batadv_tt_global_del_orig(struct batadv_priv *bat_priv,
1211 struct batadv_orig_node *orig_node,
1212 const char *message)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001213{
Sven Eckelmann56303d32012-06-05 22:31:31 +02001214 struct batadv_tt_global_entry *tt_global;
1215 struct batadv_tt_common_entry *tt_common_entry;
Antonio Quartullic90681b2011-10-05 17:05:25 +02001216 uint32_t i;
Sven Eckelmann807736f2012-07-15 22:26:51 +02001217 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001218 struct hlist_node *safe;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001219 struct hlist_head *head;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001220 spinlock_t *list_lock; /* protects write access to the hash lists */
Antonio Quartullia73105b2011-04-27 14:27:44 +02001221
Simon Wunderlich6e801492011-10-19 10:28:26 +02001222 if (!hash)
1223 return;
1224
Antonio Quartullia73105b2011-04-27 14:27:44 +02001225 for (i = 0; i < hash->size; i++) {
1226 head = &hash->table[i];
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001227 list_lock = &hash->list_locks[i];
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001228
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001229 spin_lock_bh(list_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -08001230 hlist_for_each_entry_safe(tt_common_entry, safe,
Sven Eckelmann7c64fd92012-02-28 10:55:36 +01001231 head, hash_entry) {
Sven Eckelmann56303d32012-06-05 22:31:31 +02001232 tt_global = container_of(tt_common_entry,
1233 struct batadv_tt_global_entry,
1234 common);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001235
Sven Eckelmann56303d32012-06-05 22:31:31 +02001236 batadv_tt_global_del_orig_entry(bat_priv, tt_global,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001237 orig_node, message);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001238
Sven Eckelmann56303d32012-06-05 22:31:31 +02001239 if (hlist_empty(&tt_global->orig_list)) {
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001240 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02001241 "Deleting global tt entry %pM: %s\n",
Sven Eckelmann56303d32012-06-05 22:31:31 +02001242 tt_global->common.addr, message);
Sasha Levinb67bfe02013-02-27 17:06:00 -08001243 hlist_del_rcu(&tt_common_entry->hash_entry);
Sven Eckelmann56303d32012-06-05 22:31:31 +02001244 batadv_tt_global_entry_free_ref(tt_global);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001245 }
Antonio Quartullia73105b2011-04-27 14:27:44 +02001246 }
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001247 spin_unlock_bh(list_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001248 }
Antonio Quartulli17071572011-11-07 16:36:40 +01001249 orig_node->tt_initialised = false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001250}
1251
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001252static bool batadv_tt_global_to_purge(struct batadv_tt_global_entry *tt_global,
1253 char **msg)
Antonio Quartullicc47f662011-04-27 14:27:57 +02001254{
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001255 bool purge = false;
1256 unsigned long roam_timeout = BATADV_TT_CLIENT_ROAM_TIMEOUT;
1257 unsigned long temp_timeout = BATADV_TT_CLIENT_TEMP_TIMEOUT;
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001258
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001259 if ((tt_global->common.flags & BATADV_TT_CLIENT_ROAM) &&
1260 batadv_has_timed_out(tt_global->roam_at, roam_timeout)) {
1261 purge = true;
1262 *msg = "Roaming timeout\n";
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001263 }
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001264
1265 if ((tt_global->common.flags & BATADV_TT_CLIENT_TEMP) &&
1266 batadv_has_timed_out(tt_global->common.added_at, temp_timeout)) {
1267 purge = true;
1268 *msg = "Temporary client timeout\n";
1269 }
1270
1271 return purge;
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001272}
1273
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001274static void batadv_tt_global_purge(struct batadv_priv *bat_priv)
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001275{
Sven Eckelmann807736f2012-07-15 22:26:51 +02001276 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
Antonio Quartullicc47f662011-04-27 14:27:57 +02001277 struct hlist_head *head;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001278 struct hlist_node *node_tmp;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001279 spinlock_t *list_lock; /* protects write access to the hash lists */
Antonio Quartullic90681b2011-10-05 17:05:25 +02001280 uint32_t i;
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001281 char *msg = NULL;
1282 struct batadv_tt_common_entry *tt_common;
1283 struct batadv_tt_global_entry *tt_global;
Antonio Quartullicc47f662011-04-27 14:27:57 +02001284
Antonio Quartullicc47f662011-04-27 14:27:57 +02001285 for (i = 0; i < hash->size; i++) {
1286 head = &hash->table[i];
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001287 list_lock = &hash->list_locks[i];
Antonio Quartullicc47f662011-04-27 14:27:57 +02001288
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001289 spin_lock_bh(list_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -08001290 hlist_for_each_entry_safe(tt_common, node_tmp, head,
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001291 hash_entry) {
1292 tt_global = container_of(tt_common,
1293 struct batadv_tt_global_entry,
1294 common);
1295
1296 if (!batadv_tt_global_to_purge(tt_global, &msg))
1297 continue;
1298
1299 batadv_dbg(BATADV_DBG_TT, bat_priv,
1300 "Deleting global tt entry (%pM): %s\n",
1301 tt_global->common.addr, msg);
1302
Sasha Levinb67bfe02013-02-27 17:06:00 -08001303 hlist_del_rcu(&tt_common->hash_entry);
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001304
1305 batadv_tt_global_entry_free_ref(tt_global);
1306 }
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001307 spin_unlock_bh(list_lock);
Antonio Quartullicc47f662011-04-27 14:27:57 +02001308 }
Antonio Quartullicc47f662011-04-27 14:27:57 +02001309}
1310
Sven Eckelmann56303d32012-06-05 22:31:31 +02001311static void batadv_tt_global_table_free(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001312{
Sven Eckelmann5bf74e92012-06-05 22:31:28 +02001313 struct batadv_hashtable *hash;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001314 spinlock_t *list_lock; /* protects write access to the hash lists */
Sven Eckelmann56303d32012-06-05 22:31:31 +02001315 struct batadv_tt_common_entry *tt_common_entry;
1316 struct batadv_tt_global_entry *tt_global;
Sasha Levinb67bfe02013-02-27 17:06:00 -08001317 struct hlist_node *node_tmp;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001318 struct hlist_head *head;
Antonio Quartullic90681b2011-10-05 17:05:25 +02001319 uint32_t i;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001320
Sven Eckelmann807736f2012-07-15 22:26:51 +02001321 if (!bat_priv->tt.global_hash)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001322 return;
1323
Sven Eckelmann807736f2012-07-15 22:26:51 +02001324 hash = bat_priv->tt.global_hash;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001325
1326 for (i = 0; i < hash->size; i++) {
1327 head = &hash->table[i];
1328 list_lock = &hash->list_locks[i];
1329
1330 spin_lock_bh(list_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -08001331 hlist_for_each_entry_safe(tt_common_entry, node_tmp,
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001332 head, hash_entry) {
Sasha Levinb67bfe02013-02-27 17:06:00 -08001333 hlist_del_rcu(&tt_common_entry->hash_entry);
Sven Eckelmann56303d32012-06-05 22:31:31 +02001334 tt_global = container_of(tt_common_entry,
1335 struct batadv_tt_global_entry,
1336 common);
1337 batadv_tt_global_entry_free_ref(tt_global);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001338 }
1339 spin_unlock_bh(list_lock);
1340 }
1341
Sven Eckelmann1a8eaf02012-05-12 02:09:32 +02001342 batadv_hash_destroy(hash);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02001343
Sven Eckelmann807736f2012-07-15 22:26:51 +02001344 bat_priv->tt.global_hash = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001345}
1346
Sven Eckelmann56303d32012-06-05 22:31:31 +02001347static bool
1348_batadv_is_ap_isolated(struct batadv_tt_local_entry *tt_local_entry,
1349 struct batadv_tt_global_entry *tt_global_entry)
Antonio Quartulli59b699c2011-07-07 15:35:36 +02001350{
1351 bool ret = false;
1352
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001353 if (tt_local_entry->common.flags & BATADV_TT_CLIENT_WIFI &&
1354 tt_global_entry->common.flags & BATADV_TT_CLIENT_WIFI)
Antonio Quartulli59b699c2011-07-07 15:35:36 +02001355 ret = true;
1356
1357 return ret;
1358}
1359
Sven Eckelmann56303d32012-06-05 22:31:31 +02001360struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
1361 const uint8_t *src,
1362 const uint8_t *addr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001363{
Sven Eckelmann56303d32012-06-05 22:31:31 +02001364 struct batadv_tt_local_entry *tt_local_entry = NULL;
1365 struct batadv_tt_global_entry *tt_global_entry = NULL;
1366 struct batadv_orig_node *orig_node = NULL;
Sven Eckelmann981d8902012-10-07 13:34:15 +02001367 struct batadv_tt_orig_list_entry *best_entry;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001368
Antonio Quartulli3d393e42011-07-07 15:35:37 +02001369 if (src && atomic_read(&bat_priv->ap_isolation)) {
Sven Eckelmanna5130882012-05-16 20:23:16 +02001370 tt_local_entry = batadv_tt_local_hash_find(bat_priv, src);
Antonio Quartulli068ee6e2012-09-23 22:38:37 +02001371 if (!tt_local_entry ||
1372 (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING))
Antonio Quartulli3d393e42011-07-07 15:35:37 +02001373 goto out;
1374 }
Marek Lindner7aadf882011-02-18 12:28:09 +00001375
Sven Eckelmanna5130882012-05-16 20:23:16 +02001376 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr);
Antonio Quartulli2dafb492011-05-05 08:42:45 +02001377 if (!tt_global_entry)
Marek Lindner7b36e8e2011-02-18 12:28:10 +00001378 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001379
Antonio Quartulli3d393e42011-07-07 15:35:37 +02001380 /* check whether the clients should not communicate due to AP
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001381 * isolation
1382 */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001383 if (tt_local_entry &&
1384 _batadv_is_ap_isolated(tt_local_entry, tt_global_entry))
Antonio Quartulli3d393e42011-07-07 15:35:37 +02001385 goto out;
1386
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001387 rcu_read_lock();
Sven Eckelmann981d8902012-10-07 13:34:15 +02001388 best_entry = batadv_transtable_best_orig(tt_global_entry);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001389 /* found anything? */
Sven Eckelmann981d8902012-10-07 13:34:15 +02001390 if (best_entry)
1391 orig_node = best_entry->orig_node;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001392 if (orig_node && !atomic_inc_not_zero(&orig_node->refcount))
1393 orig_node = NULL;
1394 rcu_read_unlock();
Sven Eckelmann981d8902012-10-07 13:34:15 +02001395
Marek Lindner7b36e8e2011-02-18 12:28:10 +00001396out:
Antonio Quartulli3d393e42011-07-07 15:35:37 +02001397 if (tt_global_entry)
Sven Eckelmanna5130882012-05-16 20:23:16 +02001398 batadv_tt_global_entry_free_ref(tt_global_entry);
Antonio Quartulli3d393e42011-07-07 15:35:37 +02001399 if (tt_local_entry)
Sven Eckelmanna5130882012-05-16 20:23:16 +02001400 batadv_tt_local_entry_free_ref(tt_local_entry);
Antonio Quartulli3d393e42011-07-07 15:35:37 +02001401
Marek Lindner7b36e8e2011-02-18 12:28:10 +00001402 return orig_node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001403}
Antonio Quartullia73105b2011-04-27 14:27:44 +02001404
1405/* Calculates the checksum of the local table of a given orig_node */
Sven Eckelmann56303d32012-06-05 22:31:31 +02001406static uint16_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
1407 struct batadv_orig_node *orig_node)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001408{
1409 uint16_t total = 0, total_one;
Sven Eckelmann807736f2012-07-15 22:26:51 +02001410 struct batadv_hashtable *hash = bat_priv->tt.global_hash;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001411 struct batadv_tt_common_entry *tt_common;
1412 struct batadv_tt_global_entry *tt_global;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001413 struct hlist_head *head;
Antonio Quartullic90681b2011-10-05 17:05:25 +02001414 uint32_t i;
1415 int j;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001416
1417 for (i = 0; i < hash->size; i++) {
1418 head = &hash->table[i];
1419
1420 rcu_read_lock();
Sasha Levinb67bfe02013-02-27 17:06:00 -08001421 hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
Sven Eckelmann56303d32012-06-05 22:31:31 +02001422 tt_global = container_of(tt_common,
1423 struct batadv_tt_global_entry,
1424 common);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001425 /* Roaming clients are in the global table for
1426 * consistency only. They don't have to be
1427 * taken into account while computing the
1428 * global crc
1429 */
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001430 if (tt_common->flags & BATADV_TT_CLIENT_ROAM)
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001431 continue;
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001432 /* Temporary clients have not been announced yet, so
1433 * they have to be skipped while computing the global
1434 * crc
1435 */
1436 if (tt_common->flags & BATADV_TT_CLIENT_TEMP)
1437 continue;
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001438
1439 /* find out if this global entry is announced by this
1440 * originator
1441 */
Sven Eckelmann56303d32012-06-05 22:31:31 +02001442 if (!batadv_tt_global_entry_has_orig(tt_global,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001443 orig_node))
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001444 continue;
1445
1446 total_one = 0;
1447 for (j = 0; j < ETH_ALEN; j++)
1448 total_one = crc16_byte(total_one,
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001449 tt_common->addr[j]);
Simon Wunderlichdb08e6e2011-10-22 20:12:51 +02001450 total ^= total_one;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001451 }
1452 rcu_read_unlock();
1453 }
1454
1455 return total;
1456}
1457
1458/* Calculates the checksum of the local table */
Sven Eckelmann56303d32012-06-05 22:31:31 +02001459static uint16_t batadv_tt_local_crc(struct batadv_priv *bat_priv)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001460{
1461 uint16_t total = 0, total_one;
Sven Eckelmann807736f2012-07-15 22:26:51 +02001462 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001463 struct batadv_tt_common_entry *tt_common;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001464 struct hlist_head *head;
Antonio Quartullic90681b2011-10-05 17:05:25 +02001465 uint32_t i;
1466 int j;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001467
1468 for (i = 0; i < hash->size; i++) {
1469 head = &hash->table[i];
1470
1471 rcu_read_lock();
Sasha Levinb67bfe02013-02-27 17:06:00 -08001472 hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
Antonio Quartulli058d0e22011-07-07 01:40:58 +02001473 /* not yet committed clients have not to be taken into
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001474 * account while computing the CRC
1475 */
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001476 if (tt_common->flags & BATADV_TT_CLIENT_NEW)
Antonio Quartulli058d0e22011-07-07 01:40:58 +02001477 continue;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001478 total_one = 0;
1479 for (j = 0; j < ETH_ALEN; j++)
1480 total_one = crc16_byte(total_one,
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001481 tt_common->addr[j]);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001482 total ^= total_one;
1483 }
Antonio Quartullia73105b2011-04-27 14:27:44 +02001484 rcu_read_unlock();
1485 }
1486
1487 return total;
1488}
1489
Sven Eckelmann56303d32012-06-05 22:31:31 +02001490static void batadv_tt_req_list_free(struct batadv_priv *bat_priv)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001491{
Sven Eckelmann56303d32012-06-05 22:31:31 +02001492 struct batadv_tt_req_node *node, *safe;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001493
Sven Eckelmann807736f2012-07-15 22:26:51 +02001494 spin_lock_bh(&bat_priv->tt.req_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001495
Sven Eckelmann807736f2012-07-15 22:26:51 +02001496 list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
Antonio Quartullia73105b2011-04-27 14:27:44 +02001497 list_del(&node->list);
1498 kfree(node);
1499 }
1500
Sven Eckelmann807736f2012-07-15 22:26:51 +02001501 spin_unlock_bh(&bat_priv->tt.req_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001502}
1503
Sven Eckelmann56303d32012-06-05 22:31:31 +02001504static void batadv_tt_save_orig_buffer(struct batadv_priv *bat_priv,
1505 struct batadv_orig_node *orig_node,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001506 const unsigned char *tt_buff,
1507 uint8_t tt_num_changes)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001508{
Sven Eckelmann08c36d32012-05-12 02:09:39 +02001509 uint16_t tt_buff_len = batadv_tt_len(tt_num_changes);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001510
1511 /* Replace the old buffer only if I received something in the
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001512 * last OGM (the OGM could carry no changes)
1513 */
Antonio Quartullia73105b2011-04-27 14:27:44 +02001514 spin_lock_bh(&orig_node->tt_buff_lock);
1515 if (tt_buff_len > 0) {
1516 kfree(orig_node->tt_buff);
1517 orig_node->tt_buff_len = 0;
1518 orig_node->tt_buff = kmalloc(tt_buff_len, GFP_ATOMIC);
1519 if (orig_node->tt_buff) {
1520 memcpy(orig_node->tt_buff, tt_buff, tt_buff_len);
1521 orig_node->tt_buff_len = tt_buff_len;
1522 }
1523 }
1524 spin_unlock_bh(&orig_node->tt_buff_lock);
1525}
1526
Sven Eckelmann56303d32012-06-05 22:31:31 +02001527static void batadv_tt_req_purge(struct batadv_priv *bat_priv)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001528{
Sven Eckelmann56303d32012-06-05 22:31:31 +02001529 struct batadv_tt_req_node *node, *safe;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001530
Sven Eckelmann807736f2012-07-15 22:26:51 +02001531 spin_lock_bh(&bat_priv->tt.req_list_lock);
1532 list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001533 if (batadv_has_timed_out(node->issued_at,
1534 BATADV_TT_REQUEST_TIMEOUT)) {
Antonio Quartullia73105b2011-04-27 14:27:44 +02001535 list_del(&node->list);
1536 kfree(node);
1537 }
1538 }
Sven Eckelmann807736f2012-07-15 22:26:51 +02001539 spin_unlock_bh(&bat_priv->tt.req_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001540}
1541
1542/* returns the pointer to the new tt_req_node struct if no request
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001543 * has already been issued for this orig_node, NULL otherwise
1544 */
Sven Eckelmann56303d32012-06-05 22:31:31 +02001545static struct batadv_tt_req_node *
1546batadv_new_tt_req_node(struct batadv_priv *bat_priv,
1547 struct batadv_orig_node *orig_node)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001548{
Sven Eckelmann56303d32012-06-05 22:31:31 +02001549 struct batadv_tt_req_node *tt_req_node_tmp, *tt_req_node = NULL;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001550
Sven Eckelmann807736f2012-07-15 22:26:51 +02001551 spin_lock_bh(&bat_priv->tt.req_list_lock);
1552 list_for_each_entry(tt_req_node_tmp, &bat_priv->tt.req_list, list) {
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02001553 if (batadv_compare_eth(tt_req_node_tmp, orig_node) &&
1554 !batadv_has_timed_out(tt_req_node_tmp->issued_at,
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001555 BATADV_TT_REQUEST_TIMEOUT))
Antonio Quartullia73105b2011-04-27 14:27:44 +02001556 goto unlock;
1557 }
1558
1559 tt_req_node = kmalloc(sizeof(*tt_req_node), GFP_ATOMIC);
1560 if (!tt_req_node)
1561 goto unlock;
1562
1563 memcpy(tt_req_node->addr, orig_node->orig, ETH_ALEN);
1564 tt_req_node->issued_at = jiffies;
1565
Sven Eckelmann807736f2012-07-15 22:26:51 +02001566 list_add(&tt_req_node->list, &bat_priv->tt.req_list);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001567unlock:
Sven Eckelmann807736f2012-07-15 22:26:51 +02001568 spin_unlock_bh(&bat_priv->tt.req_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001569 return tt_req_node;
1570}
1571
Antonio Quartulli058d0e22011-07-07 01:40:58 +02001572/* data_ptr is useless here, but has to be kept to respect the prototype */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001573static int batadv_tt_local_valid_entry(const void *entry_ptr,
1574 const void *data_ptr)
Antonio Quartulli058d0e22011-07-07 01:40:58 +02001575{
Sven Eckelmann56303d32012-06-05 22:31:31 +02001576 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02001577
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001578 if (tt_common_entry->flags & BATADV_TT_CLIENT_NEW)
Antonio Quartulli058d0e22011-07-07 01:40:58 +02001579 return 0;
1580 return 1;
1581}
1582
Sven Eckelmanna5130882012-05-16 20:23:16 +02001583static int batadv_tt_global_valid(const void *entry_ptr,
1584 const void *data_ptr)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001585{
Sven Eckelmann56303d32012-06-05 22:31:31 +02001586 const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
1587 const struct batadv_tt_global_entry *tt_global_entry;
1588 const struct batadv_orig_node *orig_node = data_ptr;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001589
Antonio Quartulli30cfd022012-07-05 23:38:29 +02001590 if (tt_common_entry->flags & BATADV_TT_CLIENT_ROAM ||
1591 tt_common_entry->flags & BATADV_TT_CLIENT_TEMP)
Antonio Quartullicc47f662011-04-27 14:27:57 +02001592 return 0;
1593
Sven Eckelmann56303d32012-06-05 22:31:31 +02001594 tt_global_entry = container_of(tt_common_entry,
1595 struct batadv_tt_global_entry,
Antonio Quartulli48100ba2011-10-30 12:17:33 +01001596 common);
1597
Sven Eckelmanna5130882012-05-16 20:23:16 +02001598 return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001599}
1600
Sven Eckelmanna5130882012-05-16 20:23:16 +02001601static struct sk_buff *
1602batadv_tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
Sven Eckelmann5bf74e92012-06-05 22:31:28 +02001603 struct batadv_hashtable *hash,
Marek Lindner736292c2013-01-12 19:19:06 +08001604 struct batadv_priv *bat_priv,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001605 int (*valid_cb)(const void *, const void *),
1606 void *cb_data)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001607{
Sven Eckelmann56303d32012-06-05 22:31:31 +02001608 struct batadv_tt_common_entry *tt_common_entry;
Sven Eckelmann96412692012-06-05 22:31:30 +02001609 struct batadv_tt_query_packet *tt_response;
1610 struct batadv_tt_change *tt_change;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001611 struct hlist_head *head;
1612 struct sk_buff *skb = NULL;
1613 uint16_t tt_tot, tt_count;
Sven Eckelmann96412692012-06-05 22:31:30 +02001614 ssize_t tt_query_size = sizeof(struct batadv_tt_query_packet);
Antonio Quartullic90681b2011-10-05 17:05:25 +02001615 uint32_t i;
Sven Eckelmann96412692012-06-05 22:31:30 +02001616 size_t len;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001617
Marek Lindner736292c2013-01-12 19:19:06 +08001618 if (tt_query_size + tt_len > bat_priv->soft_iface->mtu) {
1619 tt_len = bat_priv->soft_iface->mtu - tt_query_size;
Sven Eckelmann96412692012-06-05 22:31:30 +02001620 tt_len -= tt_len % sizeof(struct batadv_tt_change);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001621 }
Sven Eckelmann96412692012-06-05 22:31:30 +02001622 tt_tot = tt_len / sizeof(struct batadv_tt_change);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001623
Sven Eckelmann96412692012-06-05 22:31:30 +02001624 len = tt_query_size + tt_len;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02001625 skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001626 if (!skb)
1627 goto out;
1628
Simon Wunderlichc54f38c92013-07-29 17:56:44 +02001629 skb->priority = TC_PRIO_CONTROL;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02001630 skb_reserve(skb, ETH_HLEN);
Sven Eckelmann96412692012-06-05 22:31:30 +02001631 tt_response = (struct batadv_tt_query_packet *)skb_put(skb, len);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001632 tt_response->ttvn = ttvn;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001633
Sven Eckelmann96412692012-06-05 22:31:30 +02001634 tt_change = (struct batadv_tt_change *)(skb->data + tt_query_size);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001635 tt_count = 0;
1636
1637 rcu_read_lock();
1638 for (i = 0; i < hash->size; i++) {
1639 head = &hash->table[i];
1640
Sasha Levinb67bfe02013-02-27 17:06:00 -08001641 hlist_for_each_entry_rcu(tt_common_entry,
Antonio Quartullia73105b2011-04-27 14:27:44 +02001642 head, hash_entry) {
1643 if (tt_count == tt_tot)
1644 break;
1645
Antonio Quartulli48100ba2011-10-30 12:17:33 +01001646 if ((valid_cb) && (!valid_cb(tt_common_entry, cb_data)))
Antonio Quartullia73105b2011-04-27 14:27:44 +02001647 continue;
1648
Antonio Quartulli48100ba2011-10-30 12:17:33 +01001649 memcpy(tt_change->addr, tt_common_entry->addr,
1650 ETH_ALEN);
Antonio Quartulli27b37eb2012-11-08 14:21:11 +01001651 tt_change->flags = tt_common_entry->flags;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001652
1653 tt_count++;
1654 tt_change++;
1655 }
1656 }
1657 rcu_read_unlock();
1658
Antonio Quartulli9d852392011-10-17 14:25:13 +02001659 /* store in the message the number of entries we have successfully
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001660 * copied
1661 */
Antonio Quartulli9d852392011-10-17 14:25:13 +02001662 tt_response->tt_data = htons(tt_count);
1663
Antonio Quartullia73105b2011-04-27 14:27:44 +02001664out:
1665 return skb;
1666}
1667
Sven Eckelmann56303d32012-06-05 22:31:31 +02001668static int batadv_send_tt_request(struct batadv_priv *bat_priv,
1669 struct batadv_orig_node *dst_orig_node,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001670 uint8_t ttvn, uint16_t tt_crc,
1671 bool full_table)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001672{
1673 struct sk_buff *skb = NULL;
Sven Eckelmann96412692012-06-05 22:31:30 +02001674 struct batadv_tt_query_packet *tt_request;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001675 struct batadv_hard_iface *primary_if;
1676 struct batadv_tt_req_node *tt_req_node = NULL;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001677 int ret = 1;
Sven Eckelmann96412692012-06-05 22:31:30 +02001678 size_t tt_req_len;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001679
Sven Eckelmanne5d89252012-05-12 13:48:54 +02001680 primary_if = batadv_primary_if_get_selected(bat_priv);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001681 if (!primary_if)
1682 goto out;
1683
1684 /* The new tt_req will be issued only if I'm not waiting for a
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001685 * reply from the same orig_node yet
1686 */
Sven Eckelmanna5130882012-05-16 20:23:16 +02001687 tt_req_node = batadv_new_tt_req_node(bat_priv, dst_orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001688 if (!tt_req_node)
1689 goto out;
1690
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02001691 skb = netdev_alloc_skb_ip_align(NULL, sizeof(*tt_request) + ETH_HLEN);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001692 if (!skb)
1693 goto out;
1694
Simon Wunderlichc54f38c92013-07-29 17:56:44 +02001695 skb->priority = TC_PRIO_CONTROL;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02001696 skb_reserve(skb, ETH_HLEN);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001697
Sven Eckelmann96412692012-06-05 22:31:30 +02001698 tt_req_len = sizeof(*tt_request);
1699 tt_request = (struct batadv_tt_query_packet *)skb_put(skb, tt_req_len);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001700
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001701 tt_request->header.packet_type = BATADV_TT_QUERY;
Sven Eckelmann7e071c72012-06-03 22:19:13 +02001702 tt_request->header.version = BATADV_COMPAT_VERSION;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001703 memcpy(tt_request->src, primary_if->net_dev->dev_addr, ETH_ALEN);
1704 memcpy(tt_request->dst, dst_orig_node->orig, ETH_ALEN);
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001705 tt_request->header.ttl = BATADV_TTL;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001706 tt_request->ttvn = ttvn;
Antonio Quartulli6d2003f2012-04-14 13:15:27 +02001707 tt_request->tt_data = htons(tt_crc);
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001708 tt_request->flags = BATADV_TT_REQUEST;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001709
1710 if (full_table)
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001711 tt_request->flags |= BATADV_TT_FULL_TABLE;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001712
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02001713 batadv_dbg(BATADV_DBG_TT, bat_priv, "Sending TT_REQUEST to %pM [%c]\n",
1714 dst_orig_node->orig, (full_table ? 'F' : '.'));
Antonio Quartullia73105b2011-04-27 14:27:44 +02001715
Sven Eckelmannd69909d2012-06-03 22:19:20 +02001716 batadv_inc_counter(bat_priv, BATADV_CNT_TT_REQUEST_TX);
Martin Hundebøllf8214862012-04-20 17:02:45 +02001717
Martin Hundebølle91ecfc2013-04-20 13:54:39 +02001718 if (batadv_send_skb_to_orig(skb, dst_orig_node, NULL) != NET_XMIT_DROP)
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02001719 ret = 0;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001720
1721out:
Antonio Quartullia73105b2011-04-27 14:27:44 +02001722 if (primary_if)
Sven Eckelmanne5d89252012-05-12 13:48:54 +02001723 batadv_hardif_free_ref(primary_if);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001724 if (ret)
1725 kfree_skb(skb);
1726 if (ret && tt_req_node) {
Sven Eckelmann807736f2012-07-15 22:26:51 +02001727 spin_lock_bh(&bat_priv->tt.req_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001728 list_del(&tt_req_node->list);
Sven Eckelmann807736f2012-07-15 22:26:51 +02001729 spin_unlock_bh(&bat_priv->tt.req_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001730 kfree(tt_req_node);
1731 }
1732 return ret;
1733}
1734
Sven Eckelmann96412692012-06-05 22:31:30 +02001735static bool
Sven Eckelmann56303d32012-06-05 22:31:31 +02001736batadv_send_other_tt_response(struct batadv_priv *bat_priv,
Sven Eckelmann96412692012-06-05 22:31:30 +02001737 struct batadv_tt_query_packet *tt_request)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001738{
Sven Eckelmann170173b2012-10-07 12:02:22 +02001739 struct batadv_orig_node *req_dst_orig_node;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001740 struct batadv_orig_node *res_dst_orig_node = NULL;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001741 uint8_t orig_ttvn, req_ttvn, ttvn;
Martin Hundebølle91ecfc2013-04-20 13:54:39 +02001742 int res, ret = false;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001743 unsigned char *tt_buff;
1744 bool full_table;
1745 uint16_t tt_len, tt_tot;
1746 struct sk_buff *skb = NULL;
Sven Eckelmann96412692012-06-05 22:31:30 +02001747 struct batadv_tt_query_packet *tt_response;
Sven Eckelmannc67893d2012-07-08 18:33:51 +02001748 uint8_t *packet_pos;
Sven Eckelmann96412692012-06-05 22:31:30 +02001749 size_t len;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001750
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001751 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02001752 "Received TT_REQUEST from %pM for ttvn: %u (%pM) [%c]\n",
1753 tt_request->src, tt_request->ttvn, tt_request->dst,
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001754 (tt_request->flags & BATADV_TT_FULL_TABLE ? 'F' : '.'));
Antonio Quartullia73105b2011-04-27 14:27:44 +02001755
1756 /* Let's get the orig node of the REAL destination */
Sven Eckelmannda641192012-05-12 13:48:56 +02001757 req_dst_orig_node = batadv_orig_hash_find(bat_priv, tt_request->dst);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001758 if (!req_dst_orig_node)
1759 goto out;
1760
Sven Eckelmannda641192012-05-12 13:48:56 +02001761 res_dst_orig_node = batadv_orig_hash_find(bat_priv, tt_request->src);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001762 if (!res_dst_orig_node)
1763 goto out;
1764
Antonio Quartullia73105b2011-04-27 14:27:44 +02001765 orig_ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn);
1766 req_ttvn = tt_request->ttvn;
1767
Antonio Quartulli015758d2011-07-09 17:52:13 +02001768 /* I don't have the requested data */
Antonio Quartullia73105b2011-04-27 14:27:44 +02001769 if (orig_ttvn != req_ttvn ||
Al Virof25bd582012-04-22 07:44:27 +01001770 tt_request->tt_data != htons(req_dst_orig_node->tt_crc))
Antonio Quartullia73105b2011-04-27 14:27:44 +02001771 goto out;
1772
Antonio Quartulli015758d2011-07-09 17:52:13 +02001773 /* If the full table has been explicitly requested */
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001774 if (tt_request->flags & BATADV_TT_FULL_TABLE ||
Antonio Quartullia73105b2011-04-27 14:27:44 +02001775 !req_dst_orig_node->tt_buff)
1776 full_table = true;
1777 else
1778 full_table = false;
1779
1780 /* In this version, fragmentation is not implemented, then
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001781 * I'll send only one packet with as much TT entries as I can
1782 */
Antonio Quartullia73105b2011-04-27 14:27:44 +02001783 if (!full_table) {
1784 spin_lock_bh(&req_dst_orig_node->tt_buff_lock);
1785 tt_len = req_dst_orig_node->tt_buff_len;
Sven Eckelmann96412692012-06-05 22:31:30 +02001786 tt_tot = tt_len / sizeof(struct batadv_tt_change);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001787
Sven Eckelmann96412692012-06-05 22:31:30 +02001788 len = sizeof(*tt_response) + tt_len;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02001789 skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001790 if (!skb)
1791 goto unlock;
1792
Simon Wunderlichc54f38c92013-07-29 17:56:44 +02001793 skb->priority = TC_PRIO_CONTROL;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02001794 skb_reserve(skb, ETH_HLEN);
Sven Eckelmannc67893d2012-07-08 18:33:51 +02001795 packet_pos = skb_put(skb, len);
1796 tt_response = (struct batadv_tt_query_packet *)packet_pos;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001797 tt_response->ttvn = req_ttvn;
1798 tt_response->tt_data = htons(tt_tot);
1799
Sven Eckelmann96412692012-06-05 22:31:30 +02001800 tt_buff = skb->data + sizeof(*tt_response);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001801 /* Copy the last orig_node's OGM buffer */
1802 memcpy(tt_buff, req_dst_orig_node->tt_buff,
1803 req_dst_orig_node->tt_buff_len);
1804
1805 spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
1806 } else {
Sven Eckelmann96412692012-06-05 22:31:30 +02001807 tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size);
1808 tt_len *= sizeof(struct batadv_tt_change);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001809 ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn);
1810
Sven Eckelmanna5130882012-05-16 20:23:16 +02001811 skb = batadv_tt_response_fill_table(tt_len, ttvn,
Sven Eckelmann807736f2012-07-15 22:26:51 +02001812 bat_priv->tt.global_hash,
Marek Lindner736292c2013-01-12 19:19:06 +08001813 bat_priv,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001814 batadv_tt_global_valid,
1815 req_dst_orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001816 if (!skb)
1817 goto out;
1818
Sven Eckelmann96412692012-06-05 22:31:30 +02001819 tt_response = (struct batadv_tt_query_packet *)skb->data;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001820 }
1821
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001822 tt_response->header.packet_type = BATADV_TT_QUERY;
Sven Eckelmann7e071c72012-06-03 22:19:13 +02001823 tt_response->header.version = BATADV_COMPAT_VERSION;
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001824 tt_response->header.ttl = BATADV_TTL;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001825 memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN);
1826 memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001827 tt_response->flags = BATADV_TT_RESPONSE;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001828
1829 if (full_table)
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001830 tt_response->flags |= BATADV_TT_FULL_TABLE;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001831
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001832 batadv_dbg(BATADV_DBG_TT, bat_priv,
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02001833 "Sending TT_RESPONSE %pM for %pM (ttvn: %u)\n",
1834 res_dst_orig_node->orig, req_dst_orig_node->orig, req_ttvn);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001835
Sven Eckelmannd69909d2012-06-03 22:19:20 +02001836 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX);
Martin Hundebøllf8214862012-04-20 17:02:45 +02001837
Martin Hundebølle91ecfc2013-04-20 13:54:39 +02001838 res = batadv_send_skb_to_orig(skb, res_dst_orig_node, NULL);
1839 if (res != NET_XMIT_DROP)
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02001840 ret = true;
Martin Hundebølle91ecfc2013-04-20 13:54:39 +02001841
Antonio Quartullia73105b2011-04-27 14:27:44 +02001842 goto out;
1843
1844unlock:
1845 spin_unlock_bh(&req_dst_orig_node->tt_buff_lock);
1846
1847out:
1848 if (res_dst_orig_node)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001849 batadv_orig_node_free_ref(res_dst_orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001850 if (req_dst_orig_node)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001851 batadv_orig_node_free_ref(req_dst_orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001852 if (!ret)
1853 kfree_skb(skb);
1854 return ret;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001855}
Sven Eckelmann96412692012-06-05 22:31:30 +02001856
1857static bool
Sven Eckelmann56303d32012-06-05 22:31:31 +02001858batadv_send_my_tt_response(struct batadv_priv *bat_priv,
Sven Eckelmann96412692012-06-05 22:31:30 +02001859 struct batadv_tt_query_packet *tt_request)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001860{
Sven Eckelmann170173b2012-10-07 12:02:22 +02001861 struct batadv_orig_node *orig_node;
Sven Eckelmann56303d32012-06-05 22:31:31 +02001862 struct batadv_hard_iface *primary_if = NULL;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001863 uint8_t my_ttvn, req_ttvn, ttvn;
1864 int ret = false;
1865 unsigned char *tt_buff;
1866 bool full_table;
1867 uint16_t tt_len, tt_tot;
1868 struct sk_buff *skb = NULL;
Sven Eckelmann96412692012-06-05 22:31:30 +02001869 struct batadv_tt_query_packet *tt_response;
Sven Eckelmannc67893d2012-07-08 18:33:51 +02001870 uint8_t *packet_pos;
Sven Eckelmann96412692012-06-05 22:31:30 +02001871 size_t len;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001872
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001873 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02001874 "Received TT_REQUEST from %pM for ttvn: %u (me) [%c]\n",
1875 tt_request->src, tt_request->ttvn,
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001876 (tt_request->flags & BATADV_TT_FULL_TABLE ? 'F' : '.'));
Antonio Quartullia73105b2011-04-27 14:27:44 +02001877
1878
Sven Eckelmann807736f2012-07-15 22:26:51 +02001879 my_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001880 req_ttvn = tt_request->ttvn;
1881
Sven Eckelmannda641192012-05-12 13:48:56 +02001882 orig_node = batadv_orig_hash_find(bat_priv, tt_request->src);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001883 if (!orig_node)
1884 goto out;
1885
Sven Eckelmanne5d89252012-05-12 13:48:54 +02001886 primary_if = batadv_primary_if_get_selected(bat_priv);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001887 if (!primary_if)
1888 goto out;
1889
1890 /* If the full table has been explicitly requested or the gap
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001891 * is too big send the whole local translation table
1892 */
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001893 if (tt_request->flags & BATADV_TT_FULL_TABLE || my_ttvn != req_ttvn ||
Sven Eckelmann807736f2012-07-15 22:26:51 +02001894 !bat_priv->tt.last_changeset)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001895 full_table = true;
1896 else
1897 full_table = false;
1898
1899 /* In this version, fragmentation is not implemented, then
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001900 * I'll send only one packet with as much TT entries as I can
1901 */
Antonio Quartullia73105b2011-04-27 14:27:44 +02001902 if (!full_table) {
Sven Eckelmann807736f2012-07-15 22:26:51 +02001903 spin_lock_bh(&bat_priv->tt.last_changeset_lock);
1904 tt_len = bat_priv->tt.last_changeset_len;
Sven Eckelmann96412692012-06-05 22:31:30 +02001905 tt_tot = tt_len / sizeof(struct batadv_tt_change);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001906
Sven Eckelmann96412692012-06-05 22:31:30 +02001907 len = sizeof(*tt_response) + tt_len;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02001908 skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001909 if (!skb)
1910 goto unlock;
1911
Simon Wunderlichc54f38c92013-07-29 17:56:44 +02001912 skb->priority = TC_PRIO_CONTROL;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02001913 skb_reserve(skb, ETH_HLEN);
Sven Eckelmannc67893d2012-07-08 18:33:51 +02001914 packet_pos = skb_put(skb, len);
1915 tt_response = (struct batadv_tt_query_packet *)packet_pos;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001916 tt_response->ttvn = req_ttvn;
1917 tt_response->tt_data = htons(tt_tot);
1918
Sven Eckelmann96412692012-06-05 22:31:30 +02001919 tt_buff = skb->data + sizeof(*tt_response);
Sven Eckelmann807736f2012-07-15 22:26:51 +02001920 memcpy(tt_buff, bat_priv->tt.last_changeset,
1921 bat_priv->tt.last_changeset_len);
1922 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001923 } else {
Sven Eckelmann807736f2012-07-15 22:26:51 +02001924 tt_len = (uint16_t)atomic_read(&bat_priv->tt.local_entry_num);
Sven Eckelmann96412692012-06-05 22:31:30 +02001925 tt_len *= sizeof(struct batadv_tt_change);
Sven Eckelmann807736f2012-07-15 22:26:51 +02001926 ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001927
Sven Eckelmanna5130882012-05-16 20:23:16 +02001928 skb = batadv_tt_response_fill_table(tt_len, ttvn,
Sven Eckelmann807736f2012-07-15 22:26:51 +02001929 bat_priv->tt.local_hash,
Marek Lindner736292c2013-01-12 19:19:06 +08001930 bat_priv,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001931 batadv_tt_local_valid_entry,
1932 NULL);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001933 if (!skb)
1934 goto out;
1935
Sven Eckelmann96412692012-06-05 22:31:30 +02001936 tt_response = (struct batadv_tt_query_packet *)skb->data;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001937 }
1938
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001939 tt_response->header.packet_type = BATADV_TT_QUERY;
Sven Eckelmann7e071c72012-06-03 22:19:13 +02001940 tt_response->header.version = BATADV_COMPAT_VERSION;
Sven Eckelmann42d0b042012-06-03 22:19:17 +02001941 tt_response->header.ttl = BATADV_TTL;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001942 memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN);
1943 memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001944 tt_response->flags = BATADV_TT_RESPONSE;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001945
1946 if (full_table)
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001947 tt_response->flags |= BATADV_TT_FULL_TABLE;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001948
Sven Eckelmann39c75a52012-06-03 22:19:22 +02001949 batadv_dbg(BATADV_DBG_TT, bat_priv,
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02001950 "Sending TT_RESPONSE to %pM [%c]\n",
1951 orig_node->orig,
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001952 (tt_response->flags & BATADV_TT_FULL_TABLE ? 'F' : '.'));
Antonio Quartullia73105b2011-04-27 14:27:44 +02001953
Sven Eckelmannd69909d2012-06-03 22:19:20 +02001954 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_TX);
Martin Hundebøllf8214862012-04-20 17:02:45 +02001955
Martin Hundebølle91ecfc2013-04-20 13:54:39 +02001956 if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02001957 ret = true;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001958 goto out;
1959
1960unlock:
Sven Eckelmann807736f2012-07-15 22:26:51 +02001961 spin_unlock_bh(&bat_priv->tt.last_changeset_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001962out:
1963 if (orig_node)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02001964 batadv_orig_node_free_ref(orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001965 if (primary_if)
Sven Eckelmanne5d89252012-05-12 13:48:54 +02001966 batadv_hardif_free_ref(primary_if);
Antonio Quartullia73105b2011-04-27 14:27:44 +02001967 if (!ret)
1968 kfree_skb(skb);
1969 /* This packet was for me, so it doesn't need to be re-routed */
1970 return true;
1971}
1972
Sven Eckelmann56303d32012-06-05 22:31:31 +02001973bool batadv_send_tt_response(struct batadv_priv *bat_priv,
Sven Eckelmann96412692012-06-05 22:31:30 +02001974 struct batadv_tt_query_packet *tt_request)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001975{
Antonio Quartullife8a93b2013-04-03 19:10:26 +02001976 if (batadv_is_my_mac(bat_priv, tt_request->dst)) {
Simon Wunderlich20ff9d52012-01-22 20:00:23 +01001977 /* don't answer backbone gws! */
Sven Eckelmann08adf152012-05-12 13:38:47 +02001978 if (batadv_bla_is_backbone_gw_orig(bat_priv, tt_request->src))
Simon Wunderlich20ff9d52012-01-22 20:00:23 +01001979 return true;
1980
Sven Eckelmanna5130882012-05-16 20:23:16 +02001981 return batadv_send_my_tt_response(bat_priv, tt_request);
Simon Wunderlich20ff9d52012-01-22 20:00:23 +01001982 } else {
Sven Eckelmanna5130882012-05-16 20:23:16 +02001983 return batadv_send_other_tt_response(bat_priv, tt_request);
Simon Wunderlich20ff9d52012-01-22 20:00:23 +01001984 }
Antonio Quartullia73105b2011-04-27 14:27:44 +02001985}
1986
Sven Eckelmann56303d32012-06-05 22:31:31 +02001987static void _batadv_tt_update_changes(struct batadv_priv *bat_priv,
1988 struct batadv_orig_node *orig_node,
Sven Eckelmann96412692012-06-05 22:31:30 +02001989 struct batadv_tt_change *tt_change,
Sven Eckelmanna5130882012-05-16 20:23:16 +02001990 uint16_t tt_num_changes, uint8_t ttvn)
Antonio Quartullia73105b2011-04-27 14:27:44 +02001991{
1992 int i;
Sven Eckelmanna5130882012-05-16 20:23:16 +02001993 int roams;
Antonio Quartullia73105b2011-04-27 14:27:44 +02001994
1995 for (i = 0; i < tt_num_changes; i++) {
Sven Eckelmannacd34af2012-06-03 22:19:21 +02001996 if ((tt_change + i)->flags & BATADV_TT_CLIENT_DEL) {
1997 roams = (tt_change + i)->flags & BATADV_TT_CLIENT_ROAM;
Sven Eckelmanna5130882012-05-16 20:23:16 +02001998 batadv_tt_global_del(bat_priv, orig_node,
1999 (tt_change + i)->addr,
Antonio Quartullid4f44692012-05-25 00:00:54 +02002000 "tt removed by changes",
2001 roams);
Sven Eckelmann08c36d32012-05-12 02:09:39 +02002002 } else {
Sven Eckelmann08c36d32012-05-12 02:09:39 +02002003 if (!batadv_tt_global_add(bat_priv, orig_node,
Antonio Quartullid4f44692012-05-25 00:00:54 +02002004 (tt_change + i)->addr,
2005 (tt_change + i)->flags, ttvn))
Antonio Quartullia73105b2011-04-27 14:27:44 +02002006 /* In case of problem while storing a
2007 * global_entry, we stop the updating
2008 * procedure without committing the
2009 * ttvn change. This will avoid to send
2010 * corrupted data on tt_request
2011 */
2012 return;
Sven Eckelmann08c36d32012-05-12 02:09:39 +02002013 }
Antonio Quartullia73105b2011-04-27 14:27:44 +02002014 }
Antonio Quartulli17071572011-11-07 16:36:40 +01002015 orig_node->tt_initialised = true;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002016}
2017
Sven Eckelmann56303d32012-06-05 22:31:31 +02002018static void batadv_tt_fill_gtable(struct batadv_priv *bat_priv,
Sven Eckelmann96412692012-06-05 22:31:30 +02002019 struct batadv_tt_query_packet *tt_response)
Antonio Quartullia73105b2011-04-27 14:27:44 +02002020{
Sven Eckelmann170173b2012-10-07 12:02:22 +02002021 struct batadv_orig_node *orig_node;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002022
Sven Eckelmannda641192012-05-12 13:48:56 +02002023 orig_node = batadv_orig_hash_find(bat_priv, tt_response->src);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002024 if (!orig_node)
2025 goto out;
2026
2027 /* Purge the old table first.. */
Sven Eckelmann08c36d32012-05-12 02:09:39 +02002028 batadv_tt_global_del_orig(bat_priv, orig_node, "Received full table");
Antonio Quartullia73105b2011-04-27 14:27:44 +02002029
Sven Eckelmanna5130882012-05-16 20:23:16 +02002030 _batadv_tt_update_changes(bat_priv, orig_node,
Sven Eckelmann96412692012-06-05 22:31:30 +02002031 (struct batadv_tt_change *)(tt_response + 1),
Sven Eckelmanna5130882012-05-16 20:23:16 +02002032 ntohs(tt_response->tt_data),
2033 tt_response->ttvn);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002034
2035 spin_lock_bh(&orig_node->tt_buff_lock);
2036 kfree(orig_node->tt_buff);
2037 orig_node->tt_buff_len = 0;
2038 orig_node->tt_buff = NULL;
2039 spin_unlock_bh(&orig_node->tt_buff_lock);
2040
2041 atomic_set(&orig_node->last_ttvn, tt_response->ttvn);
2042
2043out:
2044 if (orig_node)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02002045 batadv_orig_node_free_ref(orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002046}
2047
Sven Eckelmann56303d32012-06-05 22:31:31 +02002048static void batadv_tt_update_changes(struct batadv_priv *bat_priv,
2049 struct batadv_orig_node *orig_node,
Sven Eckelmanna5130882012-05-16 20:23:16 +02002050 uint16_t tt_num_changes, uint8_t ttvn,
Sven Eckelmann96412692012-06-05 22:31:30 +02002051 struct batadv_tt_change *tt_change)
Antonio Quartullia73105b2011-04-27 14:27:44 +02002052{
Sven Eckelmanna5130882012-05-16 20:23:16 +02002053 _batadv_tt_update_changes(bat_priv, orig_node, tt_change,
2054 tt_num_changes, ttvn);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002055
Sven Eckelmanna5130882012-05-16 20:23:16 +02002056 batadv_tt_save_orig_buffer(bat_priv, orig_node,
2057 (unsigned char *)tt_change, tt_num_changes);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002058 atomic_set(&orig_node->last_ttvn, ttvn);
2059}
2060
Sven Eckelmann56303d32012-06-05 22:31:31 +02002061bool batadv_is_my_client(struct batadv_priv *bat_priv, const uint8_t *addr)
Antonio Quartullia73105b2011-04-27 14:27:44 +02002062{
Sven Eckelmann170173b2012-10-07 12:02:22 +02002063 struct batadv_tt_local_entry *tt_local_entry;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02002064 bool ret = false;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002065
Sven Eckelmanna5130882012-05-16 20:23:16 +02002066 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02002067 if (!tt_local_entry)
2068 goto out;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002069 /* Check if the client has been logically deleted (but is kept for
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002070 * consistency purpose)
2071 */
Antonio Quartulli7c1fd912012-09-23 22:38:34 +02002072 if ((tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) ||
2073 (tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM))
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002074 goto out;
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02002075 ret = true;
2076out:
Antonio Quartullia73105b2011-04-27 14:27:44 +02002077 if (tt_local_entry)
Sven Eckelmanna5130882012-05-16 20:23:16 +02002078 batadv_tt_local_entry_free_ref(tt_local_entry);
Antonio Quartulli7683fdc2011-04-27 14:28:07 +02002079 return ret;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002080}
2081
Sven Eckelmann56303d32012-06-05 22:31:31 +02002082void batadv_handle_tt_response(struct batadv_priv *bat_priv,
Sven Eckelmann96412692012-06-05 22:31:30 +02002083 struct batadv_tt_query_packet *tt_response)
Antonio Quartullia73105b2011-04-27 14:27:44 +02002084{
Sven Eckelmann56303d32012-06-05 22:31:31 +02002085 struct batadv_tt_req_node *node, *safe;
2086 struct batadv_orig_node *orig_node = NULL;
Sven Eckelmann96412692012-06-05 22:31:30 +02002087 struct batadv_tt_change *tt_change;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002088
Sven Eckelmann39c75a52012-06-03 22:19:22 +02002089 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02002090 "Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n",
2091 tt_response->src, tt_response->ttvn,
2092 ntohs(tt_response->tt_data),
Sven Eckelmannacd34af2012-06-03 22:19:21 +02002093 (tt_response->flags & BATADV_TT_FULL_TABLE ? 'F' : '.'));
Antonio Quartullia73105b2011-04-27 14:27:44 +02002094
Simon Wunderlich20ff9d52012-01-22 20:00:23 +01002095 /* we should have never asked a backbone gw */
Sven Eckelmann08adf152012-05-12 13:38:47 +02002096 if (batadv_bla_is_backbone_gw_orig(bat_priv, tt_response->src))
Simon Wunderlich20ff9d52012-01-22 20:00:23 +01002097 goto out;
2098
Sven Eckelmannda641192012-05-12 13:48:56 +02002099 orig_node = batadv_orig_hash_find(bat_priv, tt_response->src);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002100 if (!orig_node)
2101 goto out;
2102
Sven Eckelmann96412692012-06-05 22:31:30 +02002103 if (tt_response->flags & BATADV_TT_FULL_TABLE) {
Sven Eckelmanna5130882012-05-16 20:23:16 +02002104 batadv_tt_fill_gtable(bat_priv, tt_response);
Sven Eckelmann96412692012-06-05 22:31:30 +02002105 } else {
2106 tt_change = (struct batadv_tt_change *)(tt_response + 1);
Sven Eckelmanna5130882012-05-16 20:23:16 +02002107 batadv_tt_update_changes(bat_priv, orig_node,
2108 ntohs(tt_response->tt_data),
Sven Eckelmann96412692012-06-05 22:31:30 +02002109 tt_response->ttvn, tt_change);
2110 }
Antonio Quartullia73105b2011-04-27 14:27:44 +02002111
2112 /* Delete the tt_req_node from pending tt_requests list */
Sven Eckelmann807736f2012-07-15 22:26:51 +02002113 spin_lock_bh(&bat_priv->tt.req_list_lock);
2114 list_for_each_entry_safe(node, safe, &bat_priv->tt.req_list, list) {
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02002115 if (!batadv_compare_eth(node->addr, tt_response->src))
Antonio Quartullia73105b2011-04-27 14:27:44 +02002116 continue;
2117 list_del(&node->list);
2118 kfree(node);
2119 }
Sven Eckelmann807736f2012-07-15 22:26:51 +02002120 spin_unlock_bh(&bat_priv->tt.req_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002121
2122 /* Recalculate the CRC for this orig_node and store it */
Sven Eckelmanna5130882012-05-16 20:23:16 +02002123 orig_node->tt_crc = batadv_tt_global_crc(bat_priv, orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002124out:
2125 if (orig_node)
Sven Eckelmann7d211ef2012-05-12 02:09:34 +02002126 batadv_orig_node_free_ref(orig_node);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002127}
2128
Sven Eckelmann56303d32012-06-05 22:31:31 +02002129int batadv_tt_init(struct batadv_priv *bat_priv)
Antonio Quartullia73105b2011-04-27 14:27:44 +02002130{
Sven Eckelmann5346c352012-05-05 13:27:28 +02002131 int ret;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002132
Sven Eckelmanna5130882012-05-16 20:23:16 +02002133 ret = batadv_tt_local_init(bat_priv);
Sven Eckelmann5346c352012-05-05 13:27:28 +02002134 if (ret < 0)
2135 return ret;
2136
Sven Eckelmanna5130882012-05-16 20:23:16 +02002137 ret = batadv_tt_global_init(bat_priv);
Sven Eckelmann5346c352012-05-05 13:27:28 +02002138 if (ret < 0)
2139 return ret;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002140
Antonio Quartulli72414442012-12-25 13:14:37 +01002141 INIT_DELAYED_WORK(&bat_priv->tt.work, batadv_tt_purge);
2142 queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work,
2143 msecs_to_jiffies(BATADV_TT_WORK_PERIOD));
Antonio Quartullia73105b2011-04-27 14:27:44 +02002144
2145 return 1;
2146}
2147
Sven Eckelmann56303d32012-06-05 22:31:31 +02002148static void batadv_tt_roam_list_free(struct batadv_priv *bat_priv)
Antonio Quartullia73105b2011-04-27 14:27:44 +02002149{
Sven Eckelmann56303d32012-06-05 22:31:31 +02002150 struct batadv_tt_roam_node *node, *safe;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002151
Sven Eckelmann807736f2012-07-15 22:26:51 +02002152 spin_lock_bh(&bat_priv->tt.roam_list_lock);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002153
Sven Eckelmann807736f2012-07-15 22:26:51 +02002154 list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
Antonio Quartullicc47f662011-04-27 14:27:57 +02002155 list_del(&node->list);
2156 kfree(node);
2157 }
2158
Sven Eckelmann807736f2012-07-15 22:26:51 +02002159 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002160}
2161
Sven Eckelmann56303d32012-06-05 22:31:31 +02002162static void batadv_tt_roam_purge(struct batadv_priv *bat_priv)
Antonio Quartullicc47f662011-04-27 14:27:57 +02002163{
Sven Eckelmann56303d32012-06-05 22:31:31 +02002164 struct batadv_tt_roam_node *node, *safe;
Antonio Quartullicc47f662011-04-27 14:27:57 +02002165
Sven Eckelmann807736f2012-07-15 22:26:51 +02002166 spin_lock_bh(&bat_priv->tt.roam_list_lock);
2167 list_for_each_entry_safe(node, safe, &bat_priv->tt.roam_list, list) {
Sven Eckelmann42d0b042012-06-03 22:19:17 +02002168 if (!batadv_has_timed_out(node->first_time,
2169 BATADV_ROAMING_MAX_TIME))
Antonio Quartullicc47f662011-04-27 14:27:57 +02002170 continue;
2171
2172 list_del(&node->list);
2173 kfree(node);
2174 }
Sven Eckelmann807736f2012-07-15 22:26:51 +02002175 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002176}
2177
2178/* This function checks whether the client already reached the
2179 * maximum number of possible roaming phases. In this case the ROAMING_ADV
2180 * will not be sent.
2181 *
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002182 * returns true if the ROAMING_ADV can be sent, false otherwise
2183 */
Sven Eckelmann56303d32012-06-05 22:31:31 +02002184static bool batadv_tt_check_roam_count(struct batadv_priv *bat_priv,
Sven Eckelmanna5130882012-05-16 20:23:16 +02002185 uint8_t *client)
Antonio Quartullicc47f662011-04-27 14:27:57 +02002186{
Sven Eckelmann56303d32012-06-05 22:31:31 +02002187 struct batadv_tt_roam_node *tt_roam_node;
Antonio Quartullicc47f662011-04-27 14:27:57 +02002188 bool ret = false;
2189
Sven Eckelmann807736f2012-07-15 22:26:51 +02002190 spin_lock_bh(&bat_priv->tt.roam_list_lock);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002191 /* The new tt_req will be issued only if I'm not waiting for a
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002192 * reply from the same orig_node yet
2193 */
Sven Eckelmann807736f2012-07-15 22:26:51 +02002194 list_for_each_entry(tt_roam_node, &bat_priv->tt.roam_list, list) {
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02002195 if (!batadv_compare_eth(tt_roam_node->addr, client))
Antonio Quartullicc47f662011-04-27 14:27:57 +02002196 continue;
2197
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02002198 if (batadv_has_timed_out(tt_roam_node->first_time,
Sven Eckelmann42d0b042012-06-03 22:19:17 +02002199 BATADV_ROAMING_MAX_TIME))
Antonio Quartullicc47f662011-04-27 14:27:57 +02002200 continue;
2201
Sven Eckelmann3e348192012-05-16 20:23:22 +02002202 if (!batadv_atomic_dec_not_zero(&tt_roam_node->counter))
Antonio Quartullicc47f662011-04-27 14:27:57 +02002203 /* Sorry, you roamed too many times! */
2204 goto unlock;
2205 ret = true;
2206 break;
2207 }
2208
2209 if (!ret) {
2210 tt_roam_node = kmalloc(sizeof(*tt_roam_node), GFP_ATOMIC);
2211 if (!tt_roam_node)
2212 goto unlock;
2213
2214 tt_roam_node->first_time = jiffies;
Sven Eckelmann42d0b042012-06-03 22:19:17 +02002215 atomic_set(&tt_roam_node->counter,
2216 BATADV_ROAMING_MAX_COUNT - 1);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002217 memcpy(tt_roam_node->addr, client, ETH_ALEN);
2218
Sven Eckelmann807736f2012-07-15 22:26:51 +02002219 list_add(&tt_roam_node->list, &bat_priv->tt.roam_list);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002220 ret = true;
2221 }
2222
2223unlock:
Sven Eckelmann807736f2012-07-15 22:26:51 +02002224 spin_unlock_bh(&bat_priv->tt.roam_list_lock);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002225 return ret;
2226}
2227
Sven Eckelmann56303d32012-06-05 22:31:31 +02002228static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client,
2229 struct batadv_orig_node *orig_node)
Antonio Quartullicc47f662011-04-27 14:27:57 +02002230{
Antonio Quartullicc47f662011-04-27 14:27:57 +02002231 struct sk_buff *skb = NULL;
Sven Eckelmann96412692012-06-05 22:31:30 +02002232 struct batadv_roam_adv_packet *roam_adv_packet;
Antonio Quartullicc47f662011-04-27 14:27:57 +02002233 int ret = 1;
Sven Eckelmann56303d32012-06-05 22:31:31 +02002234 struct batadv_hard_iface *primary_if;
Sven Eckelmann96412692012-06-05 22:31:30 +02002235 size_t len = sizeof(*roam_adv_packet);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002236
2237 /* before going on we have to check whether the client has
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002238 * already roamed to us too many times
2239 */
Sven Eckelmanna5130882012-05-16 20:23:16 +02002240 if (!batadv_tt_check_roam_count(bat_priv, client))
Antonio Quartullicc47f662011-04-27 14:27:57 +02002241 goto out;
2242
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02002243 skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002244 if (!skb)
2245 goto out;
2246
Simon Wunderlichc54f38c92013-07-29 17:56:44 +02002247 skb->priority = TC_PRIO_CONTROL;
Antonio Quartulli41ab6c42013-04-02 22:28:44 +02002248 skb_reserve(skb, ETH_HLEN);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002249
Sven Eckelmann96412692012-06-05 22:31:30 +02002250 roam_adv_packet = (struct batadv_roam_adv_packet *)skb_put(skb, len);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002251
Sven Eckelmannacd34af2012-06-03 22:19:21 +02002252 roam_adv_packet->header.packet_type = BATADV_ROAM_ADV;
Sven Eckelmann7e071c72012-06-03 22:19:13 +02002253 roam_adv_packet->header.version = BATADV_COMPAT_VERSION;
Sven Eckelmann42d0b042012-06-03 22:19:17 +02002254 roam_adv_packet->header.ttl = BATADV_TTL;
Sven Eckelmann162d5492012-06-28 11:56:52 +02002255 roam_adv_packet->reserved = 0;
Sven Eckelmanne5d89252012-05-12 13:48:54 +02002256 primary_if = batadv_primary_if_get_selected(bat_priv);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002257 if (!primary_if)
2258 goto out;
2259 memcpy(roam_adv_packet->src, primary_if->net_dev->dev_addr, ETH_ALEN);
Sven Eckelmanne5d89252012-05-12 13:48:54 +02002260 batadv_hardif_free_ref(primary_if);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002261 memcpy(roam_adv_packet->dst, orig_node->orig, ETH_ALEN);
2262 memcpy(roam_adv_packet->client, client, ETH_ALEN);
2263
Sven Eckelmann39c75a52012-06-03 22:19:22 +02002264 batadv_dbg(BATADV_DBG_TT, bat_priv,
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02002265 "Sending ROAMING_ADV to %pM (client %pM)\n",
2266 orig_node->orig, client);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002267
Sven Eckelmannd69909d2012-06-03 22:19:20 +02002268 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX);
Martin Hundebøllf8214862012-04-20 17:02:45 +02002269
Martin Hundebølle91ecfc2013-04-20 13:54:39 +02002270 if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02002271 ret = 0;
Antonio Quartullicc47f662011-04-27 14:27:57 +02002272
2273out:
Martin Hundebøllbb351ba2012-10-16 16:13:48 +02002274 if (ret && skb)
Antonio Quartullicc47f662011-04-27 14:27:57 +02002275 kfree_skb(skb);
2276 return;
Antonio Quartullia73105b2011-04-27 14:27:44 +02002277}
2278
Sven Eckelmanna5130882012-05-16 20:23:16 +02002279static void batadv_tt_purge(struct work_struct *work)
Antonio Quartullia73105b2011-04-27 14:27:44 +02002280{
Sven Eckelmann56303d32012-06-05 22:31:31 +02002281 struct delayed_work *delayed_work;
Sven Eckelmann807736f2012-07-15 22:26:51 +02002282 struct batadv_priv_tt *priv_tt;
Sven Eckelmann56303d32012-06-05 22:31:31 +02002283 struct batadv_priv *bat_priv;
2284
2285 delayed_work = container_of(work, struct delayed_work, work);
Sven Eckelmann807736f2012-07-15 22:26:51 +02002286 priv_tt = container_of(delayed_work, struct batadv_priv_tt, work);
2287 bat_priv = container_of(priv_tt, struct batadv_priv, tt);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002288
Sven Eckelmanna5130882012-05-16 20:23:16 +02002289 batadv_tt_local_purge(bat_priv);
Antonio Quartulli30cfd022012-07-05 23:38:29 +02002290 batadv_tt_global_purge(bat_priv);
Sven Eckelmanna5130882012-05-16 20:23:16 +02002291 batadv_tt_req_purge(bat_priv);
2292 batadv_tt_roam_purge(bat_priv);
Antonio Quartullia73105b2011-04-27 14:27:44 +02002293
Antonio Quartulli72414442012-12-25 13:14:37 +01002294 queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work,
2295 msecs_to_jiffies(BATADV_TT_WORK_PERIOD));
Antonio Quartullia73105b2011-04-27 14:27:44 +02002296}
Antonio Quartullicc47f662011-04-27 14:27:57 +02002297
Sven Eckelmann56303d32012-06-05 22:31:31 +02002298void batadv_tt_free(struct batadv_priv *bat_priv)
Antonio Quartullicc47f662011-04-27 14:27:57 +02002299{
Sven Eckelmann807736f2012-07-15 22:26:51 +02002300 cancel_delayed_work_sync(&bat_priv->tt.work);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002301
Sven Eckelmanna5130882012-05-16 20:23:16 +02002302 batadv_tt_local_table_free(bat_priv);
2303 batadv_tt_global_table_free(bat_priv);
2304 batadv_tt_req_list_free(bat_priv);
2305 batadv_tt_changes_list_free(bat_priv);
2306 batadv_tt_roam_list_free(bat_priv);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002307
Sven Eckelmann807736f2012-07-15 22:26:51 +02002308 kfree(bat_priv->tt.last_changeset);
Antonio Quartullicc47f662011-04-27 14:27:57 +02002309}
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002310
Antonio Quartulli697f2532011-11-07 16:47:01 +01002311/* This function will enable or disable the specified flags for all the entries
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002312 * in the given hash table and returns the number of modified entries
2313 */
Sven Eckelmann5bf74e92012-06-05 22:31:28 +02002314static uint16_t batadv_tt_set_flags(struct batadv_hashtable *hash,
2315 uint16_t flags, bool enable)
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002316{
Antonio Quartullic90681b2011-10-05 17:05:25 +02002317 uint32_t i;
Antonio Quartulli697f2532011-11-07 16:47:01 +01002318 uint16_t changed_num = 0;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002319 struct hlist_head *head;
Sven Eckelmann56303d32012-06-05 22:31:31 +02002320 struct batadv_tt_common_entry *tt_common_entry;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002321
2322 if (!hash)
Antonio Quartulli697f2532011-11-07 16:47:01 +01002323 goto out;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002324
2325 for (i = 0; i < hash->size; i++) {
2326 head = &hash->table[i];
2327
2328 rcu_read_lock();
Sasha Levinb67bfe02013-02-27 17:06:00 -08002329 hlist_for_each_entry_rcu(tt_common_entry,
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002330 head, hash_entry) {
Antonio Quartulli697f2532011-11-07 16:47:01 +01002331 if (enable) {
2332 if ((tt_common_entry->flags & flags) == flags)
2333 continue;
2334 tt_common_entry->flags |= flags;
2335 } else {
2336 if (!(tt_common_entry->flags & flags))
2337 continue;
2338 tt_common_entry->flags &= ~flags;
2339 }
2340 changed_num++;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002341 }
2342 rcu_read_unlock();
2343 }
Antonio Quartulli697f2532011-11-07 16:47:01 +01002344out:
2345 return changed_num;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002346}
2347
Sven Eckelmannacd34af2012-06-03 22:19:21 +02002348/* Purge out all the tt local entries marked with BATADV_TT_CLIENT_PENDING */
Sven Eckelmann56303d32012-06-05 22:31:31 +02002349static void batadv_tt_local_purge_pending_clients(struct batadv_priv *bat_priv)
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002350{
Sven Eckelmann807736f2012-07-15 22:26:51 +02002351 struct batadv_hashtable *hash = bat_priv->tt.local_hash;
Sven Eckelmann56303d32012-06-05 22:31:31 +02002352 struct batadv_tt_common_entry *tt_common;
2353 struct batadv_tt_local_entry *tt_local;
Sasha Levinb67bfe02013-02-27 17:06:00 -08002354 struct hlist_node *node_tmp;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002355 struct hlist_head *head;
2356 spinlock_t *list_lock; /* protects write access to the hash lists */
Antonio Quartullic90681b2011-10-05 17:05:25 +02002357 uint32_t i;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002358
2359 if (!hash)
2360 return;
2361
2362 for (i = 0; i < hash->size; i++) {
2363 head = &hash->table[i];
2364 list_lock = &hash->list_locks[i];
2365
2366 spin_lock_bh(list_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -08002367 hlist_for_each_entry_safe(tt_common, node_tmp, head,
Sven Eckelmannacd34af2012-06-03 22:19:21 +02002368 hash_entry) {
2369 if (!(tt_common->flags & BATADV_TT_CLIENT_PENDING))
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002370 continue;
2371
Sven Eckelmann39c75a52012-06-03 22:19:22 +02002372 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02002373 "Deleting local tt entry (%pM): pending\n",
Sven Eckelmannacd34af2012-06-03 22:19:21 +02002374 tt_common->addr);
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002375
Sven Eckelmann807736f2012-07-15 22:26:51 +02002376 atomic_dec(&bat_priv->tt.local_entry_num);
Sasha Levinb67bfe02013-02-27 17:06:00 -08002377 hlist_del_rcu(&tt_common->hash_entry);
Sven Eckelmann56303d32012-06-05 22:31:31 +02002378 tt_local = container_of(tt_common,
2379 struct batadv_tt_local_entry,
2380 common);
2381 batadv_tt_local_entry_free_ref(tt_local);
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002382 }
2383 spin_unlock_bh(list_lock);
2384 }
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002385}
2386
Sven Eckelmann56303d32012-06-05 22:31:31 +02002387static int batadv_tt_commit_changes(struct batadv_priv *bat_priv,
Sven Eckelmanna5130882012-05-16 20:23:16 +02002388 unsigned char **packet_buff,
2389 int *packet_buff_len, int packet_min_len)
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002390{
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002391 uint16_t changed_num = 0;
2392
Sven Eckelmann807736f2012-07-15 22:26:51 +02002393 if (atomic_read(&bat_priv->tt.local_changes) < 1)
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002394 return -ENOENT;
2395
Sven Eckelmann807736f2012-07-15 22:26:51 +02002396 changed_num = batadv_tt_set_flags(bat_priv->tt.local_hash,
Sven Eckelmannacd34af2012-06-03 22:19:21 +02002397 BATADV_TT_CLIENT_NEW, false);
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002398
2399 /* all reset entries have to be counted as local entries */
Sven Eckelmann807736f2012-07-15 22:26:51 +02002400 atomic_add(changed_num, &bat_priv->tt.local_entry_num);
Sven Eckelmanna5130882012-05-16 20:23:16 +02002401 batadv_tt_local_purge_pending_clients(bat_priv);
Sven Eckelmann807736f2012-07-15 22:26:51 +02002402 bat_priv->tt.local_crc = batadv_tt_local_crc(bat_priv);
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002403
2404 /* Increment the TTVN only once per OGM interval */
Sven Eckelmann807736f2012-07-15 22:26:51 +02002405 atomic_inc(&bat_priv->tt.vn);
Sven Eckelmann39c75a52012-06-03 22:19:22 +02002406 batadv_dbg(BATADV_DBG_TT, bat_priv,
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02002407 "Local changes committed, updating to ttvn %u\n",
Sven Eckelmann807736f2012-07-15 22:26:51 +02002408 (uint8_t)atomic_read(&bat_priv->tt.vn));
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002409
2410 /* reset the sending counter */
Sven Eckelmann807736f2012-07-15 22:26:51 +02002411 atomic_set(&bat_priv->tt.ogm_append_cnt, BATADV_TT_OGM_APPEND_MAX);
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002412
Sven Eckelmanna5130882012-05-16 20:23:16 +02002413 return batadv_tt_changes_fill_buff(bat_priv, packet_buff,
2414 packet_buff_len, packet_min_len);
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002415}
2416
2417/* when calling this function (hard_iface == primary_if) has to be true */
Sven Eckelmann56303d32012-06-05 22:31:31 +02002418int batadv_tt_append_diff(struct batadv_priv *bat_priv,
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002419 unsigned char **packet_buff, int *packet_buff_len,
2420 int packet_min_len)
2421{
2422 int tt_num_changes;
2423
2424 /* if at least one change happened */
Sven Eckelmanna5130882012-05-16 20:23:16 +02002425 tt_num_changes = batadv_tt_commit_changes(bat_priv, packet_buff,
2426 packet_buff_len,
2427 packet_min_len);
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002428
2429 /* if the changes have been sent often enough */
2430 if ((tt_num_changes < 0) &&
Sven Eckelmann807736f2012-07-15 22:26:51 +02002431 (!batadv_atomic_dec_not_zero(&bat_priv->tt.ogm_append_cnt))) {
Sven Eckelmanna5130882012-05-16 20:23:16 +02002432 batadv_tt_realloc_packet_buff(packet_buff, packet_buff_len,
2433 packet_min_len, packet_min_len);
Marek Lindnerbe9aa4c2012-05-07 04:22:05 +08002434 tt_num_changes = 0;
2435 }
2436
2437 return tt_num_changes;
Antonio Quartulli058d0e22011-07-07 01:40:58 +02002438}
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002439
Sven Eckelmann56303d32012-06-05 22:31:31 +02002440bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, uint8_t *src,
Sven Eckelmann08c36d32012-05-12 02:09:39 +02002441 uint8_t *dst)
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002442{
Sven Eckelmann56303d32012-06-05 22:31:31 +02002443 struct batadv_tt_local_entry *tt_local_entry = NULL;
2444 struct batadv_tt_global_entry *tt_global_entry = NULL;
Marek Lindner5870adc2012-06-20 17:16:05 +02002445 bool ret = false;
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002446
2447 if (!atomic_read(&bat_priv->ap_isolation))
Marek Lindner5870adc2012-06-20 17:16:05 +02002448 goto out;
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002449
Sven Eckelmanna5130882012-05-16 20:23:16 +02002450 tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst);
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002451 if (!tt_local_entry)
2452 goto out;
2453
Sven Eckelmanna5130882012-05-16 20:23:16 +02002454 tt_global_entry = batadv_tt_global_hash_find(bat_priv, src);
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002455 if (!tt_global_entry)
2456 goto out;
2457
Antonio Quartulli1f129fe2012-06-25 20:49:50 +00002458 if (!_batadv_is_ap_isolated(tt_local_entry, tt_global_entry))
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002459 goto out;
2460
Marek Lindner5870adc2012-06-20 17:16:05 +02002461 ret = true;
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002462
2463out:
2464 if (tt_global_entry)
Sven Eckelmanna5130882012-05-16 20:23:16 +02002465 batadv_tt_global_entry_free_ref(tt_global_entry);
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002466 if (tt_local_entry)
Sven Eckelmanna5130882012-05-16 20:23:16 +02002467 batadv_tt_local_entry_free_ref(tt_local_entry);
Antonio Quartulli59b699c2011-07-07 15:35:36 +02002468 return ret;
2469}
Marek Lindnera943cac2011-07-30 13:10:18 +02002470
Sven Eckelmann56303d32012-06-05 22:31:31 +02002471void batadv_tt_update_orig(struct batadv_priv *bat_priv,
2472 struct batadv_orig_node *orig_node,
Sven Eckelmann08c36d32012-05-12 02:09:39 +02002473 const unsigned char *tt_buff, uint8_t tt_num_changes,
2474 uint8_t ttvn, uint16_t tt_crc)
Marek Lindnera943cac2011-07-30 13:10:18 +02002475{
2476 uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
2477 bool full_table = true;
Sven Eckelmann96412692012-06-05 22:31:30 +02002478 struct batadv_tt_change *tt_change;
Marek Lindnera943cac2011-07-30 13:10:18 +02002479
Simon Wunderlich20ff9d52012-01-22 20:00:23 +01002480 /* don't care about a backbone gateways updates. */
Sven Eckelmann08adf152012-05-12 13:38:47 +02002481 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig))
Simon Wunderlich20ff9d52012-01-22 20:00:23 +01002482 return;
2483
Antonio Quartulli17071572011-11-07 16:36:40 +01002484 /* orig table not initialised AND first diff is in the OGM OR the ttvn
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002485 * increased by one -> we can apply the attached changes
2486 */
Antonio Quartulli17071572011-11-07 16:36:40 +01002487 if ((!orig_node->tt_initialised && ttvn == 1) ||
2488 ttvn - orig_ttvn == 1) {
Marek Lindnera943cac2011-07-30 13:10:18 +02002489 /* the OGM could not contain the changes due to their size or
Sven Eckelmann42d0b042012-06-03 22:19:17 +02002490 * because they have already been sent BATADV_TT_OGM_APPEND_MAX
2491 * times.
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002492 * In this case send a tt request
2493 */
Marek Lindnera943cac2011-07-30 13:10:18 +02002494 if (!tt_num_changes) {
2495 full_table = false;
2496 goto request_table;
2497 }
2498
Sven Eckelmann96412692012-06-05 22:31:30 +02002499 tt_change = (struct batadv_tt_change *)tt_buff;
Sven Eckelmanna5130882012-05-16 20:23:16 +02002500 batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes,
Sven Eckelmann96412692012-06-05 22:31:30 +02002501 ttvn, tt_change);
Marek Lindnera943cac2011-07-30 13:10:18 +02002502
2503 /* Even if we received the precomputed crc with the OGM, we
2504 * prefer to recompute it to spot any possible inconsistency
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002505 * in the global table
2506 */
Sven Eckelmanna5130882012-05-16 20:23:16 +02002507 orig_node->tt_crc = batadv_tt_global_crc(bat_priv, orig_node);
Marek Lindnera943cac2011-07-30 13:10:18 +02002508
2509 /* The ttvn alone is not enough to guarantee consistency
2510 * because a single value could represent different states
2511 * (due to the wrap around). Thus a node has to check whether
2512 * the resulting table (after applying the changes) is still
2513 * consistent or not. E.g. a node could disconnect while its
2514 * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case
2515 * checking the CRC value is mandatory to detect the
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002516 * inconsistency
2517 */
Marek Lindnera943cac2011-07-30 13:10:18 +02002518 if (orig_node->tt_crc != tt_crc)
2519 goto request_table;
Marek Lindnera943cac2011-07-30 13:10:18 +02002520 } else {
2521 /* if we missed more than one change or our tables are not
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02002522 * in sync anymore -> request fresh tt data
2523 */
Antonio Quartulli17071572011-11-07 16:36:40 +01002524 if (!orig_node->tt_initialised || ttvn != orig_ttvn ||
2525 orig_node->tt_crc != tt_crc) {
Marek Lindnera943cac2011-07-30 13:10:18 +02002526request_table:
Sven Eckelmann39c75a52012-06-03 22:19:22 +02002527 batadv_dbg(BATADV_DBG_TT, bat_priv,
Antonio Quartulli39a32992012-11-19 09:01:43 +01002528 "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u crc: %#.4x last_crc: %#.4x num_changes: %u)\n",
Sven Eckelmann1eda58b2012-05-12 13:48:58 +02002529 orig_node->orig, ttvn, orig_ttvn, tt_crc,
2530 orig_node->tt_crc, tt_num_changes);
Sven Eckelmanna5130882012-05-16 20:23:16 +02002531 batadv_send_tt_request(bat_priv, orig_node, ttvn,
2532 tt_crc, full_table);
Marek Lindnera943cac2011-07-30 13:10:18 +02002533 return;
2534 }
2535 }
2536}
Antonio Quartulli3275e7c2012-03-16 18:03:28 +01002537
2538/* returns true whether we know that the client has moved from its old
2539 * originator to another one. This entry is kept is still kept for consistency
2540 * purposes
2541 */
Sven Eckelmann56303d32012-06-05 22:31:31 +02002542bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,
Sven Eckelmann08c36d32012-05-12 02:09:39 +02002543 uint8_t *addr)
Antonio Quartulli3275e7c2012-03-16 18:03:28 +01002544{
Sven Eckelmann56303d32012-06-05 22:31:31 +02002545 struct batadv_tt_global_entry *tt_global_entry;
Antonio Quartulli3275e7c2012-03-16 18:03:28 +01002546 bool ret = false;
2547
Sven Eckelmanna5130882012-05-16 20:23:16 +02002548 tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr);
Antonio Quartulli3275e7c2012-03-16 18:03:28 +01002549 if (!tt_global_entry)
2550 goto out;
2551
Antonio Quartullic1d07432013-01-15 22:17:19 +10002552 ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM;
Sven Eckelmanna5130882012-05-16 20:23:16 +02002553 batadv_tt_global_entry_free_ref(tt_global_entry);
Antonio Quartulli3275e7c2012-03-16 18:03:28 +01002554out:
2555 return ret;
2556}
Antonio Quartulli30cfd022012-07-05 23:38:29 +02002557
Antonio Quartulli7c1fd912012-09-23 22:38:34 +02002558/**
2559 * batadv_tt_local_client_is_roaming - tells whether the client is roaming
2560 * @bat_priv: the bat priv with all the soft interface information
2561 * @addr: the MAC address of the local client to query
2562 *
2563 * Returns true if the local client is known to be roaming (it is not served by
2564 * this node anymore) or not. If yes, the client is still present in the table
2565 * to keep the latter consistent with the node TTVN
2566 */
2567bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv,
2568 uint8_t *addr)
2569{
2570 struct batadv_tt_local_entry *tt_local_entry;
2571 bool ret = false;
2572
2573 tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr);
2574 if (!tt_local_entry)
2575 goto out;
2576
2577 ret = tt_local_entry->common.flags & BATADV_TT_CLIENT_ROAM;
2578 batadv_tt_local_entry_free_ref(tt_local_entry);
2579out:
2580 return ret;
Antonio Quartulli7c1fd912012-09-23 22:38:34 +02002581}
2582
Antonio Quartulli30cfd022012-07-05 23:38:29 +02002583bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
2584 struct batadv_orig_node *orig_node,
2585 const unsigned char *addr)
2586{
2587 bool ret = false;
2588
Antonio Quartulli1f36aeb2012-11-08 21:55:29 +01002589 /* if the originator is a backbone node (meaning it belongs to the same
2590 * LAN of this node) the temporary client must not be added because to
2591 * reach such destination the node must use the LAN instead of the mesh
2592 */
2593 if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig))
2594 goto out;
2595
Antonio Quartulli30cfd022012-07-05 23:38:29 +02002596 if (!batadv_tt_global_add(bat_priv, orig_node, addr,
2597 BATADV_TT_CLIENT_TEMP,
2598 atomic_read(&orig_node->last_ttvn)))
2599 goto out;
2600
2601 batadv_dbg(BATADV_DBG_TT, bat_priv,
2602 "Added temporary global client (addr: %pM orig: %pM)\n",
2603 addr, orig_node->orig);
2604 ret = true;
2605out:
2606 return ret;
2607}