blob: dad99641df2a82d4235ad0bdba16110d8ca75663 [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
557 soft_iface->needed_headroom = needed_headroom;
558 soft_iface->needed_tailroom = lower_tailroom;
559}
560
Sven Eckelmannff15c272017-12-02 19:51:53 +0100561/**
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 Eckelmann95638772012-05-12 02:09:31 +0200568int batadv_hardif_min_mtu(struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000569{
Marek Lindnera19d3d82013-05-27 15:33:25 +0800570 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200571 const struct batadv_hard_iface *hard_iface;
Antonio Quartulli930cd6e2014-01-21 11:22:05 +0100572 int min_mtu = INT_MAX;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000573
574 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200575 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200576 if (hard_iface->if_status != BATADV_IF_ACTIVE &&
577 hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000578 continue;
579
Marek Lindnere6c10f42011-02-18 12:33:20 +0000580 if (hard_iface->soft_iface != soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000581 continue;
582
Marek Lindnera19d3d82013-05-27 15:33:25 +0800583 min_mtu = min_t(int, hard_iface->net_dev->mtu, min_mtu);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000584 }
585 rcu_read_unlock();
Marek Lindnera19d3d82013-05-27 15:33:25 +0800586
Marek Lindnera19d3d82013-05-27 15:33:25 +0800587 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 Lindnera19d3d82013-05-27 15:33:25 +0800597
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000598out:
Antonio Quartulli930cd6e2014-01-21 11:22:05 +0100599 /* 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 Eckelmann21ba5ab2020-07-31 20:33:00 +0200602 * maximum local table size
Antonio Quartulli930cd6e2014-01-21 11:22:05 +0100603 */
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 Eckelmannc6c8fea2010-12-13 11:19:28 +0000612}
613
Sven Eckelmannff15c272017-12-02 19:51:53 +0100614/**
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 Eckelmann95638772012-05-12 02:09:31 +0200619void batadv_update_min_mtu(struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000620{
Marek Lindnera19d3d82013-05-27 15:33:25 +0800621 soft_iface->mtu = batadv_hardif_min_mtu(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000622
Marek Lindnera19d3d82013-05-27 15:33:25 +0800623 /* 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 Eckelmannc6c8fea2010-12-13 11:19:28 +0000627}
628
Sven Eckelmann56303d32012-06-05 22:31:31 +0200629static void
630batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000631{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200632 struct batadv_priv *bat_priv;
633 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000634
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200635 if (hard_iface->if_status != BATADV_IF_INACTIVE)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200636 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000637
Marek Lindnere6c10f42011-02-18 12:33:20 +0000638 bat_priv = netdev_priv(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000639
Antonio Quartulli29824a52016-05-25 23:27:31 +0800640 bat_priv->algo_ops->iface.update_mac(hard_iface);
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200641 hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000642
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200643 /* the first active interface becomes our primary interface or
Antonio Quartulli015758d2011-07-09 17:52:13 +0200644 * the next active interface after the old primary interface was removed
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000645 */
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200646 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200647 if (!primary_if)
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200648 batadv_primary_if_select(bat_priv, hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000649
Sven Eckelmann3e348192012-05-16 20:23:22 +0200650 batadv_info(hard_iface->soft_iface, "Interface activated: %s\n",
651 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000652
Sven Eckelmann95638772012-05-12 02:09:31 +0200653 batadv_update_min_mtu(hard_iface->soft_iface);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200654
Antonio Quartulli29824a52016-05-25 23:27:31 +0800655 if (bat_priv->algo_ops->iface.activate)
656 bat_priv->algo_ops->iface.activate(hard_iface);
Antonio Quartullib6cf5d42016-04-14 09:37:05 +0800657
Marek Lindner32ae9b22011-04-20 15:40:58 +0200658out:
659 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100660 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000661}
662
Sven Eckelmann56303d32012-06-05 22:31:31 +0200663static void
664batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000665{
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200666 if (hard_iface->if_status != BATADV_IF_ACTIVE &&
667 hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000668 return;
669
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200670 hard_iface->if_status = BATADV_IF_INACTIVE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000671
Sven Eckelmann3e348192012-05-16 20:23:22 +0200672 batadv_info(hard_iface->soft_iface, "Interface deactivated: %s\n",
673 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000674
Sven Eckelmann95638772012-05-12 02:09:31 +0200675 batadv_update_min_mtu(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000676}
677
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100678/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100679 * batadv_master_del_slave() - remove hard_iface from the current master iface
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100680 * @slave: the interface enslaved in another master
681 * @master: the master from which slave has to be removed
682 *
Sven Eckelmannbccb48c2020-06-01 20:13:21 +0200683 * 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 Eckelmann62fe7102015-09-15 19:00:48 +0200685 *
686 * Return: 0 on success, a negative value representing the error otherwise
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100687 */
688static 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 Eckelmannff15c272017-12-02 19:51:53 +0100703/**
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 Eckelmann56303d32012-06-05 22:31:31 +0200711int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200712 struct net *net, const char *iface_name)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000713{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200714 struct batadv_priv *bat_priv;
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100715 struct net_device *soft_iface, *master;
Antonio Quartulli293e9332013-05-19 12:55:16 +0200716 __be16 ethertype = htons(ETH_P_BATMAN);
Marek Lindner411d6ed2013-05-08 13:31:59 +0800717 int max_header_len = batadv_max_header_len();
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000718 int ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000719
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200720 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000721 goto out;
722
Sven Eckelmann17a86912016-04-11 13:06:40 +0200723 kref_get(&hard_iface->refcount);
Marek Lindnered75ccb2011-02-10 14:33:51 +0000724
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200725 soft_iface = dev_get_by_name(net, iface_name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000726
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000727 if (!soft_iface) {
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200728 soft_iface = batadv_softif_create(net, iface_name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000729
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000730 if (!soft_iface) {
731 ret = -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000732 goto err;
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000733 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000734
735 /* dev_get_by_name() increases the reference counter for us */
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000736 dev_hold(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000737 }
738
Sven Eckelmann04b482a2012-05-12 02:09:38 +0200739 if (!batadv_softif_is_valid(soft_iface)) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100740 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000741 soft_iface->name);
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000742 ret = -EINVAL;
Marek Lindner77af7572012-02-07 17:20:48 +0800743 goto err_dev;
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000744 }
745
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100746 /* 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 Eckelmanne44d8fe2011-03-04 21:36:41 +0000754 hard_iface->soft_iface = soft_iface;
Marek Lindnere6c10f42011-02-18 12:33:20 +0000755 bat_priv = netdev_priv(hard_iface->soft_iface);
Marek Lindnerd0b9fd82011-07-30 12:33:33 +0200756
Jiri Pirko6dffb042015-12-03 12:12:10 +0100757 ret = netdev_master_upper_dev_link(hard_iface->net_dev,
David Ahern42ab19e2017-10-04 17:48:47 -0700758 soft_iface, NULL, NULL, NULL);
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800759 if (ret)
760 goto err_dev;
761
Antonio Quartulli29824a52016-05-25 23:27:31 +0800762 ret = bat_priv->algo_ops->iface.enable(hard_iface);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200763 if (ret < 0)
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800764 goto err_upper;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000765
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200766 hard_iface->if_status = BATADV_IF_INACTIVE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000767
Sven Eckelmannd7d6de92016-03-05 16:09:18 +0100768 kref_get(&hard_iface->refcount);
Sven Eckelmann7e071c72012-06-03 22:19:13 +0200769 hard_iface->batman_adv_ptype.type = ethertype;
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200770 hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
Marek Lindnere6c10f42011-02-18 12:33:20 +0000771 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
772 dev_add_pack(&hard_iface->batman_adv_ptype);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000773
Sven Eckelmann3e348192012-05-16 20:23:22 +0200774 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
775 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000776
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200777 if (atomic_read(&bat_priv->fragmentation) &&
Marek Lindner411d6ed2013-05-08 13:31:59 +0800778 hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len)
Sven Eckelmann3e348192012-05-16 20:23:22 +0200779 batadv_info(hard_iface->soft_iface,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800780 "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 +0200781 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800782 ETH_DATA_LEN + max_header_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000783
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200784 if (!atomic_read(&bat_priv->fragmentation) &&
Marek Lindner411d6ed2013-05-08 13:31:59 +0800785 hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len)
Sven Eckelmann3e348192012-05-16 20:23:22 +0200786 batadv_info(hard_iface->soft_iface,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800787 "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 +0200788 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800789 ETH_DATA_LEN + max_header_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000790
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200791 if (batadv_hardif_is_iface_up(hard_iface))
792 batadv_hardif_activate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000793 else
Sven Eckelmann3e348192012-05-16 20:23:22 +0200794 batadv_err(hard_iface->soft_iface,
795 "Not using interface %s (retrying later): interface not active\n",
796 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000797
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200798 batadv_hardif_recalc_extra_skbroom(soft_iface);
799
Sven Eckelmann9e6b5642019-06-02 10:57:31 +0200800 if (bat_priv->algo_ops->iface.enabled)
801 bat_priv->algo_ops->iface.enabled(hard_iface);
802
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000803out:
804 return 0;
805
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800806err_upper:
807 netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface);
Marek Lindner77af7572012-02-07 17:20:48 +0800808err_dev:
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800809 hard_iface->soft_iface = NULL;
Marek Lindner77af7572012-02-07 17:20:48 +0800810 dev_put(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000811err:
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100812 batadv_hardif_put(hard_iface);
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000813 return ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000814}
815
Sven Eckelmannff15c272017-12-02 19:51:53 +0100816/**
Sven Eckelmanndee222c72018-08-16 16:54:45 +0200817 * 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 Eckelmannbccb48c2020-06-01 20:13:21 +0200821 * off when another function is modifying the list at the same time. The
Sven Eckelmanndee222c72018-08-16 16:54:45 +0200822 * caller can use the rtnl_lock to make sure that the count is accurate.
823 *
824 * Return: number of connected/enslaved hard interfaces
825 */
826static 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 Eckelmannff15c272017-12-02 19:51:53 +0100844 * 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 Eckelmanna15fd362013-02-11 17:10:24 +0800849void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
850 enum batadv_hard_if_cleanup autodel)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000851{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200852 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
853 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000854
Sven Eckelmannf2d23862016-03-19 13:55:21 +0100855 batadv_hardif_deactivate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000856
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200857 if (hard_iface->if_status != BATADV_IF_INACTIVE)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200858 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000859
Sven Eckelmann3e348192012-05-16 20:23:22 +0200860 batadv_info(hard_iface->soft_iface, "Removing interface: %s\n",
861 hard_iface->net_dev->name);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000862 dev_remove_pack(&hard_iface->batman_adv_ptype);
Sven Eckelmannd7d6de92016-03-05 16:09:18 +0100863 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000864
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200865 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200866 if (hard_iface == primary_if) {
Sven Eckelmann56303d32012-06-05 22:31:31 +0200867 struct batadv_hard_iface *new_if;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000868
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200869 new_if = batadv_hardif_get_active(hard_iface->soft_iface);
870 batadv_primary_if_select(bat_priv, new_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000871
872 if (new_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100873 batadv_hardif_put(new_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000874 }
875
Antonio Quartulli29824a52016-05-25 23:27:31 +0800876 bat_priv->algo_ops->iface.disable(hard_iface);
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200877 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000878
Marek Lindnere6c10f42011-02-18 12:33:20 +0000879 /* delete all references to this hard_iface */
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200880 batadv_purge_orig_ref(bat_priv);
Sven Eckelmann9455e342012-05-12 02:09:37 +0200881 batadv_purge_outstanding_packets(bat_priv, hard_iface);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000882 dev_put(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000883
Antonio Quartullia5256f72015-08-04 22:26:19 +0200884 netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface);
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200885 batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface);
Antonio Quartullia5256f72015-08-04 22:26:19 +0200886
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000887 /* nobody uses this interface anymore */
Sven Eckelmanndee222c72018-08-16 16:54:45 +0200888 if (batadv_hardif_cnt(hard_iface->soft_iface) <= 1) {
Antonio Quartulli8257f552013-08-19 18:39:59 +0200889 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 Eckelmannc6c8fea2010-12-13 11:19:28 +0000894
Sven Eckelmann27915aa2016-11-02 18:14:43 +0100895 hard_iface->soft_iface = NULL;
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100896 batadv_hardif_put(hard_iface);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200897
898out:
899 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100900 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000901}
902
Sven Eckelmann56303d32012-06-05 22:31:31 +0200903static struct batadv_hard_iface *
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200904batadv_hardif_add_interface(struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000905{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200906 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000907 int ret;
908
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200909 ASSERT_RTNL();
910
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100911 if (!batadv_is_valid_iface(net_dev))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000912 goto out;
913
914 dev_hold(net_dev);
915
Antonio Quartulli7db3fc22013-04-02 12:16:53 +0200916 hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC);
Joe Perches320f4222011-08-29 14:17:24 -0700917 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000918 goto release_dev;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000919
Sven Eckelmann5853e222012-05-12 02:09:24 +0200920 ret = batadv_sysfs_add_hardif(&hard_iface->hardif_obj, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000921 if (ret)
922 goto free_if;
923
Marek Lindnere6c10f42011-02-18 12:33:20 +0000924 hard_iface->net_dev = net_dev;
925 hard_iface->soft_iface = NULL;
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200926 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100927
Greg Kroah-Hartman3bcacd12019-06-14 09:11:23 +0200928 batadv_debugfs_add_hardif(hard_iface);
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100929
Marek Lindnere6c10f42011-02-18 12:33:20 +0000930 INIT_LIST_HEAD(&hard_iface->list);
Marek Lindnercef63412015-08-04 21:09:55 +0800931 INIT_HLIST_HEAD(&hard_iface->neigh_list);
Simon Wunderlich5bc44dc2013-01-11 10:19:51 +0100932
Sven Eckelmann40e220b2019-10-03 17:02:01 +0200933 mutex_init(&hard_iface->bat_iv.ogm_buff_mutex);
Marek Lindnercef63412015-08-04 21:09:55 +0800934 spin_lock_init(&hard_iface->neigh_list_lock);
Sven Eckelmannb2367e42016-07-15 17:39:28 +0200935 kref_init(&hard_iface->refcount);
Marek Lindnercef63412015-08-04 21:09:55 +0800936
Matthias Schiffercaf65bf2013-03-09 23:14:23 +0100937 hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200938 hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev);
939 if (batadv_is_wifi_hardif(hard_iface))
Matthias Schiffercaf65bf2013-03-09 23:14:23 +0100940 hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
941
Linus Lüssing3bda14d2020-06-01 22:35:22 +0200942 atomic_set(&hard_iface->hop_penalty, 0);
943
Marek Lindner7db682d2016-05-10 22:31:59 +0800944 batadv_v_hardif_init(hard_iface);
945
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200946 batadv_check_known_mac_addr(hard_iface->net_dev);
Sven Eckelmannb2367e42016-07-15 17:39:28 +0200947 kref_get(&hard_iface->refcount);
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200948 list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
Sven Eckelmannfb69be62018-10-30 22:01:24 +0100949 batadv_hardif_generation++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000950
Marek Lindnere6c10f42011-02-18 12:33:20 +0000951 return hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000952
953free_if:
Marek Lindnere6c10f42011-02-18 12:33:20 +0000954 kfree(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000955release_dev:
956 dev_put(net_dev);
957out:
958 return NULL;
959}
960
Sven Eckelmann56303d32012-06-05 22:31:31 +0200961static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000962{
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200963 ASSERT_RTNL();
964
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000965 /* first deactivate interface */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200966 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmanna15fd362013-02-11 17:10:24 +0800967 batadv_hardif_disable_interface(hard_iface,
Sven Eckelmann06d640c2016-07-10 15:47:57 +0200968 BATADV_IF_CLEANUP_KEEP);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000969
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200970 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000971 return;
972
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200973 hard_iface->if_status = BATADV_IF_TO_BE_REMOVED;
Sven Eckelmann569c9852016-06-13 07:41:31 +0200974 batadv_debugfs_del_hardif(hard_iface);
975 batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
976 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000977}
978
Sven Eckelmannff15c272017-12-02 19:51:53 +0100979/**
Sven Eckelmann6da7be72018-06-01 19:24:24 +0200980 * 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 */
986static 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 Eckelmann18a1cb62012-05-12 18:33:57 +02001005static int batadv_hard_if_event(struct notifier_block *this,
1006 unsigned long event, void *ptr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001007{
Jiri Pirko351638e2013-05-28 01:30:21 +00001008 struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
Sven Eckelmann56303d32012-06-05 22:31:31 +02001009 struct batadv_hard_iface *hard_iface;
1010 struct batadv_hard_iface *primary_if = NULL;
1011 struct batadv_priv *bat_priv;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001012
Sven Eckelmann6da7be72018-06-01 19:24:24 +02001013 if (batadv_softif_is_valid(net_dev))
1014 return batadv_hard_if_event_softif(event, net_dev);
Sven Eckelmann37130292013-02-11 17:10:22 +08001015
Sven Eckelmann56303d32012-06-05 22:31:31 +02001016 hard_iface = batadv_hardif_get_by_netdev(net_dev);
Andrew Lunna1a66b12015-12-03 21:12:33 +01001017 if (!hard_iface && (event == NETDEV_REGISTER ||
1018 event == NETDEV_POST_TYPE_CHANGE))
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001019 hard_iface = batadv_hardif_add_interface(net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001020
Marek Lindnere6c10f42011-02-18 12:33:20 +00001021 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001022 goto out;
1023
1024 switch (event) {
1025 case NETDEV_UP:
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001026 batadv_hardif_activate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001027 break;
1028 case NETDEV_GOING_DOWN:
1029 case NETDEV_DOWN:
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001030 batadv_hardif_deactivate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001031 break;
1032 case NETDEV_UNREGISTER:
Andrew Lunna1a66b12015-12-03 21:12:33 +01001033 case NETDEV_PRE_TYPE_CHANGE:
Marek Lindnere6c10f42011-02-18 12:33:20 +00001034 list_del_rcu(&hard_iface->list);
Sven Eckelmannfb69be62018-10-30 22:01:24 +01001035 batadv_hardif_generation++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001036
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001037 batadv_hardif_remove_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001038 break;
1039 case NETDEV_CHANGEMTU:
Marek Lindnere6c10f42011-02-18 12:33:20 +00001040 if (hard_iface->soft_iface)
Sven Eckelmann95638772012-05-12 02:09:31 +02001041 batadv_update_min_mtu(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001042 break;
1043 case NETDEV_CHANGEADDR:
Sven Eckelmanne9a4f292012-06-03 22:19:19 +02001044 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001045 goto hardif_put;
1046
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001047 batadv_check_known_mac_addr(hard_iface->net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001048
Marek Lindnere6c10f42011-02-18 12:33:20 +00001049 bat_priv = netdev_priv(hard_iface->soft_iface);
Antonio Quartulli29824a52016-05-25 23:27:31 +08001050 bat_priv->algo_ops->iface.update_mac(hard_iface);
Marek Lindner01c42242011-11-28 21:31:55 +08001051
Sven Eckelmanne5d89252012-05-12 13:48:54 +02001052 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +02001053 if (!primary_if)
1054 goto hardif_put;
1055
1056 if (hard_iface == primary_if)
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001057 batadv_primary_if_update_addr(bat_priv, NULL);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001058 break;
Sven Eckelmannee3b5e92016-09-30 15:21:06 +02001059 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 Eckelmann36dc6212018-06-01 19:24:23 +02001064 case NETDEV_CHANGENAME:
1065 batadv_debugfs_rename_hardif(hard_iface);
1066 break;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001067 default:
1068 break;
Joe Perchesf81c6222011-06-03 11:51:19 +00001069 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001070
1071hardif_put:
Sven Eckelmann82047ad2016-01-17 11:01:10 +01001072 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001073out:
Marek Lindner32ae9b22011-04-20 15:40:58 +02001074 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +01001075 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001076 return NOTIFY_DONE;
1077}
1078
Sven Eckelmann95638772012-05-12 02:09:31 +02001079struct notifier_block batadv_hard_if_notifier = {
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001080 .notifier_call = batadv_hard_if_event,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001081};