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) 2007-2020 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 3 | * |
| 4 | * Marek Lindner, Simon Wunderlich |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 7 | #include "hard-interface.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 8 | #include "main.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 9 | |
Sven Eckelmann | 7a659d5 | 2016-01-16 10:29:54 +0100 | [diff] [blame] | 10 | #include <linux/atomic.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 11 | #include <linux/byteorder/generic.h> |
| 12 | #include <linux/errno.h> |
Sven Eckelmann | b92b94a | 2017-11-19 17:12:02 +0100 | [diff] [blame] | 13 | #include <linux/gfp.h> |
Sven Eckelmann | fcafa5e | 2016-05-15 11:07:42 +0200 | [diff] [blame] | 14 | #include <linux/if.h> |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 15 | #include <linux/if_arp.h> |
Antonio Quartulli | af5d4f7 | 2012-11-26 00:38:50 +0100 | [diff] [blame] | 16 | #include <linux/if_ether.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Sven Eckelmann | 7a659d5 | 2016-01-16 10:29:54 +0100 | [diff] [blame] | 18 | #include <linux/kref.h> |
Sven Eckelmann | e192875 | 2019-05-24 16:28:50 +0200 | [diff] [blame] | 19 | #include <linux/limits.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 20 | #include <linux/list.h> |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 21 | #include <linux/mutex.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/printk.h> |
| 24 | #include <linux/rculist.h> |
| 25 | #include <linux/rtnetlink.h> |
| 26 | #include <linux/slab.h> |
Marek Lindner | cef6341 | 2015-08-04 21:09:55 +0800 | [diff] [blame] | 27 | #include <linux/spinlock.h> |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 28 | #include <net/net_namespace.h> |
| 29 | #include <net/rtnetlink.h> |
Sven Eckelmann | fec149f | 2017-12-21 10:17:41 +0100 | [diff] [blame] | 30 | #include <uapi/linux/batadv_packet.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 31 | |
Sven Eckelmann | a2d0816 | 2016-05-15 11:07:46 +0200 | [diff] [blame] | 32 | #include "bat_v.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 33 | #include "bridge_loop_avoidance.h" |
| 34 | #include "debugfs.h" |
| 35 | #include "distributed-arp-table.h" |
| 36 | #include "gateway_client.h" |
Sven Eckelmann | ba41208 | 2016-05-15 23:48:31 +0200 | [diff] [blame] | 37 | #include "log.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 38 | #include "originator.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 39 | #include "send.h" |
| 40 | #include "soft-interface.h" |
| 41 | #include "sysfs.h" |
| 42 | #include "translation-table.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 43 | |
Sven Eckelmann | 140ed8e | 2016-01-05 12:06:26 +0100 | [diff] [blame] | 44 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 45 | * batadv_hardif_release() - release hard interface from lists and queue for |
Sven Eckelmann | 140ed8e | 2016-01-05 12:06:26 +0100 | [diff] [blame] | 46 | * free after rcu grace period |
Sven Eckelmann | 7a659d5 | 2016-01-16 10:29:54 +0100 | [diff] [blame] | 47 | * @ref: kref pointer of the hard interface |
Sven Eckelmann | 140ed8e | 2016-01-05 12:06:26 +0100 | [diff] [blame] | 48 | */ |
Sven Eckelmann | 7a659d5 | 2016-01-16 10:29:54 +0100 | [diff] [blame] | 49 | void batadv_hardif_release(struct kref *ref) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 50 | { |
Sven Eckelmann | 7a659d5 | 2016-01-16 10:29:54 +0100 | [diff] [blame] | 51 | struct batadv_hard_iface *hard_iface; |
| 52 | |
| 53 | hard_iface = container_of(ref, struct batadv_hard_iface, refcount); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 54 | dev_put(hard_iface->net_dev); |
Sven Eckelmann | 140ed8e | 2016-01-05 12:06:26 +0100 | [diff] [blame] | 55 | |
| 56 | kfree_rcu(hard_iface, rcu); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 59 | /** |
| 60 | * batadv_hardif_get_by_netdev() - Get hard interface object of a net_device |
| 61 | * @net_dev: net_device to search for |
| 62 | * |
| 63 | * Return: batadv_hard_iface of net_dev (with increased refcnt), NULL on errors |
| 64 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 65 | struct batadv_hard_iface * |
| 66 | batadv_hardif_get_by_netdev(const struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 67 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 68 | struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 69 | |
| 70 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 71 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 72 | if (hard_iface->net_dev == net_dev && |
Sven Eckelmann | 7a659d5 | 2016-01-16 10:29:54 +0100 | [diff] [blame] | 73 | kref_get_unless_zero(&hard_iface->refcount)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 74 | goto out; |
| 75 | } |
| 76 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 77 | hard_iface = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 78 | |
| 79 | out: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 80 | rcu_read_unlock(); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 81 | return hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 84 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 85 | * batadv_getlink_net() - return link net namespace (of use fallback) |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 86 | * @netdev: net_device to check |
| 87 | * @fallback_net: return in case get_link_net is not available for @netdev |
| 88 | * |
| 89 | * Return: result of rtnl_link_ops->get_link_net or @fallback_net |
| 90 | */ |
Sven Eckelmann | 88ffc7d | 2016-09-30 15:21:00 +0200 | [diff] [blame] | 91 | static struct net *batadv_getlink_net(const struct net_device *netdev, |
| 92 | struct net *fallback_net) |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 93 | { |
| 94 | if (!netdev->rtnl_link_ops) |
| 95 | return fallback_net; |
| 96 | |
| 97 | if (!netdev->rtnl_link_ops->get_link_net) |
| 98 | return fallback_net; |
| 99 | |
| 100 | return netdev->rtnl_link_ops->get_link_net(netdev); |
| 101 | } |
| 102 | |
| 103 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 104 | * batadv_mutual_parents() - check if two devices are each others parent |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 105 | * @dev1: 1st net dev |
| 106 | * @net1: 1st devices netns |
| 107 | * @dev2: 2nd net dev |
| 108 | * @net2: 2nd devices netns |
Andrew Lunn | 1bc4e2b | 2016-02-11 22:15:57 +0100 | [diff] [blame] | 109 | * |
| 110 | * veth devices come in pairs and each is the parent of the other! |
| 111 | * |
| 112 | * Return: true if the devices are each others parent, otherwise false |
| 113 | */ |
| 114 | static bool batadv_mutual_parents(const struct net_device *dev1, |
Sven Eckelmann | 88ffc7d | 2016-09-30 15:21:00 +0200 | [diff] [blame] | 115 | struct net *net1, |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 116 | const struct net_device *dev2, |
Sven Eckelmann | 88ffc7d | 2016-09-30 15:21:00 +0200 | [diff] [blame] | 117 | struct net *net2) |
Andrew Lunn | 1bc4e2b | 2016-02-11 22:15:57 +0100 | [diff] [blame] | 118 | { |
| 119 | int dev1_parent_iflink = dev_get_iflink(dev1); |
| 120 | int dev2_parent_iflink = dev_get_iflink(dev2); |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 121 | const struct net *dev1_parent_net; |
| 122 | const struct net *dev2_parent_net; |
| 123 | |
| 124 | dev1_parent_net = batadv_getlink_net(dev1, net1); |
| 125 | dev2_parent_net = batadv_getlink_net(dev2, net2); |
Andrew Lunn | 1bc4e2b | 2016-02-11 22:15:57 +0100 | [diff] [blame] | 126 | |
| 127 | if (!dev1_parent_iflink || !dev2_parent_iflink) |
| 128 | return false; |
| 129 | |
| 130 | return (dev1_parent_iflink == dev2->ifindex) && |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 131 | (dev2_parent_iflink == dev1->ifindex) && |
| 132 | net_eq(dev1_parent_net, net2) && |
| 133 | net_eq(dev2_parent_net, net1); |
Andrew Lunn | 1bc4e2b | 2016-02-11 22:15:57 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 137 | * batadv_is_on_batman_iface() - check if a device is a batman iface descendant |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 138 | * @net_dev: the device to check |
| 139 | * |
| 140 | * If the user creates any virtual device on top of a batman-adv interface, it |
Sven Eckelmann | bccb48c | 2020-06-01 20:13:21 +0200 | [diff] [blame] | 141 | * is important to prevent this new interface from being used to create a new |
| 142 | * mesh network (this behaviour would lead to a batman-over-batman |
| 143 | * configuration). This function recursively checks all the fathers of the |
| 144 | * device passed as argument looking for a batman-adv soft interface. |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 145 | * |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 146 | * Return: true if the device is descendant of a batman-adv mesh interface (or |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 147 | * if it is a batman-adv interface itself), false otherwise |
| 148 | */ |
| 149 | static bool batadv_is_on_batman_iface(const struct net_device *net_dev) |
| 150 | { |
Andrew Lunn | 2cd45a0 | 2016-04-21 12:57:27 +0200 | [diff] [blame] | 151 | struct net *net = dev_net(net_dev); |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 152 | struct net_device *parent_dev; |
Sven Eckelmann | 88ffc7d | 2016-09-30 15:21:00 +0200 | [diff] [blame] | 153 | struct net *parent_net; |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 154 | bool ret; |
| 155 | |
| 156 | /* check if this is a batman-adv mesh interface */ |
| 157 | if (batadv_softif_is_valid(net_dev)) |
| 158 | return true; |
| 159 | |
| 160 | /* no more parents..stop recursion */ |
Nicolas Dichtel | a54acb3 | 2015-04-02 17:07:00 +0200 | [diff] [blame] | 161 | if (dev_get_iflink(net_dev) == 0 || |
| 162 | dev_get_iflink(net_dev) == net_dev->ifindex) |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 163 | return false; |
| 164 | |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 165 | parent_net = batadv_getlink_net(net_dev, net); |
| 166 | |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 167 | /* recurse over the parent device */ |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 168 | parent_dev = __dev_get_by_index((struct net *)parent_net, |
| 169 | dev_get_iflink(net_dev)); |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 170 | /* if we got a NULL parent_dev there is something broken.. */ |
Sven Eckelmann | 955d341 | 2018-12-30 12:46:01 +0100 | [diff] [blame] | 171 | if (!parent_dev) { |
| 172 | pr_err("Cannot find parent device\n"); |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 173 | return false; |
Sven Eckelmann | 955d341 | 2018-12-30 12:46:01 +0100 | [diff] [blame] | 174 | } |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 175 | |
Andrew Lunn | 275019d | 2016-07-03 13:31:33 +0200 | [diff] [blame] | 176 | if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net)) |
Andrew Lunn | 1bc4e2b | 2016-02-11 22:15:57 +0100 | [diff] [blame] | 177 | return false; |
| 178 | |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 179 | ret = batadv_is_on_batman_iface(parent_dev); |
| 180 | |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 181 | return ret; |
| 182 | } |
| 183 | |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 184 | static bool batadv_is_valid_iface(const struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 185 | { |
| 186 | if (net_dev->flags & IFF_LOOPBACK) |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 187 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 188 | |
| 189 | if (net_dev->type != ARPHRD_ETHER) |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 190 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 191 | |
| 192 | if (net_dev->addr_len != ETH_ALEN) |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 193 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 194 | |
| 195 | /* no batman over batman */ |
Antonio Quartulli | b7eddd0 | 2012-09-09 10:46:46 +0200 | [diff] [blame] | 196 | if (batadv_is_on_batman_iface(net_dev)) |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 197 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 198 | |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 199 | return true; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Matthias Schiffer | de68d10 | 2013-03-09 23:14:22 +0100 | [diff] [blame] | 202 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 203 | * batadv_get_real_netdevice() - check if the given netdev struct is a virtual |
Marek Lindner | 5ed4a46 | 2016-09-30 15:21:04 +0200 | [diff] [blame] | 204 | * interface on top of another 'real' interface |
| 205 | * @netdev: the device to check |
| 206 | * |
Marek Lindner | 1942de1 | 2016-09-30 15:21:05 +0200 | [diff] [blame] | 207 | * Callers must hold the rtnl semaphore. You may want batadv_get_real_netdev() |
| 208 | * instead of this. |
| 209 | * |
Marek Lindner | 5ed4a46 | 2016-09-30 15:21:04 +0200 | [diff] [blame] | 210 | * Return: the 'real' net device or the original net device and NULL in case |
| 211 | * of an error. |
| 212 | */ |
| 213 | static struct net_device *batadv_get_real_netdevice(struct net_device *netdev) |
| 214 | { |
| 215 | struct batadv_hard_iface *hard_iface = NULL; |
| 216 | struct net_device *real_netdev = NULL; |
| 217 | struct net *real_net; |
| 218 | struct net *net; |
| 219 | int ifindex; |
| 220 | |
| 221 | ASSERT_RTNL(); |
| 222 | |
| 223 | if (!netdev) |
| 224 | return NULL; |
| 225 | |
| 226 | if (netdev->ifindex == dev_get_iflink(netdev)) { |
| 227 | dev_hold(netdev); |
| 228 | return netdev; |
| 229 | } |
| 230 | |
| 231 | hard_iface = batadv_hardif_get_by_netdev(netdev); |
| 232 | if (!hard_iface || !hard_iface->soft_iface) |
| 233 | goto out; |
| 234 | |
| 235 | net = dev_net(hard_iface->soft_iface); |
| 236 | ifindex = dev_get_iflink(netdev); |
| 237 | real_net = batadv_getlink_net(netdev, net); |
| 238 | real_netdev = dev_get_by_index(real_net, ifindex); |
| 239 | |
| 240 | out: |
| 241 | if (hard_iface) |
| 242 | batadv_hardif_put(hard_iface); |
| 243 | return real_netdev; |
| 244 | } |
| 245 | |
| 246 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 247 | * batadv_get_real_netdev() - check if the given net_device struct is a virtual |
Marek Lindner | 1942de1 | 2016-09-30 15:21:05 +0200 | [diff] [blame] | 248 | * interface on top of another 'real' interface |
Matthias Schiffer | de68d10 | 2013-03-09 23:14:22 +0100 | [diff] [blame] | 249 | * @net_device: the device to check |
| 250 | * |
Marek Lindner | 1942de1 | 2016-09-30 15:21:05 +0200 | [diff] [blame] | 251 | * Return: the 'real' net device or the original net device and NULL in case |
| 252 | * of an error. |
Matthias Schiffer | de68d10 | 2013-03-09 23:14:22 +0100 | [diff] [blame] | 253 | */ |
Marek Lindner | 1942de1 | 2016-09-30 15:21:05 +0200 | [diff] [blame] | 254 | struct net_device *batadv_get_real_netdev(struct net_device *net_device) |
| 255 | { |
| 256 | struct net_device *real_netdev; |
| 257 | |
| 258 | rtnl_lock(); |
| 259 | real_netdev = batadv_get_real_netdevice(net_device); |
| 260 | rtnl_unlock(); |
| 261 | |
| 262 | return real_netdev; |
| 263 | } |
| 264 | |
| 265 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 266 | * batadv_is_wext_netdev() - check if the given net_device struct is a |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 267 | * wext wifi interface |
Marek Lindner | f44a3ae | 2016-09-30 15:21:02 +0200 | [diff] [blame] | 268 | * @net_device: the device to check |
| 269 | * |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 270 | * Return: true if the net device is a wext wireless device, false |
Marek Lindner | f44a3ae | 2016-09-30 15:21:02 +0200 | [diff] [blame] | 271 | * otherwise. |
| 272 | */ |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 273 | static bool batadv_is_wext_netdev(struct net_device *net_device) |
Matthias Schiffer | de68d10 | 2013-03-09 23:14:22 +0100 | [diff] [blame] | 274 | { |
Antonio Quartulli | 0c69aec | 2013-10-13 02:50:18 +0200 | [diff] [blame] | 275 | if (!net_device) |
| 276 | return false; |
| 277 | |
Matthias Schiffer | de68d10 | 2013-03-09 23:14:22 +0100 | [diff] [blame] | 278 | #ifdef CONFIG_WIRELESS_EXT |
| 279 | /* pre-cfg80211 drivers have to implement WEXT, so it is possible to |
| 280 | * check for wireless_handlers != NULL |
| 281 | */ |
| 282 | if (net_device->wireless_handlers) |
| 283 | return true; |
| 284 | #endif |
| 285 | |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 286 | return false; |
| 287 | } |
| 288 | |
| 289 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 290 | * batadv_is_cfg80211_netdev() - check if the given net_device struct is a |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 291 | * cfg80211 wifi interface |
| 292 | * @net_device: the device to check |
| 293 | * |
| 294 | * Return: true if the net device is a cfg80211 wireless device, false |
| 295 | * otherwise. |
| 296 | */ |
| 297 | static bool batadv_is_cfg80211_netdev(struct net_device *net_device) |
| 298 | { |
| 299 | if (!net_device) |
| 300 | return false; |
| 301 | |
Matthias Schiffer | de68d10 | 2013-03-09 23:14:22 +0100 | [diff] [blame] | 302 | /* cfg80211 drivers have to set ieee80211_ptr */ |
| 303 | if (net_device->ieee80211_ptr) |
| 304 | return true; |
| 305 | |
| 306 | return false; |
| 307 | } |
| 308 | |
Linus Lüssing | 3111bee | 2016-08-07 12:34:19 +0200 | [diff] [blame] | 309 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 310 | * batadv_wifi_flags_evaluate() - calculate wifi flags for net_device |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 311 | * @net_device: the device to check |
| 312 | * |
| 313 | * Return: batadv_hard_iface_wifi_flags flags of the device |
| 314 | */ |
| 315 | static u32 batadv_wifi_flags_evaluate(struct net_device *net_device) |
| 316 | { |
| 317 | u32 wifi_flags = 0; |
Marek Lindner | 5ed4a46 | 2016-09-30 15:21:04 +0200 | [diff] [blame] | 318 | struct net_device *real_netdev; |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 319 | |
| 320 | if (batadv_is_wext_netdev(net_device)) |
| 321 | wifi_flags |= BATADV_HARDIF_WIFI_WEXT_DIRECT; |
| 322 | |
| 323 | if (batadv_is_cfg80211_netdev(net_device)) |
| 324 | wifi_flags |= BATADV_HARDIF_WIFI_CFG80211_DIRECT; |
| 325 | |
Marek Lindner | 5ed4a46 | 2016-09-30 15:21:04 +0200 | [diff] [blame] | 326 | real_netdev = batadv_get_real_netdevice(net_device); |
| 327 | if (!real_netdev) |
| 328 | return wifi_flags; |
| 329 | |
| 330 | if (real_netdev == net_device) |
| 331 | goto out; |
| 332 | |
| 333 | if (batadv_is_wext_netdev(real_netdev)) |
| 334 | wifi_flags |= BATADV_HARDIF_WIFI_WEXT_INDIRECT; |
| 335 | |
| 336 | if (batadv_is_cfg80211_netdev(real_netdev)) |
| 337 | wifi_flags |= BATADV_HARDIF_WIFI_CFG80211_INDIRECT; |
| 338 | |
| 339 | out: |
| 340 | dev_put(real_netdev); |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 341 | return wifi_flags; |
| 342 | } |
| 343 | |
| 344 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 345 | * batadv_is_cfg80211_hardif() - check if the given hardif is a cfg80211 wifi |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 346 | * interface |
| 347 | * @hard_iface: the device to check |
| 348 | * |
| 349 | * Return: true if the net device is a cfg80211 wireless device, false |
| 350 | * otherwise. |
| 351 | */ |
| 352 | bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface) |
| 353 | { |
| 354 | u32 allowed_flags = 0; |
| 355 | |
| 356 | allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_DIRECT; |
Marek Lindner | 5ed4a46 | 2016-09-30 15:21:04 +0200 | [diff] [blame] | 357 | allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_INDIRECT; |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 358 | |
| 359 | return !!(hard_iface->wifi_flags & allowed_flags); |
| 360 | } |
| 361 | |
| 362 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 363 | * batadv_is_wifi_hardif() - check if the given hardif is a wifi interface |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 364 | * @hard_iface: the device to check |
| 365 | * |
| 366 | * Return: true if the net device is a 802.11 wireless device, false otherwise. |
| 367 | */ |
| 368 | bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface) |
| 369 | { |
| 370 | if (!hard_iface) |
| 371 | return false; |
| 372 | |
| 373 | return hard_iface->wifi_flags != 0; |
Matthias Schiffer | de68d10 | 2013-03-09 23:14:22 +0100 | [diff] [blame] | 374 | } |
| 375 | |
Linus Lüssing | 3111bee | 2016-08-07 12:34:19 +0200 | [diff] [blame] | 376 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 377 | * batadv_hardif_no_broadcast() - check whether (re)broadcast is necessary |
Linus Lüssing | 3111bee | 2016-08-07 12:34:19 +0200 | [diff] [blame] | 378 | * @if_outgoing: the outgoing interface checked and considered for (re)broadcast |
| 379 | * @orig_addr: the originator of this packet |
| 380 | * @orig_neigh: originator address of the forwarder we just got the packet from |
| 381 | * (NULL if we originated) |
| 382 | * |
| 383 | * Checks whether a packet needs to be (re)broadcasted on the given interface. |
| 384 | * |
| 385 | * Return: |
| 386 | * BATADV_HARDIF_BCAST_NORECIPIENT: No neighbor on interface |
| 387 | * BATADV_HARDIF_BCAST_DUPFWD: Just one neighbor, but it is the forwarder |
| 388 | * BATADV_HARDIF_BCAST_DUPORIG: Just one neighbor, but it is the originator |
| 389 | * BATADV_HARDIF_BCAST_OK: Several neighbors, must broadcast |
| 390 | */ |
| 391 | int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing, |
| 392 | u8 *orig_addr, u8 *orig_neigh) |
| 393 | { |
| 394 | struct batadv_hardif_neigh_node *hardif_neigh; |
| 395 | struct hlist_node *first; |
| 396 | int ret = BATADV_HARDIF_BCAST_OK; |
| 397 | |
| 398 | rcu_read_lock(); |
| 399 | |
| 400 | /* 0 neighbors -> no (re)broadcast */ |
| 401 | first = rcu_dereference(hlist_first_rcu(&if_outgoing->neigh_list)); |
| 402 | if (!first) { |
| 403 | ret = BATADV_HARDIF_BCAST_NORECIPIENT; |
| 404 | goto out; |
| 405 | } |
| 406 | |
| 407 | /* >1 neighbors -> (re)brodcast */ |
| 408 | if (rcu_dereference(hlist_next_rcu(first))) |
| 409 | goto out; |
| 410 | |
| 411 | hardif_neigh = hlist_entry(first, struct batadv_hardif_neigh_node, |
| 412 | list); |
| 413 | |
| 414 | /* 1 neighbor, is the originator -> no rebroadcast */ |
| 415 | if (orig_addr && batadv_compare_eth(hardif_neigh->orig, orig_addr)) { |
| 416 | ret = BATADV_HARDIF_BCAST_DUPORIG; |
| 417 | /* 1 neighbor, is the one we received from -> no rebroadcast */ |
| 418 | } else if (orig_neigh && |
| 419 | batadv_compare_eth(hardif_neigh->orig, orig_neigh)) { |
| 420 | ret = BATADV_HARDIF_BCAST_DUPFWD; |
| 421 | } |
| 422 | |
| 423 | out: |
| 424 | rcu_read_unlock(); |
| 425 | return ret; |
| 426 | } |
| 427 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 428 | static struct batadv_hard_iface * |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 429 | batadv_hardif_get_active(const struct net_device *soft_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 430 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 431 | struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 432 | |
| 433 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 434 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 435 | if (hard_iface->soft_iface != soft_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 436 | continue; |
| 437 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 438 | if (hard_iface->if_status == BATADV_IF_ACTIVE && |
Sven Eckelmann | 7a659d5 | 2016-01-16 10:29:54 +0100 | [diff] [blame] | 439 | kref_get_unless_zero(&hard_iface->refcount)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 440 | goto out; |
| 441 | } |
| 442 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 443 | hard_iface = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 444 | |
| 445 | out: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 446 | rcu_read_unlock(); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 447 | return hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 450 | static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv, |
| 451 | struct batadv_hard_iface *oldif) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 452 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 453 | struct batadv_hard_iface *primary_if; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 454 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 455 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 456 | if (!primary_if) |
| 457 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 458 | |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 459 | batadv_dat_init_own_addr(bat_priv, primary_if); |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 460 | batadv_bla_update_orig_address(bat_priv, primary_if, oldif); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 461 | out: |
| 462 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 463 | batadv_hardif_put(primary_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 466 | static void batadv_primary_if_select(struct batadv_priv *bat_priv, |
| 467 | struct batadv_hard_iface *new_hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 468 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 469 | struct batadv_hard_iface *curr_hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 470 | |
Sven Eckelmann | c3caf51 | 2011-05-03 11:51:38 +0200 | [diff] [blame] | 471 | ASSERT_RTNL(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 472 | |
Sven Eckelmann | 17a8691 | 2016-04-11 13:06:40 +0200 | [diff] [blame] | 473 | if (new_hard_iface) |
| 474 | kref_get(&new_hard_iface->refcount); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 475 | |
Antonio Quartulli | cf78bb0 | 2020-05-20 10:41:40 +0200 | [diff] [blame] | 476 | curr_hard_iface = rcu_replace_pointer(bat_priv->primary_if, |
| 477 | new_hard_iface, 1); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 478 | |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 479 | if (!new_hard_iface) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 480 | goto out; |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 481 | |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 482 | bat_priv->algo_ops->iface.primary_set(new_hard_iface); |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 483 | batadv_primary_if_update_addr(bat_priv, curr_hard_iface); |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 484 | |
| 485 | out: |
| 486 | if (curr_hard_iface) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 487 | batadv_hardif_put(curr_hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 490 | static bool |
| 491 | batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 492 | { |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 493 | if (hard_iface->net_dev->flags & IFF_UP) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 494 | return true; |
| 495 | |
| 496 | return false; |
| 497 | } |
| 498 | |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 499 | static void batadv_check_known_mac_addr(const struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 500 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 501 | const struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 502 | |
| 503 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 504 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 505 | if (hard_iface->if_status != BATADV_IF_ACTIVE && |
| 506 | hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 507 | continue; |
| 508 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 509 | if (hard_iface->net_dev == net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 510 | continue; |
| 511 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 512 | if (!batadv_compare_eth(hard_iface->net_dev->dev_addr, |
| 513 | net_dev->dev_addr)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 514 | continue; |
| 515 | |
Sven Eckelmann | 6796958 | 2012-03-26 16:22:45 +0200 | [diff] [blame] | 516 | pr_warn("The newly added mac address (%pM) already exists on: %s\n", |
| 517 | net_dev->dev_addr, hard_iface->net_dev->name); |
| 518 | pr_warn("It is strongly recommended to keep mac addresses unique to avoid problems!\n"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 519 | } |
| 520 | rcu_read_unlock(); |
| 521 | } |
| 522 | |
Sven Eckelmann | 7bca68c | 2015-08-07 19:28:42 +0200 | [diff] [blame] | 523 | /** |
| 524 | * batadv_hardif_recalc_extra_skbroom() - Recalculate skbuff extra head/tailroom |
| 525 | * @soft_iface: netdev struct of the mesh interface |
| 526 | */ |
| 527 | static void batadv_hardif_recalc_extra_skbroom(struct net_device *soft_iface) |
| 528 | { |
| 529 | const struct batadv_hard_iface *hard_iface; |
| 530 | unsigned short lower_header_len = ETH_HLEN; |
| 531 | unsigned short lower_headroom = 0; |
| 532 | unsigned short lower_tailroom = 0; |
| 533 | unsigned short needed_headroom; |
| 534 | |
| 535 | rcu_read_lock(); |
| 536 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 537 | if (hard_iface->if_status == BATADV_IF_NOT_IN_USE) |
| 538 | continue; |
| 539 | |
| 540 | if (hard_iface->soft_iface != soft_iface) |
| 541 | continue; |
| 542 | |
| 543 | lower_header_len = max_t(unsigned short, lower_header_len, |
| 544 | hard_iface->net_dev->hard_header_len); |
| 545 | |
| 546 | lower_headroom = max_t(unsigned short, lower_headroom, |
| 547 | hard_iface->net_dev->needed_headroom); |
| 548 | |
| 549 | lower_tailroom = max_t(unsigned short, lower_tailroom, |
| 550 | hard_iface->net_dev->needed_tailroom); |
| 551 | } |
| 552 | rcu_read_unlock(); |
| 553 | |
| 554 | needed_headroom = lower_headroom + (lower_header_len - ETH_HLEN); |
| 555 | needed_headroom += batadv_max_header_len(); |
| 556 | |
| 557 | soft_iface->needed_headroom = needed_headroom; |
| 558 | soft_iface->needed_tailroom = lower_tailroom; |
| 559 | } |
| 560 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 561 | /** |
| 562 | * batadv_hardif_min_mtu() - Calculate maximum MTU for soft interface |
| 563 | * @soft_iface: netdev struct of the soft interface |
| 564 | * |
| 565 | * Return: MTU for the soft-interface (limited by the minimal MTU of all active |
| 566 | * slave interfaces) |
| 567 | */ |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 568 | int batadv_hardif_min_mtu(struct net_device *soft_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 569 | { |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 570 | struct batadv_priv *bat_priv = netdev_priv(soft_iface); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 571 | const struct batadv_hard_iface *hard_iface; |
Antonio Quartulli | 930cd6e | 2014-01-21 11:22:05 +0100 | [diff] [blame] | 572 | int min_mtu = INT_MAX; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 573 | |
| 574 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 575 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 576 | if (hard_iface->if_status != BATADV_IF_ACTIVE && |
| 577 | hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 578 | continue; |
| 579 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 580 | if (hard_iface->soft_iface != soft_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 581 | continue; |
| 582 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 583 | min_mtu = min_t(int, hard_iface->net_dev->mtu, min_mtu); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 584 | } |
| 585 | rcu_read_unlock(); |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 586 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 587 | if (atomic_read(&bat_priv->fragmentation) == 0) |
| 588 | goto out; |
| 589 | |
| 590 | /* with fragmentation enabled the maximum size of internally generated |
| 591 | * packets such as translation table exchanges or tvlv containers, etc |
| 592 | * has to be calculated |
| 593 | */ |
| 594 | min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE); |
| 595 | min_mtu -= sizeof(struct batadv_frag_packet); |
| 596 | min_mtu *= BATADV_FRAG_MAX_FRAGMENTS; |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 597 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 598 | out: |
Antonio Quartulli | 930cd6e | 2014-01-21 11:22:05 +0100 | [diff] [blame] | 599 | /* report to the other components the maximum amount of bytes that |
| 600 | * batman-adv can send over the wire (without considering the payload |
| 601 | * overhead). For example, this value is used by TT to compute the |
Sven Eckelmann | 21ba5ab | 2020-07-31 20:33:00 +0200 | [diff] [blame] | 602 | * maximum local table size |
Antonio Quartulli | 930cd6e | 2014-01-21 11:22:05 +0100 | [diff] [blame] | 603 | */ |
| 604 | atomic_set(&bat_priv->packet_size_max, min_mtu); |
| 605 | |
| 606 | /* the real soft-interface MTU is computed by removing the payload |
| 607 | * overhead from the maximum amount of bytes that was just computed. |
| 608 | * |
| 609 | * However batman-adv does not support MTUs bigger than ETH_DATA_LEN |
| 610 | */ |
| 611 | return min_t(int, min_mtu - batadv_max_header_len(), ETH_DATA_LEN); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 614 | /** |
| 615 | * batadv_update_min_mtu() - Adjusts the MTU if a new interface with a smaller |
| 616 | * MTU appeared |
| 617 | * @soft_iface: netdev struct of the soft interface |
| 618 | */ |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 619 | void batadv_update_min_mtu(struct net_device *soft_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 620 | { |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 621 | soft_iface->mtu = batadv_hardif_min_mtu(soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 622 | |
Marek Lindner | a19d3d8 | 2013-05-27 15:33:25 +0800 | [diff] [blame] | 623 | /* Check if the local translate table should be cleaned up to match a |
| 624 | * new (and smaller) MTU. |
| 625 | */ |
| 626 | batadv_tt_local_resize_to_mtu(soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 629 | static void |
| 630 | batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 631 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 632 | struct batadv_priv *bat_priv; |
| 633 | struct batadv_hard_iface *primary_if = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 634 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 635 | if (hard_iface->if_status != BATADV_IF_INACTIVE) |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 636 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 637 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 638 | bat_priv = netdev_priv(hard_iface->soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 639 | |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 640 | bat_priv->algo_ops->iface.update_mac(hard_iface); |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 641 | hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 642 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 643 | /* the first active interface becomes our primary interface or |
Antonio Quartulli | 015758d | 2011-07-09 17:52:13 +0200 | [diff] [blame] | 644 | * the next active interface after the old primary interface was removed |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 645 | */ |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 646 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 647 | if (!primary_if) |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 648 | batadv_primary_if_select(bat_priv, hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 649 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 650 | batadv_info(hard_iface->soft_iface, "Interface activated: %s\n", |
| 651 | hard_iface->net_dev->name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 652 | |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 653 | batadv_update_min_mtu(hard_iface->soft_iface); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 654 | |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 655 | if (bat_priv->algo_ops->iface.activate) |
| 656 | bat_priv->algo_ops->iface.activate(hard_iface); |
Antonio Quartulli | b6cf5d4 | 2016-04-14 09:37:05 +0800 | [diff] [blame] | 657 | |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 658 | out: |
| 659 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 660 | batadv_hardif_put(primary_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 663 | static void |
| 664 | batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 665 | { |
Sven Eckelmann | 825ffe1 | 2017-08-23 21:52:13 +0200 | [diff] [blame] | 666 | if (hard_iface->if_status != BATADV_IF_ACTIVE && |
| 667 | hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 668 | return; |
| 669 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 670 | hard_iface->if_status = BATADV_IF_INACTIVE; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 671 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 672 | batadv_info(hard_iface->soft_iface, "Interface deactivated: %s\n", |
| 673 | hard_iface->net_dev->name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 674 | |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 675 | batadv_update_min_mtu(hard_iface->soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Antonio Quartulli | cb4b0d4 | 2013-02-16 14:42:39 +0100 | [diff] [blame] | 678 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 679 | * batadv_master_del_slave() - remove hard_iface from the current master iface |
Antonio Quartulli | cb4b0d4 | 2013-02-16 14:42:39 +0100 | [diff] [blame] | 680 | * @slave: the interface enslaved in another master |
| 681 | * @master: the master from which slave has to be removed |
| 682 | * |
Sven Eckelmann | bccb48c | 2020-06-01 20:13:21 +0200 | [diff] [blame] | 683 | * Invoke ndo_del_slave on master passing slave as argument. In this way the |
| 684 | * slave is free'd and the master can correctly change its internal state. |
Sven Eckelmann | 62fe710 | 2015-09-15 19:00:48 +0200 | [diff] [blame] | 685 | * |
| 686 | * Return: 0 on success, a negative value representing the error otherwise |
Antonio Quartulli | cb4b0d4 | 2013-02-16 14:42:39 +0100 | [diff] [blame] | 687 | */ |
| 688 | static int batadv_master_del_slave(struct batadv_hard_iface *slave, |
| 689 | struct net_device *master) |
| 690 | { |
| 691 | int ret; |
| 692 | |
| 693 | if (!master) |
| 694 | return 0; |
| 695 | |
| 696 | ret = -EBUSY; |
| 697 | if (master->netdev_ops->ndo_del_slave) |
| 698 | ret = master->netdev_ops->ndo_del_slave(master, slave->net_dev); |
| 699 | |
| 700 | return ret; |
| 701 | } |
| 702 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 703 | /** |
| 704 | * batadv_hardif_enable_interface() - Enslave hard interface to soft interface |
| 705 | * @hard_iface: hard interface to add to soft interface |
| 706 | * @net: the applicable net namespace |
| 707 | * @iface_name: name of the soft interface |
| 708 | * |
| 709 | * Return: 0 on success or negative error number in case of failure |
| 710 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 711 | int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, |
Andrew Lunn | 2cd45a0 | 2016-04-21 12:57:27 +0200 | [diff] [blame] | 712 | struct net *net, const char *iface_name) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 713 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 714 | struct batadv_priv *bat_priv; |
Antonio Quartulli | cb4b0d4 | 2013-02-16 14:42:39 +0100 | [diff] [blame] | 715 | struct net_device *soft_iface, *master; |
Antonio Quartulli | 293e933 | 2013-05-19 12:55:16 +0200 | [diff] [blame] | 716 | __be16 ethertype = htons(ETH_P_BATMAN); |
Marek Lindner | 411d6ed | 2013-05-08 13:31:59 +0800 | [diff] [blame] | 717 | int max_header_len = batadv_max_header_len(); |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 718 | int ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 719 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 720 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 721 | goto out; |
| 722 | |
Sven Eckelmann | 17a8691 | 2016-04-11 13:06:40 +0200 | [diff] [blame] | 723 | kref_get(&hard_iface->refcount); |
Marek Lindner | ed75ccb | 2011-02-10 14:33:51 +0000 | [diff] [blame] | 724 | |
Andrew Lunn | 2cd45a0 | 2016-04-21 12:57:27 +0200 | [diff] [blame] | 725 | soft_iface = dev_get_by_name(net, iface_name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 726 | |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 727 | if (!soft_iface) { |
Andrew Lunn | 2cd45a0 | 2016-04-21 12:57:27 +0200 | [diff] [blame] | 728 | soft_iface = batadv_softif_create(net, iface_name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 729 | |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 730 | if (!soft_iface) { |
| 731 | ret = -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 732 | goto err; |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 733 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 734 | |
| 735 | /* dev_get_by_name() increases the reference counter for us */ |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 736 | dev_hold(soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Sven Eckelmann | 04b482a | 2012-05-12 02:09:38 +0200 | [diff] [blame] | 739 | if (!batadv_softif_is_valid(soft_iface)) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 740 | pr_err("Can't create batman mesh interface %s: already exists as regular interface\n", |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 741 | soft_iface->name); |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 742 | ret = -EINVAL; |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 743 | goto err_dev; |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Antonio Quartulli | cb4b0d4 | 2013-02-16 14:42:39 +0100 | [diff] [blame] | 746 | /* check if the interface is enslaved in another virtual one and |
| 747 | * in that case unlink it first |
| 748 | */ |
| 749 | master = netdev_master_upper_dev_get(hard_iface->net_dev); |
| 750 | ret = batadv_master_del_slave(hard_iface, master); |
| 751 | if (ret) |
| 752 | goto err_dev; |
| 753 | |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 754 | hard_iface->soft_iface = soft_iface; |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 755 | bat_priv = netdev_priv(hard_iface->soft_iface); |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 756 | |
Jiri Pirko | 6dffb04 | 2015-12-03 12:12:10 +0100 | [diff] [blame] | 757 | ret = netdev_master_upper_dev_link(hard_iface->net_dev, |
David Ahern | 42ab19e | 2017-10-04 17:48:47 -0700 | [diff] [blame] | 758 | soft_iface, NULL, NULL, NULL); |
Sven Eckelmann | 3dbd550 | 2013-02-11 17:10:27 +0800 | [diff] [blame] | 759 | if (ret) |
| 760 | goto err_dev; |
| 761 | |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 762 | ret = bat_priv->algo_ops->iface.enable(hard_iface); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 763 | if (ret < 0) |
Sven Eckelmann | 3dbd550 | 2013-02-11 17:10:27 +0800 | [diff] [blame] | 764 | goto err_upper; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 765 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 766 | hard_iface->if_status = BATADV_IF_INACTIVE; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 767 | |
Sven Eckelmann | d7d6de9 | 2016-03-05 16:09:18 +0100 | [diff] [blame] | 768 | kref_get(&hard_iface->refcount); |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 769 | hard_iface->batman_adv_ptype.type = ethertype; |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 770 | hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv; |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 771 | hard_iface->batman_adv_ptype.dev = hard_iface->net_dev; |
| 772 | dev_add_pack(&hard_iface->batman_adv_ptype); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 773 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 774 | batadv_info(hard_iface->soft_iface, "Adding interface: %s\n", |
| 775 | hard_iface->net_dev->name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 776 | |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 777 | if (atomic_read(&bat_priv->fragmentation) && |
Marek Lindner | 411d6ed | 2013-05-08 13:31:59 +0800 | [diff] [blame] | 778 | hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len) |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 779 | batadv_info(hard_iface->soft_iface, |
Marek Lindner | 411d6ed | 2013-05-08 13:31:59 +0800 | [diff] [blame] | 780 | "The MTU of interface %s is too small (%i) to handle the transport of batman-adv packets. Packets going over this interface will be fragmented on layer2 which could impact the performance. Setting the MTU to %i would solve the problem.\n", |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 781 | hard_iface->net_dev->name, hard_iface->net_dev->mtu, |
Marek Lindner | 411d6ed | 2013-05-08 13:31:59 +0800 | [diff] [blame] | 782 | ETH_DATA_LEN + max_header_len); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 783 | |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 784 | if (!atomic_read(&bat_priv->fragmentation) && |
Marek Lindner | 411d6ed | 2013-05-08 13:31:59 +0800 | [diff] [blame] | 785 | hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len) |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 786 | batadv_info(hard_iface->soft_iface, |
Marek Lindner | 411d6ed | 2013-05-08 13:31:59 +0800 | [diff] [blame] | 787 | "The MTU of interface %s is too small (%i) to handle the transport of batman-adv packets. If you experience problems getting traffic through try increasing the MTU to %i.\n", |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 788 | hard_iface->net_dev->name, hard_iface->net_dev->mtu, |
Marek Lindner | 411d6ed | 2013-05-08 13:31:59 +0800 | [diff] [blame] | 789 | ETH_DATA_LEN + max_header_len); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 790 | |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 791 | if (batadv_hardif_is_iface_up(hard_iface)) |
| 792 | batadv_hardif_activate_interface(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 793 | else |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 794 | batadv_err(hard_iface->soft_iface, |
| 795 | "Not using interface %s (retrying later): interface not active\n", |
| 796 | hard_iface->net_dev->name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 797 | |
Sven Eckelmann | 7bca68c | 2015-08-07 19:28:42 +0200 | [diff] [blame] | 798 | batadv_hardif_recalc_extra_skbroom(soft_iface); |
| 799 | |
Sven Eckelmann | 9e6b564 | 2019-06-02 10:57:31 +0200 | [diff] [blame] | 800 | if (bat_priv->algo_ops->iface.enabled) |
| 801 | bat_priv->algo_ops->iface.enabled(hard_iface); |
| 802 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 803 | out: |
| 804 | return 0; |
| 805 | |
Sven Eckelmann | 3dbd550 | 2013-02-11 17:10:27 +0800 | [diff] [blame] | 806 | err_upper: |
| 807 | netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface); |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 808 | err_dev: |
Sven Eckelmann | 3dbd550 | 2013-02-11 17:10:27 +0800 | [diff] [blame] | 809 | hard_iface->soft_iface = NULL; |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 810 | dev_put(soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 811 | err: |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 812 | batadv_hardif_put(hard_iface); |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 813 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 816 | /** |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 817 | * batadv_hardif_cnt() - get number of interfaces enslaved to soft interface |
| 818 | * @soft_iface: soft interface to check |
| 819 | * |
| 820 | * This function is only using RCU for locking - the result can therefore be |
Sven Eckelmann | bccb48c | 2020-06-01 20:13:21 +0200 | [diff] [blame] | 821 | * off when another function is modifying the list at the same time. The |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 822 | * caller can use the rtnl_lock to make sure that the count is accurate. |
| 823 | * |
| 824 | * Return: number of connected/enslaved hard interfaces |
| 825 | */ |
| 826 | static size_t batadv_hardif_cnt(const struct net_device *soft_iface) |
| 827 | { |
| 828 | struct batadv_hard_iface *hard_iface; |
| 829 | size_t count = 0; |
| 830 | |
| 831 | rcu_read_lock(); |
| 832 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
| 833 | if (hard_iface->soft_iface != soft_iface) |
| 834 | continue; |
| 835 | |
| 836 | count++; |
| 837 | } |
| 838 | rcu_read_unlock(); |
| 839 | |
| 840 | return count; |
| 841 | } |
| 842 | |
| 843 | /** |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 844 | * batadv_hardif_disable_interface() - Remove hard interface from soft interface |
| 845 | * @hard_iface: hard interface to be removed |
| 846 | * @autodel: whether to delete soft interface when it doesn't contain any other |
| 847 | * slave interfaces |
| 848 | */ |
Sven Eckelmann | a15fd36 | 2013-02-11 17:10:24 +0800 | [diff] [blame] | 849 | void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface, |
| 850 | enum batadv_hard_if_cleanup autodel) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 851 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 852 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
| 853 | struct batadv_hard_iface *primary_if = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 854 | |
Sven Eckelmann | f2d2386 | 2016-03-19 13:55:21 +0100 | [diff] [blame] | 855 | batadv_hardif_deactivate_interface(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 856 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 857 | if (hard_iface->if_status != BATADV_IF_INACTIVE) |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 858 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 859 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 860 | batadv_info(hard_iface->soft_iface, "Removing interface: %s\n", |
| 861 | hard_iface->net_dev->name); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 862 | dev_remove_pack(&hard_iface->batman_adv_ptype); |
Sven Eckelmann | d7d6de9 | 2016-03-05 16:09:18 +0100 | [diff] [blame] | 863 | batadv_hardif_put(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 864 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 865 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 866 | if (hard_iface == primary_if) { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 867 | struct batadv_hard_iface *new_if; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 868 | |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 869 | new_if = batadv_hardif_get_active(hard_iface->soft_iface); |
| 870 | batadv_primary_if_select(bat_priv, new_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 871 | |
| 872 | if (new_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 873 | batadv_hardif_put(new_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 876 | bat_priv->algo_ops->iface.disable(hard_iface); |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 877 | hard_iface->if_status = BATADV_IF_NOT_IN_USE; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 878 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 879 | /* delete all references to this hard_iface */ |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 880 | batadv_purge_orig_ref(bat_priv); |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 881 | batadv_purge_outstanding_packets(bat_priv, hard_iface); |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 882 | dev_put(hard_iface->soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 883 | |
Antonio Quartulli | a5256f7 | 2015-08-04 22:26:19 +0200 | [diff] [blame] | 884 | netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface); |
Sven Eckelmann | 7bca68c | 2015-08-07 19:28:42 +0200 | [diff] [blame] | 885 | batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface); |
Antonio Quartulli | a5256f7 | 2015-08-04 22:26:19 +0200 | [diff] [blame] | 886 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 887 | /* nobody uses this interface anymore */ |
Sven Eckelmann | dee222c7 | 2018-08-16 16:54:45 +0200 | [diff] [blame] | 888 | if (batadv_hardif_cnt(hard_iface->soft_iface) <= 1) { |
Antonio Quartulli | 8257f55 | 2013-08-19 18:39:59 +0200 | [diff] [blame] | 889 | batadv_gw_check_client_stop(bat_priv); |
| 890 | |
| 891 | if (autodel == BATADV_IF_CLEANUP_AUTO) |
| 892 | batadv_softif_destroy_sysfs(hard_iface->soft_iface); |
| 893 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 894 | |
Sven Eckelmann | 27915aa | 2016-11-02 18:14:43 +0100 | [diff] [blame] | 895 | hard_iface->soft_iface = NULL; |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 896 | batadv_hardif_put(hard_iface); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 897 | |
| 898 | out: |
| 899 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 900 | batadv_hardif_put(primary_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 903 | static struct batadv_hard_iface * |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 904 | batadv_hardif_add_interface(struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 905 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 906 | struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 907 | int ret; |
| 908 | |
Sven Eckelmann | c3caf51 | 2011-05-03 11:51:38 +0200 | [diff] [blame] | 909 | ASSERT_RTNL(); |
| 910 | |
Sven Eckelmann | 4b426b1 | 2016-02-22 21:02:39 +0100 | [diff] [blame] | 911 | if (!batadv_is_valid_iface(net_dev)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 912 | goto out; |
| 913 | |
| 914 | dev_hold(net_dev); |
| 915 | |
Antonio Quartulli | 7db3fc2 | 2013-04-02 12:16:53 +0200 | [diff] [blame] | 916 | hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC); |
Joe Perches | 320f422 | 2011-08-29 14:17:24 -0700 | [diff] [blame] | 917 | if (!hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 918 | goto release_dev; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 919 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 920 | ret = batadv_sysfs_add_hardif(&hard_iface->hardif_obj, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 921 | if (ret) |
| 922 | goto free_if; |
| 923 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 924 | hard_iface->net_dev = net_dev; |
| 925 | hard_iface->soft_iface = NULL; |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 926 | hard_iface->if_status = BATADV_IF_NOT_IN_USE; |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 927 | |
Greg Kroah-Hartman | 3bcacd1 | 2019-06-14 09:11:23 +0200 | [diff] [blame] | 928 | batadv_debugfs_add_hardif(hard_iface); |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 929 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 930 | INIT_LIST_HEAD(&hard_iface->list); |
Marek Lindner | cef6341 | 2015-08-04 21:09:55 +0800 | [diff] [blame] | 931 | INIT_HLIST_HEAD(&hard_iface->neigh_list); |
Simon Wunderlich | 5bc44dc | 2013-01-11 10:19:51 +0100 | [diff] [blame] | 932 | |
Sven Eckelmann | 40e220b | 2019-10-03 17:02:01 +0200 | [diff] [blame] | 933 | mutex_init(&hard_iface->bat_iv.ogm_buff_mutex); |
Marek Lindner | cef6341 | 2015-08-04 21:09:55 +0800 | [diff] [blame] | 934 | spin_lock_init(&hard_iface->neigh_list_lock); |
Sven Eckelmann | b2367e4 | 2016-07-15 17:39:28 +0200 | [diff] [blame] | 935 | kref_init(&hard_iface->refcount); |
Marek Lindner | cef6341 | 2015-08-04 21:09:55 +0800 | [diff] [blame] | 936 | |
Matthias Schiffer | caf65bf | 2013-03-09 23:14:23 +0100 | [diff] [blame] | 937 | hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT; |
Sven Eckelmann | 10b1bbb | 2016-09-30 15:21:03 +0200 | [diff] [blame] | 938 | hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev); |
| 939 | if (batadv_is_wifi_hardif(hard_iface)) |
Matthias Schiffer | caf65bf | 2013-03-09 23:14:23 +0100 | [diff] [blame] | 940 | hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS; |
| 941 | |
Linus Lüssing | 3bda14d | 2020-06-01 22:35:22 +0200 | [diff] [blame] | 942 | atomic_set(&hard_iface->hop_penalty, 0); |
| 943 | |
Marek Lindner | 7db682d | 2016-05-10 22:31:59 +0800 | [diff] [blame] | 944 | batadv_v_hardif_init(hard_iface); |
| 945 | |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 946 | batadv_check_known_mac_addr(hard_iface->net_dev); |
Sven Eckelmann | b2367e4 | 2016-07-15 17:39:28 +0200 | [diff] [blame] | 947 | kref_get(&hard_iface->refcount); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 948 | list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list); |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 949 | batadv_hardif_generation++; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 950 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 951 | return hard_iface; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 952 | |
| 953 | free_if: |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 954 | kfree(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 955 | release_dev: |
| 956 | dev_put(net_dev); |
| 957 | out: |
| 958 | return NULL; |
| 959 | } |
| 960 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 961 | static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 962 | { |
Sven Eckelmann | c3caf51 | 2011-05-03 11:51:38 +0200 | [diff] [blame] | 963 | ASSERT_RTNL(); |
| 964 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 965 | /* first deactivate interface */ |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 966 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) |
Sven Eckelmann | a15fd36 | 2013-02-11 17:10:24 +0800 | [diff] [blame] | 967 | batadv_hardif_disable_interface(hard_iface, |
Sven Eckelmann | 06d640c | 2016-07-10 15:47:57 +0200 | [diff] [blame] | 968 | BATADV_IF_CLEANUP_KEEP); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 969 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 970 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 971 | return; |
| 972 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 973 | hard_iface->if_status = BATADV_IF_TO_BE_REMOVED; |
Sven Eckelmann | 569c985 | 2016-06-13 07:41:31 +0200 | [diff] [blame] | 974 | batadv_debugfs_del_hardif(hard_iface); |
| 975 | batadv_sysfs_del_hardif(&hard_iface->hardif_obj); |
| 976 | batadv_hardif_put(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 979 | /** |
Sven Eckelmann | 6da7be7 | 2018-06-01 19:24:24 +0200 | [diff] [blame] | 980 | * batadv_hard_if_event_softif() - Handle events for soft interfaces |
| 981 | * @event: NETDEV_* event to handle |
| 982 | * @net_dev: net_device which generated an event |
| 983 | * |
| 984 | * Return: NOTIFY_* result |
| 985 | */ |
| 986 | static int batadv_hard_if_event_softif(unsigned long event, |
| 987 | struct net_device *net_dev) |
| 988 | { |
| 989 | struct batadv_priv *bat_priv; |
| 990 | |
| 991 | switch (event) { |
| 992 | case NETDEV_REGISTER: |
| 993 | batadv_sysfs_add_meshif(net_dev); |
| 994 | bat_priv = netdev_priv(net_dev); |
| 995 | batadv_softif_create_vlan(bat_priv, BATADV_NO_FLAGS); |
| 996 | break; |
| 997 | case NETDEV_CHANGENAME: |
| 998 | batadv_debugfs_rename_meshif(net_dev); |
| 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | return NOTIFY_DONE; |
| 1003 | } |
| 1004 | |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 1005 | static int batadv_hard_if_event(struct notifier_block *this, |
| 1006 | unsigned long event, void *ptr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1007 | { |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 1008 | struct net_device *net_dev = netdev_notifier_info_to_dev(ptr); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1009 | struct batadv_hard_iface *hard_iface; |
| 1010 | struct batadv_hard_iface *primary_if = NULL; |
| 1011 | struct batadv_priv *bat_priv; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1012 | |
Sven Eckelmann | 6da7be7 | 2018-06-01 19:24:24 +0200 | [diff] [blame] | 1013 | if (batadv_softif_is_valid(net_dev)) |
| 1014 | return batadv_hard_if_event_softif(event, net_dev); |
Sven Eckelmann | 3713029 | 2013-02-11 17:10:22 +0800 | [diff] [blame] | 1015 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1016 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
Andrew Lunn | a1a66b1 | 2015-12-03 21:12:33 +0100 | [diff] [blame] | 1017 | if (!hard_iface && (event == NETDEV_REGISTER || |
| 1018 | event == NETDEV_POST_TYPE_CHANGE)) |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 1019 | hard_iface = batadv_hardif_add_interface(net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1020 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 1021 | if (!hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1022 | goto out; |
| 1023 | |
| 1024 | switch (event) { |
| 1025 | case NETDEV_UP: |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 1026 | batadv_hardif_activate_interface(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1027 | break; |
| 1028 | case NETDEV_GOING_DOWN: |
| 1029 | case NETDEV_DOWN: |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 1030 | batadv_hardif_deactivate_interface(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1031 | break; |
| 1032 | case NETDEV_UNREGISTER: |
Andrew Lunn | a1a66b1 | 2015-12-03 21:12:33 +0100 | [diff] [blame] | 1033 | case NETDEV_PRE_TYPE_CHANGE: |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 1034 | list_del_rcu(&hard_iface->list); |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 1035 | batadv_hardif_generation++; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1036 | |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 1037 | batadv_hardif_remove_interface(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1038 | break; |
| 1039 | case NETDEV_CHANGEMTU: |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 1040 | if (hard_iface->soft_iface) |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 1041 | batadv_update_min_mtu(hard_iface->soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1042 | break; |
| 1043 | case NETDEV_CHANGEADDR: |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 1044 | if (hard_iface->if_status == BATADV_IF_NOT_IN_USE) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1045 | goto hardif_put; |
| 1046 | |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 1047 | batadv_check_known_mac_addr(hard_iface->net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1048 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 1049 | bat_priv = netdev_priv(hard_iface->soft_iface); |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 1050 | bat_priv->algo_ops->iface.update_mac(hard_iface); |
Marek Lindner | 01c4224 | 2011-11-28 21:31:55 +0800 | [diff] [blame] | 1051 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 1052 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 1053 | if (!primary_if) |
| 1054 | goto hardif_put; |
| 1055 | |
| 1056 | if (hard_iface == primary_if) |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 1057 | batadv_primary_if_update_addr(bat_priv, NULL); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1058 | break; |
Sven Eckelmann | ee3b5e9 | 2016-09-30 15:21:06 +0200 | [diff] [blame] | 1059 | case NETDEV_CHANGEUPPER: |
| 1060 | hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev); |
| 1061 | if (batadv_is_wifi_hardif(hard_iface)) |
| 1062 | hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS; |
| 1063 | break; |
Sven Eckelmann | 36dc621 | 2018-06-01 19:24:23 +0200 | [diff] [blame] | 1064 | case NETDEV_CHANGENAME: |
| 1065 | batadv_debugfs_rename_hardif(hard_iface); |
| 1066 | break; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1067 | default: |
| 1068 | break; |
Joe Perches | f81c622 | 2011-06-03 11:51:19 +0000 | [diff] [blame] | 1069 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1070 | |
| 1071 | hardif_put: |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 1072 | batadv_hardif_put(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1073 | out: |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 1074 | if (primary_if) |
Sven Eckelmann | 82047ad | 2016-01-17 11:01:10 +0100 | [diff] [blame] | 1075 | batadv_hardif_put(primary_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1076 | return NOTIFY_DONE; |
| 1077 | } |
| 1078 | |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 1079 | struct notifier_block batadv_hard_if_notifier = { |
Sven Eckelmann | 18a1cb6 | 2012-05-12 18:33:57 +0200 | [diff] [blame] | 1080 | .notifier_call = batadv_hard_if_event, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1081 | }; |