]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - net/batman-adv/hard-interface.c
batman-adv: Prefix remaining function like macros with batadv_
[mirror_ubuntu-jammy-kernel.git] / net / batman-adv / hard-interface.c
CommitLineData
9cfc7bd6 1/* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
c6c8fea2
SE
2 *
3 * Marek Lindner, Simon Wunderlich
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
c6c8fea2
SE
18 */
19
20#include "main.h"
21#include "hard-interface.h"
22#include "soft-interface.h"
23#include "send.h"
24#include "translation-table.h"
25#include "routing.h"
26#include "bat_sysfs.h"
27#include "originator.h"
28#include "hash.h"
23721387 29#include "bridge_loop_avoidance.h"
c6c8fea2
SE
30
31#include <linux/if_arp.h>
32
9563877e 33void batadv_hardif_free_rcu(struct rcu_head *rcu)
c6c8fea2 34{
e6c10f43 35 struct hard_iface *hard_iface;
c6c8fea2 36
e6c10f43
ML
37 hard_iface = container_of(rcu, struct hard_iface, rcu);
38 dev_put(hard_iface->net_dev);
39 kfree(hard_iface);
c6c8fea2
SE
40}
41
9563877e 42struct hard_iface *batadv_hardif_get_by_netdev(const struct net_device *net_dev)
c6c8fea2 43{
e6c10f43 44 struct hard_iface *hard_iface;
c6c8fea2
SE
45
46 rcu_read_lock();
3193e8fd 47 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
e6c10f43
ML
48 if (hard_iface->net_dev == net_dev &&
49 atomic_inc_not_zero(&hard_iface->refcount))
c6c8fea2
SE
50 goto out;
51 }
52
e6c10f43 53 hard_iface = NULL;
c6c8fea2
SE
54
55out:
c6c8fea2 56 rcu_read_unlock();
e6c10f43 57 return hard_iface;
c6c8fea2
SE
58}
59
18a1cb6e 60static int batadv_is_valid_iface(const struct net_device *net_dev)
c6c8fea2
SE
61{
62 if (net_dev->flags & IFF_LOOPBACK)
63 return 0;
64
65 if (net_dev->type != ARPHRD_ETHER)
66 return 0;
67
68 if (net_dev->addr_len != ETH_ALEN)
69 return 0;
70
71 /* no batman over batman */
04b482a2 72 if (batadv_softif_is_valid(net_dev))
c6c8fea2 73 return 0;
c6c8fea2 74
c6c8fea2
SE
75 return 1;
76}
77
18a1cb6e
SE
78static struct hard_iface *
79batadv_hardif_get_active(const struct net_device *soft_iface)
c6c8fea2 80{
e6c10f43 81 struct hard_iface *hard_iface;
c6c8fea2
SE
82
83 rcu_read_lock();
3193e8fd 84 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
e6c10f43 85 if (hard_iface->soft_iface != soft_iface)
c6c8fea2
SE
86 continue;
87
e6c10f43
ML
88 if (hard_iface->if_status == IF_ACTIVE &&
89 atomic_inc_not_zero(&hard_iface->refcount))
c6c8fea2
SE
90 goto out;
91 }
92
e6c10f43 93 hard_iface = NULL;
c6c8fea2
SE
94
95out:
c6c8fea2 96 rcu_read_unlock();
e6c10f43 97 return hard_iface;
c6c8fea2
SE
98}
99
18a1cb6e
SE
100static void batadv_primary_if_update_addr(struct bat_priv *bat_priv,
101 struct hard_iface *oldif)
c6c8fea2
SE
102{
103 struct vis_packet *vis_packet;
32ae9b22
ML
104 struct hard_iface *primary_if;
105
e5d89254 106 primary_if = batadv_primary_if_get_selected(bat_priv);
32ae9b22
ML
107 if (!primary_if)
108 goto out;
c6c8fea2
SE
109
110 vis_packet = (struct vis_packet *)
111 bat_priv->my_vis_info->skb_packet->data;
32ae9b22 112 memcpy(vis_packet->vis_orig, primary_if->net_dev->dev_addr, ETH_ALEN);
c6c8fea2 113 memcpy(vis_packet->sender_orig,
32ae9b22
ML
114 primary_if->net_dev->dev_addr, ETH_ALEN);
115
08adf151 116 batadv_bla_update_orig_address(bat_priv, primary_if, oldif);
32ae9b22
ML
117out:
118 if (primary_if)
e5d89254 119 batadv_hardif_free_ref(primary_if);
c6c8fea2
SE
120}
121
18a1cb6e
SE
122static void batadv_primary_if_select(struct bat_priv *bat_priv,
123 struct hard_iface *new_hard_iface)
c6c8fea2 124{
32ae9b22 125 struct hard_iface *curr_hard_iface;
c6c8fea2 126
c3caf519 127 ASSERT_RTNL();
c6c8fea2 128
32ae9b22
ML
129 if (new_hard_iface && !atomic_inc_not_zero(&new_hard_iface->refcount))
130 new_hard_iface = NULL;
c6c8fea2 131
728cbc6a 132 curr_hard_iface = rcu_dereference_protected(bat_priv->primary_if, 1);
32ae9b22 133 rcu_assign_pointer(bat_priv->primary_if, new_hard_iface);
c6c8fea2 134
32ae9b22 135 if (!new_hard_iface)
23721387 136 goto out;
32ae9b22 137
cd8b78e7 138 bat_priv->bat_algo_ops->bat_primary_iface_set(new_hard_iface);
18a1cb6e 139 batadv_primary_if_update_addr(bat_priv, curr_hard_iface);
23721387
SW
140
141out:
142 if (curr_hard_iface)
e5d89254 143 batadv_hardif_free_ref(curr_hard_iface);
c6c8fea2
SE
144}
145
18a1cb6e 146static bool batadv_hardif_is_iface_up(const struct hard_iface *hard_iface)
c6c8fea2 147{
e6c10f43 148 if (hard_iface->net_dev->flags & IFF_UP)
c6c8fea2
SE
149 return true;
150
151 return false;
152}
153
18a1cb6e 154static void batadv_check_known_mac_addr(const struct net_device *net_dev)
c6c8fea2 155{
747e4221 156 const struct hard_iface *hard_iface;
c6c8fea2
SE
157
158 rcu_read_lock();
3193e8fd 159 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
e6c10f43
ML
160 if ((hard_iface->if_status != IF_ACTIVE) &&
161 (hard_iface->if_status != IF_TO_BE_ACTIVATED))
c6c8fea2
SE
162 continue;
163
e6c10f43 164 if (hard_iface->net_dev == net_dev)
c6c8fea2
SE
165 continue;
166
1eda58bf
SE
167 if (!batadv_compare_eth(hard_iface->net_dev->dev_addr,
168 net_dev->dev_addr))
c6c8fea2
SE
169 continue;
170
67969581
SE
171 pr_warn("The newly added mac address (%pM) already exists on: %s\n",
172 net_dev->dev_addr, hard_iface->net_dev->name);
173 pr_warn("It is strongly recommended to keep mac addresses unique to avoid problems!\n");
c6c8fea2
SE
174 }
175 rcu_read_unlock();
176}
177
9563877e 178int batadv_hardif_min_mtu(struct net_device *soft_iface)
c6c8fea2 179{
747e4221
SE
180 const struct bat_priv *bat_priv = netdev_priv(soft_iface);
181 const struct hard_iface *hard_iface;
c6c8fea2 182 /* allow big frames if all devices are capable to do so
9cfc7bd6
SE
183 * (have MTU > 1500 + BAT_HEADER_LEN)
184 */
c6c8fea2
SE
185 int min_mtu = ETH_DATA_LEN;
186
187 if (atomic_read(&bat_priv->fragmentation))
188 goto out;
189
190 rcu_read_lock();
3193e8fd 191 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
e6c10f43
ML
192 if ((hard_iface->if_status != IF_ACTIVE) &&
193 (hard_iface->if_status != IF_TO_BE_ACTIVATED))
c6c8fea2
SE
194 continue;
195
e6c10f43 196 if (hard_iface->soft_iface != soft_iface)
c6c8fea2
SE
197 continue;
198
e6c10f43 199 min_mtu = min_t(int, hard_iface->net_dev->mtu - BAT_HEADER_LEN,
c6c8fea2
SE
200 min_mtu);
201 }
202 rcu_read_unlock();
203out:
204 return min_mtu;
205}
206
207/* adjusts the MTU if a new interface with a smaller MTU appeared. */
9563877e 208void batadv_update_min_mtu(struct net_device *soft_iface)
c6c8fea2
SE
209{
210 int min_mtu;
211
9563877e 212 min_mtu = batadv_hardif_min_mtu(soft_iface);
c6c8fea2
SE
213 if (soft_iface->mtu != min_mtu)
214 soft_iface->mtu = min_mtu;
215}
216
18a1cb6e 217static void batadv_hardif_activate_interface(struct hard_iface *hard_iface)
c6c8fea2
SE
218{
219 struct bat_priv *bat_priv;
32ae9b22 220 struct hard_iface *primary_if = NULL;
c6c8fea2 221
e6c10f43 222 if (hard_iface->if_status != IF_INACTIVE)
32ae9b22 223 goto out;
c6c8fea2 224
e6c10f43 225 bat_priv = netdev_priv(hard_iface->soft_iface);
c6c8fea2 226
c3229398 227 bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
e6c10f43 228 hard_iface->if_status = IF_TO_BE_ACTIVATED;
c6c8fea2 229
9cfc7bd6 230 /* the first active interface becomes our primary interface or
015758d0 231 * the next active interface after the old primary interface was removed
c6c8fea2 232 */
e5d89254 233 primary_if = batadv_primary_if_get_selected(bat_priv);
32ae9b22 234 if (!primary_if)
18a1cb6e 235 batadv_primary_if_select(bat_priv, hard_iface);
c6c8fea2 236
3e34819e
SE
237 batadv_info(hard_iface->soft_iface, "Interface activated: %s\n",
238 hard_iface->net_dev->name);
c6c8fea2 239
9563877e 240 batadv_update_min_mtu(hard_iface->soft_iface);
32ae9b22
ML
241
242out:
243 if (primary_if)
e5d89254 244 batadv_hardif_free_ref(primary_if);
c6c8fea2
SE
245}
246
18a1cb6e 247static void batadv_hardif_deactivate_interface(struct hard_iface *hard_iface)
c6c8fea2 248{
e6c10f43
ML
249 if ((hard_iface->if_status != IF_ACTIVE) &&
250 (hard_iface->if_status != IF_TO_BE_ACTIVATED))
c6c8fea2
SE
251 return;
252
e6c10f43 253 hard_iface->if_status = IF_INACTIVE;
c6c8fea2 254
3e34819e
SE
255 batadv_info(hard_iface->soft_iface, "Interface deactivated: %s\n",
256 hard_iface->net_dev->name);
c6c8fea2 257
9563877e 258 batadv_update_min_mtu(hard_iface->soft_iface);
c6c8fea2
SE
259}
260
9563877e
SE
261int batadv_hardif_enable_interface(struct hard_iface *hard_iface,
262 const char *iface_name)
c6c8fea2
SE
263{
264 struct bat_priv *bat_priv;
e44d8fe2
SE
265 struct net_device *soft_iface;
266 int ret;
c6c8fea2 267
e6c10f43 268 if (hard_iface->if_status != IF_NOT_IN_USE)
c6c8fea2
SE
269 goto out;
270
e6c10f43 271 if (!atomic_inc_not_zero(&hard_iface->refcount))
ed75ccbe
ML
272 goto out;
273
6e242f90
ML
274 /* hard-interface is part of a bridge */
275 if (hard_iface->net_dev->priv_flags & IFF_BRIDGE_PORT)
86ceb360 276 pr_err("You are about to enable batman-adv on '%s' which already is part of a bridge. Unless you know exactly what you are doing this is probably wrong and won't work the way you think it would.\n",
6e242f90
ML
277 hard_iface->net_dev->name);
278
e44d8fe2 279 soft_iface = dev_get_by_name(&init_net, iface_name);
c6c8fea2 280
e44d8fe2 281 if (!soft_iface) {
04b482a2 282 soft_iface = batadv_softif_create(iface_name);
c6c8fea2 283
e44d8fe2
SE
284 if (!soft_iface) {
285 ret = -ENOMEM;
c6c8fea2 286 goto err;
e44d8fe2 287 }
c6c8fea2
SE
288
289 /* dev_get_by_name() increases the reference counter for us */
e44d8fe2
SE
290 dev_hold(soft_iface);
291 }
292
04b482a2 293 if (!batadv_softif_is_valid(soft_iface)) {
86ceb360 294 pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
e44d8fe2 295 soft_iface->name);
e44d8fe2 296 ret = -EINVAL;
77af7575 297 goto err_dev;
c6c8fea2
SE
298 }
299
e44d8fe2 300 hard_iface->soft_iface = soft_iface;
e6c10f43 301 bat_priv = netdev_priv(hard_iface->soft_iface);
d0b9fd89 302
77af7575 303 ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
5346c35e 304 if (ret < 0)
77af7575 305 goto err_dev;
c6c8fea2 306
e6c10f43 307 hard_iface->if_num = bat_priv->num_ifaces;
c6c8fea2 308 bat_priv->num_ifaces++;
e6c10f43 309 hard_iface->if_status = IF_INACTIVE;
7d211efc 310 batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces);
c6c8fea2 311
e6c10f43 312 hard_iface->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN);
3193e8fd 313 hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
e6c10f43
ML
314 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
315 dev_add_pack(&hard_iface->batman_adv_ptype);
c6c8fea2 316
e6c10f43 317 atomic_set(&hard_iface->frag_seqno, 1);
3e34819e
SE
318 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
319 hard_iface->net_dev->name);
c6c8fea2 320
e6c10f43 321 if (atomic_read(&bat_priv->fragmentation) && hard_iface->net_dev->mtu <
c6c8fea2 322 ETH_DATA_LEN + BAT_HEADER_LEN)
3e34819e
SE
323 batadv_info(hard_iface->soft_iface,
324 "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 %zi would solve the problem.\n",
325 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
326 ETH_DATA_LEN + BAT_HEADER_LEN);
c6c8fea2 327
e6c10f43 328 if (!atomic_read(&bat_priv->fragmentation) && hard_iface->net_dev->mtu <
c6c8fea2 329 ETH_DATA_LEN + BAT_HEADER_LEN)
3e34819e
SE
330 batadv_info(hard_iface->soft_iface,
331 "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 %zi.\n",
332 hard_iface->net_dev->name, hard_iface->net_dev->mtu,
333 ETH_DATA_LEN + BAT_HEADER_LEN);
c6c8fea2 334
18a1cb6e
SE
335 if (batadv_hardif_is_iface_up(hard_iface))
336 batadv_hardif_activate_interface(hard_iface);
c6c8fea2 337 else
3e34819e
SE
338 batadv_err(hard_iface->soft_iface,
339 "Not using interface %s (retrying later): interface not active\n",
340 hard_iface->net_dev->name);
c6c8fea2
SE
341
342 /* begin scheduling originator messages on that interface */
9455e34c 343 batadv_schedule_bat_ogm(hard_iface);
c6c8fea2
SE
344
345out:
346 return 0;
347
77af7575
ML
348err_dev:
349 dev_put(soft_iface);
c6c8fea2 350err:
e5d89254 351 batadv_hardif_free_ref(hard_iface);
e44d8fe2 352 return ret;
c6c8fea2
SE
353}
354
9563877e 355void batadv_hardif_disable_interface(struct hard_iface *hard_iface)
c6c8fea2 356{
e6c10f43 357 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
32ae9b22 358 struct hard_iface *primary_if = NULL;
c6c8fea2 359
e6c10f43 360 if (hard_iface->if_status == IF_ACTIVE)
18a1cb6e 361 batadv_hardif_deactivate_interface(hard_iface);
c6c8fea2 362
e6c10f43 363 if (hard_iface->if_status != IF_INACTIVE)
32ae9b22 364 goto out;
c6c8fea2 365
3e34819e
SE
366 batadv_info(hard_iface->soft_iface, "Removing interface: %s\n",
367 hard_iface->net_dev->name);
e6c10f43 368 dev_remove_pack(&hard_iface->batman_adv_ptype);
c6c8fea2
SE
369
370 bat_priv->num_ifaces--;
7d211efc 371 batadv_orig_hash_del_if(hard_iface, bat_priv->num_ifaces);
c6c8fea2 372
e5d89254 373 primary_if = batadv_primary_if_get_selected(bat_priv);
32ae9b22 374 if (hard_iface == primary_if) {
e6c10f43 375 struct hard_iface *new_if;
c6c8fea2 376
18a1cb6e
SE
377 new_if = batadv_hardif_get_active(hard_iface->soft_iface);
378 batadv_primary_if_select(bat_priv, new_if);
c6c8fea2
SE
379
380 if (new_if)
e5d89254 381 batadv_hardif_free_ref(new_if);
c6c8fea2
SE
382 }
383
00a50076 384 bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
e6c10f43 385 hard_iface->if_status = IF_NOT_IN_USE;
c6c8fea2 386
e6c10f43 387 /* delete all references to this hard_iface */
7d211efc 388 batadv_purge_orig_ref(bat_priv);
9455e34c 389 batadv_purge_outstanding_packets(bat_priv, hard_iface);
e6c10f43 390 dev_put(hard_iface->soft_iface);
c6c8fea2
SE
391
392 /* nobody uses this interface anymore */
393 if (!bat_priv->num_ifaces)
04b482a2 394 batadv_softif_destroy(hard_iface->soft_iface);
c6c8fea2 395
e6c10f43 396 hard_iface->soft_iface = NULL;
e5d89254 397 batadv_hardif_free_ref(hard_iface);
32ae9b22
ML
398
399out:
400 if (primary_if)
e5d89254 401 batadv_hardif_free_ref(primary_if);
c6c8fea2
SE
402}
403
18a1cb6e
SE
404static struct hard_iface *
405batadv_hardif_add_interface(struct net_device *net_dev)
c6c8fea2 406{
e6c10f43 407 struct hard_iface *hard_iface;
c6c8fea2
SE
408 int ret;
409
c3caf519
SE
410 ASSERT_RTNL();
411
18a1cb6e 412 ret = batadv_is_valid_iface(net_dev);
c6c8fea2
SE
413 if (ret != 1)
414 goto out;
415
416 dev_hold(net_dev);
417
704509b8 418 hard_iface = kmalloc(sizeof(*hard_iface), GFP_ATOMIC);
320f422f 419 if (!hard_iface)
c6c8fea2 420 goto release_dev;
c6c8fea2 421
5853e22c 422 ret = batadv_sysfs_add_hardif(&hard_iface->hardif_obj, net_dev);
c6c8fea2
SE
423 if (ret)
424 goto free_if;
425
e6c10f43
ML
426 hard_iface->if_num = -1;
427 hard_iface->net_dev = net_dev;
428 hard_iface->soft_iface = NULL;
429 hard_iface->if_status = IF_NOT_IN_USE;
430 INIT_LIST_HEAD(&hard_iface->list);
ed75ccbe 431 /* extra reference for return */
e6c10f43 432 atomic_set(&hard_iface->refcount, 2);
c6c8fea2 433
18a1cb6e 434 batadv_check_known_mac_addr(hard_iface->net_dev);
3193e8fd 435 list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
c6c8fea2 436
9cfc7bd6 437 /* This can't be called via a bat_priv callback because
8140625e
ML
438 * we have no bat_priv yet.
439 */
440 atomic_set(&hard_iface->seqno, 1);
441 hard_iface->packet_buff = NULL;
442
e6c10f43 443 return hard_iface;
c6c8fea2
SE
444
445free_if:
e6c10f43 446 kfree(hard_iface);
c6c8fea2
SE
447release_dev:
448 dev_put(net_dev);
449out:
450 return NULL;
451}
452
18a1cb6e 453static void batadv_hardif_remove_interface(struct hard_iface *hard_iface)
c6c8fea2 454{
c3caf519
SE
455 ASSERT_RTNL();
456
c6c8fea2 457 /* first deactivate interface */
e6c10f43 458 if (hard_iface->if_status != IF_NOT_IN_USE)
9563877e 459 batadv_hardif_disable_interface(hard_iface);
c6c8fea2 460
e6c10f43 461 if (hard_iface->if_status != IF_NOT_IN_USE)
c6c8fea2
SE
462 return;
463
e6c10f43 464 hard_iface->if_status = IF_TO_BE_REMOVED;
5853e22c 465 batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
e5d89254 466 batadv_hardif_free_ref(hard_iface);
c6c8fea2
SE
467}
468
9563877e 469void batadv_hardif_remove_interfaces(void)
c6c8fea2 470{
e6c10f43 471 struct hard_iface *hard_iface, *hard_iface_tmp;
c6c8fea2 472
c3caf519 473 rtnl_lock();
e6c10f43 474 list_for_each_entry_safe(hard_iface, hard_iface_tmp,
3193e8fd 475 &batadv_hardif_list, list) {
e6c10f43 476 list_del_rcu(&hard_iface->list);
18a1cb6e 477 batadv_hardif_remove_interface(hard_iface);
c6c8fea2
SE
478 }
479 rtnl_unlock();
480}
481
18a1cb6e
SE
482static int batadv_hard_if_event(struct notifier_block *this,
483 unsigned long event, void *ptr)
c6c8fea2 484{
5f718c20 485 struct net_device *net_dev = ptr;
9563877e 486 struct hard_iface *hard_iface = batadv_hardif_get_by_netdev(net_dev);
32ae9b22 487 struct hard_iface *primary_if = NULL;
c6c8fea2
SE
488 struct bat_priv *bat_priv;
489
e6c10f43 490 if (!hard_iface && event == NETDEV_REGISTER)
18a1cb6e 491 hard_iface = batadv_hardif_add_interface(net_dev);
c6c8fea2 492
e6c10f43 493 if (!hard_iface)
c6c8fea2
SE
494 goto out;
495
496 switch (event) {
497 case NETDEV_UP:
18a1cb6e 498 batadv_hardif_activate_interface(hard_iface);
c6c8fea2
SE
499 break;
500 case NETDEV_GOING_DOWN:
501 case NETDEV_DOWN:
18a1cb6e 502 batadv_hardif_deactivate_interface(hard_iface);
c6c8fea2
SE
503 break;
504 case NETDEV_UNREGISTER:
e6c10f43 505 list_del_rcu(&hard_iface->list);
c6c8fea2 506
18a1cb6e 507 batadv_hardif_remove_interface(hard_iface);
c6c8fea2
SE
508 break;
509 case NETDEV_CHANGEMTU:
e6c10f43 510 if (hard_iface->soft_iface)
9563877e 511 batadv_update_min_mtu(hard_iface->soft_iface);
c6c8fea2
SE
512 break;
513 case NETDEV_CHANGEADDR:
e6c10f43 514 if (hard_iface->if_status == IF_NOT_IN_USE)
c6c8fea2
SE
515 goto hardif_put;
516
18a1cb6e 517 batadv_check_known_mac_addr(hard_iface->net_dev);
c6c8fea2 518
e6c10f43 519 bat_priv = netdev_priv(hard_iface->soft_iface);
c3229398 520 bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
01c4224b 521
e5d89254 522 primary_if = batadv_primary_if_get_selected(bat_priv);
32ae9b22
ML
523 if (!primary_if)
524 goto hardif_put;
525
526 if (hard_iface == primary_if)
18a1cb6e 527 batadv_primary_if_update_addr(bat_priv, NULL);
c6c8fea2
SE
528 break;
529 default:
530 break;
f81c6224 531 }
c6c8fea2
SE
532
533hardif_put:
e5d89254 534 batadv_hardif_free_ref(hard_iface);
c6c8fea2 535out:
32ae9b22 536 if (primary_if)
e5d89254 537 batadv_hardif_free_ref(primary_if);
c6c8fea2
SE
538 return NOTIFY_DONE;
539}
540
bc279080 541/* This function returns true if the interface represented by ifindex is a
9cfc7bd6
SE
542 * 802.11 wireless device
543 */
9563877e 544bool batadv_is_wifi_iface(int ifindex)
bc279080
AQ
545{
546 struct net_device *net_device = NULL;
547 bool ret = false;
548
549 if (ifindex == NULL_IFINDEX)
550 goto out;
551
552 net_device = dev_get_by_index(&init_net, ifindex);
553 if (!net_device)
554 goto out;
555
556#ifdef CONFIG_WIRELESS_EXT
557 /* pre-cfg80211 drivers have to implement WEXT, so it is possible to
9cfc7bd6
SE
558 * check for wireless_handlers != NULL
559 */
bc279080
AQ
560 if (net_device->wireless_handlers)
561 ret = true;
562 else
563#endif
564 /* cfg80211 drivers have to set ieee80211_ptr */
565 if (net_device->ieee80211_ptr)
566 ret = true;
567out:
568 if (net_device)
569 dev_put(net_device);
570 return ret;
571}
572
9563877e 573struct notifier_block batadv_hard_if_notifier = {
18a1cb6e 574 .notifier_call = batadv_hard_if_event,
c6c8fea2 575};