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