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