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