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