Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1 | /* Copyright (C) 2008-2012 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 2 | * |
| 3 | * Simon Wunderlich |
| 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 "send.h" |
| 22 | #include "translation-table.h" |
| 23 | #include "vis.h" |
| 24 | #include "soft-interface.h" |
| 25 | #include "hard-interface.h" |
| 26 | #include "hash.h" |
| 27 | #include "originator.h" |
| 28 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 29 | #define BATADV_MAX_VIS_PACKET_SIZE 1000 |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 30 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 31 | static void batadv_start_vis_timer(struct batadv_priv *bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 32 | |
| 33 | /* free the info */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 34 | static void batadv_free_info(struct kref *ref) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 35 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 36 | struct batadv_vis_info *info; |
| 37 | struct batadv_priv *bat_priv; |
| 38 | struct batadv_recvlist_node *entry, *tmp; |
| 39 | |
| 40 | info = container_of(ref, struct batadv_vis_info, refcount); |
| 41 | bat_priv = info->bat_priv; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 42 | |
| 43 | list_del_init(&info->send_list); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 44 | spin_lock_bh(&bat_priv->vis.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 45 | list_for_each_entry_safe(entry, tmp, &info->recv_list, list) { |
| 46 | list_del(&entry->list); |
| 47 | kfree(entry); |
| 48 | } |
| 49 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 50 | spin_unlock_bh(&bat_priv->vis.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 51 | kfree_skb(info->skb_packet); |
Sven Eckelmann | dda9fc6 | 2011-01-28 18:34:06 +0100 | [diff] [blame] | 52 | kfree(info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* Compare two vis packets, used by the hashing algorithm */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 56 | static int batadv_vis_info_cmp(const struct hlist_node *node, const void *data2) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 57 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 58 | const struct batadv_vis_info *d1, *d2; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 59 | const struct batadv_vis_packet *p1, *p2; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 60 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 61 | d1 = container_of(node, struct batadv_vis_info, hash_entry); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 62 | d2 = data2; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 63 | p1 = (struct batadv_vis_packet *)d1->skb_packet->data; |
| 64 | p2 = (struct batadv_vis_packet *)d2->skb_packet->data; |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 65 | return batadv_compare_eth(p1->vis_orig, p2->vis_orig); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 68 | /* hash function to choose an entry in a hash table of given size |
| 69 | * hash algorithm from http://en.wikipedia.org/wiki/Hash_table |
| 70 | */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 71 | static uint32_t batadv_vis_info_choose(const void *data, uint32_t size) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 72 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 73 | const struct batadv_vis_info *vis_info = data; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 74 | const struct batadv_vis_packet *packet; |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 75 | const unsigned char *key; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 76 | uint32_t hash = 0; |
| 77 | size_t i; |
| 78 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 79 | packet = (struct batadv_vis_packet *)vis_info->skb_packet->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 80 | key = packet->vis_orig; |
| 81 | for (i = 0; i < ETH_ALEN; i++) { |
| 82 | hash += key[i]; |
| 83 | hash += (hash << 10); |
| 84 | hash ^= (hash >> 6); |
| 85 | } |
| 86 | |
| 87 | hash += (hash << 3); |
| 88 | hash ^= (hash >> 11); |
| 89 | hash += (hash << 15); |
| 90 | |
| 91 | return hash % size; |
| 92 | } |
| 93 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 94 | static struct batadv_vis_info * |
| 95 | batadv_vis_hash_find(struct batadv_priv *bat_priv, const void *data) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 96 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 97 | struct batadv_hashtable *hash = bat_priv->vis.hash; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 98 | struct hlist_head *head; |
| 99 | struct hlist_node *node; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 100 | struct batadv_vis_info *vis_info, *vis_info_tmp = NULL; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 101 | uint32_t index; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 102 | |
| 103 | if (!hash) |
| 104 | return NULL; |
| 105 | |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 106 | index = batadv_vis_info_choose(data, hash->size); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 107 | head = &hash->table[index]; |
| 108 | |
| 109 | rcu_read_lock(); |
| 110 | hlist_for_each_entry_rcu(vis_info, node, head, hash_entry) { |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 111 | if (!batadv_vis_info_cmp(node, data)) |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 112 | continue; |
| 113 | |
| 114 | vis_info_tmp = vis_info; |
| 115 | break; |
| 116 | } |
| 117 | rcu_read_unlock(); |
| 118 | |
| 119 | return vis_info_tmp; |
| 120 | } |
| 121 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 122 | /* insert interface to the list of interfaces of one originator, if it |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 123 | * does not already exist in the list |
| 124 | */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 125 | static void batadv_vis_data_insert_interface(const uint8_t *interface, |
| 126 | struct hlist_head *if_list, |
| 127 | bool primary) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 128 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 129 | struct batadv_if_list_entry *entry; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 130 | struct hlist_node *pos; |
| 131 | |
| 132 | hlist_for_each_entry(entry, pos, if_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 133 | if (batadv_compare_eth(entry->addr, interface)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 134 | return; |
| 135 | } |
| 136 | |
Antonio Quartulli | 015758d | 2011-07-09 17:52:13 +0200 | [diff] [blame] | 137 | /* it's a new address, add it to the list */ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 138 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 139 | if (!entry) |
| 140 | return; |
| 141 | memcpy(entry->addr, interface, ETH_ALEN); |
| 142 | entry->primary = primary; |
| 143 | hlist_add_head(&entry->list, if_list); |
| 144 | } |
| 145 | |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 146 | static void batadv_vis_data_read_prim_sec(struct seq_file *seq, |
| 147 | const struct hlist_head *if_list) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 148 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 149 | struct batadv_if_list_entry *entry; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 150 | struct hlist_node *pos; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 151 | |
| 152 | hlist_for_each_entry(entry, pos, if_list, list) { |
| 153 | if (entry->primary) |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 154 | seq_printf(seq, "PRIMARY, "); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 155 | else |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 156 | seq_printf(seq, "SEC %pM, ", entry->addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 157 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* read an entry */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 161 | static ssize_t |
| 162 | batadv_vis_data_read_entry(struct seq_file *seq, |
| 163 | const struct batadv_vis_info_entry *entry, |
| 164 | const uint8_t *src, bool primary) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 165 | { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 166 | if (primary && entry->quality == 0) |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 167 | return seq_printf(seq, "TT %pM, ", entry->dest); |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 168 | else if (batadv_compare_eth(entry->src, src)) |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 169 | return seq_printf(seq, "TQ %pM %d, ", entry->dest, |
| 170 | entry->quality); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 175 | static void |
| 176 | batadv_vis_data_insert_interfaces(struct hlist_head *list, |
| 177 | struct batadv_vis_packet *packet, |
| 178 | struct batadv_vis_info_entry *entries) |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 179 | { |
| 180 | int i; |
| 181 | |
| 182 | for (i = 0; i < packet->entries; i++) { |
| 183 | if (entries[i].quality == 0) |
| 184 | continue; |
| 185 | |
| 186 | if (batadv_compare_eth(entries[i].src, packet->vis_orig)) |
| 187 | continue; |
| 188 | |
| 189 | batadv_vis_data_insert_interface(entries[i].src, list, false); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | static void batadv_vis_data_read_entries(struct seq_file *seq, |
| 194 | struct hlist_head *list, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 195 | struct batadv_vis_packet *packet, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 196 | struct batadv_vis_info_entry *entries) |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 197 | { |
| 198 | int i; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 199 | struct batadv_if_list_entry *entry; |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 200 | struct hlist_node *pos; |
| 201 | |
| 202 | hlist_for_each_entry(entry, pos, list, list) { |
| 203 | seq_printf(seq, "%pM,", entry->addr); |
| 204 | |
| 205 | for (i = 0; i < packet->entries; i++) |
| 206 | batadv_vis_data_read_entry(seq, &entries[i], |
| 207 | entry->addr, entry->primary); |
| 208 | |
| 209 | /* add primary/secondary records */ |
| 210 | if (batadv_compare_eth(entry->addr, packet->vis_orig)) |
| 211 | batadv_vis_data_read_prim_sec(seq, list); |
| 212 | |
| 213 | seq_printf(seq, "\n"); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | static void batadv_vis_seq_print_text_bucket(struct seq_file *seq, |
| 218 | const struct hlist_head *head) |
| 219 | { |
| 220 | struct hlist_node *node; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 221 | struct batadv_vis_info *info; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 222 | struct batadv_vis_packet *packet; |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 223 | uint8_t *entries_pos; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 224 | struct batadv_vis_info_entry *entries; |
| 225 | struct batadv_if_list_entry *entry; |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 226 | struct hlist_node *pos, *n; |
| 227 | |
| 228 | HLIST_HEAD(vis_if_list); |
| 229 | |
| 230 | hlist_for_each_entry_rcu(info, node, head, hash_entry) { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 231 | packet = (struct batadv_vis_packet *)info->skb_packet->data; |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 232 | entries_pos = (uint8_t *)packet + sizeof(*packet); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 233 | entries = (struct batadv_vis_info_entry *)entries_pos; |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 234 | |
| 235 | batadv_vis_data_insert_interface(packet->vis_orig, &vis_if_list, |
| 236 | true); |
| 237 | batadv_vis_data_insert_interfaces(&vis_if_list, packet, |
| 238 | entries); |
| 239 | batadv_vis_data_read_entries(seq, &vis_if_list, packet, |
| 240 | entries); |
| 241 | |
| 242 | hlist_for_each_entry_safe(entry, pos, n, &vis_if_list, list) { |
| 243 | hlist_del(&entry->list); |
| 244 | kfree(entry); |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
Sven Eckelmann | d0f714f | 2012-05-12 02:09:41 +0200 | [diff] [blame] | 249 | int batadv_vis_seq_print_text(struct seq_file *seq, void *offset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 250 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 251 | struct batadv_hard_iface *primary_if; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 252 | struct hlist_head *head; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 253 | struct net_device *net_dev = (struct net_device *)seq->private; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 254 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 255 | struct batadv_hashtable *hash = bat_priv->vis.hash; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 256 | uint32_t i; |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 257 | int ret = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 258 | int vis_server = atomic_read(&bat_priv->vis_mode); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 259 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 260 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 261 | if (!primary_if) |
| 262 | goto out; |
| 263 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 264 | if (vis_server == BATADV_VIS_TYPE_CLIENT_UPDATE) |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 265 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 266 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 267 | spin_lock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 268 | for (i = 0; i < hash->size; i++) { |
| 269 | head = &hash->table[i]; |
Sven Eckelmann | 28afd3c | 2012-05-16 20:23:23 +0200 | [diff] [blame] | 270 | batadv_vis_seq_print_text_bucket(seq, head); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 271 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 272 | spin_unlock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 273 | |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 274 | out: |
| 275 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 276 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 277 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* add the info packet to the send list, if it was not |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 281 | * already linked in. |
| 282 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 283 | static void batadv_send_list_add(struct batadv_priv *bat_priv, |
| 284 | struct batadv_vis_info *info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 285 | { |
| 286 | if (list_empty(&info->send_list)) { |
| 287 | kref_get(&info->refcount); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 288 | list_add_tail(&info->send_list, &bat_priv->vis.send_list); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
| 292 | /* delete the info packet from the send list, if it was |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 293 | * linked in. |
| 294 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 295 | static void batadv_send_list_del(struct batadv_vis_info *info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 296 | { |
| 297 | if (!list_empty(&info->send_list)) { |
| 298 | list_del_init(&info->send_list); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 299 | kref_put(&info->refcount, batadv_free_info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
| 303 | /* tries to add one entry to the receive list. */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 304 | static void batadv_recv_list_add(struct batadv_priv *bat_priv, |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 305 | struct list_head *recv_list, const char *mac) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 306 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 307 | struct batadv_recvlist_node *entry; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 308 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 309 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 310 | if (!entry) |
| 311 | return; |
| 312 | |
| 313 | memcpy(entry->mac, mac, ETH_ALEN); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 314 | spin_lock_bh(&bat_priv->vis.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 315 | list_add_tail(&entry->list, recv_list); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 316 | spin_unlock_bh(&bat_priv->vis.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /* returns 1 if this mac is in the recv_list */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 320 | static int batadv_recv_list_is_in(struct batadv_priv *bat_priv, |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 321 | const struct list_head *recv_list, |
| 322 | const char *mac) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 323 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 324 | const struct batadv_recvlist_node *entry; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 325 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 326 | spin_lock_bh(&bat_priv->vis.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 327 | list_for_each_entry(entry, recv_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 328 | if (batadv_compare_eth(entry->mac, mac)) { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 329 | spin_unlock_bh(&bat_priv->vis.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 330 | return 1; |
| 331 | } |
| 332 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 333 | spin_unlock_bh(&bat_priv->vis.list_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | /* try to add the packet to the vis_hash. return NULL if invalid (e.g. too old, |
| 338 | * broken.. ). vis hash must be locked outside. is_new is set when the packet |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 339 | * is newer than old entries in the hash. |
| 340 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 341 | static struct batadv_vis_info * |
| 342 | batadv_add_packet(struct batadv_priv *bat_priv, |
| 343 | struct batadv_vis_packet *vis_packet, int vis_info_len, |
| 344 | int *is_new, int make_broadcast) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 345 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 346 | struct batadv_vis_info *info, *old_info; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 347 | struct batadv_vis_packet *search_packet, *old_packet; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 348 | struct batadv_vis_info search_elem; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 349 | struct batadv_vis_packet *packet; |
| 350 | struct sk_buff *tmp_skb; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 351 | int hash_added; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 352 | size_t len; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 353 | size_t max_entries; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 354 | |
| 355 | *is_new = 0; |
| 356 | /* sanity check */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 357 | if (!bat_priv->vis.hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 358 | return NULL; |
| 359 | |
| 360 | /* see if the packet is already in vis_hash */ |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 361 | search_elem.skb_packet = dev_alloc_skb(sizeof(*search_packet)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 362 | if (!search_elem.skb_packet) |
| 363 | return NULL; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 364 | len = sizeof(*search_packet); |
| 365 | tmp_skb = search_elem.skb_packet; |
| 366 | search_packet = (struct batadv_vis_packet *)skb_put(tmp_skb, len); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 367 | |
| 368 | memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 369 | old_info = batadv_vis_hash_find(bat_priv, &search_elem); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 370 | kfree_skb(search_elem.skb_packet); |
| 371 | |
| 372 | if (old_info) { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 373 | tmp_skb = old_info->skb_packet; |
| 374 | old_packet = (struct batadv_vis_packet *)tmp_skb->data; |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 375 | if (!batadv_seq_after(ntohl(vis_packet->seqno), |
| 376 | ntohl(old_packet->seqno))) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 377 | if (old_packet->seqno == vis_packet->seqno) { |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 378 | batadv_recv_list_add(bat_priv, |
| 379 | &old_info->recv_list, |
| 380 | vis_packet->sender_orig); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 381 | return old_info; |
| 382 | } else { |
| 383 | /* newer packet is already in hash. */ |
| 384 | return NULL; |
| 385 | } |
| 386 | } |
| 387 | /* remove old entry */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 388 | batadv_hash_remove(bat_priv->vis.hash, batadv_vis_info_cmp, |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 389 | batadv_vis_info_choose, old_info); |
| 390 | batadv_send_list_del(old_info); |
| 391 | kref_put(&old_info->refcount, batadv_free_info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 394 | info = kmalloc(sizeof(*info), GFP_ATOMIC); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 395 | if (!info) |
| 396 | return NULL; |
| 397 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 398 | len = sizeof(*packet) + vis_info_len; |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 399 | info->skb_packet = dev_alloc_skb(len + ETH_HLEN + NET_IP_ALIGN); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 400 | if (!info->skb_packet) { |
| 401 | kfree(info); |
| 402 | return NULL; |
| 403 | } |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 404 | skb_reserve(info->skb_packet, ETH_HLEN + NET_IP_ALIGN); |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 405 | packet = (struct batadv_vis_packet *)skb_put(info->skb_packet, len); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 406 | |
| 407 | kref_init(&info->refcount); |
| 408 | INIT_LIST_HEAD(&info->send_list); |
| 409 | INIT_LIST_HEAD(&info->recv_list); |
| 410 | info->first_seen = jiffies; |
| 411 | info->bat_priv = bat_priv; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 412 | memcpy(packet, vis_packet, len); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 413 | |
| 414 | /* initialize and add new packet. */ |
| 415 | *is_new = 1; |
| 416 | |
| 417 | /* Make it a broadcast packet, if required */ |
| 418 | if (make_broadcast) |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 419 | memcpy(packet->target_orig, batadv_broadcast_addr, ETH_ALEN); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 420 | |
| 421 | /* repair if entries is longer than packet. */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 422 | max_entries = vis_info_len / sizeof(struct batadv_vis_info_entry); |
| 423 | if (packet->entries > max_entries) |
| 424 | packet->entries = max_entries; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 425 | |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 426 | batadv_recv_list_add(bat_priv, &info->recv_list, packet->sender_orig); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 427 | |
| 428 | /* try to add it */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 429 | hash_added = batadv_hash_add(bat_priv->vis.hash, batadv_vis_info_cmp, |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 430 | batadv_vis_info_choose, info, |
| 431 | &info->hash_entry); |
Antonio Quartulli | 1a1f37d | 2011-07-10 00:36:36 +0200 | [diff] [blame] | 432 | if (hash_added != 0) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 433 | /* did not work (for some reason) */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 434 | kref_put(&info->refcount, batadv_free_info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 435 | info = NULL; |
| 436 | } |
| 437 | |
| 438 | return info; |
| 439 | } |
| 440 | |
| 441 | /* handle the server sync packet, forward if needed. */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 442 | void batadv_receive_server_sync_packet(struct batadv_priv *bat_priv, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 443 | struct batadv_vis_packet *vis_packet, |
Sven Eckelmann | d0f714f | 2012-05-12 02:09:41 +0200 | [diff] [blame] | 444 | int vis_info_len) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 445 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 446 | struct batadv_vis_info *info; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 447 | int is_new, make_broadcast; |
| 448 | int vis_server = atomic_read(&bat_priv->vis_mode); |
| 449 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 450 | make_broadcast = (vis_server == BATADV_VIS_TYPE_SERVER_SYNC); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 451 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 452 | spin_lock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 453 | info = batadv_add_packet(bat_priv, vis_packet, vis_info_len, |
| 454 | &is_new, make_broadcast); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 455 | if (!info) |
| 456 | goto end; |
| 457 | |
| 458 | /* only if we are server ourselves and packet is newer than the one in |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 459 | * hash. |
| 460 | */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 461 | if (vis_server == BATADV_VIS_TYPE_SERVER_SYNC && is_new) |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 462 | batadv_send_list_add(bat_priv, info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 463 | end: |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 464 | spin_unlock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /* handle an incoming client update packet and schedule forward if needed. */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 468 | void batadv_receive_client_update_packet(struct batadv_priv *bat_priv, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 469 | struct batadv_vis_packet *vis_packet, |
Sven Eckelmann | d0f714f | 2012-05-12 02:09:41 +0200 | [diff] [blame] | 470 | int vis_info_len) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 471 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 472 | struct batadv_vis_info *info; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 473 | struct batadv_vis_packet *packet; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 474 | int is_new; |
| 475 | int vis_server = atomic_read(&bat_priv->vis_mode); |
| 476 | int are_target = 0; |
| 477 | |
| 478 | /* clients shall not broadcast. */ |
| 479 | if (is_broadcast_ether_addr(vis_packet->target_orig)) |
| 480 | return; |
| 481 | |
| 482 | /* Are we the target for this VIS packet? */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 483 | if (vis_server == BATADV_VIS_TYPE_SERVER_SYNC && |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 484 | batadv_is_my_mac(vis_packet->target_orig)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 485 | are_target = 1; |
| 486 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 487 | spin_lock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 488 | info = batadv_add_packet(bat_priv, vis_packet, vis_info_len, |
| 489 | &is_new, are_target); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 490 | |
| 491 | if (!info) |
| 492 | goto end; |
| 493 | /* note that outdated packets will be dropped at this point. */ |
| 494 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 495 | packet = (struct batadv_vis_packet *)info->skb_packet->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 496 | |
| 497 | /* send only if we're the target server or ... */ |
| 498 | if (are_target && is_new) { |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 499 | packet->vis_type = BATADV_VIS_TYPE_SERVER_SYNC; /* upgrade! */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 500 | batadv_send_list_add(bat_priv, info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 501 | |
| 502 | /* ... we're not the recipient (and thus need to forward). */ |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 503 | } else if (!batadv_is_my_mac(packet->target_orig)) { |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 504 | batadv_send_list_add(bat_priv, info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | end: |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 508 | spin_unlock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /* Walk the originators and find the VIS server with the best tq. Set the packet |
| 512 | * address to its address and return the best_tq. |
| 513 | * |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 514 | * Must be called with the originator hash locked |
| 515 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 516 | static int batadv_find_best_vis_server(struct batadv_priv *bat_priv, |
| 517 | struct batadv_vis_info *info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 518 | { |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 519 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 520 | struct batadv_neigh_node *router; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 521 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 522 | struct hlist_head *head; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 523 | struct batadv_orig_node *orig_node; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 524 | struct batadv_vis_packet *packet; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 525 | int best_tq = -1; |
| 526 | uint32_t i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 527 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 528 | packet = (struct batadv_vis_packet *)info->skb_packet->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 529 | |
| 530 | for (i = 0; i < hash->size; i++) { |
| 531 | head = &hash->table[i]; |
| 532 | |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 533 | rcu_read_lock(); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 534 | hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 535 | router = batadv_orig_node_get_router(orig_node); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 536 | if (!router) |
| 537 | continue; |
| 538 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 539 | if ((orig_node->flags & BATADV_VIS_SERVER) && |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 540 | (router->tq_avg > best_tq)) { |
| 541 | best_tq = router->tq_avg; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 542 | memcpy(packet->target_orig, orig_node->orig, |
| 543 | ETH_ALEN); |
| 544 | } |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 545 | batadv_neigh_node_free_ref(router); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 546 | } |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 547 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | return best_tq; |
| 551 | } |
| 552 | |
| 553 | /* Return true if the vis packet is full. */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 554 | static bool batadv_vis_packet_full(const struct batadv_vis_info *info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 555 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 556 | const struct batadv_vis_packet *packet; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 557 | size_t num; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 558 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 559 | packet = (struct batadv_vis_packet *)info->skb_packet->data; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 560 | num = BATADV_MAX_VIS_PACKET_SIZE / sizeof(struct batadv_vis_info_entry); |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 561 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 562 | if (num < packet->entries + 1) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 563 | return true; |
| 564 | return false; |
| 565 | } |
| 566 | |
| 567 | /* generates a packet of own vis data, |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 568 | * returns 0 on success, -1 if no packet could be generated |
| 569 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 570 | static int batadv_generate_vis_packet(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 571 | { |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 572 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 573 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 574 | struct hlist_head *head; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 575 | struct batadv_orig_node *orig_node; |
| 576 | struct batadv_neigh_node *router; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 577 | struct batadv_vis_info *info = bat_priv->vis.my_info; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 578 | struct batadv_vis_packet *packet; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 579 | struct batadv_vis_info_entry *entry; |
| 580 | struct batadv_tt_common_entry *tt_common_entry; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 581 | uint8_t *packet_pos; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 582 | int best_tq = -1; |
| 583 | uint32_t i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 584 | |
| 585 | info->first_seen = jiffies; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 586 | packet = (struct batadv_vis_packet *)info->skb_packet->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 587 | packet->vis_type = atomic_read(&bat_priv->vis_mode); |
| 588 | |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 589 | memcpy(packet->target_orig, batadv_broadcast_addr, ETH_ALEN); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 590 | packet->header.ttl = BATADV_TTL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 591 | packet->seqno = htonl(ntohl(packet->seqno) + 1); |
| 592 | packet->entries = 0; |
Sven Eckelmann | 162d549 | 2012-06-28 11:56:52 +0200 | [diff] [blame] | 593 | packet->reserved = 0; |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 594 | skb_trim(info->skb_packet, sizeof(*packet)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 595 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 596 | if (packet->vis_type == BATADV_VIS_TYPE_CLIENT_UPDATE) { |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 597 | best_tq = batadv_find_best_vis_server(bat_priv, info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 598 | |
Marek Lindner | d007260 | 2011-01-19 20:01:44 +0000 | [diff] [blame] | 599 | if (best_tq < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 600 | return best_tq; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | for (i = 0; i < hash->size; i++) { |
| 604 | head = &hash->table[i]; |
| 605 | |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 606 | rcu_read_lock(); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 607 | hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 608 | router = batadv_orig_node_get_router(orig_node); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 609 | if (!router) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 610 | continue; |
| 611 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 612 | if (!batadv_compare_eth(router->addr, orig_node->orig)) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 613 | goto next; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 614 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 615 | if (router->if_incoming->if_status != BATADV_IF_ACTIVE) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 616 | goto next; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 617 | |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 618 | if (router->tq_avg < 1) |
| 619 | goto next; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 620 | |
| 621 | /* fill one entry into buffer. */ |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 622 | packet_pos = skb_put(info->skb_packet, sizeof(*entry)); |
| 623 | entry = (struct batadv_vis_info_entry *)packet_pos; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 624 | memcpy(entry->src, |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 625 | router->if_incoming->net_dev->dev_addr, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 626 | ETH_ALEN); |
| 627 | memcpy(entry->dest, orig_node->orig, ETH_ALEN); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 628 | entry->quality = router->tq_avg; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 629 | packet->entries++; |
| 630 | |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 631 | next: |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 632 | batadv_neigh_node_free_ref(router); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 633 | |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 634 | if (batadv_vis_packet_full(info)) |
Marek Lindner | d007260 | 2011-01-19 20:01:44 +0000 | [diff] [blame] | 635 | goto unlock; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 636 | } |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 637 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 640 | hash = bat_priv->tt.local_hash; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 641 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 642 | for (i = 0; i < hash->size; i++) { |
| 643 | head = &hash->table[i]; |
| 644 | |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 645 | rcu_read_lock(); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 646 | hlist_for_each_entry_rcu(tt_common_entry, node, head, |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 647 | hash_entry) { |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 648 | packet_pos = skb_put(info->skb_packet, sizeof(*entry)); |
| 649 | entry = (struct batadv_vis_info_entry *)packet_pos; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 650 | memset(entry->src, 0, ETH_ALEN); |
Antonio Quartulli | 48100ba | 2011-10-30 12:17:33 +0100 | [diff] [blame] | 651 | memcpy(entry->dest, tt_common_entry->addr, ETH_ALEN); |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 652 | entry->quality = 0; /* 0 means TT */ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 653 | packet->entries++; |
| 654 | |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 655 | if (batadv_vis_packet_full(info)) |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 656 | goto unlock; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 657 | } |
Antonio Quartulli | 7683fdc | 2011-04-27 14:28:07 +0200 | [diff] [blame] | 658 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 661 | return 0; |
Marek Lindner | d007260 | 2011-01-19 20:01:44 +0000 | [diff] [blame] | 662 | |
| 663 | unlock: |
| 664 | rcu_read_unlock(); |
| 665 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /* free old vis packets. Must be called with this vis_hash_lock |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 669 | * held |
| 670 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 671 | static void batadv_purge_vis_packets(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 672 | { |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 673 | uint32_t i; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 674 | struct batadv_hashtable *hash = bat_priv->vis.hash; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 675 | struct hlist_node *node, *node_tmp; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 676 | struct hlist_head *head; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 677 | struct batadv_vis_info *info; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 678 | |
| 679 | for (i = 0; i < hash->size; i++) { |
| 680 | head = &hash->table[i]; |
| 681 | |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 682 | hlist_for_each_entry_safe(info, node, node_tmp, |
| 683 | head, hash_entry) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 684 | /* never purge own data. */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 685 | if (info == bat_priv->vis.my_info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 686 | continue; |
| 687 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 688 | if (batadv_has_timed_out(info->first_seen, |
Sven Eckelmann | edbf7ff | 2012-06-03 22:19:16 +0200 | [diff] [blame] | 689 | BATADV_VIS_TIMEOUT)) { |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 690 | hlist_del(node); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 691 | batadv_send_list_del(info); |
| 692 | kref_put(&info->refcount, batadv_free_info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 698 | static void batadv_broadcast_vis_packet(struct batadv_priv *bat_priv, |
| 699 | struct batadv_vis_info *info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 700 | { |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 701 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 702 | struct hlist_node *node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 703 | struct hlist_head *head; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 704 | struct batadv_orig_node *orig_node; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 705 | struct batadv_vis_packet *packet; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 706 | struct sk_buff *skb; |
Antonio Quartulli | c90681b | 2011-10-05 17:05:25 +0200 | [diff] [blame] | 707 | uint32_t i; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 708 | |
| 709 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 710 | packet = (struct batadv_vis_packet *)info->skb_packet->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 711 | |
| 712 | /* send to all routers in range. */ |
| 713 | for (i = 0; i < hash->size; i++) { |
| 714 | head = &hash->table[i]; |
| 715 | |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 716 | rcu_read_lock(); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 717 | hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 718 | /* if it's a vis server and reachable, send it. */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 719 | if (!(orig_node->flags & BATADV_VIS_SERVER)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 720 | continue; |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 721 | |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 722 | /* don't send it if we already received the packet from |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 723 | * this node. |
| 724 | */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 725 | if (batadv_recv_list_is_in(bat_priv, &info->recv_list, |
Martin Hundebøll | bb351ba | 2012-10-16 16:13:48 +0200 | [diff] [blame] | 726 | orig_node->orig)) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 727 | continue; |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 728 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 729 | memcpy(packet->target_orig, orig_node->orig, ETH_ALEN); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 730 | skb = skb_clone(info->skb_packet, GFP_ATOMIC); |
Martin Hundebøll | bb351ba | 2012-10-16 16:13:48 +0200 | [diff] [blame] | 731 | if (!skb) |
| 732 | continue; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 733 | |
Martin Hundebøll | bb351ba | 2012-10-16 16:13:48 +0200 | [diff] [blame] | 734 | if (!batadv_send_skb_to_orig(skb, orig_node, NULL)) |
| 735 | kfree_skb(skb); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 736 | } |
Marek Lindner | fb778ea | 2011-01-19 20:01:40 +0000 | [diff] [blame] | 737 | rcu_read_unlock(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 738 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 741 | static void batadv_unicast_vis_packet(struct batadv_priv *bat_priv, |
| 742 | struct batadv_vis_info *info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 743 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 744 | struct batadv_orig_node *orig_node; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 745 | struct sk_buff *skb; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 746 | struct batadv_vis_packet *packet; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 747 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 748 | packet = (struct batadv_vis_packet *)info->skb_packet->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 749 | |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 750 | orig_node = batadv_orig_hash_find(bat_priv, packet->target_orig); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 751 | if (!orig_node) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 752 | goto out; |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 753 | |
Martin Hundebøll | bb351ba | 2012-10-16 16:13:48 +0200 | [diff] [blame] | 754 | skb = skb_clone(info->skb_packet, GFP_ATOMIC); |
| 755 | if (!skb) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 756 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 757 | |
Martin Hundebøll | bb351ba | 2012-10-16 16:13:48 +0200 | [diff] [blame] | 758 | if (!batadv_send_skb_to_orig(skb, orig_node, NULL)) |
| 759 | kfree_skb(skb); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 760 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 761 | out: |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 762 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 763 | batadv_orig_node_free_ref(orig_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 766 | /* only send one vis packet. called from batadv_send_vis_packets() */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 767 | static void batadv_send_vis_packet(struct batadv_priv *bat_priv, |
| 768 | struct batadv_vis_info *info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 769 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 770 | struct batadv_hard_iface *primary_if; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 771 | struct batadv_vis_packet *packet; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 772 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 773 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 774 | if (!primary_if) |
| 775 | goto out; |
| 776 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 777 | packet = (struct batadv_vis_packet *)info->skb_packet->data; |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 778 | if (packet->header.ttl < 2) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 779 | pr_debug("Error - can't send vis packet: ttl exceeded\n"); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 780 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 783 | memcpy(packet->sender_orig, primary_if->net_dev->dev_addr, ETH_ALEN); |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 784 | packet->header.ttl--; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 785 | |
| 786 | if (is_broadcast_ether_addr(packet->target_orig)) |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 787 | batadv_broadcast_vis_packet(bat_priv, info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 788 | else |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 789 | batadv_unicast_vis_packet(bat_priv, info); |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 790 | packet->header.ttl++; /* restore TTL */ |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 791 | |
| 792 | out: |
| 793 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 794 | batadv_hardif_free_ref(primary_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /* called from timer; send (and maybe generate) vis packet. */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 798 | static void batadv_send_vis_packets(struct work_struct *work) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 799 | { |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 800 | struct delayed_work *delayed_work; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 801 | struct batadv_priv *bat_priv; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 802 | struct batadv_priv_vis *priv_vis; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 803 | struct batadv_vis_info *info; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 804 | |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 805 | delayed_work = container_of(work, struct delayed_work, work); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 806 | priv_vis = container_of(delayed_work, struct batadv_priv_vis, work); |
| 807 | bat_priv = container_of(priv_vis, struct batadv_priv, vis); |
| 808 | spin_lock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 809 | batadv_purge_vis_packets(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 810 | |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 811 | if (batadv_generate_vis_packet(bat_priv) == 0) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 812 | /* schedule if generation was successful */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 813 | batadv_send_list_add(bat_priv, bat_priv->vis.my_info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 816 | while (!list_empty(&bat_priv->vis.send_list)) { |
| 817 | info = list_first_entry(&bat_priv->vis.send_list, |
Sven Eckelmann | 1181e1d | 2011-01-28 18:34:07 +0100 | [diff] [blame] | 818 | typeof(*info), send_list); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 819 | |
| 820 | kref_get(&info->refcount); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 821 | spin_unlock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 822 | |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 823 | batadv_send_vis_packet(bat_priv, info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 824 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 825 | spin_lock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 826 | batadv_send_list_del(info); |
| 827 | kref_put(&info->refcount, batadv_free_info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 828 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 829 | spin_unlock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 830 | batadv_start_vis_timer(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* init the vis server. this may only be called when if_list is already |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 834 | * initialized (e.g. bat0 is initialized, interfaces have been added) |
| 835 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 836 | int batadv_vis_init(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 837 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 838 | struct batadv_vis_packet *packet; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 839 | int hash_added; |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 840 | unsigned int len; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 841 | unsigned long first_seen; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 842 | struct sk_buff *tmp_skb; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 843 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 844 | if (bat_priv->vis.hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 845 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 846 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 847 | spin_lock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 848 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 849 | bat_priv->vis.hash = batadv_hash_new(256); |
| 850 | if (!bat_priv->vis.hash) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 851 | pr_err("Can't initialize vis_hash\n"); |
| 852 | goto err; |
| 853 | } |
| 854 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 855 | bat_priv->vis.my_info = kmalloc(BATADV_MAX_VIS_PACKET_SIZE, GFP_ATOMIC); |
| 856 | if (!bat_priv->vis.my_info) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 857 | goto err; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 858 | |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 859 | len = sizeof(*packet) + BATADV_MAX_VIS_PACKET_SIZE; |
| 860 | len += ETH_HLEN + NET_IP_ALIGN; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 861 | bat_priv->vis.my_info->skb_packet = dev_alloc_skb(len); |
| 862 | if (!bat_priv->vis.my_info->skb_packet) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 863 | goto free_info; |
| 864 | |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 865 | skb_reserve(bat_priv->vis.my_info->skb_packet, ETH_HLEN + NET_IP_ALIGN); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 866 | tmp_skb = bat_priv->vis.my_info->skb_packet; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 867 | packet = (struct batadv_vis_packet *)skb_put(tmp_skb, sizeof(*packet)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 868 | |
| 869 | /* prefill the vis info */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 870 | first_seen = jiffies - msecs_to_jiffies(BATADV_VIS_INTERVAL); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 871 | bat_priv->vis.my_info->first_seen = first_seen; |
| 872 | INIT_LIST_HEAD(&bat_priv->vis.my_info->recv_list); |
| 873 | INIT_LIST_HEAD(&bat_priv->vis.my_info->send_list); |
| 874 | kref_init(&bat_priv->vis.my_info->refcount); |
| 875 | bat_priv->vis.my_info->bat_priv = bat_priv; |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 876 | packet->header.version = BATADV_COMPAT_VERSION; |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 877 | packet->header.packet_type = BATADV_VIS; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 878 | packet->header.ttl = BATADV_TTL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 879 | packet->seqno = 0; |
Sven Eckelmann | 162d549 | 2012-06-28 11:56:52 +0200 | [diff] [blame] | 880 | packet->reserved = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 881 | packet->entries = 0; |
| 882 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 883 | INIT_LIST_HEAD(&bat_priv->vis.send_list); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 884 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 885 | hash_added = batadv_hash_add(bat_priv->vis.hash, batadv_vis_info_cmp, |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 886 | batadv_vis_info_choose, |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 887 | bat_priv->vis.my_info, |
| 888 | &bat_priv->vis.my_info->hash_entry); |
Antonio Quartulli | 1a1f37d | 2011-07-10 00:36:36 +0200 | [diff] [blame] | 889 | if (hash_added != 0) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 890 | pr_err("Can't add own vis packet into hash\n"); |
| 891 | /* not in hash, need to remove it manually. */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 892 | kref_put(&bat_priv->vis.my_info->refcount, batadv_free_info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 893 | goto err; |
| 894 | } |
| 895 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 896 | spin_unlock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 897 | batadv_start_vis_timer(bat_priv); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 898 | return 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 899 | |
| 900 | free_info: |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 901 | kfree(bat_priv->vis.my_info); |
| 902 | bat_priv->vis.my_info = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 903 | err: |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 904 | spin_unlock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | d0f714f | 2012-05-12 02:09:41 +0200 | [diff] [blame] | 905 | batadv_vis_quit(bat_priv); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 906 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | /* Decrease the reference count on a hash item info */ |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 910 | static void batadv_free_info_ref(struct hlist_node *node, void *arg) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 911 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 912 | struct batadv_vis_info *info; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 913 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 914 | info = container_of(node, struct batadv_vis_info, hash_entry); |
Sven Eckelmann | eaad8ad | 2012-05-16 20:23:18 +0200 | [diff] [blame] | 915 | batadv_send_list_del(info); |
| 916 | kref_put(&info->refcount, batadv_free_info); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | /* shutdown vis-server */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 920 | void batadv_vis_quit(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 921 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 922 | if (!bat_priv->vis.hash) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 923 | return; |
| 924 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 925 | cancel_delayed_work_sync(&bat_priv->vis.work); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 926 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 927 | spin_lock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 928 | /* properly remove, kill timers ... */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 929 | batadv_hash_delete(bat_priv->vis.hash, batadv_free_info_ref, NULL); |
| 930 | bat_priv->vis.hash = NULL; |
| 931 | bat_priv->vis.my_info = NULL; |
| 932 | spin_unlock_bh(&bat_priv->vis.hash_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* schedule packets for (re)transmission */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 936 | static void batadv_start_vis_timer(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 937 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 938 | INIT_DELAYED_WORK(&bat_priv->vis.work, batadv_send_vis_packets); |
| 939 | queue_delayed_work(batadv_event_workqueue, &bat_priv->vis.work, |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 940 | msecs_to_jiffies(BATADV_VIS_INTERVAL)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 941 | } |