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