hard-interface.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
  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. #include "main.h"
  22. #include "hard-interface.h"
  23. #include "soft-interface.h"
  24. #include "send.h"
  25. #include "translation-table.h"
  26. #include "routing.h"
  27. #include "bat_sysfs.h"
  28. #include "originator.h"
  29. #include "hash.h"
  30. #include <linux/if_arp.h>
  31. static int batman_skb_recv(struct sk_buff *skb,
  32. struct net_device *dev,
  33. struct packet_type *ptype,
  34. struct net_device *orig_dev);
  35. void hardif_free_rcu(struct rcu_head *rcu)
  36. {
  37. struct hard_iface *hard_iface;
  38. hard_iface = container_of(rcu, struct hard_iface, rcu);
  39. dev_put(hard_iface->net_dev);
  40. kfree(hard_iface);
  41. }
  42. struct hard_iface *hardif_get_by_netdev(const struct net_device *net_dev)
  43. {
  44. struct hard_iface *hard_iface;
  45. rcu_read_lock();
  46. list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
  47. if (hard_iface->net_dev == net_dev &&
  48. atomic_inc_not_zero(&hard_iface->refcount))
  49. goto out;
  50. }
  51. hard_iface = NULL;
  52. out:
  53. rcu_read_unlock();
  54. return hard_iface;
  55. }
  56. static int is_valid_iface(const struct net_device *net_dev)
  57. {
  58. if (net_dev->flags & IFF_LOOPBACK)
  59. return 0;
  60. if (net_dev->type != ARPHRD_ETHER)
  61. return 0;
  62. if (net_dev->addr_len != ETH_ALEN)
  63. return 0;
  64. /* no batman over batman */
  65. if (softif_is_valid(net_dev))
  66. return 0;
  67. /* Device is being bridged */
  68. /* if (net_dev->priv_flags & IFF_BRIDGE_PORT)
  69. return 0; */
  70. return 1;
  71. }
  72. static struct hard_iface *hardif_get_active(const struct net_device *soft_iface)
  73. {
  74. struct hard_iface *hard_iface;
  75. rcu_read_lock();
  76. list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
  77. if (hard_iface->soft_iface != soft_iface)
  78. continue;
  79. if (hard_iface->if_status == IF_ACTIVE &&
  80. atomic_inc_not_zero(&hard_iface->refcount))
  81. goto out;
  82. }
  83. hard_iface = NULL;
  84. out:
  85. rcu_read_unlock();
  86. return hard_iface;
  87. }
  88. static void primary_if_update_addr(struct bat_priv *bat_priv)
  89. {
  90. struct vis_packet *vis_packet;
  91. struct hard_iface *primary_if;
  92. primary_if = primary_if_get_selected(bat_priv);
  93. if (!primary_if)
  94. goto out;
  95. vis_packet = (struct vis_packet *)
  96. bat_priv->my_vis_info->skb_packet->data;
  97. memcpy(vis_packet->vis_orig, primary_if->net_dev->dev_addr, ETH_ALEN);
  98. memcpy(vis_packet->sender_orig,
  99. primary_if->net_dev->dev_addr, ETH_ALEN);
  100. out:
  101. if (primary_if)
  102. hardif_free_ref(primary_if);
  103. }
  104. static void primary_if_select(struct bat_priv *bat_priv,
  105. struct hard_iface *new_hard_iface)
  106. {
  107. struct hard_iface *curr_hard_iface;
  108. ASSERT_RTNL();
  109. if (new_hard_iface && !atomic_inc_not_zero(&new_hard_iface->refcount))
  110. new_hard_iface = NULL;
  111. curr_hard_iface = rcu_dereference_protected(bat_priv->primary_if, 1);
  112. rcu_assign_pointer(bat_priv->primary_if, new_hard_iface);
  113. if (curr_hard_iface)
  114. hardif_free_ref(curr_hard_iface);
  115. if (!new_hard_iface)
  116. return;
  117. bat_priv->bat_algo_ops->bat_ogm_init_primary(new_hard_iface);
  118. primary_if_update_addr(bat_priv);
  119. }
  120. static bool hardif_is_iface_up(const struct hard_iface *hard_iface)
  121. {
  122. if (hard_iface->net_dev->flags & IFF_UP)
  123. return true;
  124. return false;
  125. }
  126. static void check_known_mac_addr(const struct net_device *net_dev)
  127. {
  128. const struct hard_iface *hard_iface;
  129. rcu_read_lock();
  130. list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
  131. if ((hard_iface->if_status != IF_ACTIVE) &&
  132. (hard_iface->if_status != IF_TO_BE_ACTIVATED))
  133. continue;
  134. if (hard_iface->net_dev == net_dev)
  135. continue;
  136. if (!compare_eth(hard_iface->net_dev->dev_addr,
  137. net_dev->dev_addr))
  138. continue;
  139. pr_warning("The newly added mac address (%pM) already exists "
  140. "on: %s\n", net_dev->dev_addr,
  141. hard_iface->net_dev->name);
  142. pr_warning("It is strongly recommended to keep mac addresses "
  143. "unique to avoid problems!\n");
  144. }
  145. rcu_read_unlock();
  146. }
  147. int hardif_min_mtu(struct net_device *soft_iface)
  148. {
  149. const struct bat_priv *bat_priv = netdev_priv(soft_iface);
  150. const struct hard_iface *hard_iface;
  151. /* allow big frames if all devices are capable to do so
  152. * (have MTU > 1500 + BAT_HEADER_LEN) */
  153. int min_mtu = ETH_DATA_LEN;
  154. if (atomic_read(&bat_priv->fragmentation))
  155. goto out;
  156. rcu_read_lock();
  157. list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
  158. if ((hard_iface->if_status != IF_ACTIVE) &&
  159. (hard_iface->if_status != IF_TO_BE_ACTIVATED))
  160. continue;
  161. if (hard_iface->soft_iface != soft_iface)
  162. continue;
  163. min_mtu = min_t(int, hard_iface->net_dev->mtu - BAT_HEADER_LEN,
  164. min_mtu);
  165. }
  166. rcu_read_unlock();
  167. out:
  168. return min_mtu;
  169. }
  170. /* adjusts the MTU if a new interface with a smaller MTU appeared. */
  171. void update_min_mtu(struct net_device *soft_iface)
  172. {
  173. int min_mtu;
  174. min_mtu = hardif_min_mtu(soft_iface);
  175. if (soft_iface->mtu != min_mtu)
  176. soft_iface->mtu = min_mtu;
  177. }
  178. static void hardif_activate_interface(struct hard_iface *hard_iface)
  179. {
  180. struct bat_priv *bat_priv;
  181. struct hard_iface *primary_if = NULL;
  182. if (hard_iface->if_status != IF_INACTIVE)
  183. goto out;
  184. bat_priv = netdev_priv(hard_iface->soft_iface);
  185. bat_priv->bat_algo_ops->bat_ogm_update_mac(hard_iface);
  186. hard_iface->if_status = IF_TO_BE_ACTIVATED;
  187. /**
  188. * the first active interface becomes our primary interface or
  189. * the next active interface after the old primary interface was removed
  190. */
  191. primary_if = primary_if_get_selected(bat_priv);
  192. if (!primary_if)
  193. primary_if_select(bat_priv, hard_iface);
  194. bat_info(hard_iface->soft_iface, "Interface activated: %s\n",
  195. hard_iface->net_dev->name);
  196. update_min_mtu(hard_iface->soft_iface);
  197. out:
  198. if (primary_if)
  199. hardif_free_ref(primary_if);
  200. }
  201. static void hardif_deactivate_interface(struct hard_iface *hard_iface)
  202. {
  203. if ((hard_iface->if_status != IF_ACTIVE) &&
  204. (hard_iface->if_status != IF_TO_BE_ACTIVATED))
  205. return;
  206. hard_iface->if_status = IF_INACTIVE;
  207. bat_info(hard_iface->soft_iface, "Interface deactivated: %s\n",
  208. hard_iface->net_dev->name);
  209. update_min_mtu(hard_iface->soft_iface);
  210. }
  211. int hardif_enable_interface(struct hard_iface *hard_iface,
  212. const char *iface_name)
  213. {
  214. struct bat_priv *bat_priv;
  215. struct net_device *soft_iface;
  216. int ret;
  217. if (hard_iface->if_status != IF_NOT_IN_USE)
  218. goto out;
  219. if (!atomic_inc_not_zero(&hard_iface->refcount))
  220. goto out;
  221. /* hard-interface is part of a bridge */
  222. if (hard_iface->net_dev->priv_flags & IFF_BRIDGE_PORT)
  223. pr_err("You are about to enable batman-adv on '%s' which "
  224. "already is part of a bridge. Unless you know exactly "
  225. "what you are doing this is probably wrong and won't "
  226. "work the way you think it would.\n",
  227. hard_iface->net_dev->name);
  228. soft_iface = dev_get_by_name(&init_net, iface_name);
  229. if (!soft_iface) {
  230. soft_iface = softif_create(iface_name);
  231. if (!soft_iface) {
  232. ret = -ENOMEM;
  233. goto err;
  234. }
  235. /* dev_get_by_name() increases the reference counter for us */
  236. dev_hold(soft_iface);
  237. }
  238. if (!softif_is_valid(soft_iface)) {
  239. pr_err("Can't create batman mesh interface %s: "
  240. "already exists as regular interface\n",
  241. soft_iface->name);
  242. dev_put(soft_iface);
  243. ret = -EINVAL;
  244. goto err;
  245. }
  246. hard_iface->soft_iface = soft_iface;
  247. bat_priv = netdev_priv(hard_iface->soft_iface);
  248. bat_priv->bat_algo_ops->bat_ogm_init(hard_iface);
  249. if (!hard_iface->packet_buff) {
  250. bat_err(hard_iface->soft_iface, "Can't add interface packet "
  251. "(%s): out of memory\n", hard_iface->net_dev->name);
  252. ret = -ENOMEM;
  253. goto err;
  254. }
  255. hard_iface->if_num = bat_priv->num_ifaces;
  256. bat_priv->num_ifaces++;
  257. hard_iface->if_status = IF_INACTIVE;
  258. orig_hash_add_if(hard_iface, bat_priv->num_ifaces);
  259. hard_iface->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN);
  260. hard_iface->batman_adv_ptype.func = batman_skb_recv;
  261. hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
  262. dev_add_pack(&hard_iface->batman_adv_ptype);
  263. atomic_set(&hard_iface->seqno, 1);
  264. atomic_set(&hard_iface->frag_seqno, 1);
  265. bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
  266. hard_iface->net_dev->name);
  267. if (atomic_read(&bat_priv->fragmentation) && hard_iface->net_dev->mtu <
  268. ETH_DATA_LEN + BAT_HEADER_LEN)
  269. bat_info(hard_iface->soft_iface,
  270. "The MTU of interface %s is too small (%i) to handle "
  271. "the transport of batman-adv packets. Packets going "
  272. "over this interface will be fragmented on layer2 "
  273. "which could impact the performance. Setting the MTU "
  274. "to %zi would solve the problem.\n",
  275. hard_iface->net_dev->name, hard_iface->net_dev->mtu,
  276. ETH_DATA_LEN + BAT_HEADER_LEN);
  277. if (!atomic_read(&bat_priv->fragmentation) && hard_iface->net_dev->mtu <
  278. ETH_DATA_LEN + BAT_HEADER_LEN)
  279. bat_info(hard_iface->soft_iface,
  280. "The MTU of interface %s is too small (%i) to handle "
  281. "the transport of batman-adv packets. If you experience"
  282. " problems getting traffic through try increasing the "
  283. "MTU to %zi.\n",
  284. hard_iface->net_dev->name, hard_iface->net_dev->mtu,
  285. ETH_DATA_LEN + BAT_HEADER_LEN);
  286. if (hardif_is_iface_up(hard_iface))
  287. hardif_activate_interface(hard_iface);
  288. else
  289. bat_err(hard_iface->soft_iface, "Not using interface %s "
  290. "(retrying later): interface not active\n",
  291. hard_iface->net_dev->name);
  292. /* begin scheduling originator messages on that interface */
  293. schedule_bat_ogm(hard_iface);
  294. out:
  295. return 0;
  296. err:
  297. hardif_free_ref(hard_iface);
  298. return ret;
  299. }
  300. void hardif_disable_interface(struct hard_iface *hard_iface)
  301. {
  302. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  303. struct hard_iface *primary_if = NULL;
  304. if (hard_iface->if_status == IF_ACTIVE)
  305. hardif_deactivate_interface(hard_iface);
  306. if (hard_iface->if_status != IF_INACTIVE)
  307. goto out;
  308. bat_info(hard_iface->soft_iface, "Removing interface: %s\n",
  309. hard_iface->net_dev->name);
  310. dev_remove_pack(&hard_iface->batman_adv_ptype);
  311. bat_priv->num_ifaces--;
  312. orig_hash_del_if(hard_iface, bat_priv->num_ifaces);
  313. primary_if = primary_if_get_selected(bat_priv);
  314. if (hard_iface == primary_if) {
  315. struct hard_iface *new_if;
  316. new_if = hardif_get_active(hard_iface->soft_iface);
  317. primary_if_select(bat_priv, new_if);
  318. if (new_if)
  319. hardif_free_ref(new_if);
  320. }
  321. kfree(hard_iface->packet_buff);
  322. hard_iface->packet_buff = NULL;
  323. hard_iface->if_status = IF_NOT_IN_USE;
  324. /* delete all references to this hard_iface */
  325. purge_orig_ref(bat_priv);
  326. purge_outstanding_packets(bat_priv, hard_iface);
  327. dev_put(hard_iface->soft_iface);
  328. /* nobody uses this interface anymore */
  329. if (!bat_priv->num_ifaces)
  330. softif_destroy(hard_iface->soft_iface);
  331. hard_iface->soft_iface = NULL;
  332. hardif_free_ref(hard_iface);
  333. out:
  334. if (primary_if)
  335. hardif_free_ref(primary_if);
  336. }
  337. static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
  338. {
  339. struct hard_iface *hard_iface;
  340. int ret;
  341. ASSERT_RTNL();
  342. ret = is_valid_iface(net_dev);
  343. if (ret != 1)
  344. goto out;
  345. dev_hold(net_dev);
  346. hard_iface = kmalloc(sizeof(*hard_iface), GFP_ATOMIC);
  347. if (!hard_iface)
  348. goto release_dev;
  349. ret = sysfs_add_hardif(&hard_iface->hardif_obj, net_dev);
  350. if (ret)
  351. goto free_if;
  352. hard_iface->if_num = -1;
  353. hard_iface->net_dev = net_dev;
  354. hard_iface->soft_iface = NULL;
  355. hard_iface->if_status = IF_NOT_IN_USE;
  356. INIT_LIST_HEAD(&hard_iface->list);
  357. /* extra reference for return */
  358. atomic_set(&hard_iface->refcount, 2);
  359. check_known_mac_addr(hard_iface->net_dev);
  360. list_add_tail_rcu(&hard_iface->list, &hardif_list);
  361. return hard_iface;
  362. free_if:
  363. kfree(hard_iface);
  364. release_dev:
  365. dev_put(net_dev);
  366. out:
  367. return NULL;
  368. }
  369. static void hardif_remove_interface(struct hard_iface *hard_iface)
  370. {
  371. ASSERT_RTNL();
  372. /* first deactivate interface */
  373. if (hard_iface->if_status != IF_NOT_IN_USE)
  374. hardif_disable_interface(hard_iface);
  375. if (hard_iface->if_status != IF_NOT_IN_USE)
  376. return;
  377. hard_iface->if_status = IF_TO_BE_REMOVED;
  378. sysfs_del_hardif(&hard_iface->hardif_obj);
  379. hardif_free_ref(hard_iface);
  380. }
  381. void hardif_remove_interfaces(void)
  382. {
  383. struct hard_iface *hard_iface, *hard_iface_tmp;
  384. rtnl_lock();
  385. list_for_each_entry_safe(hard_iface, hard_iface_tmp,
  386. &hardif_list, list) {
  387. list_del_rcu(&hard_iface->list);
  388. hardif_remove_interface(hard_iface);
  389. }
  390. rtnl_unlock();
  391. }
  392. static int hard_if_event(struct notifier_block *this,
  393. unsigned long event, void *ptr)
  394. {
  395. struct net_device *net_dev = ptr;
  396. struct hard_iface *hard_iface = hardif_get_by_netdev(net_dev);
  397. struct hard_iface *primary_if = NULL;
  398. struct bat_priv *bat_priv;
  399. if (!hard_iface && event == NETDEV_REGISTER)
  400. hard_iface = hardif_add_interface(net_dev);
  401. if (!hard_iface)
  402. goto out;
  403. switch (event) {
  404. case NETDEV_UP:
  405. hardif_activate_interface(hard_iface);
  406. break;
  407. case NETDEV_GOING_DOWN:
  408. case NETDEV_DOWN:
  409. hardif_deactivate_interface(hard_iface);
  410. break;
  411. case NETDEV_UNREGISTER:
  412. list_del_rcu(&hard_iface->list);
  413. hardif_remove_interface(hard_iface);
  414. break;
  415. case NETDEV_CHANGEMTU:
  416. if (hard_iface->soft_iface)
  417. update_min_mtu(hard_iface->soft_iface);
  418. break;
  419. case NETDEV_CHANGEADDR:
  420. if (hard_iface->if_status == IF_NOT_IN_USE)
  421. goto hardif_put;
  422. check_known_mac_addr(hard_iface->net_dev);
  423. bat_priv = netdev_priv(hard_iface->soft_iface);
  424. bat_priv->bat_algo_ops->bat_ogm_update_mac(hard_iface);
  425. primary_if = primary_if_get_selected(bat_priv);
  426. if (!primary_if)
  427. goto hardif_put;
  428. if (hard_iface == primary_if)
  429. primary_if_update_addr(bat_priv);
  430. break;
  431. default:
  432. break;
  433. }
  434. hardif_put:
  435. hardif_free_ref(hard_iface);
  436. out:
  437. if (primary_if)
  438. hardif_free_ref(primary_if);
  439. return NOTIFY_DONE;
  440. }
  441. /* incoming packets with the batman ethertype received on any active hard
  442. * interface */
  443. static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
  444. struct packet_type *ptype,
  445. struct net_device *orig_dev)
  446. {
  447. struct bat_priv *bat_priv;
  448. struct batman_ogm_packet *batman_ogm_packet;
  449. struct hard_iface *hard_iface;
  450. int ret;
  451. hard_iface = container_of(ptype, struct hard_iface, batman_adv_ptype);
  452. skb = skb_share_check(skb, GFP_ATOMIC);
  453. /* skb was released by skb_share_check() */
  454. if (!skb)
  455. goto err_out;
  456. /* packet should hold at least type and version */
  457. if (unlikely(!pskb_may_pull(skb, 2)))
  458. goto err_free;
  459. /* expect a valid ethernet header here. */
  460. if (unlikely(skb->mac_len != sizeof(struct ethhdr)
  461. || !skb_mac_header(skb)))
  462. goto err_free;
  463. if (!hard_iface->soft_iface)
  464. goto err_free;
  465. bat_priv = netdev_priv(hard_iface->soft_iface);
  466. if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
  467. goto err_free;
  468. /* discard frames on not active interfaces */
  469. if (hard_iface->if_status != IF_ACTIVE)
  470. goto err_free;
  471. batman_ogm_packet = (struct batman_ogm_packet *)skb->data;
  472. if (batman_ogm_packet->header.version != COMPAT_VERSION) {
  473. bat_dbg(DBG_BATMAN, bat_priv,
  474. "Drop packet: incompatible batman version (%i)\n",
  475. batman_ogm_packet->header.version);
  476. goto err_free;
  477. }
  478. /* all receive handlers return whether they received or reused
  479. * the supplied skb. if not, we have to free the skb. */
  480. switch (batman_ogm_packet->header.packet_type) {
  481. /* batman originator packet */
  482. case BAT_OGM:
  483. ret = recv_bat_ogm_packet(skb, hard_iface);
  484. break;
  485. /* batman icmp packet */
  486. case BAT_ICMP:
  487. ret = recv_icmp_packet(skb, hard_iface);
  488. break;
  489. /* unicast packet */
  490. case BAT_UNICAST:
  491. ret = recv_unicast_packet(skb, hard_iface);
  492. break;
  493. /* fragmented unicast packet */
  494. case BAT_UNICAST_FRAG:
  495. ret = recv_ucast_frag_packet(skb, hard_iface);
  496. break;
  497. /* broadcast packet */
  498. case BAT_BCAST:
  499. ret = recv_bcast_packet(skb, hard_iface);
  500. break;
  501. /* vis packet */
  502. case BAT_VIS:
  503. ret = recv_vis_packet(skb, hard_iface);
  504. break;
  505. /* Translation table query (request or response) */
  506. case BAT_TT_QUERY:
  507. ret = recv_tt_query(skb, hard_iface);
  508. break;
  509. /* Roaming advertisement */
  510. case BAT_ROAM_ADV:
  511. ret = recv_roam_adv(skb, hard_iface);
  512. break;
  513. default:
  514. ret = NET_RX_DROP;
  515. }
  516. if (ret == NET_RX_DROP)
  517. kfree_skb(skb);
  518. /* return NET_RX_SUCCESS in any case as we
  519. * most probably dropped the packet for
  520. * routing-logical reasons. */
  521. return NET_RX_SUCCESS;
  522. err_free:
  523. kfree_skb(skb);
  524. err_out:
  525. return NET_RX_DROP;
  526. }
  527. /* This function returns true if the interface represented by ifindex is a
  528. * 802.11 wireless device */
  529. bool is_wifi_iface(int ifindex)
  530. {
  531. struct net_device *net_device = NULL;
  532. bool ret = false;
  533. if (ifindex == NULL_IFINDEX)
  534. goto out;
  535. net_device = dev_get_by_index(&init_net, ifindex);
  536. if (!net_device)
  537. goto out;
  538. #ifdef CONFIG_WIRELESS_EXT
  539. /* pre-cfg80211 drivers have to implement WEXT, so it is possible to
  540. * check for wireless_handlers != NULL */
  541. if (net_device->wireless_handlers)
  542. ret = true;
  543. else
  544. #endif
  545. /* cfg80211 drivers have to set ieee80211_ptr */
  546. if (net_device->ieee80211_ptr)
  547. ret = true;
  548. out:
  549. if (net_device)
  550. dev_put(net_device);
  551. return ret;
  552. }
  553. struct notifier_block hard_if_notifier = {
  554. .notifier_call = hard_if_event,
  555. };