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