soft-interface.c 17 KB

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