Sven Eckelmann | 9f6446c | 2015-04-23 13:16:35 +0200 | [diff] [blame] | 1 | /* Copyright (C) 2011-2015 B.A.T.M.A.N. contributors: |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [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 |
Antonio Quartulli | ebf38fb | 2013-11-03 20:40:48 +0100 | [diff] [blame] | 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 18 | #include "bridge_loop_avoidance.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 19 | #include "main.h" |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 20 | |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 21 | #include <linux/atomic.h> |
| 22 | #include <linux/byteorder/generic.h> |
| 23 | #include <linux/compiler.h> |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 24 | #include <linux/crc16.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 25 | #include <linux/errno.h> |
| 26 | #include <linux/etherdevice.h> |
| 27 | #include <linux/fs.h> |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 28 | #include <linux/if_arp.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 29 | #include <linux/if_ether.h> |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 30 | #include <linux/if_vlan.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 31 | #include <linux/jhash.h> |
| 32 | #include <linux/jiffies.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/list.h> |
| 35 | #include <linux/lockdep.h> |
| 36 | #include <linux/netdevice.h> |
| 37 | #include <linux/rculist.h> |
| 38 | #include <linux/rcupdate.h> |
| 39 | #include <linux/seq_file.h> |
| 40 | #include <linux/skbuff.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/spinlock.h> |
| 43 | #include <linux/stddef.h> |
| 44 | #include <linux/string.h> |
| 45 | #include <linux/workqueue.h> |
| 46 | #include <net/arp.h> |
| 47 | |
| 48 | #include "hard-interface.h" |
| 49 | #include "hash.h" |
| 50 | #include "originator.h" |
| 51 | #include "packet.h" |
| 52 | #include "translation-table.h" |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 53 | |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 54 | static const u8 batadv_announce_mac[4] = {0x43, 0x05, 0x43, 0x05}; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 55 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 56 | static void batadv_bla_periodic_work(struct work_struct *work); |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 57 | static void |
| 58 | batadv_bla_send_announce(struct batadv_priv *bat_priv, |
| 59 | struct batadv_bla_backbone_gw *backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 60 | |
| 61 | /* return the index of the claim */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 62 | static inline u32 batadv_choose_claim(const void *data, u32 size) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 63 | { |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 64 | struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 65 | u32 hash = 0; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 66 | |
Sven Eckelmann | 36fd61c | 2015-03-01 09:46:18 +0100 | [diff] [blame] | 67 | hash = jhash(&claim->addr, sizeof(claim->addr), hash); |
| 68 | hash = jhash(&claim->vid, sizeof(claim->vid), hash); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 69 | |
| 70 | return hash % size; |
| 71 | } |
| 72 | |
| 73 | /* return the index of the backbone gateway */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 74 | static inline u32 batadv_choose_backbone_gw(const void *data, u32 size) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 75 | { |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 76 | const struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 77 | u32 hash = 0; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 78 | |
Sven Eckelmann | 36fd61c | 2015-03-01 09:46:18 +0100 | [diff] [blame] | 79 | hash = jhash(&claim->addr, sizeof(claim->addr), hash); |
| 80 | hash = jhash(&claim->vid, sizeof(claim->vid), hash); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 81 | |
| 82 | return hash % size; |
| 83 | } |
| 84 | |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 85 | /* compares address and vid of two backbone gws */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 86 | static int batadv_compare_backbone_gw(const struct hlist_node *node, |
| 87 | const void *data2) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 88 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 89 | const void *data1 = container_of(node, struct batadv_bla_backbone_gw, |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 90 | hash_entry); |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 91 | const struct batadv_bla_backbone_gw *gw1 = data1, *gw2 = data2; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 92 | |
Simon Wunderlich | c76d152 | 2012-10-15 22:38:04 +0200 | [diff] [blame] | 93 | if (!batadv_compare_eth(gw1->orig, gw2->orig)) |
| 94 | return 0; |
| 95 | |
| 96 | if (gw1->vid != gw2->vid) |
| 97 | return 0; |
| 98 | |
| 99 | return 1; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* compares address and vid of two claims */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 103 | static int batadv_compare_claim(const struct hlist_node *node, |
| 104 | const void *data2) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 105 | { |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 106 | const void *data1 = container_of(node, struct batadv_bla_claim, |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 107 | hash_entry); |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 108 | const struct batadv_bla_claim *cl1 = data1, *cl2 = data2; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 109 | |
Simon Wunderlich | c76d152 | 2012-10-15 22:38:04 +0200 | [diff] [blame] | 110 | if (!batadv_compare_eth(cl1->addr, cl2->addr)) |
| 111 | return 0; |
| 112 | |
| 113 | if (cl1->vid != cl2->vid) |
| 114 | return 0; |
| 115 | |
| 116 | return 1; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* free a backbone gw */ |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 120 | static void |
| 121 | batadv_backbone_gw_free_ref(struct batadv_bla_backbone_gw *backbone_gw) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 122 | { |
| 123 | if (atomic_dec_and_test(&backbone_gw->refcount)) |
| 124 | kfree_rcu(backbone_gw, rcu); |
| 125 | } |
| 126 | |
| 127 | /* finally deinitialize the claim */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 128 | static void batadv_claim_free_rcu(struct rcu_head *rcu) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 129 | { |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 130 | struct batadv_bla_claim *claim; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 131 | |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 132 | claim = container_of(rcu, struct batadv_bla_claim, rcu); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 133 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 134 | batadv_backbone_gw_free_ref(claim->backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 135 | kfree(claim); |
| 136 | } |
| 137 | |
| 138 | /* free a claim, call claim_free_rcu if its the last reference */ |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 139 | static void batadv_claim_free_ref(struct batadv_bla_claim *claim) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 140 | { |
| 141 | if (atomic_dec_and_test(&claim->refcount)) |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 142 | call_rcu(&claim->rcu, batadv_claim_free_rcu); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 145 | /** |
| 146 | * batadv_claim_hash_find |
| 147 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 148 | * @data: search data (may be local/static data) |
| 149 | * |
| 150 | * looks for a claim in the hash, and returns it if found |
| 151 | * or NULL otherwise. |
| 152 | */ |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 153 | static struct batadv_bla_claim |
| 154 | *batadv_claim_hash_find(struct batadv_priv *bat_priv, |
| 155 | struct batadv_bla_claim *data) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 156 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 157 | struct batadv_hashtable *hash = bat_priv->bla.claim_hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 158 | struct hlist_head *head; |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 159 | struct batadv_bla_claim *claim; |
| 160 | struct batadv_bla_claim *claim_tmp = NULL; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 161 | int index; |
| 162 | |
| 163 | if (!hash) |
| 164 | return NULL; |
| 165 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 166 | index = batadv_choose_claim(data, hash->size); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 167 | head = &hash->table[index]; |
| 168 | |
| 169 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 170 | hlist_for_each_entry_rcu(claim, head, hash_entry) { |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 171 | if (!batadv_compare_claim(&claim->hash_entry, data)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 172 | continue; |
| 173 | |
| 174 | if (!atomic_inc_not_zero(&claim->refcount)) |
| 175 | continue; |
| 176 | |
| 177 | claim_tmp = claim; |
| 178 | break; |
| 179 | } |
| 180 | rcu_read_unlock(); |
| 181 | |
| 182 | return claim_tmp; |
| 183 | } |
| 184 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 185 | /** |
| 186 | * batadv_backbone_hash_find - looks for a claim in the hash |
| 187 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 188 | * @addr: the address of the originator |
| 189 | * @vid: the VLAN ID |
| 190 | * |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 191 | * Returns claim if found or NULL otherwise. |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 192 | */ |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 193 | static struct batadv_bla_backbone_gw * |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 194 | batadv_backbone_hash_find(struct batadv_priv *bat_priv, u8 *addr, |
| 195 | unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 196 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 197 | struct batadv_hashtable *hash = bat_priv->bla.backbone_hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 198 | struct hlist_head *head; |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 199 | struct batadv_bla_backbone_gw search_entry, *backbone_gw; |
| 200 | struct batadv_bla_backbone_gw *backbone_gw_tmp = NULL; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 201 | int index; |
| 202 | |
| 203 | if (!hash) |
| 204 | return NULL; |
| 205 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 206 | ether_addr_copy(search_entry.orig, addr); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 207 | search_entry.vid = vid; |
| 208 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 209 | index = batadv_choose_backbone_gw(&search_entry, hash->size); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 210 | head = &hash->table[index]; |
| 211 | |
| 212 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 213 | hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) { |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 214 | if (!batadv_compare_backbone_gw(&backbone_gw->hash_entry, |
| 215 | &search_entry)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 216 | continue; |
| 217 | |
| 218 | if (!atomic_inc_not_zero(&backbone_gw->refcount)) |
| 219 | continue; |
| 220 | |
| 221 | backbone_gw_tmp = backbone_gw; |
| 222 | break; |
| 223 | } |
| 224 | rcu_read_unlock(); |
| 225 | |
| 226 | return backbone_gw_tmp; |
| 227 | } |
| 228 | |
| 229 | /* delete all claims for a backbone */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 230 | static void |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 231 | batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 232 | { |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 233 | struct batadv_hashtable *hash; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 234 | struct hlist_node *node_tmp; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 235 | struct hlist_head *head; |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 236 | struct batadv_bla_claim *claim; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 237 | int i; |
| 238 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
| 239 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 240 | hash = backbone_gw->bat_priv->bla.claim_hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 241 | if (!hash) |
| 242 | return; |
| 243 | |
| 244 | for (i = 0; i < hash->size; i++) { |
| 245 | head = &hash->table[i]; |
| 246 | list_lock = &hash->list_locks[i]; |
| 247 | |
| 248 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 249 | hlist_for_each_entry_safe(claim, node_tmp, |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 250 | head, hash_entry) { |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 251 | if (claim->backbone_gw != backbone_gw) |
| 252 | continue; |
| 253 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 254 | batadv_claim_free_ref(claim); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 255 | hlist_del_rcu(&claim->hash_entry); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 256 | } |
| 257 | spin_unlock_bh(list_lock); |
| 258 | } |
| 259 | |
Antonio Quartulli | 3f68785 | 2014-11-02 11:29:56 +0100 | [diff] [blame] | 260 | /* all claims gone, initialize CRC */ |
Sven Eckelmann | 3964f72 | 2012-06-03 22:19:10 +0200 | [diff] [blame] | 261 | backbone_gw->crc = BATADV_BLA_CRC_INIT; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 264 | /** |
| 265 | * batadv_bla_send_claim - sends a claim frame according to the provided info |
| 266 | * @bat_priv: the bat priv with all the soft interface information |
Martin Hundebøll | e335718 | 2014-07-15 09:41:06 +0200 | [diff] [blame] | 267 | * @mac: the mac address to be announced within the claim |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 268 | * @vid: the VLAN ID |
| 269 | * @claimtype: the type of the claim (CLAIM, UNCLAIM, ANNOUNCE, ...) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 270 | */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 271 | static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac, |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 272 | unsigned short vid, int claimtype) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 273 | { |
| 274 | struct sk_buff *skb; |
| 275 | struct ethhdr *ethhdr; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 276 | struct batadv_hard_iface *primary_if; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 277 | struct net_device *soft_iface; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 278 | u8 *hw_src; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 279 | struct batadv_bla_claim_dst local_claim_dest; |
Al Viro | 3e2f1a1 | 2012-04-22 07:47:50 +0100 | [diff] [blame] | 280 | __be32 zeroip = 0; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 281 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 282 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 283 | if (!primary_if) |
| 284 | return; |
| 285 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 286 | memcpy(&local_claim_dest, &bat_priv->bla.claim_dest, |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 287 | sizeof(local_claim_dest)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 288 | local_claim_dest.type = claimtype; |
| 289 | |
| 290 | soft_iface = primary_if->soft_iface; |
| 291 | |
| 292 | skb = arp_create(ARPOP_REPLY, ETH_P_ARP, |
| 293 | /* IP DST: 0.0.0.0 */ |
| 294 | zeroip, |
| 295 | primary_if->soft_iface, |
| 296 | /* IP SRC: 0.0.0.0 */ |
| 297 | zeroip, |
| 298 | /* Ethernet DST: Broadcast */ |
| 299 | NULL, |
| 300 | /* Ethernet SRC/HW SRC: originator mac */ |
| 301 | primary_if->net_dev->dev_addr, |
Simon Wunderlich | 99e966f | 2012-06-23 12:34:17 +0200 | [diff] [blame] | 302 | /* HW DST: FF:43:05:XX:YY:YY |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 303 | * with XX = claim type |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 304 | * and YY:YY = group id |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 305 | */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 306 | (u8 *)&local_claim_dest); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 307 | |
| 308 | if (!skb) |
| 309 | goto out; |
| 310 | |
| 311 | ethhdr = (struct ethhdr *)skb->data; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 312 | hw_src = (u8 *)ethhdr + ETH_HLEN + sizeof(struct arphdr); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 313 | |
| 314 | /* now we pretend that the client would have sent this ... */ |
| 315 | switch (claimtype) { |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 316 | case BATADV_CLAIM_TYPE_CLAIM: |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 317 | /* normal claim frame |
| 318 | * set Ethernet SRC to the clients mac |
| 319 | */ |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 320 | ether_addr_copy(ethhdr->h_source, mac); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 321 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 322 | "bla_send_claim(): CLAIM %pM on vid %d\n", mac, |
| 323 | BATADV_PRINT_VID(vid)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 324 | break; |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 325 | case BATADV_CLAIM_TYPE_UNCLAIM: |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 326 | /* unclaim frame |
| 327 | * set HW SRC to the clients mac |
| 328 | */ |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 329 | ether_addr_copy(hw_src, mac); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 330 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 331 | "bla_send_claim(): UNCLAIM %pM on vid %d\n", mac, |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 332 | BATADV_PRINT_VID(vid)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 333 | break; |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 334 | case BATADV_CLAIM_TYPE_ANNOUNCE: |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 335 | /* announcement frame |
| 336 | * set HW SRC to the special mac containg the crc |
| 337 | */ |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 338 | ether_addr_copy(hw_src, mac); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 339 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 340 | "bla_send_claim(): ANNOUNCE of %pM on vid %d\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 341 | ethhdr->h_source, BATADV_PRINT_VID(vid)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 342 | break; |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 343 | case BATADV_CLAIM_TYPE_REQUEST: |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 344 | /* request frame |
Simon Wunderlich | 99e966f | 2012-06-23 12:34:17 +0200 | [diff] [blame] | 345 | * set HW SRC and header destination to the receiving backbone |
| 346 | * gws mac |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 347 | */ |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 348 | ether_addr_copy(hw_src, mac); |
| 349 | ether_addr_copy(ethhdr->h_dest, mac); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 350 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 351 | "bla_send_claim(): REQUEST of %pM to %pM on vid %d\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 352 | ethhdr->h_source, ethhdr->h_dest, |
| 353 | BATADV_PRINT_VID(vid)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 354 | break; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 355 | } |
| 356 | |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 357 | if (vid & BATADV_VLAN_HAS_TAG) |
| 358 | skb = vlan_insert_tag(skb, htons(ETH_P_8021Q), |
| 359 | vid & VLAN_VID_MASK); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 360 | |
| 361 | skb_reset_mac_header(skb); |
| 362 | skb->protocol = eth_type_trans(skb, soft_iface); |
Marek Lindner | 1c9b055 | 2012-06-23 11:47:53 +0200 | [diff] [blame] | 363 | batadv_inc_counter(bat_priv, BATADV_CNT_RX); |
| 364 | batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES, |
| 365 | skb->len + ETH_HLEN); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 366 | soft_iface->last_rx = jiffies; |
| 367 | |
| 368 | netif_rx(skb); |
| 369 | out: |
| 370 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 371 | batadv_hardif_free_ref(primary_if); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 374 | /** |
| 375 | * batadv_bla_get_backbone_gw |
| 376 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 377 | * @orig: the mac address of the originator |
| 378 | * @vid: the VLAN ID |
Martin Hundebøll | e335718 | 2014-07-15 09:41:06 +0200 | [diff] [blame] | 379 | * @own_backbone: set if the requested backbone is local |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 380 | * |
| 381 | * searches for the backbone gw or creates a new one if it could not |
| 382 | * be found. |
| 383 | */ |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 384 | static struct batadv_bla_backbone_gw * |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 385 | batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig, |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 386 | unsigned short vid, bool own_backbone) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 387 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 388 | struct batadv_bla_backbone_gw *entry; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 389 | struct batadv_orig_node *orig_node; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 390 | int hash_added; |
| 391 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 392 | entry = batadv_backbone_hash_find(bat_priv, orig, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 393 | |
| 394 | if (entry) |
| 395 | return entry; |
| 396 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 397 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 398 | "bla_get_backbone_gw(): not found (%pM, %d), creating new entry\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 399 | orig, BATADV_PRINT_VID(vid)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 400 | |
| 401 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 402 | if (!entry) |
| 403 | return NULL; |
| 404 | |
| 405 | entry->vid = vid; |
| 406 | entry->lasttime = jiffies; |
Sven Eckelmann | 3964f72 | 2012-06-03 22:19:10 +0200 | [diff] [blame] | 407 | entry->crc = BATADV_BLA_CRC_INIT; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 408 | entry->bat_priv = bat_priv; |
| 409 | atomic_set(&entry->request_sent, 0); |
Simon Wunderlich | 2870987 | 2012-09-13 18:18:46 +0200 | [diff] [blame] | 410 | atomic_set(&entry->wait_periods, 0); |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 411 | ether_addr_copy(entry->orig, orig); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 412 | |
| 413 | /* one for the hash, one for returning */ |
| 414 | atomic_set(&entry->refcount, 2); |
| 415 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 416 | hash_added = batadv_hash_add(bat_priv->bla.backbone_hash, |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 417 | batadv_compare_backbone_gw, |
| 418 | batadv_choose_backbone_gw, entry, |
| 419 | &entry->hash_entry); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 420 | |
| 421 | if (unlikely(hash_added != 0)) { |
| 422 | /* hash failed, free the structure */ |
| 423 | kfree(entry); |
| 424 | return NULL; |
| 425 | } |
| 426 | |
Antonio Quartulli | 95fb130 | 2013-08-07 18:28:55 +0200 | [diff] [blame] | 427 | /* this is a gateway now, remove any TT entry on this VLAN */ |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 428 | orig_node = batadv_orig_hash_find(bat_priv, orig); |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 429 | if (orig_node) { |
Antonio Quartulli | 95fb130 | 2013-08-07 18:28:55 +0200 | [diff] [blame] | 430 | batadv_tt_global_del_orig(bat_priv, orig_node, vid, |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 431 | "became a backbone gateway"); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 432 | batadv_orig_node_free_ref(orig_node); |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 433 | } |
Simon Wunderlich | 52aebd6 | 2012-09-08 18:02:53 +0200 | [diff] [blame] | 434 | |
Simon Wunderlich | d807f27 | 2012-09-09 22:27:57 +0200 | [diff] [blame] | 435 | if (own_backbone) { |
Simon Wunderlich | 52aebd6 | 2012-09-08 18:02:53 +0200 | [diff] [blame] | 436 | batadv_bla_send_announce(bat_priv, entry); |
| 437 | |
Simon Wunderlich | d807f27 | 2012-09-09 22:27:57 +0200 | [diff] [blame] | 438 | /* this will be decreased in the worker thread */ |
| 439 | atomic_inc(&entry->request_sent); |
Simon Wunderlich | 2870987 | 2012-09-13 18:18:46 +0200 | [diff] [blame] | 440 | atomic_set(&entry->wait_periods, BATADV_BLA_WAIT_PERIODS); |
Simon Wunderlich | d807f27 | 2012-09-09 22:27:57 +0200 | [diff] [blame] | 441 | atomic_inc(&bat_priv->bla.num_requests); |
| 442 | } |
| 443 | |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 444 | return entry; |
| 445 | } |
| 446 | |
| 447 | /* update or add the own backbone gw to make sure we announce |
| 448 | * where we receive other backbone gws |
| 449 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 450 | static void |
| 451 | batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv, |
| 452 | struct batadv_hard_iface *primary_if, |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 453 | unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 454 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 455 | struct batadv_bla_backbone_gw *backbone_gw; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 456 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 457 | backbone_gw = batadv_bla_get_backbone_gw(bat_priv, |
| 458 | primary_if->net_dev->dev_addr, |
Simon Wunderlich | 52aebd6 | 2012-09-08 18:02:53 +0200 | [diff] [blame] | 459 | vid, true); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 460 | if (unlikely(!backbone_gw)) |
| 461 | return; |
| 462 | |
| 463 | backbone_gw->lasttime = jiffies; |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 464 | batadv_backbone_gw_free_ref(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 465 | } |
| 466 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 467 | /** |
| 468 | * batadv_bla_answer_request - answer a bla request by sending own claims |
| 469 | * @bat_priv: the bat priv with all the soft interface information |
Martin Hundebøll | e335718 | 2014-07-15 09:41:06 +0200 | [diff] [blame] | 470 | * @primary_if: interface where the request came on |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 471 | * @vid: the vid where the request came on |
| 472 | * |
| 473 | * Repeat all of our own claims, and finally send an ANNOUNCE frame |
| 474 | * to allow the requester another check if the CRC is correct now. |
| 475 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 476 | static void batadv_bla_answer_request(struct batadv_priv *bat_priv, |
| 477 | struct batadv_hard_iface *primary_if, |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 478 | unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 479 | { |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 480 | struct hlist_head *head; |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 481 | struct batadv_hashtable *hash; |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 482 | struct batadv_bla_claim *claim; |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 483 | struct batadv_bla_backbone_gw *backbone_gw; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 484 | int i; |
| 485 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 486 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 487 | "bla_answer_request(): received a claim request, send all of our own claims again\n"); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 488 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 489 | backbone_gw = batadv_backbone_hash_find(bat_priv, |
| 490 | primary_if->net_dev->dev_addr, |
| 491 | vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 492 | if (!backbone_gw) |
| 493 | return; |
| 494 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 495 | hash = bat_priv->bla.claim_hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 496 | for (i = 0; i < hash->size; i++) { |
| 497 | head = &hash->table[i]; |
| 498 | |
| 499 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 500 | hlist_for_each_entry_rcu(claim, head, hash_entry) { |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 501 | /* only own claims are interesting */ |
| 502 | if (claim->backbone_gw != backbone_gw) |
| 503 | continue; |
| 504 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 505 | batadv_bla_send_claim(bat_priv, claim->addr, claim->vid, |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 506 | BATADV_CLAIM_TYPE_CLAIM); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 507 | } |
| 508 | rcu_read_unlock(); |
| 509 | } |
| 510 | |
| 511 | /* finally, send an announcement frame */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 512 | batadv_bla_send_announce(bat_priv, backbone_gw); |
| 513 | batadv_backbone_gw_free_ref(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 516 | /** |
| 517 | * batadv_bla_send_request - send a request to repeat claims |
| 518 | * @backbone_gw: the backbone gateway from whom we are out of sync |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 519 | * |
| 520 | * When the crc is wrong, ask the backbone gateway for a full table update. |
| 521 | * After the request, it will repeat all of his own claims and finally |
| 522 | * send an announcement claim with which we can check again. |
| 523 | */ |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 524 | static void batadv_bla_send_request(struct batadv_bla_backbone_gw *backbone_gw) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 525 | { |
| 526 | /* first, remove all old entries */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 527 | batadv_bla_del_backbone_claims(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 528 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 529 | batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv, |
| 530 | "Sending REQUEST to %pM\n", backbone_gw->orig); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 531 | |
| 532 | /* send request */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 533 | batadv_bla_send_claim(backbone_gw->bat_priv, backbone_gw->orig, |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 534 | backbone_gw->vid, BATADV_CLAIM_TYPE_REQUEST); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 535 | |
| 536 | /* no local broadcasts should be sent or received, for now. */ |
| 537 | if (!atomic_read(&backbone_gw->request_sent)) { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 538 | atomic_inc(&backbone_gw->bat_priv->bla.num_requests); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 539 | atomic_set(&backbone_gw->request_sent, 1); |
| 540 | } |
| 541 | } |
| 542 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 543 | /** |
| 544 | * batadv_bla_send_announce |
| 545 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 546 | * @backbone_gw: our backbone gateway which should be announced |
| 547 | * |
| 548 | * This function sends an announcement. It is called from multiple |
| 549 | * places. |
| 550 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 551 | static void batadv_bla_send_announce(struct batadv_priv *bat_priv, |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 552 | struct batadv_bla_backbone_gw *backbone_gw) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 553 | { |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 554 | u8 mac[ETH_ALEN]; |
Al Viro | 3e2f1a1 | 2012-04-22 07:47:50 +0100 | [diff] [blame] | 555 | __be16 crc; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 556 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 557 | memcpy(mac, batadv_announce_mac, 4); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 558 | crc = htons(backbone_gw->crc); |
Al Viro | 1a5852d | 2012-04-22 07:50:29 +0100 | [diff] [blame] | 559 | memcpy(&mac[4], &crc, 2); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 560 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 561 | batadv_bla_send_claim(bat_priv, mac, backbone_gw->vid, |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 562 | BATADV_CLAIM_TYPE_ANNOUNCE); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 563 | } |
| 564 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 565 | /** |
| 566 | * batadv_bla_add_claim - Adds a claim in the claim hash |
| 567 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 568 | * @mac: the mac address of the claim |
| 569 | * @vid: the VLAN ID of the frame |
| 570 | * @backbone_gw: the backbone gateway which claims it |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 571 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 572 | static void batadv_bla_add_claim(struct batadv_priv *bat_priv, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 573 | const u8 *mac, const unsigned short vid, |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 574 | struct batadv_bla_backbone_gw *backbone_gw) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 575 | { |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 576 | struct batadv_bla_claim *claim; |
| 577 | struct batadv_bla_claim search_claim; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 578 | int hash_added; |
| 579 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 580 | ether_addr_copy(search_claim.addr, mac); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 581 | search_claim.vid = vid; |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 582 | claim = batadv_claim_hash_find(bat_priv, &search_claim); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 583 | |
| 584 | /* create a new claim entry if it does not exist yet. */ |
| 585 | if (!claim) { |
| 586 | claim = kzalloc(sizeof(*claim), GFP_ATOMIC); |
| 587 | if (!claim) |
| 588 | return; |
| 589 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 590 | ether_addr_copy(claim->addr, mac); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 591 | claim->vid = vid; |
| 592 | claim->lasttime = jiffies; |
| 593 | claim->backbone_gw = backbone_gw; |
| 594 | |
| 595 | atomic_set(&claim->refcount, 2); |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 596 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 597 | "bla_add_claim(): adding new entry %pM, vid %d to hash ...\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 598 | mac, BATADV_PRINT_VID(vid)); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 599 | hash_added = batadv_hash_add(bat_priv->bla.claim_hash, |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 600 | batadv_compare_claim, |
| 601 | batadv_choose_claim, claim, |
| 602 | &claim->hash_entry); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 603 | |
| 604 | if (unlikely(hash_added != 0)) { |
| 605 | /* only local changes happened. */ |
| 606 | kfree(claim); |
| 607 | return; |
| 608 | } |
| 609 | } else { |
| 610 | claim->lasttime = jiffies; |
| 611 | if (claim->backbone_gw == backbone_gw) |
| 612 | /* no need to register a new backbone */ |
| 613 | goto claim_free_ref; |
| 614 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 615 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 616 | "bla_add_claim(): changing ownership for %pM, vid %d\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 617 | mac, BATADV_PRINT_VID(vid)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 618 | |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 619 | claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN); |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 620 | batadv_backbone_gw_free_ref(claim->backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 621 | } |
| 622 | /* set (new) backbone gw */ |
| 623 | atomic_inc(&backbone_gw->refcount); |
| 624 | claim->backbone_gw = backbone_gw; |
| 625 | |
| 626 | backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN); |
| 627 | backbone_gw->lasttime = jiffies; |
| 628 | |
| 629 | claim_free_ref: |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 630 | batadv_claim_free_ref(claim); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* Delete a claim from the claim hash which has the |
| 634 | * given mac address and vid. |
| 635 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 636 | static void batadv_bla_del_claim(struct batadv_priv *bat_priv, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 637 | const u8 *mac, const unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 638 | { |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 639 | struct batadv_bla_claim search_claim, *claim; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 640 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 641 | ether_addr_copy(search_claim.addr, mac); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 642 | search_claim.vid = vid; |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 643 | claim = batadv_claim_hash_find(bat_priv, &search_claim); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 644 | if (!claim) |
| 645 | return; |
| 646 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 647 | batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_del_claim(): %pM, vid %d\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 648 | mac, BATADV_PRINT_VID(vid)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 649 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 650 | batadv_hash_remove(bat_priv->bla.claim_hash, batadv_compare_claim, |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 651 | batadv_choose_claim, claim); |
| 652 | batadv_claim_free_ref(claim); /* reference from the hash is gone */ |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 653 | |
| 654 | claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN); |
| 655 | |
| 656 | /* don't need the reference from hash_find() anymore */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 657 | batadv_claim_free_ref(claim); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | /* check for ANNOUNCE frame, return 1 if handled */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 661 | static int batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr, |
| 662 | u8 *backbone_addr, unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 663 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 664 | struct batadv_bla_backbone_gw *backbone_gw; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 665 | u16 crc; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 666 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 667 | if (memcmp(an_addr, batadv_announce_mac, 4) != 0) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 668 | return 0; |
| 669 | |
Simon Wunderlich | 52aebd6 | 2012-09-08 18:02:53 +0200 | [diff] [blame] | 670 | backbone_gw = batadv_bla_get_backbone_gw(bat_priv, backbone_addr, vid, |
| 671 | false); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 672 | |
| 673 | if (unlikely(!backbone_gw)) |
| 674 | return 1; |
| 675 | |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 676 | /* handle as ANNOUNCE frame */ |
| 677 | backbone_gw->lasttime = jiffies; |
Al Viro | 3e2f1a1 | 2012-04-22 07:47:50 +0100 | [diff] [blame] | 678 | crc = ntohs(*((__be16 *)(&an_addr[4]))); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 679 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 680 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Antonio Quartulli | 39a3299 | 2012-11-19 09:01:43 +0100 | [diff] [blame] | 681 | "handle_announce(): ANNOUNCE vid %d (sent by %pM)... CRC = %#.4x\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 682 | BATADV_PRINT_VID(vid), backbone_gw->orig, crc); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 683 | |
| 684 | if (backbone_gw->crc != crc) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 685 | batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv, |
Antonio Quartulli | 39a3299 | 2012-11-19 09:01:43 +0100 | [diff] [blame] | 686 | "handle_announce(): CRC FAILED for %pM/%d (my = %#.4x, sent = %#.4x)\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 687 | backbone_gw->orig, |
| 688 | BATADV_PRINT_VID(backbone_gw->vid), |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 689 | backbone_gw->crc, crc); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 690 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 691 | batadv_bla_send_request(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 692 | } else { |
| 693 | /* if we have sent a request and the crc was OK, |
| 694 | * we can allow traffic again. |
| 695 | */ |
| 696 | if (atomic_read(&backbone_gw->request_sent)) { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 697 | atomic_dec(&backbone_gw->bat_priv->bla.num_requests); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 698 | atomic_set(&backbone_gw->request_sent, 0); |
| 699 | } |
| 700 | } |
| 701 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 702 | batadv_backbone_gw_free_ref(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 703 | return 1; |
| 704 | } |
| 705 | |
| 706 | /* check for REQUEST frame, return 1 if handled */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 707 | static int batadv_handle_request(struct batadv_priv *bat_priv, |
| 708 | struct batadv_hard_iface *primary_if, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 709 | u8 *backbone_addr, struct ethhdr *ethhdr, |
| 710 | unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 711 | { |
| 712 | /* check for REQUEST frame */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 713 | if (!batadv_compare_eth(backbone_addr, ethhdr->h_dest)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 714 | return 0; |
| 715 | |
| 716 | /* sanity check, this should not happen on a normal switch, |
| 717 | * we ignore it in this case. |
| 718 | */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 719 | if (!batadv_compare_eth(ethhdr->h_dest, primary_if->net_dev->dev_addr)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 720 | return 1; |
| 721 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 722 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 723 | "handle_request(): REQUEST vid %d (sent by %pM)...\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 724 | BATADV_PRINT_VID(vid), ethhdr->h_source); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 725 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 726 | batadv_bla_answer_request(bat_priv, primary_if, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 727 | return 1; |
| 728 | } |
| 729 | |
| 730 | /* check for UNCLAIM frame, return 1 if handled */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 731 | static int batadv_handle_unclaim(struct batadv_priv *bat_priv, |
| 732 | struct batadv_hard_iface *primary_if, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 733 | u8 *backbone_addr, u8 *claim_addr, |
| 734 | unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 735 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 736 | struct batadv_bla_backbone_gw *backbone_gw; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 737 | |
| 738 | /* unclaim in any case if it is our own */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 739 | if (primary_if && batadv_compare_eth(backbone_addr, |
| 740 | primary_if->net_dev->dev_addr)) |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 741 | batadv_bla_send_claim(bat_priv, claim_addr, vid, |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 742 | BATADV_CLAIM_TYPE_UNCLAIM); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 743 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 744 | backbone_gw = batadv_backbone_hash_find(bat_priv, backbone_addr, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 745 | |
| 746 | if (!backbone_gw) |
| 747 | return 1; |
| 748 | |
| 749 | /* this must be an UNCLAIM frame */ |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 750 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 751 | "handle_unclaim(): UNCLAIM %pM on vid %d (sent by %pM)...\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 752 | claim_addr, BATADV_PRINT_VID(vid), backbone_gw->orig); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 753 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 754 | batadv_bla_del_claim(bat_priv, claim_addr, vid); |
| 755 | batadv_backbone_gw_free_ref(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 756 | return 1; |
| 757 | } |
| 758 | |
| 759 | /* check for CLAIM frame, return 1 if handled */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 760 | static int batadv_handle_claim(struct batadv_priv *bat_priv, |
| 761 | struct batadv_hard_iface *primary_if, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 762 | u8 *backbone_addr, u8 *claim_addr, |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 763 | unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 764 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 765 | struct batadv_bla_backbone_gw *backbone_gw; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 766 | |
| 767 | /* register the gateway if not yet available, and add the claim. */ |
| 768 | |
Simon Wunderlich | 52aebd6 | 2012-09-08 18:02:53 +0200 | [diff] [blame] | 769 | backbone_gw = batadv_bla_get_backbone_gw(bat_priv, backbone_addr, vid, |
| 770 | false); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 771 | |
| 772 | if (unlikely(!backbone_gw)) |
| 773 | return 1; |
| 774 | |
| 775 | /* this must be a CLAIM frame */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 776 | batadv_bla_add_claim(bat_priv, claim_addr, vid, backbone_gw); |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 777 | if (batadv_compare_eth(backbone_addr, primary_if->net_dev->dev_addr)) |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 778 | batadv_bla_send_claim(bat_priv, claim_addr, vid, |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 779 | BATADV_CLAIM_TYPE_CLAIM); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 780 | |
| 781 | /* TODO: we could call something like tt_local_del() here. */ |
| 782 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 783 | batadv_backbone_gw_free_ref(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 784 | return 1; |
| 785 | } |
| 786 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 787 | /** |
| 788 | * batadv_check_claim_group |
| 789 | * @bat_priv: the bat priv with all the soft interface information |
Martin Hundebøll | e335718 | 2014-07-15 09:41:06 +0200 | [diff] [blame] | 790 | * @primary_if: the primary interface of this batman interface |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 791 | * @hw_src: the Hardware source in the ARP Header |
| 792 | * @hw_dst: the Hardware destination in the ARP Header |
| 793 | * @ethhdr: pointer to the Ethernet header of the claim frame |
| 794 | * |
| 795 | * checks if it is a claim packet and if its on the same group. |
| 796 | * This function also applies the group ID of the sender |
| 797 | * if it is in the same mesh. |
| 798 | * |
| 799 | * returns: |
| 800 | * 2 - if it is a claim packet and on the same group |
| 801 | * 1 - if is a claim packet from another group |
| 802 | * 0 - if it is not a claim packet |
| 803 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 804 | static int batadv_check_claim_group(struct batadv_priv *bat_priv, |
| 805 | struct batadv_hard_iface *primary_if, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 806 | u8 *hw_src, u8 *hw_dst, |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 807 | struct ethhdr *ethhdr) |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 808 | { |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 809 | u8 *backbone_addr; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 810 | struct batadv_orig_node *orig_node; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 811 | struct batadv_bla_claim_dst *bla_dst, *bla_dst_own; |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 812 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 813 | bla_dst = (struct batadv_bla_claim_dst *)hw_dst; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 814 | bla_dst_own = &bat_priv->bla.claim_dest; |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 815 | |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 816 | /* if announcement packet, use the source, |
| 817 | * otherwise assume it is in the hw_src |
| 818 | */ |
| 819 | switch (bla_dst->type) { |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 820 | case BATADV_CLAIM_TYPE_CLAIM: |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 821 | backbone_addr = hw_src; |
| 822 | break; |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 823 | case BATADV_CLAIM_TYPE_REQUEST: |
| 824 | case BATADV_CLAIM_TYPE_ANNOUNCE: |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 825 | case BATADV_CLAIM_TYPE_UNCLAIM: |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 826 | backbone_addr = ethhdr->h_source; |
| 827 | break; |
| 828 | default: |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | /* don't accept claim frames from ourselves */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 833 | if (batadv_compare_eth(backbone_addr, primary_if->net_dev->dev_addr)) |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 834 | return 0; |
| 835 | |
| 836 | /* if its already the same group, it is fine. */ |
| 837 | if (bla_dst->group == bla_dst_own->group) |
| 838 | return 2; |
| 839 | |
| 840 | /* lets see if this originator is in our mesh */ |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 841 | orig_node = batadv_orig_hash_find(bat_priv, backbone_addr); |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 842 | |
| 843 | /* dont accept claims from gateways which are not in |
| 844 | * the same mesh or group. |
| 845 | */ |
| 846 | if (!orig_node) |
| 847 | return 1; |
| 848 | |
| 849 | /* if our mesh friends mac is bigger, use it for ourselves. */ |
| 850 | if (ntohs(bla_dst->group) > ntohs(bla_dst_own->group)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 851 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Antonio Quartulli | 39a3299 | 2012-11-19 09:01:43 +0100 | [diff] [blame] | 852 | "taking other backbones claim group: %#.4x\n", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 853 | ntohs(bla_dst->group)); |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 854 | bla_dst_own->group = bla_dst->group; |
| 855 | } |
| 856 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 857 | batadv_orig_node_free_ref(orig_node); |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 858 | |
| 859 | return 2; |
| 860 | } |
| 861 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 862 | /** |
| 863 | * batadv_bla_process_claim |
| 864 | * @bat_priv: the bat priv with all the soft interface information |
Martin Hundebøll | e335718 | 2014-07-15 09:41:06 +0200 | [diff] [blame] | 865 | * @primary_if: the primary hard interface of this batman soft interface |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 866 | * @skb: the frame to be checked |
| 867 | * |
| 868 | * Check if this is a claim frame, and process it accordingly. |
| 869 | * |
| 870 | * returns 1 if it was a claim frame, otherwise return 0 to |
| 871 | * tell the callee that it can use the frame on its own. |
| 872 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 873 | static int batadv_bla_process_claim(struct batadv_priv *bat_priv, |
| 874 | struct batadv_hard_iface *primary_if, |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 875 | struct sk_buff *skb) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 876 | { |
Simon Wunderlich | d46b6bf | 2014-06-23 15:55:36 +0200 | [diff] [blame] | 877 | struct batadv_bla_claim_dst *bla_dst, *bla_dst_own; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 878 | u8 *hw_src, *hw_dst; |
Simon Wunderlich | d46b6bf | 2014-06-23 15:55:36 +0200 | [diff] [blame] | 879 | struct vlan_hdr *vhdr, vhdr_buf; |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 880 | struct ethhdr *ethhdr; |
| 881 | struct arphdr *arphdr; |
| 882 | unsigned short vid; |
Simon Wunderlich | d46b6bf | 2014-06-23 15:55:36 +0200 | [diff] [blame] | 883 | int vlan_depth = 0; |
Antonio Quartulli | 293e933 | 2013-05-19 12:55:16 +0200 | [diff] [blame] | 884 | __be16 proto; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 885 | int headlen; |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 886 | int ret; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 887 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 888 | vid = batadv_get_vid(skb, 0); |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 889 | ethhdr = eth_hdr(skb); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 890 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 891 | proto = ethhdr->h_proto; |
| 892 | headlen = ETH_HLEN; |
| 893 | if (vid & BATADV_VLAN_HAS_TAG) { |
Simon Wunderlich | d46b6bf | 2014-06-23 15:55:36 +0200 | [diff] [blame] | 894 | /* Traverse the VLAN/Ethertypes. |
| 895 | * |
| 896 | * At this point it is known that the first protocol is a VLAN |
| 897 | * header, so start checking at the encapsulated protocol. |
| 898 | * |
| 899 | * The depth of the VLAN headers is recorded to drop BLA claim |
| 900 | * frames encapsulated into multiple VLAN headers (QinQ). |
| 901 | */ |
| 902 | do { |
| 903 | vhdr = skb_header_pointer(skb, headlen, VLAN_HLEN, |
| 904 | &vhdr_buf); |
| 905 | if (!vhdr) |
| 906 | return 0; |
| 907 | |
| 908 | proto = vhdr->h_vlan_encapsulated_proto; |
| 909 | headlen += VLAN_HLEN; |
| 910 | vlan_depth++; |
| 911 | } while (proto == htons(ETH_P_8021Q)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 912 | } |
| 913 | |
Antonio Quartulli | 293e933 | 2013-05-19 12:55:16 +0200 | [diff] [blame] | 914 | if (proto != htons(ETH_P_ARP)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 915 | return 0; /* not a claim frame */ |
| 916 | |
| 917 | /* this must be a ARP frame. check if it is a claim. */ |
| 918 | |
| 919 | if (unlikely(!pskb_may_pull(skb, headlen + arp_hdr_len(skb->dev)))) |
| 920 | return 0; |
| 921 | |
| 922 | /* pskb_may_pull() may have modified the pointers, get ethhdr again */ |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 923 | ethhdr = eth_hdr(skb); |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 924 | arphdr = (struct arphdr *)((u8 *)ethhdr + headlen); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 925 | |
| 926 | /* Check whether the ARP frame carries a valid |
| 927 | * IP information |
| 928 | */ |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 929 | if (arphdr->ar_hrd != htons(ARPHRD_ETHER)) |
| 930 | return 0; |
| 931 | if (arphdr->ar_pro != htons(ETH_P_IP)) |
| 932 | return 0; |
| 933 | if (arphdr->ar_hln != ETH_ALEN) |
| 934 | return 0; |
| 935 | if (arphdr->ar_pln != 4) |
| 936 | return 0; |
| 937 | |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 938 | hw_src = (u8 *)arphdr + sizeof(struct arphdr); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 939 | hw_dst = hw_src + ETH_ALEN + 4; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 940 | bla_dst = (struct batadv_bla_claim_dst *)hw_dst; |
Simon Wunderlich | d46b6bf | 2014-06-23 15:55:36 +0200 | [diff] [blame] | 941 | bla_dst_own = &bat_priv->bla.claim_dest; |
| 942 | |
| 943 | /* check if it is a claim frame in general */ |
| 944 | if (memcmp(bla_dst->magic, bla_dst_own->magic, |
| 945 | sizeof(bla_dst->magic)) != 0) |
| 946 | return 0; |
| 947 | |
| 948 | /* check if there is a claim frame encapsulated deeper in (QinQ) and |
| 949 | * drop that, as this is not supported by BLA but should also not be |
| 950 | * sent via the mesh. |
| 951 | */ |
| 952 | if (vlan_depth > 1) |
| 953 | return 1; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 954 | |
| 955 | /* check if it is a claim frame. */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 956 | ret = batadv_check_claim_group(bat_priv, primary_if, hw_src, hw_dst, |
| 957 | ethhdr); |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 958 | if (ret == 1) |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 959 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 960 | "bla_process_claim(): received a claim frame from another group. From: %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 961 | ethhdr->h_source, BATADV_PRINT_VID(vid), hw_src, |
| 962 | hw_dst); |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 963 | |
| 964 | if (ret < 2) |
| 965 | return ret; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 966 | |
| 967 | /* become a backbone gw ourselves on this vlan if not happened yet */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 968 | batadv_bla_update_own_backbone_gw(bat_priv, primary_if, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 969 | |
| 970 | /* check for the different types of claim frames ... */ |
| 971 | switch (bla_dst->type) { |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 972 | case BATADV_CLAIM_TYPE_CLAIM: |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 973 | if (batadv_handle_claim(bat_priv, primary_if, hw_src, |
| 974 | ethhdr->h_source, vid)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 975 | return 1; |
| 976 | break; |
Simon Wunderlich | 3eb8773 | 2012-06-23 12:34:18 +0200 | [diff] [blame] | 977 | case BATADV_CLAIM_TYPE_UNCLAIM: |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 978 | if (batadv_handle_unclaim(bat_priv, primary_if, |
| 979 | ethhdr->h_source, hw_src, vid)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 980 | return 1; |
| 981 | break; |
| 982 | |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 983 | case BATADV_CLAIM_TYPE_ANNOUNCE: |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 984 | if (batadv_handle_announce(bat_priv, hw_src, ethhdr->h_source, |
| 985 | vid)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 986 | return 1; |
| 987 | break; |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 988 | case BATADV_CLAIM_TYPE_REQUEST: |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 989 | if (batadv_handle_request(bat_priv, primary_if, hw_src, ethhdr, |
| 990 | vid)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 991 | return 1; |
| 992 | break; |
| 993 | } |
| 994 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 995 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 996 | "bla_process_claim(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 997 | ethhdr->h_source, BATADV_PRINT_VID(vid), hw_src, hw_dst); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 998 | return 1; |
| 999 | } |
| 1000 | |
| 1001 | /* Check when we last heard from other nodes, and remove them in case of |
| 1002 | * a time out, or clean all backbone gws if now is set. |
| 1003 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1004 | static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1005 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 1006 | struct batadv_bla_backbone_gw *backbone_gw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1007 | struct hlist_node *node_tmp; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1008 | struct hlist_head *head; |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 1009 | struct batadv_hashtable *hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1010 | spinlock_t *list_lock; /* protects write access to the hash lists */ |
| 1011 | int i; |
| 1012 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1013 | hash = bat_priv->bla.backbone_hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1014 | if (!hash) |
| 1015 | return; |
| 1016 | |
| 1017 | for (i = 0; i < hash->size; i++) { |
| 1018 | head = &hash->table[i]; |
| 1019 | list_lock = &hash->list_locks[i]; |
| 1020 | |
| 1021 | spin_lock_bh(list_lock); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1022 | hlist_for_each_entry_safe(backbone_gw, node_tmp, |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1023 | head, hash_entry) { |
| 1024 | if (now) |
| 1025 | goto purge_now; |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1026 | if (!batadv_has_timed_out(backbone_gw->lasttime, |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1027 | BATADV_BLA_BACKBONE_TIMEOUT)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1028 | continue; |
| 1029 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1030 | batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1031 | "bla_purge_backbone_gw(): backbone gw %pM timed out\n", |
| 1032 | backbone_gw->orig); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1033 | |
| 1034 | purge_now: |
| 1035 | /* don't wait for the pending request anymore */ |
| 1036 | if (atomic_read(&backbone_gw->request_sent)) |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1037 | atomic_dec(&bat_priv->bla.num_requests); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1038 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1039 | batadv_bla_del_backbone_claims(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1040 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1041 | hlist_del_rcu(&backbone_gw->hash_entry); |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1042 | batadv_backbone_gw_free_ref(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1043 | } |
| 1044 | spin_unlock_bh(list_lock); |
| 1045 | } |
| 1046 | } |
| 1047 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 1048 | /** |
| 1049 | * batadv_bla_purge_claims |
| 1050 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1051 | * @primary_if: the selected primary interface, may be NULL if now is set |
| 1052 | * @now: whether the whole hash shall be wiped now |
| 1053 | * |
| 1054 | * Check when we heard last time from our own claims, and remove them in case of |
| 1055 | * a time out, or clean all claims if now is set |
| 1056 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1057 | static void batadv_bla_purge_claims(struct batadv_priv *bat_priv, |
| 1058 | struct batadv_hard_iface *primary_if, |
| 1059 | int now) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1060 | { |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 1061 | struct batadv_bla_claim *claim; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1062 | struct hlist_head *head; |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 1063 | struct batadv_hashtable *hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1064 | int i; |
| 1065 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1066 | hash = bat_priv->bla.claim_hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1067 | if (!hash) |
| 1068 | return; |
| 1069 | |
| 1070 | for (i = 0; i < hash->size; i++) { |
| 1071 | head = &hash->table[i]; |
| 1072 | |
| 1073 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1074 | hlist_for_each_entry_rcu(claim, head, hash_entry) { |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1075 | if (now) |
| 1076 | goto purge_now; |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1077 | if (!batadv_compare_eth(claim->backbone_gw->orig, |
| 1078 | primary_if->net_dev->dev_addr)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1079 | continue; |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1080 | if (!batadv_has_timed_out(claim->lasttime, |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1081 | BATADV_BLA_CLAIM_TIMEOUT)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1082 | continue; |
| 1083 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1084 | batadv_dbg(BATADV_DBG_BLA, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1085 | "bla_purge_claims(): %pM, vid %d, time out\n", |
| 1086 | claim->addr, claim->vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1087 | |
| 1088 | purge_now: |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1089 | batadv_handle_unclaim(bat_priv, primary_if, |
| 1090 | claim->backbone_gw->orig, |
| 1091 | claim->addr, claim->vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1092 | } |
| 1093 | rcu_read_unlock(); |
| 1094 | } |
| 1095 | } |
| 1096 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 1097 | /** |
| 1098 | * batadv_bla_update_orig_address |
| 1099 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1100 | * @primary_if: the new selected primary_if |
| 1101 | * @oldif: the old primary interface, may be NULL |
| 1102 | * |
| 1103 | * Update the backbone gateways when the own orig address changes. |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1104 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1105 | void batadv_bla_update_orig_address(struct batadv_priv *bat_priv, |
| 1106 | struct batadv_hard_iface *primary_if, |
| 1107 | struct batadv_hard_iface *oldif) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1108 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 1109 | struct batadv_bla_backbone_gw *backbone_gw; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1110 | struct hlist_head *head; |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 1111 | struct batadv_hashtable *hash; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1112 | __be16 group; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1113 | int i; |
| 1114 | |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 1115 | /* reset bridge loop avoidance group id */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1116 | group = htons(crc16(0, primary_if->net_dev->dev_addr, ETH_ALEN)); |
| 1117 | bat_priv->bla.claim_dest.group = group; |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 1118 | |
Simon Wunderlich | d5b4c93 | 2013-06-07 16:52:05 +0200 | [diff] [blame] | 1119 | /* purge everything when bridge loop avoidance is turned off */ |
| 1120 | if (!atomic_read(&bat_priv->bridge_loop_avoidance)) |
| 1121 | oldif = NULL; |
| 1122 | |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1123 | if (!oldif) { |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1124 | batadv_bla_purge_claims(bat_priv, NULL, 1); |
| 1125 | batadv_bla_purge_backbone_gw(bat_priv, 1); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1126 | return; |
| 1127 | } |
| 1128 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1129 | hash = bat_priv->bla.backbone_hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1130 | if (!hash) |
| 1131 | return; |
| 1132 | |
| 1133 | for (i = 0; i < hash->size; i++) { |
| 1134 | head = &hash->table[i]; |
| 1135 | |
| 1136 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1137 | hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) { |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1138 | /* own orig still holds the old value. */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1139 | if (!batadv_compare_eth(backbone_gw->orig, |
| 1140 | oldif->net_dev->dev_addr)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1141 | continue; |
| 1142 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 1143 | ether_addr_copy(backbone_gw->orig, |
| 1144 | primary_if->net_dev->dev_addr); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1145 | /* send an announce frame so others will ask for our |
| 1146 | * claims and update their tables. |
| 1147 | */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1148 | batadv_bla_send_announce(bat_priv, backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1149 | } |
| 1150 | rcu_read_unlock(); |
| 1151 | } |
| 1152 | } |
| 1153 | |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1154 | /* periodic work to do: |
| 1155 | * * purge structures when they are too old |
| 1156 | * * send announcements |
| 1157 | */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1158 | static void batadv_bla_periodic_work(struct work_struct *work) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1159 | { |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 1160 | struct delayed_work *delayed_work; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1161 | struct batadv_priv *bat_priv; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1162 | struct batadv_priv_bla *priv_bla; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1163 | struct hlist_head *head; |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 1164 | struct batadv_bla_backbone_gw *backbone_gw; |
Sven Eckelmann | 5bf74e9 | 2012-06-05 22:31:28 +0200 | [diff] [blame] | 1165 | struct batadv_hashtable *hash; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1166 | struct batadv_hard_iface *primary_if; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1167 | int i; |
| 1168 | |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 1169 | delayed_work = container_of(work, struct delayed_work, work); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1170 | priv_bla = container_of(delayed_work, struct batadv_priv_bla, work); |
| 1171 | bat_priv = container_of(priv_bla, struct batadv_priv, bla); |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1172 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1173 | if (!primary_if) |
| 1174 | goto out; |
| 1175 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1176 | batadv_bla_purge_claims(bat_priv, primary_if, 0); |
| 1177 | batadv_bla_purge_backbone_gw(bat_priv, 0); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1178 | |
| 1179 | if (!atomic_read(&bat_priv->bridge_loop_avoidance)) |
| 1180 | goto out; |
| 1181 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1182 | hash = bat_priv->bla.backbone_hash; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1183 | if (!hash) |
| 1184 | goto out; |
| 1185 | |
| 1186 | for (i = 0; i < hash->size; i++) { |
| 1187 | head = &hash->table[i]; |
| 1188 | |
| 1189 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1190 | hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1191 | if (!batadv_compare_eth(backbone_gw->orig, |
| 1192 | primary_if->net_dev->dev_addr)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1193 | continue; |
| 1194 | |
| 1195 | backbone_gw->lasttime = jiffies; |
| 1196 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1197 | batadv_bla_send_announce(bat_priv, backbone_gw); |
Simon Wunderlich | d807f27 | 2012-09-09 22:27:57 +0200 | [diff] [blame] | 1198 | |
| 1199 | /* request_sent is only set after creation to avoid |
| 1200 | * problems when we are not yet known as backbone gw |
| 1201 | * in the backbone. |
| 1202 | * |
Simon Wunderlich | 2870987 | 2012-09-13 18:18:46 +0200 | [diff] [blame] | 1203 | * We can reset this now after we waited some periods |
| 1204 | * to give bridge forward delays and bla group forming |
| 1205 | * some grace time. |
Simon Wunderlich | d807f27 | 2012-09-09 22:27:57 +0200 | [diff] [blame] | 1206 | */ |
| 1207 | |
| 1208 | if (atomic_read(&backbone_gw->request_sent) == 0) |
| 1209 | continue; |
| 1210 | |
Simon Wunderlich | 2870987 | 2012-09-13 18:18:46 +0200 | [diff] [blame] | 1211 | if (!atomic_dec_and_test(&backbone_gw->wait_periods)) |
| 1212 | continue; |
| 1213 | |
Simon Wunderlich | d807f27 | 2012-09-09 22:27:57 +0200 | [diff] [blame] | 1214 | atomic_dec(&backbone_gw->bat_priv->bla.num_requests); |
| 1215 | atomic_set(&backbone_gw->request_sent, 0); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1216 | } |
| 1217 | rcu_read_unlock(); |
| 1218 | } |
| 1219 | out: |
| 1220 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1221 | batadv_hardif_free_ref(primary_if); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1222 | |
Antonio Quartulli | 7241444 | 2012-12-25 13:14:37 +0100 | [diff] [blame] | 1223 | queue_delayed_work(batadv_event_workqueue, &bat_priv->bla.work, |
| 1224 | msecs_to_jiffies(BATADV_BLA_PERIOD_LENGTH)); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1225 | } |
| 1226 | |
Sven Eckelmann | 5d52dad | 2012-03-29 12:38:20 +0200 | [diff] [blame] | 1227 | /* The hash for claim and backbone hash receive the same key because they |
| 1228 | * are getting initialized by hash_new with the same key. Reinitializing |
| 1229 | * them with to different keys to allow nested locking without generating |
| 1230 | * lockdep warnings |
| 1231 | */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1232 | static struct lock_class_key batadv_claim_hash_lock_class_key; |
| 1233 | static struct lock_class_key batadv_backbone_hash_lock_class_key; |
Sven Eckelmann | 5d52dad | 2012-03-29 12:38:20 +0200 | [diff] [blame] | 1234 | |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1235 | /* initialize all bla structures */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1236 | int batadv_bla_init(struct batadv_priv *bat_priv) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1237 | { |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1238 | int i; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 1239 | u8 claim_dest[ETH_ALEN] = {0xff, 0x43, 0x05, 0x00, 0x00, 0x00}; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1240 | struct batadv_hard_iface *primary_if; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 1241 | u16 crc; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1242 | unsigned long entrytime; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1243 | |
Linus Lüssing | 7dac7b7 | 2012-10-17 14:53:05 +0200 | [diff] [blame] | 1244 | spin_lock_init(&bat_priv->bla.bcast_duplist_lock); |
| 1245 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1246 | batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla hash registering\n"); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1247 | |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 1248 | /* setting claim destination address */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1249 | memcpy(&bat_priv->bla.claim_dest.magic, claim_dest, 3); |
| 1250 | bat_priv->bla.claim_dest.type = 0; |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1251 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 1252 | if (primary_if) { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1253 | crc = crc16(0, primary_if->net_dev->dev_addr, ETH_ALEN); |
| 1254 | bat_priv->bla.claim_dest.group = htons(crc); |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1255 | batadv_hardif_free_ref(primary_if); |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 1256 | } else { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1257 | bat_priv->bla.claim_dest.group = 0; /* will be set later */ |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 1258 | } |
| 1259 | |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1260 | /* initialize the duplicate list */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1261 | entrytime = jiffies - msecs_to_jiffies(BATADV_DUPLIST_TIMEOUT); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1262 | for (i = 0; i < BATADV_DUPLIST_SIZE; i++) |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1263 | bat_priv->bla.bcast_duplist[i].entrytime = entrytime; |
| 1264 | bat_priv->bla.bcast_duplist_curr = 0; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1265 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1266 | if (bat_priv->bla.claim_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1267 | return 0; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1268 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1269 | bat_priv->bla.claim_hash = batadv_hash_new(128); |
| 1270 | bat_priv->bla.backbone_hash = batadv_hash_new(32); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1271 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1272 | if (!bat_priv->bla.claim_hash || !bat_priv->bla.backbone_hash) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1273 | return -ENOMEM; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1274 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1275 | batadv_hash_set_lock_class(bat_priv->bla.claim_hash, |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1276 | &batadv_claim_hash_lock_class_key); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1277 | batadv_hash_set_lock_class(bat_priv->bla.backbone_hash, |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1278 | &batadv_backbone_hash_lock_class_key); |
Sven Eckelmann | 5d52dad | 2012-03-29 12:38:20 +0200 | [diff] [blame] | 1279 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1280 | batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla hashes initialized\n"); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1281 | |
Antonio Quartulli | 7241444 | 2012-12-25 13:14:37 +0100 | [diff] [blame] | 1282 | INIT_DELAYED_WORK(&bat_priv->bla.work, batadv_bla_periodic_work); |
| 1283 | |
| 1284 | queue_delayed_work(batadv_event_workqueue, &bat_priv->bla.work, |
| 1285 | msecs_to_jiffies(BATADV_BLA_PERIOD_LENGTH)); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 1286 | return 0; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1287 | } |
| 1288 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 1289 | /** |
| 1290 | * batadv_bla_check_bcast_duplist |
| 1291 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 004e86f | 2012-10-18 13:47:42 +0200 | [diff] [blame] | 1292 | * @skb: contains the bcast_packet to be checked |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1293 | * |
| 1294 | * check if it is on our broadcast list. Another gateway might |
| 1295 | * have sent the same packet because it is connected to the same backbone, |
| 1296 | * so we have to remove this duplicate. |
| 1297 | * |
| 1298 | * This is performed by checking the CRC, which will tell us |
| 1299 | * with a good chance that it is the same packet. If it is furthermore |
| 1300 | * sent by another host, drop it. We allow equal packets from |
| 1301 | * the same host however as this might be intended. |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1302 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1303 | int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv, |
Simon Wunderlich | 004e86f | 2012-10-18 13:47:42 +0200 | [diff] [blame] | 1304 | struct sk_buff *skb) |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1305 | { |
Simon Wunderlich | 004e86f | 2012-10-18 13:47:42 +0200 | [diff] [blame] | 1306 | int i, curr, ret = 0; |
| 1307 | __be32 crc; |
| 1308 | struct batadv_bcast_packet *bcast_packet; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1309 | struct batadv_bcast_duplist_entry *entry; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1310 | |
Simon Wunderlich | 004e86f | 2012-10-18 13:47:42 +0200 | [diff] [blame] | 1311 | bcast_packet = (struct batadv_bcast_packet *)skb->data; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1312 | |
| 1313 | /* calculate the crc ... */ |
Simon Wunderlich | 004e86f | 2012-10-18 13:47:42 +0200 | [diff] [blame] | 1314 | crc = batadv_skb_crc32(skb, (u8 *)(bcast_packet + 1)); |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1315 | |
Linus Lüssing | 7dac7b7 | 2012-10-17 14:53:05 +0200 | [diff] [blame] | 1316 | spin_lock_bh(&bat_priv->bla.bcast_duplist_lock); |
| 1317 | |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1318 | for (i = 0; i < BATADV_DUPLIST_SIZE; i++) { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1319 | curr = (bat_priv->bla.bcast_duplist_curr + i); |
| 1320 | curr %= BATADV_DUPLIST_SIZE; |
| 1321 | entry = &bat_priv->bla.bcast_duplist[curr]; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1322 | |
| 1323 | /* we can stop searching if the entry is too old ; |
| 1324 | * later entries will be even older |
| 1325 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1326 | if (batadv_has_timed_out(entry->entrytime, |
| 1327 | BATADV_DUPLIST_TIMEOUT)) |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1328 | break; |
| 1329 | |
| 1330 | if (entry->crc != crc) |
| 1331 | continue; |
| 1332 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1333 | if (batadv_compare_eth(entry->orig, bcast_packet->orig)) |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1334 | continue; |
| 1335 | |
| 1336 | /* this entry seems to match: same crc, not too old, |
| 1337 | * and from another gw. therefore return 1 to forbid it. |
| 1338 | */ |
Linus Lüssing | 7dac7b7 | 2012-10-17 14:53:05 +0200 | [diff] [blame] | 1339 | ret = 1; |
| 1340 | goto out; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1341 | } |
Linus Lüssing | 7dac7b7 | 2012-10-17 14:53:05 +0200 | [diff] [blame] | 1342 | /* not found, add a new entry (overwrite the oldest entry) |
Antonio Quartulli | 3f68785 | 2014-11-02 11:29:56 +0100 | [diff] [blame] | 1343 | * and allow it, its the first occurrence. |
Linus Lüssing | 7dac7b7 | 2012-10-17 14:53:05 +0200 | [diff] [blame] | 1344 | */ |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1345 | curr = (bat_priv->bla.bcast_duplist_curr + BATADV_DUPLIST_SIZE - 1); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1346 | curr %= BATADV_DUPLIST_SIZE; |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1347 | entry = &bat_priv->bla.bcast_duplist[curr]; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1348 | entry->crc = crc; |
| 1349 | entry->entrytime = jiffies; |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 1350 | ether_addr_copy(entry->orig, bcast_packet->orig); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1351 | bat_priv->bla.bcast_duplist_curr = curr; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1352 | |
Linus Lüssing | 7dac7b7 | 2012-10-17 14:53:05 +0200 | [diff] [blame] | 1353 | out: |
| 1354 | spin_unlock_bh(&bat_priv->bla.bcast_duplist_lock); |
| 1355 | |
| 1356 | return ret; |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1357 | } |
| 1358 | |
Simon Wunderlich | 1b371d1 | 2014-01-15 21:17:54 +0100 | [diff] [blame] | 1359 | /** |
| 1360 | * batadv_bla_is_backbone_gw_orig |
| 1361 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1362 | * @orig: originator mac address |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1363 | * @vid: VLAN identifier |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1364 | * |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1365 | * Check if the originator is a gateway for the VLAN identified by vid. |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1366 | * |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1367 | * Returns true if orig is a backbone for this vid, false otherwise. |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1368 | */ |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 1369 | bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig, |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1370 | unsigned short vid) |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1371 | { |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1372 | struct batadv_hashtable *hash = bat_priv->bla.backbone_hash; |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1373 | struct hlist_head *head; |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 1374 | struct batadv_bla_backbone_gw *backbone_gw; |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1375 | int i; |
| 1376 | |
| 1377 | if (!atomic_read(&bat_priv->bridge_loop_avoidance)) |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1378 | return false; |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1379 | |
| 1380 | if (!hash) |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1381 | return false; |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1382 | |
| 1383 | for (i = 0; i < hash->size; i++) { |
| 1384 | head = &hash->table[i]; |
| 1385 | |
| 1386 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1387 | hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) { |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1388 | if (batadv_compare_eth(backbone_gw->orig, orig) && |
| 1389 | backbone_gw->vid == vid) { |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1390 | rcu_read_unlock(); |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1391 | return true; |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | rcu_read_unlock(); |
| 1395 | } |
| 1396 | |
Antonio Quartulli | cfd4f75 | 2013-08-07 18:28:56 +0200 | [diff] [blame] | 1397 | return false; |
Simon Wunderlich | 20ff9d5 | 2012-01-22 20:00:23 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 1400 | /** |
| 1401 | * batadv_bla_is_backbone_gw |
| 1402 | * @skb: the frame to be checked |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1403 | * @orig_node: the orig_node of the frame |
| 1404 | * @hdr_size: maximum length of the frame |
| 1405 | * |
| 1406 | * bla_is_backbone_gw inspects the skb for the VLAN ID and returns 1 |
| 1407 | * if the orig_node is also a gateway on the soft interface, otherwise it |
| 1408 | * returns 0. |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1409 | */ |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 1410 | int batadv_bla_is_backbone_gw(struct sk_buff *skb, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1411 | struct batadv_orig_node *orig_node, int hdr_size) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1412 | { |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 1413 | struct batadv_bla_backbone_gw *backbone_gw; |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1414 | unsigned short vid; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1415 | |
| 1416 | if (!atomic_read(&orig_node->bat_priv->bridge_loop_avoidance)) |
| 1417 | return 0; |
| 1418 | |
| 1419 | /* first, find out the vid. */ |
Antonio Quartulli | 0d12507 | 2012-02-18 11:27:34 +0100 | [diff] [blame] | 1420 | if (!pskb_may_pull(skb, hdr_size + ETH_HLEN)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1421 | return 0; |
| 1422 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 1423 | vid = batadv_get_vid(skb, hdr_size); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1424 | |
| 1425 | /* see if this originator is a backbone gw for this VLAN */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1426 | backbone_gw = batadv_backbone_hash_find(orig_node->bat_priv, |
| 1427 | orig_node->orig, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1428 | if (!backbone_gw) |
| 1429 | return 0; |
| 1430 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1431 | batadv_backbone_gw_free_ref(backbone_gw); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1432 | return 1; |
| 1433 | } |
| 1434 | |
| 1435 | /* free all bla structures (for softinterface free or module unload) */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1436 | void batadv_bla_free(struct batadv_priv *bat_priv) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1437 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1438 | struct batadv_hard_iface *primary_if; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1439 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1440 | cancel_delayed_work_sync(&bat_priv->bla.work); |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1441 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1442 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1443 | if (bat_priv->bla.claim_hash) { |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1444 | batadv_bla_purge_claims(bat_priv, primary_if, 1); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1445 | batadv_hash_destroy(bat_priv->bla.claim_hash); |
| 1446 | bat_priv->bla.claim_hash = NULL; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1447 | } |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1448 | if (bat_priv->bla.backbone_hash) { |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1449 | batadv_bla_purge_backbone_gw(bat_priv, 1); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1450 | batadv_hash_destroy(bat_priv->bla.backbone_hash); |
| 1451 | bat_priv->bla.backbone_hash = NULL; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1452 | } |
| 1453 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1454 | batadv_hardif_free_ref(primary_if); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1455 | } |
| 1456 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 1457 | /** |
| 1458 | * batadv_bla_rx |
| 1459 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1460 | * @skb: the frame to be checked |
| 1461 | * @vid: the VLAN ID of the frame |
Simon Wunderlich | 2d3f6cc | 2012-07-04 20:38:19 +0200 | [diff] [blame] | 1462 | * @is_bcast: the packet came in a broadcast packet type. |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1463 | * |
| 1464 | * bla_rx avoidance checks if: |
| 1465 | * * we have to race for a claim |
| 1466 | * * if the frame is allowed on the LAN |
| 1467 | * |
| 1468 | * in these cases, the skb is further handled by this function and |
| 1469 | * returns 1, otherwise it returns 0 and the caller shall further |
| 1470 | * process the skb. |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1471 | */ |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 1472 | int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, |
| 1473 | unsigned short vid, bool is_bcast) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1474 | { |
| 1475 | struct ethhdr *ethhdr; |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 1476 | struct batadv_bla_claim search_claim, *claim = NULL; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1477 | struct batadv_hard_iface *primary_if; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1478 | int ret; |
| 1479 | |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 1480 | ethhdr = eth_hdr(skb); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1481 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1482 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1483 | if (!primary_if) |
| 1484 | goto handled; |
| 1485 | |
| 1486 | if (!atomic_read(&bat_priv->bridge_loop_avoidance)) |
| 1487 | goto allow; |
| 1488 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1489 | if (unlikely(atomic_read(&bat_priv->bla.num_requests))) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1490 | /* don't allow broadcasts while requests are in flight */ |
Simon Wunderlich | 2d3f6cc | 2012-07-04 20:38:19 +0200 | [diff] [blame] | 1491 | if (is_multicast_ether_addr(ethhdr->h_dest) && is_bcast) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1492 | goto handled; |
| 1493 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 1494 | ether_addr_copy(search_claim.addr, ethhdr->h_source); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1495 | search_claim.vid = vid; |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1496 | claim = batadv_claim_hash_find(bat_priv, &search_claim); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1497 | |
| 1498 | if (!claim) { |
| 1499 | /* possible optimization: race for a claim */ |
| 1500 | /* No claim exists yet, claim it for us! |
| 1501 | */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1502 | batadv_handle_claim(bat_priv, primary_if, |
| 1503 | primary_if->net_dev->dev_addr, |
| 1504 | ethhdr->h_source, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1505 | goto allow; |
| 1506 | } |
| 1507 | |
| 1508 | /* if it is our own claim ... */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1509 | if (batadv_compare_eth(claim->backbone_gw->orig, |
| 1510 | primary_if->net_dev->dev_addr)) { |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1511 | /* ... allow it in any case */ |
| 1512 | claim->lasttime = jiffies; |
| 1513 | goto allow; |
| 1514 | } |
| 1515 | |
| 1516 | /* if it is a broadcast ... */ |
Simon Wunderlich | 2d3f6cc | 2012-07-04 20:38:19 +0200 | [diff] [blame] | 1517 | if (is_multicast_ether_addr(ethhdr->h_dest) && is_bcast) { |
| 1518 | /* ... drop it. the responsible gateway is in charge. |
| 1519 | * |
| 1520 | * We need to check is_bcast because with the gateway |
| 1521 | * feature, broadcasts (like DHCP requests) may be sent |
| 1522 | * using a unicast packet type. |
| 1523 | */ |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1524 | goto handled; |
| 1525 | } else { |
| 1526 | /* seems the client considers us as its best gateway. |
| 1527 | * send a claim and update the claim table |
| 1528 | * immediately. |
| 1529 | */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1530 | batadv_handle_claim(bat_priv, primary_if, |
| 1531 | primary_if->net_dev->dev_addr, |
| 1532 | ethhdr->h_source, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1533 | goto allow; |
| 1534 | } |
| 1535 | allow: |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1536 | batadv_bla_update_own_backbone_gw(bat_priv, primary_if, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1537 | ret = 0; |
| 1538 | goto out; |
| 1539 | |
| 1540 | handled: |
| 1541 | kfree_skb(skb); |
| 1542 | ret = 1; |
| 1543 | |
| 1544 | out: |
| 1545 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1546 | batadv_hardif_free_ref(primary_if); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1547 | if (claim) |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1548 | batadv_claim_free_ref(claim); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1549 | return ret; |
| 1550 | } |
| 1551 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 1552 | /** |
| 1553 | * batadv_bla_tx |
| 1554 | * @bat_priv: the bat priv with all the soft interface information |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1555 | * @skb: the frame to be checked |
| 1556 | * @vid: the VLAN ID of the frame |
| 1557 | * |
| 1558 | * bla_tx checks if: |
| 1559 | * * a claim was received which has to be processed |
| 1560 | * * the frame is allowed on the mesh |
| 1561 | * |
| 1562 | * in these cases, the skb is further handled by this function and |
| 1563 | * returns 1, otherwise it returns 0 and the caller shall further |
| 1564 | * process the skb. |
Linus Lüssing | 9d2c948 | 2013-08-06 20:21:15 +0200 | [diff] [blame] | 1565 | * |
| 1566 | * This call might reallocate skb data. |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1567 | */ |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 1568 | int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, |
| 1569 | unsigned short vid) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1570 | { |
| 1571 | struct ethhdr *ethhdr; |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 1572 | struct batadv_bla_claim search_claim, *claim = NULL; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1573 | struct batadv_hard_iface *primary_if; |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1574 | int ret = 0; |
| 1575 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1576 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1577 | if (!primary_if) |
| 1578 | goto out; |
| 1579 | |
| 1580 | if (!atomic_read(&bat_priv->bridge_loop_avoidance)) |
| 1581 | goto allow; |
| 1582 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1583 | if (batadv_bla_process_claim(bat_priv, primary_if, skb)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1584 | goto handled; |
| 1585 | |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 1586 | ethhdr = eth_hdr(skb); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1587 | |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1588 | if (unlikely(atomic_read(&bat_priv->bla.num_requests))) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1589 | /* don't allow broadcasts while requests are in flight */ |
| 1590 | if (is_multicast_ether_addr(ethhdr->h_dest)) |
| 1591 | goto handled; |
| 1592 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 1593 | ether_addr_copy(search_claim.addr, ethhdr->h_source); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1594 | search_claim.vid = vid; |
| 1595 | |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1596 | claim = batadv_claim_hash_find(bat_priv, &search_claim); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1597 | |
| 1598 | /* if no claim exists, allow it. */ |
| 1599 | if (!claim) |
| 1600 | goto allow; |
| 1601 | |
| 1602 | /* check if we are responsible. */ |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1603 | if (batadv_compare_eth(claim->backbone_gw->orig, |
| 1604 | primary_if->net_dev->dev_addr)) { |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1605 | /* if yes, the client has roamed and we have |
| 1606 | * to unclaim it. |
| 1607 | */ |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1608 | batadv_handle_unclaim(bat_priv, primary_if, |
| 1609 | primary_if->net_dev->dev_addr, |
| 1610 | ethhdr->h_source, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1611 | goto allow; |
| 1612 | } |
| 1613 | |
| 1614 | /* check if it is a multicast/broadcast frame */ |
| 1615 | if (is_multicast_ether_addr(ethhdr->h_dest)) { |
| 1616 | /* drop it. the responsible gateway has forwarded it into |
| 1617 | * the backbone network. |
| 1618 | */ |
| 1619 | goto handled; |
| 1620 | } else { |
| 1621 | /* we must allow it. at least if we are |
| 1622 | * responsible for the DESTINATION. |
| 1623 | */ |
| 1624 | goto allow; |
| 1625 | } |
| 1626 | allow: |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1627 | batadv_bla_update_own_backbone_gw(bat_priv, primary_if, vid); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1628 | ret = 0; |
| 1629 | goto out; |
| 1630 | handled: |
| 1631 | ret = 1; |
| 1632 | out: |
| 1633 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1634 | batadv_hardif_free_ref(primary_if); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1635 | if (claim) |
Sven Eckelmann | 3b300de | 2012-05-12 18:33:53 +0200 | [diff] [blame] | 1636 | batadv_claim_free_ref(claim); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1637 | return ret; |
| 1638 | } |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1639 | |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 1640 | int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset) |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1641 | { |
| 1642 | struct net_device *net_dev = (struct net_device *)seq->private; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1643 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1644 | struct batadv_hashtable *hash = bat_priv->bla.claim_hash; |
Marek Lindner | 712bbfe4 | 2012-12-25 17:03:25 +0800 | [diff] [blame] | 1645 | struct batadv_bla_claim *claim; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1646 | struct batadv_hard_iface *primary_if; |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1647 | struct hlist_head *head; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 1648 | u32 i; |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1649 | bool is_own; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 1650 | u8 *primary_addr; |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1651 | |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 1652 | primary_if = batadv_seq_print_text_primary_if_get(seq); |
| 1653 | if (!primary_if) |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1654 | goto out; |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1655 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1656 | primary_addr = primary_if->net_dev->dev_addr; |
Simon Wunderlich | 38ef3d1 | 2012-01-22 20:00:26 +0100 | [diff] [blame] | 1657 | seq_printf(seq, |
Antonio Quartulli | 39a3299 | 2012-11-19 09:01:43 +0100 | [diff] [blame] | 1658 | "Claims announced for the mesh %s (orig %pM, group id %#.4x)\n", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1659 | net_dev->name, primary_addr, |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1660 | ntohs(bat_priv->bla.claim_dest.group)); |
Antonio Quartulli | 39a3299 | 2012-11-19 09:01:43 +0100 | [diff] [blame] | 1661 | seq_printf(seq, " %-17s %-5s %-17s [o] (%-6s)\n", |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1662 | "Client", "VID", "Originator", "CRC"); |
| 1663 | for (i = 0; i < hash->size; i++) { |
| 1664 | head = &hash->table[i]; |
| 1665 | |
| 1666 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1667 | hlist_for_each_entry_rcu(claim, head, hash_entry) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1668 | is_own = batadv_compare_eth(claim->backbone_gw->orig, |
| 1669 | primary_addr); |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 1670 | seq_printf(seq, " * %pM on %5d by %pM [%c] (%#.4x)\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 1671 | claim->addr, BATADV_PRINT_VID(claim->vid), |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1672 | claim->backbone_gw->orig, |
| 1673 | (is_own ? 'x' : ' '), |
| 1674 | claim->backbone_gw->crc); |
| 1675 | } |
| 1676 | rcu_read_unlock(); |
| 1677 | } |
| 1678 | out: |
| 1679 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1680 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 1681 | return 0; |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 1682 | } |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1683 | |
| 1684 | int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset) |
| 1685 | { |
| 1686 | struct net_device *net_dev = (struct net_device *)seq->private; |
| 1687 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1688 | struct batadv_hashtable *hash = bat_priv->bla.backbone_hash; |
Marek Lindner | bae9877 | 2012-12-25 17:03:24 +0800 | [diff] [blame] | 1689 | struct batadv_bla_backbone_gw *backbone_gw; |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1690 | struct batadv_hard_iface *primary_if; |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1691 | struct hlist_head *head; |
| 1692 | int secs, msecs; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 1693 | u32 i; |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1694 | bool is_own; |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame^] | 1695 | u8 *primary_addr; |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1696 | |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 1697 | primary_if = batadv_seq_print_text_primary_if_get(seq); |
| 1698 | if (!primary_if) |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1699 | goto out; |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1700 | |
| 1701 | primary_addr = primary_if->net_dev->dev_addr; |
| 1702 | seq_printf(seq, |
Antonio Quartulli | 39a3299 | 2012-11-19 09:01:43 +0100 | [diff] [blame] | 1703 | "Backbones announced for the mesh %s (orig %pM, group id %#.4x)\n", |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1704 | net_dev->name, primary_addr, |
Sven Eckelmann | 807736f | 2012-07-15 22:26:51 +0200 | [diff] [blame] | 1705 | ntohs(bat_priv->bla.claim_dest.group)); |
Antonio Quartulli | 39a3299 | 2012-11-19 09:01:43 +0100 | [diff] [blame] | 1706 | seq_printf(seq, " %-17s %-5s %-9s (%-6s)\n", |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1707 | "Originator", "VID", "last seen", "CRC"); |
| 1708 | for (i = 0; i < hash->size; i++) { |
| 1709 | head = &hash->table[i]; |
| 1710 | |
| 1711 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1712 | hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) { |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1713 | msecs = jiffies_to_msecs(jiffies - |
| 1714 | backbone_gw->lasttime); |
| 1715 | secs = msecs / 1000; |
| 1716 | msecs = msecs % 1000; |
| 1717 | |
| 1718 | is_own = batadv_compare_eth(backbone_gw->orig, |
| 1719 | primary_addr); |
| 1720 | if (is_own) |
| 1721 | continue; |
| 1722 | |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 1723 | seq_printf(seq, " * %pM on %5d %4i.%03is (%#.4x)\n", |
Antonio Quartulli | 5f80df6 | 2013-04-19 18:07:01 +0200 | [diff] [blame] | 1724 | backbone_gw->orig, |
| 1725 | BATADV_PRINT_VID(backbone_gw->vid), secs, |
Antonio Quartulli | eb2deb6 | 2013-04-19 18:07:00 +0200 | [diff] [blame] | 1726 | msecs, backbone_gw->crc); |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1727 | } |
| 1728 | rcu_read_unlock(); |
| 1729 | } |
| 1730 | out: |
| 1731 | if (primary_if) |
| 1732 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 30da63a | 2012-08-03 17:15:46 +0200 | [diff] [blame] | 1733 | return 0; |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 1734 | } |