soft-interface.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /* Copyright (C) 2007-2012 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 "soft-interface.h"
  21. #include "hard-interface.h"
  22. #include "distributed-arp-table.h"
  23. #include "routing.h"
  24. #include "send.h"
  25. #include "debugfs.h"
  26. #include "translation-table.h"
  27. #include "hash.h"
  28. #include "gateway_common.h"
  29. #include "gateway_client.h"
  30. #include "sysfs.h"
  31. #include "originator.h"
  32. #include <linux/slab.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/etherdevice.h>
  35. #include <linux/if_vlan.h>
  36. #include <linux/if_ether.h>
  37. #include "unicast.h"
  38. #include "bridge_loop_avoidance.h"
  39. static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
  40. static void batadv_get_drvinfo(struct net_device *dev,
  41. struct ethtool_drvinfo *info);
  42. static u32 batadv_get_msglevel(struct net_device *dev);
  43. static void batadv_set_msglevel(struct net_device *dev, u32 value);
  44. static u32 batadv_get_link(struct net_device *dev);
  45. static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data);
  46. static void batadv_get_ethtool_stats(struct net_device *dev,
  47. struct ethtool_stats *stats, u64 *data);
  48. static int batadv_get_sset_count(struct net_device *dev, int stringset);
  49. static const struct ethtool_ops batadv_ethtool_ops = {
  50. .get_settings = batadv_get_settings,
  51. .get_drvinfo = batadv_get_drvinfo,
  52. .get_msglevel = batadv_get_msglevel,
  53. .set_msglevel = batadv_set_msglevel,
  54. .get_link = batadv_get_link,
  55. .get_strings = batadv_get_strings,
  56. .get_ethtool_stats = batadv_get_ethtool_stats,
  57. .get_sset_count = batadv_get_sset_count,
  58. };
  59. int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)
  60. {
  61. int result;
  62. /* TODO: We must check if we can release all references to non-payload
  63. * data using skb_header_release in our skbs to allow skb_cow_header to
  64. * work optimally. This means that those skbs are not allowed to read
  65. * or write any data which is before the current position of skb->data
  66. * after that call and thus allow other skbs with the same data buffer
  67. * to write freely in that area.
  68. */
  69. result = skb_cow_head(skb, len);
  70. if (result < 0)
  71. return result;
  72. skb_push(skb, len);
  73. return 0;
  74. }
  75. static int batadv_interface_open(struct net_device *dev)
  76. {
  77. netif_start_queue(dev);
  78. return 0;
  79. }
  80. static int batadv_interface_release(struct net_device *dev)
  81. {
  82. netif_stop_queue(dev);
  83. return 0;
  84. }
  85. static struct net_device_stats *batadv_interface_stats(struct net_device *dev)
  86. {
  87. struct batadv_priv *bat_priv = netdev_priv(dev);
  88. struct net_device_stats *stats = &bat_priv->stats;
  89. stats->tx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_TX);
  90. stats->tx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_TX_BYTES);
  91. stats->tx_dropped = batadv_sum_counter(bat_priv, BATADV_CNT_TX_DROPPED);
  92. stats->rx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_RX);
  93. stats->rx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_RX_BYTES);
  94. return stats;
  95. }
  96. static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
  97. {
  98. struct batadv_priv *bat_priv = netdev_priv(dev);
  99. struct sockaddr *addr = p;
  100. uint8_t old_addr[ETH_ALEN];
  101. if (!is_valid_ether_addr(addr->sa_data))
  102. return -EADDRNOTAVAIL;
  103. memcpy(old_addr, dev->dev_addr, ETH_ALEN);
  104. memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
  105. /* only modify transtable if it has been initialized before */
  106. if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE) {
  107. batadv_tt_local_remove(bat_priv, old_addr,
  108. "mac address changed", false);
  109. batadv_tt_local_add(dev, addr->sa_data, BATADV_NULL_IFINDEX);
  110. }
  111. dev->addr_assign_type &= ~NET_ADDR_RANDOM;
  112. return 0;
  113. }
  114. static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)
  115. {
  116. /* check ranges */
  117. if ((new_mtu < 68) || (new_mtu > batadv_hardif_min_mtu(dev)))
  118. return -EINVAL;
  119. dev->mtu = new_mtu;
  120. return 0;
  121. }
  122. static int batadv_interface_tx(struct sk_buff *skb,
  123. struct net_device *soft_iface)
  124. {
  125. struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
  126. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  127. struct batadv_hard_iface *primary_if = NULL;
  128. struct batadv_bcast_packet *bcast_packet;
  129. struct vlan_ethhdr *vhdr;
  130. __be16 ethertype = __constant_htons(ETH_P_BATMAN);
  131. static const uint8_t stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00,
  132. 0x00, 0x00};
  133. static const uint8_t ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00,
  134. 0x00, 0x00};
  135. unsigned int header_len = 0;
  136. int data_len = skb->len, ret;
  137. short vid __maybe_unused = -1;
  138. bool do_bcast = false;
  139. uint32_t seqno;
  140. unsigned long brd_delay = 1;
  141. if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
  142. goto dropped;
  143. soft_iface->trans_start = jiffies;
  144. switch (ntohs(ethhdr->h_proto)) {
  145. case ETH_P_8021Q:
  146. vhdr = (struct vlan_ethhdr *)skb->data;
  147. vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
  148. if (vhdr->h_vlan_encapsulated_proto != ethertype)
  149. break;
  150. /* fall through */
  151. case ETH_P_BATMAN:
  152. goto dropped;
  153. }
  154. if (batadv_bla_tx(bat_priv, skb, vid))
  155. goto dropped;
  156. /* Register the client MAC in the transtable */
  157. batadv_tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif);
  158. /* don't accept stp packets. STP does not help in meshes.
  159. * better use the bridge loop avoidance ...
  160. *
  161. * The same goes for ECTP sent at least by some Cisco Switches,
  162. * it might confuse the mesh when used with bridge loop avoidance.
  163. */
  164. if (batadv_compare_eth(ethhdr->h_dest, stp_addr))
  165. goto dropped;
  166. if (batadv_compare_eth(ethhdr->h_dest, ectp_addr))
  167. goto dropped;
  168. if (is_multicast_ether_addr(ethhdr->h_dest)) {
  169. do_bcast = true;
  170. switch (atomic_read(&bat_priv->gw_mode)) {
  171. case BATADV_GW_MODE_SERVER:
  172. /* gateway servers should not send dhcp
  173. * requests into the mesh
  174. */
  175. ret = batadv_gw_is_dhcp_target(skb, &header_len);
  176. if (ret)
  177. goto dropped;
  178. break;
  179. case BATADV_GW_MODE_CLIENT:
  180. /* gateway clients should send dhcp requests
  181. * via unicast to their gateway
  182. */
  183. ret = batadv_gw_is_dhcp_target(skb, &header_len);
  184. if (ret)
  185. do_bcast = false;
  186. break;
  187. case BATADV_GW_MODE_OFF:
  188. default:
  189. break;
  190. }
  191. }
  192. /* ethernet packet should be broadcasted */
  193. if (do_bcast) {
  194. primary_if = batadv_primary_if_get_selected(bat_priv);
  195. if (!primary_if)
  196. goto dropped;
  197. /* in case of ARP request, we do not immediately broadcasti the
  198. * packet, instead we first wait for DAT to try to retrieve the
  199. * correct ARP entry
  200. */
  201. if (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb))
  202. brd_delay = msecs_to_jiffies(ARP_REQ_DELAY);
  203. if (batadv_skb_head_push(skb, sizeof(*bcast_packet)) < 0)
  204. goto dropped;
  205. bcast_packet = (struct batadv_bcast_packet *)skb->data;
  206. bcast_packet->header.version = BATADV_COMPAT_VERSION;
  207. bcast_packet->header.ttl = BATADV_TTL;
  208. /* batman packet type: broadcast */
  209. bcast_packet->header.packet_type = BATADV_BCAST;
  210. bcast_packet->reserved = 0;
  211. /* hw address of first interface is the orig mac because only
  212. * this mac is known throughout the mesh
  213. */
  214. memcpy(bcast_packet->orig,
  215. primary_if->net_dev->dev_addr, ETH_ALEN);
  216. /* set broadcast sequence number */
  217. seqno = atomic_inc_return(&bat_priv->bcast_seqno);
  218. bcast_packet->seqno = htonl(seqno);
  219. batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
  220. /* a copy is stored in the bcast list, therefore removing
  221. * the original skb.
  222. */
  223. kfree_skb(skb);
  224. /* unicast packet */
  225. } else {
  226. if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_OFF) {
  227. ret = batadv_gw_out_of_range(bat_priv, skb, ethhdr);
  228. if (ret)
  229. goto dropped;
  230. }
  231. if (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb))
  232. goto dropped;
  233. batadv_dat_snoop_outgoing_arp_reply(bat_priv, skb);
  234. ret = batadv_unicast_send_skb(bat_priv, skb);
  235. if (ret != 0)
  236. goto dropped_freed;
  237. }
  238. batadv_inc_counter(bat_priv, BATADV_CNT_TX);
  239. batadv_add_counter(bat_priv, BATADV_CNT_TX_BYTES, data_len);
  240. goto end;
  241. dropped:
  242. kfree_skb(skb);
  243. dropped_freed:
  244. batadv_inc_counter(bat_priv, BATADV_CNT_TX_DROPPED);
  245. end:
  246. if (primary_if)
  247. batadv_hardif_free_ref(primary_if);
  248. return NETDEV_TX_OK;
  249. }
  250. void batadv_interface_rx(struct net_device *soft_iface,
  251. struct sk_buff *skb, struct batadv_hard_iface *recv_if,
  252. int hdr_size, struct batadv_orig_node *orig_node)
  253. {
  254. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  255. struct ethhdr *ethhdr;
  256. struct vlan_ethhdr *vhdr;
  257. struct batadv_header *batadv_header = (struct batadv_header *)skb->data;
  258. short vid __maybe_unused = -1;
  259. __be16 ethertype = __constant_htons(ETH_P_BATMAN);
  260. bool is_bcast;
  261. is_bcast = (batadv_header->packet_type == BATADV_BCAST);
  262. /* check if enough space is available for pulling, and pull */
  263. if (!pskb_may_pull(skb, hdr_size))
  264. goto dropped;
  265. skb_pull_rcsum(skb, hdr_size);
  266. skb_reset_mac_header(skb);
  267. ethhdr = (struct ethhdr *)skb_mac_header(skb);
  268. switch (ntohs(ethhdr->h_proto)) {
  269. case ETH_P_8021Q:
  270. vhdr = (struct vlan_ethhdr *)skb->data;
  271. vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
  272. if (vhdr->h_vlan_encapsulated_proto != ethertype)
  273. break;
  274. /* fall through */
  275. case ETH_P_BATMAN:
  276. goto dropped;
  277. }
  278. /* skb->dev & skb->pkt_type are set here */
  279. if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
  280. goto dropped;
  281. skb->protocol = eth_type_trans(skb, soft_iface);
  282. /* should not be necessary anymore as we use skb_pull_rcsum()
  283. * TODO: please verify this and remove this TODO
  284. * -- Dec 21st 2009, Simon Wunderlich
  285. */
  286. /* skb->ip_summed = CHECKSUM_UNNECESSARY; */
  287. batadv_inc_counter(bat_priv, BATADV_CNT_RX);
  288. batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
  289. skb->len + ETH_HLEN);
  290. soft_iface->last_rx = jiffies;
  291. /* Let the bridge loop avoidance check the packet. If will
  292. * not handle it, we can safely push it up.
  293. */
  294. if (batadv_bla_rx(bat_priv, skb, vid, is_bcast))
  295. goto out;
  296. if (orig_node)
  297. batadv_tt_add_temporary_global_entry(bat_priv, orig_node,
  298. ethhdr->h_source);
  299. if (batadv_is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest))
  300. goto dropped;
  301. netif_rx(skb);
  302. goto out;
  303. dropped:
  304. kfree_skb(skb);
  305. out:
  306. return;
  307. }
  308. /* batman-adv network devices have devices nesting below it and are a special
  309. * "super class" of normal network devices; split their locks off into a
  310. * separate class since they always nest.
  311. */
  312. static struct lock_class_key batadv_netdev_xmit_lock_key;
  313. static struct lock_class_key batadv_netdev_addr_lock_key;
  314. /**
  315. * batadv_set_lockdep_class_one - Set lockdep class for a single tx queue
  316. * @dev: device which owns the tx queue
  317. * @txq: tx queue to modify
  318. * @_unused: always NULL
  319. */
  320. static void batadv_set_lockdep_class_one(struct net_device *dev,
  321. struct netdev_queue *txq,
  322. void *_unused)
  323. {
  324. lockdep_set_class(&txq->_xmit_lock, &batadv_netdev_xmit_lock_key);
  325. }
  326. /**
  327. * batadv_set_lockdep_class - Set txq and addr_list lockdep class
  328. * @dev: network device to modify
  329. */
  330. static void batadv_set_lockdep_class(struct net_device *dev)
  331. {
  332. lockdep_set_class(&dev->addr_list_lock, &batadv_netdev_addr_lock_key);
  333. netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
  334. }
  335. /**
  336. * batadv_softif_init - Late stage initialization of soft interface
  337. * @dev: registered network device to modify
  338. *
  339. * Returns error code on failures
  340. */
  341. static int batadv_softif_init(struct net_device *dev)
  342. {
  343. batadv_set_lockdep_class(dev);
  344. return 0;
  345. }
  346. static const struct net_device_ops batadv_netdev_ops = {
  347. .ndo_init = batadv_softif_init,
  348. .ndo_open = batadv_interface_open,
  349. .ndo_stop = batadv_interface_release,
  350. .ndo_get_stats = batadv_interface_stats,
  351. .ndo_set_mac_address = batadv_interface_set_mac_addr,
  352. .ndo_change_mtu = batadv_interface_change_mtu,
  353. .ndo_start_xmit = batadv_interface_tx,
  354. .ndo_validate_addr = eth_validate_addr
  355. };
  356. static void batadv_interface_setup(struct net_device *dev)
  357. {
  358. struct batadv_priv *priv = netdev_priv(dev);
  359. ether_setup(dev);
  360. dev->netdev_ops = &batadv_netdev_ops;
  361. dev->destructor = free_netdev;
  362. dev->tx_queue_len = 0;
  363. /* can't call min_mtu, because the needed variables
  364. * have not been initialized yet
  365. */
  366. dev->mtu = ETH_DATA_LEN;
  367. /* reserve more space in the skbuff for our header */
  368. dev->hard_header_len = BATADV_HEADER_LEN;
  369. /* generate random address */
  370. eth_hw_addr_random(dev);
  371. SET_ETHTOOL_OPS(dev, &batadv_ethtool_ops);
  372. memset(priv, 0, sizeof(*priv));
  373. }
  374. struct net_device *batadv_softif_create(const char *name)
  375. {
  376. struct net_device *soft_iface;
  377. struct batadv_priv *bat_priv;
  378. int ret;
  379. size_t cnt_len = sizeof(uint64_t) * BATADV_CNT_NUM;
  380. soft_iface = alloc_netdev(sizeof(*bat_priv), name,
  381. batadv_interface_setup);
  382. if (!soft_iface)
  383. goto out;
  384. bat_priv = netdev_priv(soft_iface);
  385. /* batadv_interface_stats() needs to be available as soon as
  386. * register_netdevice() has been called
  387. */
  388. bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(uint64_t));
  389. if (!bat_priv->bat_counters)
  390. goto free_soft_iface;
  391. ret = register_netdevice(soft_iface);
  392. if (ret < 0) {
  393. pr_err("Unable to register the batman interface '%s': %i\n",
  394. name, ret);
  395. goto free_bat_counters;
  396. }
  397. atomic_set(&bat_priv->aggregated_ogms, 1);
  398. atomic_set(&bat_priv->bonding, 0);
  399. atomic_set(&bat_priv->bridge_loop_avoidance, 0);
  400. #ifdef CONFIG_BATMAN_ADV_DAT
  401. atomic_set(&bat_priv->distributed_arp_table, 1);
  402. #endif
  403. atomic_set(&bat_priv->ap_isolation, 0);
  404. atomic_set(&bat_priv->vis_mode, BATADV_VIS_TYPE_CLIENT_UPDATE);
  405. atomic_set(&bat_priv->gw_mode, BATADV_GW_MODE_OFF);
  406. atomic_set(&bat_priv->gw_sel_class, 20);
  407. atomic_set(&bat_priv->gw_bandwidth, 41);
  408. atomic_set(&bat_priv->orig_interval, 1000);
  409. atomic_set(&bat_priv->hop_penalty, 30);
  410. atomic_set(&bat_priv->log_level, 0);
  411. atomic_set(&bat_priv->fragmentation, 1);
  412. atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
  413. atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
  414. atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
  415. atomic_set(&bat_priv->bcast_seqno, 1);
  416. atomic_set(&bat_priv->tt.vn, 0);
  417. atomic_set(&bat_priv->tt.local_changes, 0);
  418. atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
  419. #ifdef CONFIG_BATMAN_ADV_BLA
  420. atomic_set(&bat_priv->bla.num_requests, 0);
  421. #endif
  422. bat_priv->tt.last_changeset = NULL;
  423. bat_priv->tt.last_changeset_len = 0;
  424. bat_priv->primary_if = NULL;
  425. bat_priv->num_ifaces = 0;
  426. ret = batadv_algo_select(bat_priv, batadv_routing_algo);
  427. if (ret < 0)
  428. goto unreg_soft_iface;
  429. ret = batadv_sysfs_add_meshif(soft_iface);
  430. if (ret < 0)
  431. goto unreg_soft_iface;
  432. ret = batadv_debugfs_add_meshif(soft_iface);
  433. if (ret < 0)
  434. goto unreg_sysfs;
  435. ret = batadv_mesh_init(soft_iface);
  436. if (ret < 0)
  437. goto unreg_debugfs;
  438. return soft_iface;
  439. unreg_debugfs:
  440. batadv_debugfs_del_meshif(soft_iface);
  441. unreg_sysfs:
  442. batadv_sysfs_del_meshif(soft_iface);
  443. unreg_soft_iface:
  444. free_percpu(bat_priv->bat_counters);
  445. unregister_netdevice(soft_iface);
  446. return NULL;
  447. free_bat_counters:
  448. free_percpu(bat_priv->bat_counters);
  449. free_soft_iface:
  450. free_netdev(soft_iface);
  451. out:
  452. return NULL;
  453. }
  454. void batadv_softif_destroy(struct net_device *soft_iface)
  455. {
  456. batadv_debugfs_del_meshif(soft_iface);
  457. batadv_sysfs_del_meshif(soft_iface);
  458. batadv_mesh_free(soft_iface);
  459. unregister_netdevice(soft_iface);
  460. }
  461. int batadv_softif_is_valid(const struct net_device *net_dev)
  462. {
  463. if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx)
  464. return 1;
  465. return 0;
  466. }
  467. /* ethtool */
  468. static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  469. {
  470. cmd->supported = 0;
  471. cmd->advertising = 0;
  472. ethtool_cmd_speed_set(cmd, SPEED_10);
  473. cmd->duplex = DUPLEX_FULL;
  474. cmd->port = PORT_TP;
  475. cmd->phy_address = 0;
  476. cmd->transceiver = XCVR_INTERNAL;
  477. cmd->autoneg = AUTONEG_DISABLE;
  478. cmd->maxtxpkt = 0;
  479. cmd->maxrxpkt = 0;
  480. return 0;
  481. }
  482. static void batadv_get_drvinfo(struct net_device *dev,
  483. struct ethtool_drvinfo *info)
  484. {
  485. strcpy(info->driver, "B.A.T.M.A.N. advanced");
  486. strcpy(info->version, BATADV_SOURCE_VERSION);
  487. strcpy(info->fw_version, "N/A");
  488. strcpy(info->bus_info, "batman");
  489. }
  490. static u32 batadv_get_msglevel(struct net_device *dev)
  491. {
  492. return -EOPNOTSUPP;
  493. }
  494. static void batadv_set_msglevel(struct net_device *dev, u32 value)
  495. {
  496. }
  497. static u32 batadv_get_link(struct net_device *dev)
  498. {
  499. return 1;
  500. }
  501. /* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
  502. * Declare each description string in struct.name[] to get fixed sized buffer
  503. * and compile time checking for strings longer than ETH_GSTRING_LEN.
  504. */
  505. static const struct {
  506. const char name[ETH_GSTRING_LEN];
  507. } batadv_counters_strings[] = {
  508. { "tx" },
  509. { "tx_bytes" },
  510. { "tx_dropped" },
  511. { "rx" },
  512. { "rx_bytes" },
  513. { "forward" },
  514. { "forward_bytes" },
  515. { "mgmt_tx" },
  516. { "mgmt_tx_bytes" },
  517. { "mgmt_rx" },
  518. { "mgmt_rx_bytes" },
  519. { "tt_request_tx" },
  520. { "tt_request_rx" },
  521. { "tt_response_tx" },
  522. { "tt_response_rx" },
  523. { "tt_roam_adv_tx" },
  524. { "tt_roam_adv_rx" },
  525. #ifdef CONFIG_BATMAN_ADV_DAT
  526. { "dat_get_tx" },
  527. { "dat_get_rx" },
  528. { "dat_put_tx" },
  529. { "dat_put_rx" },
  530. { "dat_cached_reply_tx" },
  531. #endif
  532. };
  533. static void batadv_get_strings(struct net_device *dev, uint32_t stringset,
  534. uint8_t *data)
  535. {
  536. if (stringset == ETH_SS_STATS)
  537. memcpy(data, batadv_counters_strings,
  538. sizeof(batadv_counters_strings));
  539. }
  540. static void batadv_get_ethtool_stats(struct net_device *dev,
  541. struct ethtool_stats *stats,
  542. uint64_t *data)
  543. {
  544. struct batadv_priv *bat_priv = netdev_priv(dev);
  545. int i;
  546. for (i = 0; i < BATADV_CNT_NUM; i++)
  547. data[i] = batadv_sum_counter(bat_priv, i);
  548. }
  549. static int batadv_get_sset_count(struct net_device *dev, int stringset)
  550. {
  551. if (stringset == ETH_SS_STATS)
  552. return BATADV_CNT_NUM;
  553. return -EOPNOTSUPP;
  554. }