main.c 18 KB

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