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