2 * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich
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.
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.
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
23 #include "soft-interface.h"
24 #include "hard-interface.h"
27 #include "bat_debugfs.h"
28 #include "translation-table.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>
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);
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,
55 int my_skb_head_push(struct sk_buff *skb, unsigned int len)
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.
67 result = skb_cow_head(skb, len);
75 static void softif_neigh_free_rcu(struct rcu_head *rcu)
77 struct softif_neigh *softif_neigh;
79 softif_neigh = container_of(rcu, struct softif_neigh, rcu);
83 static void softif_neigh_free_ref(struct softif_neigh *softif_neigh)
85 if (atomic_dec_and_test(&softif_neigh->refcount))
86 call_rcu(&softif_neigh->rcu, softif_neigh_free_rcu);
89 static void softif_neigh_vid_free_rcu(struct rcu_head *rcu)
91 struct softif_neigh_vid *softif_neigh_vid;
92 struct softif_neigh *softif_neigh;
93 struct hlist_node *node, *node_tmp;
94 struct bat_priv *bat_priv;
96 softif_neigh_vid = container_of(rcu, struct softif_neigh_vid, rcu);
97 bat_priv = softif_neigh_vid->bat_priv;
99 spin_lock_bh(&bat_priv->softif_neigh_lock);
100 hlist_for_each_entry_safe(softif_neigh, node, node_tmp,
101 &softif_neigh_vid->softif_neigh_list, list) {
102 hlist_del_rcu(&softif_neigh->list);
103 softif_neigh_free_ref(softif_neigh);
105 spin_unlock_bh(&bat_priv->softif_neigh_lock);
107 kfree(softif_neigh_vid);
110 static void softif_neigh_vid_free_ref(struct softif_neigh_vid *softif_neigh_vid)
112 if (atomic_dec_and_test(&softif_neigh_vid->refcount))
113 call_rcu(&softif_neigh_vid->rcu, softif_neigh_vid_free_rcu);
116 static struct softif_neigh_vid *softif_neigh_vid_get(struct bat_priv *bat_priv,
119 struct softif_neigh_vid *softif_neigh_vid;
120 struct hlist_node *node;
123 hlist_for_each_entry_rcu(softif_neigh_vid, node,
124 &bat_priv->softif_neigh_vids, list) {
125 if (softif_neigh_vid->vid != vid)
128 if (!atomic_inc_not_zero(&softif_neigh_vid->refcount))
134 softif_neigh_vid = kzalloc(sizeof(struct softif_neigh_vid),
136 if (!softif_neigh_vid)
139 softif_neigh_vid->vid = vid;
140 softif_neigh_vid->bat_priv = bat_priv;
142 /* initialize with 2 - caller decrements counter by one */
143 atomic_set(&softif_neigh_vid->refcount, 2);
144 INIT_HLIST_HEAD(&softif_neigh_vid->softif_neigh_list);
145 INIT_HLIST_NODE(&softif_neigh_vid->list);
146 spin_lock_bh(&bat_priv->softif_neigh_vid_lock);
147 hlist_add_head_rcu(&softif_neigh_vid->list,
148 &bat_priv->softif_neigh_vids);
149 spin_unlock_bh(&bat_priv->softif_neigh_vid_lock);
153 return softif_neigh_vid;
156 static struct softif_neigh *softif_neigh_get(struct bat_priv *bat_priv,
157 uint8_t *addr, short vid)
159 struct softif_neigh_vid *softif_neigh_vid;
160 struct softif_neigh *softif_neigh = NULL;
161 struct hlist_node *node;
163 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
164 if (!softif_neigh_vid)
168 hlist_for_each_entry_rcu(softif_neigh, node,
169 &softif_neigh_vid->softif_neigh_list,
171 if (!compare_eth(softif_neigh->addr, addr))
174 if (!atomic_inc_not_zero(&softif_neigh->refcount))
177 softif_neigh->last_seen = jiffies;
181 softif_neigh = kzalloc(sizeof(struct softif_neigh), GFP_ATOMIC);
185 memcpy(softif_neigh->addr, addr, ETH_ALEN);
186 softif_neigh->last_seen = jiffies;
187 /* initialize with 2 - caller decrements counter by one */
188 atomic_set(&softif_neigh->refcount, 2);
190 INIT_HLIST_NODE(&softif_neigh->list);
191 spin_lock_bh(&bat_priv->softif_neigh_lock);
192 hlist_add_head_rcu(&softif_neigh->list,
193 &softif_neigh_vid->softif_neigh_list);
194 spin_unlock_bh(&bat_priv->softif_neigh_lock);
199 if (softif_neigh_vid)
200 softif_neigh_vid_free_ref(softif_neigh_vid);
204 static struct softif_neigh *softif_neigh_get_selected(
205 struct softif_neigh_vid *softif_neigh_vid)
207 struct softif_neigh *softif_neigh;
210 softif_neigh = rcu_dereference(softif_neigh_vid->softif_neigh);
212 if (softif_neigh && !atomic_inc_not_zero(&softif_neigh->refcount))
219 static struct softif_neigh *softif_neigh_vid_get_selected(
220 struct bat_priv *bat_priv,
223 struct softif_neigh_vid *softif_neigh_vid;
224 struct softif_neigh *softif_neigh = NULL;
226 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
227 if (!softif_neigh_vid)
230 softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
232 if (softif_neigh_vid)
233 softif_neigh_vid_free_ref(softif_neigh_vid);
237 static void softif_neigh_vid_select(struct bat_priv *bat_priv,
238 struct softif_neigh *new_neigh,
241 struct softif_neigh_vid *softif_neigh_vid;
242 struct softif_neigh *curr_neigh;
244 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
245 if (!softif_neigh_vid)
248 spin_lock_bh(&bat_priv->softif_neigh_lock);
250 if (new_neigh && !atomic_inc_not_zero(&new_neigh->refcount))
253 curr_neigh = softif_neigh_vid->softif_neigh;
254 rcu_assign_pointer(softif_neigh_vid->softif_neigh, new_neigh);
256 if ((curr_neigh) && (!new_neigh))
257 bat_dbg(DBG_ROUTES, bat_priv,
258 "Removing mesh exit point on vid: %d (prev: %pM).\n",
259 vid, curr_neigh->addr);
260 else if ((curr_neigh) && (new_neigh))
261 bat_dbg(DBG_ROUTES, bat_priv,
262 "Changing mesh exit point on vid: %d from %pM "
263 "to %pM.\n", vid, curr_neigh->addr, new_neigh->addr);
264 else if ((!curr_neigh) && (new_neigh))
265 bat_dbg(DBG_ROUTES, bat_priv,
266 "Setting mesh exit point on vid: %d to %pM.\n",
267 vid, new_neigh->addr);
270 softif_neigh_free_ref(curr_neigh);
272 spin_unlock_bh(&bat_priv->softif_neigh_lock);
275 if (softif_neigh_vid)
276 softif_neigh_vid_free_ref(softif_neigh_vid);
279 static void softif_neigh_vid_deselect(struct bat_priv *bat_priv,
280 struct softif_neigh_vid *softif_neigh_vid)
282 struct softif_neigh *curr_neigh;
283 struct softif_neigh *softif_neigh = NULL, *softif_neigh_tmp;
284 struct hard_iface *primary_if = NULL;
285 struct hlist_node *node;
287 primary_if = primary_if_get_selected(bat_priv);
291 /* find new softif_neigh immediately to avoid temporary loops */
293 curr_neigh = rcu_dereference(softif_neigh_vid->softif_neigh);
295 hlist_for_each_entry_rcu(softif_neigh_tmp, node,
296 &softif_neigh_vid->softif_neigh_list,
298 if (softif_neigh_tmp == curr_neigh)
301 /* we got a neighbor but its mac is 'bigger' than ours */
302 if (memcmp(primary_if->net_dev->dev_addr,
303 softif_neigh_tmp->addr, ETH_ALEN) < 0)
306 if (!atomic_inc_not_zero(&softif_neigh_tmp->refcount))
309 softif_neigh = softif_neigh_tmp;
316 softif_neigh_vid_select(bat_priv, softif_neigh, softif_neigh_vid->vid);
319 hardif_free_ref(primary_if);
321 softif_neigh_free_ref(softif_neigh);
324 int softif_neigh_seq_print_text(struct seq_file *seq, void *offset)
326 struct net_device *net_dev = (struct net_device *)seq->private;
327 struct bat_priv *bat_priv = netdev_priv(net_dev);
328 struct softif_neigh_vid *softif_neigh_vid;
329 struct softif_neigh *softif_neigh;
330 struct hard_iface *primary_if;
331 struct hlist_node *node, *node_tmp;
332 struct softif_neigh *curr_softif_neigh;
333 int ret = 0, last_seen_secs, last_seen_msecs;
335 primary_if = primary_if_get_selected(bat_priv);
337 ret = seq_printf(seq, "BATMAN mesh %s disabled - "
338 "please specify interfaces to enable it\n",
343 if (primary_if->if_status != IF_ACTIVE) {
344 ret = seq_printf(seq, "BATMAN mesh %s "
345 "disabled - primary interface not active\n",
350 seq_printf(seq, "Softif neighbor list (%s)\n", net_dev->name);
353 hlist_for_each_entry_rcu(softif_neigh_vid, node,
354 &bat_priv->softif_neigh_vids, list) {
355 seq_printf(seq, " %-15s %s on vid: %d\n",
356 "Originator", "last-seen", softif_neigh_vid->vid);
358 curr_softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
360 hlist_for_each_entry_rcu(softif_neigh, node_tmp,
361 &softif_neigh_vid->softif_neigh_list,
363 last_seen_secs = jiffies_to_msecs(jiffies -
364 softif_neigh->last_seen) / 1000;
365 last_seen_msecs = jiffies_to_msecs(jiffies -
366 softif_neigh->last_seen) % 1000;
367 seq_printf(seq, "%s %pM %3i.%03is\n",
368 curr_softif_neigh == softif_neigh
369 ? "=>" : " ", softif_neigh->addr,
370 last_seen_secs, last_seen_msecs);
373 if (curr_softif_neigh)
374 softif_neigh_free_ref(curr_softif_neigh);
376 seq_printf(seq, "\n");
382 hardif_free_ref(primary_if);
386 void softif_neigh_purge(struct bat_priv *bat_priv)
388 struct softif_neigh *softif_neigh, *curr_softif_neigh;
389 struct softif_neigh_vid *softif_neigh_vid;
390 struct hlist_node *node, *node_tmp, *node_tmp2;
394 hlist_for_each_entry_rcu(softif_neigh_vid, node,
395 &bat_priv->softif_neigh_vids, list) {
396 if (!atomic_inc_not_zero(&softif_neigh_vid->refcount))
399 curr_softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
402 spin_lock_bh(&bat_priv->softif_neigh_lock);
403 hlist_for_each_entry_safe(softif_neigh, node_tmp, node_tmp2,
404 &softif_neigh_vid->softif_neigh_list,
406 if ((!time_after(jiffies, softif_neigh->last_seen +
407 msecs_to_jiffies(SOFTIF_NEIGH_TIMEOUT))) &&
408 (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE))
411 if (curr_softif_neigh == softif_neigh) {
412 bat_dbg(DBG_ROUTES, bat_priv,
413 "Current mesh exit point on vid: %d "
415 softif_neigh_vid->vid,
420 hlist_del_rcu(&softif_neigh->list);
421 softif_neigh_free_ref(softif_neigh);
423 spin_unlock_bh(&bat_priv->softif_neigh_lock);
425 /* soft_neigh_vid_deselect() needs to acquire the
426 * softif_neigh_lock */
428 softif_neigh_vid_deselect(bat_priv, softif_neigh_vid);
430 if (curr_softif_neigh)
431 softif_neigh_free_ref(curr_softif_neigh);
433 softif_neigh_vid_free_ref(softif_neigh_vid);
437 spin_lock_bh(&bat_priv->softif_neigh_vid_lock);
438 hlist_for_each_entry_safe(softif_neigh_vid, node, node_tmp,
439 &bat_priv->softif_neigh_vids, list) {
440 if (!hlist_empty(&softif_neigh_vid->softif_neigh_list))
443 hlist_del_rcu(&softif_neigh_vid->list);
444 softif_neigh_vid_free_ref(softif_neigh_vid);
446 spin_unlock_bh(&bat_priv->softif_neigh_vid_lock);
450 static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev,
453 struct bat_priv *bat_priv = netdev_priv(dev);
454 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
455 struct batman_packet *batman_packet;
456 struct softif_neigh *softif_neigh = NULL;
457 struct hard_iface *primary_if = NULL;
458 struct softif_neigh *curr_softif_neigh = NULL;
460 if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
461 batman_packet = (struct batman_packet *)
462 (skb->data + ETH_HLEN + VLAN_HLEN);
464 batman_packet = (struct batman_packet *)(skb->data + ETH_HLEN);
466 if (batman_packet->version != COMPAT_VERSION)
469 if (batman_packet->packet_type != BAT_PACKET)
472 if (!(batman_packet->flags & PRIMARIES_FIRST_HOP))
475 if (is_my_mac(batman_packet->orig))
478 softif_neigh = softif_neigh_get(bat_priv, batman_packet->orig, vid);
482 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
483 if (curr_softif_neigh == softif_neigh)
486 primary_if = primary_if_get_selected(bat_priv);
490 /* we got a neighbor but its mac is 'bigger' than ours */
491 if (memcmp(primary_if->net_dev->dev_addr,
492 softif_neigh->addr, ETH_ALEN) < 0)
495 /* close own batX device and use softif_neigh as exit node */
496 if (!curr_softif_neigh) {
497 softif_neigh_vid_select(bat_priv, softif_neigh, vid);
501 /* switch to new 'smallest neighbor' */
502 if (memcmp(softif_neigh->addr, curr_softif_neigh->addr, ETH_ALEN) < 0)
503 softif_neigh_vid_select(bat_priv, softif_neigh, vid);
508 softif_neigh_free_ref(softif_neigh);
509 if (curr_softif_neigh)
510 softif_neigh_free_ref(curr_softif_neigh);
512 hardif_free_ref(primary_if);
516 static int interface_open(struct net_device *dev)
518 netif_start_queue(dev);
522 static int interface_release(struct net_device *dev)
524 netif_stop_queue(dev);
528 static struct net_device_stats *interface_stats(struct net_device *dev)
530 struct bat_priv *bat_priv = netdev_priv(dev);
531 return &bat_priv->stats;
534 static int interface_set_mac_addr(struct net_device *dev, void *p)
536 struct bat_priv *bat_priv = netdev_priv(dev);
537 struct sockaddr *addr = p;
539 if (!is_valid_ether_addr(addr->sa_data))
540 return -EADDRNOTAVAIL;
542 /* only modify transtable if it has been initialised before */
543 if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
544 tt_local_remove(bat_priv, dev->dev_addr,
545 "mac address changed");
546 tt_local_add(dev, addr->sa_data);
549 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
553 static int interface_change_mtu(struct net_device *dev, int new_mtu)
556 if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev)))
564 int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
566 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
567 struct bat_priv *bat_priv = netdev_priv(soft_iface);
568 struct hard_iface *primary_if = NULL;
569 struct bcast_packet *bcast_packet;
570 struct vlan_ethhdr *vhdr;
571 struct softif_neigh *curr_softif_neigh = NULL;
572 int data_len = skb->len, ret;
574 bool do_bcast = false;
576 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
579 soft_iface->trans_start = jiffies;
581 switch (ntohs(ethhdr->h_proto)) {
583 vhdr = (struct vlan_ethhdr *)skb->data;
584 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
586 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
591 softif_batman_recv(skb, soft_iface, vid);
596 * if we have a another chosen mesh exit node in range
597 * it will transport the packets to the mesh
599 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
600 if (curr_softif_neigh)
603 /* TODO: check this for locks */
604 tt_local_add(soft_iface, ethhdr->h_source);
606 if (is_multicast_ether_addr(ethhdr->h_dest)) {
607 ret = gw_is_target(bat_priv, skb);
616 /* ethernet packet should be broadcasted */
618 primary_if = primary_if_get_selected(bat_priv);
622 if (my_skb_head_push(skb, sizeof(struct bcast_packet)) < 0)
625 bcast_packet = (struct bcast_packet *)skb->data;
626 bcast_packet->version = COMPAT_VERSION;
627 bcast_packet->ttl = TTL;
629 /* batman packet type: broadcast */
630 bcast_packet->packet_type = BAT_BCAST;
632 /* hw address of first interface is the orig mac because only
633 * this mac is known throughout the mesh */
634 memcpy(bcast_packet->orig,
635 primary_if->net_dev->dev_addr, ETH_ALEN);
637 /* set broadcast sequence number */
638 bcast_packet->seqno =
639 htonl(atomic_inc_return(&bat_priv->bcast_seqno));
641 add_bcast_packet_to_list(bat_priv, skb);
643 /* a copy is stored in the bcast list, therefore removing
644 * the original skb. */
649 ret = unicast_send_skb(skb, bat_priv);
654 bat_priv->stats.tx_packets++;
655 bat_priv->stats.tx_bytes += data_len;
661 bat_priv->stats.tx_dropped++;
663 if (curr_softif_neigh)
664 softif_neigh_free_ref(curr_softif_neigh);
666 hardif_free_ref(primary_if);
670 void interface_rx(struct net_device *soft_iface,
671 struct sk_buff *skb, struct hard_iface *recv_if,
674 struct bat_priv *bat_priv = netdev_priv(soft_iface);
675 struct unicast_packet *unicast_packet;
676 struct ethhdr *ethhdr;
677 struct vlan_ethhdr *vhdr;
678 struct softif_neigh *curr_softif_neigh = NULL;
682 /* check if enough space is available for pulling, and pull */
683 if (!pskb_may_pull(skb, hdr_size))
686 skb_pull_rcsum(skb, hdr_size);
687 skb_reset_mac_header(skb);
689 ethhdr = (struct ethhdr *)skb_mac_header(skb);
691 switch (ntohs(ethhdr->h_proto)) {
693 vhdr = (struct vlan_ethhdr *)skb->data;
694 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
696 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
705 * if we have a another chosen mesh exit node in range
706 * it will transport the packets to the non-mesh network
708 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
709 if (curr_softif_neigh) {
710 skb_push(skb, hdr_size);
711 unicast_packet = (struct unicast_packet *)skb->data;
713 if ((unicast_packet->packet_type != BAT_UNICAST) &&
714 (unicast_packet->packet_type != BAT_UNICAST_FRAG))
717 skb_reset_mac_header(skb);
719 memcpy(unicast_packet->dest,
720 curr_softif_neigh->addr, ETH_ALEN);
721 ret = route_unicast_packet(skb, recv_if);
722 if (ret == NET_RX_DROP)
728 /* skb->dev & skb->pkt_type are set here */
729 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
731 skb->protocol = eth_type_trans(skb, soft_iface);
733 /* should not be necessary anymore as we use skb_pull_rcsum()
734 * TODO: please verify this and remove this TODO
735 * -- Dec 21st 2009, Simon Wunderlich */
737 /* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
739 bat_priv->stats.rx_packets++;
740 bat_priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr);
742 soft_iface->last_rx = jiffies;
750 if (curr_softif_neigh)
751 softif_neigh_free_ref(curr_softif_neigh);
755 #ifdef HAVE_NET_DEVICE_OPS
756 static const struct net_device_ops bat_netdev_ops = {
757 .ndo_open = interface_open,
758 .ndo_stop = interface_release,
759 .ndo_get_stats = interface_stats,
760 .ndo_set_mac_address = interface_set_mac_addr,
761 .ndo_change_mtu = interface_change_mtu,
762 .ndo_start_xmit = interface_tx,
763 .ndo_validate_addr = eth_validate_addr
767 static void interface_setup(struct net_device *dev)
769 struct bat_priv *priv = netdev_priv(dev);
770 char dev_addr[ETH_ALEN];
774 #ifdef HAVE_NET_DEVICE_OPS
775 dev->netdev_ops = &bat_netdev_ops;
777 dev->open = interface_open;
778 dev->stop = interface_release;
779 dev->get_stats = interface_stats;
780 dev->set_mac_address = interface_set_mac_addr;
781 dev->change_mtu = interface_change_mtu;
782 dev->hard_start_xmit = interface_tx;
784 dev->destructor = free_netdev;
785 dev->tx_queue_len = 0;
788 * can't call min_mtu, because the needed variables
789 * have not been initialized yet
791 dev->mtu = ETH_DATA_LEN;
792 /* reserve more space in the skbuff for our header */
793 dev->hard_header_len = BAT_HEADER_LEN;
795 /* generate random address */
796 random_ether_addr(dev_addr);
797 memcpy(dev->dev_addr, dev_addr, ETH_ALEN);
799 SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);
801 memset(priv, 0, sizeof(struct bat_priv));
804 struct net_device *softif_create(char *name)
806 struct net_device *soft_iface;
807 struct bat_priv *bat_priv;
810 soft_iface = alloc_netdev(sizeof(struct bat_priv) , name,
814 pr_err("Unable to allocate the batman interface: %s\n", name);
818 ret = register_netdevice(soft_iface);
820 pr_err("Unable to register the batman interface '%s': %i\n",
822 goto free_soft_iface;
825 bat_priv = netdev_priv(soft_iface);
827 atomic_set(&bat_priv->aggregated_ogms, 1);
828 atomic_set(&bat_priv->bonding, 0);
829 atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
830 atomic_set(&bat_priv->gw_mode, GW_MODE_OFF);
831 atomic_set(&bat_priv->gw_sel_class, 20);
832 atomic_set(&bat_priv->gw_bandwidth, 41);
833 atomic_set(&bat_priv->orig_interval, 1000);
834 atomic_set(&bat_priv->hop_penalty, 10);
835 atomic_set(&bat_priv->log_level, 0);
836 atomic_set(&bat_priv->fragmentation, 1);
837 atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
838 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
840 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
841 atomic_set(&bat_priv->bcast_seqno, 1);
842 atomic_set(&bat_priv->tt_local_changed, 0);
844 bat_priv->primary_if = NULL;
845 bat_priv->num_ifaces = 0;
847 ret = sysfs_add_meshif(soft_iface);
849 goto unreg_soft_iface;
851 ret = debugfs_add_meshif(soft_iface);
855 ret = mesh_init(soft_iface);
862 debugfs_del_meshif(soft_iface);
864 sysfs_del_meshif(soft_iface);
866 unregister_netdev(soft_iface);
870 free_netdev(soft_iface);
875 void softif_destroy(struct net_device *soft_iface)
877 debugfs_del_meshif(soft_iface);
878 sysfs_del_meshif(soft_iface);
879 mesh_free(soft_iface);
880 unregister_netdevice(soft_iface);
883 int softif_is_valid(struct net_device *net_dev)
885 #ifdef HAVE_NET_DEVICE_OPS
886 if (net_dev->netdev_ops->ndo_start_xmit == interface_tx)
889 if (net_dev->hard_start_xmit == interface_tx)
897 static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
900 cmd->advertising = 0;
901 ethtool_cmd_speed_set(cmd, SPEED_10);
902 cmd->duplex = DUPLEX_FULL;
904 cmd->phy_address = 0;
905 cmd->transceiver = XCVR_INTERNAL;
906 cmd->autoneg = AUTONEG_DISABLE;
913 static void bat_get_drvinfo(struct net_device *dev,
914 struct ethtool_drvinfo *info)
916 strcpy(info->driver, "B.A.T.M.A.N. advanced");
917 strcpy(info->version, SOURCE_VERSION);
918 strcpy(info->fw_version, "N/A");
919 strcpy(info->bus_info, "batman");
922 static u32 bat_get_msglevel(struct net_device *dev)
927 static void bat_set_msglevel(struct net_device *dev, u32 value)
931 static u32 bat_get_link(struct net_device *dev)