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 "originator.h"
34 #include <linux/slab.h>
35 #include <linux/ethtool.h>
36 #include <linux/etherdevice.h>
37 #include <linux/if_vlan.h>
41 static int bat_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
);
42 static void bat_get_drvinfo(struct net_device
*dev
,
43 struct ethtool_drvinfo
*info
);
44 static u32
bat_get_msglevel(struct net_device
*dev
);
45 static void bat_set_msglevel(struct net_device
*dev
, u32 value
);
46 static u32
bat_get_link(struct net_device
*dev
);
48 static const struct ethtool_ops bat_ethtool_ops
= {
49 .get_settings
= bat_get_settings
,
50 .get_drvinfo
= bat_get_drvinfo
,
51 .get_msglevel
= bat_get_msglevel
,
52 .set_msglevel
= bat_set_msglevel
,
53 .get_link
= bat_get_link
,
56 int my_skb_head_push(struct sk_buff
*skb
, unsigned int len
)
61 * TODO: We must check if we can release all references to non-payload
62 * data using skb_header_release in our skbs to allow skb_cow_header to
63 * work optimally. This means that those skbs are not allowed to read
64 * or write any data which is before the current position of skb->data
65 * after that call and thus allow other skbs with the same data buffer
66 * to write freely in that area.
68 result
= skb_cow_head(skb
, len
);
76 static void softif_neigh_free_ref(struct softif_neigh
*softif_neigh
)
78 if (atomic_dec_and_test(&softif_neigh
->refcount
))
79 kfree_rcu(softif_neigh
, rcu
);
82 static void softif_neigh_vid_free_rcu(struct rcu_head
*rcu
)
84 struct softif_neigh_vid
*softif_neigh_vid
;
85 struct softif_neigh
*softif_neigh
;
86 struct hlist_node
*node
, *node_tmp
;
87 struct bat_priv
*bat_priv
;
89 softif_neigh_vid
= container_of(rcu
, struct softif_neigh_vid
, rcu
);
90 bat_priv
= softif_neigh_vid
->bat_priv
;
92 spin_lock_bh(&bat_priv
->softif_neigh_lock
);
93 hlist_for_each_entry_safe(softif_neigh
, node
, node_tmp
,
94 &softif_neigh_vid
->softif_neigh_list
, list
) {
95 hlist_del_rcu(&softif_neigh
->list
);
96 softif_neigh_free_ref(softif_neigh
);
98 spin_unlock_bh(&bat_priv
->softif_neigh_lock
);
100 kfree(softif_neigh_vid
);
103 static void softif_neigh_vid_free_ref(struct softif_neigh_vid
*softif_neigh_vid
)
105 if (atomic_dec_and_test(&softif_neigh_vid
->refcount
))
106 call_rcu(&softif_neigh_vid
->rcu
, softif_neigh_vid_free_rcu
);
109 static struct softif_neigh_vid
*softif_neigh_vid_get(struct bat_priv
*bat_priv
,
112 struct softif_neigh_vid
*softif_neigh_vid
;
113 struct hlist_node
*node
;
116 hlist_for_each_entry_rcu(softif_neigh_vid
, node
,
117 &bat_priv
->softif_neigh_vids
, list
) {
118 if (softif_neigh_vid
->vid
!= vid
)
121 if (!atomic_inc_not_zero(&softif_neigh_vid
->refcount
))
127 softif_neigh_vid
= kzalloc(sizeof(*softif_neigh_vid
), GFP_ATOMIC
);
128 if (!softif_neigh_vid
)
131 softif_neigh_vid
->vid
= vid
;
132 softif_neigh_vid
->bat_priv
= bat_priv
;
134 /* initialize with 2 - caller decrements counter by one */
135 atomic_set(&softif_neigh_vid
->refcount
, 2);
136 INIT_HLIST_HEAD(&softif_neigh_vid
->softif_neigh_list
);
137 INIT_HLIST_NODE(&softif_neigh_vid
->list
);
138 spin_lock_bh(&bat_priv
->softif_neigh_vid_lock
);
139 hlist_add_head_rcu(&softif_neigh_vid
->list
,
140 &bat_priv
->softif_neigh_vids
);
141 spin_unlock_bh(&bat_priv
->softif_neigh_vid_lock
);
145 return softif_neigh_vid
;
148 static struct softif_neigh
*softif_neigh_get(struct bat_priv
*bat_priv
,
149 const uint8_t *addr
, short vid
)
151 struct softif_neigh_vid
*softif_neigh_vid
;
152 struct softif_neigh
*softif_neigh
= NULL
;
153 struct hlist_node
*node
;
155 softif_neigh_vid
= softif_neigh_vid_get(bat_priv
, vid
);
156 if (!softif_neigh_vid
)
160 hlist_for_each_entry_rcu(softif_neigh
, node
,
161 &softif_neigh_vid
->softif_neigh_list
,
163 if (!compare_eth(softif_neigh
->addr
, addr
))
166 if (!atomic_inc_not_zero(&softif_neigh
->refcount
))
169 softif_neigh
->last_seen
= jiffies
;
173 softif_neigh
= kzalloc(sizeof(*softif_neigh
), GFP_ATOMIC
);
177 memcpy(softif_neigh
->addr
, addr
, ETH_ALEN
);
178 softif_neigh
->last_seen
= jiffies
;
179 /* initialize with 2 - caller decrements counter by one */
180 atomic_set(&softif_neigh
->refcount
, 2);
182 INIT_HLIST_NODE(&softif_neigh
->list
);
183 spin_lock_bh(&bat_priv
->softif_neigh_lock
);
184 hlist_add_head_rcu(&softif_neigh
->list
,
185 &softif_neigh_vid
->softif_neigh_list
);
186 spin_unlock_bh(&bat_priv
->softif_neigh_lock
);
191 if (softif_neigh_vid
)
192 softif_neigh_vid_free_ref(softif_neigh_vid
);
196 static struct softif_neigh
*softif_neigh_get_selected(
197 struct softif_neigh_vid
*softif_neigh_vid
)
199 struct softif_neigh
*softif_neigh
;
202 softif_neigh
= rcu_dereference(softif_neigh_vid
->softif_neigh
);
204 if (softif_neigh
&& !atomic_inc_not_zero(&softif_neigh
->refcount
))
211 static struct softif_neigh
*softif_neigh_vid_get_selected(
212 struct bat_priv
*bat_priv
,
215 struct softif_neigh_vid
*softif_neigh_vid
;
216 struct softif_neigh
*softif_neigh
= NULL
;
218 softif_neigh_vid
= softif_neigh_vid_get(bat_priv
, vid
);
219 if (!softif_neigh_vid
)
222 softif_neigh
= softif_neigh_get_selected(softif_neigh_vid
);
224 if (softif_neigh_vid
)
225 softif_neigh_vid_free_ref(softif_neigh_vid
);
229 static void softif_neigh_vid_select(struct bat_priv
*bat_priv
,
230 struct softif_neigh
*new_neigh
,
233 struct softif_neigh_vid
*softif_neigh_vid
;
234 struct softif_neigh
*curr_neigh
;
236 softif_neigh_vid
= softif_neigh_vid_get(bat_priv
, vid
);
237 if (!softif_neigh_vid
)
240 spin_lock_bh(&bat_priv
->softif_neigh_lock
);
242 if (new_neigh
&& !atomic_inc_not_zero(&new_neigh
->refcount
))
245 curr_neigh
= rcu_dereference_protected(softif_neigh_vid
->softif_neigh
,
247 rcu_assign_pointer(softif_neigh_vid
->softif_neigh
, new_neigh
);
249 if ((curr_neigh
) && (!new_neigh
))
250 bat_dbg(DBG_ROUTES
, bat_priv
,
251 "Removing mesh exit point on vid: %d (prev: %pM).\n",
252 vid
, curr_neigh
->addr
);
253 else if ((curr_neigh
) && (new_neigh
))
254 bat_dbg(DBG_ROUTES
, bat_priv
,
255 "Changing mesh exit point on vid: %d from %pM "
256 "to %pM.\n", vid
, curr_neigh
->addr
, new_neigh
->addr
);
257 else if ((!curr_neigh
) && (new_neigh
))
258 bat_dbg(DBG_ROUTES
, bat_priv
,
259 "Setting mesh exit point on vid: %d to %pM.\n",
260 vid
, new_neigh
->addr
);
263 softif_neigh_free_ref(curr_neigh
);
265 spin_unlock_bh(&bat_priv
->softif_neigh_lock
);
268 if (softif_neigh_vid
)
269 softif_neigh_vid_free_ref(softif_neigh_vid
);
272 static void softif_neigh_vid_deselect(struct bat_priv
*bat_priv
,
273 struct softif_neigh_vid
*softif_neigh_vid
)
275 struct softif_neigh
*curr_neigh
;
276 struct softif_neigh
*softif_neigh
= NULL
, *softif_neigh_tmp
;
277 struct hard_iface
*primary_if
= NULL
;
278 struct hlist_node
*node
;
280 primary_if
= primary_if_get_selected(bat_priv
);
284 /* find new softif_neigh immediately to avoid temporary loops */
286 curr_neigh
= rcu_dereference(softif_neigh_vid
->softif_neigh
);
288 hlist_for_each_entry_rcu(softif_neigh_tmp
, node
,
289 &softif_neigh_vid
->softif_neigh_list
,
291 if (softif_neigh_tmp
== curr_neigh
)
294 /* we got a neighbor but its mac is 'bigger' than ours */
295 if (memcmp(primary_if
->net_dev
->dev_addr
,
296 softif_neigh_tmp
->addr
, ETH_ALEN
) < 0)
299 if (!atomic_inc_not_zero(&softif_neigh_tmp
->refcount
))
302 softif_neigh
= softif_neigh_tmp
;
309 softif_neigh_vid_select(bat_priv
, softif_neigh
, softif_neigh_vid
->vid
);
312 hardif_free_ref(primary_if
);
314 softif_neigh_free_ref(softif_neigh
);
317 int softif_neigh_seq_print_text(struct seq_file
*seq
, void *offset
)
319 struct net_device
*net_dev
= (struct net_device
*)seq
->private;
320 struct bat_priv
*bat_priv
= netdev_priv(net_dev
);
321 struct softif_neigh_vid
*softif_neigh_vid
;
322 struct softif_neigh
*softif_neigh
;
323 struct hard_iface
*primary_if
;
324 struct hlist_node
*node
, *node_tmp
;
325 struct softif_neigh
*curr_softif_neigh
;
326 int ret
= 0, last_seen_secs
, last_seen_msecs
;
328 primary_if
= primary_if_get_selected(bat_priv
);
330 ret
= seq_printf(seq
, "BATMAN mesh %s disabled - "
331 "please specify interfaces to enable it\n",
336 if (primary_if
->if_status
!= IF_ACTIVE
) {
337 ret
= seq_printf(seq
, "BATMAN mesh %s "
338 "disabled - primary interface not active\n",
343 seq_printf(seq
, "Softif neighbor list (%s)\n", net_dev
->name
);
346 hlist_for_each_entry_rcu(softif_neigh_vid
, node
,
347 &bat_priv
->softif_neigh_vids
, list
) {
348 seq_printf(seq
, " %-15s %s on vid: %d\n",
349 "Originator", "last-seen", softif_neigh_vid
->vid
);
351 curr_softif_neigh
= softif_neigh_get_selected(softif_neigh_vid
);
353 hlist_for_each_entry_rcu(softif_neigh
, node_tmp
,
354 &softif_neigh_vid
->softif_neigh_list
,
356 last_seen_secs
= jiffies_to_msecs(jiffies
-
357 softif_neigh
->last_seen
) / 1000;
358 last_seen_msecs
= jiffies_to_msecs(jiffies
-
359 softif_neigh
->last_seen
) % 1000;
360 seq_printf(seq
, "%s %pM %3i.%03is\n",
361 curr_softif_neigh
== softif_neigh
362 ? "=>" : " ", softif_neigh
->addr
,
363 last_seen_secs
, last_seen_msecs
);
366 if (curr_softif_neigh
)
367 softif_neigh_free_ref(curr_softif_neigh
);
369 seq_printf(seq
, "\n");
375 hardif_free_ref(primary_if
);
379 void softif_neigh_purge(struct bat_priv
*bat_priv
)
381 struct softif_neigh
*softif_neigh
, *curr_softif_neigh
;
382 struct softif_neigh_vid
*softif_neigh_vid
;
383 struct hlist_node
*node
, *node_tmp
, *node_tmp2
;
387 hlist_for_each_entry_rcu(softif_neigh_vid
, node
,
388 &bat_priv
->softif_neigh_vids
, list
) {
389 if (!atomic_inc_not_zero(&softif_neigh_vid
->refcount
))
392 curr_softif_neigh
= softif_neigh_get_selected(softif_neigh_vid
);
395 spin_lock_bh(&bat_priv
->softif_neigh_lock
);
396 hlist_for_each_entry_safe(softif_neigh
, node_tmp
, node_tmp2
,
397 &softif_neigh_vid
->softif_neigh_list
,
399 if ((!time_after(jiffies
, softif_neigh
->last_seen
+
400 msecs_to_jiffies(SOFTIF_NEIGH_TIMEOUT
))) &&
401 (atomic_read(&bat_priv
->mesh_state
) == MESH_ACTIVE
))
404 if (curr_softif_neigh
== softif_neigh
) {
405 bat_dbg(DBG_ROUTES
, bat_priv
,
406 "Current mesh exit point on vid: %d "
408 softif_neigh_vid
->vid
,
413 hlist_del_rcu(&softif_neigh
->list
);
414 softif_neigh_free_ref(softif_neigh
);
416 spin_unlock_bh(&bat_priv
->softif_neigh_lock
);
418 /* soft_neigh_vid_deselect() needs to acquire the
419 * softif_neigh_lock */
421 softif_neigh_vid_deselect(bat_priv
, softif_neigh_vid
);
423 if (curr_softif_neigh
)
424 softif_neigh_free_ref(curr_softif_neigh
);
426 softif_neigh_vid_free_ref(softif_neigh_vid
);
430 spin_lock_bh(&bat_priv
->softif_neigh_vid_lock
);
431 hlist_for_each_entry_safe(softif_neigh_vid
, node
, node_tmp
,
432 &bat_priv
->softif_neigh_vids
, list
) {
433 if (!hlist_empty(&softif_neigh_vid
->softif_neigh_list
))
436 hlist_del_rcu(&softif_neigh_vid
->list
);
437 softif_neigh_vid_free_ref(softif_neigh_vid
);
439 spin_unlock_bh(&bat_priv
->softif_neigh_vid_lock
);
443 static void softif_batman_recv(struct sk_buff
*skb
, struct net_device
*dev
,
446 struct bat_priv
*bat_priv
= netdev_priv(dev
);
447 struct ethhdr
*ethhdr
= (struct ethhdr
*)skb
->data
;
448 struct batman_ogm_packet
*batman_ogm_packet
;
449 struct softif_neigh
*softif_neigh
= NULL
;
450 struct hard_iface
*primary_if
= NULL
;
451 struct softif_neigh
*curr_softif_neigh
= NULL
;
453 if (ntohs(ethhdr
->h_proto
) == ETH_P_8021Q
)
454 batman_ogm_packet
= (struct batman_ogm_packet
*)
455 (skb
->data
+ ETH_HLEN
+ VLAN_HLEN
);
457 batman_ogm_packet
= (struct batman_ogm_packet
*)
458 (skb
->data
+ ETH_HLEN
);
460 if (batman_ogm_packet
->version
!= COMPAT_VERSION
)
463 if (batman_ogm_packet
->packet_type
!= BAT_OGM
)
466 if (!(batman_ogm_packet
->flags
& PRIMARIES_FIRST_HOP
))
469 if (is_my_mac(batman_ogm_packet
->orig
))
472 softif_neigh
= softif_neigh_get(bat_priv
, batman_ogm_packet
->orig
, vid
);
476 curr_softif_neigh
= softif_neigh_vid_get_selected(bat_priv
, vid
);
477 if (curr_softif_neigh
== softif_neigh
)
480 primary_if
= primary_if_get_selected(bat_priv
);
484 /* we got a neighbor but its mac is 'bigger' than ours */
485 if (memcmp(primary_if
->net_dev
->dev_addr
,
486 softif_neigh
->addr
, ETH_ALEN
) < 0)
489 /* close own batX device and use softif_neigh as exit node */
490 if (!curr_softif_neigh
) {
491 softif_neigh_vid_select(bat_priv
, softif_neigh
, vid
);
495 /* switch to new 'smallest neighbor' */
496 if (memcmp(softif_neigh
->addr
, curr_softif_neigh
->addr
, ETH_ALEN
) < 0)
497 softif_neigh_vid_select(bat_priv
, softif_neigh
, vid
);
502 softif_neigh_free_ref(softif_neigh
);
503 if (curr_softif_neigh
)
504 softif_neigh_free_ref(curr_softif_neigh
);
506 hardif_free_ref(primary_if
);
510 static int interface_open(struct net_device
*dev
)
512 netif_start_queue(dev
);
516 static int interface_release(struct net_device
*dev
)
518 netif_stop_queue(dev
);
522 static struct net_device_stats
*interface_stats(struct net_device
*dev
)
524 struct bat_priv
*bat_priv
= netdev_priv(dev
);
525 return &bat_priv
->stats
;
528 static int interface_set_mac_addr(struct net_device
*dev
, void *p
)
530 struct bat_priv
*bat_priv
= netdev_priv(dev
);
531 struct sockaddr
*addr
= p
;
533 if (!is_valid_ether_addr(addr
->sa_data
))
534 return -EADDRNOTAVAIL
;
536 /* only modify transtable if it has been initialized before */
537 if (atomic_read(&bat_priv
->mesh_state
) == MESH_ACTIVE
) {
538 tt_local_remove(bat_priv
, dev
->dev_addr
,
539 "mac address changed", false);
540 tt_local_add(dev
, addr
->sa_data
, NULL_IFINDEX
);
543 memcpy(dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
547 static int interface_change_mtu(struct net_device
*dev
, int new_mtu
)
550 if ((new_mtu
< 68) || (new_mtu
> hardif_min_mtu(dev
)))
558 static int interface_tx(struct sk_buff
*skb
, struct net_device
*soft_iface
)
560 struct ethhdr
*ethhdr
= (struct ethhdr
*)skb
->data
;
561 struct bat_priv
*bat_priv
= netdev_priv(soft_iface
);
562 struct hard_iface
*primary_if
= NULL
;
563 struct bcast_packet
*bcast_packet
;
564 struct vlan_ethhdr
*vhdr
;
565 struct softif_neigh
*curr_softif_neigh
= NULL
;
566 unsigned int header_len
= 0;
567 int data_len
= skb
->len
, ret
;
569 bool do_bcast
= false;
571 if (atomic_read(&bat_priv
->mesh_state
) != MESH_ACTIVE
)
574 soft_iface
->trans_start
= jiffies
;
576 switch (ntohs(ethhdr
->h_proto
)) {
578 vhdr
= (struct vlan_ethhdr
*)skb
->data
;
579 vid
= ntohs(vhdr
->h_vlan_TCI
) & VLAN_VID_MASK
;
581 if (ntohs(vhdr
->h_vlan_encapsulated_proto
) != ETH_P_BATMAN
)
586 softif_batman_recv(skb
, soft_iface
, vid
);
591 * if we have a another chosen mesh exit node in range
592 * it will transport the packets to the mesh
594 curr_softif_neigh
= softif_neigh_vid_get_selected(bat_priv
, vid
);
595 if (curr_softif_neigh
)
598 /* Register the client MAC in the transtable */
599 tt_local_add(soft_iface
, ethhdr
->h_source
, skb
->skb_iif
);
601 if (is_multicast_ether_addr(ethhdr
->h_dest
)) {
604 switch (atomic_read(&bat_priv
->gw_mode
)) {
606 /* gateway servers should not send dhcp
607 * requests into the mesh */
608 ret
= gw_is_dhcp_target(skb
, &header_len
);
613 /* gateway clients should send dhcp requests
614 * via unicast to their gateway */
615 ret
= gw_is_dhcp_target(skb
, &header_len
);
625 /* ethernet packet should be broadcasted */
627 primary_if
= primary_if_get_selected(bat_priv
);
631 if (my_skb_head_push(skb
, sizeof(*bcast_packet
)) < 0)
634 bcast_packet
= (struct bcast_packet
*)skb
->data
;
635 bcast_packet
->version
= COMPAT_VERSION
;
636 bcast_packet
->ttl
= TTL
;
638 /* batman packet type: broadcast */
639 bcast_packet
->packet_type
= BAT_BCAST
;
641 /* hw address of first interface is the orig mac because only
642 * this mac is known throughout the mesh */
643 memcpy(bcast_packet
->orig
,
644 primary_if
->net_dev
->dev_addr
, ETH_ALEN
);
646 /* set broadcast sequence number */
647 bcast_packet
->seqno
=
648 htonl(atomic_inc_return(&bat_priv
->bcast_seqno
));
650 add_bcast_packet_to_list(bat_priv
, skb
, 1);
652 /* a copy is stored in the bcast list, therefore removing
653 * the original skb. */
658 if (atomic_read(&bat_priv
->gw_mode
) != GW_MODE_OFF
) {
659 ret
= gw_out_of_range(bat_priv
, skb
, ethhdr
);
664 ret
= unicast_send_skb(skb
, bat_priv
);
669 bat_priv
->stats
.tx_packets
++;
670 bat_priv
->stats
.tx_bytes
+= data_len
;
676 bat_priv
->stats
.tx_dropped
++;
678 if (curr_softif_neigh
)
679 softif_neigh_free_ref(curr_softif_neigh
);
681 hardif_free_ref(primary_if
);
685 void interface_rx(struct net_device
*soft_iface
,
686 struct sk_buff
*skb
, struct hard_iface
*recv_if
,
689 struct bat_priv
*bat_priv
= netdev_priv(soft_iface
);
690 struct unicast_packet
*unicast_packet
;
691 struct ethhdr
*ethhdr
;
692 struct vlan_ethhdr
*vhdr
;
693 struct softif_neigh
*curr_softif_neigh
= NULL
;
697 /* check if enough space is available for pulling, and pull */
698 if (!pskb_may_pull(skb
, hdr_size
))
701 skb_pull_rcsum(skb
, hdr_size
);
702 skb_reset_mac_header(skb
);
704 ethhdr
= (struct ethhdr
*)skb_mac_header(skb
);
706 switch (ntohs(ethhdr
->h_proto
)) {
708 vhdr
= (struct vlan_ethhdr
*)skb
->data
;
709 vid
= ntohs(vhdr
->h_vlan_TCI
) & VLAN_VID_MASK
;
711 if (ntohs(vhdr
->h_vlan_encapsulated_proto
) != ETH_P_BATMAN
)
720 * if we have a another chosen mesh exit node in range
721 * it will transport the packets to the non-mesh network
723 curr_softif_neigh
= softif_neigh_vid_get_selected(bat_priv
, vid
);
724 if (curr_softif_neigh
) {
725 skb_push(skb
, hdr_size
);
726 unicast_packet
= (struct unicast_packet
*)skb
->data
;
728 if ((unicast_packet
->packet_type
!= BAT_UNICAST
) &&
729 (unicast_packet
->packet_type
!= BAT_UNICAST_FRAG
))
732 skb_reset_mac_header(skb
);
734 memcpy(unicast_packet
->dest
,
735 curr_softif_neigh
->addr
, ETH_ALEN
);
736 ret
= route_unicast_packet(skb
, recv_if
);
737 if (ret
== NET_RX_DROP
)
743 /* skb->dev & skb->pkt_type are set here */
744 if (unlikely(!pskb_may_pull(skb
, ETH_HLEN
)))
746 skb
->protocol
= eth_type_trans(skb
, soft_iface
);
748 /* should not be necessary anymore as we use skb_pull_rcsum()
749 * TODO: please verify this and remove this TODO
750 * -- Dec 21st 2009, Simon Wunderlich */
752 /* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
754 bat_priv
->stats
.rx_packets
++;
755 bat_priv
->stats
.rx_bytes
+= skb
->len
+ sizeof(struct ethhdr
);
757 soft_iface
->last_rx
= jiffies
;
759 if (is_ap_isolated(bat_priv
, ethhdr
->h_source
, ethhdr
->h_dest
))
768 if (curr_softif_neigh
)
769 softif_neigh_free_ref(curr_softif_neigh
);
773 static const struct net_device_ops bat_netdev_ops
= {
774 .ndo_open
= interface_open
,
775 .ndo_stop
= interface_release
,
776 .ndo_get_stats
= interface_stats
,
777 .ndo_set_mac_address
= interface_set_mac_addr
,
778 .ndo_change_mtu
= interface_change_mtu
,
779 .ndo_start_xmit
= interface_tx
,
780 .ndo_validate_addr
= eth_validate_addr
783 static void interface_setup(struct net_device
*dev
)
785 struct bat_priv
*priv
= netdev_priv(dev
);
786 char dev_addr
[ETH_ALEN
];
790 dev
->netdev_ops
= &bat_netdev_ops
;
791 dev
->destructor
= free_netdev
;
792 dev
->tx_queue_len
= 0;
795 * can't call min_mtu, because the needed variables
796 * have not been initialized yet
798 dev
->mtu
= ETH_DATA_LEN
;
799 /* reserve more space in the skbuff for our header */
800 dev
->hard_header_len
= BAT_HEADER_LEN
;
802 /* generate random address */
803 random_ether_addr(dev_addr
);
804 memcpy(dev
->dev_addr
, dev_addr
, ETH_ALEN
);
806 SET_ETHTOOL_OPS(dev
, &bat_ethtool_ops
);
808 memset(priv
, 0, sizeof(*priv
));
811 struct net_device
*softif_create(const char *name
)
813 struct net_device
*soft_iface
;
814 struct bat_priv
*bat_priv
;
817 soft_iface
= alloc_netdev(sizeof(*bat_priv
), name
, interface_setup
);
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
->ap_isolation
, 0);
834 atomic_set(&bat_priv
->vis_mode
, VIS_TYPE_CLIENT_UPDATE
);
835 atomic_set(&bat_priv
->gw_mode
, GW_MODE_OFF
);
836 atomic_set(&bat_priv
->gw_sel_class
, 20);
837 atomic_set(&bat_priv
->gw_bandwidth
, 41);
838 atomic_set(&bat_priv
->orig_interval
, 1000);
839 atomic_set(&bat_priv
->hop_penalty
, 10);
840 atomic_set(&bat_priv
->log_level
, 0);
841 atomic_set(&bat_priv
->fragmentation
, 1);
842 atomic_set(&bat_priv
->bcast_queue_left
, BCAST_QUEUE_LEN
);
843 atomic_set(&bat_priv
->batman_queue_left
, BATMAN_QUEUE_LEN
);
845 atomic_set(&bat_priv
->mesh_state
, MESH_INACTIVE
);
846 atomic_set(&bat_priv
->bcast_seqno
, 1);
847 atomic_set(&bat_priv
->ttvn
, 0);
848 atomic_set(&bat_priv
->tt_local_changes
, 0);
849 atomic_set(&bat_priv
->tt_ogm_append_cnt
, 0);
851 bat_priv
->tt_buff
= NULL
;
852 bat_priv
->tt_buff_len
= 0;
853 bat_priv
->tt_poss_change
= false;
855 bat_priv
->primary_if
= NULL
;
856 bat_priv
->num_ifaces
= 0;
858 ret
= sysfs_add_meshif(soft_iface
);
860 goto unreg_soft_iface
;
862 ret
= debugfs_add_meshif(soft_iface
);
866 ret
= mesh_init(soft_iface
);
873 debugfs_del_meshif(soft_iface
);
875 sysfs_del_meshif(soft_iface
);
877 unregister_netdevice(soft_iface
);
881 free_netdev(soft_iface
);
886 void softif_destroy(struct net_device
*soft_iface
)
888 debugfs_del_meshif(soft_iface
);
889 sysfs_del_meshif(soft_iface
);
890 mesh_free(soft_iface
);
891 unregister_netdevice(soft_iface
);
894 int softif_is_valid(const struct net_device
*net_dev
)
896 if (net_dev
->netdev_ops
->ndo_start_xmit
== interface_tx
)
903 static int bat_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
906 cmd
->advertising
= 0;
907 ethtool_cmd_speed_set(cmd
, SPEED_10
);
908 cmd
->duplex
= DUPLEX_FULL
;
910 cmd
->phy_address
= 0;
911 cmd
->transceiver
= XCVR_INTERNAL
;
912 cmd
->autoneg
= AUTONEG_DISABLE
;
919 static void bat_get_drvinfo(struct net_device
*dev
,
920 struct ethtool_drvinfo
*info
)
922 strcpy(info
->driver
, "B.A.T.M.A.N. advanced");
923 strcpy(info
->version
, SOURCE_VERSION
);
924 strcpy(info
->fw_version
, "N/A");
925 strcpy(info
->bus_info
, "batman");
928 static u32
bat_get_msglevel(struct net_device
*dev
)
933 static void bat_set_msglevel(struct net_device
*dev
, u32 value
)
937 static u32
bat_get_link(struct net_device
*dev
)