soft-interface.c 19 KB

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