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