soft-interface.c 18 KB

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