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