Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1 | /* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 2 | * |
Antonio Quartulli | 35c133a | 2012-03-14 13:03:01 +0100 | [diff] [blame] | 3 | * Marek Lindner, Simon Wunderlich, Antonio Quartulli |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of version 2 of the GNU General Public |
| 7 | * License as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 | * 02110-1301, USA |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "main.h" |
| 21 | #include "translation-table.h" |
| 22 | #include "soft-interface.h" |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 23 | #include "hard-interface.h" |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 24 | #include "send.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 25 | #include "hash.h" |
| 26 | #include "originator.h" |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 27 | #include "routing.h" |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 28 | #include "bridge_loop_avoidance.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 29 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 30 | #include <linux/crc16.h> |
| 31 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 32 | static void batadv_send_roam_adv(struct bat_priv *bat_priv, uint8_t *client, |
| 33 | struct orig_node *orig_node); |
| 34 | static void batadv_tt_purge(struct work_struct *work); |
| 35 | static void |
| 36 | batadv_tt_global_del_orig_list(struct tt_global_entry *tt_global_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 37 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 38 | /* returns 1 if they are the same mac addr */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 39 | static int batadv_compare_tt(const struct hlist_node *node, const void *data2) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 40 | { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 41 | const void *data1 = container_of(node, struct tt_common_entry, |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 42 | hash_entry); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 43 | |
| 44 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
| 45 | } |
| 46 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 47 | static void batadv_tt_start_timer(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 48 | { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 49 | INIT_DELAYED_WORK(&bat_priv->tt_work, batadv_tt_purge); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 50 | queue_delayed_work(batadv_event_workqueue, &bat_priv->tt_work, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 51 | msecs_to_jiffies(5000)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 54 | static struct tt_common_entry *batadv_tt_hash_find(struct hashtable_t *hash, |
| 55 | const void *data) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 56 | { |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 57 | struct hlist_head *head; |
| 58 | struct hlist_node *node; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 59 | struct tt_common_entry *tt_common_entry, *tt_common_entry_tmp = NULL; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 60 | uint32_t index; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 61 | |
| 62 | if (!hash) |
| 63 | return NULL; |
| 64 | |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 65 | index = batadv_choose_orig(data, hash->size); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 66 | head = &hash->table[index]; |
| 67 | |
| 68 | rcu_read_lock(); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 69 | hlist_for_each_entry_rcu(tt_common_entry, node, head, hash_entry) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 70 | if (!batadv_compare_eth(tt_common_entry, data)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 71 | continue; |
| 72 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 73 | if (!atomic_inc_not_zero(&tt_common_entry->refcount)) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 74 | continue; |
| 75 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 76 | tt_common_entry_tmp = tt_common_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 77 | break; |
| 78 | } |
| 79 | rcu_read_unlock(); |
| 80 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 81 | return tt_common_entry_tmp; |
| 82 | } |
| 83 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 84 | static struct tt_local_entry * |
| 85 | batadv_tt_local_hash_find(struct bat_priv *bat_priv, const void *data) |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 86 | { |
| 87 | struct tt_common_entry *tt_common_entry; |
| 88 | struct tt_local_entry *tt_local_entry = NULL; |
| 89 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 90 | tt_common_entry = batadv_tt_hash_find(bat_priv->tt_local_hash, data); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 91 | if (tt_common_entry) |
| 92 | tt_local_entry = container_of(tt_common_entry, |
| 93 | struct tt_local_entry, common); |
| 94 | return tt_local_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 97 | static struct tt_global_entry * |
| 98 | batadv_tt_global_hash_find(struct bat_priv *bat_priv, const void *data) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 99 | { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 100 | struct tt_common_entry *tt_common_entry; |
| 101 | struct tt_global_entry *tt_global_entry = NULL; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 102 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 103 | tt_common_entry = batadv_tt_hash_find(bat_priv->tt_global_hash, data); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 104 | if (tt_common_entry) |
| 105 | tt_global_entry = container_of(tt_common_entry, |
| 106 | struct tt_global_entry, common); |
| 107 | return tt_global_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 108 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 111 | static void |
| 112 | batadv_tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 113 | { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 114 | if (atomic_dec_and_test(&tt_local_entry->common.refcount)) |
| 115 | kfree_rcu(tt_local_entry, common.rcu); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 118 | static void batadv_tt_global_entry_free_rcu(struct rcu_head *rcu) |
Simon Wunderlich | 531027f | 2011-10-19 11:02:25 +0200 | [diff] [blame] | 119 | { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 120 | struct tt_common_entry *tt_common_entry; |
Simon Wunderlich | 531027f | 2011-10-19 11:02:25 +0200 | [diff] [blame] | 121 | struct tt_global_entry *tt_global_entry; |
| 122 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 123 | tt_common_entry = container_of(rcu, struct tt_common_entry, rcu); |
| 124 | tt_global_entry = container_of(tt_common_entry, struct tt_global_entry, |
| 125 | common); |
Simon Wunderlich | 531027f | 2011-10-19 11:02:25 +0200 | [diff] [blame] | 126 | |
Simon Wunderlich | 531027f | 2011-10-19 11:02:25 +0200 | [diff] [blame] | 127 | kfree(tt_global_entry); |
| 128 | } |
| 129 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 130 | static void |
| 131 | batadv_tt_global_entry_free_ref(struct tt_global_entry *tt_global_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 132 | { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 133 | if (atomic_dec_and_test(&tt_global_entry->common.refcount)) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 134 | batadv_tt_global_del_orig_list(tt_global_entry); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 135 | call_rcu(&tt_global_entry->common.rcu, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 136 | batadv_tt_global_entry_free_rcu); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 140 | static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 141 | { |
| 142 | struct tt_orig_list_entry *orig_entry; |
| 143 | |
| 144 | orig_entry = container_of(rcu, struct tt_orig_list_entry, rcu); |
| 145 | atomic_dec(&orig_entry->orig_node->tt_size); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 146 | batadv_orig_node_free_ref(orig_entry->orig_node); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 147 | kfree(orig_entry); |
| 148 | } |
| 149 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 150 | static void |
| 151 | batadv_tt_orig_list_entry_free_ref(struct tt_orig_list_entry *orig_entry) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 152 | { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 153 | call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 156 | static void batadv_tt_local_event(struct bat_priv *bat_priv, |
| 157 | const uint8_t *addr, uint8_t flags) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 158 | { |
| 159 | struct tt_change_node *tt_change_node; |
| 160 | |
| 161 | tt_change_node = kmalloc(sizeof(*tt_change_node), GFP_ATOMIC); |
| 162 | |
| 163 | if (!tt_change_node) |
| 164 | return; |
| 165 | |
Antonio Quartulli | ff66c97 | 2011-06-30 01:14:00 +0200 | [diff] [blame] | 166 | tt_change_node->change.flags = flags; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 167 | memcpy(tt_change_node->change.addr, addr, ETH_ALEN); |
| 168 | |
| 169 | spin_lock_bh(&bat_priv->tt_changes_list_lock); |
| 170 | /* track the change in the OGMinterval list */ |
| 171 | list_add_tail(&tt_change_node->list, &bat_priv->tt_changes_list); |
| 172 | atomic_inc(&bat_priv->tt_local_changes); |
| 173 | spin_unlock_bh(&bat_priv->tt_changes_list_lock); |
| 174 | |
| 175 | atomic_set(&bat_priv->tt_ogm_append_cnt, 0); |
| 176 | } |
| 177 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 178 | int batadv_tt_len(int changes_num) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 179 | { |
| 180 | return changes_num * sizeof(struct tt_change); |
| 181 | } |
| 182 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 183 | static int batadv_tt_local_init(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 184 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 185 | if (bat_priv->tt_local_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 186 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 187 | |
Sven Eckelmann | 1a8eaf0 | 2012-05-12 02:09:32 +0200 | [diff] [blame] | 188 | bat_priv->tt_local_hash = batadv_hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 189 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 190 | if (!bat_priv->tt_local_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 191 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 192 | |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 193 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 196 | void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, |
| 197 | int ifindex) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 198 | { |
| 199 | struct bat_priv *bat_priv = netdev_priv(soft_iface); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 200 | struct tt_local_entry *tt_local_entry = NULL; |
| 201 | struct tt_global_entry *tt_global_entry = NULL; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 202 | struct hlist_head *head; |
| 203 | struct hlist_node *node; |
| 204 | struct tt_orig_list_entry *orig_entry; |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 205 | int hash_added; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 206 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 207 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 208 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 209 | if (tt_local_entry) { |
| 210 | tt_local_entry->last_seen = jiffies; |
Antonio Quartulli | 521251f | 2012-01-16 00:36:58 +0100 | [diff] [blame] | 211 | /* possibly unset the TT_CLIENT_PENDING flag */ |
| 212 | tt_local_entry->common.flags &= ~TT_CLIENT_PENDING; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 213 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 216 | tt_local_entry = kmalloc(sizeof(*tt_local_entry), GFP_ATOMIC); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 217 | if (!tt_local_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 218 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 219 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 220 | batadv_dbg(DBG_TT, bat_priv, |
| 221 | "Creating new local tt entry: %pM (ttvn: %d)\n", addr, |
| 222 | (uint8_t)atomic_read(&bat_priv->ttvn)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 223 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 224 | memcpy(tt_local_entry->common.addr, addr, ETH_ALEN); |
| 225 | tt_local_entry->common.flags = NO_FLAGS; |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 226 | if (batadv_is_wifi_iface(ifindex)) |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 227 | tt_local_entry->common.flags |= TT_CLIENT_WIFI; |
| 228 | atomic_set(&tt_local_entry->common.refcount, 2); |
| 229 | tt_local_entry->last_seen = jiffies; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 230 | |
| 231 | /* the batman interface mac address should never be purged */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 232 | if (batadv_compare_eth(addr, soft_iface->dev_addr)) |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 233 | tt_local_entry->common.flags |= TT_CLIENT_NOPURGE; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 234 | |
Antonio Quartulli | c40ed2b | 2012-01-06 21:31:33 +0100 | [diff] [blame] | 235 | /* The local entry has to be marked as NEW to avoid to send it in |
| 236 | * a full table response going out before the next ttvn increment |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 237 | * (consistency check) |
| 238 | */ |
Antonio Quartulli | c40ed2b | 2012-01-06 21:31:33 +0100 | [diff] [blame] | 239 | tt_local_entry->common.flags |= TT_CLIENT_NEW; |
| 240 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 241 | hash_added = batadv_hash_add(bat_priv->tt_local_hash, batadv_compare_tt, |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 242 | batadv_choose_orig, |
| 243 | &tt_local_entry->common, |
Sven Eckelmann | c0a5592 | 2012-05-12 13:48:55 +0200 | [diff] [blame] | 244 | &tt_local_entry->common.hash_entry); |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 245 | |
| 246 | if (unlikely(hash_added != 0)) { |
| 247 | /* remove the reference for the hash */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 248 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 249 | goto out; |
| 250 | } |
| 251 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 252 | batadv_tt_local_event(bat_priv, addr, tt_local_entry->common.flags); |
Antonio Quartulli | ff66c97 | 2011-06-30 01:14:00 +0200 | [diff] [blame] | 253 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 254 | /* remove address from global hash if present */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 255 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 256 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 257 | /* Check whether it is a roaming! */ |
| 258 | if (tt_global_entry) { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 259 | /* These node are probably going to update their tt table */ |
| 260 | head = &tt_global_entry->orig_list; |
| 261 | rcu_read_lock(); |
| 262 | hlist_for_each_entry_rcu(orig_entry, node, head, list) { |
| 263 | orig_entry->orig_node->tt_poss_change = true; |
| 264 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 265 | batadv_send_roam_adv(bat_priv, |
| 266 | tt_global_entry->common.addr, |
| 267 | orig_entry->orig_node); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 268 | } |
| 269 | rcu_read_unlock(); |
| 270 | /* The global entry has to be marked as ROAMING and |
| 271 | * has to be kept for consistency purpose |
| 272 | */ |
David S. Miller | 220b07e | 2011-12-16 15:07:28 -0500 | [diff] [blame] | 273 | tt_global_entry->common.flags |= TT_CLIENT_ROAM; |
Antonio Quartulli | 03fc307 | 2011-12-04 12:26:50 +0100 | [diff] [blame] | 274 | tt_global_entry->roam_at = jiffies; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 275 | } |
| 276 | out: |
| 277 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 278 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 279 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 280 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 283 | static void batadv_tt_realloc_packet_buff(unsigned char **packet_buff, |
| 284 | int *packet_buff_len, |
| 285 | int min_packet_len, |
| 286 | int new_packet_len) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 287 | { |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 288 | unsigned char *new_buff; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 289 | |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 290 | new_buff = kmalloc(new_packet_len, GFP_ATOMIC); |
| 291 | |
| 292 | /* keep old buffer if kmalloc should fail */ |
| 293 | if (new_buff) { |
| 294 | memcpy(new_buff, *packet_buff, min_packet_len); |
| 295 | kfree(*packet_buff); |
| 296 | *packet_buff = new_buff; |
| 297 | *packet_buff_len = new_packet_len; |
| 298 | } |
| 299 | } |
| 300 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 301 | static void batadv_tt_prepare_packet_buff(struct bat_priv *bat_priv, |
| 302 | unsigned char **packet_buff, |
| 303 | int *packet_buff_len, |
| 304 | int min_packet_len) |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 305 | { |
| 306 | struct hard_iface *primary_if; |
| 307 | int req_len; |
| 308 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 309 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 310 | |
| 311 | req_len = min_packet_len; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 312 | req_len += batadv_tt_len(atomic_read(&bat_priv->tt_local_changes)); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 313 | |
| 314 | /* if we have too many changes for one packet don't send any |
| 315 | * and wait for the tt table request which will be fragmented |
| 316 | */ |
| 317 | if ((!primary_if) || (req_len > primary_if->soft_iface->mtu)) |
| 318 | req_len = min_packet_len; |
| 319 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 320 | batadv_tt_realloc_packet_buff(packet_buff, packet_buff_len, |
| 321 | min_packet_len, req_len); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 322 | |
| 323 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 324 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 325 | } |
| 326 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 327 | static int batadv_tt_changes_fill_buff(struct bat_priv *bat_priv, |
| 328 | unsigned char **packet_buff, |
| 329 | int *packet_buff_len, |
| 330 | int min_packet_len) |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 331 | { |
| 332 | struct tt_change_node *entry, *safe; |
| 333 | int count = 0, tot_changes = 0, new_len; |
| 334 | unsigned char *tt_buff; |
| 335 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 336 | batadv_tt_prepare_packet_buff(bat_priv, packet_buff, |
| 337 | packet_buff_len, min_packet_len); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 338 | |
| 339 | new_len = *packet_buff_len - min_packet_len; |
| 340 | tt_buff = *packet_buff + min_packet_len; |
| 341 | |
| 342 | if (new_len > 0) |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 343 | tot_changes = new_len / batadv_tt_len(1); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 344 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 345 | spin_lock_bh(&bat_priv->tt_changes_list_lock); |
| 346 | atomic_set(&bat_priv->tt_local_changes, 0); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 347 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 348 | list_for_each_entry_safe(entry, safe, &bat_priv->tt_changes_list, |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 349 | list) { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 350 | if (count < tot_changes) { |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 351 | memcpy(tt_buff + batadv_tt_len(count), |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 352 | &entry->change, sizeof(struct tt_change)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 353 | count++; |
| 354 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 355 | list_del(&entry->list); |
| 356 | kfree(entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 357 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 358 | spin_unlock_bh(&bat_priv->tt_changes_list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 359 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 360 | /* Keep the buffer for possible tt_request */ |
| 361 | spin_lock_bh(&bat_priv->tt_buff_lock); |
| 362 | kfree(bat_priv->tt_buff); |
| 363 | bat_priv->tt_buff_len = 0; |
| 364 | bat_priv->tt_buff = NULL; |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 365 | /* check whether this new OGM has no changes due to size problems */ |
| 366 | if (new_len > 0) { |
| 367 | /* if kmalloc() fails we will reply with the full table |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 368 | * instead of providing the diff |
| 369 | */ |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 370 | bat_priv->tt_buff = kmalloc(new_len, GFP_ATOMIC); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 371 | if (bat_priv->tt_buff) { |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 372 | memcpy(bat_priv->tt_buff, tt_buff, new_len); |
| 373 | bat_priv->tt_buff_len = new_len; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | spin_unlock_bh(&bat_priv->tt_buff_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 377 | |
Marek Lindner | 08ad76e | 2012-04-23 16:32:55 +0800 | [diff] [blame] | 378 | return count; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 381 | int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 382 | { |
| 383 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 384 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 385 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 386 | struct tt_common_entry *tt_common_entry; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 387 | struct hard_iface *primary_if; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 388 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 389 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 390 | uint32_t i; |
| 391 | int ret = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 392 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 393 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 394 | if (!primary_if) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 395 | ret = seq_printf(seq, |
| 396 | "BATMAN mesh %s disabled - please specify interfaces to enable it\n", |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 397 | net_dev->name); |
| 398 | goto out; |
| 399 | } |
| 400 | |
| 401 | if (primary_if->if_status != IF_ACTIVE) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 402 | ret = seq_printf(seq, |
| 403 | "BATMAN mesh %s disabled - primary interface not active\n", |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 404 | net_dev->name); |
| 405 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 408 | seq_printf(seq, |
| 409 | "Locally retrieved addresses (from %s) announced via TT (TTVN: %u):\n", |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 410 | net_dev->name, (uint8_t)atomic_read(&bat_priv->ttvn)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 411 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 412 | for (i = 0; i < hash->size; i++) { |
| 413 | head = &hash->table[i]; |
| 414 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 415 | rcu_read_lock(); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 416 | hlist_for_each_entry_rcu(tt_common_entry, node, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 417 | head, hash_entry) { |
Simon Wunderlich | d099c2c | 2011-10-22 18:15:26 +0200 | [diff] [blame] | 418 | seq_printf(seq, " * %pM [%c%c%c%c%c]\n", |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 419 | tt_common_entry->addr, |
| 420 | (tt_common_entry->flags & |
| 421 | TT_CLIENT_ROAM ? 'R' : '.'), |
| 422 | (tt_common_entry->flags & |
| 423 | TT_CLIENT_NOPURGE ? 'P' : '.'), |
| 424 | (tt_common_entry->flags & |
| 425 | TT_CLIENT_NEW ? 'N' : '.'), |
| 426 | (tt_common_entry->flags & |
| 427 | TT_CLIENT_PENDING ? 'X' : '.'), |
| 428 | (tt_common_entry->flags & |
| 429 | TT_CLIENT_WIFI ? 'W' : '.')); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 430 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 431 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 432 | } |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 433 | out: |
| 434 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 435 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 436 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 439 | static void batadv_tt_local_set_pending(struct bat_priv *bat_priv, |
| 440 | struct tt_local_entry *tt_local_entry, |
| 441 | uint16_t flags, const char *message) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 442 | { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 443 | batadv_tt_local_event(bat_priv, tt_local_entry->common.addr, |
| 444 | tt_local_entry->common.flags | flags); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 445 | |
Antonio Quartulli | 015758d | 2011-07-09 17:52:13 +0200 | [diff] [blame] | 446 | /* The local client has to be marked as "pending to be removed" but has |
| 447 | * to be kept in the table in order to send it in a full table |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 448 | * response issued before the net ttvn increment (consistency check) |
| 449 | */ |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 450 | tt_local_entry->common.flags |= TT_CLIENT_PENDING; |
Antonio Quartulli | c566dbb | 2012-01-06 21:31:34 +0100 | [diff] [blame] | 451 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 452 | batadv_dbg(DBG_TT, bat_priv, |
| 453 | "Local tt entry (%pM) pending to be removed: %s\n", |
| 454 | tt_local_entry->common.addr, message); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 457 | void batadv_tt_local_remove(struct bat_priv *bat_priv, const uint8_t *addr, |
| 458 | const char *message, bool roaming) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 459 | { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 460 | struct tt_local_entry *tt_local_entry = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 461 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 462 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 463 | if (!tt_local_entry) |
| 464 | goto out; |
| 465 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 466 | batadv_tt_local_set_pending(bat_priv, tt_local_entry, TT_CLIENT_DEL | |
| 467 | (roaming ? TT_CLIENT_ROAM : NO_FLAGS), |
| 468 | message); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 469 | out: |
| 470 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 471 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 474 | static void batadv_tt_local_purge(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 475 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 476 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
| 477 | struct tt_local_entry *tt_local_entry; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 478 | struct tt_common_entry *tt_common_entry; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 479 | struct hlist_node *node, *node_tmp; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 480 | struct hlist_head *head; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 481 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 482 | uint32_t i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 483 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 484 | for (i = 0; i < hash->size; i++) { |
| 485 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 486 | list_lock = &hash->list_locks[i]; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 487 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 488 | spin_lock_bh(list_lock); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 489 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 490 | head, hash_entry) { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 491 | tt_local_entry = container_of(tt_common_entry, |
| 492 | struct tt_local_entry, |
| 493 | common); |
| 494 | if (tt_local_entry->common.flags & TT_CLIENT_NOPURGE) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 495 | continue; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 496 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 497 | /* entry already marked for deletion */ |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 498 | if (tt_local_entry->common.flags & TT_CLIENT_PENDING) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 499 | continue; |
| 500 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 501 | if (!batadv_has_timed_out(tt_local_entry->last_seen, |
| 502 | TT_LOCAL_TIMEOUT)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 503 | continue; |
| 504 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 505 | batadv_tt_local_set_pending(bat_priv, tt_local_entry, |
| 506 | TT_CLIENT_DEL, "timed out"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 507 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 508 | spin_unlock_bh(list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 513 | static void batadv_tt_local_table_free(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 514 | { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 515 | struct hashtable_t *hash; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 516 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 517 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 518 | struct tt_local_entry *tt_local_entry; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 519 | struct hlist_node *node, *node_tmp; |
| 520 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 521 | uint32_t i; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 522 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 523 | if (!bat_priv->tt_local_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 524 | return; |
| 525 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 526 | hash = bat_priv->tt_local_hash; |
| 527 | |
| 528 | for (i = 0; i < hash->size; i++) { |
| 529 | head = &hash->table[i]; |
| 530 | list_lock = &hash->list_locks[i]; |
| 531 | |
| 532 | spin_lock_bh(list_lock); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 533 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 534 | head, hash_entry) { |
| 535 | hlist_del_rcu(node); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 536 | tt_local_entry = container_of(tt_common_entry, |
| 537 | struct tt_local_entry, |
| 538 | common); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 539 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 540 | } |
| 541 | spin_unlock_bh(list_lock); |
| 542 | } |
| 543 | |
Sven Eckelmann | 1a8eaf0 | 2012-05-12 02:09:32 +0200 | [diff] [blame] | 544 | batadv_hash_destroy(hash); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 545 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 546 | bat_priv->tt_local_hash = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 549 | static int batadv_tt_global_init(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 550 | { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 551 | if (bat_priv->tt_global_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 552 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 553 | |
Sven Eckelmann | 1a8eaf0 | 2012-05-12 02:09:32 +0200 | [diff] [blame] | 554 | bat_priv->tt_global_hash = batadv_hash_new(1024); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 555 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 556 | if (!bat_priv->tt_global_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 557 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 558 | |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 559 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 562 | static void batadv_tt_changes_list_free(struct bat_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 563 | { |
| 564 | struct tt_change_node *entry, *safe; |
| 565 | |
| 566 | spin_lock_bh(&bat_priv->tt_changes_list_lock); |
| 567 | |
| 568 | list_for_each_entry_safe(entry, safe, &bat_priv->tt_changes_list, |
| 569 | list) { |
| 570 | list_del(&entry->list); |
| 571 | kfree(entry); |
| 572 | } |
| 573 | |
| 574 | atomic_set(&bat_priv->tt_local_changes, 0); |
| 575 | spin_unlock_bh(&bat_priv->tt_changes_list_lock); |
| 576 | } |
| 577 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 578 | /* find out if an orig_node is already in the list of a tt_global_entry. |
| 579 | * returns 1 if found, 0 otherwise |
| 580 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 581 | static bool batadv_tt_global_entry_has_orig(const struct tt_global_entry *entry, |
| 582 | const struct orig_node *orig_node) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 583 | { |
| 584 | struct tt_orig_list_entry *tmp_orig_entry; |
| 585 | const struct hlist_head *head; |
| 586 | struct hlist_node *node; |
| 587 | bool found = false; |
| 588 | |
| 589 | rcu_read_lock(); |
| 590 | head = &entry->orig_list; |
| 591 | hlist_for_each_entry_rcu(tmp_orig_entry, node, head, list) { |
| 592 | if (tmp_orig_entry->orig_node == orig_node) { |
| 593 | found = true; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | rcu_read_unlock(); |
| 598 | return found; |
| 599 | } |
| 600 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 601 | static void |
| 602 | batadv_tt_global_add_orig_entry(struct tt_global_entry *tt_global_entry, |
| 603 | struct orig_node *orig_node, int ttvn) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 604 | { |
| 605 | struct tt_orig_list_entry *orig_entry; |
| 606 | |
| 607 | orig_entry = kzalloc(sizeof(*orig_entry), GFP_ATOMIC); |
| 608 | if (!orig_entry) |
| 609 | return; |
| 610 | |
| 611 | INIT_HLIST_NODE(&orig_entry->list); |
| 612 | atomic_inc(&orig_node->refcount); |
| 613 | atomic_inc(&orig_node->tt_size); |
| 614 | orig_entry->orig_node = orig_node; |
| 615 | orig_entry->ttvn = ttvn; |
| 616 | |
| 617 | spin_lock_bh(&tt_global_entry->list_lock); |
| 618 | hlist_add_head_rcu(&orig_entry->list, |
| 619 | &tt_global_entry->orig_list); |
| 620 | spin_unlock_bh(&tt_global_entry->list_lock); |
| 621 | } |
| 622 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 623 | /* caller must hold orig_node refcount */ |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 624 | int batadv_tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, |
| 625 | const unsigned char *tt_addr, uint8_t ttvn, |
| 626 | bool roaming, bool wifi) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 627 | { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 628 | struct tt_global_entry *tt_global_entry = NULL; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 629 | int ret = 0; |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 630 | int hash_added; |
Sven Eckelmann | c0a5592 | 2012-05-12 13:48:55 +0200 | [diff] [blame] | 631 | struct tt_common_entry *common; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 632 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 633 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, tt_addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 634 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 635 | if (!tt_global_entry) { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 636 | tt_global_entry = kzalloc(sizeof(*tt_global_entry), |
| 637 | GFP_ATOMIC); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 638 | if (!tt_global_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 639 | goto out; |
| 640 | |
Sven Eckelmann | c0a5592 | 2012-05-12 13:48:55 +0200 | [diff] [blame] | 641 | common = &tt_global_entry->common; |
| 642 | memcpy(common->addr, tt_addr, ETH_ALEN); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 643 | |
Sven Eckelmann | c0a5592 | 2012-05-12 13:48:55 +0200 | [diff] [blame] | 644 | common->flags = NO_FLAGS; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 645 | tt_global_entry->roam_at = 0; |
Sven Eckelmann | c0a5592 | 2012-05-12 13:48:55 +0200 | [diff] [blame] | 646 | atomic_set(&common->refcount, 2); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 647 | |
| 648 | INIT_HLIST_HEAD(&tt_global_entry->orig_list); |
| 649 | spin_lock_init(&tt_global_entry->list_lock); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 650 | |
Sven Eckelmann | c0a5592 | 2012-05-12 13:48:55 +0200 | [diff] [blame] | 651 | hash_added = batadv_hash_add(bat_priv->tt_global_hash, |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 652 | batadv_compare_tt, |
| 653 | batadv_choose_orig, common, |
| 654 | &common->hash_entry); |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 655 | |
| 656 | if (unlikely(hash_added != 0)) { |
| 657 | /* remove the reference for the hash */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 658 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 659 | goto out_remove; |
| 660 | } |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 661 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 662 | batadv_tt_global_add_orig_entry(tt_global_entry, orig_node, |
| 663 | ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 664 | } else { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 665 | /* there is already a global entry, use this one. */ |
| 666 | |
| 667 | /* If there is the TT_CLIENT_ROAM flag set, there is only one |
| 668 | * originator left in the list and we previously received a |
| 669 | * delete + roaming change for this originator. |
| 670 | * |
| 671 | * We should first delete the old originator before adding the |
| 672 | * new one. |
| 673 | */ |
| 674 | if (tt_global_entry->common.flags & TT_CLIENT_ROAM) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 675 | batadv_tt_global_del_orig_list(tt_global_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 676 | tt_global_entry->common.flags &= ~TT_CLIENT_ROAM; |
| 677 | tt_global_entry->roam_at = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 678 | } |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 679 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 680 | if (!batadv_tt_global_entry_has_orig(tt_global_entry, |
| 681 | orig_node)) |
| 682 | batadv_tt_global_add_orig_entry(tt_global_entry, |
| 683 | orig_node, ttvn); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 684 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 685 | |
Antonio Quartulli | bc27908 | 2011-07-07 15:35:35 +0200 | [diff] [blame] | 686 | if (wifi) |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 687 | tt_global_entry->common.flags |= TT_CLIENT_WIFI; |
Antonio Quartulli | bc27908 | 2011-07-07 15:35:35 +0200 | [diff] [blame] | 688 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 689 | batadv_dbg(DBG_TT, bat_priv, |
| 690 | "Creating new global tt entry: %pM (via %pM)\n", |
| 691 | tt_global_entry->common.addr, orig_node->orig); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 692 | |
Simon Wunderlich | 80b3f58 | 2011-11-02 20:26:45 +0100 | [diff] [blame] | 693 | out_remove: |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 694 | /* remove address from local hash if present */ |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 695 | batadv_tt_local_remove(bat_priv, tt_global_entry->common.addr, |
| 696 | "global tt received", roaming); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 697 | ret = 1; |
| 698 | out: |
| 699 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 700 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 701 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 704 | /* print all orig nodes who announce the address for this global entry. |
| 705 | * it is assumed that the caller holds rcu_read_lock(); |
| 706 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 707 | static void |
| 708 | batadv_tt_global_print_entry(struct tt_global_entry *tt_global_entry, |
| 709 | struct seq_file *seq) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 710 | { |
| 711 | struct hlist_head *head; |
| 712 | struct hlist_node *node; |
| 713 | struct tt_orig_list_entry *orig_entry; |
| 714 | struct tt_common_entry *tt_common_entry; |
| 715 | uint16_t flags; |
| 716 | uint8_t last_ttvn; |
| 717 | |
| 718 | tt_common_entry = &tt_global_entry->common; |
| 719 | |
| 720 | head = &tt_global_entry->orig_list; |
| 721 | |
| 722 | hlist_for_each_entry_rcu(orig_entry, node, head, list) { |
| 723 | flags = tt_common_entry->flags; |
| 724 | last_ttvn = atomic_read(&orig_entry->orig_node->last_ttvn); |
| 725 | seq_printf(seq, " * %pM (%3u) via %pM (%3u) [%c%c]\n", |
| 726 | tt_global_entry->common.addr, orig_entry->ttvn, |
| 727 | orig_entry->orig_node->orig, last_ttvn, |
| 728 | (flags & TT_CLIENT_ROAM ? 'R' : '.'), |
| 729 | (flags & TT_CLIENT_WIFI ? 'W' : '.')); |
| 730 | } |
| 731 | } |
| 732 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 733 | int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 734 | { |
| 735 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 736 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 737 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 738 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 739 | struct tt_global_entry *tt_global_entry; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 740 | struct hard_iface *primary_if; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 741 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 742 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 743 | uint32_t i; |
| 744 | int ret = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 745 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 746 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 747 | if (!primary_if) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 748 | ret = seq_printf(seq, |
| 749 | "BATMAN mesh %s disabled - please specify interfaces to enable it\n", |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 750 | net_dev->name); |
| 751 | goto out; |
| 752 | } |
| 753 | |
| 754 | if (primary_if->if_status != IF_ACTIVE) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 755 | ret = seq_printf(seq, |
| 756 | "BATMAN mesh %s disabled - primary interface not active\n", |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 757 | net_dev->name); |
| 758 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 761 | seq_printf(seq, |
| 762 | "Globally announced TT entries received via the mesh %s\n", |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 763 | net_dev->name); |
Antonio Quartulli | df6edb9 | 2011-07-07 15:35:38 +0200 | [diff] [blame] | 764 | seq_printf(seq, " %-13s %s %-15s %s %s\n", |
| 765 | "Client", "(TTVN)", "Originator", "(Curr TTVN)", "Flags"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 766 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 767 | for (i = 0; i < hash->size; i++) { |
| 768 | head = &hash->table[i]; |
| 769 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 770 | rcu_read_lock(); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 771 | hlist_for_each_entry_rcu(tt_common_entry, node, |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 772 | head, hash_entry) { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 773 | tt_global_entry = container_of(tt_common_entry, |
| 774 | struct tt_global_entry, |
| 775 | common); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 776 | batadv_tt_global_print_entry(tt_global_entry, seq); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 777 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 778 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 779 | } |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 780 | out: |
| 781 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 782 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 783 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 786 | /* deletes the orig list of a tt_global_entry */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 787 | static void |
| 788 | batadv_tt_global_del_orig_list(struct tt_global_entry *tt_global_entry) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 789 | { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 790 | struct hlist_head *head; |
| 791 | struct hlist_node *node, *safe; |
| 792 | struct tt_orig_list_entry *orig_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 793 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 794 | spin_lock_bh(&tt_global_entry->list_lock); |
| 795 | head = &tt_global_entry->orig_list; |
| 796 | hlist_for_each_entry_safe(orig_entry, node, safe, head, list) { |
| 797 | hlist_del_rcu(node); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 798 | batadv_tt_orig_list_entry_free_ref(orig_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 799 | } |
| 800 | spin_unlock_bh(&tt_global_entry->list_lock); |
| 801 | |
| 802 | } |
| 803 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 804 | static void |
| 805 | batadv_tt_global_del_orig_entry(struct bat_priv *bat_priv, |
| 806 | struct tt_global_entry *tt_global_entry, |
| 807 | struct orig_node *orig_node, |
| 808 | const char *message) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 809 | { |
| 810 | struct hlist_head *head; |
| 811 | struct hlist_node *node, *safe; |
| 812 | struct tt_orig_list_entry *orig_entry; |
| 813 | |
| 814 | spin_lock_bh(&tt_global_entry->list_lock); |
| 815 | head = &tt_global_entry->orig_list; |
| 816 | hlist_for_each_entry_safe(orig_entry, node, safe, head, list) { |
| 817 | if (orig_entry->orig_node == orig_node) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 818 | batadv_dbg(DBG_TT, bat_priv, |
| 819 | "Deleting %pM from global tt entry %pM: %s\n", |
| 820 | orig_node->orig, |
| 821 | tt_global_entry->common.addr, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 822 | hlist_del_rcu(node); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 823 | batadv_tt_orig_list_entry_free_ref(orig_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | spin_unlock_bh(&tt_global_entry->list_lock); |
| 827 | } |
| 828 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 829 | static void batadv_tt_global_del_struct(struct bat_priv *bat_priv, |
| 830 | struct tt_global_entry *tt_global_entry, |
| 831 | const char *message) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 832 | { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 833 | batadv_dbg(DBG_TT, bat_priv, "Deleting global tt entry %pM: %s\n", |
| 834 | tt_global_entry->common.addr, message); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 835 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 836 | batadv_hash_remove(bat_priv->tt_global_hash, batadv_compare_tt, |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 837 | batadv_choose_orig, tt_global_entry->common.addr); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 838 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 839 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 842 | /* If the client is to be deleted, we check if it is the last origantor entry |
| 843 | * within tt_global entry. If yes, we set the TT_CLIENT_ROAM flag and the timer, |
| 844 | * otherwise we simply remove the originator scheduled for deletion. |
| 845 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 846 | static void |
| 847 | batadv_tt_global_del_roaming(struct bat_priv *bat_priv, |
| 848 | struct tt_global_entry *tt_global_entry, |
| 849 | struct orig_node *orig_node, const char *message) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 850 | { |
| 851 | bool last_entry = true; |
| 852 | struct hlist_head *head; |
| 853 | struct hlist_node *node; |
| 854 | struct tt_orig_list_entry *orig_entry; |
| 855 | |
| 856 | /* no local entry exists, case 1: |
| 857 | * Check if this is the last one or if other entries exist. |
| 858 | */ |
| 859 | |
| 860 | rcu_read_lock(); |
| 861 | head = &tt_global_entry->orig_list; |
| 862 | hlist_for_each_entry_rcu(orig_entry, node, head, list) { |
| 863 | if (orig_entry->orig_node != orig_node) { |
| 864 | last_entry = false; |
| 865 | break; |
| 866 | } |
| 867 | } |
| 868 | rcu_read_unlock(); |
| 869 | |
| 870 | if (last_entry) { |
| 871 | /* its the last one, mark for roaming. */ |
| 872 | tt_global_entry->common.flags |= TT_CLIENT_ROAM; |
| 873 | tt_global_entry->roam_at = jiffies; |
| 874 | } else |
| 875 | /* there is another entry, we can simply delete this |
| 876 | * one and can still use the other one. |
| 877 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 878 | batadv_tt_global_del_orig_entry(bat_priv, tt_global_entry, |
| 879 | orig_node, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | |
| 883 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 884 | static void batadv_tt_global_del(struct bat_priv *bat_priv, |
| 885 | struct orig_node *orig_node, |
| 886 | const unsigned char *addr, |
| 887 | const char *message, bool roaming) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 888 | { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 889 | struct tt_global_entry *tt_global_entry = NULL; |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 890 | struct tt_local_entry *local_entry = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 891 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 892 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 893 | if (!tt_global_entry) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 894 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 895 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 896 | if (!roaming) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 897 | batadv_tt_global_del_orig_entry(bat_priv, tt_global_entry, |
| 898 | orig_node, message); |
Sven Eckelmann | 92f90f5 | 2011-12-22 20:31:12 +0800 | [diff] [blame] | 899 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 900 | if (hlist_empty(&tt_global_entry->orig_list)) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 901 | batadv_tt_global_del_struct(bat_priv, tt_global_entry, |
| 902 | message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 903 | |
Sven Eckelmann | 92f90f5 | 2011-12-22 20:31:12 +0800 | [diff] [blame] | 904 | goto out; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 905 | } |
Sven Eckelmann | 92f90f5 | 2011-12-22 20:31:12 +0800 | [diff] [blame] | 906 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 907 | /* if we are deleting a global entry due to a roam |
| 908 | * event, there are two possibilities: |
| 909 | * 1) the client roamed from node A to node B => if there |
| 910 | * is only one originator left for this client, we mark |
| 911 | * it with TT_CLIENT_ROAM, we start a timer and we |
| 912 | * wait for node B to claim it. In case of timeout |
| 913 | * the entry is purged. |
| 914 | * |
| 915 | * If there are other originators left, we directly delete |
| 916 | * the originator. |
| 917 | * 2) the client roamed to us => we can directly delete |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 918 | * the global entry, since it is useless now. |
| 919 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 920 | local_entry = batadv_tt_local_hash_find(bat_priv, |
| 921 | tt_global_entry->common.addr); |
| 922 | if (local_entry) { |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 923 | /* local entry exists, case 2: client roamed to us. */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 924 | batadv_tt_global_del_orig_list(tt_global_entry); |
| 925 | batadv_tt_global_del_struct(bat_priv, tt_global_entry, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 926 | } else |
| 927 | /* no local entry exists, case 1: check for roaming */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 928 | batadv_tt_global_del_roaming(bat_priv, tt_global_entry, |
| 929 | orig_node, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 930 | |
Sven Eckelmann | 92f90f5 | 2011-12-22 20:31:12 +0800 | [diff] [blame] | 931 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 932 | out: |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 933 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 934 | batadv_tt_global_entry_free_ref(tt_global_entry); |
| 935 | if (local_entry) |
| 936 | batadv_tt_local_entry_free_ref(local_entry); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 937 | } |
| 938 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 939 | void batadv_tt_global_del_orig(struct bat_priv *bat_priv, |
| 940 | struct orig_node *orig_node, const char *message) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 941 | { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 942 | struct tt_global_entry *global_entry; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 943 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 944 | uint32_t i; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 945 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
| 946 | struct hlist_node *node, *safe; |
| 947 | struct hlist_head *head; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 948 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 949 | |
Simon Wunderlich | 6e80149 | 2011-10-19 10:28:26 +0200 | [diff] [blame] | 950 | if (!hash) |
| 951 | return; |
| 952 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 953 | for (i = 0; i < hash->size; i++) { |
| 954 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 955 | list_lock = &hash->list_locks[i]; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 956 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 957 | spin_lock_bh(list_lock); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 958 | hlist_for_each_entry_safe(tt_common_entry, node, safe, |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 959 | head, hash_entry) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 960 | global_entry = container_of(tt_common_entry, |
| 961 | struct tt_global_entry, |
| 962 | common); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 963 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 964 | batadv_tt_global_del_orig_entry(bat_priv, global_entry, |
| 965 | orig_node, message); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 966 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 967 | if (hlist_empty(&global_entry->orig_list)) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 968 | batadv_dbg(DBG_TT, bat_priv, |
| 969 | "Deleting global tt entry %pM: %s\n", |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 970 | global_entry->common.addr, message); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 971 | hlist_del_rcu(node); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 972 | batadv_tt_global_entry_free_ref(global_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 973 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 974 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 975 | spin_unlock_bh(list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 976 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 977 | atomic_set(&orig_node->tt_size, 0); |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 978 | orig_node->tt_initialised = false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 981 | static void batadv_tt_global_roam_purge(struct bat_priv *bat_priv) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 982 | { |
| 983 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 984 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 985 | struct tt_global_entry *tt_global_entry; |
| 986 | struct hlist_node *node, *node_tmp; |
| 987 | struct hlist_head *head; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 988 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 989 | uint32_t i; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 990 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 991 | for (i = 0; i < hash->size; i++) { |
| 992 | head = &hash->table[i]; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 993 | list_lock = &hash->list_locks[i]; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 994 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 995 | spin_lock_bh(list_lock); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 996 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 997 | head, hash_entry) { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 998 | tt_global_entry = container_of(tt_common_entry, |
| 999 | struct tt_global_entry, |
| 1000 | common); |
| 1001 | if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1002 | continue; |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1003 | if (!batadv_has_timed_out(tt_global_entry->roam_at, |
| 1004 | TT_CLIENT_ROAM_TIMEOUT)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1005 | continue; |
| 1006 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1007 | batadv_dbg(DBG_TT, bat_priv, |
| 1008 | "Deleting global tt entry (%pM): Roaming timeout\n", |
| 1009 | tt_global_entry->common.addr); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1010 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1011 | hlist_del_rcu(node); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1012 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1013 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1014 | spin_unlock_bh(list_lock); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1015 | } |
| 1016 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1017 | } |
| 1018 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1019 | static void batadv_tt_global_table_free(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1020 | { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1021 | struct hashtable_t *hash; |
| 1022 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1023 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1024 | struct tt_global_entry *tt_global_entry; |
| 1025 | struct hlist_node *node, *node_tmp; |
| 1026 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1027 | uint32_t i; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1028 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 1029 | if (!bat_priv->tt_global_hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1030 | return; |
| 1031 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1032 | hash = bat_priv->tt_global_hash; |
| 1033 | |
| 1034 | for (i = 0; i < hash->size; i++) { |
| 1035 | head = &hash->table[i]; |
| 1036 | list_lock = &hash->list_locks[i]; |
| 1037 | |
| 1038 | spin_lock_bh(list_lock); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1039 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1040 | head, hash_entry) { |
| 1041 | hlist_del_rcu(node); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1042 | tt_global_entry = container_of(tt_common_entry, |
| 1043 | struct tt_global_entry, |
| 1044 | common); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1045 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1046 | } |
| 1047 | spin_unlock_bh(list_lock); |
| 1048 | } |
| 1049 | |
Sven Eckelmann | 1a8eaf0 | 2012-05-12 02:09:32 +0200 | [diff] [blame] | 1050 | batadv_hash_destroy(hash); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1051 | |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 1052 | bat_priv->tt_global_hash = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1055 | static bool _batadv_is_ap_isolated(struct tt_local_entry *tt_local_entry, |
| 1056 | struct tt_global_entry *tt_global_entry) |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 1057 | { |
| 1058 | bool ret = false; |
| 1059 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1060 | if (tt_local_entry->common.flags & TT_CLIENT_WIFI && |
| 1061 | tt_global_entry->common.flags & TT_CLIENT_WIFI) |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 1062 | ret = true; |
| 1063 | |
| 1064 | return ret; |
| 1065 | } |
| 1066 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1067 | struct orig_node *batadv_transtable_search(struct bat_priv *bat_priv, |
| 1068 | const uint8_t *src, |
| 1069 | const uint8_t *addr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1070 | { |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1071 | struct tt_local_entry *tt_local_entry = NULL; |
| 1072 | struct tt_global_entry *tt_global_entry = NULL; |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1073 | struct orig_node *orig_node = NULL; |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1074 | struct neigh_node *router = NULL; |
| 1075 | struct hlist_head *head; |
| 1076 | struct hlist_node *node; |
| 1077 | struct tt_orig_list_entry *orig_entry; |
| 1078 | int best_tq; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1079 | |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1080 | if (src && atomic_read(&bat_priv->ap_isolation)) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1081 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, src); |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1082 | if (!tt_local_entry) |
| 1083 | goto out; |
| 1084 | } |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 1085 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1086 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 1087 | if (!tt_global_entry) |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1088 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1089 | |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1090 | /* check whether the clients should not communicate due to AP |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1091 | * isolation |
| 1092 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1093 | if (tt_local_entry && |
| 1094 | _batadv_is_ap_isolated(tt_local_entry, tt_global_entry)) |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1095 | goto out; |
| 1096 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1097 | best_tq = 0; |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1098 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1099 | rcu_read_lock(); |
| 1100 | head = &tt_global_entry->orig_list; |
| 1101 | hlist_for_each_entry_rcu(orig_entry, node, head, list) { |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1102 | router = batadv_orig_node_get_router(orig_entry->orig_node); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1103 | if (!router) |
| 1104 | continue; |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1105 | |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1106 | if (router->tq_avg > best_tq) { |
| 1107 | orig_node = orig_entry->orig_node; |
| 1108 | best_tq = router->tq_avg; |
| 1109 | } |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1110 | batadv_neigh_node_free_ref(router); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1111 | } |
| 1112 | /* found anything? */ |
| 1113 | if (orig_node && !atomic_inc_not_zero(&orig_node->refcount)) |
| 1114 | orig_node = NULL; |
| 1115 | rcu_read_unlock(); |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1116 | out: |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1117 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1118 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1119 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1120 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 3d393e4 | 2011-07-07 15:35:37 +0200 | [diff] [blame] | 1121 | |
Marek Lindner | 7b36e8e | 2011-02-18 12:28:10 +0000 | [diff] [blame] | 1122 | return orig_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1123 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1124 | |
| 1125 | /* Calculates the checksum of the local table of a given orig_node */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1126 | static uint16_t batadv_tt_global_crc(struct bat_priv *bat_priv, |
| 1127 | struct orig_node *orig_node) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1128 | { |
| 1129 | uint16_t total = 0, total_one; |
| 1130 | struct hashtable_t *hash = bat_priv->tt_global_hash; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1131 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1132 | struct tt_global_entry *tt_global_entry; |
| 1133 | struct hlist_node *node; |
| 1134 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1135 | uint32_t i; |
| 1136 | int j; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1137 | |
| 1138 | for (i = 0; i < hash->size; i++) { |
| 1139 | head = &hash->table[i]; |
| 1140 | |
| 1141 | rcu_read_lock(); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1142 | hlist_for_each_entry_rcu(tt_common_entry, node, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1143 | head, hash_entry) { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1144 | tt_global_entry = container_of(tt_common_entry, |
| 1145 | struct tt_global_entry, |
| 1146 | common); |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1147 | /* Roaming clients are in the global table for |
| 1148 | * consistency only. They don't have to be |
| 1149 | * taken into account while computing the |
| 1150 | * global crc |
| 1151 | */ |
| 1152 | if (tt_global_entry->common.flags & TT_CLIENT_ROAM) |
| 1153 | continue; |
| 1154 | |
| 1155 | /* find out if this global entry is announced by this |
| 1156 | * originator |
| 1157 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1158 | if (!batadv_tt_global_entry_has_orig(tt_global_entry, |
| 1159 | orig_node)) |
Simon Wunderlich | db08e6e | 2011-10-22 20:12:51 +0200 | [diff] [blame] | 1160 | continue; |
| 1161 | |
| 1162 | total_one = 0; |
| 1163 | for (j = 0; j < ETH_ALEN; j++) |
| 1164 | total_one = crc16_byte(total_one, |
| 1165 | tt_global_entry->common.addr[j]); |
| 1166 | total ^= total_one; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1167 | } |
| 1168 | rcu_read_unlock(); |
| 1169 | } |
| 1170 | |
| 1171 | return total; |
| 1172 | } |
| 1173 | |
| 1174 | /* Calculates the checksum of the local table */ |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 1175 | static uint16_t batadv_tt_local_crc(struct bat_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1176 | { |
| 1177 | uint16_t total = 0, total_one; |
| 1178 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1179 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1180 | struct hlist_node *node; |
| 1181 | struct hlist_head *head; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1182 | uint32_t i; |
| 1183 | int j; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1184 | |
| 1185 | for (i = 0; i < hash->size; i++) { |
| 1186 | head = &hash->table[i]; |
| 1187 | |
| 1188 | rcu_read_lock(); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1189 | hlist_for_each_entry_rcu(tt_common_entry, node, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1190 | head, hash_entry) { |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1191 | /* not yet committed clients have not to be taken into |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1192 | * account while computing the CRC |
| 1193 | */ |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1194 | if (tt_common_entry->flags & TT_CLIENT_NEW) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1195 | continue; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1196 | total_one = 0; |
| 1197 | for (j = 0; j < ETH_ALEN; j++) |
| 1198 | total_one = crc16_byte(total_one, |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1199 | tt_common_entry->addr[j]); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1200 | total ^= total_one; |
| 1201 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1202 | rcu_read_unlock(); |
| 1203 | } |
| 1204 | |
| 1205 | return total; |
| 1206 | } |
| 1207 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1208 | static void batadv_tt_req_list_free(struct bat_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1209 | { |
| 1210 | struct tt_req_node *node, *safe; |
| 1211 | |
| 1212 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 1213 | |
| 1214 | list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { |
| 1215 | list_del(&node->list); |
| 1216 | kfree(node); |
| 1217 | } |
| 1218 | |
| 1219 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 1220 | } |
| 1221 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1222 | static void batadv_tt_save_orig_buffer(struct bat_priv *bat_priv, |
| 1223 | struct orig_node *orig_node, |
| 1224 | const unsigned char *tt_buff, |
| 1225 | uint8_t tt_num_changes) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1226 | { |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1227 | uint16_t tt_buff_len = batadv_tt_len(tt_num_changes); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1228 | |
| 1229 | /* Replace the old buffer only if I received something in the |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1230 | * last OGM (the OGM could carry no changes) |
| 1231 | */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1232 | spin_lock_bh(&orig_node->tt_buff_lock); |
| 1233 | if (tt_buff_len > 0) { |
| 1234 | kfree(orig_node->tt_buff); |
| 1235 | orig_node->tt_buff_len = 0; |
| 1236 | orig_node->tt_buff = kmalloc(tt_buff_len, GFP_ATOMIC); |
| 1237 | if (orig_node->tt_buff) { |
| 1238 | memcpy(orig_node->tt_buff, tt_buff, tt_buff_len); |
| 1239 | orig_node->tt_buff_len = tt_buff_len; |
| 1240 | } |
| 1241 | } |
| 1242 | spin_unlock_bh(&orig_node->tt_buff_lock); |
| 1243 | } |
| 1244 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1245 | static void batadv_tt_req_purge(struct bat_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1246 | { |
| 1247 | struct tt_req_node *node, *safe; |
| 1248 | |
| 1249 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 1250 | list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1251 | if (batadv_has_timed_out(node->issued_at, TT_REQUEST_TIMEOUT)) { |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1252 | list_del(&node->list); |
| 1253 | kfree(node); |
| 1254 | } |
| 1255 | } |
| 1256 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 1257 | } |
| 1258 | |
| 1259 | /* returns the pointer to the new tt_req_node struct if no request |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1260 | * has already been issued for this orig_node, NULL otherwise |
| 1261 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1262 | static struct tt_req_node *batadv_new_tt_req_node(struct bat_priv *bat_priv, |
| 1263 | struct orig_node *orig_node) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1264 | { |
| 1265 | struct tt_req_node *tt_req_node_tmp, *tt_req_node = NULL; |
| 1266 | |
| 1267 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 1268 | list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1269 | if (batadv_compare_eth(tt_req_node_tmp, orig_node) && |
| 1270 | !batadv_has_timed_out(tt_req_node_tmp->issued_at, |
| 1271 | TT_REQUEST_TIMEOUT)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1272 | goto unlock; |
| 1273 | } |
| 1274 | |
| 1275 | tt_req_node = kmalloc(sizeof(*tt_req_node), GFP_ATOMIC); |
| 1276 | if (!tt_req_node) |
| 1277 | goto unlock; |
| 1278 | |
| 1279 | memcpy(tt_req_node->addr, orig_node->orig, ETH_ALEN); |
| 1280 | tt_req_node->issued_at = jiffies; |
| 1281 | |
| 1282 | list_add(&tt_req_node->list, &bat_priv->tt_req_list); |
| 1283 | unlock: |
| 1284 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 1285 | return tt_req_node; |
| 1286 | } |
| 1287 | |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1288 | /* data_ptr is useless here, but has to be kept to respect the prototype */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1289 | static int batadv_tt_local_valid_entry(const void *entry_ptr, |
| 1290 | const void *data_ptr) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1291 | { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1292 | const struct tt_common_entry *tt_common_entry = entry_ptr; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1293 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1294 | if (tt_common_entry->flags & TT_CLIENT_NEW) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1295 | return 0; |
| 1296 | return 1; |
| 1297 | } |
| 1298 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1299 | static int batadv_tt_global_valid(const void *entry_ptr, |
| 1300 | const void *data_ptr) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1301 | { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1302 | const struct tt_common_entry *tt_common_entry = entry_ptr; |
| 1303 | const struct tt_global_entry *tt_global_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1304 | const struct orig_node *orig_node = data_ptr; |
| 1305 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1306 | if (tt_common_entry->flags & TT_CLIENT_ROAM) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1307 | return 0; |
| 1308 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1309 | tt_global_entry = container_of(tt_common_entry, struct tt_global_entry, |
| 1310 | common); |
| 1311 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1312 | return batadv_tt_global_entry_has_orig(tt_global_entry, orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1313 | } |
| 1314 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1315 | static struct sk_buff * |
| 1316 | batadv_tt_response_fill_table(uint16_t tt_len, uint8_t ttvn, |
| 1317 | struct hashtable_t *hash, |
| 1318 | struct hard_iface *primary_if, |
| 1319 | int (*valid_cb)(const void *, const void *), |
| 1320 | void *cb_data) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1321 | { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1322 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1323 | struct tt_query_packet *tt_response; |
| 1324 | struct tt_change *tt_change; |
| 1325 | struct hlist_node *node; |
| 1326 | struct hlist_head *head; |
| 1327 | struct sk_buff *skb = NULL; |
| 1328 | uint16_t tt_tot, tt_count; |
| 1329 | ssize_t tt_query_size = sizeof(struct tt_query_packet); |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 1330 | uint32_t i; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1331 | |
| 1332 | if (tt_query_size + tt_len > primary_if->soft_iface->mtu) { |
| 1333 | tt_len = primary_if->soft_iface->mtu - tt_query_size; |
| 1334 | tt_len -= tt_len % sizeof(struct tt_change); |
| 1335 | } |
| 1336 | tt_tot = tt_len / sizeof(struct tt_change); |
| 1337 | |
| 1338 | skb = dev_alloc_skb(tt_query_size + tt_len + ETH_HLEN); |
| 1339 | if (!skb) |
| 1340 | goto out; |
| 1341 | |
| 1342 | skb_reserve(skb, ETH_HLEN); |
| 1343 | tt_response = (struct tt_query_packet *)skb_put(skb, |
| 1344 | tt_query_size + tt_len); |
| 1345 | tt_response->ttvn = ttvn; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1346 | |
| 1347 | tt_change = (struct tt_change *)(skb->data + tt_query_size); |
| 1348 | tt_count = 0; |
| 1349 | |
| 1350 | rcu_read_lock(); |
| 1351 | for (i = 0; i < hash->size; i++) { |
| 1352 | head = &hash->table[i]; |
| 1353 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1354 | hlist_for_each_entry_rcu(tt_common_entry, node, |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1355 | head, hash_entry) { |
| 1356 | if (tt_count == tt_tot) |
| 1357 | break; |
| 1358 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1359 | if ((valid_cb) && (!valid_cb(tt_common_entry, cb_data))) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1360 | continue; |
| 1361 | |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1362 | memcpy(tt_change->addr, tt_common_entry->addr, |
| 1363 | ETH_ALEN); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1364 | tt_change->flags = NO_FLAGS; |
| 1365 | |
| 1366 | tt_count++; |
| 1367 | tt_change++; |
| 1368 | } |
| 1369 | } |
| 1370 | rcu_read_unlock(); |
| 1371 | |
Antonio Quartulli | 9d85239 | 2011-10-17 14:25:13 +0200 | [diff] [blame] | 1372 | /* store in the message the number of entries we have successfully |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1373 | * copied |
| 1374 | */ |
Antonio Quartulli | 9d85239 | 2011-10-17 14:25:13 +0200 | [diff] [blame] | 1375 | tt_response->tt_data = htons(tt_count); |
| 1376 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1377 | out: |
| 1378 | return skb; |
| 1379 | } |
| 1380 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1381 | static int batadv_send_tt_request(struct bat_priv *bat_priv, |
| 1382 | struct orig_node *dst_orig_node, |
| 1383 | uint8_t ttvn, uint16_t tt_crc, |
| 1384 | bool full_table) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1385 | { |
| 1386 | struct sk_buff *skb = NULL; |
| 1387 | struct tt_query_packet *tt_request; |
| 1388 | struct neigh_node *neigh_node = NULL; |
| 1389 | struct hard_iface *primary_if; |
| 1390 | struct tt_req_node *tt_req_node = NULL; |
| 1391 | int ret = 1; |
| 1392 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1393 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1394 | if (!primary_if) |
| 1395 | goto out; |
| 1396 | |
| 1397 | /* The new tt_req will be issued only if I'm not waiting for a |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1398 | * reply from the same orig_node yet |
| 1399 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1400 | tt_req_node = batadv_new_tt_req_node(bat_priv, dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1401 | if (!tt_req_node) |
| 1402 | goto out; |
| 1403 | |
| 1404 | skb = dev_alloc_skb(sizeof(struct tt_query_packet) + ETH_HLEN); |
| 1405 | if (!skb) |
| 1406 | goto out; |
| 1407 | |
| 1408 | skb_reserve(skb, ETH_HLEN); |
| 1409 | |
| 1410 | tt_request = (struct tt_query_packet *)skb_put(skb, |
| 1411 | sizeof(struct tt_query_packet)); |
| 1412 | |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 1413 | tt_request->header.packet_type = BAT_TT_QUERY; |
| 1414 | tt_request->header.version = COMPAT_VERSION; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1415 | memcpy(tt_request->src, primary_if->net_dev->dev_addr, ETH_ALEN); |
| 1416 | memcpy(tt_request->dst, dst_orig_node->orig, ETH_ALEN); |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 1417 | tt_request->header.ttl = TTL; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1418 | tt_request->ttvn = ttvn; |
Antonio Quartulli | 6d2003f | 2012-04-14 13:15:27 +0200 | [diff] [blame] | 1419 | tt_request->tt_data = htons(tt_crc); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1420 | tt_request->flags = TT_REQUEST; |
| 1421 | |
| 1422 | if (full_table) |
| 1423 | tt_request->flags |= TT_FULL_TABLE; |
| 1424 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1425 | neigh_node = batadv_orig_node_get_router(dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1426 | if (!neigh_node) |
| 1427 | goto out; |
| 1428 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1429 | batadv_dbg(DBG_TT, bat_priv, |
| 1430 | "Sending TT_REQUEST to %pM via %pM [%c]\n", |
| 1431 | dst_orig_node->orig, neigh_node->addr, |
| 1432 | (full_table ? 'F' : '.')); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1433 | |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 1434 | batadv_inc_counter(bat_priv, BAT_CNT_TT_REQUEST_TX); |
| 1435 | |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 1436 | batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1437 | ret = 0; |
| 1438 | |
| 1439 | out: |
| 1440 | if (neigh_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1441 | batadv_neigh_node_free_ref(neigh_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1442 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1443 | batadv_hardif_free_ref(primary_if); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1444 | if (ret) |
| 1445 | kfree_skb(skb); |
| 1446 | if (ret && tt_req_node) { |
| 1447 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 1448 | list_del(&tt_req_node->list); |
| 1449 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 1450 | kfree(tt_req_node); |
| 1451 | } |
| 1452 | return ret; |
| 1453 | } |
| 1454 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1455 | static bool batadv_send_other_tt_response(struct bat_priv *bat_priv, |
| 1456 | struct tt_query_packet *tt_request) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1457 | { |
| 1458 | struct orig_node *req_dst_orig_node = NULL, *res_dst_orig_node = NULL; |
| 1459 | struct neigh_node *neigh_node = NULL; |
| 1460 | struct hard_iface *primary_if = NULL; |
| 1461 | uint8_t orig_ttvn, req_ttvn, ttvn; |
| 1462 | int ret = false; |
| 1463 | unsigned char *tt_buff; |
| 1464 | bool full_table; |
| 1465 | uint16_t tt_len, tt_tot; |
| 1466 | struct sk_buff *skb = NULL; |
| 1467 | struct tt_query_packet *tt_response; |
| 1468 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1469 | batadv_dbg(DBG_TT, bat_priv, |
| 1470 | "Received TT_REQUEST from %pM for ttvn: %u (%pM) [%c]\n", |
| 1471 | tt_request->src, tt_request->ttvn, tt_request->dst, |
| 1472 | (tt_request->flags & TT_FULL_TABLE ? 'F' : '.')); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1473 | |
| 1474 | /* Let's get the orig node of the REAL destination */ |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 1475 | req_dst_orig_node = batadv_orig_hash_find(bat_priv, tt_request->dst); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1476 | if (!req_dst_orig_node) |
| 1477 | goto out; |
| 1478 | |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 1479 | res_dst_orig_node = batadv_orig_hash_find(bat_priv, tt_request->src); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1480 | if (!res_dst_orig_node) |
| 1481 | goto out; |
| 1482 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1483 | neigh_node = batadv_orig_node_get_router(res_dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1484 | if (!neigh_node) |
| 1485 | goto out; |
| 1486 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1487 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1488 | if (!primary_if) |
| 1489 | goto out; |
| 1490 | |
| 1491 | orig_ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn); |
| 1492 | req_ttvn = tt_request->ttvn; |
| 1493 | |
Antonio Quartulli | 015758d | 2011-07-09 17:52:13 +0200 | [diff] [blame] | 1494 | /* I don't have the requested data */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1495 | if (orig_ttvn != req_ttvn || |
Al Viro | f25bd58 | 2012-04-22 07:44:27 +0100 | [diff] [blame] | 1496 | tt_request->tt_data != htons(req_dst_orig_node->tt_crc)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1497 | goto out; |
| 1498 | |
Antonio Quartulli | 015758d | 2011-07-09 17:52:13 +0200 | [diff] [blame] | 1499 | /* If the full table has been explicitly requested */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1500 | if (tt_request->flags & TT_FULL_TABLE || |
| 1501 | !req_dst_orig_node->tt_buff) |
| 1502 | full_table = true; |
| 1503 | else |
| 1504 | full_table = false; |
| 1505 | |
| 1506 | /* In this version, fragmentation is not implemented, then |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1507 | * I'll send only one packet with as much TT entries as I can |
| 1508 | */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1509 | if (!full_table) { |
| 1510 | spin_lock_bh(&req_dst_orig_node->tt_buff_lock); |
| 1511 | tt_len = req_dst_orig_node->tt_buff_len; |
| 1512 | tt_tot = tt_len / sizeof(struct tt_change); |
| 1513 | |
| 1514 | skb = dev_alloc_skb(sizeof(struct tt_query_packet) + |
| 1515 | tt_len + ETH_HLEN); |
| 1516 | if (!skb) |
| 1517 | goto unlock; |
| 1518 | |
| 1519 | skb_reserve(skb, ETH_HLEN); |
| 1520 | tt_response = (struct tt_query_packet *)skb_put(skb, |
| 1521 | sizeof(struct tt_query_packet) + tt_len); |
| 1522 | tt_response->ttvn = req_ttvn; |
| 1523 | tt_response->tt_data = htons(tt_tot); |
| 1524 | |
| 1525 | tt_buff = skb->data + sizeof(struct tt_query_packet); |
| 1526 | /* Copy the last orig_node's OGM buffer */ |
| 1527 | memcpy(tt_buff, req_dst_orig_node->tt_buff, |
| 1528 | req_dst_orig_node->tt_buff_len); |
| 1529 | |
| 1530 | spin_unlock_bh(&req_dst_orig_node->tt_buff_lock); |
| 1531 | } else { |
| 1532 | tt_len = (uint16_t)atomic_read(&req_dst_orig_node->tt_size) * |
| 1533 | sizeof(struct tt_change); |
| 1534 | ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn); |
| 1535 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1536 | skb = batadv_tt_response_fill_table(tt_len, ttvn, |
| 1537 | bat_priv->tt_global_hash, |
| 1538 | primary_if, |
| 1539 | batadv_tt_global_valid, |
| 1540 | req_dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1541 | if (!skb) |
| 1542 | goto out; |
| 1543 | |
| 1544 | tt_response = (struct tt_query_packet *)skb->data; |
| 1545 | } |
| 1546 | |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 1547 | tt_response->header.packet_type = BAT_TT_QUERY; |
| 1548 | tt_response->header.version = COMPAT_VERSION; |
| 1549 | tt_response->header.ttl = TTL; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1550 | memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN); |
| 1551 | memcpy(tt_response->dst, tt_request->src, ETH_ALEN); |
| 1552 | tt_response->flags = TT_RESPONSE; |
| 1553 | |
| 1554 | if (full_table) |
| 1555 | tt_response->flags |= TT_FULL_TABLE; |
| 1556 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1557 | batadv_dbg(DBG_TT, bat_priv, |
| 1558 | "Sending TT_RESPONSE %pM via %pM for %pM (ttvn: %u)\n", |
| 1559 | res_dst_orig_node->orig, neigh_node->addr, |
| 1560 | req_dst_orig_node->orig, req_ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1561 | |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 1562 | batadv_inc_counter(bat_priv, BAT_CNT_TT_RESPONSE_TX); |
| 1563 | |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 1564 | batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1565 | ret = true; |
| 1566 | goto out; |
| 1567 | |
| 1568 | unlock: |
| 1569 | spin_unlock_bh(&req_dst_orig_node->tt_buff_lock); |
| 1570 | |
| 1571 | out: |
| 1572 | if (res_dst_orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1573 | batadv_orig_node_free_ref(res_dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1574 | if (req_dst_orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1575 | batadv_orig_node_free_ref(req_dst_orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1576 | if (neigh_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1577 | batadv_neigh_node_free_ref(neigh_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1578 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1579 | batadv_hardif_free_ref(primary_if); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1580 | if (!ret) |
| 1581 | kfree_skb(skb); |
| 1582 | return ret; |
| 1583 | |
| 1584 | } |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1585 | static bool batadv_send_my_tt_response(struct bat_priv *bat_priv, |
| 1586 | struct tt_query_packet *tt_request) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1587 | { |
| 1588 | struct orig_node *orig_node = NULL; |
| 1589 | struct neigh_node *neigh_node = NULL; |
| 1590 | struct hard_iface *primary_if = NULL; |
| 1591 | uint8_t my_ttvn, req_ttvn, ttvn; |
| 1592 | int ret = false; |
| 1593 | unsigned char *tt_buff; |
| 1594 | bool full_table; |
| 1595 | uint16_t tt_len, tt_tot; |
| 1596 | struct sk_buff *skb = NULL; |
| 1597 | struct tt_query_packet *tt_response; |
| 1598 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1599 | batadv_dbg(DBG_TT, bat_priv, |
| 1600 | "Received TT_REQUEST from %pM for ttvn: %u (me) [%c]\n", |
| 1601 | tt_request->src, tt_request->ttvn, |
| 1602 | (tt_request->flags & TT_FULL_TABLE ? 'F' : '.')); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1603 | |
| 1604 | |
| 1605 | my_ttvn = (uint8_t)atomic_read(&bat_priv->ttvn); |
| 1606 | req_ttvn = tt_request->ttvn; |
| 1607 | |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 1608 | orig_node = batadv_orig_hash_find(bat_priv, tt_request->src); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1609 | if (!orig_node) |
| 1610 | goto out; |
| 1611 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1612 | neigh_node = batadv_orig_node_get_router(orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1613 | if (!neigh_node) |
| 1614 | goto out; |
| 1615 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1616 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1617 | if (!primary_if) |
| 1618 | goto out; |
| 1619 | |
| 1620 | /* If the full table has been explicitly requested or the gap |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1621 | * is too big send the whole local translation table |
| 1622 | */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1623 | if (tt_request->flags & TT_FULL_TABLE || my_ttvn != req_ttvn || |
| 1624 | !bat_priv->tt_buff) |
| 1625 | full_table = true; |
| 1626 | else |
| 1627 | full_table = false; |
| 1628 | |
| 1629 | /* In this version, fragmentation is not implemented, then |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1630 | * I'll send only one packet with as much TT entries as I can |
| 1631 | */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1632 | if (!full_table) { |
| 1633 | spin_lock_bh(&bat_priv->tt_buff_lock); |
| 1634 | tt_len = bat_priv->tt_buff_len; |
| 1635 | tt_tot = tt_len / sizeof(struct tt_change); |
| 1636 | |
| 1637 | skb = dev_alloc_skb(sizeof(struct tt_query_packet) + |
| 1638 | tt_len + ETH_HLEN); |
| 1639 | if (!skb) |
| 1640 | goto unlock; |
| 1641 | |
| 1642 | skb_reserve(skb, ETH_HLEN); |
| 1643 | tt_response = (struct tt_query_packet *)skb_put(skb, |
| 1644 | sizeof(struct tt_query_packet) + tt_len); |
| 1645 | tt_response->ttvn = req_ttvn; |
| 1646 | tt_response->tt_data = htons(tt_tot); |
| 1647 | |
| 1648 | tt_buff = skb->data + sizeof(struct tt_query_packet); |
| 1649 | memcpy(tt_buff, bat_priv->tt_buff, |
| 1650 | bat_priv->tt_buff_len); |
| 1651 | spin_unlock_bh(&bat_priv->tt_buff_lock); |
| 1652 | } else { |
| 1653 | tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) * |
| 1654 | sizeof(struct tt_change); |
| 1655 | ttvn = (uint8_t)atomic_read(&bat_priv->ttvn); |
| 1656 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1657 | skb = batadv_tt_response_fill_table(tt_len, ttvn, |
| 1658 | bat_priv->tt_local_hash, |
| 1659 | primary_if, |
| 1660 | batadv_tt_local_valid_entry, |
| 1661 | NULL); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1662 | if (!skb) |
| 1663 | goto out; |
| 1664 | |
| 1665 | tt_response = (struct tt_query_packet *)skb->data; |
| 1666 | } |
| 1667 | |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 1668 | tt_response->header.packet_type = BAT_TT_QUERY; |
| 1669 | tt_response->header.version = COMPAT_VERSION; |
| 1670 | tt_response->header.ttl = TTL; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1671 | memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN); |
| 1672 | memcpy(tt_response->dst, tt_request->src, ETH_ALEN); |
| 1673 | tt_response->flags = TT_RESPONSE; |
| 1674 | |
| 1675 | if (full_table) |
| 1676 | tt_response->flags |= TT_FULL_TABLE; |
| 1677 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1678 | batadv_dbg(DBG_TT, bat_priv, |
| 1679 | "Sending TT_RESPONSE to %pM via %pM [%c]\n", |
| 1680 | orig_node->orig, neigh_node->addr, |
| 1681 | (tt_response->flags & TT_FULL_TABLE ? 'F' : '.')); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1682 | |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 1683 | batadv_inc_counter(bat_priv, BAT_CNT_TT_RESPONSE_TX); |
| 1684 | |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 1685 | batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1686 | ret = true; |
| 1687 | goto out; |
| 1688 | |
| 1689 | unlock: |
| 1690 | spin_unlock_bh(&bat_priv->tt_buff_lock); |
| 1691 | out: |
| 1692 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1693 | batadv_orig_node_free_ref(orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1694 | if (neigh_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1695 | batadv_neigh_node_free_ref(neigh_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1696 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1697 | batadv_hardif_free_ref(primary_if); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1698 | if (!ret) |
| 1699 | kfree_skb(skb); |
| 1700 | /* This packet was for me, so it doesn't need to be re-routed */ |
| 1701 | return true; |
| 1702 | } |
| 1703 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1704 | bool batadv_send_tt_response(struct bat_priv *bat_priv, |
| 1705 | struct tt_query_packet *tt_request) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1706 | { |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 1707 | if (batadv_is_my_mac(tt_request->dst)) { |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1708 | /* don't answer backbone gws! */ |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 1709 | if (batadv_bla_is_backbone_gw_orig(bat_priv, tt_request->src)) |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1710 | return true; |
| 1711 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1712 | return batadv_send_my_tt_response(bat_priv, tt_request); |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1713 | } else { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1714 | return batadv_send_other_tt_response(bat_priv, tt_request); |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1715 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1716 | } |
| 1717 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1718 | static void _batadv_tt_update_changes(struct bat_priv *bat_priv, |
| 1719 | struct orig_node *orig_node, |
| 1720 | struct tt_change *tt_change, |
| 1721 | uint16_t tt_num_changes, uint8_t ttvn) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1722 | { |
| 1723 | int i; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1724 | int is_wifi; |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1725 | int roams; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1726 | |
| 1727 | for (i = 0; i < tt_num_changes; i++) { |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1728 | if ((tt_change + i)->flags & TT_CLIENT_DEL) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1729 | roams = (tt_change + i)->flags & TT_CLIENT_ROAM; |
| 1730 | batadv_tt_global_del(bat_priv, orig_node, |
| 1731 | (tt_change + i)->addr, |
| 1732 | "tt removed by changes", |
| 1733 | roams); |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1734 | } else { |
| 1735 | is_wifi = (tt_change + i)->flags & TT_CLIENT_WIFI; |
| 1736 | if (!batadv_tt_global_add(bat_priv, orig_node, |
| 1737 | (tt_change + i)->addr, ttvn, |
| 1738 | false, is_wifi)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1739 | /* In case of problem while storing a |
| 1740 | * global_entry, we stop the updating |
| 1741 | * procedure without committing the |
| 1742 | * ttvn change. This will avoid to send |
| 1743 | * corrupted data on tt_request |
| 1744 | */ |
| 1745 | return; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1746 | } |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1747 | } |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 1748 | orig_node->tt_initialised = true; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1749 | } |
| 1750 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1751 | static void batadv_tt_fill_gtable(struct bat_priv *bat_priv, |
| 1752 | struct tt_query_packet *tt_response) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1753 | { |
| 1754 | struct orig_node *orig_node = NULL; |
| 1755 | |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 1756 | orig_node = batadv_orig_hash_find(bat_priv, tt_response->src); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1757 | if (!orig_node) |
| 1758 | goto out; |
| 1759 | |
| 1760 | /* Purge the old table first.. */ |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1761 | batadv_tt_global_del_orig(bat_priv, orig_node, "Received full table"); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1762 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1763 | _batadv_tt_update_changes(bat_priv, orig_node, |
| 1764 | (struct tt_change *)(tt_response + 1), |
| 1765 | ntohs(tt_response->tt_data), |
| 1766 | tt_response->ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1767 | |
| 1768 | spin_lock_bh(&orig_node->tt_buff_lock); |
| 1769 | kfree(orig_node->tt_buff); |
| 1770 | orig_node->tt_buff_len = 0; |
| 1771 | orig_node->tt_buff = NULL; |
| 1772 | spin_unlock_bh(&orig_node->tt_buff_lock); |
| 1773 | |
| 1774 | atomic_set(&orig_node->last_ttvn, tt_response->ttvn); |
| 1775 | |
| 1776 | out: |
| 1777 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1778 | batadv_orig_node_free_ref(orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1779 | } |
| 1780 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1781 | static void batadv_tt_update_changes(struct bat_priv *bat_priv, |
| 1782 | struct orig_node *orig_node, |
| 1783 | uint16_t tt_num_changes, uint8_t ttvn, |
| 1784 | struct tt_change *tt_change) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1785 | { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1786 | _batadv_tt_update_changes(bat_priv, orig_node, tt_change, |
| 1787 | tt_num_changes, ttvn); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1788 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1789 | batadv_tt_save_orig_buffer(bat_priv, orig_node, |
| 1790 | (unsigned char *)tt_change, tt_num_changes); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1791 | atomic_set(&orig_node->last_ttvn, ttvn); |
| 1792 | } |
| 1793 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1794 | bool batadv_is_my_client(struct bat_priv *bat_priv, const uint8_t *addr) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1795 | { |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1796 | struct tt_local_entry *tt_local_entry = NULL; |
| 1797 | bool ret = false; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1798 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1799 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, addr); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1800 | if (!tt_local_entry) |
| 1801 | goto out; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1802 | /* Check if the client has been logically deleted (but is kept for |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1803 | * consistency purpose) |
| 1804 | */ |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 1805 | if (tt_local_entry->common.flags & TT_CLIENT_PENDING) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 1806 | goto out; |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1807 | ret = true; |
| 1808 | out: |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1809 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1810 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 1811 | return ret; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1812 | } |
| 1813 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1814 | void batadv_handle_tt_response(struct bat_priv *bat_priv, |
| 1815 | struct tt_query_packet *tt_response) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1816 | { |
| 1817 | struct tt_req_node *node, *safe; |
| 1818 | struct orig_node *orig_node = NULL; |
| 1819 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1820 | batadv_dbg(DBG_TT, bat_priv, |
| 1821 | "Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n", |
| 1822 | tt_response->src, tt_response->ttvn, |
| 1823 | ntohs(tt_response->tt_data), |
| 1824 | (tt_response->flags & TT_FULL_TABLE ? 'F' : '.')); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1825 | |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1826 | /* we should have never asked a backbone gw */ |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 1827 | if (batadv_bla_is_backbone_gw_orig(bat_priv, tt_response->src)) |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1828 | goto out; |
| 1829 | |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 1830 | orig_node = batadv_orig_hash_find(bat_priv, tt_response->src); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1831 | if (!orig_node) |
| 1832 | goto out; |
| 1833 | |
| 1834 | if (tt_response->flags & TT_FULL_TABLE) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1835 | batadv_tt_fill_gtable(bat_priv, tt_response); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1836 | else |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1837 | batadv_tt_update_changes(bat_priv, orig_node, |
| 1838 | ntohs(tt_response->tt_data), |
| 1839 | tt_response->ttvn, |
| 1840 | (struct tt_change *)(tt_response + 1)); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1841 | |
| 1842 | /* Delete the tt_req_node from pending tt_requests list */ |
| 1843 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
| 1844 | list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1845 | if (!batadv_compare_eth(node->addr, tt_response->src)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1846 | continue; |
| 1847 | list_del(&node->list); |
| 1848 | kfree(node); |
| 1849 | } |
| 1850 | spin_unlock_bh(&bat_priv->tt_req_list_lock); |
| 1851 | |
| 1852 | /* Recalculate the CRC for this orig_node and store it */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1853 | orig_node->tt_crc = batadv_tt_global_crc(bat_priv, orig_node); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1854 | /* Roaming phase is over: tables are in sync again. I can |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1855 | * unset the flag |
| 1856 | */ |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1857 | orig_node->tt_poss_change = false; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1858 | out: |
| 1859 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1860 | batadv_orig_node_free_ref(orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1861 | } |
| 1862 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 1863 | int batadv_tt_init(struct bat_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1864 | { |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1865 | int ret; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1866 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1867 | ret = batadv_tt_local_init(bat_priv); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1868 | if (ret < 0) |
| 1869 | return ret; |
| 1870 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1871 | ret = batadv_tt_global_init(bat_priv); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1872 | if (ret < 0) |
| 1873 | return ret; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1874 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1875 | batadv_tt_start_timer(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1876 | |
| 1877 | return 1; |
| 1878 | } |
| 1879 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1880 | static void batadv_tt_roam_list_free(struct bat_priv *bat_priv) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1881 | { |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1882 | struct tt_roam_node *node, *safe; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1883 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1884 | spin_lock_bh(&bat_priv->tt_roam_list_lock); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 1885 | |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1886 | list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { |
| 1887 | list_del(&node->list); |
| 1888 | kfree(node); |
| 1889 | } |
| 1890 | |
| 1891 | spin_unlock_bh(&bat_priv->tt_roam_list_lock); |
| 1892 | } |
| 1893 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1894 | static void batadv_tt_roam_purge(struct bat_priv *bat_priv) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1895 | { |
| 1896 | struct tt_roam_node *node, *safe; |
| 1897 | |
| 1898 | spin_lock_bh(&bat_priv->tt_roam_list_lock); |
| 1899 | list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1900 | if (!batadv_has_timed_out(node->first_time, ROAMING_MAX_TIME)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1901 | continue; |
| 1902 | |
| 1903 | list_del(&node->list); |
| 1904 | kfree(node); |
| 1905 | } |
| 1906 | spin_unlock_bh(&bat_priv->tt_roam_list_lock); |
| 1907 | } |
| 1908 | |
| 1909 | /* This function checks whether the client already reached the |
| 1910 | * maximum number of possible roaming phases. In this case the ROAMING_ADV |
| 1911 | * will not be sent. |
| 1912 | * |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1913 | * returns true if the ROAMING_ADV can be sent, false otherwise |
| 1914 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1915 | static bool batadv_tt_check_roam_count(struct bat_priv *bat_priv, |
| 1916 | uint8_t *client) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1917 | { |
| 1918 | struct tt_roam_node *tt_roam_node; |
| 1919 | bool ret = false; |
| 1920 | |
| 1921 | spin_lock_bh(&bat_priv->tt_roam_list_lock); |
| 1922 | /* The new tt_req will be issued only if I'm not waiting for a |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1923 | * reply from the same orig_node yet |
| 1924 | */ |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1925 | list_for_each_entry(tt_roam_node, &bat_priv->tt_roam_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1926 | if (!batadv_compare_eth(tt_roam_node->addr, client)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1927 | continue; |
| 1928 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1929 | if (batadv_has_timed_out(tt_roam_node->first_time, |
| 1930 | ROAMING_MAX_TIME)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1931 | continue; |
| 1932 | |
| 1933 | if (!atomic_dec_not_zero(&tt_roam_node->counter)) |
| 1934 | /* Sorry, you roamed too many times! */ |
| 1935 | goto unlock; |
| 1936 | ret = true; |
| 1937 | break; |
| 1938 | } |
| 1939 | |
| 1940 | if (!ret) { |
| 1941 | tt_roam_node = kmalloc(sizeof(*tt_roam_node), GFP_ATOMIC); |
| 1942 | if (!tt_roam_node) |
| 1943 | goto unlock; |
| 1944 | |
| 1945 | tt_roam_node->first_time = jiffies; |
| 1946 | atomic_set(&tt_roam_node->counter, ROAMING_MAX_COUNT - 1); |
| 1947 | memcpy(tt_roam_node->addr, client, ETH_ALEN); |
| 1948 | |
| 1949 | list_add(&tt_roam_node->list, &bat_priv->tt_roam_list); |
| 1950 | ret = true; |
| 1951 | } |
| 1952 | |
| 1953 | unlock: |
| 1954 | spin_unlock_bh(&bat_priv->tt_roam_list_lock); |
| 1955 | return ret; |
| 1956 | } |
| 1957 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1958 | static void batadv_send_roam_adv(struct bat_priv *bat_priv, uint8_t *client, |
| 1959 | struct orig_node *orig_node) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1960 | { |
| 1961 | struct neigh_node *neigh_node = NULL; |
| 1962 | struct sk_buff *skb = NULL; |
| 1963 | struct roam_adv_packet *roam_adv_packet; |
| 1964 | int ret = 1; |
| 1965 | struct hard_iface *primary_if; |
| 1966 | |
| 1967 | /* before going on we have to check whether the client has |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1968 | * already roamed to us too many times |
| 1969 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 1970 | if (!batadv_tt_check_roam_count(bat_priv, client)) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1971 | goto out; |
| 1972 | |
| 1973 | skb = dev_alloc_skb(sizeof(struct roam_adv_packet) + ETH_HLEN); |
| 1974 | if (!skb) |
| 1975 | goto out; |
| 1976 | |
| 1977 | skb_reserve(skb, ETH_HLEN); |
| 1978 | |
| 1979 | roam_adv_packet = (struct roam_adv_packet *)skb_put(skb, |
| 1980 | sizeof(struct roam_adv_packet)); |
| 1981 | |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 1982 | roam_adv_packet->header.packet_type = BAT_ROAM_ADV; |
| 1983 | roam_adv_packet->header.version = COMPAT_VERSION; |
| 1984 | roam_adv_packet->header.ttl = TTL; |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1985 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1986 | if (!primary_if) |
| 1987 | goto out; |
| 1988 | memcpy(roam_adv_packet->src, primary_if->net_dev->dev_addr, ETH_ALEN); |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1989 | batadv_hardif_free_ref(primary_if); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1990 | memcpy(roam_adv_packet->dst, orig_node->orig, ETH_ALEN); |
| 1991 | memcpy(roam_adv_packet->client, client, ETH_ALEN); |
| 1992 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1993 | neigh_node = batadv_orig_node_get_router(orig_node); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 1994 | if (!neigh_node) |
| 1995 | goto out; |
| 1996 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1997 | batadv_dbg(DBG_TT, bat_priv, |
| 1998 | "Sending ROAMING_ADV to %pM (client %pM) via %pM\n", |
| 1999 | orig_node->orig, client, neigh_node->addr); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2000 | |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 2001 | batadv_inc_counter(bat_priv, BAT_CNT_TT_ROAM_ADV_TX); |
| 2002 | |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 2003 | batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2004 | ret = 0; |
| 2005 | |
| 2006 | out: |
| 2007 | if (neigh_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 2008 | batadv_neigh_node_free_ref(neigh_node); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2009 | if (ret) |
| 2010 | kfree_skb(skb); |
| 2011 | return; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2012 | } |
| 2013 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2014 | static void batadv_tt_purge(struct work_struct *work) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2015 | { |
| 2016 | struct delayed_work *delayed_work = |
| 2017 | container_of(work, struct delayed_work, work); |
| 2018 | struct bat_priv *bat_priv = |
| 2019 | container_of(delayed_work, struct bat_priv, tt_work); |
| 2020 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2021 | batadv_tt_local_purge(bat_priv); |
| 2022 | batadv_tt_global_roam_purge(bat_priv); |
| 2023 | batadv_tt_req_purge(bat_priv); |
| 2024 | batadv_tt_roam_purge(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2025 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2026 | batadv_tt_start_timer(bat_priv); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 2027 | } |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2028 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 2029 | void batadv_tt_free(struct bat_priv *bat_priv) |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2030 | { |
| 2031 | cancel_delayed_work_sync(&bat_priv->tt_work); |
| 2032 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2033 | batadv_tt_local_table_free(bat_priv); |
| 2034 | batadv_tt_global_table_free(bat_priv); |
| 2035 | batadv_tt_req_list_free(bat_priv); |
| 2036 | batadv_tt_changes_list_free(bat_priv); |
| 2037 | batadv_tt_roam_list_free(bat_priv); |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 2038 | |
| 2039 | kfree(bat_priv->tt_buff); |
| 2040 | } |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2041 | |
Antonio Quartulli | 697f253 | 2011-11-07 16:47:01 +0100 | [diff] [blame] | 2042 | /* This function will enable or disable the specified flags for all the entries |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2043 | * in the given hash table and returns the number of modified entries |
| 2044 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2045 | static uint16_t batadv_tt_set_flags(struct hashtable_t *hash, uint16_t flags, |
| 2046 | bool enable) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2047 | { |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 2048 | uint32_t i; |
Antonio Quartulli | 697f253 | 2011-11-07 16:47:01 +0100 | [diff] [blame] | 2049 | uint16_t changed_num = 0; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2050 | struct hlist_head *head; |
| 2051 | struct hlist_node *node; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2052 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2053 | |
| 2054 | if (!hash) |
Antonio Quartulli | 697f253 | 2011-11-07 16:47:01 +0100 | [diff] [blame] | 2055 | goto out; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2056 | |
| 2057 | for (i = 0; i < hash->size; i++) { |
| 2058 | head = &hash->table[i]; |
| 2059 | |
| 2060 | rcu_read_lock(); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2061 | hlist_for_each_entry_rcu(tt_common_entry, node, |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2062 | head, hash_entry) { |
Antonio Quartulli | 697f253 | 2011-11-07 16:47:01 +0100 | [diff] [blame] | 2063 | if (enable) { |
| 2064 | if ((tt_common_entry->flags & flags) == flags) |
| 2065 | continue; |
| 2066 | tt_common_entry->flags |= flags; |
| 2067 | } else { |
| 2068 | if (!(tt_common_entry->flags & flags)) |
| 2069 | continue; |
| 2070 | tt_common_entry->flags &= ~flags; |
| 2071 | } |
| 2072 | changed_num++; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2073 | } |
| 2074 | rcu_read_unlock(); |
| 2075 | } |
Antonio Quartulli | 697f253 | 2011-11-07 16:47:01 +0100 | [diff] [blame] | 2076 | out: |
| 2077 | return changed_num; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | /* Purge out all the tt local entries marked with TT_CLIENT_PENDING */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2081 | static void batadv_tt_local_purge_pending_clients(struct bat_priv *bat_priv) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2082 | { |
| 2083 | struct hashtable_t *hash = bat_priv->tt_local_hash; |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2084 | struct tt_common_entry *tt_common_entry; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2085 | struct tt_local_entry *tt_local_entry; |
| 2086 | struct hlist_node *node, *node_tmp; |
| 2087 | struct hlist_head *head; |
| 2088 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 2089 | uint32_t i; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2090 | |
| 2091 | if (!hash) |
| 2092 | return; |
| 2093 | |
| 2094 | for (i = 0; i < hash->size; i++) { |
| 2095 | head = &hash->table[i]; |
| 2096 | list_lock = &hash->list_locks[i]; |
| 2097 | |
| 2098 | spin_lock_bh(list_lock); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2099 | hlist_for_each_entry_safe(tt_common_entry, node, node_tmp, |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2100 | head, hash_entry) { |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2101 | if (!(tt_common_entry->flags & TT_CLIENT_PENDING)) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2102 | continue; |
| 2103 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2104 | batadv_dbg(DBG_TT, bat_priv, |
| 2105 | "Deleting local tt entry (%pM): pending\n", |
| 2106 | tt_common_entry->addr); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2107 | |
| 2108 | atomic_dec(&bat_priv->num_local_tt); |
| 2109 | hlist_del_rcu(node); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 2110 | tt_local_entry = container_of(tt_common_entry, |
| 2111 | struct tt_local_entry, |
| 2112 | common); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2113 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2114 | } |
| 2115 | spin_unlock_bh(list_lock); |
| 2116 | } |
| 2117 | |
| 2118 | } |
| 2119 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2120 | static int batadv_tt_commit_changes(struct bat_priv *bat_priv, |
| 2121 | unsigned char **packet_buff, |
| 2122 | int *packet_buff_len, int packet_min_len) |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2123 | { |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 2124 | uint16_t changed_num = 0; |
| 2125 | |
| 2126 | if (atomic_read(&bat_priv->tt_local_changes) < 1) |
| 2127 | return -ENOENT; |
| 2128 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2129 | changed_num = batadv_tt_set_flags(bat_priv->tt_local_hash, |
| 2130 | TT_CLIENT_NEW, false); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 2131 | |
| 2132 | /* all reset entries have to be counted as local entries */ |
Antonio Quartulli | 697f253 | 2011-11-07 16:47:01 +0100 | [diff] [blame] | 2133 | atomic_add(changed_num, &bat_priv->num_local_tt); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2134 | batadv_tt_local_purge_pending_clients(bat_priv); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 2135 | bat_priv->tt_crc = batadv_tt_local_crc(bat_priv); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2136 | |
| 2137 | /* Increment the TTVN only once per OGM interval */ |
| 2138 | atomic_inc(&bat_priv->ttvn); |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2139 | batadv_dbg(DBG_TT, bat_priv, |
| 2140 | "Local changes committed, updating to ttvn %u\n", |
| 2141 | (uint8_t)atomic_read(&bat_priv->ttvn)); |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2142 | bat_priv->tt_poss_change = false; |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 2143 | |
| 2144 | /* reset the sending counter */ |
| 2145 | atomic_set(&bat_priv->tt_ogm_append_cnt, TT_OGM_APPEND_MAX); |
| 2146 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2147 | return batadv_tt_changes_fill_buff(bat_priv, packet_buff, |
| 2148 | packet_buff_len, packet_min_len); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | /* when calling this function (hard_iface == primary_if) has to be true */ |
| 2152 | int batadv_tt_append_diff(struct bat_priv *bat_priv, |
| 2153 | unsigned char **packet_buff, int *packet_buff_len, |
| 2154 | int packet_min_len) |
| 2155 | { |
| 2156 | int tt_num_changes; |
| 2157 | |
| 2158 | /* if at least one change happened */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2159 | tt_num_changes = batadv_tt_commit_changes(bat_priv, packet_buff, |
| 2160 | packet_buff_len, |
| 2161 | packet_min_len); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 2162 | |
| 2163 | /* if the changes have been sent often enough */ |
| 2164 | if ((tt_num_changes < 0) && |
| 2165 | (!atomic_dec_not_zero(&bat_priv->tt_ogm_append_cnt))) { |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2166 | batadv_tt_realloc_packet_buff(packet_buff, packet_buff_len, |
| 2167 | packet_min_len, packet_min_len); |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 2168 | tt_num_changes = 0; |
| 2169 | } |
| 2170 | |
| 2171 | return tt_num_changes; |
Antonio Quartulli | 058d0e2 | 2011-07-07 01:40:58 +0200 | [diff] [blame] | 2172 | } |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 2173 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 2174 | bool batadv_is_ap_isolated(struct bat_priv *bat_priv, uint8_t *src, |
| 2175 | uint8_t *dst) |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 2176 | { |
| 2177 | struct tt_local_entry *tt_local_entry = NULL; |
| 2178 | struct tt_global_entry *tt_global_entry = NULL; |
| 2179 | bool ret = true; |
| 2180 | |
| 2181 | if (!atomic_read(&bat_priv->ap_isolation)) |
| 2182 | return false; |
| 2183 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2184 | tt_local_entry = batadv_tt_local_hash_find(bat_priv, dst); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 2185 | if (!tt_local_entry) |
| 2186 | goto out; |
| 2187 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2188 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, src); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 2189 | if (!tt_global_entry) |
| 2190 | goto out; |
| 2191 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2192 | if (_batadv_is_ap_isolated(tt_local_entry, tt_global_entry)) |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 2193 | goto out; |
| 2194 | |
| 2195 | ret = false; |
| 2196 | |
| 2197 | out: |
| 2198 | if (tt_global_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2199 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 2200 | if (tt_local_entry) |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2201 | batadv_tt_local_entry_free_ref(tt_local_entry); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 2202 | return ret; |
| 2203 | } |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2204 | |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 2205 | void batadv_tt_update_orig(struct bat_priv *bat_priv, |
| 2206 | struct orig_node *orig_node, |
| 2207 | const unsigned char *tt_buff, uint8_t tt_num_changes, |
| 2208 | uint8_t ttvn, uint16_t tt_crc) |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2209 | { |
| 2210 | uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn); |
| 2211 | bool full_table = true; |
| 2212 | |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 2213 | /* don't care about a backbone gateways updates. */ |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 2214 | if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig)) |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 2215 | return; |
| 2216 | |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 2217 | /* orig table not initialised AND first diff is in the OGM OR the ttvn |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2218 | * increased by one -> we can apply the attached changes |
| 2219 | */ |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 2220 | if ((!orig_node->tt_initialised && ttvn == 1) || |
| 2221 | ttvn - orig_ttvn == 1) { |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2222 | /* the OGM could not contain the changes due to their size or |
| 2223 | * because they have already been sent TT_OGM_APPEND_MAX times. |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2224 | * In this case send a tt request |
| 2225 | */ |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2226 | if (!tt_num_changes) { |
| 2227 | full_table = false; |
| 2228 | goto request_table; |
| 2229 | } |
| 2230 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2231 | batadv_tt_update_changes(bat_priv, orig_node, tt_num_changes, |
| 2232 | ttvn, (struct tt_change *)tt_buff); |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2233 | |
| 2234 | /* Even if we received the precomputed crc with the OGM, we |
| 2235 | * prefer to recompute it to spot any possible inconsistency |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2236 | * in the global table |
| 2237 | */ |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2238 | orig_node->tt_crc = batadv_tt_global_crc(bat_priv, orig_node); |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2239 | |
| 2240 | /* The ttvn alone is not enough to guarantee consistency |
| 2241 | * because a single value could represent different states |
| 2242 | * (due to the wrap around). Thus a node has to check whether |
| 2243 | * the resulting table (after applying the changes) is still |
| 2244 | * consistent or not. E.g. a node could disconnect while its |
| 2245 | * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case |
| 2246 | * checking the CRC value is mandatory to detect the |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2247 | * inconsistency |
| 2248 | */ |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2249 | if (orig_node->tt_crc != tt_crc) |
| 2250 | goto request_table; |
| 2251 | |
| 2252 | /* Roaming phase is over: tables are in sync again. I can |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2253 | * unset the flag |
| 2254 | */ |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2255 | orig_node->tt_poss_change = false; |
| 2256 | } else { |
| 2257 | /* if we missed more than one change or our tables are not |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 2258 | * in sync anymore -> request fresh tt data |
| 2259 | */ |
Antonio Quartulli | 1707157 | 2011-11-07 16:36:40 +0100 | [diff] [blame] | 2260 | if (!orig_node->tt_initialised || ttvn != orig_ttvn || |
| 2261 | orig_node->tt_crc != tt_crc) { |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2262 | request_table: |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 2263 | batadv_dbg(DBG_TT, bat_priv, |
| 2264 | "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u crc: %u last_crc: %u num_changes: %u)\n", |
| 2265 | orig_node->orig, ttvn, orig_ttvn, tt_crc, |
| 2266 | orig_node->tt_crc, tt_num_changes); |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2267 | batadv_send_tt_request(bat_priv, orig_node, ttvn, |
| 2268 | tt_crc, full_table); |
Marek Lindner | a943cac | 2011-07-30 13:10:18 +0200 | [diff] [blame] | 2269 | return; |
| 2270 | } |
| 2271 | } |
| 2272 | } |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 2273 | |
| 2274 | /* returns true whether we know that the client has moved from its old |
| 2275 | * originator to another one. This entry is kept is still kept for consistency |
| 2276 | * purposes |
| 2277 | */ |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 2278 | bool batadv_tt_global_client_is_roaming(struct bat_priv *bat_priv, |
| 2279 | uint8_t *addr) |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 2280 | { |
| 2281 | struct tt_global_entry *tt_global_entry; |
| 2282 | bool ret = false; |
| 2283 | |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2284 | tt_global_entry = batadv_tt_global_hash_find(bat_priv, addr); |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 2285 | if (!tt_global_entry) |
| 2286 | goto out; |
| 2287 | |
| 2288 | ret = tt_global_entry->common.flags & TT_CLIENT_ROAM; |
Sven Eckelmann | a513088 | 2012-05-16 20:23:16 +0200 | [diff] [blame^] | 2289 | batadv_tt_global_entry_free_ref(tt_global_entry); |
Antonio Quartulli | 3275e7c | 2012-03-16 18:03:28 +0100 | [diff] [blame] | 2290 | out: |
| 2291 | return ret; |
| 2292 | } |