main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /* Copyright (C) 2007-2016 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, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "main.h"
  18. #include <linux/atomic.h>
  19. #include <linux/bug.h>
  20. #include <linux/byteorder/generic.h>
  21. #include <linux/crc32c.h>
  22. #include <linux/errno.h>
  23. #include <linux/fs.h>
  24. #include <linux/if_ether.h>
  25. #include <linux/if_vlan.h>
  26. #include <linux/init.h>
  27. #include <linux/ip.h>
  28. #include <linux/ipv6.h>
  29. #include <linux/kernel.h>
  30. #include <linux/kref.h>
  31. #include <linux/list.h>
  32. #include <linux/module.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/printk.h>
  35. #include <linux/rculist.h>
  36. #include <linux/rcupdate.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/skbuff.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/stddef.h>
  41. #include <linux/string.h>
  42. #include <linux/workqueue.h>
  43. #include <net/dsfield.h>
  44. #include <net/rtnetlink.h>
  45. #include "bat_algo.h"
  46. #include "bat_iv_ogm.h"
  47. #include "bat_v.h"
  48. #include "bridge_loop_avoidance.h"
  49. #include "debugfs.h"
  50. #include "distributed-arp-table.h"
  51. #include "gateway_client.h"
  52. #include "gateway_common.h"
  53. #include "hard-interface.h"
  54. #include "icmp_socket.h"
  55. #include "log.h"
  56. #include "multicast.h"
  57. #include "netlink.h"
  58. #include "network-coding.h"
  59. #include "originator.h"
  60. #include "packet.h"
  61. #include "routing.h"
  62. #include "send.h"
  63. #include "soft-interface.h"
  64. #include "tp_meter.h"
  65. #include "translation-table.h"
  66. /* List manipulations on hardif_list have to be rtnl_lock()'ed,
  67. * list traversals just rcu-locked
  68. */
  69. struct list_head batadv_hardif_list;
  70. static int (*batadv_rx_handler[256])(struct sk_buff *,
  71. struct batadv_hard_iface *);
  72. unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  73. struct workqueue_struct *batadv_event_workqueue;
  74. static void batadv_recv_handler_init(void);
  75. static int __init batadv_init(void)
  76. {
  77. int ret;
  78. ret = batadv_tt_cache_init();
  79. if (ret < 0)
  80. return ret;
  81. INIT_LIST_HEAD(&batadv_hardif_list);
  82. batadv_algo_init();
  83. batadv_recv_handler_init();
  84. batadv_v_init();
  85. batadv_iv_init();
  86. batadv_nc_init();
  87. batadv_tp_meter_init();
  88. batadv_event_workqueue = create_singlethread_workqueue("bat_events");
  89. if (!batadv_event_workqueue)
  90. goto err_create_wq;
  91. batadv_socket_init();
  92. batadv_debugfs_init();
  93. register_netdevice_notifier(&batadv_hard_if_notifier);
  94. rtnl_link_register(&batadv_link_ops);
  95. batadv_netlink_register();
  96. pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n",
  97. BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION);
  98. return 0;
  99. err_create_wq:
  100. batadv_tt_cache_destroy();
  101. return -ENOMEM;
  102. }
  103. static void __exit batadv_exit(void)
  104. {
  105. batadv_debugfs_destroy();
  106. batadv_netlink_unregister();
  107. rtnl_link_unregister(&batadv_link_ops);
  108. unregister_netdevice_notifier(&batadv_hard_if_notifier);
  109. batadv_hardif_remove_interfaces();
  110. flush_workqueue(batadv_event_workqueue);
  111. destroy_workqueue(batadv_event_workqueue);
  112. batadv_event_workqueue = NULL;
  113. rcu_barrier();
  114. batadv_tt_cache_destroy();
  115. }
  116. int batadv_mesh_init(struct net_device *soft_iface)
  117. {
  118. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  119. int ret;
  120. spin_lock_init(&bat_priv->forw_bat_list_lock);
  121. spin_lock_init(&bat_priv->forw_bcast_list_lock);
  122. spin_lock_init(&bat_priv->tt.changes_list_lock);
  123. spin_lock_init(&bat_priv->tt.req_list_lock);
  124. spin_lock_init(&bat_priv->tt.roam_list_lock);
  125. spin_lock_init(&bat_priv->tt.last_changeset_lock);
  126. spin_lock_init(&bat_priv->tt.commit_lock);
  127. spin_lock_init(&bat_priv->gw.list_lock);
  128. #ifdef CONFIG_BATMAN_ADV_MCAST
  129. spin_lock_init(&bat_priv->mcast.want_lists_lock);
  130. #endif
  131. spin_lock_init(&bat_priv->tvlv.container_list_lock);
  132. spin_lock_init(&bat_priv->tvlv.handler_list_lock);
  133. spin_lock_init(&bat_priv->softif_vlan_list_lock);
  134. spin_lock_init(&bat_priv->tp_list_lock);
  135. INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
  136. INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
  137. INIT_HLIST_HEAD(&bat_priv->gw.list);
  138. #ifdef CONFIG_BATMAN_ADV_MCAST
  139. INIT_HLIST_HEAD(&bat_priv->mcast.want_all_unsnoopables_list);
  140. INIT_HLIST_HEAD(&bat_priv->mcast.want_all_ipv4_list);
  141. INIT_HLIST_HEAD(&bat_priv->mcast.want_all_ipv6_list);
  142. #endif
  143. INIT_LIST_HEAD(&bat_priv->tt.changes_list);
  144. INIT_HLIST_HEAD(&bat_priv->tt.req_list);
  145. INIT_LIST_HEAD(&bat_priv->tt.roam_list);
  146. #ifdef CONFIG_BATMAN_ADV_MCAST
  147. INIT_HLIST_HEAD(&bat_priv->mcast.mla_list);
  148. #endif
  149. INIT_HLIST_HEAD(&bat_priv->tvlv.container_list);
  150. INIT_HLIST_HEAD(&bat_priv->tvlv.handler_list);
  151. INIT_HLIST_HEAD(&bat_priv->softif_vlan_list);
  152. INIT_HLIST_HEAD(&bat_priv->tp_list);
  153. ret = batadv_v_mesh_init(bat_priv);
  154. if (ret < 0)
  155. goto err;
  156. ret = batadv_originator_init(bat_priv);
  157. if (ret < 0)
  158. goto err;
  159. ret = batadv_tt_init(bat_priv);
  160. if (ret < 0)
  161. goto err;
  162. ret = batadv_bla_init(bat_priv);
  163. if (ret < 0)
  164. goto err;
  165. ret = batadv_dat_init(bat_priv);
  166. if (ret < 0)
  167. goto err;
  168. ret = batadv_nc_mesh_init(bat_priv);
  169. if (ret < 0)
  170. goto err;
  171. batadv_gw_init(bat_priv);
  172. batadv_mcast_init(bat_priv);
  173. atomic_set(&bat_priv->gw.reselect, 0);
  174. atomic_set(&bat_priv->mesh_state, BATADV_MESH_ACTIVE);
  175. return 0;
  176. err:
  177. batadv_mesh_free(soft_iface);
  178. return ret;
  179. }
  180. void batadv_mesh_free(struct net_device *soft_iface)
  181. {
  182. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  183. atomic_set(&bat_priv->mesh_state, BATADV_MESH_DEACTIVATING);
  184. batadv_purge_outstanding_packets(bat_priv, NULL);
  185. batadv_gw_node_free(bat_priv);
  186. batadv_v_mesh_free(bat_priv);
  187. batadv_nc_mesh_free(bat_priv);
  188. batadv_dat_free(bat_priv);
  189. batadv_bla_free(bat_priv);
  190. batadv_mcast_free(bat_priv);
  191. /* Free the TT and the originator tables only after having terminated
  192. * all the other depending components which may use these structures for
  193. * their purposes.
  194. */
  195. batadv_tt_free(bat_priv);
  196. /* Since the originator table clean up routine is accessing the TT
  197. * tables as well, it has to be invoked after the TT tables have been
  198. * freed and marked as empty. This ensures that no cleanup RCU callbacks
  199. * accessing the TT data are scheduled for later execution.
  200. */
  201. batadv_originator_free(bat_priv);
  202. batadv_gw_free(bat_priv);
  203. free_percpu(bat_priv->bat_counters);
  204. bat_priv->bat_counters = NULL;
  205. atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
  206. }
  207. /**
  208. * batadv_is_my_mac - check if the given mac address belongs to any of the real
  209. * interfaces in the current mesh
  210. * @bat_priv: the bat priv with all the soft interface information
  211. * @addr: the address to check
  212. *
  213. * Return: 'true' if the mac address was found, false otherwise.
  214. */
  215. bool batadv_is_my_mac(struct batadv_priv *bat_priv, const u8 *addr)
  216. {
  217. const struct batadv_hard_iface *hard_iface;
  218. bool is_my_mac = false;
  219. rcu_read_lock();
  220. list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
  221. if (hard_iface->if_status != BATADV_IF_ACTIVE)
  222. continue;
  223. if (hard_iface->soft_iface != bat_priv->soft_iface)
  224. continue;
  225. if (batadv_compare_eth(hard_iface->net_dev->dev_addr, addr)) {
  226. is_my_mac = true;
  227. break;
  228. }
  229. }
  230. rcu_read_unlock();
  231. return is_my_mac;
  232. }
  233. #ifdef CONFIG_BATMAN_ADV_DEBUGFS
  234. /**
  235. * batadv_seq_print_text_primary_if_get - called from debugfs table printing
  236. * function that requires the primary interface
  237. * @seq: debugfs table seq_file struct
  238. *
  239. * Return: primary interface if found or NULL otherwise.
  240. */
  241. struct batadv_hard_iface *
  242. batadv_seq_print_text_primary_if_get(struct seq_file *seq)
  243. {
  244. struct net_device *net_dev = (struct net_device *)seq->private;
  245. struct batadv_priv *bat_priv = netdev_priv(net_dev);
  246. struct batadv_hard_iface *primary_if;
  247. primary_if = batadv_primary_if_get_selected(bat_priv);
  248. if (!primary_if) {
  249. seq_printf(seq,
  250. "BATMAN mesh %s disabled - please specify interfaces to enable it\n",
  251. net_dev->name);
  252. goto out;
  253. }
  254. if (primary_if->if_status == BATADV_IF_ACTIVE)
  255. goto out;
  256. seq_printf(seq,
  257. "BATMAN mesh %s disabled - primary interface not active\n",
  258. net_dev->name);
  259. batadv_hardif_put(primary_if);
  260. primary_if = NULL;
  261. out:
  262. return primary_if;
  263. }
  264. #endif
  265. /**
  266. * batadv_max_header_len - calculate maximum encapsulation overhead for a
  267. * payload packet
  268. *
  269. * Return: the maximum encapsulation overhead in bytes.
  270. */
  271. int batadv_max_header_len(void)
  272. {
  273. int header_len = 0;
  274. header_len = max_t(int, header_len,
  275. sizeof(struct batadv_unicast_packet));
  276. header_len = max_t(int, header_len,
  277. sizeof(struct batadv_unicast_4addr_packet));
  278. header_len = max_t(int, header_len,
  279. sizeof(struct batadv_bcast_packet));
  280. #ifdef CONFIG_BATMAN_ADV_NC
  281. header_len = max_t(int, header_len,
  282. sizeof(struct batadv_coded_packet));
  283. #endif
  284. return header_len + ETH_HLEN;
  285. }
  286. /**
  287. * batadv_skb_set_priority - sets skb priority according to packet content
  288. * @skb: the packet to be sent
  289. * @offset: offset to the packet content
  290. *
  291. * This function sets a value between 256 and 263 (802.1d priority), which
  292. * can be interpreted by the cfg80211 or other drivers.
  293. */
  294. void batadv_skb_set_priority(struct sk_buff *skb, int offset)
  295. {
  296. struct iphdr ip_hdr_tmp, *ip_hdr;
  297. struct ipv6hdr ip6_hdr_tmp, *ip6_hdr;
  298. struct ethhdr ethhdr_tmp, *ethhdr;
  299. struct vlan_ethhdr *vhdr, vhdr_tmp;
  300. u32 prio;
  301. /* already set, do nothing */
  302. if (skb->priority >= 256 && skb->priority <= 263)
  303. return;
  304. ethhdr = skb_header_pointer(skb, offset, sizeof(*ethhdr), &ethhdr_tmp);
  305. if (!ethhdr)
  306. return;
  307. switch (ethhdr->h_proto) {
  308. case htons(ETH_P_8021Q):
  309. vhdr = skb_header_pointer(skb, offset + sizeof(*vhdr),
  310. sizeof(*vhdr), &vhdr_tmp);
  311. if (!vhdr)
  312. return;
  313. prio = ntohs(vhdr->h_vlan_TCI) & VLAN_PRIO_MASK;
  314. prio = prio >> VLAN_PRIO_SHIFT;
  315. break;
  316. case htons(ETH_P_IP):
  317. ip_hdr = skb_header_pointer(skb, offset + sizeof(*ethhdr),
  318. sizeof(*ip_hdr), &ip_hdr_tmp);
  319. if (!ip_hdr)
  320. return;
  321. prio = (ipv4_get_dsfield(ip_hdr) & 0xfc) >> 5;
  322. break;
  323. case htons(ETH_P_IPV6):
  324. ip6_hdr = skb_header_pointer(skb, offset + sizeof(*ethhdr),
  325. sizeof(*ip6_hdr), &ip6_hdr_tmp);
  326. if (!ip6_hdr)
  327. return;
  328. prio = (ipv6_get_dsfield(ip6_hdr) & 0xfc) >> 5;
  329. break;
  330. default:
  331. return;
  332. }
  333. skb->priority = prio + 256;
  334. }
  335. static int batadv_recv_unhandled_packet(struct sk_buff *skb,
  336. struct batadv_hard_iface *recv_if)
  337. {
  338. return NET_RX_DROP;
  339. }
  340. /* incoming packets with the batman ethertype received on any active hard
  341. * interface
  342. */
  343. int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
  344. struct packet_type *ptype,
  345. struct net_device *orig_dev)
  346. {
  347. struct batadv_priv *bat_priv;
  348. struct batadv_ogm_packet *batadv_ogm_packet;
  349. struct batadv_hard_iface *hard_iface;
  350. u8 idx;
  351. int ret;
  352. hard_iface = container_of(ptype, struct batadv_hard_iface,
  353. batman_adv_ptype);
  354. /* Prevent processing a packet received on an interface which is getting
  355. * shut down otherwise the packet may trigger de-reference errors
  356. * further down in the receive path.
  357. */
  358. if (!kref_get_unless_zero(&hard_iface->refcount))
  359. goto err_out;
  360. skb = skb_share_check(skb, GFP_ATOMIC);
  361. /* skb was released by skb_share_check() */
  362. if (!skb)
  363. goto err_put;
  364. /* packet should hold at least type and version */
  365. if (unlikely(!pskb_may_pull(skb, 2)))
  366. goto err_free;
  367. /* expect a valid ethernet header here. */
  368. if (unlikely(skb->mac_len != ETH_HLEN || !skb_mac_header(skb)))
  369. goto err_free;
  370. if (!hard_iface->soft_iface)
  371. goto err_free;
  372. bat_priv = netdev_priv(hard_iface->soft_iface);
  373. if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
  374. goto err_free;
  375. /* discard frames on not active interfaces */
  376. if (hard_iface->if_status != BATADV_IF_ACTIVE)
  377. goto err_free;
  378. batadv_ogm_packet = (struct batadv_ogm_packet *)skb->data;
  379. if (batadv_ogm_packet->version != BATADV_COMPAT_VERSION) {
  380. batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
  381. "Drop packet: incompatible batman version (%i)\n",
  382. batadv_ogm_packet->version);
  383. goto err_free;
  384. }
  385. /* reset control block to avoid left overs from previous users */
  386. memset(skb->cb, 0, sizeof(struct batadv_skb_cb));
  387. /* all receive handlers return whether they received or reused
  388. * the supplied skb. if not, we have to free the skb.
  389. */
  390. idx = batadv_ogm_packet->packet_type;
  391. ret = (*batadv_rx_handler[idx])(skb, hard_iface);
  392. if (ret == NET_RX_DROP)
  393. kfree_skb(skb);
  394. batadv_hardif_put(hard_iface);
  395. /* return NET_RX_SUCCESS in any case as we
  396. * most probably dropped the packet for
  397. * routing-logical reasons.
  398. */
  399. return NET_RX_SUCCESS;
  400. err_free:
  401. kfree_skb(skb);
  402. err_put:
  403. batadv_hardif_put(hard_iface);
  404. err_out:
  405. return NET_RX_DROP;
  406. }
  407. static void batadv_recv_handler_init(void)
  408. {
  409. int i;
  410. for (i = 0; i < ARRAY_SIZE(batadv_rx_handler); i++)
  411. batadv_rx_handler[i] = batadv_recv_unhandled_packet;
  412. for (i = BATADV_UNICAST_MIN; i <= BATADV_UNICAST_MAX; i++)
  413. batadv_rx_handler[i] = batadv_recv_unhandled_unicast_packet;
  414. /* compile time checks for sizes */
  415. BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6);
  416. BUILD_BUG_ON(sizeof(struct batadv_ogm_packet) != 24);
  417. BUILD_BUG_ON(sizeof(struct batadv_icmp_header) != 20);
  418. BUILD_BUG_ON(sizeof(struct batadv_icmp_packet) != 20);
  419. BUILD_BUG_ON(sizeof(struct batadv_icmp_packet_rr) != 116);
  420. BUILD_BUG_ON(sizeof(struct batadv_unicast_packet) != 10);
  421. BUILD_BUG_ON(sizeof(struct batadv_unicast_4addr_packet) != 18);
  422. BUILD_BUG_ON(sizeof(struct batadv_frag_packet) != 20);
  423. BUILD_BUG_ON(sizeof(struct batadv_bcast_packet) != 14);
  424. BUILD_BUG_ON(sizeof(struct batadv_coded_packet) != 46);
  425. BUILD_BUG_ON(sizeof(struct batadv_unicast_tvlv_packet) != 20);
  426. BUILD_BUG_ON(sizeof(struct batadv_tvlv_hdr) != 4);
  427. BUILD_BUG_ON(sizeof(struct batadv_tvlv_gateway_data) != 8);
  428. BUILD_BUG_ON(sizeof(struct batadv_tvlv_tt_vlan_data) != 8);
  429. BUILD_BUG_ON(sizeof(struct batadv_tvlv_tt_change) != 12);
  430. BUILD_BUG_ON(sizeof(struct batadv_tvlv_roam_adv) != 8);
  431. /* broadcast packet */
  432. batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
  433. /* unicast packets ... */
  434. /* unicast with 4 addresses packet */
  435. batadv_rx_handler[BATADV_UNICAST_4ADDR] = batadv_recv_unicast_packet;
  436. /* unicast packet */
  437. batadv_rx_handler[BATADV_UNICAST] = batadv_recv_unicast_packet;
  438. /* unicast tvlv packet */
  439. batadv_rx_handler[BATADV_UNICAST_TVLV] = batadv_recv_unicast_tvlv;
  440. /* batman icmp packet */
  441. batadv_rx_handler[BATADV_ICMP] = batadv_recv_icmp_packet;
  442. /* Fragmented packets */
  443. batadv_rx_handler[BATADV_UNICAST_FRAG] = batadv_recv_frag_packet;
  444. }
  445. int
  446. batadv_recv_handler_register(u8 packet_type,
  447. int (*recv_handler)(struct sk_buff *,
  448. struct batadv_hard_iface *))
  449. {
  450. int (*curr)(struct sk_buff *,
  451. struct batadv_hard_iface *);
  452. curr = batadv_rx_handler[packet_type];
  453. if ((curr != batadv_recv_unhandled_packet) &&
  454. (curr != batadv_recv_unhandled_unicast_packet))
  455. return -EBUSY;
  456. batadv_rx_handler[packet_type] = recv_handler;
  457. return 0;
  458. }
  459. void batadv_recv_handler_unregister(u8 packet_type)
  460. {
  461. batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet;
  462. }
  463. /**
  464. * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in
  465. * the header
  466. * @skb: skb pointing to fragmented socket buffers
  467. * @payload_ptr: Pointer to position inside the head buffer of the skb
  468. * marking the start of the data to be CRC'ed
  469. *
  470. * payload_ptr must always point to an address in the skb head buffer and not to
  471. * a fragment.
  472. *
  473. * Return: big endian crc32c of the checksummed data
  474. */
  475. __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
  476. {
  477. u32 crc = 0;
  478. unsigned int from;
  479. unsigned int to = skb->len;
  480. struct skb_seq_state st;
  481. const u8 *data;
  482. unsigned int len;
  483. unsigned int consumed = 0;
  484. from = (unsigned int)(payload_ptr - skb->data);
  485. skb_prepare_seq_read(skb, from, to, &st);
  486. while ((len = skb_seq_read(consumed, &data, &st)) != 0) {
  487. crc = crc32c(crc, data, len);
  488. consumed += len;
  489. }
  490. return htonl(crc);
  491. }
  492. /**
  493. * batadv_get_vid - extract the VLAN identifier from skb if any
  494. * @skb: the buffer containing the packet
  495. * @header_len: length of the batman header preceding the ethernet header
  496. *
  497. * Return: VID with the BATADV_VLAN_HAS_TAG flag when the packet embedded in the
  498. * skb is vlan tagged. Otherwise BATADV_NO_FLAGS.
  499. */
  500. unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len)
  501. {
  502. struct ethhdr *ethhdr = (struct ethhdr *)(skb->data + header_len);
  503. struct vlan_ethhdr *vhdr;
  504. unsigned short vid;
  505. if (ethhdr->h_proto != htons(ETH_P_8021Q))
  506. return BATADV_NO_FLAGS;
  507. if (!pskb_may_pull(skb, header_len + VLAN_ETH_HLEN))
  508. return BATADV_NO_FLAGS;
  509. vhdr = (struct vlan_ethhdr *)(skb->data + header_len);
  510. vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
  511. vid |= BATADV_VLAN_HAS_TAG;
  512. return vid;
  513. }
  514. /**
  515. * batadv_vlan_ap_isola_get - return the AP isolation status for the given vlan
  516. * @bat_priv: the bat priv with all the soft interface information
  517. * @vid: the VLAN identifier for which the AP isolation attributed as to be
  518. * looked up
  519. *
  520. * Return: true if AP isolation is on for the VLAN idenfied by vid, false
  521. * otherwise
  522. */
  523. bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid)
  524. {
  525. bool ap_isolation_enabled = false;
  526. struct batadv_softif_vlan *vlan;
  527. /* if the AP isolation is requested on a VLAN, then check for its
  528. * setting in the proper VLAN private data structure
  529. */
  530. vlan = batadv_softif_vlan_get(bat_priv, vid);
  531. if (vlan) {
  532. ap_isolation_enabled = atomic_read(&vlan->ap_isolation);
  533. batadv_softif_vlan_put(vlan);
  534. }
  535. return ap_isolation_enabled;
  536. }
  537. module_init(batadv_init);
  538. module_exit(batadv_exit);
  539. MODULE_LICENSE("GPL");
  540. MODULE_AUTHOR(BATADV_DRIVER_AUTHOR);
  541. MODULE_DESCRIPTION(BATADV_DRIVER_DESC);
  542. MODULE_SUPPORTED_DEVICE(BATADV_DRIVER_DEVICE);
  543. MODULE_VERSION(BATADV_SOURCE_VERSION);
  544. MODULE_ALIAS_RTNL_LINK("batadv");