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