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