soft-interface.c 17 KB

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