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