Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1 | /* |
Sven Eckelmann | 64afe35 | 2011-01-27 10:38:15 +0100 | [diff] [blame] | 2 | * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 3 | * |
| 4 | * Marek Lindner, Simon Wunderlich |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of version 2 of the GNU General Public |
| 8 | * License as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 | * 02110-1301, USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "main.h" |
| 23 | #include "translation-table.h" |
| 24 | #include "soft-interface.h" |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 25 | #include "hard-interface.h" |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 26 | #include "send.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 27 | #include "hash.h" |
| 28 | #include "originator.h" |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 29 | #include "routing.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 30 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 31 | #include <linux/crc16.h> |
| 32 | |
| 33 | static void _tt_global_del(struct bat_priv *bat_priv, |
| 34 | struct tt_global_entry *tt_global_entry, |
| 35 | const char *message); |
| 36 | static void tt_purge(struct work_struct *work); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 37 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 38 | /* returns 1 if they are the same mac addr */ |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 39 | static int compare_ltt(const struct hlist_node *node, const void *data2) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 40 | { |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 41 | const void *data1 = container_of(node, struct tt_local_entry, |
| 42 | hash_entry); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 43 | |
| 44 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
| 45 | } |
| 46 | |
| 47 | /* returns 1 if they are the same mac addr */ |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 48 | static int compare_gtt(const struct hlist_node *node, const void *data2) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 49 | { |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 50 | const void *data1 = container_of(node, struct tt_global_entry, |
| 51 | hash_entry); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 52 | |
| 53 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
| 54 | } |
| 55 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 56 | static void tt_start_timer(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 57 | { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 58 | INIT_DELAYED_WORK(&bat_priv->tt_work, tt_purge); |
| 59 | queue_delayed_work(bat_event_workqueue, &bat_priv->tt_work, |
| 60 | msecs_to_jiffies(5000)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 63 | static struct tt_local_entry *tt_local_hash_find(struct bat_priv *bat_priv, |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 64 | const void *data) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 65 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 66 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 67 | struct hlist_head *head; |
| 68 | struct hlist_node *node; |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 69 | struct tt_local_entry *tt_local_entry, *tt_local_entry_tmp = NULL; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 70 | int index; |
| 71 | |
| 72 | if (!hash) |
| 73 | return NULL; |
| 74 | |
| 75 | index = choose_orig(data, hash->size); |
| 76 | head = &hash->table[index]; |
| 77 | |
| 78 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 79 | hlist_for_each_entry_rcu(tt_local_entry, node, head, hash_entry) { |
| 80 | if (!compare_eth(tt_local_entry, data)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 81 | continue; |
| 82 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 83 | if (!atomic_inc_not_zero(&tt_local_entry->refcount)) |
| 84 | continue; |
| 85 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 86 | tt_local_entry_tmp = tt_local_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 87 | break; |
| 88 | } |
| 89 | rcu_read_unlock(); |
| 90 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 91 | return tt_local_entry_tmp; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 94 | static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 95 | const void *data) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 96 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 97 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 98 | struct hlist_head *head; |
| 99 | struct hlist_node *node; |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 100 | struct tt_global_entry *tt_global_entry; |
| 101 | struct tt_global_entry *tt_global_entry_tmp = NULL; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 102 | int index; |
| 103 | |
| 104 | if (!hash) |
| 105 | return NULL; |
| 106 | |
| 107 | index = choose_orig(data, hash->size); |
| 108 | head = &hash->table[index]; |
| 109 | |
| 110 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 111 | hlist_for_each_entry_rcu(tt_global_entry, node, head, hash_entry) { |
| 112 | if (!compare_eth(tt_global_entry, data)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 113 | continue; |
| 114 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 115 | if (!atomic_inc_not_zero(&tt_global_entry->refcount)) |
| 116 | continue; |
| 117 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 118 | tt_global_entry_tmp = tt_global_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 119 | break; |
| 120 | } |
| 121 | rcu_read_unlock(); |
| 122 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 123 | return tt_global_entry_tmp; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 126 | static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) |
| 127 | { |
| 128 | unsigned long deadline; |
| 129 | deadline = starting_time + msecs_to_jiffies(timeout); |
| 130 | |
| 131 | return time_after(jiffies, deadline); |
| 132 | } |
| 133 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 134 | static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) |
| 135 | { |
| 136 | if (atomic_dec_and_test(&tt_local_entry->refcount)) |
| 137 | kfree_rcu(tt_local_entry, rcu); |
| 138 | } |
| 139 | |
Simon Wunderlich | 531027f | 2011-10-19 11:02:25 +0200 | [diff] [blame^] | 140 | static void tt_global_entry_free_rcu(struct rcu_head *rcu) |
| 141 | { |
| 142 | struct tt_global_entry *tt_global_entry; |
| 143 | |
| 144 | tt_global_entry = container_of(rcu, struct tt_global_entry, rcu); |
| 145 | |
| 146 | if (tt_global_entry->orig_node) |
| 147 | orig_node_free_ref(tt_global_entry->orig_node); |
| 148 | |
| 149 | kfree(tt_global_entry); |
| 150 | } |
| 151 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 152 | static void tt_global_entry_free_ref(struct tt_global_entry *tt_global_entry) |
| 153 | { |
| 154 | if (atomic_dec_and_test(&tt_global_entry->refcount)) |
Simon Wunderlich | 531027f | 2011-10-19 11:02:25 +0200 | [diff] [blame^] | 155 | call_rcu(&tt_global_entry->rcu, tt_global_entry_free_rcu); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 156 | } |
| 157 | |
Antonio Quartulli | ff66c97 | 2011-06-30 01:14:00 +0200 | [diff] [blame] | 158 | static void tt_local_event(struct bat_priv *bat_priv, const uint8_t *addr, |
| 159 | uint8_t flags) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 160 | { |
| 161 | struct tt_change_node *tt_change_node; |
| 162 | |
| 163 | tt_change_node = kmalloc(sizeof(*tt_change_node), GFP_ATOMIC); |
| 164 | |
| 165 | if (!tt_change_node) |
| 166 | return; |
| 167 | |
Antonio Quartulli | ff66c97 | 2011-06-30 01:14:00 +0200 | [diff] [blame] | 168 | tt_change_node->change.flags = flags; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 169 | memcpy(tt_change_node->change.addr, addr, ETH_ALEN); |
| 170 | |
| 171 | spin_lock_bh(&bat_priv->tt_changes_list_lock); |
| 172 | /* track the change in the OGMinterval list */ |
| 173 | list_add_tail(&tt_change_node->list, &bat_priv->tt_changes_list); |
| 174 | atomic_inc(&bat_priv->tt_local_changes); |
| 175 | spin_unlock_bh(&bat_priv->tt_changes_list_lock); |
| 176 | |
| 177 | atomic_set(&bat_priv->tt_ogm_append_cnt, 0); |
| 178 | } |
| 179 | |
| 180 | int tt_len(int changes_num) |
| 181 | { |
| 182 | return changes_num * sizeof(struct tt_change); |
| 183 | } |
| 184 | |
| 185 | static int tt_local_init(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 186 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 187 | if (bat_priv->tt_local_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 188 | return 1; |
| 189 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 190 | bat_priv->tt_local_hash = hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 191 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 192 | if (!bat_priv->tt_local_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 193 | return 0; |
| 194 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 195 | return 1; |
| 196 | } |
| 197 | |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 198 | void tt_local_add(struct net_device *soft_iface, const uint8_t *addr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 199 | { |
| 200 | struct bat_priv *bat_priv = netdev_priv(soft_iface); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 201 | struct tt_local_entry *tt_local_entry = NULL; |
| 202 | struct tt_global_entry *tt_global_entry = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 203 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 204 | tt_local_entry = tt_local_hash_find(bat_priv, addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 205 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 206 | if (tt_local_entry) { |
| 207 | tt_local_entry->last_seen = jiffies; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 208 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 211 | tt_local_entry = kmalloc(sizeof(*tt_local_entry), GFP_ATOMIC); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 212 | if (!tt_local_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 213 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 214 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 215 | bat_dbg(DBG_TT, bat_priv, |
| 216 | "Creating new local tt entry: %pM (ttvn: %d)\n", addr, |
| 217 | (uint8_t)atomic_read(&bat_priv->ttvn)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 218 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 219 | memcpy(tt_local_entry->addr, addr, ETH_ALEN); |
| 220 | tt_local_entry->last_seen = jiffies; |
Antonio Quartulli | 5fbc159 | 2011-06-17 16:11:27 +0200 | [diff] [blame] | 221 | tt_local_entry->flags = NO_FLAGS; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 222 | atomic_set(&tt_local_entry->refcount, 2); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 223 | |
| 224 | /* the batman interface mac address should never be purged */ |
Marek Lindner | 39901e7 | 2011-02-18 12:28:08 +0000 | [diff] [blame] | 225 | if (compare_eth(addr, soft_iface->dev_addr)) |
Antonio Quartulli | 5fbc159 | 2011-06-17 16:11:27 +0200 | [diff] [blame] | 226 | tt_local_entry->flags |= TT_CLIENT_NOPURGE; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 227 | |
Antonio Quartulli | ff66c97 | 2011-06-30 01:14:00 +0200 | [diff] [blame] | 228 | tt_local_event(bat_priv, addr, tt_local_entry->flags); |
| 229 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 230 | /* The local entry has to be marked as NEW to avoid to send it in |
| 231 | * a full table response going out before the next ttvn increment |
| 232 | * (consistency check) */ |
| 233 | tt_local_entry->flags |= TT_CLIENT_NEW; |
| 234 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 235 | hash_add(bat_priv->tt_local_hash, compare_ltt, choose_orig, |
| 236 | tt_local_entry, &tt_local_entry->hash_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 237 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 238 | /* remove address from global hash if present */ |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 239 | tt_global_entry = tt_global_hash_find(bat_priv, addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 240 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 241 | /* Check whether it is a roaming! */ |
| 242 | if (tt_global_entry) { |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 243 | /* This node is probably going to update its tt table */ |
| 244 | tt_global_entry->orig_node->tt_poss_change = true; |
Antonio Quartulli | 980d55b | 2011-07-07 01:40:59 +0200 | [diff] [blame] | 245 | /* The global entry has to be marked as PENDING and has to be |
| 246 | * kept for consistency purpose */ |
| 247 | tt_global_entry->flags |= TT_CLIENT_PENDING; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 248 | send_roam_adv(bat_priv, tt_global_entry->addr, |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 249 | tt_global_entry->orig_node); |
| 250 | } |
| 251 | out: |
| 252 | if (tt_local_entry) |
| 253 | tt_local_entry_free_ref(tt_local_entry); |
| 254 | if (tt_global_entry) |
| 255 | tt_global_entry_free_ref(tt_global_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 258 | int tt_changes_fill_buffer(struct bat_priv *bat_priv, |
| 259 | unsigned char *buff, int buff_len) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 260 | { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 261 | int count = 0, tot_changes = 0; |
| 262 | struct tt_change_node *entry, *safe; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 263 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 264 | if (buff_len > 0) |
| 265 | tot_changes = buff_len / tt_len(1); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 266 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 267 | spin_lock_bh(&bat_priv->tt_changes_list_lock); |
| 268 | atomic_set(&bat_priv->tt_local_changes, 0); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 269 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 270 | list_for_each_entry_safe(entry, safe, &bat_priv->tt_changes_list, |
| 271 | list) { |
| 272 | if (count < tot_changes) { |
| 273 | memcpy(buff + tt_len(count), |
| 274 | &entry->change, sizeof(struct tt_change)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 275 | count++; |
| 276 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 277 | list_del(&entry->list); |
| 278 | kfree(entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 279 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 280 | spin_unlock_bh(&bat_priv->tt_changes_list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 281 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 282 | /* Keep the buffer for possible tt_request */ |
| 283 | spin_lock_bh(&bat_priv->tt_buff_lock); |
| 284 | kfree(bat_priv->tt_buff); |
| 285 | bat_priv->tt_buff_len = 0; |
| 286 | bat_priv->tt_buff = NULL; |
| 287 | /* We check whether this new OGM has no changes due to size |
| 288 | * problems */ |
| 289 | if (buff_len > 0) { |
| 290 | /** |
| 291 | * if kmalloc() fails we will reply with the full table |
| 292 | * instead of providing the diff |
| 293 | */ |
| 294 | bat_priv->tt_buff = kmalloc(buff_len, GFP_ATOMIC); |
| 295 | if (bat_priv->tt_buff) { |
| 296 | memcpy(bat_priv->tt_buff, buff, buff_len); |
| 297 | bat_priv->tt_buff_len = buff_len; |
| 298 | } |
| 299 | } |
| 300 | spin_unlock_bh(&bat_priv->tt_buff_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 301 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 302 | return tot_changes; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 305 | int tt_local_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 306 | { |
| 307 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 308 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 309 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 310 | struct tt_local_entry *tt_local_entry; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 311 | struct hard_iface *primary_if; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 312 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 313 | struct hlist_head *head; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 314 | size_t buf_size, pos; |
| 315 | char *buff; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 316 | int i, ret = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 317 | |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 318 | primary_if = primary_if_get_selected(bat_priv); |
| 319 | if (!primary_if) { |
| 320 | ret = seq_printf(seq, "BATMAN mesh %s disabled - " |
| 321 | "please specify interfaces to enable it\n", |
| 322 | net_dev->name); |
| 323 | goto out; |
| 324 | } |
| 325 | |
| 326 | if (primary_if->if_status != IF_ACTIVE) { |
| 327 | ret = seq_printf(seq, "BATMAN mesh %s disabled - " |
| 328 | "primary interface not active\n", |
| 329 | net_dev->name); |
| 330 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | seq_printf(seq, "Locally retrieved addresses (from %s) " |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 334 | "announced via TT (TTVN: %u):\n", |
| 335 | net_dev->name, (uint8_t)atomic_read(&bat_priv->ttvn)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 336 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 337 | buf_size = 1; |
| 338 | /* Estimate length for: " * xx:xx:xx:xx:xx:xx\n" */ |
| 339 | for (i = 0; i < hash->size; i++) { |
| 340 | head = &hash->table[i]; |
| 341 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 342 | rcu_read_lock(); |
| 343 | __hlist_for_each_rcu(node, head) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 344 | buf_size += 21; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 345 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | buff = kmalloc(buf_size, GFP_ATOMIC); |
| 349 | if (!buff) { |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 350 | ret = -ENOMEM; |
| 351 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 352 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 353 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 354 | buff[0] = '\0'; |
| 355 | pos = 0; |
| 356 | |
| 357 | for (i = 0; i < hash->size; i++) { |
| 358 | head = &hash->table[i]; |
| 359 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 360 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 361 | hlist_for_each_entry_rcu(tt_local_entry, node, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 362 | head, hash_entry) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 363 | pos += snprintf(buff + pos, 22, " * %pM\n", |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 364 | tt_local_entry->addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 365 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 366 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 369 | seq_printf(seq, "%s", buff); |
| 370 | kfree(buff); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 371 | out: |
| 372 | if (primary_if) |
| 373 | hardif_free_ref(primary_if); |
| 374 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 377 | static void tt_local_set_pending(struct bat_priv *bat_priv, |
| 378 | struct tt_local_entry *tt_local_entry, |
| 379 | uint16_t flags) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 380 | { |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 381 | tt_local_event(bat_priv, tt_local_entry->addr, |
| 382 | tt_local_entry->flags | flags); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 383 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 384 | /* The local client has to be merked as "pending to be removed" but has |
| 385 | * to be kept in the table in order to send it in an full tables |
| 386 | * response issued before the net ttvn increment (consistency check) */ |
| 387 | tt_local_entry->flags |= TT_CLIENT_PENDING; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 390 | void tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr, |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 391 | const char *message, bool roaming) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 392 | { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 393 | struct tt_local_entry *tt_local_entry = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 394 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 395 | tt_local_entry = tt_local_hash_find(bat_priv, addr); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 396 | if (!tt_local_entry) |
| 397 | goto out; |
| 398 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 399 | tt_local_set_pending(bat_priv, tt_local_entry, TT_CLIENT_DEL | |
| 400 | (roaming ? TT_CLIENT_ROAM : NO_FLAGS)); |
| 401 | |
| 402 | bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) pending to be removed: " |
| 403 | "%s\n", tt_local_entry->addr, message); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 404 | out: |
| 405 | if (tt_local_entry) |
| 406 | tt_local_entry_free_ref(tt_local_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 409 | static void tt_local_purge(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 410 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 411 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 412 | struct tt_local_entry *tt_local_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 413 | struct hlist_node *node, *node_tmp; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 414 | struct hlist_head *head; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 415 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 416 | int i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 417 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 418 | for (i = 0; i < hash->size; i++) { |
| 419 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 420 | list_lock = &hash->list_locks[i]; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 421 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 422 | spin_lock_bh(list_lock); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 423 | hlist_for_each_entry_safe(tt_local_entry, node, node_tmp, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 424 | head, hash_entry) { |
Antonio Quartulli | 5fbc159 | 2011-06-17 16:11:27 +0200 | [diff] [blame] | 425 | if (tt_local_entry->flags & TT_CLIENT_NOPURGE) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 426 | continue; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 427 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 428 | /* entry already marked for deletion */ |
| 429 | if (tt_local_entry->flags & TT_CLIENT_PENDING) |
| 430 | continue; |
| 431 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 432 | if (!is_out_of_time(tt_local_entry->last_seen, |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 433 | TT_LOCAL_TIMEOUT * 1000)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 434 | continue; |
| 435 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 436 | tt_local_set_pending(bat_priv, tt_local_entry, |
| 437 | TT_CLIENT_DEL); |
| 438 | bat_dbg(DBG_TT, bat_priv, "Local tt entry (%pM) " |
| 439 | "pending to be removed: timed out\n", |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 440 | tt_local_entry->addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 441 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 442 | spin_unlock_bh(list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 447 | static void tt_local_table_free(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 448 | { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 449 | struct hashtable_t *hash; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 450 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 451 | struct tt_local_entry *tt_local_entry; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 452 | struct hlist_node *node, *node_tmp; |
| 453 | struct hlist_head *head; |
| 454 | int i; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 455 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 456 | if (!bat_priv->tt_local_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 457 | return; |
| 458 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 459 | hash = bat_priv->tt_local_hash; |
| 460 | |
| 461 | for (i = 0; i < hash->size; i++) { |
| 462 | head = &hash->table[i]; |
| 463 | list_lock = &hash->list_locks[i]; |
| 464 | |
| 465 | spin_lock_bh(list_lock); |
| 466 | hlist_for_each_entry_safe(tt_local_entry, node, node_tmp, |
| 467 | head, hash_entry) { |
| 468 | hlist_del_rcu(node); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 469 | tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 470 | } |
| 471 | spin_unlock_bh(list_lock); |
| 472 | } |
| 473 | |
| 474 | hash_destroy(hash); |
| 475 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 476 | bat_priv->tt_local_hash = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 479 | static int tt_global_init(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 480 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 481 | if (bat_priv->tt_global_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 482 | return 1; |
| 483 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 484 | bat_priv->tt_global_hash = hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 485 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 486 | if (!bat_priv->tt_global_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 487 | return 0; |
| 488 | |
| 489 | return 1; |
| 490 | } |
| 491 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 492 | static void tt_changes_list_free(struct bat_priv *bat_priv) |
| 493 | { |
| 494 | struct tt_change_node *entry, *safe; |
| 495 | |
| 496 | spin_lock_bh(&bat_priv->tt_changes_list_lock); |
| 497 | |
| 498 | list_for_each_entry_safe(entry, safe, &bat_priv->tt_changes_list, |
| 499 | list) { |
| 500 | list_del(&entry->list); |
| 501 | kfree(entry); |
| 502 | } |
| 503 | |
| 504 | atomic_set(&bat_priv->tt_local_changes, 0); |
| 505 | spin_unlock_bh(&bat_priv->tt_changes_list_lock); |
| 506 | } |
| 507 | |
| 508 | /* caller must hold orig_node refcount */ |
| 509 | int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 510 | const unsigned char *tt_addr, uint8_t ttvn, bool roaming) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 511 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 512 | struct tt_global_entry *tt_global_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 513 | struct orig_node *orig_node_tmp; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 514 | int ret = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 515 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 516 | tt_global_entry = tt_global_hash_find(bat_priv, tt_addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 517 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 518 | if (!tt_global_entry) { |
| 519 | tt_global_entry = |
| 520 | kmalloc(sizeof(*tt_global_entry), |
| 521 | GFP_ATOMIC); |
| 522 | if (!tt_global_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 523 | goto out; |
| 524 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 525 | memcpy(tt_global_entry->addr, tt_addr, ETH_ALEN); |
| 526 | /* Assign the new orig_node */ |
| 527 | atomic_inc(&orig_node->refcount); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 528 | tt_global_entry->orig_node = orig_node; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 529 | tt_global_entry->ttvn = ttvn; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 530 | tt_global_entry->flags = NO_FLAGS; |
| 531 | tt_global_entry->roam_at = 0; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 532 | atomic_set(&tt_global_entry->refcount, 2); |
| 533 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 534 | hash_add(bat_priv->tt_global_hash, compare_gtt, |
| 535 | choose_orig, tt_global_entry, |
| 536 | &tt_global_entry->hash_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 537 | atomic_inc(&orig_node->tt_size); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 538 | } else { |
| 539 | if (tt_global_entry->orig_node != orig_node) { |
| 540 | atomic_dec(&tt_global_entry->orig_node->tt_size); |
| 541 | orig_node_tmp = tt_global_entry->orig_node; |
| 542 | atomic_inc(&orig_node->refcount); |
| 543 | tt_global_entry->orig_node = orig_node; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 544 | orig_node_free_ref(orig_node_tmp); |
| 545 | atomic_inc(&orig_node->tt_size); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 546 | } |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 547 | tt_global_entry->ttvn = ttvn; |
| 548 | tt_global_entry->flags = NO_FLAGS; |
| 549 | tt_global_entry->roam_at = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 550 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 551 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 552 | bat_dbg(DBG_TT, bat_priv, |
| 553 | "Creating new global tt entry: %pM (via %pM)\n", |
| 554 | tt_global_entry->addr, orig_node->orig); |
| 555 | |
| 556 | /* remove address from local hash if present */ |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 557 | tt_local_remove(bat_priv, tt_global_entry->addr, |
| 558 | "global tt received", roaming); |
| 559 | ret = 1; |
| 560 | out: |
| 561 | if (tt_global_entry) |
| 562 | tt_global_entry_free_ref(tt_global_entry); |
| 563 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 566 | int tt_global_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 567 | { |
| 568 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 569 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 570 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
| 571 | struct tt_global_entry *tt_global_entry; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 572 | struct hard_iface *primary_if; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 573 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 574 | struct hlist_head *head; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 575 | size_t buf_size, pos; |
| 576 | char *buff; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 577 | int i, ret = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 578 | |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 579 | primary_if = primary_if_get_selected(bat_priv); |
| 580 | if (!primary_if) { |
| 581 | ret = seq_printf(seq, "BATMAN mesh %s disabled - please " |
| 582 | "specify interfaces to enable it\n", |
| 583 | net_dev->name); |
| 584 | goto out; |
| 585 | } |
| 586 | |
| 587 | if (primary_if->if_status != IF_ACTIVE) { |
| 588 | ret = seq_printf(seq, "BATMAN mesh %s disabled - " |
| 589 | "primary interface not active\n", |
| 590 | net_dev->name); |
| 591 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 594 | seq_printf(seq, |
| 595 | "Globally announced TT entries received via the mesh %s\n", |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 596 | net_dev->name); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 597 | seq_printf(seq, " %-13s %s %-15s %s\n", |
| 598 | "Client", "(TTVN)", "Originator", "(Curr TTVN)"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 599 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 600 | buf_size = 1; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 601 | /* Estimate length for: " * xx:xx:xx:xx:xx:xx (ttvn) via |
| 602 | * xx:xx:xx:xx:xx:xx (cur_ttvn)\n"*/ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 603 | for (i = 0; i < hash->size; i++) { |
| 604 | head = &hash->table[i]; |
| 605 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 606 | rcu_read_lock(); |
| 607 | __hlist_for_each_rcu(node, head) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 608 | buf_size += 59; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 609 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | buff = kmalloc(buf_size, GFP_ATOMIC); |
| 613 | if (!buff) { |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 614 | ret = -ENOMEM; |
| 615 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 616 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 617 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 618 | buff[0] = '\0'; |
| 619 | pos = 0; |
| 620 | |
| 621 | for (i = 0; i < hash->size; i++) { |
| 622 | head = &hash->table[i]; |
| 623 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 624 | rcu_read_lock(); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 625 | hlist_for_each_entry_rcu(tt_global_entry, node, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 626 | head, hash_entry) { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 627 | pos += snprintf(buff + pos, 61, |
| 628 | " * %pM (%3u) via %pM (%3u)\n", |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 629 | tt_global_entry->addr, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 630 | tt_global_entry->ttvn, |
| 631 | tt_global_entry->orig_node->orig, |
| 632 | (uint8_t) atomic_read( |
| 633 | &tt_global_entry->orig_node-> |
| 634 | last_ttvn)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 635 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 636 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 639 | seq_printf(seq, "%s", buff); |
| 640 | kfree(buff); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 641 | out: |
| 642 | if (primary_if) |
| 643 | hardif_free_ref(primary_if); |
| 644 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 647 | static void _tt_global_del(struct bat_priv *bat_priv, |
| 648 | struct tt_global_entry *tt_global_entry, |
| 649 | const char *message) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 650 | { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 651 | if (!tt_global_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 652 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 653 | |
| 654 | bat_dbg(DBG_TT, bat_priv, |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 655 | "Deleting global tt entry %pM (via %pM): %s\n", |
| 656 | tt_global_entry->addr, tt_global_entry->orig_node->orig, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 657 | message); |
| 658 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 659 | atomic_dec(&tt_global_entry->orig_node->tt_size); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 660 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 661 | hash_remove(bat_priv->tt_global_hash, compare_gtt, choose_orig, |
| 662 | tt_global_entry->addr); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 663 | out: |
| 664 | if (tt_global_entry) |
| 665 | tt_global_entry_free_ref(tt_global_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 668 | void tt_global_del(struct bat_priv *bat_priv, |
| 669 | struct orig_node *orig_node, const unsigned char *addr, |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 670 | const char *message, bool roaming) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 671 | { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 672 | struct tt_global_entry *tt_global_entry = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 673 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 674 | tt_global_entry = tt_global_hash_find(bat_priv, addr); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 675 | if (!tt_global_entry) |
| 676 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 677 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 678 | if (tt_global_entry->orig_node == orig_node) { |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 679 | if (roaming) { |
| 680 | tt_global_entry->flags |= TT_CLIENT_ROAM; |
| 681 | tt_global_entry->roam_at = jiffies; |
| 682 | goto out; |
| 683 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 684 | _tt_global_del(bat_priv, tt_global_entry, message); |
| 685 | } |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 686 | out: |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 687 | if (tt_global_entry) |
| 688 | tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | void tt_global_del_orig(struct bat_priv *bat_priv, |
| 692 | struct orig_node *orig_node, const char *message) |
| 693 | { |
| 694 | struct tt_global_entry *tt_global_entry; |
| 695 | int i; |
| 696 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
| 697 | struct hlist_node *node, *safe; |
| 698 | struct hlist_head *head; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 699 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 700 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 701 | for (i = 0; i < hash->size; i++) { |
| 702 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 703 | list_lock = &hash->list_locks[i]; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 704 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 705 | spin_lock_bh(list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 706 | hlist_for_each_entry_safe(tt_global_entry, node, safe, |
| 707 | head, hash_entry) { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 708 | if (tt_global_entry->orig_node == orig_node) { |
| 709 | bat_dbg(DBG_TT, bat_priv, |
| 710 | "Deleting global tt entry %pM " |
| 711 | "(via %pM): originator time out\n", |
| 712 | tt_global_entry->addr, |
| 713 | tt_global_entry->orig_node->orig); |
| 714 | hlist_del_rcu(node); |
| 715 | tt_global_entry_free_ref(tt_global_entry); |
| 716 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 717 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 718 | spin_unlock_bh(list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 719 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 720 | atomic_set(&orig_node->tt_size, 0); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 723 | static void tt_global_roam_purge(struct bat_priv *bat_priv) |
| 724 | { |
| 725 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
| 726 | struct tt_global_entry *tt_global_entry; |
| 727 | struct hlist_node *node, *node_tmp; |
| 728 | struct hlist_head *head; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 729 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 730 | int i; |
| 731 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 732 | for (i = 0; i < hash->size; i++) { |
| 733 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 734 | list_lock = &hash->list_locks[i]; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 735 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 736 | spin_lock_bh(list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 737 | hlist_for_each_entry_safe(tt_global_entry, node, node_tmp, |
| 738 | head, hash_entry) { |
| 739 | if (!(tt_global_entry->flags & TT_CLIENT_ROAM)) |
| 740 | continue; |
| 741 | if (!is_out_of_time(tt_global_entry->roam_at, |
| 742 | TT_CLIENT_ROAM_TIMEOUT * 1000)) |
| 743 | continue; |
| 744 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 745 | bat_dbg(DBG_TT, bat_priv, "Deleting global " |
| 746 | "tt entry (%pM): Roaming timeout\n", |
| 747 | tt_global_entry->addr); |
| 748 | atomic_dec(&tt_global_entry->orig_node->tt_size); |
| 749 | hlist_del_rcu(node); |
| 750 | tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 751 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 752 | spin_unlock_bh(list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 753 | } |
| 754 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 755 | } |
| 756 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 757 | static void tt_global_table_free(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 758 | { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 759 | struct hashtable_t *hash; |
| 760 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
| 761 | struct tt_global_entry *tt_global_entry; |
| 762 | struct hlist_node *node, *node_tmp; |
| 763 | struct hlist_head *head; |
| 764 | int i; |
| 765 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 766 | if (!bat_priv->tt_global_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 767 | return; |
| 768 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 769 | hash = bat_priv->tt_global_hash; |
| 770 | |
| 771 | for (i = 0; i < hash->size; i++) { |
| 772 | head = &hash->table[i]; |
| 773 | list_lock = &hash->list_locks[i]; |
| 774 | |
| 775 | spin_lock_bh(list_lock); |
| 776 | hlist_for_each_entry_safe(tt_global_entry, node, node_tmp, |
| 777 | head, hash_entry) { |
| 778 | hlist_del_rcu(node); |
| 779 | tt_global_entry_free_ref(tt_global_entry); |
| 780 | } |
| 781 | spin_unlock_bh(list_lock); |
| 782 | } |
| 783 | |
| 784 | hash_destroy(hash); |
| 785 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 786 | bat_priv->tt_global_hash = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 789 | struct orig_node *transtable_search(struct bat_priv *bat_priv, |
| 790 | const uint8_t *addr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 791 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 792 | struct tt_global_entry *tt_global_entry; |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 793 | struct orig_node *orig_node = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 794 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 795 | tt_global_entry = tt_global_hash_find(bat_priv, addr); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 796 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 797 | if (!tt_global_entry) |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 798 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 799 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 800 | if (!atomic_inc_not_zero(&tt_global_entry->orig_node->refcount)) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 801 | goto free_tt; |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 802 | |
Antonio Quartulli | 980d55b | 2011-07-07 01:40:59 +0200 | [diff] [blame] | 803 | /* A global client marked as PENDING has already moved from that |
| 804 | * originator */ |
| 805 | if (tt_global_entry->flags & TT_CLIENT_PENDING) |
| 806 | goto free_tt; |
| 807 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 808 | orig_node = tt_global_entry->orig_node; |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 809 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 810 | free_tt: |
| 811 | tt_global_entry_free_ref(tt_global_entry); |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 812 | out: |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 813 | return orig_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 814 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 815 | |
| 816 | /* Calculates the checksum of the local table of a given orig_node */ |
| 817 | uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node) |
| 818 | { |
| 819 | uint16_t total = 0, total_one; |
| 820 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
| 821 | struct tt_global_entry *tt_global_entry; |
| 822 | struct hlist_node *node; |
| 823 | struct hlist_head *head; |
| 824 | int i, j; |
| 825 | |
| 826 | for (i = 0; i < hash->size; i++) { |
| 827 | head = &hash->table[i]; |
| 828 | |
| 829 | rcu_read_lock(); |
| 830 | hlist_for_each_entry_rcu(tt_global_entry, node, |
| 831 | head, hash_entry) { |
| 832 | if (compare_eth(tt_global_entry->orig_node, |
| 833 | orig_node)) { |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 834 | /* Roaming clients are in the global table for |
| 835 | * consistency only. They don't have to be |
| 836 | * taken into account while computing the |
| 837 | * global crc */ |
| 838 | if (tt_global_entry->flags & TT_CLIENT_ROAM) |
| 839 | continue; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 840 | total_one = 0; |
| 841 | for (j = 0; j < ETH_ALEN; j++) |
| 842 | total_one = crc16_byte(total_one, |
| 843 | tt_global_entry->addr[j]); |
| 844 | total ^= total_one; |
| 845 | } |
| 846 | } |
| 847 | rcu_read_unlock(); |
| 848 | } |
| 849 | |
| 850 | return total; |
| 851 | } |
| 852 | |
| 853 | /* Calculates the checksum of the local table */ |
| 854 | uint16_t tt_local_crc(struct bat_priv *bat_priv) |
| 855 | { |
| 856 | uint16_t total = 0, total_one; |
| 857 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 858 | struct tt_local_entry *tt_local_entry; |
| 859 | struct hlist_node *node; |
| 860 | struct hlist_head *head; |
| 861 | int i, j; |
| 862 | |
| 863 | for (i = 0; i < hash->size; i++) { |
| 864 | head = &hash->table[i]; |
| 865 | |
| 866 | rcu_read_lock(); |
| 867 | hlist_for_each_entry_rcu(tt_local_entry, node, |
| 868 | head, hash_entry) { |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 869 | /* not yet committed clients have not to be taken into |
| 870 | * account while computing the CRC */ |
| 871 | if (tt_local_entry->flags & TT_CLIENT_NEW) |
| 872 | continue; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 873 | total_one = 0; |
| 874 | for (j = 0; j < ETH_ALEN; j++) |
| 875 | total_one = crc16_byte(total_one, |
| 876 | tt_local_entry->addr[j]); |
| 877 | total ^= total_one; |
| 878 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 879 | rcu_read_unlock(); |
| 880 | } |
| 881 | |
| 882 | return total; |
| 883 | } |
| 884 | |
| 885 | static void tt_req_list_free(struct bat_priv *bat_priv) |
| 886 | { |
| 887 | struct tt_req_node *node, *safe; |
| 888 | |
| 889 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 890 | |
| 891 | list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { |
| 892 | list_del(&node->list); |
| 893 | kfree(node); |
| 894 | } |
| 895 | |
| 896 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 897 | } |
| 898 | |
| 899 | void tt_save_orig_buffer(struct bat_priv *bat_priv, struct orig_node *orig_node, |
| 900 | const unsigned char *tt_buff, uint8_t tt_num_changes) |
| 901 | { |
| 902 | uint16_t tt_buff_len = tt_len(tt_num_changes); |
| 903 | |
| 904 | /* Replace the old buffer only if I received something in the |
| 905 | * last OGM (the OGM could carry no changes) */ |
| 906 | spin_lock_bh(&orig_node->tt_buff_lock); |
| 907 | if (tt_buff_len > 0) { |
| 908 | kfree(orig_node->tt_buff); |
| 909 | orig_node->tt_buff_len = 0; |
| 910 | orig_node->tt_buff = kmalloc(tt_buff_len, GFP_ATOMIC); |
| 911 | if (orig_node->tt_buff) { |
| 912 | memcpy(orig_node->tt_buff, tt_buff, tt_buff_len); |
| 913 | orig_node->tt_buff_len = tt_buff_len; |
| 914 | } |
| 915 | } |
| 916 | spin_unlock_bh(&orig_node->tt_buff_lock); |
| 917 | } |
| 918 | |
| 919 | static void tt_req_purge(struct bat_priv *bat_priv) |
| 920 | { |
| 921 | struct tt_req_node *node, *safe; |
| 922 | |
| 923 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 924 | list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { |
| 925 | if (is_out_of_time(node->issued_at, |
| 926 | TT_REQUEST_TIMEOUT * 1000)) { |
| 927 | list_del(&node->list); |
| 928 | kfree(node); |
| 929 | } |
| 930 | } |
| 931 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 932 | } |
| 933 | |
| 934 | /* returns the pointer to the new tt_req_node struct if no request |
| 935 | * has already been issued for this orig_node, NULL otherwise */ |
| 936 | static struct tt_req_node *new_tt_req_node(struct bat_priv *bat_priv, |
| 937 | struct orig_node *orig_node) |
| 938 | { |
| 939 | struct tt_req_node *tt_req_node_tmp, *tt_req_node = NULL; |
| 940 | |
| 941 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 942 | list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) { |
| 943 | if (compare_eth(tt_req_node_tmp, orig_node) && |
| 944 | !is_out_of_time(tt_req_node_tmp->issued_at, |
| 945 | TT_REQUEST_TIMEOUT * 1000)) |
| 946 | goto unlock; |
| 947 | } |
| 948 | |
| 949 | tt_req_node = kmalloc(sizeof(*tt_req_node), GFP_ATOMIC); |
| 950 | if (!tt_req_node) |
| 951 | goto unlock; |
| 952 | |
| 953 | memcpy(tt_req_node->addr, orig_node->orig, ETH_ALEN); |
| 954 | tt_req_node->issued_at = jiffies; |
| 955 | |
| 956 | list_add(&tt_req_node->list, &bat_priv->tt_req_list); |
| 957 | unlock: |
| 958 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 959 | return tt_req_node; |
| 960 | } |
| 961 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 962 | /* data_ptr is useless here, but has to be kept to respect the prototype */ |
| 963 | static int tt_local_valid_entry(const void *entry_ptr, const void *data_ptr) |
| 964 | { |
| 965 | const struct tt_local_entry *tt_local_entry = entry_ptr; |
| 966 | |
| 967 | if (tt_local_entry->flags & TT_CLIENT_NEW) |
| 968 | return 0; |
| 969 | return 1; |
| 970 | } |
| 971 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 972 | static int tt_global_valid_entry(const void *entry_ptr, const void *data_ptr) |
| 973 | { |
| 974 | const struct tt_global_entry *tt_global_entry = entry_ptr; |
| 975 | const struct orig_node *orig_node = data_ptr; |
| 976 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 977 | if (tt_global_entry->flags & TT_CLIENT_ROAM) |
| 978 | return 0; |
| 979 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 980 | return (tt_global_entry->orig_node == orig_node); |
| 981 | } |
| 982 | |
| 983 | static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn, |
| 984 | struct hashtable_t *hash, |
| 985 | struct hard_iface *primary_if, |
| 986 | int (*valid_cb)(const void *, |
| 987 | const void *), |
| 988 | void *cb_data) |
| 989 | { |
| 990 | struct tt_local_entry *tt_local_entry; |
| 991 | struct tt_query_packet *tt_response; |
| 992 | struct tt_change *tt_change; |
| 993 | struct hlist_node *node; |
| 994 | struct hlist_head *head; |
| 995 | struct sk_buff *skb = NULL; |
| 996 | uint16_t tt_tot, tt_count; |
| 997 | ssize_t tt_query_size = sizeof(struct tt_query_packet); |
| 998 | int i; |
| 999 | |
| 1000 | if (tt_query_size + tt_len > primary_if->soft_iface->mtu) { |
| 1001 | tt_len = primary_if->soft_iface->mtu - tt_query_size; |
| 1002 | tt_len -= tt_len % sizeof(struct tt_change); |
| 1003 | } |
| 1004 | tt_tot = tt_len / sizeof(struct tt_change); |
| 1005 | |
| 1006 | skb = dev_alloc_skb(tt_query_size + tt_len + ETH_HLEN); |
| 1007 | if (!skb) |
| 1008 | goto out; |
| 1009 | |
| 1010 | skb_reserve(skb, ETH_HLEN); |
| 1011 | tt_response = (struct tt_query_packet *)skb_put(skb, |
| 1012 | tt_query_size + tt_len); |
| 1013 | tt_response->ttvn = ttvn; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1014 | |
| 1015 | tt_change = (struct tt_change *)(skb->data + tt_query_size); |
| 1016 | tt_count = 0; |
| 1017 | |
| 1018 | rcu_read_lock(); |
| 1019 | for (i = 0; i < hash->size; i++) { |
| 1020 | head = &hash->table[i]; |
| 1021 | |
| 1022 | hlist_for_each_entry_rcu(tt_local_entry, node, |
| 1023 | head, hash_entry) { |
| 1024 | if (tt_count == tt_tot) |
| 1025 | break; |
| 1026 | |
| 1027 | if ((valid_cb) && (!valid_cb(tt_local_entry, cb_data))) |
| 1028 | continue; |
| 1029 | |
| 1030 | memcpy(tt_change->addr, tt_local_entry->addr, ETH_ALEN); |
| 1031 | tt_change->flags = NO_FLAGS; |
| 1032 | |
| 1033 | tt_count++; |
| 1034 | tt_change++; |
| 1035 | } |
| 1036 | } |
| 1037 | rcu_read_unlock(); |
| 1038 | |
Antonio Quartulli | 9d85239 | 2011-10-17 14:25:13 +0200 | [diff] [blame] | 1039 | /* store in the message the number of entries we have successfully |
| 1040 | * copied */ |
| 1041 | tt_response->tt_data = htons(tt_count); |
| 1042 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1043 | out: |
| 1044 | return skb; |
| 1045 | } |
| 1046 | |
| 1047 | int send_tt_request(struct bat_priv *bat_priv, struct orig_node *dst_orig_node, |
| 1048 | uint8_t ttvn, uint16_t tt_crc, bool full_table) |
| 1049 | { |
| 1050 | struct sk_buff *skb = NULL; |
| 1051 | struct tt_query_packet *tt_request; |
| 1052 | struct neigh_node *neigh_node = NULL; |
| 1053 | struct hard_iface *primary_if; |
| 1054 | struct tt_req_node *tt_req_node = NULL; |
| 1055 | int ret = 1; |
| 1056 | |
| 1057 | primary_if = primary_if_get_selected(bat_priv); |
| 1058 | if (!primary_if) |
| 1059 | goto out; |
| 1060 | |
| 1061 | /* The new tt_req will be issued only if I'm not waiting for a |
| 1062 | * reply from the same orig_node yet */ |
| 1063 | tt_req_node = new_tt_req_node(bat_priv, dst_orig_node); |
| 1064 | if (!tt_req_node) |
| 1065 | goto out; |
| 1066 | |
| 1067 | skb = dev_alloc_skb(sizeof(struct tt_query_packet) + ETH_HLEN); |
| 1068 | if (!skb) |
| 1069 | goto out; |
| 1070 | |
| 1071 | skb_reserve(skb, ETH_HLEN); |
| 1072 | |
| 1073 | tt_request = (struct tt_query_packet *)skb_put(skb, |
| 1074 | sizeof(struct tt_query_packet)); |
| 1075 | |
| 1076 | tt_request->packet_type = BAT_TT_QUERY; |
| 1077 | tt_request->version = COMPAT_VERSION; |
| 1078 | memcpy(tt_request->src, primary_if->net_dev->dev_addr, ETH_ALEN); |
| 1079 | memcpy(tt_request->dst, dst_orig_node->orig, ETH_ALEN); |
| 1080 | tt_request->ttl = TTL; |
| 1081 | tt_request->ttvn = ttvn; |
| 1082 | tt_request->tt_data = tt_crc; |
| 1083 | tt_request->flags = TT_REQUEST; |
| 1084 | |
| 1085 | if (full_table) |
| 1086 | tt_request->flags |= TT_FULL_TABLE; |
| 1087 | |
| 1088 | neigh_node = orig_node_get_router(dst_orig_node); |
| 1089 | if (!neigh_node) |
| 1090 | goto out; |
| 1091 | |
| 1092 | bat_dbg(DBG_TT, bat_priv, "Sending TT_REQUEST to %pM via %pM " |
| 1093 | "[%c]\n", dst_orig_node->orig, neigh_node->addr, |
| 1094 | (full_table ? 'F' : '.')); |
| 1095 | |
| 1096 | send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
| 1097 | ret = 0; |
| 1098 | |
| 1099 | out: |
| 1100 | if (neigh_node) |
| 1101 | neigh_node_free_ref(neigh_node); |
| 1102 | if (primary_if) |
| 1103 | hardif_free_ref(primary_if); |
| 1104 | if (ret) |
| 1105 | kfree_skb(skb); |
| 1106 | if (ret && tt_req_node) { |
| 1107 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 1108 | list_del(&tt_req_node->list); |
| 1109 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 1110 | kfree(tt_req_node); |
| 1111 | } |
| 1112 | return ret; |
| 1113 | } |
| 1114 | |
| 1115 | static bool send_other_tt_response(struct bat_priv *bat_priv, |
| 1116 | struct tt_query_packet *tt_request) |
| 1117 | { |
| 1118 | struct orig_node *req_dst_orig_node = NULL, *res_dst_orig_node = NULL; |
| 1119 | struct neigh_node *neigh_node = NULL; |
| 1120 | struct hard_iface *primary_if = NULL; |
| 1121 | uint8_t orig_ttvn, req_ttvn, ttvn; |
| 1122 | int ret = false; |
| 1123 | unsigned char *tt_buff; |
| 1124 | bool full_table; |
| 1125 | uint16_t tt_len, tt_tot; |
| 1126 | struct sk_buff *skb = NULL; |
| 1127 | struct tt_query_packet *tt_response; |
| 1128 | |
| 1129 | bat_dbg(DBG_TT, bat_priv, |
| 1130 | "Received TT_REQUEST from %pM for " |
| 1131 | "ttvn: %u (%pM) [%c]\n", tt_request->src, |
| 1132 | tt_request->ttvn, tt_request->dst, |
| 1133 | (tt_request->flags & TT_FULL_TABLE ? 'F' : '.')); |
| 1134 | |
| 1135 | /* Let's get the orig node of the REAL destination */ |
| 1136 | req_dst_orig_node = get_orig_node(bat_priv, tt_request->dst); |
| 1137 | if (!req_dst_orig_node) |
| 1138 | goto out; |
| 1139 | |
| 1140 | res_dst_orig_node = get_orig_node(bat_priv, tt_request->src); |
| 1141 | if (!res_dst_orig_node) |
| 1142 | goto out; |
| 1143 | |
| 1144 | neigh_node = orig_node_get_router(res_dst_orig_node); |
| 1145 | if (!neigh_node) |
| 1146 | goto out; |
| 1147 | |
| 1148 | primary_if = primary_if_get_selected(bat_priv); |
| 1149 | if (!primary_if) |
| 1150 | goto out; |
| 1151 | |
| 1152 | orig_ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn); |
| 1153 | req_ttvn = tt_request->ttvn; |
| 1154 | |
| 1155 | /* I have not the requested data */ |
| 1156 | if (orig_ttvn != req_ttvn || |
| 1157 | tt_request->tt_data != req_dst_orig_node->tt_crc) |
| 1158 | goto out; |
| 1159 | |
| 1160 | /* If it has explicitly been requested the full table */ |
| 1161 | if (tt_request->flags & TT_FULL_TABLE || |
| 1162 | !req_dst_orig_node->tt_buff) |
| 1163 | full_table = true; |
| 1164 | else |
| 1165 | full_table = false; |
| 1166 | |
| 1167 | /* In this version, fragmentation is not implemented, then |
| 1168 | * I'll send only one packet with as much TT entries as I can */ |
| 1169 | if (!full_table) { |
| 1170 | spin_lock_bh(&req_dst_orig_node->tt_buff_lock); |
| 1171 | tt_len = req_dst_orig_node->tt_buff_len; |
| 1172 | tt_tot = tt_len / sizeof(struct tt_change); |
| 1173 | |
| 1174 | skb = dev_alloc_skb(sizeof(struct tt_query_packet) + |
| 1175 | tt_len + ETH_HLEN); |
| 1176 | if (!skb) |
| 1177 | goto unlock; |
| 1178 | |
| 1179 | skb_reserve(skb, ETH_HLEN); |
| 1180 | tt_response = (struct tt_query_packet *)skb_put(skb, |
| 1181 | sizeof(struct tt_query_packet) + tt_len); |
| 1182 | tt_response->ttvn = req_ttvn; |
| 1183 | tt_response->tt_data = htons(tt_tot); |
| 1184 | |
| 1185 | tt_buff = skb->data + sizeof(struct tt_query_packet); |
| 1186 | /* Copy the last orig_node's OGM buffer */ |
| 1187 | memcpy(tt_buff, req_dst_orig_node->tt_buff, |
| 1188 | req_dst_orig_node->tt_buff_len); |
| 1189 | |
| 1190 | spin_unlock_bh(&req_dst_orig_node->tt_buff_lock); |
| 1191 | } else { |
| 1192 | tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size) * |
| 1193 | sizeof(struct tt_change); |
| 1194 | ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn); |
| 1195 | |
| 1196 | skb = tt_response_fill_table(tt_len, ttvn, |
| 1197 | bat_priv->tt_global_hash, |
| 1198 | primary_if, tt_global_valid_entry, |
| 1199 | req_dst_orig_node); |
| 1200 | if (!skb) |
| 1201 | goto out; |
| 1202 | |
| 1203 | tt_response = (struct tt_query_packet *)skb->data; |
| 1204 | } |
| 1205 | |
| 1206 | tt_response->packet_type = BAT_TT_QUERY; |
| 1207 | tt_response->version = COMPAT_VERSION; |
| 1208 | tt_response->ttl = TTL; |
| 1209 | memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN); |
| 1210 | memcpy(tt_response->dst, tt_request->src, ETH_ALEN); |
| 1211 | tt_response->flags = TT_RESPONSE; |
| 1212 | |
| 1213 | if (full_table) |
| 1214 | tt_response->flags |= TT_FULL_TABLE; |
| 1215 | |
| 1216 | bat_dbg(DBG_TT, bat_priv, |
| 1217 | "Sending TT_RESPONSE %pM via %pM for %pM (ttvn: %u)\n", |
| 1218 | res_dst_orig_node->orig, neigh_node->addr, |
| 1219 | req_dst_orig_node->orig, req_ttvn); |
| 1220 | |
| 1221 | send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
| 1222 | ret = true; |
| 1223 | goto out; |
| 1224 | |
| 1225 | unlock: |
| 1226 | spin_unlock_bh(&req_dst_orig_node->tt_buff_lock); |
| 1227 | |
| 1228 | out: |
| 1229 | if (res_dst_orig_node) |
| 1230 | orig_node_free_ref(res_dst_orig_node); |
| 1231 | if (req_dst_orig_node) |
| 1232 | orig_node_free_ref(req_dst_orig_node); |
| 1233 | if (neigh_node) |
| 1234 | neigh_node_free_ref(neigh_node); |
| 1235 | if (primary_if) |
| 1236 | hardif_free_ref(primary_if); |
| 1237 | if (!ret) |
| 1238 | kfree_skb(skb); |
| 1239 | return ret; |
| 1240 | |
| 1241 | } |
| 1242 | static bool send_my_tt_response(struct bat_priv *bat_priv, |
| 1243 | struct tt_query_packet *tt_request) |
| 1244 | { |
| 1245 | struct orig_node *orig_node = NULL; |
| 1246 | struct neigh_node *neigh_node = NULL; |
| 1247 | struct hard_iface *primary_if = NULL; |
| 1248 | uint8_t my_ttvn, req_ttvn, ttvn; |
| 1249 | int ret = false; |
| 1250 | unsigned char *tt_buff; |
| 1251 | bool full_table; |
| 1252 | uint16_t tt_len, tt_tot; |
| 1253 | struct sk_buff *skb = NULL; |
| 1254 | struct tt_query_packet *tt_response; |
| 1255 | |
| 1256 | bat_dbg(DBG_TT, bat_priv, |
| 1257 | "Received TT_REQUEST from %pM for " |
| 1258 | "ttvn: %u (me) [%c]\n", tt_request->src, |
| 1259 | tt_request->ttvn, |
| 1260 | (tt_request->flags & TT_FULL_TABLE ? 'F' : '.')); |
| 1261 | |
| 1262 | |
| 1263 | my_ttvn = (uint8_t)atomic_read(&bat_priv->ttvn); |
| 1264 | req_ttvn = tt_request->ttvn; |
| 1265 | |
| 1266 | orig_node = get_orig_node(bat_priv, tt_request->src); |
| 1267 | if (!orig_node) |
| 1268 | goto out; |
| 1269 | |
| 1270 | neigh_node = orig_node_get_router(orig_node); |
| 1271 | if (!neigh_node) |
| 1272 | goto out; |
| 1273 | |
| 1274 | primary_if = primary_if_get_selected(bat_priv); |
| 1275 | if (!primary_if) |
| 1276 | goto out; |
| 1277 | |
| 1278 | /* If the full table has been explicitly requested or the gap |
| 1279 | * is too big send the whole local translation table */ |
| 1280 | if (tt_request->flags & TT_FULL_TABLE || my_ttvn != req_ttvn || |
| 1281 | !bat_priv->tt_buff) |
| 1282 | full_table = true; |
| 1283 | else |
| 1284 | full_table = false; |
| 1285 | |
| 1286 | /* In this version, fragmentation is not implemented, then |
| 1287 | * I'll send only one packet with as much TT entries as I can */ |
| 1288 | if (!full_table) { |
| 1289 | spin_lock_bh(&bat_priv->tt_buff_lock); |
| 1290 | tt_len = bat_priv->tt_buff_len; |
| 1291 | tt_tot = tt_len / sizeof(struct tt_change); |
| 1292 | |
| 1293 | skb = dev_alloc_skb(sizeof(struct tt_query_packet) + |
| 1294 | tt_len + ETH_HLEN); |
| 1295 | if (!skb) |
| 1296 | goto unlock; |
| 1297 | |
| 1298 | skb_reserve(skb, ETH_HLEN); |
| 1299 | tt_response = (struct tt_query_packet *)skb_put(skb, |
| 1300 | sizeof(struct tt_query_packet) + tt_len); |
| 1301 | tt_response->ttvn = req_ttvn; |
| 1302 | tt_response->tt_data = htons(tt_tot); |
| 1303 | |
| 1304 | tt_buff = skb->data + sizeof(struct tt_query_packet); |
| 1305 | memcpy(tt_buff, bat_priv->tt_buff, |
| 1306 | bat_priv->tt_buff_len); |
| 1307 | spin_unlock_bh(&bat_priv->tt_buff_lock); |
| 1308 | } else { |
| 1309 | tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) * |
| 1310 | sizeof(struct tt_change); |
| 1311 | ttvn = (uint8_t)atomic_read(&bat_priv->ttvn); |
| 1312 | |
| 1313 | skb = tt_response_fill_table(tt_len, ttvn, |
| 1314 | bat_priv->tt_local_hash, |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1315 | primary_if, tt_local_valid_entry, |
| 1316 | NULL); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1317 | if (!skb) |
| 1318 | goto out; |
| 1319 | |
| 1320 | tt_response = (struct tt_query_packet *)skb->data; |
| 1321 | } |
| 1322 | |
| 1323 | tt_response->packet_type = BAT_TT_QUERY; |
| 1324 | tt_response->version = COMPAT_VERSION; |
| 1325 | tt_response->ttl = TTL; |
| 1326 | memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN); |
| 1327 | memcpy(tt_response->dst, tt_request->src, ETH_ALEN); |
| 1328 | tt_response->flags = TT_RESPONSE; |
| 1329 | |
| 1330 | if (full_table) |
| 1331 | tt_response->flags |= TT_FULL_TABLE; |
| 1332 | |
| 1333 | bat_dbg(DBG_TT, bat_priv, |
| 1334 | "Sending TT_RESPONSE to %pM via %pM [%c]\n", |
| 1335 | orig_node->orig, neigh_node->addr, |
| 1336 | (tt_response->flags & TT_FULL_TABLE ? 'F' : '.')); |
| 1337 | |
| 1338 | send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
| 1339 | ret = true; |
| 1340 | goto out; |
| 1341 | |
| 1342 | unlock: |
| 1343 | spin_unlock_bh(&bat_priv->tt_buff_lock); |
| 1344 | out: |
| 1345 | if (orig_node) |
| 1346 | orig_node_free_ref(orig_node); |
| 1347 | if (neigh_node) |
| 1348 | neigh_node_free_ref(neigh_node); |
| 1349 | if (primary_if) |
| 1350 | hardif_free_ref(primary_if); |
| 1351 | if (!ret) |
| 1352 | kfree_skb(skb); |
| 1353 | /* This packet was for me, so it doesn't need to be re-routed */ |
| 1354 | return true; |
| 1355 | } |
| 1356 | |
| 1357 | bool send_tt_response(struct bat_priv *bat_priv, |
| 1358 | struct tt_query_packet *tt_request) |
| 1359 | { |
| 1360 | if (is_my_mac(tt_request->dst)) |
| 1361 | return send_my_tt_response(bat_priv, tt_request); |
| 1362 | else |
| 1363 | return send_other_tt_response(bat_priv, tt_request); |
| 1364 | } |
| 1365 | |
| 1366 | static void _tt_update_changes(struct bat_priv *bat_priv, |
| 1367 | struct orig_node *orig_node, |
| 1368 | struct tt_change *tt_change, |
| 1369 | uint16_t tt_num_changes, uint8_t ttvn) |
| 1370 | { |
| 1371 | int i; |
| 1372 | |
| 1373 | for (i = 0; i < tt_num_changes; i++) { |
Antonio Quartulli | 5fbc159 | 2011-06-17 16:11:27 +0200 | [diff] [blame] | 1374 | if ((tt_change + i)->flags & TT_CLIENT_DEL) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1375 | tt_global_del(bat_priv, orig_node, |
| 1376 | (tt_change + i)->addr, |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1377 | "tt removed by changes", |
| 1378 | (tt_change + i)->flags & TT_CLIENT_ROAM); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1379 | else |
| 1380 | if (!tt_global_add(bat_priv, orig_node, |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1381 | (tt_change + i)->addr, ttvn, false)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1382 | /* In case of problem while storing a |
| 1383 | * global_entry, we stop the updating |
| 1384 | * procedure without committing the |
| 1385 | * ttvn change. This will avoid to send |
| 1386 | * corrupted data on tt_request |
| 1387 | */ |
| 1388 | return; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | static void tt_fill_gtable(struct bat_priv *bat_priv, |
| 1393 | struct tt_query_packet *tt_response) |
| 1394 | { |
| 1395 | struct orig_node *orig_node = NULL; |
| 1396 | |
| 1397 | orig_node = orig_hash_find(bat_priv, tt_response->src); |
| 1398 | if (!orig_node) |
| 1399 | goto out; |
| 1400 | |
| 1401 | /* Purge the old table first.. */ |
| 1402 | tt_global_del_orig(bat_priv, orig_node, "Received full table"); |
| 1403 | |
| 1404 | _tt_update_changes(bat_priv, orig_node, |
| 1405 | (struct tt_change *)(tt_response + 1), |
| 1406 | tt_response->tt_data, tt_response->ttvn); |
| 1407 | |
| 1408 | spin_lock_bh(&orig_node->tt_buff_lock); |
| 1409 | kfree(orig_node->tt_buff); |
| 1410 | orig_node->tt_buff_len = 0; |
| 1411 | orig_node->tt_buff = NULL; |
| 1412 | spin_unlock_bh(&orig_node->tt_buff_lock); |
| 1413 | |
| 1414 | atomic_set(&orig_node->last_ttvn, tt_response->ttvn); |
| 1415 | |
| 1416 | out: |
| 1417 | if (orig_node) |
| 1418 | orig_node_free_ref(orig_node); |
| 1419 | } |
| 1420 | |
| 1421 | void tt_update_changes(struct bat_priv *bat_priv, struct orig_node *orig_node, |
| 1422 | uint16_t tt_num_changes, uint8_t ttvn, |
| 1423 | struct tt_change *tt_change) |
| 1424 | { |
| 1425 | _tt_update_changes(bat_priv, orig_node, tt_change, tt_num_changes, |
| 1426 | ttvn); |
| 1427 | |
| 1428 | tt_save_orig_buffer(bat_priv, orig_node, (unsigned char *)tt_change, |
| 1429 | tt_num_changes); |
| 1430 | atomic_set(&orig_node->last_ttvn, ttvn); |
| 1431 | } |
| 1432 | |
| 1433 | bool is_my_client(struct bat_priv *bat_priv, const uint8_t *addr) |
| 1434 | { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1435 | struct tt_local_entry *tt_local_entry = NULL; |
| 1436 | bool ret = false; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1437 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1438 | tt_local_entry = tt_local_hash_find(bat_priv, addr); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1439 | if (!tt_local_entry) |
| 1440 | goto out; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1441 | /* Check if the client has been logically deleted (but is kept for |
| 1442 | * consistency purpose) */ |
| 1443 | if (tt_local_entry->flags & TT_CLIENT_PENDING) |
| 1444 | goto out; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1445 | ret = true; |
| 1446 | out: |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1447 | if (tt_local_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1448 | tt_local_entry_free_ref(tt_local_entry); |
| 1449 | return ret; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | void handle_tt_response(struct bat_priv *bat_priv, |
| 1453 | struct tt_query_packet *tt_response) |
| 1454 | { |
| 1455 | struct tt_req_node *node, *safe; |
| 1456 | struct orig_node *orig_node = NULL; |
| 1457 | |
| 1458 | bat_dbg(DBG_TT, bat_priv, "Received TT_RESPONSE from %pM for " |
| 1459 | "ttvn %d t_size: %d [%c]\n", |
| 1460 | tt_response->src, tt_response->ttvn, |
| 1461 | tt_response->tt_data, |
| 1462 | (tt_response->flags & TT_FULL_TABLE ? 'F' : '.')); |
| 1463 | |
| 1464 | orig_node = orig_hash_find(bat_priv, tt_response->src); |
| 1465 | if (!orig_node) |
| 1466 | goto out; |
| 1467 | |
| 1468 | if (tt_response->flags & TT_FULL_TABLE) |
| 1469 | tt_fill_gtable(bat_priv, tt_response); |
| 1470 | else |
| 1471 | tt_update_changes(bat_priv, orig_node, tt_response->tt_data, |
| 1472 | tt_response->ttvn, |
| 1473 | (struct tt_change *)(tt_response + 1)); |
| 1474 | |
| 1475 | /* Delete the tt_req_node from pending tt_requests list */ |
| 1476 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 1477 | list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { |
| 1478 | if (!compare_eth(node->addr, tt_response->src)) |
| 1479 | continue; |
| 1480 | list_del(&node->list); |
| 1481 | kfree(node); |
| 1482 | } |
| 1483 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 1484 | |
| 1485 | /* Recalculate the CRC for this orig_node and store it */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1486 | orig_node->tt_crc = tt_global_crc(bat_priv, orig_node); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1487 | /* Roaming phase is over: tables are in sync again. I can |
| 1488 | * unset the flag */ |
| 1489 | orig_node->tt_poss_change = false; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1490 | out: |
| 1491 | if (orig_node) |
| 1492 | orig_node_free_ref(orig_node); |
| 1493 | } |
| 1494 | |
| 1495 | int tt_init(struct bat_priv *bat_priv) |
| 1496 | { |
| 1497 | if (!tt_local_init(bat_priv)) |
| 1498 | return 0; |
| 1499 | |
| 1500 | if (!tt_global_init(bat_priv)) |
| 1501 | return 0; |
| 1502 | |
| 1503 | tt_start_timer(bat_priv); |
| 1504 | |
| 1505 | return 1; |
| 1506 | } |
| 1507 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1508 | static void tt_roam_list_free(struct bat_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1509 | { |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1510 | struct tt_roam_node *node, *safe; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1511 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1512 | spin_lock_bh(&bat_priv->tt_roam_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1513 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1514 | list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { |
| 1515 | list_del(&node->list); |
| 1516 | kfree(node); |
| 1517 | } |
| 1518 | |
| 1519 | spin_unlock_bh(&bat_priv->tt_roam_list_lock); |
| 1520 | } |
| 1521 | |
| 1522 | static void tt_roam_purge(struct bat_priv *bat_priv) |
| 1523 | { |
| 1524 | struct tt_roam_node *node, *safe; |
| 1525 | |
| 1526 | spin_lock_bh(&bat_priv->tt_roam_list_lock); |
| 1527 | list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { |
| 1528 | if (!is_out_of_time(node->first_time, |
| 1529 | ROAMING_MAX_TIME * 1000)) |
| 1530 | continue; |
| 1531 | |
| 1532 | list_del(&node->list); |
| 1533 | kfree(node); |
| 1534 | } |
| 1535 | spin_unlock_bh(&bat_priv->tt_roam_list_lock); |
| 1536 | } |
| 1537 | |
| 1538 | /* This function checks whether the client already reached the |
| 1539 | * maximum number of possible roaming phases. In this case the ROAMING_ADV |
| 1540 | * will not be sent. |
| 1541 | * |
| 1542 | * returns true if the ROAMING_ADV can be sent, false otherwise */ |
| 1543 | static bool tt_check_roam_count(struct bat_priv *bat_priv, |
| 1544 | uint8_t *client) |
| 1545 | { |
| 1546 | struct tt_roam_node *tt_roam_node; |
| 1547 | bool ret = false; |
| 1548 | |
| 1549 | spin_lock_bh(&bat_priv->tt_roam_list_lock); |
| 1550 | /* The new tt_req will be issued only if I'm not waiting for a |
| 1551 | * reply from the same orig_node yet */ |
| 1552 | list_for_each_entry(tt_roam_node, &bat_priv->tt_roam_list, list) { |
| 1553 | if (!compare_eth(tt_roam_node->addr, client)) |
| 1554 | continue; |
| 1555 | |
| 1556 | if (is_out_of_time(tt_roam_node->first_time, |
| 1557 | ROAMING_MAX_TIME * 1000)) |
| 1558 | continue; |
| 1559 | |
| 1560 | if (!atomic_dec_not_zero(&tt_roam_node->counter)) |
| 1561 | /* Sorry, you roamed too many times! */ |
| 1562 | goto unlock; |
| 1563 | ret = true; |
| 1564 | break; |
| 1565 | } |
| 1566 | |
| 1567 | if (!ret) { |
| 1568 | tt_roam_node = kmalloc(sizeof(*tt_roam_node), GFP_ATOMIC); |
| 1569 | if (!tt_roam_node) |
| 1570 | goto unlock; |
| 1571 | |
| 1572 | tt_roam_node->first_time = jiffies; |
| 1573 | atomic_set(&tt_roam_node->counter, ROAMING_MAX_COUNT - 1); |
| 1574 | memcpy(tt_roam_node->addr, client, ETH_ALEN); |
| 1575 | |
| 1576 | list_add(&tt_roam_node->list, &bat_priv->tt_roam_list); |
| 1577 | ret = true; |
| 1578 | } |
| 1579 | |
| 1580 | unlock: |
| 1581 | spin_unlock_bh(&bat_priv->tt_roam_list_lock); |
| 1582 | return ret; |
| 1583 | } |
| 1584 | |
| 1585 | void send_roam_adv(struct bat_priv *bat_priv, uint8_t *client, |
| 1586 | struct orig_node *orig_node) |
| 1587 | { |
| 1588 | struct neigh_node *neigh_node = NULL; |
| 1589 | struct sk_buff *skb = NULL; |
| 1590 | struct roam_adv_packet *roam_adv_packet; |
| 1591 | int ret = 1; |
| 1592 | struct hard_iface *primary_if; |
| 1593 | |
| 1594 | /* before going on we have to check whether the client has |
| 1595 | * already roamed to us too many times */ |
| 1596 | if (!tt_check_roam_count(bat_priv, client)) |
| 1597 | goto out; |
| 1598 | |
| 1599 | skb = dev_alloc_skb(sizeof(struct roam_adv_packet) + ETH_HLEN); |
| 1600 | if (!skb) |
| 1601 | goto out; |
| 1602 | |
| 1603 | skb_reserve(skb, ETH_HLEN); |
| 1604 | |
| 1605 | roam_adv_packet = (struct roam_adv_packet *)skb_put(skb, |
| 1606 | sizeof(struct roam_adv_packet)); |
| 1607 | |
| 1608 | roam_adv_packet->packet_type = BAT_ROAM_ADV; |
| 1609 | roam_adv_packet->version = COMPAT_VERSION; |
| 1610 | roam_adv_packet->ttl = TTL; |
| 1611 | primary_if = primary_if_get_selected(bat_priv); |
| 1612 | if (!primary_if) |
| 1613 | goto out; |
| 1614 | memcpy(roam_adv_packet->src, primary_if->net_dev->dev_addr, ETH_ALEN); |
| 1615 | hardif_free_ref(primary_if); |
| 1616 | memcpy(roam_adv_packet->dst, orig_node->orig, ETH_ALEN); |
| 1617 | memcpy(roam_adv_packet->client, client, ETH_ALEN); |
| 1618 | |
| 1619 | neigh_node = orig_node_get_router(orig_node); |
| 1620 | if (!neigh_node) |
| 1621 | goto out; |
| 1622 | |
| 1623 | bat_dbg(DBG_TT, bat_priv, |
| 1624 | "Sending ROAMING_ADV to %pM (client %pM) via %pM\n", |
| 1625 | orig_node->orig, client, neigh_node->addr); |
| 1626 | |
| 1627 | send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
| 1628 | ret = 0; |
| 1629 | |
| 1630 | out: |
| 1631 | if (neigh_node) |
| 1632 | neigh_node_free_ref(neigh_node); |
| 1633 | if (ret) |
| 1634 | kfree_skb(skb); |
| 1635 | return; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static void tt_purge(struct work_struct *work) |
| 1639 | { |
| 1640 | struct delayed_work *delayed_work = |
| 1641 | container_of(work, struct delayed_work, work); |
| 1642 | struct bat_priv *bat_priv = |
| 1643 | container_of(delayed_work, struct bat_priv, tt_work); |
| 1644 | |
| 1645 | tt_local_purge(bat_priv); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1646 | tt_global_roam_purge(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1647 | tt_req_purge(bat_priv); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1648 | tt_roam_purge(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1649 | |
| 1650 | tt_start_timer(bat_priv); |
| 1651 | } |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1652 | |
| 1653 | void tt_free(struct bat_priv *bat_priv) |
| 1654 | { |
| 1655 | cancel_delayed_work_sync(&bat_priv->tt_work); |
| 1656 | |
| 1657 | tt_local_table_free(bat_priv); |
| 1658 | tt_global_table_free(bat_priv); |
| 1659 | tt_req_list_free(bat_priv); |
| 1660 | tt_changes_list_free(bat_priv); |
| 1661 | tt_roam_list_free(bat_priv); |
| 1662 | |
| 1663 | kfree(bat_priv->tt_buff); |
| 1664 | } |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1665 | |
| 1666 | /* This function will reset the specified flags from all the entries in |
| 1667 | * the given hash table and will increment num_local_tt for each involved |
| 1668 | * entry */ |
| 1669 | static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags) |
| 1670 | { |
| 1671 | int i; |
| 1672 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 1673 | struct hlist_head *head; |
| 1674 | struct hlist_node *node; |
| 1675 | struct tt_local_entry *tt_local_entry; |
| 1676 | |
| 1677 | if (!hash) |
| 1678 | return; |
| 1679 | |
| 1680 | for (i = 0; i < hash->size; i++) { |
| 1681 | head = &hash->table[i]; |
| 1682 | |
| 1683 | rcu_read_lock(); |
| 1684 | hlist_for_each_entry_rcu(tt_local_entry, node, |
| 1685 | head, hash_entry) { |
Antonio Quartulli | 3190126 | 2011-10-16 18:53:37 +0200 | [diff] [blame] | 1686 | if (!(tt_local_entry->flags & flags)) |
| 1687 | continue; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1688 | tt_local_entry->flags &= ~flags; |
| 1689 | atomic_inc(&bat_priv->num_local_tt); |
| 1690 | } |
| 1691 | rcu_read_unlock(); |
| 1692 | } |
| 1693 | |
| 1694 | } |
| 1695 | |
| 1696 | /* Purge out all the tt local entries marked with TT_CLIENT_PENDING */ |
| 1697 | static void tt_local_purge_pending_clients(struct bat_priv *bat_priv) |
| 1698 | { |
| 1699 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 1700 | struct tt_local_entry *tt_local_entry; |
| 1701 | struct hlist_node *node, *node_tmp; |
| 1702 | struct hlist_head *head; |
| 1703 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
| 1704 | int i; |
| 1705 | |
| 1706 | if (!hash) |
| 1707 | return; |
| 1708 | |
| 1709 | for (i = 0; i < hash->size; i++) { |
| 1710 | head = &hash->table[i]; |
| 1711 | list_lock = &hash->list_locks[i]; |
| 1712 | |
| 1713 | spin_lock_bh(list_lock); |
| 1714 | hlist_for_each_entry_safe(tt_local_entry, node, node_tmp, |
| 1715 | head, hash_entry) { |
| 1716 | if (!(tt_local_entry->flags & TT_CLIENT_PENDING)) |
| 1717 | continue; |
| 1718 | |
| 1719 | bat_dbg(DBG_TT, bat_priv, "Deleting local tt entry " |
| 1720 | "(%pM): pending\n", tt_local_entry->addr); |
| 1721 | |
| 1722 | atomic_dec(&bat_priv->num_local_tt); |
| 1723 | hlist_del_rcu(node); |
| 1724 | tt_local_entry_free_ref(tt_local_entry); |
| 1725 | } |
| 1726 | spin_unlock_bh(list_lock); |
| 1727 | } |
| 1728 | |
| 1729 | } |
| 1730 | |
| 1731 | void tt_commit_changes(struct bat_priv *bat_priv) |
| 1732 | { |
| 1733 | tt_local_reset_flags(bat_priv, TT_CLIENT_NEW); |
| 1734 | tt_local_purge_pending_clients(bat_priv); |
| 1735 | |
| 1736 | /* Increment the TTVN only once per OGM interval */ |
| 1737 | atomic_inc(&bat_priv->ttvn); |
| 1738 | bat_priv->tt_poss_change = false; |
| 1739 | } |