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