blob: 11bfe533e2a44d339b2eab0706c905af74c74216 [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann567db7b2012-01-01 00:41:38 +01002 * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
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
22#include "main.h"
23#include "soft-interface.h"
24#include "hard-interface.h"
25#include "routing.h"
26#include "send.h"
27#include "bat_debugfs.h"
28#include "translation-table.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000029#include "hash.h"
30#include "gateway_common.h"
31#include "gateway_client.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000032#include "bat_sysfs.h"
Antonio Quartulli43676ab52011-04-26 21:31:45 +020033#include "originator.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000034#include <linux/slab.h>
35#include <linux/ethtool.h>
36#include <linux/etherdevice.h>
37#include <linux/if_vlan.h>
38#include "unicast.h"
Simon Wunderlich23721382012-01-22 20:00:19 +010039#include "bridge_loop_avoidance.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000040
41
42static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
43static void bat_get_drvinfo(struct net_device *dev,
44 struct ethtool_drvinfo *info);
45static u32 bat_get_msglevel(struct net_device *dev);
46static void bat_set_msglevel(struct net_device *dev, u32 value);
47static u32 bat_get_link(struct net_device *dev);
Martin Hundebøllf8214862012-04-20 17:02:45 +020048static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data);
49static void batadv_get_ethtool_stats(struct net_device *dev,
50 struct ethtool_stats *stats, u64 *data);
51static int batadv_get_sset_count(struct net_device *dev, int stringset);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000052
53static const struct ethtool_ops bat_ethtool_ops = {
54 .get_settings = bat_get_settings,
55 .get_drvinfo = bat_get_drvinfo,
56 .get_msglevel = bat_get_msglevel,
57 .set_msglevel = bat_set_msglevel,
58 .get_link = bat_get_link,
Martin Hundebøllf8214862012-04-20 17:02:45 +020059 .get_strings = batadv_get_strings,
60 .get_ethtool_stats = batadv_get_ethtool_stats,
61 .get_sset_count = batadv_get_sset_count,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000062};
63
64int my_skb_head_push(struct sk_buff *skb, unsigned int len)
65{
66 int result;
67
68 /**
69 * TODO: We must check if we can release all references to non-payload
70 * data using skb_header_release in our skbs to allow skb_cow_header to
71 * work optimally. This means that those skbs are not allowed to read
72 * or write any data which is before the current position of skb->data
73 * after that call and thus allow other skbs with the same data buffer
74 * to write freely in that area.
75 */
76 result = skb_cow_head(skb, len);
77 if (result < 0)
78 return result;
79
80 skb_push(skb, len);
81 return 0;
82}
83
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000084static int interface_open(struct net_device *dev)
85{
86 netif_start_queue(dev);
87 return 0;
88}
89
90static int interface_release(struct net_device *dev)
91{
92 netif_stop_queue(dev);
93 return 0;
94}
95
96static struct net_device_stats *interface_stats(struct net_device *dev)
97{
98 struct bat_priv *bat_priv = netdev_priv(dev);
99 return &bat_priv->stats;
100}
101
102static int interface_set_mac_addr(struct net_device *dev, void *p)
103{
104 struct bat_priv *bat_priv = netdev_priv(dev);
105 struct sockaddr *addr = p;
106
107 if (!is_valid_ether_addr(addr->sa_data))
108 return -EADDRNOTAVAIL;
109
Antonio Quartulli015758d2011-07-09 17:52:13 +0200110 /* only modify transtable if it has been initialized before */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000111 if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200112 tt_local_remove(bat_priv, dev->dev_addr,
Antonio Quartullicc47f662011-04-27 14:27:57 +0200113 "mac address changed", false);
Antonio Quartullibc279082011-07-07 15:35:35 +0200114 tt_local_add(dev, addr->sa_data, NULL_IFINDEX);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000115 }
116
117 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
Danny Kukawka28009a62012-02-17 05:43:27 +0000118 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000119 return 0;
120}
121
122static int interface_change_mtu(struct net_device *dev, int new_mtu)
123{
124 /* check ranges */
125 if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev)))
126 return -EINVAL;
127
128 dev->mtu = new_mtu;
129
130 return 0;
131}
132
Sven Eckelmanndb69ecf2011-06-15 15:17:21 +0200133static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000134{
135 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
136 struct bat_priv *bat_priv = netdev_priv(soft_iface);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200137 struct hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000138 struct bcast_packet *bcast_packet;
139 struct vlan_ethhdr *vhdr;
Simon Wunderlichb1a8c042012-01-22 20:00:25 +0100140 static const uint8_t stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00,
141 0x00};
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200142 unsigned int header_len = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000143 int data_len = skb->len, ret;
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100144 short vid __maybe_unused = -1;
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200145 bool do_bcast = false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000146
147 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
148 goto dropped;
149
150 soft_iface->trans_start = jiffies;
151
152 switch (ntohs(ethhdr->h_proto)) {
153 case ETH_P_8021Q:
154 vhdr = (struct vlan_ethhdr *)skb->data;
155 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
156
157 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
158 break;
159
160 /* fall through */
161 case ETH_P_BATMAN:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000162 goto dropped;
Simon Wunderlicha7f6ee92012-01-22 20:00:18 +0100163 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000164
Simon Wunderlich23721382012-01-22 20:00:19 +0100165 if (bla_tx(bat_priv, skb, vid))
166 goto dropped;
167
Antonio Quartullia73105b2011-04-27 14:27:44 +0200168 /* Register the client MAC in the transtable */
Antonio Quartullibc279082011-07-07 15:35:35 +0200169 tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000170
Simon Wunderlichb1a8c042012-01-22 20:00:25 +0100171 /* don't accept stp packets. STP does not help in meshes.
172 * better use the bridge loop avoidance ...
173 */
174 if (compare_eth(ethhdr->h_dest, stp_addr))
175 goto dropped;
176
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200177 if (is_multicast_ether_addr(ethhdr->h_dest)) {
178 do_bcast = true;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000179
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200180 switch (atomic_read(&bat_priv->gw_mode)) {
181 case GW_MODE_SERVER:
182 /* gateway servers should not send dhcp
183 * requests into the mesh */
184 ret = gw_is_dhcp_target(skb, &header_len);
185 if (ret)
186 goto dropped;
187 break;
188 case GW_MODE_CLIENT:
189 /* gateway clients should send dhcp requests
190 * via unicast to their gateway */
191 ret = gw_is_dhcp_target(skb, &header_len);
192 if (ret)
193 do_bcast = false;
194 break;
195 case GW_MODE_OFF:
196 default:
197 break;
198 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000199 }
200
201 /* ethernet packet should be broadcasted */
202 if (do_bcast) {
Marek Lindner32ae9b22011-04-20 15:40:58 +0200203 primary_if = primary_if_get_selected(bat_priv);
204 if (!primary_if)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000205 goto dropped;
206
Sven Eckelmann704509b2011-05-14 23:14:54 +0200207 if (my_skb_head_push(skb, sizeof(*bcast_packet)) < 0)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000208 goto dropped;
209
210 bcast_packet = (struct bcast_packet *)skb->data;
Sven Eckelmann76543d12011-11-20 15:47:38 +0100211 bcast_packet->header.version = COMPAT_VERSION;
212 bcast_packet->header.ttl = TTL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000213
214 /* batman packet type: broadcast */
Sven Eckelmann76543d12011-11-20 15:47:38 +0100215 bcast_packet->header.packet_type = BAT_BCAST;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000216
217 /* hw address of first interface is the orig mac because only
218 * this mac is known throughout the mesh */
219 memcpy(bcast_packet->orig,
Marek Lindner32ae9b22011-04-20 15:40:58 +0200220 primary_if->net_dev->dev_addr, ETH_ALEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000221
222 /* set broadcast sequence number */
223 bcast_packet->seqno =
224 htonl(atomic_inc_return(&bat_priv->bcast_seqno));
225
Antonio Quartulli86985292011-06-25 19:09:12 +0200226 add_bcast_packet_to_list(bat_priv, skb, 1);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000227
228 /* a copy is stored in the bcast list, therefore removing
229 * the original skb. */
230 kfree_skb(skb);
231
232 /* unicast packet */
233 } else {
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200234 if (atomic_read(&bat_priv->gw_mode) != GW_MODE_OFF) {
235 ret = gw_out_of_range(bat_priv, skb, ethhdr);
236 if (ret)
237 goto dropped;
238 }
239
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000240 ret = unicast_send_skb(skb, bat_priv);
241 if (ret != 0)
242 goto dropped_freed;
243 }
244
245 bat_priv->stats.tx_packets++;
246 bat_priv->stats.tx_bytes += data_len;
247 goto end;
248
249dropped:
250 kfree_skb(skb);
251dropped_freed:
252 bat_priv->stats.tx_dropped++;
253end:
Marek Lindner32ae9b22011-04-20 15:40:58 +0200254 if (primary_if)
255 hardif_free_ref(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000256 return NETDEV_TX_OK;
257}
258
259void interface_rx(struct net_device *soft_iface,
Marek Lindnere6c10f42011-02-18 12:33:20 +0000260 struct sk_buff *skb, struct hard_iface *recv_if,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000261 int hdr_size)
262{
263 struct bat_priv *bat_priv = netdev_priv(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000264 struct ethhdr *ethhdr;
265 struct vlan_ethhdr *vhdr;
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100266 short vid __maybe_unused = -1;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000267
268 /* check if enough space is available for pulling, and pull */
269 if (!pskb_may_pull(skb, hdr_size))
270 goto dropped;
271
272 skb_pull_rcsum(skb, hdr_size);
273 skb_reset_mac_header(skb);
274
275 ethhdr = (struct ethhdr *)skb_mac_header(skb);
276
277 switch (ntohs(ethhdr->h_proto)) {
278 case ETH_P_8021Q:
279 vhdr = (struct vlan_ethhdr *)skb->data;
280 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
281
282 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
283 break;
284
285 /* fall through */
286 case ETH_P_BATMAN:
287 goto dropped;
288 }
289
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000290 /* skb->dev & skb->pkt_type are set here */
291 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
292 goto dropped;
293 skb->protocol = eth_type_trans(skb, soft_iface);
294
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300295 /* should not be necessary anymore as we use skb_pull_rcsum()
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000296 * TODO: please verify this and remove this TODO
297 * -- Dec 21st 2009, Simon Wunderlich */
298
299/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
300
301 bat_priv->stats.rx_packets++;
Antonio Quartulli0d125072012-02-18 11:27:34 +0100302 bat_priv->stats.rx_bytes += skb->len + ETH_HLEN;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000303
304 soft_iface->last_rx = jiffies;
305
Antonio Quartulli59b699c2011-07-07 15:35:36 +0200306 if (is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest))
307 goto dropped;
308
Simon Wunderlich23721382012-01-22 20:00:19 +0100309 /* Let the bridge loop avoidance check the packet. If will
310 * not handle it, we can safely push it up.
311 */
312 if (bla_rx(bat_priv, skb, vid))
313 goto out;
314
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000315 netif_rx(skb);
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200316 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000317
318dropped:
319 kfree_skb(skb);
320out:
321 return;
322}
323
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000324static const struct net_device_ops bat_netdev_ops = {
325 .ndo_open = interface_open,
326 .ndo_stop = interface_release,
327 .ndo_get_stats = interface_stats,
328 .ndo_set_mac_address = interface_set_mac_addr,
329 .ndo_change_mtu = interface_change_mtu,
330 .ndo_start_xmit = interface_tx,
331 .ndo_validate_addr = eth_validate_addr
332};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000333
334static void interface_setup(struct net_device *dev)
335{
336 struct bat_priv *priv = netdev_priv(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000337
338 ether_setup(dev);
339
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000340 dev->netdev_ops = &bat_netdev_ops;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000341 dev->destructor = free_netdev;
Andrew Lunnaf20b712011-04-17 20:39:07 +0200342 dev->tx_queue_len = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000343
344 /**
345 * can't call min_mtu, because the needed variables
346 * have not been initialized yet
347 */
348 dev->mtu = ETH_DATA_LEN;
Sven Eckelmann6e215fd2011-05-08 12:45:45 +0200349 /* reserve more space in the skbuff for our header */
350 dev->hard_header_len = BAT_HEADER_LEN;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000351
352 /* generate random address */
Danny Kukawka28009a62012-02-17 05:43:27 +0000353 eth_hw_addr_random(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000354
355 SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);
356
Sven Eckelmann704509b2011-05-14 23:14:54 +0200357 memset(priv, 0, sizeof(*priv));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000358}
359
Sven Eckelmann747e4222011-05-14 23:14:50 +0200360struct net_device *softif_create(const char *name)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000361{
362 struct net_device *soft_iface;
363 struct bat_priv *bat_priv;
364 int ret;
365
Sven Eckelmann704509b2011-05-14 23:14:54 +0200366 soft_iface = alloc_netdev(sizeof(*bat_priv), name, interface_setup);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000367
Joe Perches320f4222011-08-29 14:17:24 -0700368 if (!soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000369 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000370
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200371 ret = register_netdevice(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000372 if (ret < 0) {
373 pr_err("Unable to register the batman interface '%s': %i\n",
374 name, ret);
375 goto free_soft_iface;
376 }
377
378 bat_priv = netdev_priv(soft_iface);
379
380 atomic_set(&bat_priv->aggregated_ogms, 1);
381 atomic_set(&bat_priv->bonding, 0);
Simon Wunderlich23721382012-01-22 20:00:19 +0100382 atomic_set(&bat_priv->bridge_loop_avoidance, 0);
Antonio Quartulli59b699c2011-07-07 15:35:36 +0200383 atomic_set(&bat_priv->ap_isolation, 0);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000384 atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
385 atomic_set(&bat_priv->gw_mode, GW_MODE_OFF);
386 atomic_set(&bat_priv->gw_sel_class, 20);
387 atomic_set(&bat_priv->gw_bandwidth, 41);
388 atomic_set(&bat_priv->orig_interval, 1000);
Marek Lindner8681a1c2012-01-27 23:11:55 +0800389 atomic_set(&bat_priv->hop_penalty, 30);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000390 atomic_set(&bat_priv->log_level, 0);
391 atomic_set(&bat_priv->fragmentation, 1);
392 atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
393 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
394
395 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
396 atomic_set(&bat_priv->bcast_seqno, 1);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200397 atomic_set(&bat_priv->ttvn, 0);
398 atomic_set(&bat_priv->tt_local_changes, 0);
399 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
Simon Wunderlich23721382012-01-22 20:00:19 +0100400 atomic_set(&bat_priv->bla_num_requests, 0);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200401
402 bat_priv->tt_buff = NULL;
403 bat_priv->tt_buff_len = 0;
Antonio Quartullicc47f662011-04-27 14:27:57 +0200404 bat_priv->tt_poss_change = false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000405
406 bat_priv->primary_if = NULL;
407 bat_priv->num_ifaces = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000408
Martin Hundebøllf8214862012-04-20 17:02:45 +0200409 bat_priv->bat_counters = __alloc_percpu(sizeof(uint64_t) * BAT_CNT_NUM,
410 __alignof__(uint64_t));
411 if (!bat_priv->bat_counters)
412 goto unreg_soft_iface;
413
Marek Lindner1c280472011-11-28 17:40:17 +0800414 ret = bat_algo_select(bat_priv, bat_routing_algo);
415 if (ret < 0)
Martin Hundebøllf8214862012-04-20 17:02:45 +0200416 goto free_bat_counters;
Marek Lindner1c280472011-11-28 17:40:17 +0800417
Sven Eckelmann5853e222012-05-12 02:09:24 +0200418 ret = batadv_sysfs_add_meshif(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000419 if (ret < 0)
Martin Hundebøllf8214862012-04-20 17:02:45 +0200420 goto free_bat_counters;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000421
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200422 ret = batadv_debugfs_add_meshif(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000423 if (ret < 0)
424 goto unreg_sysfs;
425
426 ret = mesh_init(soft_iface);
427 if (ret < 0)
428 goto unreg_debugfs;
429
430 return soft_iface;
431
432unreg_debugfs:
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200433 batadv_debugfs_del_meshif(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000434unreg_sysfs:
Sven Eckelmann5853e222012-05-12 02:09:24 +0200435 batadv_sysfs_del_meshif(soft_iface);
Martin Hundebøllf8214862012-04-20 17:02:45 +0200436free_bat_counters:
437 free_percpu(bat_priv->bat_counters);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000438unreg_soft_iface:
Simon Wunderlich06ba7ce2011-11-07 13:57:48 +0100439 unregister_netdevice(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000440 return NULL;
441
442free_soft_iface:
443 free_netdev(soft_iface);
444out:
445 return NULL;
446}
447
448void softif_destroy(struct net_device *soft_iface)
449{
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200450 batadv_debugfs_del_meshif(soft_iface);
Sven Eckelmann5853e222012-05-12 02:09:24 +0200451 batadv_sysfs_del_meshif(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000452 mesh_free(soft_iface);
453 unregister_netdevice(soft_iface);
454}
455
Sven Eckelmann747e4222011-05-14 23:14:50 +0200456int softif_is_valid(const struct net_device *net_dev)
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000457{
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000458 if (net_dev->netdev_ops->ndo_start_xmit == interface_tx)
459 return 1;
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000460
461 return 0;
462}
463
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000464/* ethtool */
465static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
466{
467 cmd->supported = 0;
468 cmd->advertising = 0;
David Decotigny70739492011-04-27 18:32:40 +0000469 ethtool_cmd_speed_set(cmd, SPEED_10);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000470 cmd->duplex = DUPLEX_FULL;
471 cmd->port = PORT_TP;
472 cmd->phy_address = 0;
473 cmd->transceiver = XCVR_INTERNAL;
474 cmd->autoneg = AUTONEG_DISABLE;
475 cmd->maxtxpkt = 0;
476 cmd->maxrxpkt = 0;
477
478 return 0;
479}
480
481static void bat_get_drvinfo(struct net_device *dev,
482 struct ethtool_drvinfo *info)
483{
484 strcpy(info->driver, "B.A.T.M.A.N. advanced");
485 strcpy(info->version, SOURCE_VERSION);
486 strcpy(info->fw_version, "N/A");
487 strcpy(info->bus_info, "batman");
488}
489
490static u32 bat_get_msglevel(struct net_device *dev)
491{
492 return -EOPNOTSUPP;
493}
494
495static void bat_set_msglevel(struct net_device *dev, u32 value)
496{
497}
498
499static u32 bat_get_link(struct net_device *dev)
500{
501 return 1;
502}
Martin Hundebøllf8214862012-04-20 17:02:45 +0200503
504/* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
505 * Declare each description string in struct.name[] to get fixed sized buffer
506 * and compile time checking for strings longer than ETH_GSTRING_LEN.
507 */
508static const struct {
509 const char name[ETH_GSTRING_LEN];
510} bat_counters_strings[] = {
511 { "forward" },
512 { "forward_bytes" },
513 { "mgmt_tx" },
514 { "mgmt_tx_bytes" },
515 { "mgmt_rx" },
516 { "mgmt_rx_bytes" },
517 { "tt_request_tx" },
518 { "tt_request_rx" },
519 { "tt_response_tx" },
520 { "tt_response_rx" },
521 { "tt_roam_adv_tx" },
522 { "tt_roam_adv_rx" },
523};
524
525static void batadv_get_strings(struct net_device *dev, uint32_t stringset,
526 uint8_t *data)
527{
528 if (stringset == ETH_SS_STATS)
529 memcpy(data, bat_counters_strings,
530 sizeof(bat_counters_strings));
531}
532
533static void batadv_get_ethtool_stats(struct net_device *dev,
534 struct ethtool_stats *stats,
535 uint64_t *data)
536{
537 struct bat_priv *bat_priv = netdev_priv(dev);
538 int i;
539
540 for (i = 0; i < BAT_CNT_NUM; i++)
541 data[i] = batadv_sum_counter(bat_priv, i);
542}
543
544static int batadv_get_sset_count(struct net_device *dev, int stringset)
545{
546 if (stringset == ETH_SS_STATS)
547 return BAT_CNT_NUM;
548
549 return -EOPNOTSUPP;
550}