hard-interface.c 17 KB

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