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