soft-interface.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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 "soft-interface.h"
  23. #include "hard-interface.h"
  24. #include "routing.h"
  25. #include "send.h"
  26. #include "bat_debugfs.h"
  27. #include "translation-table.h"
  28. #include "hash.h"
  29. #include "gateway_common.h"
  30. #include "gateway_client.h"
  31. #include "bat_sysfs.h"
  32. #include <linux/slab.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/etherdevice.h>
  35. #include <linux/if_vlan.h>
  36. #include "unicast.h"
  37. static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
  38. static void bat_get_drvinfo(struct net_device *dev,
  39. struct ethtool_drvinfo *info);
  40. static u32 bat_get_msglevel(struct net_device *dev);
  41. static void bat_set_msglevel(struct net_device *dev, u32 value);
  42. static u32 bat_get_link(struct net_device *dev);
  43. static u32 bat_get_rx_csum(struct net_device *dev);
  44. static int bat_set_rx_csum(struct net_device *dev, u32 data);
  45. static const struct ethtool_ops bat_ethtool_ops = {
  46. .get_settings = bat_get_settings,
  47. .get_drvinfo = bat_get_drvinfo,
  48. .get_msglevel = bat_get_msglevel,
  49. .set_msglevel = bat_set_msglevel,
  50. .get_link = bat_get_link,
  51. .get_rx_csum = bat_get_rx_csum,
  52. .set_rx_csum = bat_set_rx_csum
  53. };
  54. int my_skb_head_push(struct sk_buff *skb, unsigned int len)
  55. {
  56. int result;
  57. /**
  58. * TODO: We must check if we can release all references to non-payload
  59. * data using skb_header_release in our skbs to allow skb_cow_header to
  60. * work optimally. This means that those skbs are not allowed to read
  61. * or write any data which is before the current position of skb->data
  62. * after that call and thus allow other skbs with the same data buffer
  63. * to write freely in that area.
  64. */
  65. result = skb_cow_head(skb, len);
  66. if (result < 0)
  67. return result;
  68. skb_push(skb, len);
  69. return 0;
  70. }
  71. static void softif_neigh_free_rcu(struct rcu_head *rcu)
  72. {
  73. struct softif_neigh *softif_neigh;
  74. softif_neigh = container_of(rcu, struct softif_neigh, rcu);
  75. kfree(softif_neigh);
  76. }
  77. static void softif_neigh_free_ref(struct softif_neigh *softif_neigh)
  78. {
  79. if (atomic_dec_and_test(&softif_neigh->refcount))
  80. call_rcu(&softif_neigh->rcu, softif_neigh_free_rcu);
  81. }
  82. void softif_neigh_purge(struct bat_priv *bat_priv)
  83. {
  84. struct softif_neigh *softif_neigh, *softif_neigh_tmp;
  85. struct hlist_node *node, *node_tmp;
  86. spin_lock_bh(&bat_priv->softif_neigh_lock);
  87. hlist_for_each_entry_safe(softif_neigh, node, node_tmp,
  88. &bat_priv->softif_neigh_list, list) {
  89. if ((!time_after(jiffies, softif_neigh->last_seen +
  90. msecs_to_jiffies(SOFTIF_NEIGH_TIMEOUT))) &&
  91. (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE))
  92. continue;
  93. hlist_del_rcu(&softif_neigh->list);
  94. if (bat_priv->softif_neigh == softif_neigh) {
  95. bat_dbg(DBG_ROUTES, bat_priv,
  96. "Current mesh exit point '%pM' vanished "
  97. "(vid: %d).\n",
  98. softif_neigh->addr, softif_neigh->vid);
  99. softif_neigh_tmp = bat_priv->softif_neigh;
  100. bat_priv->softif_neigh = NULL;
  101. softif_neigh_free_ref(softif_neigh_tmp);
  102. }
  103. softif_neigh_free_ref(softif_neigh);
  104. }
  105. spin_unlock_bh(&bat_priv->softif_neigh_lock);
  106. }
  107. static struct softif_neigh *softif_neigh_get(struct bat_priv *bat_priv,
  108. uint8_t *addr, short vid)
  109. {
  110. struct softif_neigh *softif_neigh;
  111. struct hlist_node *node;
  112. rcu_read_lock();
  113. hlist_for_each_entry_rcu(softif_neigh, node,
  114. &bat_priv->softif_neigh_list, list) {
  115. if (!compare_eth(softif_neigh->addr, addr))
  116. continue;
  117. if (softif_neigh->vid != vid)
  118. continue;
  119. if (!atomic_inc_not_zero(&softif_neigh->refcount))
  120. continue;
  121. softif_neigh->last_seen = jiffies;
  122. goto out;
  123. }
  124. softif_neigh = kzalloc(sizeof(struct softif_neigh), GFP_ATOMIC);
  125. if (!softif_neigh)
  126. goto out;
  127. memcpy(softif_neigh->addr, addr, ETH_ALEN);
  128. softif_neigh->vid = vid;
  129. softif_neigh->last_seen = jiffies;
  130. /* initialize with 2 - caller decrements counter by one */
  131. atomic_set(&softif_neigh->refcount, 2);
  132. INIT_HLIST_NODE(&softif_neigh->list);
  133. spin_lock_bh(&bat_priv->softif_neigh_lock);
  134. hlist_add_head_rcu(&softif_neigh->list, &bat_priv->softif_neigh_list);
  135. spin_unlock_bh(&bat_priv->softif_neigh_lock);
  136. out:
  137. rcu_read_unlock();
  138. return softif_neigh;
  139. }
  140. int softif_neigh_seq_print_text(struct seq_file *seq, void *offset)
  141. {
  142. struct net_device *net_dev = (struct net_device *)seq->private;
  143. struct bat_priv *bat_priv = netdev_priv(net_dev);
  144. struct softif_neigh *softif_neigh;
  145. struct hlist_node *node;
  146. if (!bat_priv->primary_if) {
  147. return seq_printf(seq, "BATMAN mesh %s disabled - "
  148. "please specify interfaces to enable it\n",
  149. net_dev->name);
  150. }
  151. seq_printf(seq, "Softif neighbor list (%s)\n", net_dev->name);
  152. rcu_read_lock();
  153. hlist_for_each_entry_rcu(softif_neigh, node,
  154. &bat_priv->softif_neigh_list, list)
  155. seq_printf(seq, "%s %pM (vid: %d)\n",
  156. bat_priv->softif_neigh == softif_neigh
  157. ? "=>" : " ", softif_neigh->addr,
  158. softif_neigh->vid);
  159. rcu_read_unlock();
  160. return 0;
  161. }
  162. static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev,
  163. short vid)
  164. {
  165. struct bat_priv *bat_priv = netdev_priv(dev);
  166. struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
  167. struct batman_packet *batman_packet;
  168. struct softif_neigh *softif_neigh, *softif_neigh_tmp;
  169. if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
  170. batman_packet = (struct batman_packet *)
  171. (skb->data + ETH_HLEN + VLAN_HLEN);
  172. else
  173. batman_packet = (struct batman_packet *)(skb->data + ETH_HLEN);
  174. if (batman_packet->version != COMPAT_VERSION)
  175. goto err;
  176. if (batman_packet->packet_type != BAT_PACKET)
  177. goto err;
  178. if (!(batman_packet->flags & PRIMARIES_FIRST_HOP))
  179. goto err;
  180. if (is_my_mac(batman_packet->orig))
  181. goto err;
  182. softif_neigh = softif_neigh_get(bat_priv, batman_packet->orig, vid);
  183. if (!softif_neigh)
  184. goto err;
  185. if (bat_priv->softif_neigh == softif_neigh)
  186. goto out;
  187. /* we got a neighbor but its mac is 'bigger' than ours */
  188. if (memcmp(bat_priv->primary_if->net_dev->dev_addr,
  189. softif_neigh->addr, ETH_ALEN) < 0)
  190. goto out;
  191. /* switch to new 'smallest neighbor' */
  192. if ((bat_priv->softif_neigh) &&
  193. (memcmp(softif_neigh->addr, bat_priv->softif_neigh->addr,
  194. ETH_ALEN) < 0)) {
  195. bat_dbg(DBG_ROUTES, bat_priv,
  196. "Changing mesh exit point from %pM (vid: %d) "
  197. "to %pM (vid: %d).\n",
  198. bat_priv->softif_neigh->addr,
  199. bat_priv->softif_neigh->vid,
  200. softif_neigh->addr, softif_neigh->vid);
  201. softif_neigh_tmp = bat_priv->softif_neigh;
  202. bat_priv->softif_neigh = softif_neigh;
  203. softif_neigh_free_ref(softif_neigh_tmp);
  204. /* we need to hold the additional reference */
  205. goto err;
  206. }
  207. /* close own batX device and use softif_neigh as exit node */
  208. if ((!bat_priv->softif_neigh) &&
  209. (memcmp(softif_neigh->addr,
  210. bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN) < 0)) {
  211. bat_dbg(DBG_ROUTES, bat_priv,
  212. "Setting mesh exit point to %pM (vid: %d).\n",
  213. softif_neigh->addr, softif_neigh->vid);
  214. bat_priv->softif_neigh = softif_neigh;
  215. /* we need to hold the additional reference */
  216. goto err;
  217. }
  218. out:
  219. softif_neigh_free_ref(softif_neigh);
  220. err:
  221. kfree_skb(skb);
  222. return;
  223. }
  224. static int interface_open(struct net_device *dev)
  225. {
  226. netif_start_queue(dev);
  227. return 0;
  228. }
  229. static int interface_release(struct net_device *dev)
  230. {
  231. netif_stop_queue(dev);
  232. return 0;
  233. }
  234. static struct net_device_stats *interface_stats(struct net_device *dev)
  235. {
  236. struct bat_priv *bat_priv = netdev_priv(dev);
  237. return &bat_priv->stats;
  238. }
  239. static int interface_set_mac_addr(struct net_device *dev, void *p)
  240. {
  241. struct bat_priv *bat_priv = netdev_priv(dev);
  242. struct sockaddr *addr = p;
  243. if (!is_valid_ether_addr(addr->sa_data))
  244. return -EADDRNOTAVAIL;
  245. /* only modify hna-table if it has been initialised before */
  246. if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
  247. hna_local_remove(bat_priv, dev->dev_addr,
  248. "mac address changed");
  249. hna_local_add(dev, addr->sa_data);
  250. }
  251. memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
  252. return 0;
  253. }
  254. static int interface_change_mtu(struct net_device *dev, int new_mtu)
  255. {
  256. /* check ranges */
  257. if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev)))
  258. return -EINVAL;
  259. dev->mtu = new_mtu;
  260. return 0;
  261. }
  262. int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
  263. {
  264. struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
  265. struct bat_priv *bat_priv = netdev_priv(soft_iface);
  266. struct bcast_packet *bcast_packet;
  267. struct vlan_ethhdr *vhdr;
  268. int data_len = skb->len, ret;
  269. short vid = -1;
  270. bool do_bcast = false;
  271. if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
  272. goto dropped;
  273. soft_iface->trans_start = jiffies;
  274. switch (ntohs(ethhdr->h_proto)) {
  275. case ETH_P_8021Q:
  276. vhdr = (struct vlan_ethhdr *)skb->data;
  277. vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
  278. if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
  279. break;
  280. /* fall through */
  281. case ETH_P_BATMAN:
  282. softif_batman_recv(skb, soft_iface, vid);
  283. goto end;
  284. }
  285. /**
  286. * if we have a another chosen mesh exit node in range
  287. * it will transport the packets to the mesh
  288. */
  289. if ((bat_priv->softif_neigh) && (bat_priv->softif_neigh->vid == vid))
  290. goto dropped;
  291. /* TODO: check this for locks */
  292. hna_local_add(soft_iface, ethhdr->h_source);
  293. if (is_multicast_ether_addr(ethhdr->h_dest)) {
  294. ret = gw_is_target(bat_priv, skb);
  295. if (ret < 0)
  296. goto dropped;
  297. if (ret == 0)
  298. do_bcast = true;
  299. }
  300. /* ethernet packet should be broadcasted */
  301. if (do_bcast) {
  302. if (!bat_priv->primary_if)
  303. goto dropped;
  304. if (my_skb_head_push(skb, sizeof(struct bcast_packet)) < 0)
  305. goto dropped;
  306. bcast_packet = (struct bcast_packet *)skb->data;
  307. bcast_packet->version = COMPAT_VERSION;
  308. bcast_packet->ttl = TTL;
  309. /* batman packet type: broadcast */
  310. bcast_packet->packet_type = BAT_BCAST;
  311. /* hw address of first interface is the orig mac because only
  312. * this mac is known throughout the mesh */
  313. memcpy(bcast_packet->orig,
  314. bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
  315. /* set broadcast sequence number */
  316. bcast_packet->seqno =
  317. htonl(atomic_inc_return(&bat_priv->bcast_seqno));
  318. add_bcast_packet_to_list(bat_priv, skb);
  319. /* a copy is stored in the bcast list, therefore removing
  320. * the original skb. */
  321. kfree_skb(skb);
  322. /* unicast packet */
  323. } else {
  324. ret = unicast_send_skb(skb, bat_priv);
  325. if (ret != 0)
  326. goto dropped_freed;
  327. }
  328. bat_priv->stats.tx_packets++;
  329. bat_priv->stats.tx_bytes += data_len;
  330. goto end;
  331. dropped:
  332. kfree_skb(skb);
  333. dropped_freed:
  334. bat_priv->stats.tx_dropped++;
  335. end:
  336. return NETDEV_TX_OK;
  337. }
  338. void interface_rx(struct net_device *soft_iface,
  339. struct sk_buff *skb, struct hard_iface *recv_if,
  340. int hdr_size)
  341. {
  342. struct bat_priv *bat_priv = netdev_priv(soft_iface);
  343. struct unicast_packet *unicast_packet;
  344. struct ethhdr *ethhdr;
  345. struct vlan_ethhdr *vhdr;
  346. short vid = -1;
  347. int ret;
  348. /* check if enough space is available for pulling, and pull */
  349. if (!pskb_may_pull(skb, hdr_size))
  350. goto dropped;
  351. skb_pull_rcsum(skb, hdr_size);
  352. skb_reset_mac_header(skb);
  353. ethhdr = (struct ethhdr *)skb_mac_header(skb);
  354. switch (ntohs(ethhdr->h_proto)) {
  355. case ETH_P_8021Q:
  356. vhdr = (struct vlan_ethhdr *)skb->data;
  357. vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
  358. if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
  359. break;
  360. /* fall through */
  361. case ETH_P_BATMAN:
  362. goto dropped;
  363. }
  364. /**
  365. * if we have a another chosen mesh exit node in range
  366. * it will transport the packets to the non-mesh network
  367. */
  368. if ((bat_priv->softif_neigh) && (bat_priv->softif_neigh->vid == vid)) {
  369. skb_push(skb, hdr_size);
  370. unicast_packet = (struct unicast_packet *)skb->data;
  371. if ((unicast_packet->packet_type != BAT_UNICAST) &&
  372. (unicast_packet->packet_type != BAT_UNICAST_FRAG))
  373. goto dropped;
  374. skb_reset_mac_header(skb);
  375. memcpy(unicast_packet->dest,
  376. bat_priv->softif_neigh->addr, ETH_ALEN);
  377. ret = route_unicast_packet(skb, recv_if);
  378. if (ret == NET_RX_DROP)
  379. goto dropped;
  380. goto out;
  381. }
  382. /* skb->dev & skb->pkt_type are set here */
  383. if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
  384. goto dropped;
  385. skb->protocol = eth_type_trans(skb, soft_iface);
  386. /* should not be neccesary anymore as we use skb_pull_rcsum()
  387. * TODO: please verify this and remove this TODO
  388. * -- Dec 21st 2009, Simon Wunderlich */
  389. /* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
  390. bat_priv->stats.rx_packets++;
  391. bat_priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr);
  392. soft_iface->last_rx = jiffies;
  393. netif_rx(skb);
  394. return;
  395. dropped:
  396. kfree_skb(skb);
  397. out:
  398. return;
  399. }
  400. #ifdef HAVE_NET_DEVICE_OPS
  401. static const struct net_device_ops bat_netdev_ops = {
  402. .ndo_open = interface_open,
  403. .ndo_stop = interface_release,
  404. .ndo_get_stats = interface_stats,
  405. .ndo_set_mac_address = interface_set_mac_addr,
  406. .ndo_change_mtu = interface_change_mtu,
  407. .ndo_start_xmit = interface_tx,
  408. .ndo_validate_addr = eth_validate_addr
  409. };
  410. #endif
  411. static void interface_setup(struct net_device *dev)
  412. {
  413. struct bat_priv *priv = netdev_priv(dev);
  414. char dev_addr[ETH_ALEN];
  415. ether_setup(dev);
  416. #ifdef HAVE_NET_DEVICE_OPS
  417. dev->netdev_ops = &bat_netdev_ops;
  418. #else
  419. dev->open = interface_open;
  420. dev->stop = interface_release;
  421. dev->get_stats = interface_stats;
  422. dev->set_mac_address = interface_set_mac_addr;
  423. dev->change_mtu = interface_change_mtu;
  424. dev->hard_start_xmit = interface_tx;
  425. #endif
  426. dev->destructor = free_netdev;
  427. /**
  428. * can't call min_mtu, because the needed variables
  429. * have not been initialized yet
  430. */
  431. dev->mtu = ETH_DATA_LEN;
  432. dev->hard_header_len = BAT_HEADER_LEN; /* reserve more space in the
  433. * skbuff for our header */
  434. /* generate random address */
  435. random_ether_addr(dev_addr);
  436. memcpy(dev->dev_addr, dev_addr, ETH_ALEN);
  437. SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);
  438. memset(priv, 0, sizeof(struct bat_priv));
  439. }
  440. struct net_device *softif_create(char *name)
  441. {
  442. struct net_device *soft_iface;
  443. struct bat_priv *bat_priv;
  444. int ret;
  445. soft_iface = alloc_netdev(sizeof(struct bat_priv) , name,
  446. interface_setup);
  447. if (!soft_iface) {
  448. pr_err("Unable to allocate the batman interface: %s\n", name);
  449. goto out;
  450. }
  451. ret = register_netdev(soft_iface);
  452. if (ret < 0) {
  453. pr_err("Unable to register the batman interface '%s': %i\n",
  454. name, ret);
  455. goto free_soft_iface;
  456. }
  457. bat_priv = netdev_priv(soft_iface);
  458. atomic_set(&bat_priv->aggregated_ogms, 1);
  459. atomic_set(&bat_priv->bonding, 0);
  460. atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
  461. atomic_set(&bat_priv->gw_mode, GW_MODE_OFF);
  462. atomic_set(&bat_priv->gw_sel_class, 20);
  463. atomic_set(&bat_priv->gw_bandwidth, 41);
  464. atomic_set(&bat_priv->orig_interval, 1000);
  465. atomic_set(&bat_priv->hop_penalty, 10);
  466. atomic_set(&bat_priv->log_level, 0);
  467. atomic_set(&bat_priv->fragmentation, 1);
  468. atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
  469. atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
  470. atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
  471. atomic_set(&bat_priv->bcast_seqno, 1);
  472. atomic_set(&bat_priv->hna_local_changed, 0);
  473. bat_priv->primary_if = NULL;
  474. bat_priv->num_ifaces = 0;
  475. bat_priv->softif_neigh = NULL;
  476. ret = sysfs_add_meshif(soft_iface);
  477. if (ret < 0)
  478. goto unreg_soft_iface;
  479. ret = debugfs_add_meshif(soft_iface);
  480. if (ret < 0)
  481. goto unreg_sysfs;
  482. ret = mesh_init(soft_iface);
  483. if (ret < 0)
  484. goto unreg_debugfs;
  485. return soft_iface;
  486. unreg_debugfs:
  487. debugfs_del_meshif(soft_iface);
  488. unreg_sysfs:
  489. sysfs_del_meshif(soft_iface);
  490. unreg_soft_iface:
  491. unregister_netdev(soft_iface);
  492. return NULL;
  493. free_soft_iface:
  494. free_netdev(soft_iface);
  495. out:
  496. return NULL;
  497. }
  498. void softif_destroy(struct net_device *soft_iface)
  499. {
  500. debugfs_del_meshif(soft_iface);
  501. sysfs_del_meshif(soft_iface);
  502. mesh_free(soft_iface);
  503. unregister_netdevice(soft_iface);
  504. }
  505. int softif_is_valid(struct net_device *net_dev)
  506. {
  507. #ifdef HAVE_NET_DEVICE_OPS
  508. if (net_dev->netdev_ops->ndo_start_xmit == interface_tx)
  509. return 1;
  510. #else
  511. if (net_dev->hard_start_xmit == interface_tx)
  512. return 1;
  513. #endif
  514. return 0;
  515. }
  516. /* ethtool */
  517. static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  518. {
  519. cmd->supported = 0;
  520. cmd->advertising = 0;
  521. cmd->speed = SPEED_10;
  522. cmd->duplex = DUPLEX_FULL;
  523. cmd->port = PORT_TP;
  524. cmd->phy_address = 0;
  525. cmd->transceiver = XCVR_INTERNAL;
  526. cmd->autoneg = AUTONEG_DISABLE;
  527. cmd->maxtxpkt = 0;
  528. cmd->maxrxpkt = 0;
  529. return 0;
  530. }
  531. static void bat_get_drvinfo(struct net_device *dev,
  532. struct ethtool_drvinfo *info)
  533. {
  534. strcpy(info->driver, "B.A.T.M.A.N. advanced");
  535. strcpy(info->version, SOURCE_VERSION);
  536. strcpy(info->fw_version, "N/A");
  537. strcpy(info->bus_info, "batman");
  538. }
  539. static u32 bat_get_msglevel(struct net_device *dev)
  540. {
  541. return -EOPNOTSUPP;
  542. }
  543. static void bat_set_msglevel(struct net_device *dev, u32 value)
  544. {
  545. }
  546. static u32 bat_get_link(struct net_device *dev)
  547. {
  548. return 1;
  549. }
  550. static u32 bat_get_rx_csum(struct net_device *dev)
  551. {
  552. return 0;
  553. }
  554. static int bat_set_rx_csum(struct net_device *dev, u32 data)
  555. {
  556. return -EOPNOTSUPP;
  557. }