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);
46 static u32 bat_get_rx_csum(struct net_device *dev);
47 static int bat_set_rx_csum(struct net_device *dev, u32 data);
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
59 int my_skb_head_push(struct sk_buff *skb, unsigned int len)
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.
71 result = skb_cow_head(skb, len);
79 static void softif_neigh_free_rcu(struct rcu_head *rcu)
81 struct softif_neigh *softif_neigh;
83 softif_neigh = container_of(rcu, struct softif_neigh, rcu);
87 static void softif_neigh_free_ref(struct softif_neigh *softif_neigh)
89 if (atomic_dec_and_test(&softif_neigh->refcount))
90 call_rcu(&softif_neigh->rcu, softif_neigh_free_rcu);
93 static void softif_neigh_vid_free_rcu(struct rcu_head *rcu)
95 struct softif_neigh_vid *softif_neigh_vid;
96 struct softif_neigh *softif_neigh;
97 struct hlist_node *node, *node_tmp;
98 struct bat_priv *bat_priv;
100 softif_neigh_vid = container_of(rcu, struct softif_neigh_vid, rcu);
101 bat_priv = softif_neigh_vid->bat_priv;
103 spin_lock_bh(&bat_priv->softif_neigh_lock);
104 hlist_for_each_entry_safe(softif_neigh, node, node_tmp,
105 &softif_neigh_vid->softif_neigh_list, list) {
106 hlist_del_rcu(&softif_neigh->list);
107 softif_neigh_free_ref(softif_neigh);
109 spin_unlock_bh(&bat_priv->softif_neigh_lock);
111 kfree(softif_neigh_vid);
114 static void softif_neigh_vid_free_ref(struct softif_neigh_vid *softif_neigh_vid)
116 if (atomic_dec_and_test(&softif_neigh_vid->refcount))
117 call_rcu(&softif_neigh_vid->rcu, softif_neigh_vid_free_rcu);
120 static struct softif_neigh_vid *softif_neigh_vid_get(struct bat_priv *bat_priv,
123 struct softif_neigh_vid *softif_neigh_vid;
124 struct hlist_node *node;
127 hlist_for_each_entry_rcu(softif_neigh_vid, node,
128 &bat_priv->softif_neigh_vids, list) {
129 if (softif_neigh_vid->vid != vid)
132 if (!atomic_inc_not_zero(&softif_neigh_vid->refcount))
138 softif_neigh_vid = kzalloc(sizeof(struct softif_neigh_vid),
140 if (!softif_neigh_vid)
143 softif_neigh_vid->vid = vid;
144 softif_neigh_vid->bat_priv = bat_priv;
146 /* initialize with 2 - caller decrements counter by one */
147 atomic_set(&softif_neigh_vid->refcount, 2);
148 INIT_HLIST_HEAD(&softif_neigh_vid->softif_neigh_list);
149 INIT_HLIST_NODE(&softif_neigh_vid->list);
150 spin_lock_bh(&bat_priv->softif_neigh_vid_lock);
151 hlist_add_head_rcu(&softif_neigh_vid->list,
152 &bat_priv->softif_neigh_vids);
153 spin_unlock_bh(&bat_priv->softif_neigh_vid_lock);
157 return softif_neigh_vid;
160 static struct softif_neigh *softif_neigh_get(struct bat_priv *bat_priv,
161 uint8_t *addr, short vid)
163 struct softif_neigh_vid *softif_neigh_vid;
164 struct softif_neigh *softif_neigh = NULL;
165 struct hlist_node *node;
167 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
168 if (!softif_neigh_vid)
172 hlist_for_each_entry_rcu(softif_neigh, node,
173 &softif_neigh_vid->softif_neigh_list,
175 if (!compare_eth(softif_neigh->addr, addr))
178 if (!atomic_inc_not_zero(&softif_neigh->refcount))
181 softif_neigh->last_seen = jiffies;
185 softif_neigh = kzalloc(sizeof(struct softif_neigh), GFP_ATOMIC);
189 memcpy(softif_neigh->addr, addr, ETH_ALEN);
190 softif_neigh->last_seen = jiffies;
191 /* initialize with 2 - caller decrements counter by one */
192 atomic_set(&softif_neigh->refcount, 2);
194 INIT_HLIST_NODE(&softif_neigh->list);
195 spin_lock_bh(&bat_priv->softif_neigh_lock);
196 hlist_add_head_rcu(&softif_neigh->list,
197 &softif_neigh_vid->softif_neigh_list);
198 spin_unlock_bh(&bat_priv->softif_neigh_lock);
203 if (softif_neigh_vid)
204 softif_neigh_vid_free_ref(softif_neigh_vid);
208 static struct softif_neigh *softif_neigh_get_selected(
209 struct softif_neigh_vid *softif_neigh_vid)
211 struct softif_neigh *softif_neigh;
214 softif_neigh = rcu_dereference(softif_neigh_vid->softif_neigh);
216 if (softif_neigh && !atomic_inc_not_zero(&softif_neigh->refcount))
223 static struct softif_neigh *softif_neigh_vid_get_selected(
224 struct bat_priv *bat_priv,
227 struct softif_neigh_vid *softif_neigh_vid;
228 struct softif_neigh *softif_neigh = NULL;
230 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
231 if (!softif_neigh_vid)
234 softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
236 if (softif_neigh_vid)
237 softif_neigh_vid_free_ref(softif_neigh_vid);
241 static void softif_neigh_vid_select(struct bat_priv *bat_priv,
242 struct softif_neigh *new_neigh,
245 struct softif_neigh_vid *softif_neigh_vid;
246 struct softif_neigh *curr_neigh;
248 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
249 if (!softif_neigh_vid)
252 spin_lock_bh(&bat_priv->softif_neigh_lock);
254 if (new_neigh && !atomic_inc_not_zero(&new_neigh->refcount))
257 curr_neigh = softif_neigh_vid->softif_neigh;
258 rcu_assign_pointer(softif_neigh_vid->softif_neigh, new_neigh);
260 if ((curr_neigh) && (!new_neigh))
261 bat_dbg(DBG_ROUTES, bat_priv,
262 "Removing mesh exit point on vid: %d (prev: %pM).\n",
263 vid, curr_neigh->addr);
264 else if ((curr_neigh) && (new_neigh))
265 bat_dbg(DBG_ROUTES, bat_priv,
266 "Changing mesh exit point on vid: %d from %pM "
267 "to %pM.\n", vid, curr_neigh->addr, new_neigh->addr);
268 else if ((!curr_neigh) && (new_neigh))
269 bat_dbg(DBG_ROUTES, bat_priv,
270 "Setting mesh exit point on vid: %d to %pM.\n",
271 vid, new_neigh->addr);
274 softif_neigh_free_ref(curr_neigh);
276 spin_unlock_bh(&bat_priv->softif_neigh_lock);
279 if (softif_neigh_vid)
280 softif_neigh_vid_free_ref(softif_neigh_vid);
283 static void softif_neigh_vid_deselect(struct bat_priv *bat_priv,
284 struct softif_neigh_vid *softif_neigh_vid)
286 struct softif_neigh *curr_neigh;
287 struct softif_neigh *softif_neigh = NULL, *softif_neigh_tmp;
288 struct hard_iface *primary_if = NULL;
289 struct hlist_node *node;
291 primary_if = primary_if_get_selected(bat_priv);
295 /* find new softif_neigh immediately to avoid temporary loops */
297 curr_neigh = rcu_dereference(softif_neigh_vid->softif_neigh);
299 hlist_for_each_entry_rcu(softif_neigh_tmp, node,
300 &softif_neigh_vid->softif_neigh_list,
302 if (softif_neigh_tmp == curr_neigh)
305 /* we got a neighbor but its mac is 'bigger' than ours */
306 if (memcmp(primary_if->net_dev->dev_addr,
307 softif_neigh_tmp->addr, ETH_ALEN) < 0)
310 if (!atomic_inc_not_zero(&softif_neigh_tmp->refcount))
313 softif_neigh = softif_neigh_tmp;
320 softif_neigh_vid_select(bat_priv, softif_neigh, softif_neigh_vid->vid);
323 hardif_free_ref(primary_if);
325 softif_neigh_free_ref(softif_neigh);
328 int softif_neigh_seq_print_text(struct seq_file *seq, void *offset)
330 struct net_device *net_dev = (struct net_device *)seq->private;
331 struct bat_priv *bat_priv = netdev_priv(net_dev);
332 struct softif_neigh_vid *softif_neigh_vid;
333 struct softif_neigh *softif_neigh;
334 struct hard_iface *primary_if;
335 struct hlist_node *node, *node_tmp;
336 struct softif_neigh *curr_softif_neigh;
337 int ret = 0, last_seen_secs, last_seen_msecs;
339 primary_if = primary_if_get_selected(bat_priv);
341 ret = seq_printf(seq, "BATMAN mesh %s disabled - "
342 "please specify interfaces to enable it\n",
347 if (primary_if->if_status != IF_ACTIVE) {
348 ret = seq_printf(seq, "BATMAN mesh %s "
349 "disabled - primary interface not active\n",
354 seq_printf(seq, "Softif neighbor list (%s)\n", net_dev->name);
357 hlist_for_each_entry_rcu(softif_neigh_vid, node,
358 &bat_priv->softif_neigh_vids, list) {
359 seq_printf(seq, " %-15s %s on vid: %d\n",
360 "Originator", "last-seen", softif_neigh_vid->vid);
362 curr_softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
364 hlist_for_each_entry_rcu(softif_neigh, node_tmp,
365 &softif_neigh_vid->softif_neigh_list,
367 last_seen_secs = jiffies_to_msecs(jiffies -
368 softif_neigh->last_seen) / 1000;
369 last_seen_msecs = jiffies_to_msecs(jiffies -
370 softif_neigh->last_seen) % 1000;
371 seq_printf(seq, "%s %pM %3i.%03is\n",
372 curr_softif_neigh == softif_neigh
373 ? "=>" : " ", softif_neigh->addr,
374 last_seen_secs, last_seen_msecs);
377 if (curr_softif_neigh)
378 softif_neigh_free_ref(curr_softif_neigh);
380 seq_printf(seq, "\n");
386 hardif_free_ref(primary_if);
390 void softif_neigh_purge(struct bat_priv *bat_priv)
392 struct softif_neigh *softif_neigh, *curr_softif_neigh;
393 struct softif_neigh_vid *softif_neigh_vid;
394 struct hlist_node *node, *node_tmp, *node_tmp2;
398 hlist_for_each_entry_rcu(softif_neigh_vid, node,
399 &bat_priv->softif_neigh_vids, list) {
400 if (!atomic_inc_not_zero(&softif_neigh_vid->refcount))
403 curr_softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
406 spin_lock_bh(&bat_priv->softif_neigh_lock);
407 hlist_for_each_entry_safe(softif_neigh, node_tmp, node_tmp2,
408 &softif_neigh_vid->softif_neigh_list,
410 if ((!time_after(jiffies, softif_neigh->last_seen +
411 msecs_to_jiffies(SOFTIF_NEIGH_TIMEOUT))) &&
412 (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE))
415 if (curr_softif_neigh == softif_neigh) {
416 bat_dbg(DBG_ROUTES, bat_priv,
417 "Current mesh exit point on vid: %d "
419 softif_neigh_vid->vid,
424 hlist_del_rcu(&softif_neigh->list);
425 softif_neigh_free_ref(softif_neigh);
427 spin_unlock_bh(&bat_priv->softif_neigh_lock);
429 /* soft_neigh_vid_deselect() needs to acquire the
430 * softif_neigh_lock */
432 softif_neigh_vid_deselect(bat_priv, softif_neigh_vid);
434 if (curr_softif_neigh)
435 softif_neigh_free_ref(curr_softif_neigh);
437 softif_neigh_vid_free_ref(softif_neigh_vid);
441 spin_lock_bh(&bat_priv->softif_neigh_vid_lock);
442 hlist_for_each_entry_safe(softif_neigh_vid, node, node_tmp,
443 &bat_priv->softif_neigh_vids, list) {
444 if (!hlist_empty(&softif_neigh_vid->softif_neigh_list))
447 hlist_del_rcu(&softif_neigh_vid->list);
448 softif_neigh_vid_free_ref(softif_neigh_vid);
450 spin_unlock_bh(&bat_priv->softif_neigh_vid_lock);
454 static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev,
457 struct bat_priv *bat_priv = netdev_priv(dev);
458 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
459 struct batman_packet *batman_packet;
460 struct softif_neigh *softif_neigh = NULL;
461 struct hard_iface *primary_if = NULL;
462 struct softif_neigh *curr_softif_neigh = NULL;
464 if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
465 batman_packet = (struct batman_packet *)
466 (skb->data + ETH_HLEN + VLAN_HLEN);
468 batman_packet = (struct batman_packet *)(skb->data + ETH_HLEN);
470 if (batman_packet->version != COMPAT_VERSION)
473 if (batman_packet->packet_type != BAT_PACKET)
476 if (!(batman_packet->flags & PRIMARIES_FIRST_HOP))
479 if (is_my_mac(batman_packet->orig))
482 softif_neigh = softif_neigh_get(bat_priv, batman_packet->orig, vid);
486 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
487 if (curr_softif_neigh == softif_neigh)
490 primary_if = primary_if_get_selected(bat_priv);
494 /* we got a neighbor but its mac is 'bigger' than ours */
495 if (memcmp(primary_if->net_dev->dev_addr,
496 softif_neigh->addr, ETH_ALEN) < 0)
499 /* close own batX device and use softif_neigh as exit node */
500 if (!curr_softif_neigh) {
501 softif_neigh_vid_select(bat_priv, softif_neigh, vid);
505 /* switch to new 'smallest neighbor' */
506 if (memcmp(softif_neigh->addr, curr_softif_neigh->addr, ETH_ALEN) < 0)
507 softif_neigh_vid_select(bat_priv, softif_neigh, vid);
512 softif_neigh_free_ref(softif_neigh);
513 if (curr_softif_neigh)
514 softif_neigh_free_ref(curr_softif_neigh);
516 hardif_free_ref(primary_if);
520 static int interface_open(struct net_device *dev)
522 netif_start_queue(dev);
526 static int interface_release(struct net_device *dev)
528 netif_stop_queue(dev);
532 static struct net_device_stats *interface_stats(struct net_device *dev)
534 struct bat_priv *bat_priv = netdev_priv(dev);
535 return &bat_priv->stats;
538 static int interface_set_mac_addr(struct net_device *dev, void *p)
540 struct bat_priv *bat_priv = netdev_priv(dev);
541 struct sockaddr *addr = p;
543 if (!is_valid_ether_addr(addr->sa_data))
544 return -EADDRNOTAVAIL;
546 /* only modify hna-table if it has been initialised before */
547 if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
548 hna_local_remove(bat_priv, dev->dev_addr,
549 "mac address changed");
550 hna_local_add(dev, addr->sa_data);
553 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
557 static int interface_change_mtu(struct net_device *dev, int new_mtu)
560 if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev)))
568 int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
570 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
571 struct bat_priv *bat_priv = netdev_priv(soft_iface);
572 struct hard_iface *primary_if = NULL;
573 struct bcast_packet *bcast_packet;
574 struct vlan_ethhdr *vhdr;
575 struct softif_neigh *curr_softif_neigh = NULL;
576 int data_len = skb->len, ret;
578 bool do_bcast = false;
580 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
583 soft_iface->trans_start = jiffies;
585 switch (ntohs(ethhdr->h_proto)) {
587 vhdr = (struct vlan_ethhdr *)skb->data;
588 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
590 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
595 softif_batman_recv(skb, soft_iface, vid);
600 * if we have a another chosen mesh exit node in range
601 * it will transport the packets to the mesh
603 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
604 if (curr_softif_neigh)
607 /* TODO: check this for locks */
608 hna_local_add(soft_iface, ethhdr->h_source);
610 if (is_multicast_ether_addr(ethhdr->h_dest)) {
611 ret = gw_is_target(bat_priv, skb);
620 /* ethernet packet should be broadcasted */
622 primary_if = primary_if_get_selected(bat_priv);
626 if (my_skb_head_push(skb, sizeof(struct bcast_packet)) < 0)
629 bcast_packet = (struct bcast_packet *)skb->data;
630 bcast_packet->version = COMPAT_VERSION;
631 bcast_packet->ttl = TTL;
633 /* batman packet type: broadcast */
634 bcast_packet->packet_type = BAT_BCAST;
636 /* hw address of first interface is the orig mac because only
637 * this mac is known throughout the mesh */
638 memcpy(bcast_packet->orig,
639 primary_if->net_dev->dev_addr, ETH_ALEN);
641 /* set broadcast sequence number */
642 bcast_packet->seqno =
643 htonl(atomic_inc_return(&bat_priv->bcast_seqno));
645 add_bcast_packet_to_list(bat_priv, skb);
647 /* a copy is stored in the bcast list, therefore removing
648 * the original skb. */
653 ret = unicast_send_skb(skb, bat_priv);
658 bat_priv->stats.tx_packets++;
659 bat_priv->stats.tx_bytes += data_len;
665 bat_priv->stats.tx_dropped++;
667 if (curr_softif_neigh)
668 softif_neigh_free_ref(curr_softif_neigh);
670 hardif_free_ref(primary_if);
674 void interface_rx(struct net_device *soft_iface,
675 struct sk_buff *skb, struct hard_iface *recv_if,
678 struct bat_priv *bat_priv = netdev_priv(soft_iface);
679 struct unicast_packet *unicast_packet;
680 struct ethhdr *ethhdr;
681 struct vlan_ethhdr *vhdr;
682 struct softif_neigh *curr_softif_neigh = NULL;
686 /* check if enough space is available for pulling, and pull */
687 if (!pskb_may_pull(skb, hdr_size))
690 skb_pull_rcsum(skb, hdr_size);
691 skb_reset_mac_header(skb);
693 ethhdr = (struct ethhdr *)skb_mac_header(skb);
695 switch (ntohs(ethhdr->h_proto)) {
697 vhdr = (struct vlan_ethhdr *)skb->data;
698 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
700 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
709 * if we have a another chosen mesh exit node in range
710 * it will transport the packets to the non-mesh network
712 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
713 if (curr_softif_neigh) {
714 skb_push(skb, hdr_size);
715 unicast_packet = (struct unicast_packet *)skb->data;
717 if ((unicast_packet->packet_type != BAT_UNICAST) &&
718 (unicast_packet->packet_type != BAT_UNICAST_FRAG))
721 skb_reset_mac_header(skb);
723 memcpy(unicast_packet->dest,
724 curr_softif_neigh->addr, ETH_ALEN);
725 ret = route_unicast_packet(skb, recv_if);
726 if (ret == NET_RX_DROP)
732 /* skb->dev & skb->pkt_type are set here */
733 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
735 skb->protocol = eth_type_trans(skb, soft_iface);
737 /* should not be neccesary anymore as we use skb_pull_rcsum()
738 * TODO: please verify this and remove this TODO
739 * -- Dec 21st 2009, Simon Wunderlich */
741 /* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
743 bat_priv->stats.rx_packets++;
744 bat_priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr);
746 soft_iface->last_rx = jiffies;
754 if (curr_softif_neigh)
755 softif_neigh_free_ref(curr_softif_neigh);
759 #ifdef HAVE_NET_DEVICE_OPS
760 static const struct net_device_ops bat_netdev_ops = {
761 .ndo_open = interface_open,
762 .ndo_stop = interface_release,
763 .ndo_get_stats = interface_stats,
764 .ndo_set_mac_address = interface_set_mac_addr,
765 .ndo_change_mtu = interface_change_mtu,
766 .ndo_start_xmit = interface_tx,
767 .ndo_validate_addr = eth_validate_addr
771 static void interface_setup(struct net_device *dev)
773 struct bat_priv *priv = netdev_priv(dev);
774 char dev_addr[ETH_ALEN];
778 #ifdef HAVE_NET_DEVICE_OPS
779 dev->netdev_ops = &bat_netdev_ops;
781 dev->open = interface_open;
782 dev->stop = interface_release;
783 dev->get_stats = interface_stats;
784 dev->set_mac_address = interface_set_mac_addr;
785 dev->change_mtu = interface_change_mtu;
786 dev->hard_start_xmit = interface_tx;
788 dev->destructor = free_netdev;
789 dev->tx_queue_len = 0;
792 * can't call min_mtu, because the needed variables
793 * have not been initialized yet
795 dev->mtu = ETH_DATA_LEN;
796 dev->hard_header_len = BAT_HEADER_LEN; /* reserve more space in the
797 * skbuff for our header */
799 /* generate random address */
800 random_ether_addr(dev_addr);
801 memcpy(dev->dev_addr, dev_addr, ETH_ALEN);
803 SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);
805 memset(priv, 0, sizeof(struct bat_priv));
808 struct net_device *softif_create(char *name)
810 struct net_device *soft_iface;
811 struct bat_priv *bat_priv;
814 soft_iface = alloc_netdev(sizeof(struct bat_priv) , name,
818 pr_err("Unable to allocate the batman interface: %s\n", name);
822 ret = register_netdevice(soft_iface);
824 pr_err("Unable to register the batman interface '%s': %i\n",
826 goto free_soft_iface;
829 bat_priv = netdev_priv(soft_iface);
831 atomic_set(&bat_priv->aggregated_ogms, 1);
832 atomic_set(&bat_priv->bonding, 0);
833 atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
834 atomic_set(&bat_priv->gw_mode, GW_MODE_OFF);
835 atomic_set(&bat_priv->gw_sel_class, 20);
836 atomic_set(&bat_priv->gw_bandwidth, 41);
837 atomic_set(&bat_priv->orig_interval, 1000);
838 atomic_set(&bat_priv->hop_penalty, 10);
839 atomic_set(&bat_priv->log_level, 0);
840 atomic_set(&bat_priv->fragmentation, 1);
841 atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
842 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
844 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
845 atomic_set(&bat_priv->bcast_seqno, 1);
846 atomic_set(&bat_priv->hna_local_changed, 0);
848 bat_priv->primary_if = NULL;
849 bat_priv->num_ifaces = 0;
851 ret = sysfs_add_meshif(soft_iface);
853 goto unreg_soft_iface;
855 ret = debugfs_add_meshif(soft_iface);
859 ret = mesh_init(soft_iface);
866 debugfs_del_meshif(soft_iface);
868 sysfs_del_meshif(soft_iface);
870 unregister_netdev(soft_iface);
874 free_netdev(soft_iface);
879 void softif_destroy(struct net_device *soft_iface)
881 debugfs_del_meshif(soft_iface);
882 sysfs_del_meshif(soft_iface);
883 mesh_free(soft_iface);
884 unregister_netdevice(soft_iface);
887 int softif_is_valid(struct net_device *net_dev)
889 #ifdef HAVE_NET_DEVICE_OPS
890 if (net_dev->netdev_ops->ndo_start_xmit == interface_tx)
893 if (net_dev->hard_start_xmit == interface_tx)
901 static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
904 cmd->advertising = 0;
905 cmd->speed = SPEED_10;
906 cmd->duplex = DUPLEX_FULL;
908 cmd->phy_address = 0;
909 cmd->transceiver = XCVR_INTERNAL;
910 cmd->autoneg = AUTONEG_DISABLE;
917 static void bat_get_drvinfo(struct net_device *dev,
918 struct ethtool_drvinfo *info)
920 strcpy(info->driver, "B.A.T.M.A.N. advanced");
921 strcpy(info->version, SOURCE_VERSION);
922 strcpy(info->fw_version, "N/A");
923 strcpy(info->bus_info, "batman");
926 static u32 bat_get_msglevel(struct net_device *dev)
931 static void bat_set_msglevel(struct net_device *dev, u32 value)
935 static u32 bat_get_link(struct net_device *dev)
940 static u32 bat_get_rx_csum(struct net_device *dev)
945 static int bat_set_rx_csum(struct net_device *dev, u32 data)