soft-interface.c 17 KB

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