blob: 04efe022c13b5b438dbe16df3e217a29a8539ace [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2007-2011 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"
33#include <linux/slab.h>
34#include <linux/ethtool.h>
35#include <linux/etherdevice.h>
36#include <linux/if_vlan.h>
37#include "unicast.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000038
39
40static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
41static void bat_get_drvinfo(struct net_device *dev,
42 struct ethtool_drvinfo *info);
43static u32 bat_get_msglevel(struct net_device *dev);
44static void bat_set_msglevel(struct net_device *dev, u32 value);
45static u32 bat_get_link(struct net_device *dev);
46static u32 bat_get_rx_csum(struct net_device *dev);
47static int bat_set_rx_csum(struct net_device *dev, u32 data);
48
49static const struct ethtool_ops bat_ethtool_ops = {
50 .get_settings = bat_get_settings,
51 .get_drvinfo = bat_get_drvinfo,
52 .get_msglevel = bat_get_msglevel,
53 .set_msglevel = bat_set_msglevel,
54 .get_link = bat_get_link,
55 .get_rx_csum = bat_get_rx_csum,
56 .set_rx_csum = bat_set_rx_csum
57};
58
59int my_skb_head_push(struct sk_buff *skb, unsigned int len)
60{
61 int result;
62
63 /**
64 * TODO: We must check if we can release all references to non-payload
65 * data using skb_header_release in our skbs to allow skb_cow_header to
66 * work optimally. This means that those skbs are not allowed to read
67 * or write any data which is before the current position of skb->data
68 * after that call and thus allow other skbs with the same data buffer
69 * to write freely in that area.
70 */
71 result = skb_cow_head(skb, len);
72 if (result < 0)
73 return result;
74
75 skb_push(skb, len);
76 return 0;
77}
78
Marek Lindner7d2b5542011-02-10 14:33:50 +000079static void softif_neigh_free_ref(struct softif_neigh *softif_neigh)
80{
81 if (atomic_dec_and_test(&softif_neigh->refcount))
Paul E. McKenney8e3572c2011-05-02 00:52:23 -070082 kfree_rcu(softif_neigh, rcu);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000083}
84
85void softif_neigh_purge(struct bat_priv *bat_priv)
86{
87 struct softif_neigh *softif_neigh, *softif_neigh_tmp;
88 struct hlist_node *node, *node_tmp;
89
90 spin_lock_bh(&bat_priv->softif_neigh_lock);
91
92 hlist_for_each_entry_safe(softif_neigh, node, node_tmp,
93 &bat_priv->softif_neigh_list, list) {
94
95 if ((!time_after(jiffies, softif_neigh->last_seen +
96 msecs_to_jiffies(SOFTIF_NEIGH_TIMEOUT))) &&
97 (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE))
98 continue;
99
100 hlist_del_rcu(&softif_neigh->list);
101
102 if (bat_priv->softif_neigh == softif_neigh) {
103 bat_dbg(DBG_ROUTES, bat_priv,
104 "Current mesh exit point '%pM' vanished "
105 "(vid: %d).\n",
106 softif_neigh->addr, softif_neigh->vid);
107 softif_neigh_tmp = bat_priv->softif_neigh;
108 bat_priv->softif_neigh = NULL;
Marek Lindner7d2b5542011-02-10 14:33:50 +0000109 softif_neigh_free_ref(softif_neigh_tmp);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000110 }
111
Marek Lindner7d2b5542011-02-10 14:33:50 +0000112 softif_neigh_free_ref(softif_neigh);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000113 }
114
115 spin_unlock_bh(&bat_priv->softif_neigh_lock);
116}
117
118static struct softif_neigh *softif_neigh_get(struct bat_priv *bat_priv,
119 uint8_t *addr, short vid)
120{
121 struct softif_neigh *softif_neigh;
122 struct hlist_node *node;
123
124 rcu_read_lock();
125 hlist_for_each_entry_rcu(softif_neigh, node,
126 &bat_priv->softif_neigh_list, list) {
Marek Lindner39901e72011-02-18 12:28:08 +0000127 if (!compare_eth(softif_neigh->addr, addr))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000128 continue;
129
130 if (softif_neigh->vid != vid)
131 continue;
132
Marek Lindner7d2b5542011-02-10 14:33:50 +0000133 if (!atomic_inc_not_zero(&softif_neigh->refcount))
134 continue;
135
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000136 softif_neigh->last_seen = jiffies;
Marek Lindner7d2b5542011-02-10 14:33:50 +0000137 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000138 }
139
140 softif_neigh = kzalloc(sizeof(struct softif_neigh), GFP_ATOMIC);
141 if (!softif_neigh)
142 goto out;
143
144 memcpy(softif_neigh->addr, addr, ETH_ALEN);
145 softif_neigh->vid = vid;
146 softif_neigh->last_seen = jiffies;
Marek Lindner7d2b5542011-02-10 14:33:50 +0000147 /* initialize with 2 - caller decrements counter by one */
148 atomic_set(&softif_neigh->refcount, 2);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000149
150 INIT_HLIST_NODE(&softif_neigh->list);
151 spin_lock_bh(&bat_priv->softif_neigh_lock);
152 hlist_add_head_rcu(&softif_neigh->list, &bat_priv->softif_neigh_list);
153 spin_unlock_bh(&bat_priv->softif_neigh_lock);
154
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000155out:
156 rcu_read_unlock();
157 return softif_neigh;
158}
159
160int softif_neigh_seq_print_text(struct seq_file *seq, void *offset)
161{
162 struct net_device *net_dev = (struct net_device *)seq->private;
163 struct bat_priv *bat_priv = netdev_priv(net_dev);
164 struct softif_neigh *softif_neigh;
165 struct hlist_node *node;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000166
167 if (!bat_priv->primary_if) {
168 return seq_printf(seq, "BATMAN mesh %s disabled - "
169 "please specify interfaces to enable it\n",
170 net_dev->name);
171 }
172
173 seq_printf(seq, "Softif neighbor list (%s)\n", net_dev->name);
174
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000175 rcu_read_lock();
176 hlist_for_each_entry_rcu(softif_neigh, node,
177 &bat_priv->softif_neigh_list, list)
Linus Lüssing9e0b33c2011-02-18 12:20:13 +0000178 seq_printf(seq, "%s %pM (vid: %d)\n",
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000179 bat_priv->softif_neigh == softif_neigh
180 ? "=>" : " ", softif_neigh->addr,
181 softif_neigh->vid);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000182 rcu_read_unlock();
183
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000184 return 0;
185}
186
187static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev,
188 short vid)
189{
190 struct bat_priv *bat_priv = netdev_priv(dev);
191 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
192 struct batman_packet *batman_packet;
193 struct softif_neigh *softif_neigh, *softif_neigh_tmp;
194
195 if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
196 batman_packet = (struct batman_packet *)
197 (skb->data + ETH_HLEN + VLAN_HLEN);
198 else
199 batman_packet = (struct batman_packet *)(skb->data + ETH_HLEN);
200
201 if (batman_packet->version != COMPAT_VERSION)
202 goto err;
203
204 if (batman_packet->packet_type != BAT_PACKET)
205 goto err;
206
207 if (!(batman_packet->flags & PRIMARIES_FIRST_HOP))
208 goto err;
209
210 if (is_my_mac(batman_packet->orig))
211 goto err;
212
213 softif_neigh = softif_neigh_get(bat_priv, batman_packet->orig, vid);
214
215 if (!softif_neigh)
216 goto err;
217
218 if (bat_priv->softif_neigh == softif_neigh)
219 goto out;
220
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
226 /* switch to new 'smallest neighbor' */
227 if ((bat_priv->softif_neigh) &&
228 (memcmp(softif_neigh->addr, bat_priv->softif_neigh->addr,
229 ETH_ALEN) < 0)) {
230 bat_dbg(DBG_ROUTES, bat_priv,
231 "Changing mesh exit point from %pM (vid: %d) "
232 "to %pM (vid: %d).\n",
233 bat_priv->softif_neigh->addr,
234 bat_priv->softif_neigh->vid,
235 softif_neigh->addr, softif_neigh->vid);
236 softif_neigh_tmp = bat_priv->softif_neigh;
237 bat_priv->softif_neigh = softif_neigh;
Marek Lindner7d2b5542011-02-10 14:33:50 +0000238 softif_neigh_free_ref(softif_neigh_tmp);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000239 /* we need to hold the additional reference */
240 goto err;
241 }
242
243 /* close own batX device and use softif_neigh as exit node */
244 if ((!bat_priv->softif_neigh) &&
245 (memcmp(softif_neigh->addr,
246 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN) < 0)) {
247 bat_dbg(DBG_ROUTES, bat_priv,
248 "Setting mesh exit point to %pM (vid: %d).\n",
249 softif_neigh->addr, softif_neigh->vid);
250 bat_priv->softif_neigh = softif_neigh;
251 /* we need to hold the additional reference */
252 goto err;
253 }
254
255out:
Marek Lindner7d2b5542011-02-10 14:33:50 +0000256 softif_neigh_free_ref(softif_neigh);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000257err:
258 kfree_skb(skb);
259 return;
260}
261
262static int interface_open(struct net_device *dev)
263{
264 netif_start_queue(dev);
265 return 0;
266}
267
268static int interface_release(struct net_device *dev)
269{
270 netif_stop_queue(dev);
271 return 0;
272}
273
274static struct net_device_stats *interface_stats(struct net_device *dev)
275{
276 struct bat_priv *bat_priv = netdev_priv(dev);
277 return &bat_priv->stats;
278}
279
280static int interface_set_mac_addr(struct net_device *dev, void *p)
281{
282 struct bat_priv *bat_priv = netdev_priv(dev);
283 struct sockaddr *addr = p;
284
285 if (!is_valid_ether_addr(addr->sa_data))
286 return -EADDRNOTAVAIL;
287
288 /* only modify hna-table if it has been initialised before */
289 if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
290 hna_local_remove(bat_priv, dev->dev_addr,
291 "mac address changed");
292 hna_local_add(dev, addr->sa_data);
293 }
294
295 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
296 return 0;
297}
298
299static int interface_change_mtu(struct net_device *dev, int new_mtu)
300{
301 /* check ranges */
302 if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev)))
303 return -EINVAL;
304
305 dev->mtu = new_mtu;
306
307 return 0;
308}
309
310int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
311{
312 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
313 struct bat_priv *bat_priv = netdev_priv(soft_iface);
314 struct bcast_packet *bcast_packet;
315 struct vlan_ethhdr *vhdr;
316 int data_len = skb->len, ret;
317 short vid = -1;
318 bool do_bcast = false;
319
320 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
321 goto dropped;
322
323 soft_iface->trans_start = jiffies;
324
325 switch (ntohs(ethhdr->h_proto)) {
326 case ETH_P_8021Q:
327 vhdr = (struct vlan_ethhdr *)skb->data;
328 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
329
330 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
331 break;
332
333 /* fall through */
334 case ETH_P_BATMAN:
335 softif_batman_recv(skb, soft_iface, vid);
336 goto end;
337 }
338
339 /**
340 * if we have a another chosen mesh exit node in range
341 * it will transport the packets to the mesh
342 */
343 if ((bat_priv->softif_neigh) && (bat_priv->softif_neigh->vid == vid))
344 goto dropped;
345
346 /* TODO: check this for locks */
347 hna_local_add(soft_iface, ethhdr->h_source);
348
349 if (is_multicast_ether_addr(ethhdr->h_dest)) {
350 ret = gw_is_target(bat_priv, skb);
351
352 if (ret < 0)
353 goto dropped;
354
355 if (ret == 0)
356 do_bcast = true;
357 }
358
359 /* ethernet packet should be broadcasted */
360 if (do_bcast) {
361 if (!bat_priv->primary_if)
362 goto dropped;
363
364 if (my_skb_head_push(skb, sizeof(struct bcast_packet)) < 0)
365 goto dropped;
366
367 bcast_packet = (struct bcast_packet *)skb->data;
368 bcast_packet->version = COMPAT_VERSION;
369 bcast_packet->ttl = TTL;
370
371 /* batman packet type: broadcast */
372 bcast_packet->packet_type = BAT_BCAST;
373
374 /* hw address of first interface is the orig mac because only
375 * this mac is known throughout the mesh */
376 memcpy(bcast_packet->orig,
377 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
378
379 /* set broadcast sequence number */
380 bcast_packet->seqno =
381 htonl(atomic_inc_return(&bat_priv->bcast_seqno));
382
383 add_bcast_packet_to_list(bat_priv, skb);
384
385 /* a copy is stored in the bcast list, therefore removing
386 * the original skb. */
387 kfree_skb(skb);
388
389 /* unicast packet */
390 } else {
391 ret = unicast_send_skb(skb, bat_priv);
392 if (ret != 0)
393 goto dropped_freed;
394 }
395
396 bat_priv->stats.tx_packets++;
397 bat_priv->stats.tx_bytes += data_len;
398 goto end;
399
400dropped:
401 kfree_skb(skb);
402dropped_freed:
403 bat_priv->stats.tx_dropped++;
404end:
405 return NETDEV_TX_OK;
406}
407
408void interface_rx(struct net_device *soft_iface,
Marek Lindnere6c10f42011-02-18 12:33:20 +0000409 struct sk_buff *skb, struct hard_iface *recv_if,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000410 int hdr_size)
411{
412 struct bat_priv *bat_priv = netdev_priv(soft_iface);
413 struct unicast_packet *unicast_packet;
414 struct ethhdr *ethhdr;
415 struct vlan_ethhdr *vhdr;
416 short vid = -1;
417 int ret;
418
419 /* check if enough space is available for pulling, and pull */
420 if (!pskb_may_pull(skb, hdr_size))
421 goto dropped;
422
423 skb_pull_rcsum(skb, hdr_size);
424 skb_reset_mac_header(skb);
425
426 ethhdr = (struct ethhdr *)skb_mac_header(skb);
427
428 switch (ntohs(ethhdr->h_proto)) {
429 case ETH_P_8021Q:
430 vhdr = (struct vlan_ethhdr *)skb->data;
431 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
432
433 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
434 break;
435
436 /* fall through */
437 case ETH_P_BATMAN:
438 goto dropped;
439 }
440
441 /**
442 * if we have a another chosen mesh exit node in range
443 * it will transport the packets to the non-mesh network
444 */
445 if ((bat_priv->softif_neigh) && (bat_priv->softif_neigh->vid == vid)) {
446 skb_push(skb, hdr_size);
447 unicast_packet = (struct unicast_packet *)skb->data;
448
449 if ((unicast_packet->packet_type != BAT_UNICAST) &&
450 (unicast_packet->packet_type != BAT_UNICAST_FRAG))
451 goto dropped;
452
453 skb_reset_mac_header(skb);
454
455 memcpy(unicast_packet->dest,
456 bat_priv->softif_neigh->addr, ETH_ALEN);
Linus Lüssing7cefb142011-03-02 17:39:31 +0000457 ret = route_unicast_packet(skb, recv_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000458 if (ret == NET_RX_DROP)
459 goto dropped;
460
461 goto out;
462 }
463
464 /* skb->dev & skb->pkt_type are set here */
465 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
466 goto dropped;
467 skb->protocol = eth_type_trans(skb, soft_iface);
468
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300469 /* should not be necessary anymore as we use skb_pull_rcsum()
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000470 * TODO: please verify this and remove this TODO
471 * -- Dec 21st 2009, Simon Wunderlich */
472
473/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
474
475 bat_priv->stats.rx_packets++;
476 bat_priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr);
477
478 soft_iface->last_rx = jiffies;
479
480 netif_rx(skb);
481 return;
482
483dropped:
484 kfree_skb(skb);
485out:
486 return;
487}
488
489#ifdef HAVE_NET_DEVICE_OPS
490static const struct net_device_ops bat_netdev_ops = {
491 .ndo_open = interface_open,
492 .ndo_stop = interface_release,
493 .ndo_get_stats = interface_stats,
494 .ndo_set_mac_address = interface_set_mac_addr,
495 .ndo_change_mtu = interface_change_mtu,
496 .ndo_start_xmit = interface_tx,
497 .ndo_validate_addr = eth_validate_addr
498};
499#endif
500
501static void interface_setup(struct net_device *dev)
502{
503 struct bat_priv *priv = netdev_priv(dev);
504 char dev_addr[ETH_ALEN];
505
506 ether_setup(dev);
507
508#ifdef HAVE_NET_DEVICE_OPS
509 dev->netdev_ops = &bat_netdev_ops;
510#else
511 dev->open = interface_open;
512 dev->stop = interface_release;
513 dev->get_stats = interface_stats;
514 dev->set_mac_address = interface_set_mac_addr;
515 dev->change_mtu = interface_change_mtu;
516 dev->hard_start_xmit = interface_tx;
517#endif
518 dev->destructor = free_netdev;
519
520 /**
521 * can't call min_mtu, because the needed variables
522 * have not been initialized yet
523 */
524 dev->mtu = ETH_DATA_LEN;
525 dev->hard_header_len = BAT_HEADER_LEN; /* reserve more space in the
526 * skbuff for our header */
527
528 /* generate random address */
529 random_ether_addr(dev_addr);
530 memcpy(dev->dev_addr, dev_addr, ETH_ALEN);
531
532 SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);
533
534 memset(priv, 0, sizeof(struct bat_priv));
535}
536
537struct net_device *softif_create(char *name)
538{
539 struct net_device *soft_iface;
540 struct bat_priv *bat_priv;
541 int ret;
542
543 soft_iface = alloc_netdev(sizeof(struct bat_priv) , name,
544 interface_setup);
545
546 if (!soft_iface) {
547 pr_err("Unable to allocate the batman interface: %s\n", name);
548 goto out;
549 }
550
551 ret = register_netdev(soft_iface);
552 if (ret < 0) {
553 pr_err("Unable to register the batman interface '%s': %i\n",
554 name, ret);
555 goto free_soft_iface;
556 }
557
558 bat_priv = netdev_priv(soft_iface);
559
560 atomic_set(&bat_priv->aggregated_ogms, 1);
561 atomic_set(&bat_priv->bonding, 0);
562 atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
563 atomic_set(&bat_priv->gw_mode, GW_MODE_OFF);
564 atomic_set(&bat_priv->gw_sel_class, 20);
565 atomic_set(&bat_priv->gw_bandwidth, 41);
566 atomic_set(&bat_priv->orig_interval, 1000);
567 atomic_set(&bat_priv->hop_penalty, 10);
568 atomic_set(&bat_priv->log_level, 0);
569 atomic_set(&bat_priv->fragmentation, 1);
570 atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
571 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
572
573 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
574 atomic_set(&bat_priv->bcast_seqno, 1);
575 atomic_set(&bat_priv->hna_local_changed, 0);
576
577 bat_priv->primary_if = NULL;
578 bat_priv->num_ifaces = 0;
579 bat_priv->softif_neigh = NULL;
580
581 ret = sysfs_add_meshif(soft_iface);
582 if (ret < 0)
583 goto unreg_soft_iface;
584
585 ret = debugfs_add_meshif(soft_iface);
586 if (ret < 0)
587 goto unreg_sysfs;
588
589 ret = mesh_init(soft_iface);
590 if (ret < 0)
591 goto unreg_debugfs;
592
593 return soft_iface;
594
595unreg_debugfs:
596 debugfs_del_meshif(soft_iface);
597unreg_sysfs:
598 sysfs_del_meshif(soft_iface);
599unreg_soft_iface:
600 unregister_netdev(soft_iface);
601 return NULL;
602
603free_soft_iface:
604 free_netdev(soft_iface);
605out:
606 return NULL;
607}
608
609void softif_destroy(struct net_device *soft_iface)
610{
611 debugfs_del_meshif(soft_iface);
612 sysfs_del_meshif(soft_iface);
613 mesh_free(soft_iface);
614 unregister_netdevice(soft_iface);
615}
616
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000617int softif_is_valid(struct net_device *net_dev)
618{
619#ifdef HAVE_NET_DEVICE_OPS
620 if (net_dev->netdev_ops->ndo_start_xmit == interface_tx)
621 return 1;
622#else
623 if (net_dev->hard_start_xmit == interface_tx)
624 return 1;
625#endif
626
627 return 0;
628}
629
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000630/* ethtool */
631static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
632{
633 cmd->supported = 0;
634 cmd->advertising = 0;
635 cmd->speed = SPEED_10;
636 cmd->duplex = DUPLEX_FULL;
637 cmd->port = PORT_TP;
638 cmd->phy_address = 0;
639 cmd->transceiver = XCVR_INTERNAL;
640 cmd->autoneg = AUTONEG_DISABLE;
641 cmd->maxtxpkt = 0;
642 cmd->maxrxpkt = 0;
643
644 return 0;
645}
646
647static void bat_get_drvinfo(struct net_device *dev,
648 struct ethtool_drvinfo *info)
649{
650 strcpy(info->driver, "B.A.T.M.A.N. advanced");
651 strcpy(info->version, SOURCE_VERSION);
652 strcpy(info->fw_version, "N/A");
653 strcpy(info->bus_info, "batman");
654}
655
656static u32 bat_get_msglevel(struct net_device *dev)
657{
658 return -EOPNOTSUPP;
659}
660
661static void bat_set_msglevel(struct net_device *dev, u32 value)
662{
663}
664
665static u32 bat_get_link(struct net_device *dev)
666{
667 return 1;
668}
669
670static u32 bat_get_rx_csum(struct net_device *dev)
671{
672 return 0;
673}
674
675static int bat_set_rx_csum(struct net_device *dev, u32 data)
676{
677 return -EOPNOTSUPP;
678}