blob: 33904595fc56a1e512edd5f217ff602f5a9744fe [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001// SPDX-License-Identifier: GPL-2.0
Sven Eckelmann68e039f2020-01-01 00:00:01 +01002/* Copyright (C) 2007-2020 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner, Simon Wunderlich
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00005 */
6
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00007#include "hard-interface.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +02008#include "main.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00009
Sven Eckelmann7a659d52016-01-16 10:29:54 +010010#include <linux/atomic.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020011#include <linux/byteorder/generic.h>
12#include <linux/errno.h>
Sven Eckelmannb92b94a2017-11-19 17:12:02 +010013#include <linux/gfp.h>
Sven Eckelmannfcafa5e2016-05-15 11:07:42 +020014#include <linux/if.h>
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000015#include <linux/if_arp.h>
Antonio Quartulliaf5d4f72012-11-26 00:38:50 +010016#include <linux/if_ether.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020017#include <linux/kernel.h>
Sven Eckelmann7a659d52016-01-16 10:29:54 +010018#include <linux/kref.h>
Sven Eckelmanne1928752019-05-24 16:28:50 +020019#include <linux/limits.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020020#include <linux/list.h>
Sven Eckelmann40e220b2019-10-03 17:02:01 +020021#include <linux/mutex.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020022#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 Lindnercef63412015-08-04 21:09:55 +080027#include <linux/spinlock.h>
Andrew Lunn275019d2016-07-03 13:31:33 +020028#include <net/net_namespace.h>
29#include <net/rtnetlink.h>
Sven Eckelmannfec149f2017-12-21 10:17:41 +010030#include <uapi/linux/batadv_packet.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020031
Sven Eckelmanna2d08162016-05-15 11:07:46 +020032#include "bat_v.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020033#include "bridge_loop_avoidance.h"
34#include "debugfs.h"
35#include "distributed-arp-table.h"
36#include "gateway_client.h"
Sven Eckelmannba412082016-05-15 23:48:31 +020037#include "log.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020038#include "originator.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020039#include "send.h"
40#include "soft-interface.h"
41#include "sysfs.h"
42#include "translation-table.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000043
Sven Eckelmann140ed8e2016-01-05 12:06:26 +010044/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010045 * batadv_hardif_release() - release hard interface from lists and queue for
Sven Eckelmann140ed8e2016-01-05 12:06:26 +010046 * free after rcu grace period
Sven Eckelmann7a659d52016-01-16 10:29:54 +010047 * @ref: kref pointer of the hard interface
Sven Eckelmann140ed8e2016-01-05 12:06:26 +010048 */
Sven Eckelmann7a659d52016-01-16 10:29:54 +010049void batadv_hardif_release(struct kref *ref)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000050{
Sven Eckelmann7a659d52016-01-16 10:29:54 +010051 struct batadv_hard_iface *hard_iface;
52
53 hard_iface = container_of(ref, struct batadv_hard_iface, refcount);
Marek Lindnere6c10f42011-02-18 12:33:20 +000054 dev_put(hard_iface->net_dev);
Sven Eckelmann140ed8e2016-01-05 12:06:26 +010055
56 kfree_rcu(hard_iface, rcu);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000057}
58
Sven Eckelmannff15c272017-12-02 19:51:53 +010059/**
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 Eckelmann56303d32012-06-05 22:31:31 +020065struct batadv_hard_iface *
66batadv_hardif_get_by_netdev(const struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000067{
Sven Eckelmann56303d32012-06-05 22:31:31 +020068 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000069
70 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +020071 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Marek Lindnere6c10f42011-02-18 12:33:20 +000072 if (hard_iface->net_dev == net_dev &&
Sven Eckelmann7a659d52016-01-16 10:29:54 +010073 kref_get_unless_zero(&hard_iface->refcount))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000074 goto out;
75 }
76
Marek Lindnere6c10f42011-02-18 12:33:20 +000077 hard_iface = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000078
79out:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000080 rcu_read_unlock();
Marek Lindnere6c10f42011-02-18 12:33:20 +000081 return hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000082}
83
Antonio Quartullib7eddd02012-09-09 10:46:46 +020084/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010085 * batadv_getlink_net() - return link net namespace (of use fallback)
Andrew Lunn275019d2016-07-03 13:31:33 +020086 * @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 Eckelmann88ffc7d2016-09-30 15:21:00 +020091static struct net *batadv_getlink_net(const struct net_device *netdev,
92 struct net *fallback_net)
Andrew Lunn275019d2016-07-03 13:31:33 +020093{
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 Eckelmann7e9a8c22017-12-02 19:51:47 +0100104 * batadv_mutual_parents() - check if two devices are each others parent
Andrew Lunn275019d2016-07-03 13:31:33 +0200105 * @dev1: 1st net dev
106 * @net1: 1st devices netns
107 * @dev2: 2nd net dev
108 * @net2: 2nd devices netns
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100109 *
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 */
114static bool batadv_mutual_parents(const struct net_device *dev1,
Sven Eckelmann88ffc7d2016-09-30 15:21:00 +0200115 struct net *net1,
Andrew Lunn275019d2016-07-03 13:31:33 +0200116 const struct net_device *dev2,
Sven Eckelmann88ffc7d2016-09-30 15:21:00 +0200117 struct net *net2)
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100118{
119 int dev1_parent_iflink = dev_get_iflink(dev1);
120 int dev2_parent_iflink = dev_get_iflink(dev2);
Andrew Lunn275019d2016-07-03 13:31:33 +0200121 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 Lunn1bc4e2b2016-02-11 22:15:57 +0100126
127 if (!dev1_parent_iflink || !dev2_parent_iflink)
128 return false;
129
130 return (dev1_parent_iflink == dev2->ifindex) &&
Andrew Lunn275019d2016-07-03 13:31:33 +0200131 (dev2_parent_iflink == dev1->ifindex) &&
132 net_eq(dev1_parent_net, net2) &&
133 net_eq(dev2_parent_net, net1);
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100134}
135
136/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100137 * batadv_is_on_batman_iface() - check if a device is a batman iface descendant
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200138 * @net_dev: the device to check
139 *
140 * If the user creates any virtual device on top of a batman-adv interface, it
Sven Eckelmannbccb48c2020-06-01 20:13:21 +0200141 * 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 Quartullib7eddd02012-09-09 10:46:46 +0200145 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +0200146 * Return: true if the device is descendant of a batman-adv mesh interface (or
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200147 * if it is a batman-adv interface itself), false otherwise
148 */
149static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
150{
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200151 struct net *net = dev_net(net_dev);
Andrew Lunn275019d2016-07-03 13:31:33 +0200152 struct net_device *parent_dev;
Sven Eckelmann88ffc7d2016-09-30 15:21:00 +0200153 struct net *parent_net;
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200154 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 Dichtela54acb32015-04-02 17:07:00 +0200161 if (dev_get_iflink(net_dev) == 0 ||
162 dev_get_iflink(net_dev) == net_dev->ifindex)
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200163 return false;
164
Andrew Lunn275019d2016-07-03 13:31:33 +0200165 parent_net = batadv_getlink_net(net_dev, net);
166
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200167 /* recurse over the parent device */
Andrew Lunn275019d2016-07-03 13:31:33 +0200168 parent_dev = __dev_get_by_index((struct net *)parent_net,
169 dev_get_iflink(net_dev));
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200170 /* if we got a NULL parent_dev there is something broken.. */
Sven Eckelmann955d3412018-12-30 12:46:01 +0100171 if (!parent_dev) {
172 pr_err("Cannot find parent device\n");
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200173 return false;
Sven Eckelmann955d3412018-12-30 12:46:01 +0100174 }
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200175
Andrew Lunn275019d2016-07-03 13:31:33 +0200176 if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net))
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100177 return false;
178
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200179 ret = batadv_is_on_batman_iface(parent_dev);
180
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200181 return ret;
182}
183
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100184static bool batadv_is_valid_iface(const struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000185{
186 if (net_dev->flags & IFF_LOOPBACK)
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100187 return false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000188
189 if (net_dev->type != ARPHRD_ETHER)
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100190 return false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000191
192 if (net_dev->addr_len != ETH_ALEN)
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100193 return false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000194
195 /* no batman over batman */
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200196 if (batadv_is_on_batman_iface(net_dev))
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100197 return false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000198
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100199 return true;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000200}
201
Matthias Schifferde68d102013-03-09 23:14:22 +0100202/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100203 * batadv_get_real_netdevice() - check if the given netdev struct is a virtual
Marek Lindner5ed4a462016-09-30 15:21:04 +0200204 * interface on top of another 'real' interface
205 * @netdev: the device to check
206 *
Marek Lindner1942de12016-09-30 15:21:05 +0200207 * Callers must hold the rtnl semaphore. You may want batadv_get_real_netdev()
208 * instead of this.
209 *
Marek Lindner5ed4a462016-09-30 15:21:04 +0200210 * Return: the 'real' net device or the original net device and NULL in case
211 * of an error.
212 */
213static 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
240out:
241 if (hard_iface)
242 batadv_hardif_put(hard_iface);
243 return real_netdev;
244}
245
246/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100247 * batadv_get_real_netdev() - check if the given net_device struct is a virtual
Marek Lindner1942de12016-09-30 15:21:05 +0200248 * interface on top of another 'real' interface
Matthias Schifferde68d102013-03-09 23:14:22 +0100249 * @net_device: the device to check
250 *
Marek Lindner1942de12016-09-30 15:21:05 +0200251 * Return: the 'real' net device or the original net device and NULL in case
252 * of an error.
Matthias Schifferde68d102013-03-09 23:14:22 +0100253 */
Marek Lindner1942de12016-09-30 15:21:05 +0200254struct 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 Eckelmann7e9a8c22017-12-02 19:51:47 +0100266 * batadv_is_wext_netdev() - check if the given net_device struct is a
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200267 * wext wifi interface
Marek Lindnerf44a3ae2016-09-30 15:21:02 +0200268 * @net_device: the device to check
269 *
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200270 * Return: true if the net device is a wext wireless device, false
Marek Lindnerf44a3ae2016-09-30 15:21:02 +0200271 * otherwise.
272 */
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200273static bool batadv_is_wext_netdev(struct net_device *net_device)
Matthias Schifferde68d102013-03-09 23:14:22 +0100274{
Antonio Quartulli0c69aec2013-10-13 02:50:18 +0200275 if (!net_device)
276 return false;
277
Matthias Schifferde68d102013-03-09 23:14:22 +0100278#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 Eckelmann10b1bbb2016-09-30 15:21:03 +0200286 return false;
287}
288
289/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100290 * batadv_is_cfg80211_netdev() - check if the given net_device struct is a
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200291 * 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 */
297static bool batadv_is_cfg80211_netdev(struct net_device *net_device)
298{
299 if (!net_device)
300 return false;
301
Matthias Schifferde68d102013-03-09 23:14:22 +0100302 /* cfg80211 drivers have to set ieee80211_ptr */
303 if (net_device->ieee80211_ptr)
304 return true;
305
306 return false;
307}
308
Linus Lüssing3111bee2016-08-07 12:34:19 +0200309/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100310 * batadv_wifi_flags_evaluate() - calculate wifi flags for net_device
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200311 * @net_device: the device to check
312 *
313 * Return: batadv_hard_iface_wifi_flags flags of the device
314 */
315static u32 batadv_wifi_flags_evaluate(struct net_device *net_device)
316{
317 u32 wifi_flags = 0;
Marek Lindner5ed4a462016-09-30 15:21:04 +0200318 struct net_device *real_netdev;
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200319
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 Lindner5ed4a462016-09-30 15:21:04 +0200326 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
339out:
340 dev_put(real_netdev);
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200341 return wifi_flags;
342}
343
344/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100345 * batadv_is_cfg80211_hardif() - check if the given hardif is a cfg80211 wifi
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200346 * 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 */
352bool 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 Lindner5ed4a462016-09-30 15:21:04 +0200357 allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_INDIRECT;
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200358
359 return !!(hard_iface->wifi_flags & allowed_flags);
360}
361
362/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100363 * batadv_is_wifi_hardif() - check if the given hardif is a wifi interface
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200364 * @hard_iface: the device to check
365 *
366 * Return: true if the net device is a 802.11 wireless device, false otherwise.
367 */
368bool 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 Schifferde68d102013-03-09 23:14:22 +0100374}
375
Linus Lüssing3111bee2016-08-07 12:34:19 +0200376/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100377 * batadv_hardif_no_broadcast() - check whether (re)broadcast is necessary
Linus Lüssing3111bee2016-08-07 12:34:19 +0200378 * @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 */
391int 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
423out:
424 rcu_read_unlock();
425 return ret;
426}
427
Sven Eckelmann56303d32012-06-05 22:31:31 +0200428static struct batadv_hard_iface *
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200429batadv_hardif_get_active(const struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000430{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200431 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000432
433 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200434 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Marek Lindnere6c10f42011-02-18 12:33:20 +0000435 if (hard_iface->soft_iface != soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000436 continue;
437
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200438 if (hard_iface->if_status == BATADV_IF_ACTIVE &&
Sven Eckelmann7a659d52016-01-16 10:29:54 +0100439 kref_get_unless_zero(&hard_iface->refcount))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000440 goto out;
441 }
442
Marek Lindnere6c10f42011-02-18 12:33:20 +0000443 hard_iface = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000444
445out:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000446 rcu_read_unlock();
Marek Lindnere6c10f42011-02-18 12:33:20 +0000447 return hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000448}
449
Sven Eckelmann56303d32012-06-05 22:31:31 +0200450static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,
451 struct batadv_hard_iface *oldif)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000452{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200453 struct batadv_hard_iface *primary_if;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200454
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200455 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200456 if (!primary_if)
457 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000458
Antonio Quartulli785ea112011-11-23 11:35:44 +0100459 batadv_dat_init_own_addr(bat_priv, primary_if);
Sven Eckelmann08adf152012-05-12 13:38:47 +0200460 batadv_bla_update_orig_address(bat_priv, primary_if, oldif);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200461out:
462 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100463 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000464}
465
Sven Eckelmann56303d32012-06-05 22:31:31 +0200466static void batadv_primary_if_select(struct batadv_priv *bat_priv,
467 struct batadv_hard_iface *new_hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000468{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200469 struct batadv_hard_iface *curr_hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000470
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200471 ASSERT_RTNL();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000472
Sven Eckelmann17a86912016-04-11 13:06:40 +0200473 if (new_hard_iface)
474 kref_get(&new_hard_iface->refcount);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000475
Antonio Quartullicf78bb02020-05-20 10:41:40 +0200476 curr_hard_iface = rcu_replace_pointer(bat_priv->primary_if,
477 new_hard_iface, 1);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000478
Marek Lindner32ae9b22011-04-20 15:40:58 +0200479 if (!new_hard_iface)
Simon Wunderlich23721382012-01-22 20:00:19 +0100480 goto out;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200481
Antonio Quartulli29824a52016-05-25 23:27:31 +0800482 bat_priv->algo_ops->iface.primary_set(new_hard_iface);
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200483 batadv_primary_if_update_addr(bat_priv, curr_hard_iface);
Simon Wunderlich23721382012-01-22 20:00:19 +0100484
485out:
486 if (curr_hard_iface)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100487 batadv_hardif_put(curr_hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000488}
489
Sven Eckelmann56303d32012-06-05 22:31:31 +0200490static bool
491batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000492{
Marek Lindnere6c10f42011-02-18 12:33:20 +0000493 if (hard_iface->net_dev->flags & IFF_UP)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000494 return true;
495
496 return false;
497}
498
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200499static void batadv_check_known_mac_addr(const struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000500{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200501 const struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000502
503 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200504 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200505 if (hard_iface->if_status != BATADV_IF_ACTIVE &&
506 hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000507 continue;
508
Marek Lindnere6c10f42011-02-18 12:33:20 +0000509 if (hard_iface->net_dev == net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000510 continue;
511
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200512 if (!batadv_compare_eth(hard_iface->net_dev->dev_addr,
513 net_dev->dev_addr))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000514 continue;
515
Sven Eckelmann67969582012-03-26 16:22:45 +0200516 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 Eckelmannc6c8fea2010-12-13 11:19:28 +0000519 }
520 rcu_read_unlock();
521}
522
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200523/**
524 * batadv_hardif_recalc_extra_skbroom() - Recalculate skbuff extra head/tailroom
525 * @soft_iface: netdev struct of the mesh interface
526 */
527static 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
Sven Eckelmann4ca23e22020-11-26 18:15:06 +0100557 /* fragmentation headers don't strip the unicast/... header */
558 needed_headroom += sizeof(struct batadv_frag_packet);
559
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200560 soft_iface->needed_headroom = needed_headroom;
561 soft_iface->needed_tailroom = lower_tailroom;
562}
563
Sven Eckelmannff15c272017-12-02 19:51:53 +0100564/**
565 * batadv_hardif_min_mtu() - Calculate maximum MTU for soft interface
566 * @soft_iface: netdev struct of the soft interface
567 *
568 * Return: MTU for the soft-interface (limited by the minimal MTU of all active
569 * slave interfaces)
570 */
Sven Eckelmann95638772012-05-12 02:09:31 +0200571int batadv_hardif_min_mtu(struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000572{
Marek Lindnera19d3d82013-05-27 15:33:25 +0800573 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200574 const struct batadv_hard_iface *hard_iface;
Antonio Quartulli930cd6e2014-01-21 11:22:05 +0100575 int min_mtu = INT_MAX;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000576
577 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200578 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200579 if (hard_iface->if_status != BATADV_IF_ACTIVE &&
580 hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000581 continue;
582
Marek Lindnere6c10f42011-02-18 12:33:20 +0000583 if (hard_iface->soft_iface != soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000584 continue;
585
Marek Lindnera19d3d82013-05-27 15:33:25 +0800586 min_mtu = min_t(int, hard_iface->net_dev->mtu, min_mtu);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000587 }
588 rcu_read_unlock();
Marek Lindnera19d3d82013-05-27 15:33:25 +0800589
Marek Lindnera19d3d82013-05-27 15:33:25 +0800590 if (atomic_read(&bat_priv->fragmentation) == 0)
591 goto out;
592
593 /* with fragmentation enabled the maximum size of internally generated
594 * packets such as translation table exchanges or tvlv containers, etc
595 * has to be calculated
596 */
597 min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE);
598 min_mtu -= sizeof(struct batadv_frag_packet);
599 min_mtu *= BATADV_FRAG_MAX_FRAGMENTS;
Marek Lindnera19d3d82013-05-27 15:33:25 +0800600
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000601out:
Antonio Quartulli930cd6e2014-01-21 11:22:05 +0100602 /* report to the other components the maximum amount of bytes that
603 * batman-adv can send over the wire (without considering the payload
604 * overhead). For example, this value is used by TT to compute the
Sven Eckelmann21ba5ab2020-07-31 20:33:00 +0200605 * maximum local table size
Antonio Quartulli930cd6e2014-01-21 11:22:05 +0100606 */
607 atomic_set(&bat_priv->packet_size_max, min_mtu);
608
609 /* the real soft-interface MTU is computed by removing the payload
610 * overhead from the maximum amount of bytes that was just computed.
611 *
612 * However batman-adv does not support MTUs bigger than ETH_DATA_LEN
613 */
614 return min_t(int, min_mtu - batadv_max_header_len(), ETH_DATA_LEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000615}
616
Sven Eckelmannff15c272017-12-02 19:51:53 +0100617/**
618 * batadv_update_min_mtu() - Adjusts the MTU if a new interface with a smaller
619 * MTU appeared
620 * @soft_iface: netdev struct of the soft interface
621 */
Sven Eckelmann95638772012-05-12 02:09:31 +0200622void batadv_update_min_mtu(struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000623{
Marek Lindnera19d3d82013-05-27 15:33:25 +0800624 soft_iface->mtu = batadv_hardif_min_mtu(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000625
Marek Lindnera19d3d82013-05-27 15:33:25 +0800626 /* Check if the local translate table should be cleaned up to match a
627 * new (and smaller) MTU.
628 */
629 batadv_tt_local_resize_to_mtu(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000630}
631
Sven Eckelmann56303d32012-06-05 22:31:31 +0200632static void
633batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000634{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200635 struct batadv_priv *bat_priv;
636 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000637
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200638 if (hard_iface->if_status != BATADV_IF_INACTIVE)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200639 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000640
Marek Lindnere6c10f42011-02-18 12:33:20 +0000641 bat_priv = netdev_priv(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000642
Antonio Quartulli29824a52016-05-25 23:27:31 +0800643 bat_priv->algo_ops->iface.update_mac(hard_iface);
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200644 hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000645
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200646 /* the first active interface becomes our primary interface or
Antonio Quartulli015758d2011-07-09 17:52:13 +0200647 * the next active interface after the old primary interface was removed
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000648 */
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200649 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200650 if (!primary_if)
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200651 batadv_primary_if_select(bat_priv, hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000652
Sven Eckelmann3e348192012-05-16 20:23:22 +0200653 batadv_info(hard_iface->soft_iface, "Interface activated: %s\n",
654 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000655
Sven Eckelmann95638772012-05-12 02:09:31 +0200656 batadv_update_min_mtu(hard_iface->soft_iface);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200657
Antonio Quartulli29824a52016-05-25 23:27:31 +0800658 if (bat_priv->algo_ops->iface.activate)
659 bat_priv->algo_ops->iface.activate(hard_iface);
Antonio Quartullib6cf5d42016-04-14 09:37:05 +0800660
Marek Lindner32ae9b22011-04-20 15:40:58 +0200661out:
662 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100663 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000664}
665
Sven Eckelmann56303d32012-06-05 22:31:31 +0200666static void
667batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000668{
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200669 if (hard_iface->if_status != BATADV_IF_ACTIVE &&
670 hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000671 return;
672
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200673 hard_iface->if_status = BATADV_IF_INACTIVE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000674
Sven Eckelmann3e348192012-05-16 20:23:22 +0200675 batadv_info(hard_iface->soft_iface, "Interface deactivated: %s\n",
676 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000677
Sven Eckelmann95638772012-05-12 02:09:31 +0200678 batadv_update_min_mtu(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000679}
680
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100681/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100682 * batadv_master_del_slave() - remove hard_iface from the current master iface
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100683 * @slave: the interface enslaved in another master
684 * @master: the master from which slave has to be removed
685 *
Sven Eckelmannbccb48c2020-06-01 20:13:21 +0200686 * Invoke ndo_del_slave on master passing slave as argument. In this way the
687 * slave is free'd and the master can correctly change its internal state.
Sven Eckelmann62fe7102015-09-15 19:00:48 +0200688 *
689 * Return: 0 on success, a negative value representing the error otherwise
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100690 */
691static int batadv_master_del_slave(struct batadv_hard_iface *slave,
692 struct net_device *master)
693{
694 int ret;
695
696 if (!master)
697 return 0;
698
699 ret = -EBUSY;
700 if (master->netdev_ops->ndo_del_slave)
701 ret = master->netdev_ops->ndo_del_slave(master, slave->net_dev);
702
703 return ret;
704}
705
Sven Eckelmannff15c272017-12-02 19:51:53 +0100706/**
707 * batadv_hardif_enable_interface() - Enslave hard interface to soft interface
708 * @hard_iface: hard interface to add to soft interface
709 * @net: the applicable net namespace
710 * @iface_name: name of the soft interface
711 *
712 * Return: 0 on success or negative error number in case of failure
713 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200714int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200715 struct net *net, const char *iface_name)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000716{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200717 struct batadv_priv *bat_priv;
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100718 struct net_device *soft_iface, *master;
Antonio Quartulli293e9332013-05-19 12:55:16 +0200719 __be16 ethertype = htons(ETH_P_BATMAN);
Marek Lindner411d6ed2013-05-08 13:31:59 +0800720 int max_header_len = batadv_max_header_len();
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000721 int ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000722
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200723 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000724 goto out;
725
Sven Eckelmann17a86912016-04-11 13:06:40 +0200726 kref_get(&hard_iface->refcount);
Marek Lindnered75ccb2011-02-10 14:33:51 +0000727
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200728 soft_iface = dev_get_by_name(net, iface_name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000729
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000730 if (!soft_iface) {
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200731 soft_iface = batadv_softif_create(net, iface_name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000732
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000733 if (!soft_iface) {
734 ret = -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000735 goto err;
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000736 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000737
738 /* dev_get_by_name() increases the reference counter for us */
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000739 dev_hold(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000740 }
741
Sven Eckelmann04b482a2012-05-12 02:09:38 +0200742 if (!batadv_softif_is_valid(soft_iface)) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100743 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000744 soft_iface->name);
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000745 ret = -EINVAL;
Marek Lindner77af7572012-02-07 17:20:48 +0800746 goto err_dev;
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000747 }
748
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100749 /* check if the interface is enslaved in another virtual one and
750 * in that case unlink it first
751 */
752 master = netdev_master_upper_dev_get(hard_iface->net_dev);
753 ret = batadv_master_del_slave(hard_iface, master);
754 if (ret)
755 goto err_dev;
756
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000757 hard_iface->soft_iface = soft_iface;
Marek Lindnere6c10f42011-02-18 12:33:20 +0000758 bat_priv = netdev_priv(hard_iface->soft_iface);
Marek Lindnerd0b9fd82011-07-30 12:33:33 +0200759
Jiri Pirko6dffb042015-12-03 12:12:10 +0100760 ret = netdev_master_upper_dev_link(hard_iface->net_dev,
David Ahern42ab19e2017-10-04 17:48:47 -0700761 soft_iface, NULL, NULL, NULL);
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800762 if (ret)
763 goto err_dev;
764
Antonio Quartulli29824a52016-05-25 23:27:31 +0800765 ret = bat_priv->algo_ops->iface.enable(hard_iface);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200766 if (ret < 0)
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800767 goto err_upper;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000768
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200769 hard_iface->if_status = BATADV_IF_INACTIVE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000770
Sven Eckelmannd7d6de92016-03-05 16:09:18 +0100771 kref_get(&hard_iface->refcount);
Sven Eckelmann7e071c72012-06-03 22:19:13 +0200772 hard_iface->batman_adv_ptype.type = ethertype;
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200773 hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
Marek Lindnere6c10f42011-02-18 12:33:20 +0000774 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
775 dev_add_pack(&hard_iface->batman_adv_ptype);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000776
Sven Eckelmann3e348192012-05-16 20:23:22 +0200777 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
778 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000779
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200780 if (atomic_read(&bat_priv->fragmentation) &&
Marek Lindner411d6ed2013-05-08 13:31:59 +0800781 hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len)
Sven Eckelmann3e348192012-05-16 20:23:22 +0200782 batadv_info(hard_iface->soft_iface,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800783 "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 Eckelmann3e348192012-05-16 20:23:22 +0200784 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800785 ETH_DATA_LEN + max_header_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000786
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200787 if (!atomic_read(&bat_priv->fragmentation) &&
Marek Lindner411d6ed2013-05-08 13:31:59 +0800788 hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len)
Sven Eckelmann3e348192012-05-16 20:23:22 +0200789 batadv_info(hard_iface->soft_iface,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800790 "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 Eckelmann3e348192012-05-16 20:23:22 +0200791 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800792 ETH_DATA_LEN + max_header_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000793
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200794 if (batadv_hardif_is_iface_up(hard_iface))
795 batadv_hardif_activate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000796 else
Sven Eckelmann3e348192012-05-16 20:23:22 +0200797 batadv_err(hard_iface->soft_iface,
798 "Not using interface %s (retrying later): interface not active\n",
799 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000800
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200801 batadv_hardif_recalc_extra_skbroom(soft_iface);
802
Sven Eckelmann9e6b5642019-06-02 10:57:31 +0200803 if (bat_priv->algo_ops->iface.enabled)
804 bat_priv->algo_ops->iface.enabled(hard_iface);
805
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000806out:
807 return 0;
808
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800809err_upper:
810 netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface);
Marek Lindner77af7572012-02-07 17:20:48 +0800811err_dev:
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800812 hard_iface->soft_iface = NULL;
Marek Lindner77af7572012-02-07 17:20:48 +0800813 dev_put(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000814err:
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100815 batadv_hardif_put(hard_iface);
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000816 return ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000817}
818
Sven Eckelmannff15c272017-12-02 19:51:53 +0100819/**
Sven Eckelmanndee222c72018-08-16 16:54:45 +0200820 * batadv_hardif_cnt() - get number of interfaces enslaved to soft interface
821 * @soft_iface: soft interface to check
822 *
823 * This function is only using RCU for locking - the result can therefore be
Sven Eckelmannbccb48c2020-06-01 20:13:21 +0200824 * off when another function is modifying the list at the same time. The
Sven Eckelmanndee222c72018-08-16 16:54:45 +0200825 * caller can use the rtnl_lock to make sure that the count is accurate.
826 *
827 * Return: number of connected/enslaved hard interfaces
828 */
829static size_t batadv_hardif_cnt(const struct net_device *soft_iface)
830{
831 struct batadv_hard_iface *hard_iface;
832 size_t count = 0;
833
834 rcu_read_lock();
835 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
836 if (hard_iface->soft_iface != soft_iface)
837 continue;
838
839 count++;
840 }
841 rcu_read_unlock();
842
843 return count;
844}
845
846/**
Sven Eckelmannff15c272017-12-02 19:51:53 +0100847 * batadv_hardif_disable_interface() - Remove hard interface from soft interface
848 * @hard_iface: hard interface to be removed
849 * @autodel: whether to delete soft interface when it doesn't contain any other
850 * slave interfaces
851 */
Sven Eckelmanna15fd362013-02-11 17:10:24 +0800852void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
853 enum batadv_hard_if_cleanup autodel)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000854{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200855 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
856 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000857
Sven Eckelmannf2d23862016-03-19 13:55:21 +0100858 batadv_hardif_deactivate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000859
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200860 if (hard_iface->if_status != BATADV_IF_INACTIVE)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200861 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000862
Sven Eckelmann3e348192012-05-16 20:23:22 +0200863 batadv_info(hard_iface->soft_iface, "Removing interface: %s\n",
864 hard_iface->net_dev->name);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000865 dev_remove_pack(&hard_iface->batman_adv_ptype);
Sven Eckelmannd7d6de92016-03-05 16:09:18 +0100866 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000867
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200868 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200869 if (hard_iface == primary_if) {
Sven Eckelmann56303d32012-06-05 22:31:31 +0200870 struct batadv_hard_iface *new_if;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000871
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200872 new_if = batadv_hardif_get_active(hard_iface->soft_iface);
873 batadv_primary_if_select(bat_priv, new_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000874
875 if (new_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100876 batadv_hardif_put(new_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000877 }
878
Antonio Quartulli29824a52016-05-25 23:27:31 +0800879 bat_priv->algo_ops->iface.disable(hard_iface);
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200880 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000881
Marek Lindnere6c10f42011-02-18 12:33:20 +0000882 /* delete all references to this hard_iface */
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200883 batadv_purge_orig_ref(bat_priv);
Sven Eckelmann9455e342012-05-12 02:09:37 +0200884 batadv_purge_outstanding_packets(bat_priv, hard_iface);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000885 dev_put(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000886
Antonio Quartullia5256f72015-08-04 22:26:19 +0200887 netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface);
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200888 batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface);
Antonio Quartullia5256f72015-08-04 22:26:19 +0200889
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000890 /* nobody uses this interface anymore */
Sven Eckelmanndee222c72018-08-16 16:54:45 +0200891 if (batadv_hardif_cnt(hard_iface->soft_iface) <= 1) {
Antonio Quartulli8257f552013-08-19 18:39:59 +0200892 batadv_gw_check_client_stop(bat_priv);
893
894 if (autodel == BATADV_IF_CLEANUP_AUTO)
895 batadv_softif_destroy_sysfs(hard_iface->soft_iface);
896 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000897
Sven Eckelmann27915aa2016-11-02 18:14:43 +0100898 hard_iface->soft_iface = NULL;
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100899 batadv_hardif_put(hard_iface);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200900
901out:
902 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100903 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000904}
905
Sven Eckelmann56303d32012-06-05 22:31:31 +0200906static struct batadv_hard_iface *
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200907batadv_hardif_add_interface(struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000908{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200909 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000910 int ret;
911
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200912 ASSERT_RTNL();
913
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100914 if (!batadv_is_valid_iface(net_dev))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000915 goto out;
916
917 dev_hold(net_dev);
918
Antonio Quartulli7db3fc22013-04-02 12:16:53 +0200919 hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC);
Joe Perches320f4222011-08-29 14:17:24 -0700920 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000921 goto release_dev;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000922
Sven Eckelmann5853e222012-05-12 02:09:24 +0200923 ret = batadv_sysfs_add_hardif(&hard_iface->hardif_obj, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000924 if (ret)
925 goto free_if;
926
Marek Lindnere6c10f42011-02-18 12:33:20 +0000927 hard_iface->net_dev = net_dev;
928 hard_iface->soft_iface = NULL;
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200929 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100930
Greg Kroah-Hartman3bcacd12019-06-14 09:11:23 +0200931 batadv_debugfs_add_hardif(hard_iface);
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100932
Marek Lindnere6c10f42011-02-18 12:33:20 +0000933 INIT_LIST_HEAD(&hard_iface->list);
Marek Lindnercef63412015-08-04 21:09:55 +0800934 INIT_HLIST_HEAD(&hard_iface->neigh_list);
Simon Wunderlich5bc44dc2013-01-11 10:19:51 +0100935
Sven Eckelmann40e220b2019-10-03 17:02:01 +0200936 mutex_init(&hard_iface->bat_iv.ogm_buff_mutex);
Marek Lindnercef63412015-08-04 21:09:55 +0800937 spin_lock_init(&hard_iface->neigh_list_lock);
Sven Eckelmannb2367e42016-07-15 17:39:28 +0200938 kref_init(&hard_iface->refcount);
Marek Lindnercef63412015-08-04 21:09:55 +0800939
Matthias Schiffercaf65bf2013-03-09 23:14:23 +0100940 hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200941 hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev);
942 if (batadv_is_wifi_hardif(hard_iface))
Matthias Schiffercaf65bf2013-03-09 23:14:23 +0100943 hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
944
Linus Lüssing3bda14d2020-06-01 22:35:22 +0200945 atomic_set(&hard_iface->hop_penalty, 0);
946
Marek Lindner7db682d2016-05-10 22:31:59 +0800947 batadv_v_hardif_init(hard_iface);
948
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200949 batadv_check_known_mac_addr(hard_iface->net_dev);
Sven Eckelmannb2367e42016-07-15 17:39:28 +0200950 kref_get(&hard_iface->refcount);
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200951 list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
Sven Eckelmannfb69be62018-10-30 22:01:24 +0100952 batadv_hardif_generation++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000953
Marek Lindnere6c10f42011-02-18 12:33:20 +0000954 return hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000955
956free_if:
Marek Lindnere6c10f42011-02-18 12:33:20 +0000957 kfree(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000958release_dev:
959 dev_put(net_dev);
960out:
961 return NULL;
962}
963
Sven Eckelmann56303d32012-06-05 22:31:31 +0200964static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000965{
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200966 ASSERT_RTNL();
967
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000968 /* first deactivate interface */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200969 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmanna15fd362013-02-11 17:10:24 +0800970 batadv_hardif_disable_interface(hard_iface,
Sven Eckelmann06d640c2016-07-10 15:47:57 +0200971 BATADV_IF_CLEANUP_KEEP);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000972
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200973 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000974 return;
975
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200976 hard_iface->if_status = BATADV_IF_TO_BE_REMOVED;
Sven Eckelmann569c9852016-06-13 07:41:31 +0200977 batadv_debugfs_del_hardif(hard_iface);
978 batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
979 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000980}
981
Sven Eckelmannff15c272017-12-02 19:51:53 +0100982/**
Sven Eckelmann6da7be72018-06-01 19:24:24 +0200983 * batadv_hard_if_event_softif() - Handle events for soft interfaces
984 * @event: NETDEV_* event to handle
985 * @net_dev: net_device which generated an event
986 *
987 * Return: NOTIFY_* result
988 */
989static int batadv_hard_if_event_softif(unsigned long event,
990 struct net_device *net_dev)
991{
992 struct batadv_priv *bat_priv;
993
994 switch (event) {
995 case NETDEV_REGISTER:
996 batadv_sysfs_add_meshif(net_dev);
997 bat_priv = netdev_priv(net_dev);
998 batadv_softif_create_vlan(bat_priv, BATADV_NO_FLAGS);
999 break;
1000 case NETDEV_CHANGENAME:
1001 batadv_debugfs_rename_meshif(net_dev);
1002 break;
1003 }
1004
1005 return NOTIFY_DONE;
1006}
1007
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001008static int batadv_hard_if_event(struct notifier_block *this,
1009 unsigned long event, void *ptr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001010{
Jiri Pirko351638e2013-05-28 01:30:21 +00001011 struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
Sven Eckelmann56303d32012-06-05 22:31:31 +02001012 struct batadv_hard_iface *hard_iface;
1013 struct batadv_hard_iface *primary_if = NULL;
1014 struct batadv_priv *bat_priv;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001015
Sven Eckelmann6da7be72018-06-01 19:24:24 +02001016 if (batadv_softif_is_valid(net_dev))
1017 return batadv_hard_if_event_softif(event, net_dev);
Sven Eckelmann37130292013-02-11 17:10:22 +08001018
Sven Eckelmann56303d32012-06-05 22:31:31 +02001019 hard_iface = batadv_hardif_get_by_netdev(net_dev);
Andrew Lunna1a66b12015-12-03 21:12:33 +01001020 if (!hard_iface && (event == NETDEV_REGISTER ||
1021 event == NETDEV_POST_TYPE_CHANGE))
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001022 hard_iface = batadv_hardif_add_interface(net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001023
Marek Lindnere6c10f42011-02-18 12:33:20 +00001024 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001025 goto out;
1026
1027 switch (event) {
1028 case NETDEV_UP:
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001029 batadv_hardif_activate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001030 break;
1031 case NETDEV_GOING_DOWN:
1032 case NETDEV_DOWN:
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001033 batadv_hardif_deactivate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001034 break;
1035 case NETDEV_UNREGISTER:
Andrew Lunna1a66b12015-12-03 21:12:33 +01001036 case NETDEV_PRE_TYPE_CHANGE:
Marek Lindnere6c10f42011-02-18 12:33:20 +00001037 list_del_rcu(&hard_iface->list);
Sven Eckelmannfb69be62018-10-30 22:01:24 +01001038 batadv_hardif_generation++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001039
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001040 batadv_hardif_remove_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001041 break;
1042 case NETDEV_CHANGEMTU:
Marek Lindnere6c10f42011-02-18 12:33:20 +00001043 if (hard_iface->soft_iface)
Sven Eckelmann95638772012-05-12 02:09:31 +02001044 batadv_update_min_mtu(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001045 break;
1046 case NETDEV_CHANGEADDR:
Sven Eckelmanne9a4f292012-06-03 22:19:19 +02001047 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001048 goto hardif_put;
1049
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001050 batadv_check_known_mac_addr(hard_iface->net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001051
Marek Lindnere6c10f42011-02-18 12:33:20 +00001052 bat_priv = netdev_priv(hard_iface->soft_iface);
Antonio Quartulli29824a52016-05-25 23:27:31 +08001053 bat_priv->algo_ops->iface.update_mac(hard_iface);
Marek Lindner01c42242011-11-28 21:31:55 +08001054
Sven Eckelmanne5d89252012-05-12 13:48:54 +02001055 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +02001056 if (!primary_if)
1057 goto hardif_put;
1058
1059 if (hard_iface == primary_if)
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001060 batadv_primary_if_update_addr(bat_priv, NULL);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001061 break;
Sven Eckelmannee3b5e92016-09-30 15:21:06 +02001062 case NETDEV_CHANGEUPPER:
1063 hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev);
1064 if (batadv_is_wifi_hardif(hard_iface))
1065 hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
1066 break;
Sven Eckelmann36dc6212018-06-01 19:24:23 +02001067 case NETDEV_CHANGENAME:
1068 batadv_debugfs_rename_hardif(hard_iface);
1069 break;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001070 default:
1071 break;
Joe Perchesf81c6222011-06-03 11:51:19 +00001072 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001073
1074hardif_put:
Sven Eckelmann82047ad2016-01-17 11:01:10 +01001075 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001076out:
Marek Lindner32ae9b22011-04-20 15:40:58 +02001077 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +01001078 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001079 return NOTIFY_DONE;
1080}
1081
Sven Eckelmann95638772012-05-12 02:09:31 +02001082struct notifier_block batadv_hard_if_notifier = {
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001083 .notifier_call = batadv_hard_if_event,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001084};