soft-interface.c 17 KB

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