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