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