blob: 899487641bca3d45fb6856bc43e7a2658b6917cc [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001// SPDX-License-Identifier: GPL-2.0
Sven Eckelmann7a79d712018-12-31 23:59:59 +01002/* Copyright (C) 2007-2019 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>
21#include <linux/netdevice.h>
22#include <linux/printk.h>
23#include <linux/rculist.h>
24#include <linux/rtnetlink.h>
25#include <linux/slab.h>
Marek Lindnercef63412015-08-04 21:09:55 +080026#include <linux/spinlock.h>
Andrew Lunn275019d2016-07-03 13:31:33 +020027#include <net/net_namespace.h>
28#include <net/rtnetlink.h>
Sven Eckelmannfec149f2017-12-21 10:17:41 +010029#include <uapi/linux/batadv_packet.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020030
Sven Eckelmanna2d08162016-05-15 11:07:46 +020031#include "bat_v.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020032#include "bridge_loop_avoidance.h"
33#include "debugfs.h"
34#include "distributed-arp-table.h"
35#include "gateway_client.h"
Sven Eckelmannba412082016-05-15 23:48:31 +020036#include "log.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020037#include "originator.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020038#include "send.h"
39#include "soft-interface.h"
40#include "sysfs.h"
41#include "translation-table.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000042
Sven Eckelmann140ed8e2016-01-05 12:06:26 +010043/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010044 * batadv_hardif_release() - release hard interface from lists and queue for
Sven Eckelmann140ed8e2016-01-05 12:06:26 +010045 * free after rcu grace period
Sven Eckelmann7a659d52016-01-16 10:29:54 +010046 * @ref: kref pointer of the hard interface
Sven Eckelmann140ed8e2016-01-05 12:06:26 +010047 */
Sven Eckelmann7a659d52016-01-16 10:29:54 +010048void batadv_hardif_release(struct kref *ref)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000049{
Sven Eckelmann7a659d52016-01-16 10:29:54 +010050 struct batadv_hard_iface *hard_iface;
51
52 hard_iface = container_of(ref, struct batadv_hard_iface, refcount);
Marek Lindnere6c10f42011-02-18 12:33:20 +000053 dev_put(hard_iface->net_dev);
Sven Eckelmann140ed8e2016-01-05 12:06:26 +010054
55 kfree_rcu(hard_iface, rcu);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000056}
57
Sven Eckelmannff15c272017-12-02 19:51:53 +010058/**
59 * batadv_hardif_get_by_netdev() - Get hard interface object of a net_device
60 * @net_dev: net_device to search for
61 *
62 * Return: batadv_hard_iface of net_dev (with increased refcnt), NULL on errors
63 */
Sven Eckelmann56303d32012-06-05 22:31:31 +020064struct batadv_hard_iface *
65batadv_hardif_get_by_netdev(const struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000066{
Sven Eckelmann56303d32012-06-05 22:31:31 +020067 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000068
69 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +020070 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Marek Lindnere6c10f42011-02-18 12:33:20 +000071 if (hard_iface->net_dev == net_dev &&
Sven Eckelmann7a659d52016-01-16 10:29:54 +010072 kref_get_unless_zero(&hard_iface->refcount))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000073 goto out;
74 }
75
Marek Lindnere6c10f42011-02-18 12:33:20 +000076 hard_iface = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000077
78out:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000079 rcu_read_unlock();
Marek Lindnere6c10f42011-02-18 12:33:20 +000080 return hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000081}
82
Antonio Quartullib7eddd02012-09-09 10:46:46 +020083/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010084 * batadv_getlink_net() - return link net namespace (of use fallback)
Andrew Lunn275019d2016-07-03 13:31:33 +020085 * @netdev: net_device to check
86 * @fallback_net: return in case get_link_net is not available for @netdev
87 *
88 * Return: result of rtnl_link_ops->get_link_net or @fallback_net
89 */
Sven Eckelmann88ffc7d2016-09-30 15:21:00 +020090static struct net *batadv_getlink_net(const struct net_device *netdev,
91 struct net *fallback_net)
Andrew Lunn275019d2016-07-03 13:31:33 +020092{
93 if (!netdev->rtnl_link_ops)
94 return fallback_net;
95
96 if (!netdev->rtnl_link_ops->get_link_net)
97 return fallback_net;
98
99 return netdev->rtnl_link_ops->get_link_net(netdev);
100}
101
102/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100103 * batadv_mutual_parents() - check if two devices are each others parent
Andrew Lunn275019d2016-07-03 13:31:33 +0200104 * @dev1: 1st net dev
105 * @net1: 1st devices netns
106 * @dev2: 2nd net dev
107 * @net2: 2nd devices netns
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100108 *
109 * veth devices come in pairs and each is the parent of the other!
110 *
111 * Return: true if the devices are each others parent, otherwise false
112 */
113static bool batadv_mutual_parents(const struct net_device *dev1,
Sven Eckelmann88ffc7d2016-09-30 15:21:00 +0200114 struct net *net1,
Andrew Lunn275019d2016-07-03 13:31:33 +0200115 const struct net_device *dev2,
Sven Eckelmann88ffc7d2016-09-30 15:21:00 +0200116 struct net *net2)
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100117{
118 int dev1_parent_iflink = dev_get_iflink(dev1);
119 int dev2_parent_iflink = dev_get_iflink(dev2);
Andrew Lunn275019d2016-07-03 13:31:33 +0200120 const struct net *dev1_parent_net;
121 const struct net *dev2_parent_net;
122
123 dev1_parent_net = batadv_getlink_net(dev1, net1);
124 dev2_parent_net = batadv_getlink_net(dev2, net2);
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100125
126 if (!dev1_parent_iflink || !dev2_parent_iflink)
127 return false;
128
129 return (dev1_parent_iflink == dev2->ifindex) &&
Andrew Lunn275019d2016-07-03 13:31:33 +0200130 (dev2_parent_iflink == dev1->ifindex) &&
131 net_eq(dev1_parent_net, net2) &&
132 net_eq(dev2_parent_net, net1);
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100133}
134
135/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100136 * batadv_is_on_batman_iface() - check if a device is a batman iface descendant
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200137 * @net_dev: the device to check
138 *
139 * If the user creates any virtual device on top of a batman-adv interface, it
140 * is important to prevent this new interface to be used to create a new mesh
141 * network (this behaviour would lead to a batman-over-batman configuration).
142 * This function recursively checks all the fathers of the device passed as
143 * argument looking for a batman-adv soft interface.
144 *
Sven Eckelmann62fe7102015-09-15 19:00:48 +0200145 * Return: true if the device is descendant of a batman-adv mesh interface (or
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200146 * if it is a batman-adv interface itself), false otherwise
147 */
148static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
149{
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200150 struct net *net = dev_net(net_dev);
Andrew Lunn275019d2016-07-03 13:31:33 +0200151 struct net_device *parent_dev;
Sven Eckelmann88ffc7d2016-09-30 15:21:00 +0200152 struct net *parent_net;
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200153 bool ret;
154
155 /* check if this is a batman-adv mesh interface */
156 if (batadv_softif_is_valid(net_dev))
157 return true;
158
159 /* no more parents..stop recursion */
Nicolas Dichtela54acb32015-04-02 17:07:00 +0200160 if (dev_get_iflink(net_dev) == 0 ||
161 dev_get_iflink(net_dev) == net_dev->ifindex)
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200162 return false;
163
Andrew Lunn275019d2016-07-03 13:31:33 +0200164 parent_net = batadv_getlink_net(net_dev, net);
165
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200166 /* recurse over the parent device */
Andrew Lunn275019d2016-07-03 13:31:33 +0200167 parent_dev = __dev_get_by_index((struct net *)parent_net,
168 dev_get_iflink(net_dev));
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200169 /* if we got a NULL parent_dev there is something broken.. */
Sven Eckelmann955d3412018-12-30 12:46:01 +0100170 if (!parent_dev) {
171 pr_err("Cannot find parent device\n");
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200172 return false;
Sven Eckelmann955d3412018-12-30 12:46:01 +0100173 }
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200174
Andrew Lunn275019d2016-07-03 13:31:33 +0200175 if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net))
Andrew Lunn1bc4e2b2016-02-11 22:15:57 +0100176 return false;
177
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200178 ret = batadv_is_on_batman_iface(parent_dev);
179
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200180 return ret;
181}
182
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100183static bool batadv_is_valid_iface(const struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000184{
185 if (net_dev->flags & IFF_LOOPBACK)
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100186 return false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000187
188 if (net_dev->type != ARPHRD_ETHER)
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100189 return false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000190
191 if (net_dev->addr_len != ETH_ALEN)
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100192 return false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000193
194 /* no batman over batman */
Antonio Quartullib7eddd02012-09-09 10:46:46 +0200195 if (batadv_is_on_batman_iface(net_dev))
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100196 return false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000197
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100198 return true;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000199}
200
Matthias Schifferde68d102013-03-09 23:14:22 +0100201/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100202 * batadv_get_real_netdevice() - check if the given netdev struct is a virtual
Marek Lindner5ed4a462016-09-30 15:21:04 +0200203 * interface on top of another 'real' interface
204 * @netdev: the device to check
205 *
Marek Lindner1942de12016-09-30 15:21:05 +0200206 * Callers must hold the rtnl semaphore. You may want batadv_get_real_netdev()
207 * instead of this.
208 *
Marek Lindner5ed4a462016-09-30 15:21:04 +0200209 * Return: the 'real' net device or the original net device and NULL in case
210 * of an error.
211 */
212static struct net_device *batadv_get_real_netdevice(struct net_device *netdev)
213{
214 struct batadv_hard_iface *hard_iface = NULL;
215 struct net_device *real_netdev = NULL;
216 struct net *real_net;
217 struct net *net;
218 int ifindex;
219
220 ASSERT_RTNL();
221
222 if (!netdev)
223 return NULL;
224
225 if (netdev->ifindex == dev_get_iflink(netdev)) {
226 dev_hold(netdev);
227 return netdev;
228 }
229
230 hard_iface = batadv_hardif_get_by_netdev(netdev);
231 if (!hard_iface || !hard_iface->soft_iface)
232 goto out;
233
234 net = dev_net(hard_iface->soft_iface);
235 ifindex = dev_get_iflink(netdev);
236 real_net = batadv_getlink_net(netdev, net);
237 real_netdev = dev_get_by_index(real_net, ifindex);
238
239out:
240 if (hard_iface)
241 batadv_hardif_put(hard_iface);
242 return real_netdev;
243}
244
245/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100246 * batadv_get_real_netdev() - check if the given net_device struct is a virtual
Marek Lindner1942de12016-09-30 15:21:05 +0200247 * interface on top of another 'real' interface
Matthias Schifferde68d102013-03-09 23:14:22 +0100248 * @net_device: the device to check
249 *
Marek Lindner1942de12016-09-30 15:21:05 +0200250 * Return: the 'real' net device or the original net device and NULL in case
251 * of an error.
Matthias Schifferde68d102013-03-09 23:14:22 +0100252 */
Marek Lindner1942de12016-09-30 15:21:05 +0200253struct net_device *batadv_get_real_netdev(struct net_device *net_device)
254{
255 struct net_device *real_netdev;
256
257 rtnl_lock();
258 real_netdev = batadv_get_real_netdevice(net_device);
259 rtnl_unlock();
260
261 return real_netdev;
262}
263
264/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100265 * batadv_is_wext_netdev() - check if the given net_device struct is a
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200266 * wext wifi interface
Marek Lindnerf44a3ae2016-09-30 15:21:02 +0200267 * @net_device: the device to check
268 *
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200269 * Return: true if the net device is a wext wireless device, false
Marek Lindnerf44a3ae2016-09-30 15:21:02 +0200270 * otherwise.
271 */
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200272static bool batadv_is_wext_netdev(struct net_device *net_device)
Matthias Schifferde68d102013-03-09 23:14:22 +0100273{
Antonio Quartulli0c69aec2013-10-13 02:50:18 +0200274 if (!net_device)
275 return false;
276
Matthias Schifferde68d102013-03-09 23:14:22 +0100277#ifdef CONFIG_WIRELESS_EXT
278 /* pre-cfg80211 drivers have to implement WEXT, so it is possible to
279 * check for wireless_handlers != NULL
280 */
281 if (net_device->wireless_handlers)
282 return true;
283#endif
284
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200285 return false;
286}
287
288/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100289 * batadv_is_cfg80211_netdev() - check if the given net_device struct is a
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200290 * cfg80211 wifi interface
291 * @net_device: the device to check
292 *
293 * Return: true if the net device is a cfg80211 wireless device, false
294 * otherwise.
295 */
296static bool batadv_is_cfg80211_netdev(struct net_device *net_device)
297{
298 if (!net_device)
299 return false;
300
Matthias Schifferde68d102013-03-09 23:14:22 +0100301 /* cfg80211 drivers have to set ieee80211_ptr */
302 if (net_device->ieee80211_ptr)
303 return true;
304
305 return false;
306}
307
Linus Lüssing3111bee2016-08-07 12:34:19 +0200308/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100309 * batadv_wifi_flags_evaluate() - calculate wifi flags for net_device
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200310 * @net_device: the device to check
311 *
312 * Return: batadv_hard_iface_wifi_flags flags of the device
313 */
314static u32 batadv_wifi_flags_evaluate(struct net_device *net_device)
315{
316 u32 wifi_flags = 0;
Marek Lindner5ed4a462016-09-30 15:21:04 +0200317 struct net_device *real_netdev;
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200318
319 if (batadv_is_wext_netdev(net_device))
320 wifi_flags |= BATADV_HARDIF_WIFI_WEXT_DIRECT;
321
322 if (batadv_is_cfg80211_netdev(net_device))
323 wifi_flags |= BATADV_HARDIF_WIFI_CFG80211_DIRECT;
324
Marek Lindner5ed4a462016-09-30 15:21:04 +0200325 real_netdev = batadv_get_real_netdevice(net_device);
326 if (!real_netdev)
327 return wifi_flags;
328
329 if (real_netdev == net_device)
330 goto out;
331
332 if (batadv_is_wext_netdev(real_netdev))
333 wifi_flags |= BATADV_HARDIF_WIFI_WEXT_INDIRECT;
334
335 if (batadv_is_cfg80211_netdev(real_netdev))
336 wifi_flags |= BATADV_HARDIF_WIFI_CFG80211_INDIRECT;
337
338out:
339 dev_put(real_netdev);
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200340 return wifi_flags;
341}
342
343/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100344 * batadv_is_cfg80211_hardif() - check if the given hardif is a cfg80211 wifi
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200345 * interface
346 * @hard_iface: the device to check
347 *
348 * Return: true if the net device is a cfg80211 wireless device, false
349 * otherwise.
350 */
351bool batadv_is_cfg80211_hardif(struct batadv_hard_iface *hard_iface)
352{
353 u32 allowed_flags = 0;
354
355 allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_DIRECT;
Marek Lindner5ed4a462016-09-30 15:21:04 +0200356 allowed_flags |= BATADV_HARDIF_WIFI_CFG80211_INDIRECT;
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200357
358 return !!(hard_iface->wifi_flags & allowed_flags);
359}
360
361/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100362 * batadv_is_wifi_hardif() - check if the given hardif is a wifi interface
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200363 * @hard_iface: the device to check
364 *
365 * Return: true if the net device is a 802.11 wireless device, false otherwise.
366 */
367bool batadv_is_wifi_hardif(struct batadv_hard_iface *hard_iface)
368{
369 if (!hard_iface)
370 return false;
371
372 return hard_iface->wifi_flags != 0;
Matthias Schifferde68d102013-03-09 23:14:22 +0100373}
374
Linus Lüssing3111bee2016-08-07 12:34:19 +0200375/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100376 * batadv_hardif_no_broadcast() - check whether (re)broadcast is necessary
Linus Lüssing3111bee2016-08-07 12:34:19 +0200377 * @if_outgoing: the outgoing interface checked and considered for (re)broadcast
378 * @orig_addr: the originator of this packet
379 * @orig_neigh: originator address of the forwarder we just got the packet from
380 * (NULL if we originated)
381 *
382 * Checks whether a packet needs to be (re)broadcasted on the given interface.
383 *
384 * Return:
385 * BATADV_HARDIF_BCAST_NORECIPIENT: No neighbor on interface
386 * BATADV_HARDIF_BCAST_DUPFWD: Just one neighbor, but it is the forwarder
387 * BATADV_HARDIF_BCAST_DUPORIG: Just one neighbor, but it is the originator
388 * BATADV_HARDIF_BCAST_OK: Several neighbors, must broadcast
389 */
390int batadv_hardif_no_broadcast(struct batadv_hard_iface *if_outgoing,
391 u8 *orig_addr, u8 *orig_neigh)
392{
393 struct batadv_hardif_neigh_node *hardif_neigh;
394 struct hlist_node *first;
395 int ret = BATADV_HARDIF_BCAST_OK;
396
397 rcu_read_lock();
398
399 /* 0 neighbors -> no (re)broadcast */
400 first = rcu_dereference(hlist_first_rcu(&if_outgoing->neigh_list));
401 if (!first) {
402 ret = BATADV_HARDIF_BCAST_NORECIPIENT;
403 goto out;
404 }
405
406 /* >1 neighbors -> (re)brodcast */
407 if (rcu_dereference(hlist_next_rcu(first)))
408 goto out;
409
410 hardif_neigh = hlist_entry(first, struct batadv_hardif_neigh_node,
411 list);
412
413 /* 1 neighbor, is the originator -> no rebroadcast */
414 if (orig_addr && batadv_compare_eth(hardif_neigh->orig, orig_addr)) {
415 ret = BATADV_HARDIF_BCAST_DUPORIG;
416 /* 1 neighbor, is the one we received from -> no rebroadcast */
417 } else if (orig_neigh &&
418 batadv_compare_eth(hardif_neigh->orig, orig_neigh)) {
419 ret = BATADV_HARDIF_BCAST_DUPFWD;
420 }
421
422out:
423 rcu_read_unlock();
424 return ret;
425}
426
Sven Eckelmann56303d32012-06-05 22:31:31 +0200427static struct batadv_hard_iface *
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200428batadv_hardif_get_active(const struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000429{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200430 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000431
432 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200433 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Marek Lindnere6c10f42011-02-18 12:33:20 +0000434 if (hard_iface->soft_iface != soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000435 continue;
436
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200437 if (hard_iface->if_status == BATADV_IF_ACTIVE &&
Sven Eckelmann7a659d52016-01-16 10:29:54 +0100438 kref_get_unless_zero(&hard_iface->refcount))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000439 goto out;
440 }
441
Marek Lindnere6c10f42011-02-18 12:33:20 +0000442 hard_iface = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000443
444out:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000445 rcu_read_unlock();
Marek Lindnere6c10f42011-02-18 12:33:20 +0000446 return hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000447}
448
Sven Eckelmann56303d32012-06-05 22:31:31 +0200449static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,
450 struct batadv_hard_iface *oldif)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000451{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200452 struct batadv_hard_iface *primary_if;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200453
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200454 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200455 if (!primary_if)
456 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000457
Antonio Quartulli785ea112011-11-23 11:35:44 +0100458 batadv_dat_init_own_addr(bat_priv, primary_if);
Sven Eckelmann08adf152012-05-12 13:38:47 +0200459 batadv_bla_update_orig_address(bat_priv, primary_if, oldif);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200460out:
461 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100462 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000463}
464
Sven Eckelmann56303d32012-06-05 22:31:31 +0200465static void batadv_primary_if_select(struct batadv_priv *bat_priv,
466 struct batadv_hard_iface *new_hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000467{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200468 struct batadv_hard_iface *curr_hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000469
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200470 ASSERT_RTNL();
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000471
Sven Eckelmann17a86912016-04-11 13:06:40 +0200472 if (new_hard_iface)
473 kref_get(&new_hard_iface->refcount);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000474
Sven Eckelmann728cbc62011-05-15 00:50:21 +0200475 curr_hard_iface = rcu_dereference_protected(bat_priv->primary_if, 1);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200476 rcu_assign_pointer(bat_priv->primary_if, new_hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000477
Marek Lindner32ae9b22011-04-20 15:40:58 +0200478 if (!new_hard_iface)
Simon Wunderlich23721382012-01-22 20:00:19 +0100479 goto out;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200480
Antonio Quartulli29824a52016-05-25 23:27:31 +0800481 bat_priv->algo_ops->iface.primary_set(new_hard_iface);
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200482 batadv_primary_if_update_addr(bat_priv, curr_hard_iface);
Simon Wunderlich23721382012-01-22 20:00:19 +0100483
484out:
485 if (curr_hard_iface)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100486 batadv_hardif_put(curr_hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000487}
488
Sven Eckelmann56303d32012-06-05 22:31:31 +0200489static bool
490batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000491{
Marek Lindnere6c10f42011-02-18 12:33:20 +0000492 if (hard_iface->net_dev->flags & IFF_UP)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000493 return true;
494
495 return false;
496}
497
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200498static void batadv_check_known_mac_addr(const struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000499{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200500 const struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000501
502 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200503 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200504 if (hard_iface->if_status != BATADV_IF_ACTIVE &&
505 hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000506 continue;
507
Marek Lindnere6c10f42011-02-18 12:33:20 +0000508 if (hard_iface->net_dev == net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000509 continue;
510
Sven Eckelmann1eda58b2012-05-12 13:48:58 +0200511 if (!batadv_compare_eth(hard_iface->net_dev->dev_addr,
512 net_dev->dev_addr))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000513 continue;
514
Sven Eckelmann67969582012-03-26 16:22:45 +0200515 pr_warn("The newly added mac address (%pM) already exists on: %s\n",
516 net_dev->dev_addr, hard_iface->net_dev->name);
517 pr_warn("It is strongly recommended to keep mac addresses unique to avoid problems!\n");
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000518 }
519 rcu_read_unlock();
520}
521
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200522/**
523 * batadv_hardif_recalc_extra_skbroom() - Recalculate skbuff extra head/tailroom
524 * @soft_iface: netdev struct of the mesh interface
525 */
526static void batadv_hardif_recalc_extra_skbroom(struct net_device *soft_iface)
527{
528 const struct batadv_hard_iface *hard_iface;
529 unsigned short lower_header_len = ETH_HLEN;
530 unsigned short lower_headroom = 0;
531 unsigned short lower_tailroom = 0;
532 unsigned short needed_headroom;
533
534 rcu_read_lock();
535 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
536 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
537 continue;
538
539 if (hard_iface->soft_iface != soft_iface)
540 continue;
541
542 lower_header_len = max_t(unsigned short, lower_header_len,
543 hard_iface->net_dev->hard_header_len);
544
545 lower_headroom = max_t(unsigned short, lower_headroom,
546 hard_iface->net_dev->needed_headroom);
547
548 lower_tailroom = max_t(unsigned short, lower_tailroom,
549 hard_iface->net_dev->needed_tailroom);
550 }
551 rcu_read_unlock();
552
553 needed_headroom = lower_headroom + (lower_header_len - ETH_HLEN);
554 needed_headroom += batadv_max_header_len();
555
556 soft_iface->needed_headroom = needed_headroom;
557 soft_iface->needed_tailroom = lower_tailroom;
558}
559
Sven Eckelmannff15c272017-12-02 19:51:53 +0100560/**
561 * batadv_hardif_min_mtu() - Calculate maximum MTU for soft interface
562 * @soft_iface: netdev struct of the soft interface
563 *
564 * Return: MTU for the soft-interface (limited by the minimal MTU of all active
565 * slave interfaces)
566 */
Sven Eckelmann95638772012-05-12 02:09:31 +0200567int batadv_hardif_min_mtu(struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000568{
Marek Lindnera19d3d82013-05-27 15:33:25 +0800569 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
Sven Eckelmann56303d32012-06-05 22:31:31 +0200570 const struct batadv_hard_iface *hard_iface;
Antonio Quartulli930cd6e2014-01-21 11:22:05 +0100571 int min_mtu = INT_MAX;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000572
573 rcu_read_lock();
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200574 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200575 if (hard_iface->if_status != BATADV_IF_ACTIVE &&
576 hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000577 continue;
578
Marek Lindnere6c10f42011-02-18 12:33:20 +0000579 if (hard_iface->soft_iface != soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000580 continue;
581
Marek Lindnera19d3d82013-05-27 15:33:25 +0800582 min_mtu = min_t(int, hard_iface->net_dev->mtu, min_mtu);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000583 }
584 rcu_read_unlock();
Marek Lindnera19d3d82013-05-27 15:33:25 +0800585
Marek Lindnera19d3d82013-05-27 15:33:25 +0800586 if (atomic_read(&bat_priv->fragmentation) == 0)
587 goto out;
588
589 /* with fragmentation enabled the maximum size of internally generated
590 * packets such as translation table exchanges or tvlv containers, etc
591 * has to be calculated
592 */
593 min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE);
594 min_mtu -= sizeof(struct batadv_frag_packet);
595 min_mtu *= BATADV_FRAG_MAX_FRAGMENTS;
Marek Lindnera19d3d82013-05-27 15:33:25 +0800596
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000597out:
Antonio Quartulli930cd6e2014-01-21 11:22:05 +0100598 /* report to the other components the maximum amount of bytes that
599 * batman-adv can send over the wire (without considering the payload
600 * overhead). For example, this value is used by TT to compute the
601 * maximum local table table size
602 */
603 atomic_set(&bat_priv->packet_size_max, min_mtu);
604
605 /* the real soft-interface MTU is computed by removing the payload
606 * overhead from the maximum amount of bytes that was just computed.
607 *
608 * However batman-adv does not support MTUs bigger than ETH_DATA_LEN
609 */
610 return min_t(int, min_mtu - batadv_max_header_len(), ETH_DATA_LEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000611}
612
Sven Eckelmannff15c272017-12-02 19:51:53 +0100613/**
614 * batadv_update_min_mtu() - Adjusts the MTU if a new interface with a smaller
615 * MTU appeared
616 * @soft_iface: netdev struct of the soft interface
617 */
Sven Eckelmann95638772012-05-12 02:09:31 +0200618void batadv_update_min_mtu(struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000619{
Marek Lindnera19d3d82013-05-27 15:33:25 +0800620 soft_iface->mtu = batadv_hardif_min_mtu(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000621
Marek Lindnera19d3d82013-05-27 15:33:25 +0800622 /* Check if the local translate table should be cleaned up to match a
623 * new (and smaller) MTU.
624 */
625 batadv_tt_local_resize_to_mtu(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000626}
627
Sven Eckelmann56303d32012-06-05 22:31:31 +0200628static void
629batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000630{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200631 struct batadv_priv *bat_priv;
632 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000633
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200634 if (hard_iface->if_status != BATADV_IF_INACTIVE)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200635 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000636
Marek Lindnere6c10f42011-02-18 12:33:20 +0000637 bat_priv = netdev_priv(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000638
Antonio Quartulli29824a52016-05-25 23:27:31 +0800639 bat_priv->algo_ops->iface.update_mac(hard_iface);
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200640 hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000641
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +0200642 /* the first active interface becomes our primary interface or
Antonio Quartulli015758d2011-07-09 17:52:13 +0200643 * the next active interface after the old primary interface was removed
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000644 */
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200645 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200646 if (!primary_if)
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200647 batadv_primary_if_select(bat_priv, hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000648
Sven Eckelmann3e348192012-05-16 20:23:22 +0200649 batadv_info(hard_iface->soft_iface, "Interface activated: %s\n",
650 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000651
Sven Eckelmann95638772012-05-12 02:09:31 +0200652 batadv_update_min_mtu(hard_iface->soft_iface);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200653
Antonio Quartulli29824a52016-05-25 23:27:31 +0800654 if (bat_priv->algo_ops->iface.activate)
655 bat_priv->algo_ops->iface.activate(hard_iface);
Antonio Quartullib6cf5d42016-04-14 09:37:05 +0800656
Marek Lindner32ae9b22011-04-20 15:40:58 +0200657out:
658 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100659 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000660}
661
Sven Eckelmann56303d32012-06-05 22:31:31 +0200662static void
663batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000664{
Sven Eckelmann825ffe12017-08-23 21:52:13 +0200665 if (hard_iface->if_status != BATADV_IF_ACTIVE &&
666 hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000667 return;
668
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200669 hard_iface->if_status = BATADV_IF_INACTIVE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000670
Sven Eckelmann3e348192012-05-16 20:23:22 +0200671 batadv_info(hard_iface->soft_iface, "Interface deactivated: %s\n",
672 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000673
Sven Eckelmann95638772012-05-12 02:09:31 +0200674 batadv_update_min_mtu(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000675}
676
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100677/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100678 * batadv_master_del_slave() - remove hard_iface from the current master iface
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100679 * @slave: the interface enslaved in another master
680 * @master: the master from which slave has to be removed
681 *
682 * Invoke ndo_del_slave on master passing slave as argument. In this way slave
683 * is free'd and master can correctly change its internal state.
Sven Eckelmann62fe7102015-09-15 19:00:48 +0200684 *
685 * Return: 0 on success, a negative value representing the error otherwise
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100686 */
687static int batadv_master_del_slave(struct batadv_hard_iface *slave,
688 struct net_device *master)
689{
690 int ret;
691
692 if (!master)
693 return 0;
694
695 ret = -EBUSY;
696 if (master->netdev_ops->ndo_del_slave)
697 ret = master->netdev_ops->ndo_del_slave(master, slave->net_dev);
698
699 return ret;
700}
701
Sven Eckelmannff15c272017-12-02 19:51:53 +0100702/**
703 * batadv_hardif_enable_interface() - Enslave hard interface to soft interface
704 * @hard_iface: hard interface to add to soft interface
705 * @net: the applicable net namespace
706 * @iface_name: name of the soft interface
707 *
708 * Return: 0 on success or negative error number in case of failure
709 */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200710int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200711 struct net *net, const char *iface_name)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000712{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200713 struct batadv_priv *bat_priv;
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100714 struct net_device *soft_iface, *master;
Antonio Quartulli293e9332013-05-19 12:55:16 +0200715 __be16 ethertype = htons(ETH_P_BATMAN);
Marek Lindner411d6ed2013-05-08 13:31:59 +0800716 int max_header_len = batadv_max_header_len();
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000717 int ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000718
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200719 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000720 goto out;
721
Sven Eckelmann17a86912016-04-11 13:06:40 +0200722 kref_get(&hard_iface->refcount);
Marek Lindnered75ccb2011-02-10 14:33:51 +0000723
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200724 soft_iface = dev_get_by_name(net, iface_name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000725
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000726 if (!soft_iface) {
Andrew Lunn2cd45a02016-04-21 12:57:27 +0200727 soft_iface = batadv_softif_create(net, iface_name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000728
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000729 if (!soft_iface) {
730 ret = -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000731 goto err;
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000732 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000733
734 /* dev_get_by_name() increases the reference counter for us */
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000735 dev_hold(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000736 }
737
Sven Eckelmann04b482a2012-05-12 02:09:38 +0200738 if (!batadv_softif_is_valid(soft_iface)) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100739 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000740 soft_iface->name);
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000741 ret = -EINVAL;
Marek Lindner77af7572012-02-07 17:20:48 +0800742 goto err_dev;
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000743 }
744
Antonio Quartullicb4b0d42013-02-16 14:42:39 +0100745 /* check if the interface is enslaved in another virtual one and
746 * in that case unlink it first
747 */
748 master = netdev_master_upper_dev_get(hard_iface->net_dev);
749 ret = batadv_master_del_slave(hard_iface, master);
750 if (ret)
751 goto err_dev;
752
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000753 hard_iface->soft_iface = soft_iface;
Marek Lindnere6c10f42011-02-18 12:33:20 +0000754 bat_priv = netdev_priv(hard_iface->soft_iface);
Marek Lindnerd0b9fd82011-07-30 12:33:33 +0200755
Jiri Pirko6dffb042015-12-03 12:12:10 +0100756 ret = netdev_master_upper_dev_link(hard_iface->net_dev,
David Ahern42ab19e2017-10-04 17:48:47 -0700757 soft_iface, NULL, NULL, NULL);
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800758 if (ret)
759 goto err_dev;
760
Antonio Quartulli29824a52016-05-25 23:27:31 +0800761 ret = bat_priv->algo_ops->iface.enable(hard_iface);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200762 if (ret < 0)
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800763 goto err_upper;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000764
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200765 hard_iface->if_status = BATADV_IF_INACTIVE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000766
Sven Eckelmannd7d6de92016-03-05 16:09:18 +0100767 kref_get(&hard_iface->refcount);
Sven Eckelmann7e071c72012-06-03 22:19:13 +0200768 hard_iface->batman_adv_ptype.type = ethertype;
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200769 hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
Marek Lindnere6c10f42011-02-18 12:33:20 +0000770 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
771 dev_add_pack(&hard_iface->batman_adv_ptype);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000772
Sven Eckelmann3e348192012-05-16 20:23:22 +0200773 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
774 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000775
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200776 if (atomic_read(&bat_priv->fragmentation) &&
Marek Lindner411d6ed2013-05-08 13:31:59 +0800777 hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len)
Sven Eckelmann3e348192012-05-16 20:23:22 +0200778 batadv_info(hard_iface->soft_iface,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800779 "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 +0200780 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800781 ETH_DATA_LEN + max_header_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000782
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200783 if (!atomic_read(&bat_priv->fragmentation) &&
Marek Lindner411d6ed2013-05-08 13:31:59 +0800784 hard_iface->net_dev->mtu < ETH_DATA_LEN + max_header_len)
Sven Eckelmann3e348192012-05-16 20:23:22 +0200785 batadv_info(hard_iface->soft_iface,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800786 "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 +0200787 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
Marek Lindner411d6ed2013-05-08 13:31:59 +0800788 ETH_DATA_LEN + max_header_len);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000789
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200790 if (batadv_hardif_is_iface_up(hard_iface))
791 batadv_hardif_activate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000792 else
Sven Eckelmann3e348192012-05-16 20:23:22 +0200793 batadv_err(hard_iface->soft_iface,
794 "Not using interface %s (retrying later): interface not active\n",
795 hard_iface->net_dev->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000796
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200797 batadv_hardif_recalc_extra_skbroom(soft_iface);
798
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000799out:
800 return 0;
801
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800802err_upper:
803 netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface);
Marek Lindner77af7572012-02-07 17:20:48 +0800804err_dev:
Sven Eckelmann3dbd5502013-02-11 17:10:27 +0800805 hard_iface->soft_iface = NULL;
Marek Lindner77af7572012-02-07 17:20:48 +0800806 dev_put(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000807err:
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100808 batadv_hardif_put(hard_iface);
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000809 return ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000810}
811
Sven Eckelmannff15c272017-12-02 19:51:53 +0100812/**
Sven Eckelmanndee222c72018-08-16 16:54:45 +0200813 * batadv_hardif_cnt() - get number of interfaces enslaved to soft interface
814 * @soft_iface: soft interface to check
815 *
816 * This function is only using RCU for locking - the result can therefore be
817 * off when another functions is modifying the list at the same time. The
818 * caller can use the rtnl_lock to make sure that the count is accurate.
819 *
820 * Return: number of connected/enslaved hard interfaces
821 */
822static size_t batadv_hardif_cnt(const struct net_device *soft_iface)
823{
824 struct batadv_hard_iface *hard_iface;
825 size_t count = 0;
826
827 rcu_read_lock();
828 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
829 if (hard_iface->soft_iface != soft_iface)
830 continue;
831
832 count++;
833 }
834 rcu_read_unlock();
835
836 return count;
837}
838
839/**
Sven Eckelmannff15c272017-12-02 19:51:53 +0100840 * batadv_hardif_disable_interface() - Remove hard interface from soft interface
841 * @hard_iface: hard interface to be removed
842 * @autodel: whether to delete soft interface when it doesn't contain any other
843 * slave interfaces
844 */
Sven Eckelmanna15fd362013-02-11 17:10:24 +0800845void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
846 enum batadv_hard_if_cleanup autodel)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000847{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200848 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
849 struct batadv_hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000850
Sven Eckelmannf2d23862016-03-19 13:55:21 +0100851 batadv_hardif_deactivate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000852
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200853 if (hard_iface->if_status != BATADV_IF_INACTIVE)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200854 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000855
Sven Eckelmann3e348192012-05-16 20:23:22 +0200856 batadv_info(hard_iface->soft_iface, "Removing interface: %s\n",
857 hard_iface->net_dev->name);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000858 dev_remove_pack(&hard_iface->batman_adv_ptype);
Sven Eckelmannd7d6de92016-03-05 16:09:18 +0100859 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000860
Sven Eckelmanne5d89252012-05-12 13:48:54 +0200861 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200862 if (hard_iface == primary_if) {
Sven Eckelmann56303d32012-06-05 22:31:31 +0200863 struct batadv_hard_iface *new_if;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000864
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200865 new_if = batadv_hardif_get_active(hard_iface->soft_iface);
866 batadv_primary_if_select(bat_priv, new_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000867
868 if (new_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100869 batadv_hardif_put(new_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000870 }
871
Antonio Quartulli29824a52016-05-25 23:27:31 +0800872 bat_priv->algo_ops->iface.disable(hard_iface);
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200873 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000874
Marek Lindnere6c10f42011-02-18 12:33:20 +0000875 /* delete all references to this hard_iface */
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200876 batadv_purge_orig_ref(bat_priv);
Sven Eckelmann9455e342012-05-12 02:09:37 +0200877 batadv_purge_outstanding_packets(bat_priv, hard_iface);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000878 dev_put(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000879
Antonio Quartullia5256f72015-08-04 22:26:19 +0200880 netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface);
Sven Eckelmann7bca68c2015-08-07 19:28:42 +0200881 batadv_hardif_recalc_extra_skbroom(hard_iface->soft_iface);
Antonio Quartullia5256f72015-08-04 22:26:19 +0200882
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000883 /* nobody uses this interface anymore */
Sven Eckelmanndee222c72018-08-16 16:54:45 +0200884 if (batadv_hardif_cnt(hard_iface->soft_iface) <= 1) {
Antonio Quartulli8257f552013-08-19 18:39:59 +0200885 batadv_gw_check_client_stop(bat_priv);
886
887 if (autodel == BATADV_IF_CLEANUP_AUTO)
888 batadv_softif_destroy_sysfs(hard_iface->soft_iface);
889 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000890
Sven Eckelmann27915aa2016-11-02 18:14:43 +0100891 hard_iface->soft_iface = NULL;
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100892 batadv_hardif_put(hard_iface);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200893
894out:
895 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +0100896 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000897}
898
Sven Eckelmann56303d32012-06-05 22:31:31 +0200899static struct batadv_hard_iface *
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200900batadv_hardif_add_interface(struct net_device *net_dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000901{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200902 struct batadv_hard_iface *hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000903 int ret;
904
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200905 ASSERT_RTNL();
906
Sven Eckelmann4b426b12016-02-22 21:02:39 +0100907 if (!batadv_is_valid_iface(net_dev))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000908 goto out;
909
910 dev_hold(net_dev);
911
Antonio Quartulli7db3fc22013-04-02 12:16:53 +0200912 hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC);
Joe Perches320f4222011-08-29 14:17:24 -0700913 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000914 goto release_dev;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000915
Sven Eckelmann5853e222012-05-12 02:09:24 +0200916 ret = batadv_sysfs_add_hardif(&hard_iface->hardif_obj, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000917 if (ret)
918 goto free_if;
919
Marek Lindnere6c10f42011-02-18 12:33:20 +0000920 hard_iface->net_dev = net_dev;
921 hard_iface->soft_iface = NULL;
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200922 hard_iface->if_status = BATADV_IF_NOT_IN_USE;
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100923
924 ret = batadv_debugfs_add_hardif(hard_iface);
925 if (ret)
926 goto free_sysfs;
927
Marek Lindnere6c10f42011-02-18 12:33:20 +0000928 INIT_LIST_HEAD(&hard_iface->list);
Marek Lindnercef63412015-08-04 21:09:55 +0800929 INIT_HLIST_HEAD(&hard_iface->neigh_list);
Simon Wunderlich5bc44dc2013-01-11 10:19:51 +0100930
Marek Lindnercef63412015-08-04 21:09:55 +0800931 spin_lock_init(&hard_iface->neigh_list_lock);
Sven Eckelmannb2367e42016-07-15 17:39:28 +0200932 kref_init(&hard_iface->refcount);
Marek Lindnercef63412015-08-04 21:09:55 +0800933
Matthias Schiffercaf65bf2013-03-09 23:14:23 +0100934 hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
Sven Eckelmann10b1bbb2016-09-30 15:21:03 +0200935 hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev);
936 if (batadv_is_wifi_hardif(hard_iface))
Matthias Schiffercaf65bf2013-03-09 23:14:23 +0100937 hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
938
Marek Lindner7db682d2016-05-10 22:31:59 +0800939 batadv_v_hardif_init(hard_iface);
940
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200941 batadv_check_known_mac_addr(hard_iface->net_dev);
Sven Eckelmannb2367e42016-07-15 17:39:28 +0200942 kref_get(&hard_iface->refcount);
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200943 list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
Sven Eckelmannfb69be62018-10-30 22:01:24 +0100944 batadv_hardif_generation++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000945
Marek Lindnere6c10f42011-02-18 12:33:20 +0000946 return hard_iface;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000947
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100948free_sysfs:
949 batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000950free_if:
Marek Lindnere6c10f42011-02-18 12:33:20 +0000951 kfree(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000952release_dev:
953 dev_put(net_dev);
954out:
955 return NULL;
956}
957
Sven Eckelmann56303d32012-06-05 22:31:31 +0200958static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000959{
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200960 ASSERT_RTNL();
961
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000962 /* first deactivate interface */
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200963 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmanna15fd362013-02-11 17:10:24 +0800964 batadv_hardif_disable_interface(hard_iface,
Sven Eckelmann06d640c2016-07-10 15:47:57 +0200965 BATADV_IF_CLEANUP_KEEP);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000966
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200967 if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000968 return;
969
Sven Eckelmanne9a4f292012-06-03 22:19:19 +0200970 hard_iface->if_status = BATADV_IF_TO_BE_REMOVED;
Sven Eckelmann569c9852016-06-13 07:41:31 +0200971 batadv_debugfs_del_hardif(hard_iface);
972 batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
973 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000974}
975
Sven Eckelmannff15c272017-12-02 19:51:53 +0100976/**
977 * batadv_hardif_remove_interfaces() - Remove all hard interfaces
978 */
Sven Eckelmann95638772012-05-12 02:09:31 +0200979void batadv_hardif_remove_interfaces(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000980{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200981 struct batadv_hard_iface *hard_iface, *hard_iface_tmp;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000982
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200983 rtnl_lock();
Marek Lindnere6c10f42011-02-18 12:33:20 +0000984 list_for_each_entry_safe(hard_iface, hard_iface_tmp,
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200985 &batadv_hardif_list, list) {
Marek Lindnere6c10f42011-02-18 12:33:20 +0000986 list_del_rcu(&hard_iface->list);
Sven Eckelmannfb69be62018-10-30 22:01:24 +0100987 batadv_hardif_generation++;
Sven Eckelmann18a1cb62012-05-12 18:33:57 +0200988 batadv_hardif_remove_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000989 }
990 rtnl_unlock();
991}
992
Sven Eckelmann6da7be72018-06-01 19:24:24 +0200993/**
994 * batadv_hard_if_event_softif() - Handle events for soft interfaces
995 * @event: NETDEV_* event to handle
996 * @net_dev: net_device which generated an event
997 *
998 * Return: NOTIFY_* result
999 */
1000static int batadv_hard_if_event_softif(unsigned long event,
1001 struct net_device *net_dev)
1002{
1003 struct batadv_priv *bat_priv;
1004
1005 switch (event) {
1006 case NETDEV_REGISTER:
1007 batadv_sysfs_add_meshif(net_dev);
1008 bat_priv = netdev_priv(net_dev);
1009 batadv_softif_create_vlan(bat_priv, BATADV_NO_FLAGS);
1010 break;
1011 case NETDEV_CHANGENAME:
1012 batadv_debugfs_rename_meshif(net_dev);
1013 break;
1014 }
1015
1016 return NOTIFY_DONE;
1017}
1018
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001019static int batadv_hard_if_event(struct notifier_block *this,
1020 unsigned long event, void *ptr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001021{
Jiri Pirko351638e2013-05-28 01:30:21 +00001022 struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
Sven Eckelmann56303d32012-06-05 22:31:31 +02001023 struct batadv_hard_iface *hard_iface;
1024 struct batadv_hard_iface *primary_if = NULL;
1025 struct batadv_priv *bat_priv;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001026
Sven Eckelmann6da7be72018-06-01 19:24:24 +02001027 if (batadv_softif_is_valid(net_dev))
1028 return batadv_hard_if_event_softif(event, net_dev);
Sven Eckelmann37130292013-02-11 17:10:22 +08001029
Sven Eckelmann56303d32012-06-05 22:31:31 +02001030 hard_iface = batadv_hardif_get_by_netdev(net_dev);
Andrew Lunna1a66b12015-12-03 21:12:33 +01001031 if (!hard_iface && (event == NETDEV_REGISTER ||
1032 event == NETDEV_POST_TYPE_CHANGE))
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001033 hard_iface = batadv_hardif_add_interface(net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001034
Marek Lindnere6c10f42011-02-18 12:33:20 +00001035 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001036 goto out;
1037
1038 switch (event) {
1039 case NETDEV_UP:
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001040 batadv_hardif_activate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001041 break;
1042 case NETDEV_GOING_DOWN:
1043 case NETDEV_DOWN:
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001044 batadv_hardif_deactivate_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001045 break;
1046 case NETDEV_UNREGISTER:
Andrew Lunna1a66b12015-12-03 21:12:33 +01001047 case NETDEV_PRE_TYPE_CHANGE:
Marek Lindnere6c10f42011-02-18 12:33:20 +00001048 list_del_rcu(&hard_iface->list);
Sven Eckelmannfb69be62018-10-30 22:01:24 +01001049 batadv_hardif_generation++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001050
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001051 batadv_hardif_remove_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001052 break;
1053 case NETDEV_CHANGEMTU:
Marek Lindnere6c10f42011-02-18 12:33:20 +00001054 if (hard_iface->soft_iface)
Sven Eckelmann95638772012-05-12 02:09:31 +02001055 batadv_update_min_mtu(hard_iface->soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001056 break;
1057 case NETDEV_CHANGEADDR:
Sven Eckelmanne9a4f292012-06-03 22:19:19 +02001058 if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001059 goto hardif_put;
1060
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001061 batadv_check_known_mac_addr(hard_iface->net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001062
Marek Lindnere6c10f42011-02-18 12:33:20 +00001063 bat_priv = netdev_priv(hard_iface->soft_iface);
Antonio Quartulli29824a52016-05-25 23:27:31 +08001064 bat_priv->algo_ops->iface.update_mac(hard_iface);
Marek Lindner01c42242011-11-28 21:31:55 +08001065
Sven Eckelmanne5d89252012-05-12 13:48:54 +02001066 primary_if = batadv_primary_if_get_selected(bat_priv);
Marek Lindner32ae9b22011-04-20 15:40:58 +02001067 if (!primary_if)
1068 goto hardif_put;
1069
1070 if (hard_iface == primary_if)
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001071 batadv_primary_if_update_addr(bat_priv, NULL);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001072 break;
Sven Eckelmannee3b5e92016-09-30 15:21:06 +02001073 case NETDEV_CHANGEUPPER:
1074 hard_iface->wifi_flags = batadv_wifi_flags_evaluate(net_dev);
1075 if (batadv_is_wifi_hardif(hard_iface))
1076 hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
1077 break;
Sven Eckelmann36dc6212018-06-01 19:24:23 +02001078 case NETDEV_CHANGENAME:
1079 batadv_debugfs_rename_hardif(hard_iface);
1080 break;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001081 default:
1082 break;
Joe Perchesf81c6222011-06-03 11:51:19 +00001083 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001084
1085hardif_put:
Sven Eckelmann82047ad2016-01-17 11:01:10 +01001086 batadv_hardif_put(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001087out:
Marek Lindner32ae9b22011-04-20 15:40:58 +02001088 if (primary_if)
Sven Eckelmann82047ad2016-01-17 11:01:10 +01001089 batadv_hardif_put(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001090 return NOTIFY_DONE;
1091}
1092
Sven Eckelmann95638772012-05-12 02:09:31 +02001093struct notifier_block batadv_hard_if_notifier = {
Sven Eckelmann18a1cb62012-05-12 18:33:57 +02001094 .notifier_call = batadv_hard_if_event,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001095};