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