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