hard-interface.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
  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
  18. */
  19. #include "main.h"
  20. #include "distributed-arp-table.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 "sysfs.h"
  27. #include "originator.h"
  28. #include "hash.h"
  29. #include "bridge_loop_avoidance.h"
  30. #include <linux/if_arp.h>
  31. #include <linux/if_ether.h>
  32. void batadv_hardif_free_rcu(struct rcu_head *rcu)
  33. {
  34. struct batadv_hard_iface *hard_iface;
  35. hard_iface = container_of(rcu, struct batadv_hard_iface, rcu);
  36. dev_put(hard_iface->net_dev);
  37. kfree(hard_iface);
  38. }
  39. struct batadv_hard_iface *
  40. batadv_hardif_get_by_netdev(const struct net_device *net_dev)
  41. {
  42. struct batadv_hard_iface *hard_iface;
  43. rcu_read_lock();
  44. list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
  45. if (hard_iface->net_dev == net_dev &&
  46. atomic_inc_not_zero(&hard_iface->refcount))
  47. goto out;
  48. }
  49. hard_iface = NULL;
  50. out:
  51. rcu_read_unlock();
  52. return hard_iface;
  53. }
  54. /**
  55. * batadv_is_on_batman_iface - check if a device is a batman iface descendant
  56. * @net_dev: the device to check
  57. *
  58. * If the user creates any virtual device on top of a batman-adv interface, it
  59. * is important to prevent this new interface to be used to create a new mesh
  60. * network (this behaviour would lead to a batman-over-batman configuration).
  61. * This function recursively checks all the fathers of the device passed as
  62. * argument looking for a batman-adv soft interface.
  63. *
  64. * Returns true if the device is descendant of a batman-adv mesh interface (or
  65. * if it is a batman-adv interface itself), false otherwise
  66. */
  67. static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
  68. {
  69. struct net_device *parent_dev;
  70. bool ret;
  71. /* check if this is a batman-adv mesh interface */
  72. if (batadv_softif_is_valid(net_dev))
  73. return true;
  74. /* no more parents..stop recursion */
  75. if (net_dev->iflink == net_dev->ifindex)
  76. return false;
  77. /* recurse over the parent device */
  78. parent_dev = dev_get_by_index(&init_net, net_dev->iflink);
  79. /* if we got a NULL parent_dev there is something broken.. */
  80. if (WARN(!parent_dev, "Cannot find parent device"))
  81. return false;
  82. ret = batadv_is_on_batman_iface(parent_dev);
  83. if (parent_dev)
  84. dev_put(parent_dev);
  85. return ret;
  86. }
  87. static int batadv_is_valid_iface(const struct net_device *net_dev)
  88. {
  89. if (net_dev->flags & IFF_LOOPBACK)
  90. return 0;
  91. if (net_dev->type != ARPHRD_ETHER)
  92. return 0;
  93. if (net_dev->addr_len != ETH_ALEN)
  94. return 0;
  95. /* no batman over batman */
  96. if (batadv_is_on_batman_iface(net_dev))
  97. return 0;
  98. return 1;
  99. }
  100. static struct batadv_hard_iface *
  101. batadv_hardif_get_active(const struct net_device *soft_iface)
  102. {
  103. struct batadv_hard_iface *hard_iface;
  104. rcu_read_lock();
  105. list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
  106. if (hard_iface->soft_iface != soft_iface)
  107. continue;
  108. if (hard_iface->if_status == BATADV_IF_ACTIVE &&
  109. atomic_inc_not_zero(&hard_iface->refcount))
  110. goto out;
  111. }
  112. hard_iface = NULL;
  113. out:
  114. rcu_read_unlock();
  115. return hard_iface;
  116. }
  117. static void batadv_primary_if_update_addr(struct batadv_priv *bat_priv,
  118. struct batadv_hard_iface *oldif)
  119. {
  120. struct batadv_vis_packet *vis_packet;
  121. struct batadv_hard_iface *primary_if;
  122. struct sk_buff *skb;
  123. primary_if = batadv_primary_if_get_selected(bat_priv);
  124. if (!primary_if)
  125. goto out;
  126. batadv_dat_init_own_addr(bat_priv, primary_if);
  127. skb = bat_priv->vis.my_info->skb_packet;
  128. vis_packet = (struct batadv_vis_packet *)skb->data;
  129. memcpy(vis_packet->vis_orig, primary_if->net_dev->dev_addr, ETH_ALEN);
  130. memcpy(vis_packet->sender_orig,
  131. primary_if->net_dev->dev_addr, ETH_ALEN);
  132. batadv_bla_update_orig_address(bat_priv, primary_if, oldif);
  133. out:
  134. if (primary_if)
  135. batadv_hardif_free_ref(primary_if);
  136. }
  137. static void batadv_primary_if_select(struct batadv_priv *bat_priv,
  138. struct batadv_hard_iface *new_hard_iface)
  139. {
  140. struct batadv_hard_iface *curr_hard_iface;
  141. ASSERT_RTNL();
  142. if (new_hard_iface && !atomic_inc_not_zero(&new_hard_iface->refcount))
  143. new_hard_iface = NULL;
  144. curr_hard_iface = rcu_dereference_protected(bat_priv->primary_if, 1);
  145. rcu_assign_pointer(bat_priv->primary_if, new_hard_iface);
  146. if (!new_hard_iface)
  147. goto out;
  148. bat_priv->bat_algo_ops->bat_primary_iface_set(new_hard_iface);
  149. batadv_primary_if_update_addr(bat_priv, curr_hard_iface);
  150. out:
  151. if (curr_hard_iface)
  152. batadv_hardif_free_ref(curr_hard_iface);
  153. }
  154. static bool
  155. batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)
  156. {
  157. if (hard_iface->net_dev->flags & IFF_UP)
  158. return true;
  159. return false;
  160. }
  161. static void batadv_check_known_mac_addr(const struct net_device *net_dev)
  162. {
  163. const struct batadv_hard_iface *hard_iface;
  164. rcu_read_lock();
  165. list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
  166. if ((hard_iface->if_status != BATADV_IF_ACTIVE) &&
  167. (hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED))
  168. continue;
  169. if (hard_iface->net_dev == net_dev)
  170. continue;
  171. if (!batadv_compare_eth(hard_iface->net_dev->dev_addr,
  172. net_dev->dev_addr))
  173. continue;
  174. pr_warn("The newly added mac address (%pM) already exists on: %s\n",
  175. net_dev->dev_addr, hard_iface->net_dev->name);
  176. pr_warn("It is strongly recommended to keep mac addresses unique to avoid problems!\n");
  177. }
  178. rcu_read_unlock();
  179. }
  180. int batadv_hardif_min_mtu(struct net_device *soft_iface)
  181. {
  182. const struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  183. const struct batadv_hard_iface *hard_iface;
  184. /* allow big frames if all devices are capable to do so
  185. * (have MTU > 1500 + BAT_HEADER_LEN)
  186. */
  187. int min_mtu = ETH_DATA_LEN;
  188. if (atomic_read(&bat_priv->fragmentation))
  189. goto out;
  190. rcu_read_lock();
  191. list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
  192. if ((hard_iface->if_status != BATADV_IF_ACTIVE) &&
  193. (hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED))
  194. continue;
  195. if (hard_iface->soft_iface != soft_iface)
  196. continue;
  197. min_mtu = min_t(int,
  198. hard_iface->net_dev->mtu - BATADV_HEADER_LEN,
  199. min_mtu);
  200. }
  201. rcu_read_unlock();
  202. out:
  203. return min_mtu;
  204. }
  205. /* adjusts the MTU if a new interface with a smaller MTU appeared. */
  206. void batadv_update_min_mtu(struct net_device *soft_iface)
  207. {
  208. int min_mtu;
  209. min_mtu = batadv_hardif_min_mtu(soft_iface);
  210. if (soft_iface->mtu != min_mtu)
  211. soft_iface->mtu = min_mtu;
  212. }
  213. static void
  214. batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface)
  215. {
  216. struct batadv_priv *bat_priv;
  217. struct batadv_hard_iface *primary_if = NULL;
  218. if (hard_iface->if_status != BATADV_IF_INACTIVE)
  219. goto out;
  220. bat_priv = netdev_priv(hard_iface->soft_iface);
  221. bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
  222. hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED;
  223. /* the first active interface becomes our primary interface or
  224. * the next active interface after the old primary interface was removed
  225. */
  226. primary_if = batadv_primary_if_get_selected(bat_priv);
  227. if (!primary_if)
  228. batadv_primary_if_select(bat_priv, hard_iface);
  229. batadv_info(hard_iface->soft_iface, "Interface activated: %s\n",
  230. hard_iface->net_dev->name);
  231. batadv_update_min_mtu(hard_iface->soft_iface);
  232. out:
  233. if (primary_if)
  234. batadv_hardif_free_ref(primary_if);
  235. }
  236. static void
  237. batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
  238. {
  239. if ((hard_iface->if_status != BATADV_IF_ACTIVE) &&
  240. (hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED))
  241. return;
  242. hard_iface->if_status = BATADV_IF_INACTIVE;
  243. batadv_info(hard_iface->soft_iface, "Interface deactivated: %s\n",
  244. hard_iface->net_dev->name);
  245. batadv_update_min_mtu(hard_iface->soft_iface);
  246. }
  247. int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
  248. const char *iface_name)
  249. {
  250. struct batadv_priv *bat_priv;
  251. struct net_device *soft_iface;
  252. __be16 ethertype = __constant_htons(ETH_P_BATMAN);
  253. int ret;
  254. if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
  255. goto out;
  256. if (!atomic_inc_not_zero(&hard_iface->refcount))
  257. goto out;
  258. /* hard-interface is part of a bridge */
  259. if (hard_iface->net_dev->priv_flags & IFF_BRIDGE_PORT)
  260. 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",
  261. hard_iface->net_dev->name);
  262. soft_iface = dev_get_by_name(&init_net, iface_name);
  263. if (!soft_iface) {
  264. soft_iface = batadv_softif_create(iface_name);
  265. if (!soft_iface) {
  266. ret = -ENOMEM;
  267. goto err;
  268. }
  269. /* dev_get_by_name() increases the reference counter for us */
  270. dev_hold(soft_iface);
  271. }
  272. if (!batadv_softif_is_valid(soft_iface)) {
  273. pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
  274. soft_iface->name);
  275. ret = -EINVAL;
  276. goto err_dev;
  277. }
  278. hard_iface->soft_iface = soft_iface;
  279. bat_priv = netdev_priv(hard_iface->soft_iface);
  280. ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
  281. if (ret < 0)
  282. goto err_dev;
  283. hard_iface->if_num = bat_priv->num_ifaces;
  284. bat_priv->num_ifaces++;
  285. hard_iface->if_status = BATADV_IF_INACTIVE;
  286. ret = batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces);
  287. if (ret < 0) {
  288. bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
  289. bat_priv->num_ifaces--;
  290. hard_iface->if_status = BATADV_IF_NOT_IN_USE;
  291. goto err_dev;
  292. }
  293. hard_iface->batman_adv_ptype.type = ethertype;
  294. hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;
  295. hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
  296. dev_add_pack(&hard_iface->batman_adv_ptype);
  297. atomic_set(&hard_iface->frag_seqno, 1);
  298. batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
  299. hard_iface->net_dev->name);
  300. if (atomic_read(&bat_priv->fragmentation) &&
  301. hard_iface->net_dev->mtu < ETH_DATA_LEN + BATADV_HEADER_LEN)
  302. batadv_info(hard_iface->soft_iface,
  303. "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",
  304. hard_iface->net_dev->name, hard_iface->net_dev->mtu,
  305. ETH_DATA_LEN + BATADV_HEADER_LEN);
  306. if (!atomic_read(&bat_priv->fragmentation) &&
  307. hard_iface->net_dev->mtu < ETH_DATA_LEN + BATADV_HEADER_LEN)
  308. batadv_info(hard_iface->soft_iface,
  309. "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",
  310. hard_iface->net_dev->name, hard_iface->net_dev->mtu,
  311. ETH_DATA_LEN + BATADV_HEADER_LEN);
  312. if (batadv_hardif_is_iface_up(hard_iface))
  313. batadv_hardif_activate_interface(hard_iface);
  314. else
  315. batadv_err(hard_iface->soft_iface,
  316. "Not using interface %s (retrying later): interface not active\n",
  317. hard_iface->net_dev->name);
  318. /* begin scheduling originator messages on that interface */
  319. batadv_schedule_bat_ogm(hard_iface);
  320. out:
  321. return 0;
  322. err_dev:
  323. dev_put(soft_iface);
  324. err:
  325. batadv_hardif_free_ref(hard_iface);
  326. return ret;
  327. }
  328. void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
  329. {
  330. struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  331. struct batadv_hard_iface *primary_if = NULL;
  332. if (hard_iface->if_status == BATADV_IF_ACTIVE)
  333. batadv_hardif_deactivate_interface(hard_iface);
  334. if (hard_iface->if_status != BATADV_IF_INACTIVE)
  335. goto out;
  336. batadv_info(hard_iface->soft_iface, "Removing interface: %s\n",
  337. hard_iface->net_dev->name);
  338. dev_remove_pack(&hard_iface->batman_adv_ptype);
  339. bat_priv->num_ifaces--;
  340. batadv_orig_hash_del_if(hard_iface, bat_priv->num_ifaces);
  341. primary_if = batadv_primary_if_get_selected(bat_priv);
  342. if (hard_iface == primary_if) {
  343. struct batadv_hard_iface *new_if;
  344. new_if = batadv_hardif_get_active(hard_iface->soft_iface);
  345. batadv_primary_if_select(bat_priv, new_if);
  346. if (new_if)
  347. batadv_hardif_free_ref(new_if);
  348. }
  349. bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
  350. hard_iface->if_status = BATADV_IF_NOT_IN_USE;
  351. /* delete all references to this hard_iface */
  352. batadv_purge_orig_ref(bat_priv);
  353. batadv_purge_outstanding_packets(bat_priv, hard_iface);
  354. dev_put(hard_iface->soft_iface);
  355. /* nobody uses this interface anymore */
  356. if (!bat_priv->num_ifaces)
  357. batadv_softif_destroy(hard_iface->soft_iface);
  358. hard_iface->soft_iface = NULL;
  359. batadv_hardif_free_ref(hard_iface);
  360. out:
  361. if (primary_if)
  362. batadv_hardif_free_ref(primary_if);
  363. }
  364. /**
  365. * batadv_hardif_remove_interface_finish - cleans up the remains of a hardif
  366. * @work: work queue item
  367. *
  368. * Free the parts of the hard interface which can not be removed under
  369. * rtnl lock (to prevent deadlock situations).
  370. */
  371. static void batadv_hardif_remove_interface_finish(struct work_struct *work)
  372. {
  373. struct batadv_hard_iface *hard_iface;
  374. hard_iface = container_of(work, struct batadv_hard_iface,
  375. cleanup_work);
  376. batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
  377. batadv_hardif_free_ref(hard_iface);
  378. }
  379. static struct batadv_hard_iface *
  380. batadv_hardif_add_interface(struct net_device *net_dev)
  381. {
  382. struct batadv_hard_iface *hard_iface;
  383. int ret;
  384. ASSERT_RTNL();
  385. ret = batadv_is_valid_iface(net_dev);
  386. if (ret != 1)
  387. goto out;
  388. dev_hold(net_dev);
  389. hard_iface = kmalloc(sizeof(*hard_iface), GFP_ATOMIC);
  390. if (!hard_iface)
  391. goto release_dev;
  392. ret = batadv_sysfs_add_hardif(&hard_iface->hardif_obj, net_dev);
  393. if (ret)
  394. goto free_if;
  395. hard_iface->if_num = -1;
  396. hard_iface->net_dev = net_dev;
  397. hard_iface->soft_iface = NULL;
  398. hard_iface->if_status = BATADV_IF_NOT_IN_USE;
  399. INIT_LIST_HEAD(&hard_iface->list);
  400. INIT_WORK(&hard_iface->cleanup_work,
  401. batadv_hardif_remove_interface_finish);
  402. /* extra reference for return */
  403. atomic_set(&hard_iface->refcount, 2);
  404. batadv_check_known_mac_addr(hard_iface->net_dev);
  405. list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
  406. /* This can't be called via a bat_priv callback because
  407. * we have no bat_priv yet.
  408. */
  409. atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
  410. hard_iface->bat_iv.ogm_buff = NULL;
  411. return hard_iface;
  412. free_if:
  413. kfree(hard_iface);
  414. release_dev:
  415. dev_put(net_dev);
  416. out:
  417. return NULL;
  418. }
  419. static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)
  420. {
  421. ASSERT_RTNL();
  422. /* first deactivate interface */
  423. if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
  424. batadv_hardif_disable_interface(hard_iface);
  425. if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
  426. return;
  427. hard_iface->if_status = BATADV_IF_TO_BE_REMOVED;
  428. queue_work(batadv_event_workqueue, &hard_iface->cleanup_work);
  429. }
  430. void batadv_hardif_remove_interfaces(void)
  431. {
  432. struct batadv_hard_iface *hard_iface, *hard_iface_tmp;
  433. rtnl_lock();
  434. list_for_each_entry_safe(hard_iface, hard_iface_tmp,
  435. &batadv_hardif_list, list) {
  436. list_del_rcu(&hard_iface->list);
  437. batadv_hardif_remove_interface(hard_iface);
  438. }
  439. rtnl_unlock();
  440. }
  441. static int batadv_hard_if_event(struct notifier_block *this,
  442. unsigned long event, void *ptr)
  443. {
  444. struct net_device *net_dev = ptr;
  445. struct batadv_hard_iface *hard_iface;
  446. struct batadv_hard_iface *primary_if = NULL;
  447. struct batadv_priv *bat_priv;
  448. hard_iface = batadv_hardif_get_by_netdev(net_dev);
  449. if (!hard_iface && event == NETDEV_REGISTER)
  450. hard_iface = batadv_hardif_add_interface(net_dev);
  451. if (!hard_iface)
  452. goto out;
  453. switch (event) {
  454. case NETDEV_UP:
  455. batadv_hardif_activate_interface(hard_iface);
  456. break;
  457. case NETDEV_GOING_DOWN:
  458. case NETDEV_DOWN:
  459. batadv_hardif_deactivate_interface(hard_iface);
  460. break;
  461. case NETDEV_UNREGISTER:
  462. list_del_rcu(&hard_iface->list);
  463. batadv_hardif_remove_interface(hard_iface);
  464. break;
  465. case NETDEV_CHANGEMTU:
  466. if (hard_iface->soft_iface)
  467. batadv_update_min_mtu(hard_iface->soft_iface);
  468. break;
  469. case NETDEV_CHANGEADDR:
  470. if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
  471. goto hardif_put;
  472. batadv_check_known_mac_addr(hard_iface->net_dev);
  473. bat_priv = netdev_priv(hard_iface->soft_iface);
  474. bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface);
  475. primary_if = batadv_primary_if_get_selected(bat_priv);
  476. if (!primary_if)
  477. goto hardif_put;
  478. if (hard_iface == primary_if)
  479. batadv_primary_if_update_addr(bat_priv, NULL);
  480. break;
  481. default:
  482. break;
  483. }
  484. hardif_put:
  485. batadv_hardif_free_ref(hard_iface);
  486. out:
  487. if (primary_if)
  488. batadv_hardif_free_ref(primary_if);
  489. return NOTIFY_DONE;
  490. }
  491. /* This function returns true if the interface represented by ifindex is a
  492. * 802.11 wireless device
  493. */
  494. bool batadv_is_wifi_iface(int ifindex)
  495. {
  496. struct net_device *net_device = NULL;
  497. bool ret = false;
  498. if (ifindex == BATADV_NULL_IFINDEX)
  499. goto out;
  500. net_device = dev_get_by_index(&init_net, ifindex);
  501. if (!net_device)
  502. goto out;
  503. #ifdef CONFIG_WIRELESS_EXT
  504. /* pre-cfg80211 drivers have to implement WEXT, so it is possible to
  505. * check for wireless_handlers != NULL
  506. */
  507. if (net_device->wireless_handlers)
  508. ret = true;
  509. else
  510. #endif
  511. /* cfg80211 drivers have to set ieee80211_ptr */
  512. if (net_device->ieee80211_ptr)
  513. ret = true;
  514. out:
  515. if (net_device)
  516. dev_put(net_device);
  517. return ret;
  518. }
  519. struct notifier_block batadv_hard_if_notifier = {
  520. .notifier_call = batadv_hard_if_event,
  521. };