net: Add batman-adv meshing protocol
Subsystems (4)
PATCH v4 1/1 net: Add batman-adv meshing protocol
B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is a routing protocol for multi-hop ad-hoc mesh networks. The networks may be wired or wireless. See http://www.open-mesh.org/ for more information and user space tools.
---
batman-adv is a layer2 meshing protocol currently in drivers/staging/batman-adv. GregKH recently [1][2] gave us his blessing to leave the staging tree and move to a more suitable location.
Short functionality overview:
The batman-adv module is an implementation of the B.A.T.M.A.N. routing protocol operating on layer2 optimized for (but not limited to) wireless networks. Next to finding the best possible path through the network it encapsulates the data traffic and optimizes the transport as well. There also is a user space tool "batctl" which offers various functionalities next to a kernel module configuration interface. Detailed documentation can be found at the project homepage[3].
Everything is addressed in the last round of comments [4].
[1] https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-June/002881.html
[2] https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-June/002968.html
[3] http://www.open-mesh.org
[4] https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-July/003138.html
.../ABI/testing/sysfs-class-net-batman-adv | 14 + Documentation/ABI/testing/sysfs-class-net-mesh | 33 + Documentation/networking/batman-adv.txt | 239 ++++ MAINTAINERS | 8 + net/Kconfig | 1 + net/Makefile | 1 + net/batman-adv/Kconfig | 26 + net/batman-adv/Makefile | 22 + net/batman-adv/aggregation.c | 270 ++++ net/batman-adv/aggregation.h | 43 + net/batman-adv/bat_debugfs.c | 341 +++++ net/batman-adv/bat_debugfs.h | 33 + net/batman-adv/bat_sysfs.c | 536 ++++++++ net/batman-adv/bat_sysfs.h | 42 + net/batman-adv/bitarray.c | 201 +++ net/batman-adv/bitarray.h | 47 + net/batman-adv/hard-interface.c | 596 +++++++++ net/batman-adv/hard-interface.h | 45 + net/batman-adv/hash.c | 306 +++++ net/batman-adv/hash.h | 100 ++ net/batman-adv/icmp_socket.c | 356 +++++ net/batman-adv/icmp_socket.h | 34 + net/batman-adv/main.c | 225 ++++ net/batman-adv/main.h | 185 +++ net/batman-adv/originator.c | 539 ++++++++ net/batman-adv/originator.h | 36 + net/batman-adv/packet.h | 134 ++ net/batman-adv/ring_buffer.c | 52 + net/batman-adv/ring_buffer.h | 28 + net/batman-adv/routing.c | 1387 ++++++++++++++++++++ net/batman-adv/routing.h | 46 + net/batman-adv/send.c | 577 ++++++++ net/batman-adv/send.h | 41 + net/batman-adv/soft-interface.c | 395 ++++++ net/batman-adv/soft-interface.h | 32 + net/batman-adv/translation-table.c | 513 ++++++++ net/batman-adv/translation-table.h | 45 + net/batman-adv/types.h | 244 ++++ net/batman-adv/unicast.c | 265 ++++ net/batman-adv/unicast.h | 39 + net/batman-adv/vis.c | 901 +++++++++++++ net/batman-adv/vis.h | 37 + 42 files changed, 9015 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-net-batman-adv create mode 100644 Documentation/ABI/testing/sysfs-class-net-mesh create mode 100644 Documentation/networking/batman-adv.txt create mode 100644 net/batman-adv/Kconfig create mode 100644 net/batman-adv/Makefile create mode 100644 net/batman-adv/aggregation.c create mode 100644 net/batman-adv/aggregation.h create mode 100644 net/batman-adv/bat_debugfs.c create mode 100644 net/batman-adv/bat_debugfs.h create mode 100644 net/batman-adv/bat_sysfs.c create mode 100644 net/batman-adv/bat_sysfs.h create mode 100644 net/batman-adv/bitarray.c create mode 100644 net/batman-adv/bitarray.h create mode 100644 net/batman-adv/hard-interface.c create mode 100644 net/batman-adv/hard-interface.h create mode 100644 net/batman-adv/hash.c create mode 100644 net/batman-adv/hash.h create mode 100644 net/batman-adv/icmp_socket.c create mode 100644 net/batman-adv/icmp_socket.h create mode 100644 net/batman-adv/main.c create mode 100644 net/batman-adv/main.h create mode 100644 net/batman-adv/originator.c create mode 100644 net/batman-adv/originator.h create mode 100644 net/batman-adv/packet.h create mode 100644 net/batman-adv/ring_buffer.c create mode 100644 net/batman-adv/ring_buffer.h create mode 100644 net/batman-adv/routing.c create mode 100644 net/batman-adv/routing.h create mode 100644 net/batman-adv/send.c create mode 100644 net/batman-adv/send.h create mode 100644 net/batman-adv/soft-interface.c create mode 100644 net/batman-adv/soft-interface.h create mode 100644 net/batman-adv/translation-table.c create mode 100644 net/batman-adv/translation-table.h create mode 100644 net/batman-adv/types.h create mode 100644 net/batman-adv/unicast.c create mode 100644 net/batman-adv/unicast.h create mode 100644 net/batman-adv/vis.c create mode 100644 net/batman-adv/vis.h
Documentation/ABI/testing/sysfs-class-net-batman-adv new file +14 -0
@@ -0,0 +1,14 @@ + +What: /sys/class/net/<iface>/batman-adv/mesh_iface +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + The /sys/class/net/<iface>/batman-adv/mesh_iface file + displays the batman mesh interface this <iface> + currently is associated with. + +What: /sys/class/net/<iface>/batman-adv/iface_status +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + Indicates the status of <iface> as it is seen by batman.
Documentation/ABI/testing/sysfs-class-net-mesh new file +33 -0
@@ -0,0 +1,33 @@ + +What: /sys/class/net/<mesh_iface>/mesh/aggregated_ogms +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + Indicates whether the batman protocol messages of the + mesh <mesh_iface> shall be aggregated or not. + +What: /sys/class/net/<mesh_iface>/mesh/bonding +Date: June 2010 +Contact: Simon Wunderlich <[email protected]> +Description: + Indicates whether the data traffic going through the + mesh will be sent using multiple interfaces at the + same time (if available). + +What: /sys/class/net/<mesh_iface>/mesh/orig_interval +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + Defines the interval in milliseconds in which batman + sends its protocol messages. + +What: /sys/class/net/<mesh_iface>/mesh/vis_mode +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + Each batman node only maintains information about its + own local neighborhood, therefore generating graphs + showing the topology of the entire mesh is not easily + feasible without having a central instance to collect + the local topologies from all nodes. This file allows + to activate the collecting (server) mode.
Documentation/networking/batman-adv.txt new file +239 -0
239 lines not on this page · raw message
MAINTAINERS +8 -0
@@ -1262,6 +1262,14 @@ S: Maintained F: drivers/video/backlight/ F: include/linux/backlight.h +BATMAN ADVANCED +M: Marek Lindner <[email protected]> +M: Simon Wunderlich <[email protected]> +L: [email protected] +W: http://www.open-mesh.org/ +S: Maintained +F: net/batman-adv/ + BAYCOM/HDLCDRV DRIVERS FOR AX.25 M: Thomas Sailer <[email protected]> L: [email protected]
net/Kconfig +1 -0
@@ -214,6 +214,7 @@ source "net/ieee802154/Kconfig" source "net/sched/Kconfig" source "net/dcb/Kconfig" source "net/dns_resolver/Kconfig" +source "net/batman-adv/Kconfig" config RPS boolean
net/Makefile +1 -0
@@ -68,3 +68,4 @@ obj-$(CONFIG_SYSCTL) += sysctl_net.o endif obj-$(CONFIG_WIMAX) += wimax/ obj-$(CONFIG_DNS_RESOLVER) += dns_resolver/ +obj-$(CONFIG_BATMAN_ADV) += batman-adv/
net/batman-adv/Kconfig new file +26 -0
@@ -0,0 +1,26 @@ +# +# B.A.T.M.A.N meshing protocol +# + +config BATMAN_ADV + tristate "B.A.T.M.A.N. Advanced Meshing Protocol" + depends on NET + default n + ---help--- + + B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is + a routing protocol for multi-hop ad-hoc mesh networks. The + networks may be wired or wireless. See + http://www.open-mesh.org/ for more information and user space + tools. + +config BATMAN_ADV_DEBUG + bool "B.A.T.M.A.N. debugging" + depends on BATMAN_ADV != n + ---help--- + + This is an option for use by developers; most people should + say N here. This enables compilation of support for + outputting debugging information to the kernel log. The + output is controlled via the module parameter debug. +
net/batman-adv/Makefile new file +22 -0
@@ -0,0 +1,22 @@ +# +# Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: +# +# Marek Lindner, Simon Wunderlich +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of version 2 of the GNU General Public +# License as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA +# + +obj-$(CONFIG_BATMAN_ADV) += batman-adv.o +batman-adv-objs := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o unicast.o
net/batman-adv/aggregation.c new file +270 -0
270 lines not on this page · raw message
net/batman-adv/aggregation.h new file +43 -0
43 lines not on this page · raw message
net/batman-adv/bat_debugfs.c new file +341 -0
341 lines not on this page · raw message
net/batman-adv/bat_debugfs.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + + +#ifndef _NET_BATMAN_ADV_DEBUGFS_H_ +#define _NET_BATMAN_ADV_DEBUGFS_H_ + +#define DEBUGFS_BAT_SUBDIR "batman_adv" + +void debugfs_init (void ); +void debugfs_destroy (void ); +int debugfs_add_meshif (struct net_device *dev); +void debugfs_del_meshif (struct net_device *dev); + +#endif /* _NET_BATMAN_ADV_DEBUGFS_H_ */
net/batman-adv/bat_sysfs.c new file +536 -0
536 lines not on this page · raw message
net/batman-adv/bat_sysfs.h new file +42 -0
42 lines not on this page · raw message
net/batman-adv/bitarray.c new file +201 -0
201 lines not on this page · raw message
net/batman-adv/bitarray.h new file +47 -0
47 lines not on this page · raw message
net/batman-adv/hard-interface.c new file +596 -0
596 lines not on this page · raw message
net/batman-adv/hard-interface.h new file +45 -0
45 lines not on this page · raw message
net/batman-adv/hash.c new file +306 -0
306 lines not on this page · raw message
net/batman-adv/hash.h new file +100 -0
100 lines not on this page · raw message
net/batman-adv/icmp_socket.c new file +356 -0
81 lines not on this page · raw message
net/batman-adv/main.c new file +225 -0
225 lines not on this page · raw message
net/batman-adv/main.h new file +185 -0
185 lines not on this page · raw message
net/batman-adv/originator.c new file +539 -0
539 lines not on this page · raw message
net/batman-adv/packet.h new file +134 -0
134 lines not on this page · raw message
net/batman-adv/ring_buffer.c new file +52 -0
52 lines not on this page · raw message
net/batman-adv/routing.c new file +1387 -0
1,387 lines not on this page · raw message
net/batman-adv/routing.h new file +46 -0
46 lines not on this page · raw message
net/batman-adv/send.c new file +577 -0
577 lines not on this page · raw message
net/batman-adv/send.h new file +41 -0
41 lines not on this page · raw message
net/batman-adv/soft-interface.c new file +395 -0
395 lines not on this page · raw message
net/batman-adv/soft-interface.h new file +32 -0
Lines of this file are not shown. View the raw message.
net/batman-adv/translation-table.c new file +513 -0
513 lines not on this page · raw message
net/batman-adv/translation-table.h new file +45 -0
45 lines not on this page · raw message
net/batman-adv/types.h new file +244 -0
244 lines not on this page · raw message
net/batman-adv/unicast.c new file +265 -0
265 lines not on this page · raw message
net/batman-adv/vis.c new file +901 -0
901 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Part of the diff is not shown here. View the raw message.
Quoted 4 lines · Sven Eckelmann
B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is a routing protocol for multi-hop ad-hoc mesh networks. The networks may be wired or wireless. See http://www.open-mesh.org/ for more information and user space tools.
Please see below for some questions about use of RCU.
Thanx, Paul
Quoted 2,116 lines
Signed-off-by Sven Eckelmann <[email protected]>---
batman-adv is a layer2 meshing protocol currently indrivers/staging/batman-adv. GregKH recently [1][2] gave us his blessing to leave the staging tree and move to a more suitable location.Short functionality overview:
The batman-adv module is an implementation of the B.A.T.M.A.N. routing protocol operating on layer2 optimized for (but not limited to) wireless networks. Next to finding the best possible path through the network it encapsulates the data traffic and optimizes the transport as well. There also is a user space tool "batctl" which offers various functionalities next to a kernel module configuration interface. Detailed documentation can be found at the project homepage[3].
Everything is addressed in the last round of comments [4].
[1] https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-June/002881.html
[2] https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-June/002968.html
[3] http://www.open-mesh.org
[4] https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-July/003138.html.../ABI/testing/sysfs-class-net-batman-adv | 14 + Documentation/ABI/testing/sysfs-class-net-mesh | 33 + Documentation/networking/batman-adv.txt | 239 ++++ MAINTAINERS | 8 + net/Kconfig | 1 + net/Makefile | 1 + net/batman-adv/Kconfig | 26 + net/batman-adv/Makefile | 22 + net/batman-adv/aggregation.c | 270 ++++ net/batman-adv/aggregation.h | 43 + net/batman-adv/bat_debugfs.c | 341 +++++ net/batman-adv/bat_debugfs.h | 33 + net/batman-adv/bat_sysfs.c | 536 ++++++++ net/batman-adv/bat_sysfs.h | 42 + net/batman-adv/bitarray.c | 201 +++ net/batman-adv/bitarray.h | 47 + net/batman-adv/hard-interface.c | 596 +++++++++ net/batman-adv/hard-interface.h | 45 + net/batman-adv/hash.c | 306 +++++ net/batman-adv/hash.h | 100 ++ net/batman-adv/icmp_socket.c | 356 +++++ net/batman-adv/icmp_socket.h | 34 + net/batman-adv/main.c | 225 ++++ net/batman-adv/main.h | 185 +++ net/batman-adv/originator.c | 539 ++++++++ net/batman-adv/originator.h | 36 + net/batman-adv/packet.h | 134 ++ net/batman-adv/ring_buffer.c | 52 + net/batman-adv/ring_buffer.h | 28 + net/batman-adv/routing.c | 1387 ++++++++++++++++++++ net/batman-adv/routing.h | 46 + net/batman-adv/send.c | 577 ++++++++ net/batman-adv/send.h | 41 + net/batman-adv/soft-interface.c | 395 ++++++ net/batman-adv/soft-interface.h | 32 + net/batman-adv/translation-table.c | 513 ++++++++ net/batman-adv/translation-table.h | 45 + net/batman-adv/types.h | 244 ++++ net/batman-adv/unicast.c | 265 ++++ net/batman-adv/unicast.h | 39 + net/batman-adv/vis.c | 901 +++++++++++++ net/batman-adv/vis.h | 37 + 42 files changed, 9015 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-net-batman-adv create mode 100644 Documentation/ABI/testing/sysfs-class-net-mesh create mode 100644 Documentation/networking/batman-adv.txt create mode 100644 net/batman-adv/Kconfig create mode 100644 net/batman-adv/Makefile create mode 100644 net/batman-adv/aggregation.c create mode 100644 net/batman-adv/aggregation.h create mode 100644 net/batman-adv/bat_debugfs.c create mode 100644 net/batman-adv/bat_debugfs.h create mode 100644 net/batman-adv/bat_sysfs.c create mode 100644 net/batman-adv/bat_sysfs.h create mode 100644 net/batman-adv/bitarray.c create mode 100644 net/batman-adv/bitarray.h create mode 100644 net/batman-adv/hard-interface.c create mode 100644 net/batman-adv/hard-interface.h create mode 100644 net/batman-adv/hash.c create mode 100644 net/batman-adv/hash.h create mode 100644 net/batman-adv/icmp_socket.c create mode 100644 net/batman-adv/icmp_socket.h create mode 100644 net/batman-adv/main.c create mode 100644 net/batman-adv/main.h create mode 100644 net/batman-adv/originator.c create mode 100644 net/batman-adv/originator.h create mode 100644 net/batman-adv/packet.h create mode 100644 net/batman-adv/ring_buffer.c create mode 100644 net/batman-adv/ring_buffer.h create mode 100644 net/batman-adv/routing.c create mode 100644 net/batman-adv/routing.h create mode 100644 net/batman-adv/send.c create mode 100644 net/batman-adv/send.h create mode 100644 net/batman-adv/soft-interface.c create mode 100644 net/batman-adv/soft-interface.h create mode 100644 net/batman-adv/translation-table.c create mode 100644 net/batman-adv/translation-table.h create mode 100644 net/batman-adv/types.h create mode 100644 net/batman-adv/unicast.c create mode 100644 net/batman-adv/unicast.h create mode 100644 net/batman-adv/vis.c create mode 100644 net/batman-adv/vis.hDocumentation/ABI/testing/sysfs-class-net-batman-adv new file +14
-0@@ -0,0 +1,14 @@ + +What: /sys/class/net/<iface>/batman-adv/mesh_iface +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + The /sys/class/net/<iface>/batman-adv/mesh_iface file + displays the batman mesh interface this <iface> + currently is associated with. + +What: /sys/class/net/<iface>/batman-adv/iface_status +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + Indicates the status of <iface> as it is seen by batman.Documentation/ABI/testing/sysfs-class-net-mesh new file +33
-0@@ -0,0 +1,33 @@ + +What: /sys/class/net/<mesh_iface>/mesh/aggregated_ogms +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + Indicates whether the batman protocol messages of the + mesh <mesh_iface> shall be aggregated or not. + +What: /sys/class/net/<mesh_iface>/mesh/bonding +Date: June 2010 +Contact: Simon Wunderlich <[email protected]> +Description: + Indicates whether the data traffic going through the + mesh will be sent using multiple interfaces at the + same time (if available). + +What: /sys/class/net/<mesh_iface>/mesh/orig_interval +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + Defines the interval in milliseconds in which batman + sends its protocol messages. + +What: /sys/class/net/<mesh_iface>/mesh/vis_mode +Date: May 2010 +Contact: Marek Lindner <[email protected]> +Description: + Each batman node only maintains information about its + own local neighborhood, therefore generating graphs + showing the topology of the entire mesh is not easily + feasible without having a central instance to collect + the local topologies from all nodes. This file allows + to activate the collecting (server) mode.Documentation/networking/batman-adv.txt new file +239
-0@@ -0,0 +1,239 @@ +[state: 04-09-2010] + +BATMAN-ADV +---------- + +Batman advanced is a new approach to wireless networking which +does no longer operate on the IP basis. Unlike the batman daemon, +which exchanges information using UDP packets and sets routing +tables, batman-advanced operates on ISO/OSI Layer 2 only and uses +and routes (or better: bridges) Ethernet Frames. It emulates a +virtual network switch of all nodes participating. Therefore all +nodes appear to be link local, thus all higher operating proto- +cols won't be affected by any changes within the network. You can +run almost any protocol above batman advanced, prominent examples +are: IPv4, IPv6, DHCP, IPX. + +Batman advanced was implemented as a Linux kernel driver to re- +duce the overhead to a minimum. It does not depend on any (other) +network driver, and can be used on wifi as well as ethernet lan, +vpn, etc ... (anything with ethernet-style layer 2). + +CONFIGURATION +------------- + +Load the batman-adv module into your kernel: + +# insmod batman-adv.ko + +The module is now waiting for activation. You must add some in- +terfaces on which batman can operate. After loading the module +batman advanced will scan your systems interfaces to search for +compatible interfaces. Once found, it will create subfolders in +the /sys directories of each supported interface, e.g. + +# ls /sys/class/net/eth0/batman_adv/ +# iface_status mesh_iface + +If an interface does not have the "batman_adv" subfolder it prob- +ably is not supported. Not supported interfaces are: loopback, +non-ethernet and batman's own interfaces. + +Note: After the module was loaded it will continuously watch for +new interfaces to verify the compatibility. There is no need to +reload the module if you plug your USB wifi adapter into your ma- +chine after batman advanced was initially loaded. + +To activate a given interface simply write "bat0" into its +"mesh_iface" file inside the batman_adv subfolder: + +# echo bat0 > /sys/class/net/eth0/batman_adv/mesh_iface + +Repeat this step for all interfaces you wish to add. Now batman +starts using/broadcasting on this/these interface(s). + +By reading the "iface_status" file you can check its status: + +# cat /sys/class/net/eth0/batman_adv/iface_status +# active + +To deactivate an interface you have to write "none" into its +"mesh_iface" file: + +# echo none > /sys/class/net/eth0/batman_adv/mesh_iface + + +All mesh wide settings can be found in batman's own interface +folder: + +# ls /sys/class/net/bat0/mesh/ +# aggregated_ogms bonding orig_interval vis_mode + + +There is a special folder for debugging informations: + +# ls /sys/kernel/debug/batman_adv/bat0/ +# originators socket transtable_global transtable_local +# vis_data + + +Some of the files contain all sort of status information regard- +ing the mesh network. For example, you can view the table of +originators (mesh participants) with: + +# cat /sys/kernel/debug/batman_adv/bat0/originators + +Other files allow to change batman's behaviour to better fit your +requirements. For instance, you can check the current originator +interval (value in milliseconds which determines how often batman +sends its broadcast packets): + +# cat /sys/class/net/bat0/mesh/orig_interval +# 1000 + +and also change its value: + +# echo 3000 > /sys/class/net/bat0/mesh/orig_interval + +In very mobile scenarios, you might want to adjust the originator +interval to a lower value. This will make the mesh more respon- +sive to topology changes, but will also increase the overhead. + + +USAGE +----- + +To make use of your newly created mesh, batman advanced provides +a new interface "bat0" which you should use from this point on. +All interfaces added to batman advanced are not relevant any +longer because batman handles them for you. Basically, one "hands +over" the data by using the batman interface and batman will make +sure it reaches its destination. + +The "bat0" interface can be used like any other regular inter- +face. It needs an IP address which can be either statically con- +figured or dynamically (by using DHCP or similar services): + +# NodeA: ifconfig bat0 192.168.0.1 +# NodeB: ifconfig bat0 192.168.0.2 +# NodeB: ping 192.168.0.1 + +Note: In order to avoid problems remove all IP addresses previ- +ously assigned to interfaces now used by batman advanced, e.g. + +# ifconfig eth0 0.0.0.0 + + +VISUALIZATION +------------- + +If you want topology visualization, at least one mesh node must +be configured as VIS-server: + +# echo "server" > /sys/class/net/bat0/mesh/vis_mode + +Each node is either configured as "server" or as "client" (de- +fault: "client"). Clients send their topology data to the server +next to them, and server synchronize with other servers. If there +is no server configured (default) within the mesh, no topology +information will be transmitted. With these "synchronizing +servers", there can be 1 or more vis servers sharing the same (or +at least very similar) data. + +When configured as server, you can get a topology snapshot of +your mesh: + +# cat /sys/kernel/debug/batman_adv/bat0/vis_data + +This raw output is intended to be easily parsable and convertable +with other tools. Have a look at the batctl README if you want a +vis output in dot or json format for instance and how those out- +puts could then be visualised in an image. + +The raw format consists of comma separated values per entry where +each entry is giving information about a certain source inter- +face. Each entry can/has to have the following values: +-> "mac" - mac address of an originator's source interface + (each line begins with it) +-> "TQ mac value" - src mac's link quality towards mac address + of a neighbor originator's interface which + is being used for routing +-> "HNA mac" - HNA announced by source mac +-> "PRIMARY" - this is a primary interface +-> "SEC mac" - secondary mac address of source + (requires preceding PRIMARY) + +The TQ value has a range from 4 to 255 with 255 being the best. +The HNA entries are showing which hosts are connected to the mesh +via bat0 or being bridged into the mesh network. The PRIMARY/SEC +values are only applied on primary interfaces + + +LOGGING/DEBUGGING +----------------- + +All error messages, warnings and information messages are sent to +the kernel log. Depending on your operating system distribution +this can be read in one of a number of ways. Try using the com- +mands: dmesg, logread, or looking in the files /var/log/kern.log +or /var/log/syslog. All batman-adv messages are prefixed with +"batman-adv:" So to see just these messages try + +# dmesg | grep batman-adv + +When investigating problems with your mesh network it is some- +times necessary to see more detail debug messages. This must be +enabled when compiling the batman-adv module. When building bat- +man-adv as part of kernel, use "make menuconfig" and enable the +option "B.A.T.M.A.N. debugging". + +Those additional debug messages can be accessed using a special +file in debugfs + +# cat /sys/kernel/debug/batman_adv/bat0/log + +The additional debug output is by default disabled. It can be en- +abled during run time. Following log_levels are defined: + +0 - All debug output disabled +1 - Enable messages related to routing / flooding / broadcasting +2 - Enable route or hna added / changed / deleted +3 - Enable all messages + +The debug output can be changed at runtime using the file +/sys/class/net/bat0/mesh/log_level. e.g. + +# echo 2 > /sys/class/net/bat0/mesh/log_level + +will enable debug messages for when routes or HNAs change. + + +BATCTL +------ + +As batman advanced operates on layer 2 all hosts participating in +the virtual switch are completely transparent for all protocols +above layer 2. Therefore the common diagnosis tools do not work +as expected. To overcome these problems batctl was created. At +the moment the batctl contains ping, traceroute, tcpdump and +interfaces to the kernel module settings. + +For more information, please see the manpage (man batctl). + +batctl is available on http://www.open-mesh.org/ + + +CONTACT +------- + +Please send us comments, experiences, questions, anything :) + +IRC: #batman on irc.freenode.org +Mailing-list: [email protected] (optional subscription + at https://lists.open-mesh.org/mm/listinfo/b.a.t.m.a.n) + +You can also contact the Authors: + +Marek Lindner <[email protected]> +Simon Wunderlich <[email protected]> +MAINTAINERS +8
-0@@ -1262,6 +1262,14 @@ S: Maintained F: drivers/video/backlight/ F: include/linux/backlight.h +BATMAN ADVANCED +M: Marek Lindner <[email protected]> +M: Simon Wunderlich <[email protected]> +L: [email protected] +W: http://www.open-mesh.org/ +S: Maintained +F: net/batman-adv/ + BAYCOM/HDLCDRV DRIVERS FOR AX.25 M: Thomas Sailer <[email protected]> L: [email protected]net/Kconfig +1
-0@@ -214,6 +214,7 @@ source "net/ieee802154/Kconfig" source "net/sched/Kconfig" source "net/dcb/Kconfig" source "net/dns_resolver/Kconfig" +source "net/batman-adv/Kconfig" config RPS booleannet/Makefile +1
-0@@ -68,3 +68,4 @@ obj-$(CONFIG_SYSCTL) += sysctl_net.o endif obj-$(CONFIG_WIMAX) += wimax/ obj-$(CONFIG_DNS_RESOLVER) += dns_resolver/ +obj-$(CONFIG_BATMAN_ADV) += batman-adv/net/batman-adv/Kconfig new file +26
-0@@ -0,0 +1,26 @@ +# +# B.A.T.M.A.N meshing protocol +# + +config BATMAN_ADV + tristate "B.A.T.M.A.N. Advanced Meshing Protocol" + depends on NET + default n + ---help--- + + B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is + a routing protocol for multi-hop ad-hoc mesh networks. The + networks may be wired or wireless. See + http://www.open-mesh.org/ for more information and user space + tools. + +config BATMAN_ADV_DEBUG + bool "B.A.T.M.A.N. debugging" + depends on BATMAN_ADV != n + ---help--- + + This is an option for use by developers; most people should + say N here. This enables compilation of support for + outputting debugging information to the kernel log. The + output is controlled via the module parameter debug. +net/batman-adv/Makefile new file +22
-0@@ -0,0 +1,22 @@ +# +# Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: +# +# Marek Lindner, Simon Wunderlich +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of version 2 of the GNU General Public +# License as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA +# + +obj-$(CONFIG_BATMAN_ADV) += batman-adv.o +batman-adv-objs := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o unicast.onet/batman-adv/aggregation.c new file +270
-0@@ -0,0 +1,270 @@ +/* +* Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner, Simon Wunderlich +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#include "main.h" +#include "aggregation.h" +#include "send.h" +#include "routing.h" + +/* calculate the size of the hna information for a given packet */ +static int hna_len (struct batman_packet *batman_packet) +{ +return batman_packet->num_hna *ETH_ALEN ; +} + +/* return true if new_packet can be aggregated with forw_packet */ +static bool can_aggregate_with (struct batman_packet *new_batman_packet, +int packet_len, +unsigned long send_time, +bool directlink, +struct batman_if *if_incoming, +struct forw_packet *forw_packet) +{ +struct batman_packet *batman_packet = + (struct batman_packet *)forw_packet->skb->data; +int aggregated_bytes = forw_packet->packet_len + packet_len; + +/** +* we can aggregate the current packet to this aggregated packet +* if: +* +* - the send time is within our MAX_AGGREGATION_MS time +* - the resulting packet wont be bigger than +* MAX_AGGREGATION_BYTES +*/ + +if (time_before (send_time, forw_packet->send_time) && +time_after_eq (send_time +msecs_to_jiffies (MAX_AGGREGATION_MS ), + forw_packet->send_time) && + (aggregated_bytes <=MAX_AGGREGATION_BYTES )) { + +/** +* check aggregation compatibility +* -> direct link packets are broadcasted on +* their interface only +* -> aggregate packet if the current packet is +* a "global" packet as well as the base +* packet +*/ + +/* packets without direct link flag and high TTL +* are flooded through the net */ +if ((!directlink) && + (!(batman_packet->flags &DIRECTLINK )) && + (batman_packet->ttl !=1 ) && + +/* own packets originating non-primary +* interfaces leave only that interface */ + ((!forw_packet->own) || + (forw_packet->if_incoming->if_num ==0 ))) +return true; + +/* if the incoming packet is sent via this one +* interface only - we still can aggregate */ +if ((directlink) && + (new_batman_packet->ttl ==1 ) && + (forw_packet->if_incoming == if_incoming) && + +/* packets from direct neighbors or +* own secondary interface packets +* (= secondary interface packets in general) */ + (batman_packet->flags &DIRECTLINK || + (forw_packet->own && + forw_packet->if_incoming->if_num !=0 ))) +return true; + } + +return false; +} + +#define atomic_dec_not_zero (v) atomic_add_unless((v), -1, 0) +/* create a new aggregated packet and add this packet to it */ +static void new_aggregated_packet (unsigned char *packet_buff,int packet_len, +unsigned long send_time,bool direct_link, +struct batman_if *if_incoming, +int own_packet) +{ +struct bat_priv *bat_priv =netdev_priv (if_incoming->soft_iface); +struct forw_packet *forw_packet_aggr; +unsigned long flags; +unsigned char *skb_buff; + +/* own packet should always be scheduled */ +if (!own_packet) { +if (!atomic_dec_not_zero (&bat_priv->batman_queue_left)) { +bat_dbg (DBG_BATMAN , bat_priv, +"batman packet queue full\n" ); +return ; + } + } + + forw_packet_aggr =kmalloc (sizeof (struct forw_packet ),GFP_ATOMIC ); +if (!forw_packet_aggr) { +if (!own_packet) +atomic_inc (&bat_priv->batman_queue_left); +return ; + } + + forw_packet_aggr->skb =dev_alloc_skb (MAX_AGGREGATION_BYTES + +sizeof (struct ethhdr )); +if (!forw_packet_aggr->skb) { +if (!own_packet) +atomic_inc (&bat_priv->batman_queue_left); +kfree (forw_packet_aggr); +return ; + } +skb_reserve (forw_packet_aggr->skb,sizeof (struct ethhdr )); + +INIT_HLIST_NODE (&forw_packet_aggr->list); + + skb_buff =skb_put (forw_packet_aggr->skb, packet_len); + forw_packet_aggr->packet_len = packet_len; +memcpy (skb_buff, packet_buff, packet_len); + + forw_packet_aggr->own = own_packet; + forw_packet_aggr->if_incoming = if_incoming; + forw_packet_aggr->num_packets =0 ; + forw_packet_aggr->direct_link_flags =0 ; + forw_packet_aggr->send_time = send_time; + +/* save packet direct link flag status */ +if (direct_link) + forw_packet_aggr->direct_link_flags |=1 ; + +/* add new packet to packet list */ +spin_lock_irqsave (&bat_priv->forw_bat_list_lock, flags); +hlist_add_head (&forw_packet_aggr->list, &bat_priv->forw_bat_list); +spin_unlock_irqrestore (&bat_priv->forw_bat_list_lock, flags); + +/* start timer for this packet */ +INIT_DELAYED_WORK (&forw_packet_aggr->delayed_work, + send_outstanding_bat_packet); +queue_delayed_work (bat_event_workqueue, + &forw_packet_aggr->delayed_work, + send_time - jiffies); +} + +/* aggregate a new packet into the existing aggregation */ +static void aggregate (struct forw_packet *forw_packet_aggr, +unsigned char *packet_buff, +int packet_len, +bool direct_link) +{ +unsigned char *skb_buff; + + skb_buff =skb_put (forw_packet_aggr->skb, packet_len); +memcpy (skb_buff, packet_buff, packet_len); + forw_packet_aggr->packet_len += packet_len; + forw_packet_aggr->num_packets++; + +/* save packet direct link flag status */ +if (direct_link) + forw_packet_aggr->direct_link_flags |= + (1 << forw_packet_aggr->num_packets); +} + +void add_bat_packet_to_list (struct bat_priv *bat_priv, +unsigned char *packet_buff,int packet_len, +struct batman_if *if_incoming,char own_packet, +unsigned long send_time) +{ +/** +* _aggr -> pointer to the packet we want to aggregate with +* _pos -> pointer to the position in the queue +*/ +struct forw_packet *forw_packet_aggr =NULL , *forw_packet_pos =NULL ; +struct hlist_node *tmp_node; +struct batman_packet *batman_packet = + (struct batman_packet *)packet_buff; +bool direct_link = batman_packet->flags &DIRECTLINK ?1 :0 ; +unsigned long flags; + +/* find position for the packet in the forward queue */ +spin_lock_irqsave (&bat_priv->forw_bat_list_lock, flags); +/* own packets are not to be aggregated */ +if ((atomic_read (&bat_priv->aggregation_enabled)) && (!own_packet)) { +hlist_for_each_entry (forw_packet_pos, tmp_node, + &bat_priv->forw_bat_list, list) { +if (can_aggregate_with (batman_packet, + packet_len, + send_time, + direct_link, + if_incoming, + forw_packet_pos)) { + forw_packet_aggr = forw_packet_pos; +break ; + } + } + } + +/* nothing to aggregate with - either aggregation disabled or no +* suitable aggregation packet found */ +if (forw_packet_aggr ==NULL ) { +/* the following section can run without the lock */ +spin_unlock_irqrestore (&bat_priv->forw_bat_list_lock, flags); + +/** +* if we could not aggregate this packet with one of the others +* we hold it back for a while, so that it might be aggregated +* later on +*/ +if ((!own_packet) && + (atomic_read (&bat_priv->aggregation_enabled))) + send_time +=msecs_to_jiffies (MAX_AGGREGATION_MS ); + +new_aggregated_packet (packet_buff, packet_len, + send_time, direct_link, + if_incoming, own_packet); + }else { +aggregate (forw_packet_aggr, + packet_buff, packet_len, + direct_link); +spin_unlock_irqrestore (&bat_priv->forw_bat_list_lock, flags); + } +} + +/* unpack the aggregated packets and process them one by one */ +void receive_aggr_bat_packet (struct ethhdr *ethhdr,unsigned char *packet_buff, +int packet_len,struct batman_if *if_incoming) +{ +struct batman_packet *batman_packet; +int buff_pos =0 ; +unsigned char *hna_buff; + + batman_packet = (struct batman_packet *)packet_buff; + +while (aggregated_packet (buff_pos, packet_len, + batman_packet->num_hna)) { + +/* network to host order for our 32bit seqno, and the +orig_interval. */ + batman_packet->seqno =ntohl (batman_packet->seqno); + + hna_buff = packet_buff + buff_pos +BAT_PACKET_LEN ; +receive_bat_packet (ethhdr, batman_packet, + hna_buff,hna_len (batman_packet), + if_incoming); + + buff_pos +=BAT_PACKET_LEN +hna_len (batman_packet); + batman_packet = (struct batman_packet *) + (packet_buff + buff_pos); + } +}net/batman-adv/aggregation.h new file +43
-0@@ -0,0 +1,43 @@ +/* +* Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner, Simon Wunderlich +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#ifndef _NET_BATMAN_ADV_AGGREGATION_H_ +#define _NET_BATMAN_ADV_AGGREGATION_H_ + +#include "main.h" + +/* is there another aggregated packet here? */ +static inline int aggregated_packet (int buff_pos,int packet_len,int num_hna) +{ +int next_buff_pos = buff_pos +BAT_PACKET_LEN + (num_hna *ETH_ALEN ); + +return (next_buff_pos <= packet_len) && + (next_buff_pos <=MAX_AGGREGATION_BYTES ); +} + +void add_bat_packet_to_list (struct bat_priv *bat_priv, +unsigned char *packet_buff,int packet_len, +struct batman_if *if_incoming,char own_packet, +unsigned long send_time); +void receive_aggr_bat_packet (struct ethhdr *ethhdr,unsigned char *packet_buff, +int packet_len,struct batman_if *if_incoming); + +#endif /* _NET_BATMAN_ADV_AGGREGATION_H_ */ net/batman-adv/bat_debugfs.c new file +341
-0@@ -0,0 +1,341 @@ +/* +* Copyright (C) 2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#include "main.h" + +#include <linux/debugfs.h> + +#include "bat_debugfs.h" +#include "translation-table.h" +#include "originator.h" +#include "hard-interface.h" +#include "vis.h" +#include "icmp_socket.h" + +static struct dentry *bat_debugfs; + +#ifdef CONFIG_BATMAN_ADV_DEBUG +#define LOG_BUFF_MASK (log_buff_len-1) +#define LOG_BUFF (idx) (debug_log->log_buff[(idx) & LOG_BUFF_MASK]) + +static int log_buff_len =LOG_BUF_LEN ; + +static void emit_log_char (struct debug_log *debug_log,char c) +{ +LOG_BUFF (debug_log->log_end) = c; + debug_log->log_end++; + +if (debug_log->log_end - debug_log->log_start > log_buff_len) + debug_log->log_start = debug_log->log_end - log_buff_len; +} + +static int fdebug_log (struct debug_log *debug_log,char *fmt, ...) +{ +int printed_len; +va_list args; +static char debug_log_buf[256 ]; +char *p; +unsigned long flags; + +if (!debug_log) +return 0 ; + +spin_lock_irqsave (&debug_log->lock, flags); +va_start (args, fmt); + printed_len =vscnprintf (debug_log_buf,sizeof (debug_log_buf), + fmt, args); +va_end (args); + +for (p = debug_log_buf; *p !=0 ; p++) +emit_log_char (debug_log, *p); + +spin_unlock_irqrestore (&debug_log->lock, flags); + +wake_up (&debug_log->queue_wait); + +return 0 ; +} + +int debug_log (struct bat_priv *bat_priv,char *fmt, ...) +{ +va_list args; +char tmp_log_buf[256 ]; + +va_start (args, fmt); +vscnprintf (tmp_log_buf,sizeof (tmp_log_buf), fmt, args); +fdebug_log (bat_priv->debug_log,"[%10u] %s" , + (jiffies /HZ ), tmp_log_buf); +va_end (args); + +return 0 ; +} + +static int log_open (struct inode *inode,struct file *file) +{ + file->private_data = inode->i_private; +inc_module_count (); +return 0 ; +} + +static int log_release (struct inode *inode,struct file *file) +{ +dec_module_count (); +return 0 ; +} + +static ssize_t log_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +struct bat_priv *bat_priv = file->private_data; +struct debug_log *debug_log = bat_priv->debug_log; +int error, i =0 ; +char c; +unsigned long flags; + +if ((file->f_flags &O_NONBLOCK ) && + !(debug_log->log_end - debug_log->log_start)) +return -EAGAIN ; + +if ((!buf) || (count <0 )) +return -EINVAL ; + +if (count ==0 ) +return 0 ; + +if (!access_ok (VERIFY_WRITE , buf, count)) +return -EFAULT ; + + error =wait_event_interruptible (debug_log->queue_wait, + (debug_log->log_start - debug_log->log_end)); + +if (error) +return error; + +spin_lock_irqsave (&debug_log->lock, flags); + +while ((!error) && (i < count) && + (debug_log->log_start != debug_log->log_end)) { + c =LOG_BUFF (debug_log->log_start); + + debug_log->log_start++; + +spin_unlock_irqrestore (&debug_log->lock, flags); + + error =__put_user (c, buf); + +spin_lock_irqsave (&debug_log->lock, flags); + + buf++; + i++; + + } + +spin_unlock_irqrestore (&debug_log->lock, flags); + +if (!error) +return i; + +return error; +} + +static unsigned int log_poll (struct file *file,poll_table *wait) +{ +struct bat_priv *bat_priv = file->private_data; +struct debug_log *debug_log = bat_priv->debug_log; + +poll_wait (file, &debug_log->queue_wait, wait); + +if (debug_log->log_end - debug_log->log_start) +return POLLIN |POLLRDNORM ; + +return 0 ; +} + +static const struct file_operations log_fops = { + .open = log_open, + .release = log_release, + .read = log_read, + .poll = log_poll, +}; + +static int debug_log_setup (struct bat_priv *bat_priv) +{ +struct dentry *d; + +if (!bat_priv->debug_dir) + goto err; + + bat_priv->debug_log =kzalloc (sizeof (struct debug_log ),GFP_ATOMIC ); +if (!bat_priv->debug_log) + goto err; + +spin_lock_init (&bat_priv->debug_log->lock); +init_waitqueue_head (&bat_priv->debug_log->queue_wait); + + d =debugfs_create_file ("log" ,S_IFREG |S_IRUSR , + bat_priv->debug_dir, bat_priv, &log_fops); +if (d) + goto err; + +return 0 ; + +err: +return 1 ; +} + +static void debug_log_cleanup (struct bat_priv *bat_priv) +{ +kfree (bat_priv->debug_log); + bat_priv->debug_log =NULL ; +} +#else /* CONFIG_BATMAN_ADV_DEBUG */ +static int debug_log_setup (struct bat_priv *bat_priv) +{ + bat_priv->debug_log =NULL ; +return 0 ; +} + +static void debug_log_cleanup (struct bat_priv *bat_priv) +{ +return ; +} +#endif + +static int originators_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, orig_seq_print_text, net_dev); +} + +static int transtable_global_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_global_seq_print_text, net_dev); +} + +static int transtable_local_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_local_seq_print_text, net_dev); +} + +static int vis_data_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, vis_seq_print_text, net_dev); +} + +struct bat_debuginfo { +struct attribute attr; +const struct file_operations fops; +}; + +#define BAT_DEBUGINFO (_name, _mode, _open) \ +struct bat_debuginfo bat_debuginfo_##_name = { \ + .attr = { .name = __stringify(_name), \ + .mode = _mode, }, \ + .fops = { .owner = THIS_MODULE, \ + .open = _open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ + } \ +}; + +static BAT_DEBUGINFO(originators, S_IRUGO, originators_open); +static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open); +static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open); +static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open); + +static struct bat_debuginfo *mesh_debuginfos[] = { + &bat_debuginfo_originators, + &bat_debuginfo_transtable_global, + &bat_debuginfo_transtable_local, + &bat_debuginfo_vis_data, +NULL , +}; + +void debugfs_init (void ) +{ + bat_debugfs =debugfs_create_dir (DEBUGFS_BAT_SUBDIR ,NULL ); +if (bat_debugfs ==ERR_PTR (-ENODEV )) + bat_debugfs =NULL ; +} + +void debugfs_destroy (void ) +{ +if (bat_debugfs) { +debugfs_remove_recursive (bat_debugfs); + bat_debugfs =NULL ; + } +} + +int debugfs_add_meshif (struct net_device *dev) +{ +struct bat_priv *bat_priv =netdev_priv (dev); +struct bat_debuginfo **bat_debug; +struct dentry *file; + +if (!bat_debugfs) + goto out; + + bat_priv->debug_dir =debugfs_create_dir (dev->name, bat_debugfs); +if (!bat_priv->debug_dir) + goto out; + +bat_socket_setup (bat_priv); +debug_log_setup (bat_priv); + +for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) { + file =debugfs_create_file (((*bat_debug)->attr).name, +S_IFREG | ((*bat_debug)->attr).mode, + bat_priv->debug_dir, + dev, &(*bat_debug)->fops); +if (!file) { +bat_err (dev,"Can't add debugfs file: %s/%s\n" , + dev->name, ((*bat_debug)->attr).name); + goto rem_attr; + } + } + +return 0 ; +rem_attr: +debugfs_remove_recursive (bat_priv->debug_dir); + bat_priv->debug_dir =NULL ; +out: +#ifdef CONFIG_DEBUG_FS +return -ENOMEM ; +#else +return 0 ; +#endif /* CONFIG_DEBUG_FS */ +} + +void debugfs_del_meshif (struct net_device *dev) +{ +struct bat_priv *bat_priv =netdev_priv (dev); + +debug_log_cleanup (bat_priv); + +if (bat_debugfs) { +debugfs_remove_recursive (bat_priv->debug_dir); + bat_priv->debug_dir =NULL ; + } +}net/batman-adv/bat_debugfs.h new file +33
-0@@ -0,0 +1,33 @@ +/* +* Copyright (C) 2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + + +#ifndef _NET_BATMAN_ADV_DEBUGFS_H_ +#define _NET_BATMAN_ADV_DEBUGFS_H_ + +#define DEBUGFS_BAT_SUBDIR "batman_adv" + +void debugfs_init (void ); +void debugfs_destroy (void ); +int debugfs_add_meshif (struct net_device *dev); +void debugfs_del_meshif (struct net_device *dev); + +#endif /* _NET_BATMAN_ADV_DEBUGFS_H_ */ net/batman-adv/bat_sysfs.c new file +536
-0@@ -0,0 +1,536 @@ +/* +* Copyright (C) 2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#include "main.h" +#include "bat_sysfs.h" +#include "translation-table.h" +#include "originator.h" +#include "hard-interface.h" +#include "vis.h" + +#define to_dev (obj) container_of(obj, struct device, kobj) + +#define BAT_ATTR (_name, _mode, _show, _store) \ +struct bat_attribute bat_attr_##_name = { \ + .attr = {.name = __stringify(_name), \ + .mode = _mode }, \ + .show = _show, \ + .store = _store, \ +}; + +static ssize_t show_aggr_ogms (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct device *dev =to_dev (kobj->parent); +struct bat_priv *bat_priv =netdev_priv (to_net_dev (dev)); +int aggr_status =atomic_read (&bat_priv->aggregation_enabled); + +return sprintf (buff,"%s\n" , + aggr_status ==0 ?"disabled" :"enabled" ); +} + +static ssize_t store_aggr_ogms (struct kobject *kobj,struct attribute *attr, +char *buff,size_t count) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct bat_priv *bat_priv =netdev_priv (net_dev); +int aggr_tmp =-1 ; + +if (((count ==2 ) && (buff[0 ] =='1' )) || + (strncmp (buff,"enable" ,6 ) ==0 )) + aggr_tmp =1 ; + +if (((count ==2 ) && (buff[0 ] =='0' )) || + (strncmp (buff,"disable" ,7 ) ==0 )) + aggr_tmp =0 ; + +if (aggr_tmp <0 ) { +if (buff[count -1 ] =='\n' ) + buff[count -1 ] ='\0' ; + +bat_info (net_dev, +"Invalid parameter for 'aggregate OGM' setting" +"received: %s\n" , buff); +return -EINVAL ; + } + +if (atomic_read (&bat_priv->aggregation_enabled) == aggr_tmp) +return count; + +bat_info (net_dev,"Changing aggregation from: %s to: %s\n" , +atomic_read (&bat_priv->aggregation_enabled) ==1 ? +"enabled" :"disabled" , aggr_tmp ==1 ?"enabled" : +"disabled" ); + +atomic_set (&bat_priv->aggregation_enabled, (unsigned )aggr_tmp); +return count; +} + +static ssize_t show_bond (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct device *dev =to_dev (kobj->parent); +struct bat_priv *bat_priv =netdev_priv (to_net_dev (dev)); +int bond_status =atomic_read (&bat_priv->bonding_enabled); + +return sprintf (buff,"%s\n" , + bond_status ==0 ?"disabled" :"enabled" ); +} + +static ssize_t store_bond (struct kobject *kobj,struct attribute *attr, +char *buff,size_t count) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct bat_priv *bat_priv =netdev_priv (net_dev); +int bonding_enabled_tmp =-1 ; + +if (((count ==2 ) && (buff[0 ] =='1' )) || + (strncmp (buff,"enable" ,6 ) ==0 )) + bonding_enabled_tmp =1 ; + +if (((count ==2 ) && (buff[0 ] =='0' )) || + (strncmp (buff,"disable" ,7 ) ==0 )) + bonding_enabled_tmp =0 ; + +if (bonding_enabled_tmp <0 ) { +if (buff[count -1 ] =='\n' ) + buff[count -1 ] ='\0' ; + +bat_err (net_dev, +"Invalid parameter for 'bonding' setting received: " +"%s\n" , buff); +return -EINVAL ; + } + +if (atomic_read (&bat_priv->bonding_enabled) == bonding_enabled_tmp) +return count; + +bat_info (net_dev,"Changing bonding from: %s to: %s\n" , +atomic_read (&bat_priv->bonding_enabled) ==1 ? +"enabled" :"disabled" , + bonding_enabled_tmp ==1 ?"enabled" :"disabled" ); + +atomic_set (&bat_priv->bonding_enabled, (unsigned )bonding_enabled_tmp); +return count; +} + +static ssize_t show_frag (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct device *dev =to_dev (kobj->parent); +struct bat_priv *bat_priv =netdev_priv (to_net_dev (dev)); +int frag_status =atomic_read (&bat_priv->frag_enabled); + +return sprintf (buff,"%s\n" , + frag_status ==0 ?"disabled" :"enabled" ); +} + +static ssize_t store_frag (struct kobject *kobj,struct attribute *attr, +char *buff,size_t count) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct bat_priv *bat_priv =netdev_priv (net_dev); +int frag_enabled_tmp =-1 ; + +if (((count ==2 ) && (buff[0 ] =='1' )) || + (strncmp (buff,"enable" ,6 ) ==0 )) + frag_enabled_tmp =1 ; + +if (((count ==2 ) && (buff[0 ] =='0' )) || + (strncmp (buff,"disable" ,7 ) ==0 )) + frag_enabled_tmp =0 ; + +if (frag_enabled_tmp <0 ) { +if (buff[count -1 ] =='\n' ) + buff[count -1 ] ='\0' ; + +bat_err (net_dev, +"Invalid parameter for 'fragmentation' setting on mesh" +"received: %s\n" , buff); +return -EINVAL ; + } + +if (atomic_read (&bat_priv->frag_enabled) == frag_enabled_tmp) +return count; + +bat_info (net_dev,"Changing fragmentation from: %s to: %s\n" , +atomic_read (&bat_priv->frag_enabled) ==1 ? +"enabled" :"disabled" , + frag_enabled_tmp ==1 ?"enabled" :"disabled" ); + +atomic_set (&bat_priv->frag_enabled, (unsigned )frag_enabled_tmp); +update_min_mtu (net_dev); +return count; +} + +static ssize_t show_vis_mode (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct device *dev =to_dev (kobj->parent); +struct bat_priv *bat_priv =netdev_priv (to_net_dev (dev)); +int vis_mode =atomic_read (&bat_priv->vis_mode); + +return sprintf (buff,"%s\n" , + vis_mode ==VIS_TYPE_CLIENT_UPDATE ? +"client" :"server" ); +} + +static ssize_t store_vis_mode (struct kobject *kobj,struct attribute *attr, +char *buff,size_t count) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct bat_priv *bat_priv =netdev_priv (net_dev); +unsigned long val; +int ret, vis_mode_tmp =-1 ; + + ret =strict_strtoul (buff,10 , &val); + +if (((count ==2 ) && (!ret) && (val ==VIS_TYPE_CLIENT_UPDATE )) || + (strncmp (buff,"client" ,6 ) ==0 ) || + (strncmp (buff,"off" ,3 ) ==0 )) + vis_mode_tmp =VIS_TYPE_CLIENT_UPDATE ; + +if (((count ==2 ) && (!ret) && (val ==VIS_TYPE_SERVER_SYNC )) || + (strncmp (buff,"server" ,6 ) ==0 )) + vis_mode_tmp =VIS_TYPE_SERVER_SYNC ; + +if (vis_mode_tmp <0 ) { +if (buff[count -1 ] =='\n' ) + buff[count -1 ] ='\0' ; + +bat_info (net_dev, +"Invalid parameter for 'vis mode' setting received: " +"%s\n" , buff); +return -EINVAL ; + } + +if (atomic_read (&bat_priv->vis_mode) == vis_mode_tmp) +return count; + +bat_info (net_dev,"Changing vis mode from: %s to: %s\n" , +atomic_read (&bat_priv->vis_mode) ==VIS_TYPE_CLIENT_UPDATE ? +"client" :"server" , vis_mode_tmp ==VIS_TYPE_CLIENT_UPDATE ? +"client" :"server" ); + +atomic_set (&bat_priv->vis_mode, (unsigned )vis_mode_tmp); +return count; +} + +static ssize_t show_orig_interval (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct device *dev =to_dev (kobj->parent); +struct bat_priv *bat_priv =netdev_priv (to_net_dev (dev)); + +return sprintf (buff,"%i\n" , +atomic_read (&bat_priv->orig_interval)); +} + +static ssize_t store_orig_interval (struct kobject *kobj,struct attribute *attr, +char *buff,size_t count) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct bat_priv *bat_priv =netdev_priv (net_dev); +unsigned long orig_interval_tmp; +int ret; + + ret =strict_strtoul (buff,10 , &orig_interval_tmp); +if (ret) { +bat_info (net_dev,"Invalid parameter for 'orig_interval' " +"setting received: %s\n" , buff); +return -EINVAL ; + } + +if (orig_interval_tmp <JITTER *2 ) { +bat_info (net_dev,"New originator interval too small: %li " +"(min: %i)\n" , orig_interval_tmp,JITTER *2 ); +return -EINVAL ; + } + +if (atomic_read (&bat_priv->orig_interval) == orig_interval_tmp) +return count; + +bat_info (net_dev,"Changing originator interval from: %i to: %li\n" , +atomic_read (&bat_priv->orig_interval), + orig_interval_tmp); + +atomic_set (&bat_priv->orig_interval, orig_interval_tmp); +return count; +} + +#ifdef CONFIG_BATMAN_ADV_DEBUG +static ssize_t show_log_level (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct device *dev =to_dev (kobj->parent); +struct bat_priv *bat_priv =netdev_priv (to_net_dev (dev)); +int log_level =atomic_read (&bat_priv->log_level); + +return sprintf (buff,"%d\n" , log_level); +} + +static ssize_t store_log_level (struct kobject *kobj,struct attribute *attr, +char *buff,size_t count) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct bat_priv *bat_priv =netdev_priv (net_dev); +unsigned long log_level_tmp; +int ret; + + ret =strict_strtoul (buff,10 , &log_level_tmp); +if (ret) { +bat_info (net_dev,"Invalid parameter for 'log_level' " +"setting received: %s\n" , buff); +return -EINVAL ; + } + +if (log_level_tmp >3 ) { +bat_info (net_dev,"New log level too big: %li " +"(max: %i)\n" , log_level_tmp,3 ); +return -EINVAL ; + } + +if (atomic_read (&bat_priv->log_level) == log_level_tmp) +return count; + +bat_info (net_dev,"Changing log level from: %i to: %li\n" , +atomic_read (&bat_priv->log_level), + log_level_tmp); + +atomic_set (&bat_priv->log_level, (unsigned )log_level_tmp); +return count; +} +#endif + +static BAT_ATTR(aggregated_ogms, S_IRUGO | S_IWUSR, + show_aggr_ogms, store_aggr_ogms); +static BAT_ATTR(bonding, S_IRUGO | S_IWUSR, show_bond, store_bond); +static BAT_ATTR(fragmentation, S_IRUGO | S_IWUSR, show_frag, store_frag); +static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode); +static BAT_ATTR(orig_interval, S_IRUGO | S_IWUSR, + show_orig_interval, store_orig_interval); +#ifdef CONFIG_BATMAN_ADV_DEBUG +static BAT_ATTR(log_level, S_IRUGO | S_IWUSR, show_log_level, store_log_level); +#endif + +static struct bat_attribute *mesh_attrs[] = { + &bat_attr_aggregated_ogms, + &bat_attr_bonding, + &bat_attr_fragmentation, + &bat_attr_vis_mode, + &bat_attr_orig_interval, +#ifdef CONFIG_BATMAN_ADV_DEBUG + &bat_attr_log_level, +#endif +NULL , +}; + +int sysfs_add_meshif (struct net_device *dev) +{ +struct kobject *batif_kobject = &dev->dev.kobj; +struct bat_priv *bat_priv =netdev_priv (dev); +struct bat_attribute **bat_attr; +int err; + + bat_priv->mesh_obj =kobject_create_and_add (SYSFS_IF_MESH_SUBDIR , + batif_kobject); +if (!bat_priv->mesh_obj) { +bat_err (dev,"Can't add sysfs directory: %s/%s\n" , dev->name, +SYSFS_IF_MESH_SUBDIR ); + goto out; + } + +for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr) { + err =sysfs_create_file (bat_priv->mesh_obj, + &((*bat_attr)->attr)); +if (err) { +bat_err (dev,"Can't add sysfs file: %s/%s/%s\n" , + dev->name,SYSFS_IF_MESH_SUBDIR , + ((*bat_attr)->attr).name); + goto rem_attr; + } + } + +return 0 ; + +rem_attr: +for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr) +sysfs_remove_file (bat_priv->mesh_obj, &((*bat_attr)->attr)); + +kobject_put (bat_priv->mesh_obj); + bat_priv->mesh_obj =NULL ; +out: +return -ENOMEM ; +} + +void sysfs_del_meshif (struct net_device *dev) +{ +struct bat_priv *bat_priv =netdev_priv (dev); +struct bat_attribute **bat_attr; + +for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr) +sysfs_remove_file (bat_priv->mesh_obj, &((*bat_attr)->attr)); + +kobject_put (bat_priv->mesh_obj); + bat_priv->mesh_obj =NULL ; +} + +static ssize_t show_mesh_iface (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct batman_if *batman_if =get_batman_if_by_netdev (net_dev); + +if (!batman_if) +return 0 ; + +return sprintf (buff,"%s\n" , + batman_if->if_status ==IF_NOT_IN_USE ? +"none" : batman_if->soft_iface->name); +} + +static ssize_t store_mesh_iface (struct kobject *kobj,struct attribute *attr, +char *buff,size_t count) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct batman_if *batman_if =get_batman_if_by_netdev (net_dev); +int status_tmp =-1 ; + +if (!batman_if) +return count; + +if (buff[count -1 ] =='\n' ) + buff[count -1 ] ='\0' ; + +if (strlen (buff) >=IFNAMSIZ ) { +pr_err ("Invalid parameter for 'mesh_iface' setting received: " +"interface name too long '%s'\n" , buff); +return -EINVAL ; + } + +if (strncmp (buff,"none" ,4 ) ==0 ) + status_tmp =IF_NOT_IN_USE ; +else + status_tmp =IF_I_WANT_YOU ; + +if ((batman_if->if_status == status_tmp) || ((batman_if->soft_iface) && + (strncmp (batman_if->soft_iface->name, buff,IFNAMSIZ ) ==0 ))) +return count; + +if (status_tmp ==IF_NOT_IN_USE ) { +rtnl_lock (); +hardif_disable_interface (batman_if); +rtnl_unlock (); +return count; + } + +/* if the interface already is in use */ +if (batman_if->if_status !=IF_NOT_IN_USE ) { +rtnl_lock (); +hardif_disable_interface (batman_if); +rtnl_unlock (); + } + +return hardif_enable_interface (batman_if, buff); +} + +static ssize_t show_iface_status (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct device *dev =to_dev (kobj->parent); +struct net_device *net_dev =to_net_dev (dev); +struct batman_if *batman_if =get_batman_if_by_netdev (net_dev); + +if (!batman_if) +return 0 ; + +switch (batman_if->if_status) { +case IF_TO_BE_REMOVED : +return sprintf (buff,"disabling\n" ); +case IF_INACTIVE : +return sprintf (buff,"inactive\n" ); +case IF_ACTIVE : +return sprintf (buff,"active\n" ); +case IF_TO_BE_ACTIVATED : +return sprintf (buff,"enabling\n" ); +case IF_NOT_IN_USE : +default : +return sprintf (buff,"not in use\n" ); + } +} + +static BAT_ATTR(mesh_iface, S_IRUGO | S_IWUSR, + show_mesh_iface, store_mesh_iface); +static BAT_ATTR(iface_status, S_IRUGO, show_iface_status, NULL); + +static struct bat_attribute *batman_attrs[] = { + &bat_attr_mesh_iface, + &bat_attr_iface_status, +NULL , +}; + +int sysfs_add_hardif (struct kobject **hardif_obj,struct net_device *dev) +{ +struct kobject *hardif_kobject = &dev->dev.kobj; +struct bat_attribute **bat_attr; +int err; + + *hardif_obj =kobject_create_and_add (SYSFS_IF_BAT_SUBDIR , + hardif_kobject); + +if (!*hardif_obj) { +bat_err (dev,"Can't add sysfs directory: %s/%s\n" , dev->name, +SYSFS_IF_BAT_SUBDIR ); + goto out; + } + +for (bat_attr = batman_attrs; *bat_attr; ++bat_attr) { + err =sysfs_create_file (*hardif_obj, &((*bat_attr)->attr)); +if (err) { +bat_err (dev,"Can't add sysfs file: %s/%s/%s\n" , + dev->name,SYSFS_IF_BAT_SUBDIR , + ((*bat_attr)->attr).name); + goto rem_attr; + } + } + +return 0 ; + +rem_attr: +for (bat_attr = batman_attrs; *bat_attr; ++bat_attr) +sysfs_remove_file (*hardif_obj, &((*bat_attr)->attr)); +out: +return -ENOMEM ; +} + +void sysfs_del_hardif (struct kobject **hardif_obj) +{ +kobject_put (*hardif_obj); + *hardif_obj =NULL ; +}net/batman-adv/bat_sysfs.h new file +42
-0@@ -0,0 +1,42 @@ +/* +* Copyright (C) 2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + + +#ifndef _NET_BATMAN_ADV_SYSFS_H_ +#define _NET_BATMAN_ADV_SYSFS_H_ + +#define SYSFS_IF_MESH_SUBDIR "mesh" +#define SYSFS_IF_BAT_SUBDIR "batman_adv" + +struct bat_attribute { +struct attribute attr; +ssize_t (*show)(struct kobject *kobj,struct attribute *attr, +char *buf); +ssize_t (*store)(struct kobject *kobj,struct attribute *attr, +char *buf,size_t count); +}; + +int sysfs_add_meshif (struct net_device *dev); +void sysfs_del_meshif (struct net_device *dev); +int sysfs_add_hardif (struct kobject **hardif_obj,struct net_device *dev); +void sysfs_del_hardif (struct kobject **hardif_obj); + +#endif /* _NET_BATMAN_ADV_SYSFS_H_ */ net/batman-adv/bitarray.c new file +201
-0@@ -0,0 +1,201 @@ +/* +* Copyright (C) 2006-2010 B.A.T.M.A.N. contributors: +* +* Simon Wunderlich, Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#include "main.h" +#include "bitarray.h" + +#include <linux/bitops.h> + +/* returns true if the corresponding bit in the given seq_bits indicates true +* and curr_seqno is within range of last_seqno */ +uint8_t get_bit_status (TYPE_OF_WORD *seq_bits,uint32_t last_seqno, +uint32_t curr_seqno) +{ +int32_t diff, word_offset, word_num; + + diff = last_seqno - curr_seqno; +if (diff <0 || diff >=TQ_LOCAL_WINDOW_SIZE ) { +return 0 ; + }else { +/* which word */ + word_num = (last_seqno - curr_seqno) /WORD_BIT_SIZE ; +/* which position in the selected word */ + word_offset = (last_seqno - curr_seqno) %WORD_BIT_SIZE ; + +if (seq_bits[word_num] &1 << word_offset) +return 1 ; +else +return 0 ; + } +} + +/* turn corresponding bit on, so we can remember that we got the packet */ +void bit_mark (TYPE_OF_WORD *seq_bits,int32_t n) +{ +int32_t word_offset, word_num; + +/* if too old, just drop it */ +if (n <0 || n >=TQ_LOCAL_WINDOW_SIZE ) +return ; + +/* which word */ + word_num = n /WORD_BIT_SIZE ; +/* which position in the selected word */ + word_offset = n %WORD_BIT_SIZE ; + + seq_bits[word_num] |=1 << word_offset;/* turn the position on */ +} + +/* shift the packet array by n places. */ +static void bit_shift (TYPE_OF_WORD *seq_bits,int32_t n) +{ +int32_t word_offset, word_num; +int32_t i; + +if (n <=0 || n >=TQ_LOCAL_WINDOW_SIZE ) +return ; + + word_offset = n %WORD_BIT_SIZE ;/* shift how much inside each word */ + word_num = n /WORD_BIT_SIZE ;/* shift over how much (full) words */ + +for (i =NUM_WORDS -1 ; i > word_num; i--) { +/* going from old to new, so we don't overwrite the data we copy +* from. +* +* left is high, right is low: FEDC BA98 7654 3210 +* ^^ ^^ +* vvvv +* ^^^^ = from, vvvvv =to, we'd have word_num==1 and +* word_offset==WORD_BIT_SIZE/2 ????? in this example. +* (=24 bits) +* +* our desired output would be: 9876 5432 1000 0000 +* */ + + seq_bits[i] = + (seq_bits[i - word_num] << word_offset) + +/* take the lower port from the left half, shift it left +* to its final position */ + (seq_bits[i - word_num -1 ] >> + (WORD_BIT_SIZE -word_offset)); +/* and the upper part of the right half and shift it left to +* it's position */ +/* for our example that would be: word[0] = 9800 + 0076 = +* 9876 */ + } +/* now for our last word, i==word_num, we only have the it's "left" +* half. that's the 1000 word in our example.*/ + + seq_bits[i] = (seq_bits[i - word_num] << word_offset); + +/* pad the rest with 0, if there is anything */ + i--; + +for (; i >=0 ; i--) + seq_bits[i] =0 ; +} + +static void bit_reset_window (TYPE_OF_WORD *seq_bits) +{ +int i; +for (i =0 ; i <NUM_WORDS ; i++) + seq_bits[i] =0 ; +} + + +/* receive and process one packet within the sequence number window. +* +* returns: +* 1 if the window was moved (either new or very old) +* 0 if the window was not moved/shifted. +*/ +char bit_get_packet (void *priv,TYPE_OF_WORD *seq_bits, +int32_t seq_num_diff,int8_t set_mark) +{ +struct bat_priv *bat_priv = (struct bat_priv *)priv; + +/* sequence number is slightly older. We already got a sequence number +* higher than this one, so we just mark it. */ + +if ((seq_num_diff <=0 ) && (seq_num_diff > -TQ_LOCAL_WINDOW_SIZE )) { +if (set_mark) +bit_mark (seq_bits, -seq_num_diff); +return 0 ; + } + +/* sequence number is slightly newer, so we shift the window and +* set the mark if required */ + +if ((seq_num_diff >0 ) && (seq_num_diff <TQ_LOCAL_WINDOW_SIZE )) { +bit_shift (seq_bits, seq_num_diff); + +if (set_mark) +bit_mark (seq_bits,0 ); +return 1 ; + } + +/* sequence number is much newer, probably missed a lot of packets */ + +if ((seq_num_diff >=TQ_LOCAL_WINDOW_SIZE ) + || (seq_num_diff <EXPECTED_SEQNO_RANGE )) { +bat_dbg (DBG_BATMAN , bat_priv, +"We missed a lot of packets (%i) !\n" , + seq_num_diff -1 ); +bit_reset_window (seq_bits); +if (set_mark) +bit_mark (seq_bits,0 ); +return 1 ; + } + +/* received a much older packet. The other host either restarted +* or the old packet got delayed somewhere in the network. The +* packet should be dropped without calling this function if the +* seqno window is protected. */ + +if ((seq_num_diff <= -TQ_LOCAL_WINDOW_SIZE ) + || (seq_num_diff >=EXPECTED_SEQNO_RANGE )) { + +bat_dbg (DBG_BATMAN , bat_priv, +"Other host probably restarted!\n" ); + +bit_reset_window (seq_bits); +if (set_mark) +bit_mark (seq_bits,0 ); + +return 1 ; + } + +/* never reached */ +return 0 ; +} + +/* count the hamming weight, how many good packets did we receive? just count +* the 1's. +*/ +int bit_packet_count (TYPE_OF_WORD *seq_bits) +{ +int i, hamming =0 ; + +for (i =0 ; i <NUM_WORDS ; i++) + hamming +=hweight_long (seq_bits[i]); + +return hamming; +}net/batman-adv/bitarray.h new file +47
-0@@ -0,0 +1,47 @@ +/* +* Copyright (C) 2006-2010 B.A.T.M.A.N. contributors: +* +* Simon Wunderlich, Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#ifndef _NET_BATMAN_ADV_BITARRAY_H_ +#define _NET_BATMAN_ADV_BITARRAY_H_ + +/* you should choose something big, if you don't want to waste cpu +and keep the type in sync with bit_packet_count */ +#define TYPE_OF_WORD unsigned long +#define WORD_BIT_SIZE (sizeof(TYPE_OF_WORD) * 8) + +/* returns true if the corresponding bit in the given seq_bits indicates true +* and curr_seqno is within range of last_seqno */ +uint8_t get_bit_status (TYPE_OF_WORD *seq_bits,uint32_t last_seqno, +uint32_t curr_seqno); + +/* turn corresponding bit on, so we can remember that we got the packet */ +void bit_mark (TYPE_OF_WORD *seq_bits,int32_t n); + + +/* receive and process one packet, returns 1 if received seq_num is considered +* new, 0 if old */ +char bit_get_packet (void *priv,TYPE_OF_WORD *seq_bits, +int32_t seq_num_diff,int8_t set_mark); + +/* count the hamming weight, how many good packets did we receive? */ +int bit_packet_count (TYPE_OF_WORD *seq_bits); + +#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */ net/batman-adv/hard-interface.c new file +39
-0@@ -0,0 +1,596 @@ +/* +* Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner, Simon Wunderlich +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#include "main.h" +#include "hard-interface.h" +#include "soft-interface.h" +#include "send.h" +#include "translation-table.h" +#include "routing.h" +#include "bat_sysfs.h" +#include "originator.h" +#include "hash.h" + +#include <linux/if_arp.h> + +#define MIN (x, y) ((x) < (y) ? (x) : (y)) + +struct batman_if *get_batman_if_by_netdev (struct net_device *net_dev) +{ +struct batman_if *batman_if; +
net/batman-adv/hard-interface.c line 49
Quoted 10 lines
net/batman-adv/hard-interface.c new file +10
-0+rcu_read_lock (); +list_for_each_entry_rcu (batman_if, &if_list, list) { +if (batman_if->net_dev == net_dev) + goto out; + } + + batman_if =NULL ; + +out: +rcu_read_unlock ();
Here we are leaking an RCU-protected pointer outside of the RCU read-side critical section. Why is this safe?
Here is the sequence of events that I am concerned about:
1. CPU 0 executes the code above, obtains a pointer, and is about
ready to return.
2. CPU 1 executes hardif_remove_interface(), and calls
hardif_disable_interface(), which calls hardif_deactivate_interface(), which sets ->if_status to IF_INACTIVE. Then hardif_disable_interface() sets ->if_status to IF_NOT_IN_USE. Then hardif_remove_interface() frees the interface via call_rcu().
3. Of course, call_rcu() waits for an RCU grace period to elapse,
but we are no longer in an RCU read-side critical section, so there is nothing stopping the grace period from completing before we are done with the batman_if pointer.
Or am I missing some other interlock that prevents hardif_remove_interface() from freeing this structure?
I have similar concerns with your other RCU read-side critical sections.
Quoted 7,266 lines
net/batman-adv/hard-interface.c new file +547
-0+return batman_if; +} + +static int is_valid_iface (struct net_device *net_dev) +{ +if (net_dev->flags &IFF_LOOPBACK ) +return 0 ; + +if (net_dev->type !=ARPHRD_ETHER ) +return 0 ; + +if (net_dev->addr_len !=ETH_ALEN ) +return 0 ; + +/* no batman over batman */ +#ifdef HAVE_NET_DEVICE_OPS +if (net_dev->netdev_ops->ndo_start_xmit == interface_tx) +return 0 ; +#else +if (net_dev->hard_start_xmit == interface_tx) +return 0 ; +#endif + +/* Device is being bridged */ +/* if (net_dev->priv_flags & IFF_BRIDGE_PORT) +return 0; */ + +return 1 ; +} + +static struct batman_if *get_active_batman_if (struct net_device *soft_iface) +{ +struct batman_if *batman_if; + +rcu_read_lock (); +list_for_each_entry_rcu (batman_if, &if_list, list) { +if (batman_if->soft_iface != soft_iface) +continue ; + +if (batman_if->if_status ==IF_ACTIVE ) + goto out; + } + + batman_if =NULL ; + +out: +rcu_read_unlock (); +return batman_if; +} + +static void set_primary_if (struct bat_priv *bat_priv, +struct batman_if *batman_if) +{ +struct batman_packet *batman_packet; +struct vis_packet *vis_packet; + + bat_priv->primary_if = batman_if; + +if (!bat_priv->primary_if) +return ; + + batman_packet = (struct batman_packet *)(batman_if->packet_buff); + batman_packet->flags =PRIMARIES_FIRST_HOP ; + batman_packet->ttl =TTL ; + + vis_packet = (struct vis_packet *) + bat_priv->my_vis_info->skb_packet->data; +memcpy (vis_packet->vis_orig, + bat_priv->primary_if->net_dev->dev_addr,ETH_ALEN ); +memcpy (vis_packet->sender_orig, + bat_priv->primary_if->net_dev->dev_addr,ETH_ALEN ); + +/*** +* hacky trick to make sure that we send the HNA information via +* our new primary interface +*/ +atomic_set (&bat_priv->hna_local_changed,1 ); +} + +static bool hardif_is_iface_up (struct batman_if *batman_if) +{ +if (batman_if->net_dev->flags &IFF_UP ) +return true; + +return false; +} + +static void update_mac_addresses (struct batman_if *batman_if) +{ +addr_to_string (batman_if->addr_str, batman_if->net_dev->dev_addr); + +memcpy (((struct batman_packet *)(batman_if->packet_buff))->orig, + batman_if->net_dev->dev_addr,ETH_ALEN ); +memcpy (((struct batman_packet *)(batman_if->packet_buff))->prev_sender, + batman_if->net_dev->dev_addr,ETH_ALEN ); +} + +static void check_known_mac_addr (uint8_t *addr) +{ +struct batman_if *batman_if; + +rcu_read_lock (); +list_for_each_entry_rcu (batman_if, &if_list, list) { +if ((batman_if->if_status !=IF_ACTIVE ) && + (batman_if->if_status !=IF_TO_BE_ACTIVATED )) +continue ; + +if (!compare_orig (batman_if->net_dev->dev_addr, addr)) +continue ; + +pr_warning ("The newly added mac address (%pM) already exists " +"on: %s\n" , addr, batman_if->net_dev->name); +pr_warning ("It is strongly recommended to keep mac addresses " +"unique to avoid problems!\n" ); + } +rcu_read_unlock (); +} + +int hardif_min_mtu (struct net_device *soft_iface) +{ +struct bat_priv *bat_priv =netdev_priv (soft_iface); +struct batman_if *batman_if; +/* allow big frames if all devices are capable to do so +* (have MTU > 1500 + BAT_HEADER_LEN) */ +int min_mtu =ETH_DATA_LEN ; + +if (atomic_read (&bat_priv->frag_enabled)) + goto out; + +rcu_read_lock (); +list_for_each_entry_rcu (batman_if, &if_list, list) { +if ((batman_if->if_status !=IF_ACTIVE ) && + (batman_if->if_status !=IF_TO_BE_ACTIVATED )) +continue ; + +if (batman_if->soft_iface != soft_iface) +continue ; + + min_mtu =MIN (batman_if->net_dev->mtu -BAT_HEADER_LEN , + min_mtu); + } +rcu_read_unlock (); +out: +return min_mtu; +} + +/* adjusts the MTU if a new interface with a smaller MTU appeared. */ +void update_min_mtu (struct net_device *soft_iface) +{ +int min_mtu; + + min_mtu =hardif_min_mtu (soft_iface); +if (soft_iface->mtu != min_mtu) + soft_iface->mtu = min_mtu; +} + +static void hardif_activate_interface (struct batman_if *batman_if) +{ +struct bat_priv *bat_priv; + +if (batman_if->if_status !=IF_INACTIVE ) +return ; + + bat_priv =netdev_priv (batman_if->soft_iface); + +update_mac_addresses (batman_if); + batman_if->if_status =IF_TO_BE_ACTIVATED ; + +/** +* the first active interface becomes our primary interface or +* the next active interface after the old primay interface was removed +*/ +if (!bat_priv->primary_if) +set_primary_if (bat_priv, batman_if); + +bat_info (batman_if->soft_iface,"Interface activated: %s\n" , + batman_if->net_dev->name); + +update_min_mtu (batman_if->soft_iface); +return ; +} + +static void hardif_deactivate_interface (struct batman_if *batman_if) +{ +if ((batman_if->if_status !=IF_ACTIVE ) && + (batman_if->if_status !=IF_TO_BE_ACTIVATED )) +return ; + + batman_if->if_status =IF_INACTIVE ; + +bat_info (batman_if->soft_iface,"Interface deactivated: %s\n" , + batman_if->net_dev->name); + +update_min_mtu (batman_if->soft_iface); +} + +int hardif_enable_interface (struct batman_if *batman_if,char *iface_name) +{ +struct bat_priv *bat_priv; +struct batman_packet *batman_packet; + +if (batman_if->if_status !=IF_NOT_IN_USE ) + goto out; + + batman_if->soft_iface =dev_get_by_name (&init_net, iface_name); + +if (!batman_if->soft_iface) { + batman_if->soft_iface =softif_create (iface_name); + +if (!batman_if->soft_iface) + goto err; + +/* dev_get_by_name() increases the reference counter for us */ +dev_hold (batman_if->soft_iface); + } + + bat_priv =netdev_priv (batman_if->soft_iface); + batman_if->packet_len =BAT_PACKET_LEN ; + batman_if->packet_buff =kmalloc (batman_if->packet_len,GFP_ATOMIC ); + +if (!batman_if->packet_buff) { +bat_err (batman_if->soft_iface,"Can't add interface packet " +"(%s): out of memory\n" , batman_if->net_dev->name); + goto err; + } + + batman_packet = (struct batman_packet *)(batman_if->packet_buff); + batman_packet->packet_type =BAT_PACKET ; + batman_packet->version =COMPAT_VERSION ; + batman_packet->flags =0 ; + batman_packet->ttl =2 ; + batman_packet->tq =TQ_MAX_VALUE ; + batman_packet->num_hna =0 ; + + batman_if->if_num = bat_priv->num_ifaces; + bat_priv->num_ifaces++; + batman_if->if_status =IF_INACTIVE ; +orig_hash_add_if (batman_if, bat_priv->num_ifaces); + + batman_if->batman_adv_ptype.type =__constant_htons (ETH_P_BATMAN ); + batman_if->batman_adv_ptype.func = batman_skb_recv; + batman_if->batman_adv_ptype.dev = batman_if->net_dev; +dev_add_pack (&batman_if->batman_adv_ptype); + +atomic_set (&batman_if->seqno,1 ); +atomic_set (&batman_if->frag_seqno,1 ); +bat_info (batman_if->soft_iface,"Adding interface: %s\n" , + batman_if->net_dev->name); + +if (atomic_read (&bat_priv->frag_enabled) && batman_if->net_dev->mtu < +ETH_DATA_LEN +BAT_HEADER_LEN ) +bat_info (batman_if->soft_iface, +"The MTU of interface %s is too small (%i) to handle " +"the transport of batman-adv packets. Packets going " +"over this interface will be fragmented on layer2 " +"which could impact the performance. Setting the MTU " +"to %zi would solve the problem.\n" , + batman_if->net_dev->name, batman_if->net_dev->mtu, +ETH_DATA_LEN +BAT_HEADER_LEN ); + +if (!atomic_read (&bat_priv->frag_enabled) && batman_if->net_dev->mtu < +ETH_DATA_LEN +BAT_HEADER_LEN ) +bat_info (batman_if->soft_iface, +"The MTU of interface %s is too small (%i) to handle " +"the transport of batman-adv packets. If you experience" +" problems getting traffic through try increasing the " +"MTU to %zi.\n" , + batman_if->net_dev->name, batman_if->net_dev->mtu, +ETH_DATA_LEN +BAT_HEADER_LEN ); + +if (hardif_is_iface_up (batman_if)) +hardif_activate_interface (batman_if); +else +bat_err (batman_if->soft_iface,"Not using interface %s " +"(retrying later): interface not active\n" , + batman_if->net_dev->name); + +/* begin scheduling originator messages on that interface */ +schedule_own_packet (batman_if); + +out: +return 0 ; + +err: +return -ENOMEM ; +} + +void hardif_disable_interface (struct batman_if *batman_if) +{ +struct bat_priv *bat_priv =netdev_priv (batman_if->soft_iface); + +if (batman_if->if_status ==IF_ACTIVE ) +hardif_deactivate_interface (batman_if); + +if (batman_if->if_status !=IF_INACTIVE ) +return ; + +bat_info (batman_if->soft_iface,"Removing interface: %s\n" , + batman_if->net_dev->name); +dev_remove_pack (&batman_if->batman_adv_ptype); + + bat_priv->num_ifaces--; +orig_hash_del_if (batman_if, bat_priv->num_ifaces); + +if (batman_if == bat_priv->primary_if) +set_primary_if (bat_priv, +get_active_batman_if (batman_if->soft_iface)); + +kfree (batman_if->packet_buff); + batman_if->packet_buff =NULL ; + batman_if->if_status =IF_NOT_IN_USE ; + +/* delete all references to this batman_if */ +purge_orig_ref (bat_priv); +purge_outstanding_packets (bat_priv, batman_if); +dev_put (batman_if->soft_iface); + +/* nobody uses this interface anymore */ +if (!bat_priv->num_ifaces) +softif_destroy (batman_if->soft_iface); + + batman_if->soft_iface =NULL ; +} + +static struct batman_if *hardif_add_interface (struct net_device *net_dev) +{ +struct batman_if *batman_if; +int ret; + + ret =is_valid_iface (net_dev); +if (ret !=1 ) + goto out; + +dev_hold (net_dev); + + batman_if =kmalloc (sizeof (struct batman_if ),GFP_ATOMIC ); +if (!batman_if) { +pr_err ("Can't add interface (%s): out of memory\n" , + net_dev->name); + goto release_dev; + } + + ret =sysfs_add_hardif (&batman_if->hardif_obj, net_dev); +if (ret) + goto free_if; + + batman_if->if_num =-1 ; + batman_if->net_dev = net_dev; + batman_if->soft_iface =NULL ; + batman_if->if_status =IF_NOT_IN_USE ; +INIT_LIST_HEAD (&batman_if->list); + +check_known_mac_addr (batman_if->net_dev->dev_addr); +list_add_tail_rcu (&batman_if->list, &if_list); +return batman_if; + +free_if: +kfree (batman_if); +release_dev: +dev_put (net_dev); +out: +return NULL ; +} + +static void hardif_free_interface (struct rcu_head *rcu) +{ + struct batman_if *batman_if = container_of(rcu, struct batman_if, rcu); + +kfree (batman_if); +} + +static void hardif_remove_interface (struct batman_if *batman_if) +{ +/* first deactivate interface */ +if (batman_if->if_status !=IF_NOT_IN_USE ) +hardif_disable_interface (batman_if); + +if (batman_if->if_status !=IF_NOT_IN_USE ) +return ; + + batman_if->if_status =IF_TO_BE_REMOVED ; +list_del_rcu (&batman_if->list); +sysfs_del_hardif (&batman_if->hardif_obj); +dev_put (batman_if->net_dev); +call_rcu (&batman_if->rcu, hardif_free_interface); +} + +void hardif_remove_interfaces (void ) +{ +struct batman_if *batman_if, *batman_if_tmp; + +list_for_each_entry_safe (batman_if, batman_if_tmp, &if_list, list) { +rtnl_lock (); +hardif_remove_interface (batman_if); +rtnl_unlock (); + } +} + +static int hard_if_event (struct notifier_block *this, +unsigned long event,void *ptr) +{ +struct net_device *net_dev = (struct net_device *)ptr; +struct batman_if *batman_if =get_batman_if_by_netdev (net_dev); +struct bat_priv *bat_priv; + +if (!batman_if && event ==NETDEV_REGISTER ) + batman_if =hardif_add_interface (net_dev); + +if (!batman_if) + goto out; + +switch (event) { +case NETDEV_UP : +hardif_activate_interface (batman_if); +break ; +case NETDEV_GOING_DOWN : +case NETDEV_DOWN : +hardif_deactivate_interface (batman_if); +break ; +case NETDEV_UNREGISTER : +hardif_remove_interface (batman_if); +break ; +case NETDEV_CHANGEMTU : +if (batman_if->soft_iface) +update_min_mtu (batman_if->soft_iface); +break ; +case NETDEV_CHANGEADDR : +if (batman_if->if_status ==IF_NOT_IN_USE ) + goto out; + +check_known_mac_addr (batman_if->net_dev->dev_addr); +update_mac_addresses (batman_if); + + bat_priv =netdev_priv (batman_if->soft_iface); +if (batman_if == bat_priv->primary_if) +set_primary_if (bat_priv, batman_if); +break ; +default : +break ; + }; + +out: +return NOTIFY_DONE ; +} + +/* receive a packet with the batman ethertype coming on a hard +* interface */ +int batman_skb_recv (struct sk_buff *skb,struct net_device *dev, +struct packet_type *ptype,struct net_device *orig_dev) +{ +struct bat_priv *bat_priv; +struct batman_packet *batman_packet; +struct batman_if *batman_if; +int ret; + + batman_if = container_of(ptype, struct batman_if, batman_adv_ptype); + skb =skb_share_check (skb,GFP_ATOMIC ); + +/* skb was released by skb_share_check() */ +if (!skb) + goto err_out; + +/* packet should hold at least type and version */ +if (unlikely (!pskb_may_pull (skb,2 ))) + goto err_free; + +/* expect a valid ethernet header here. */ +if (unlikely (skb->mac_len !=sizeof (struct ethhdr ) + || !skb_mac_header (skb))) + goto err_free; + +if (!batman_if->soft_iface) + goto err_free; + + bat_priv =netdev_priv (batman_if->soft_iface); + +if (atomic_read (&bat_priv->mesh_state) !=MESH_ACTIVE ) + goto err_free; + +/* discard frames on not active interfaces */ +if (batman_if->if_status !=IF_ACTIVE ) + goto err_free; + + batman_packet = (struct batman_packet *)skb->data; + +if (batman_packet->version !=COMPAT_VERSION ) { +bat_dbg (DBG_BATMAN , bat_priv, +"Drop packet: incompatible batman version (%i)\n" , + batman_packet->version); + goto err_free; + } + +/* all receive handlers return whether they received or reused +* the supplied skb. if not, we have to free the skb. */ + +switch (batman_packet->packet_type) { +/* batman originator packet */ +case BAT_PACKET : + ret =recv_bat_packet (skb, batman_if); +break ; + +/* batman icmp packet */ +case BAT_ICMP : + ret =recv_icmp_packet (skb, batman_if); +break ; + +/* unicast packet */ +case BAT_UNICAST : + ret =recv_unicast_packet (skb, batman_if); +break ; + +/* fragmented unicast packet */ +case BAT_UNICAST_FRAG : + ret =recv_ucast_frag_packet (skb, batman_if); +break ; + +/* broadcast packet */ +case BAT_BCAST : + ret =recv_bcast_packet (skb, batman_if); +break ; + +/* vis packet */ +case BAT_VIS : + ret =recv_vis_packet (skb, batman_if); +break ; +default : + ret =NET_RX_DROP ; + } + +if (ret ==NET_RX_DROP ) +kfree_skb (skb); + +/* return NET_RX_SUCCESS in any case as we +* most probably dropped the packet for +* routing-logical reasons. */ + +return NET_RX_SUCCESS ; + +err_free: +kfree_skb (skb); +err_out: +return NET_RX_DROP ; +} + +struct notifier_block hard_if_notifier = { + .notifier_call = hard_if_event, +};net/batman-adv/hard-interface.h new file +45
-0@@ -0,0 +1,45 @@ +/* +* Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner, Simon Wunderlich +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_ +#define _NET_BATMAN_ADV_HARD_INTERFACE_H_ + +#define IF_NOT_IN_USE 0 +#define IF_TO_BE_REMOVED 1 +#define IF_INACTIVE 2 +#define IF_ACTIVE 3 +#define IF_TO_BE_ACTIVATED 4 +#define IF_I_WANT_YOU 5 + +extern struct notifier_block hard_if_notifier; + +struct batman_if *get_batman_if_by_netdev (struct net_device *net_dev); +int hardif_enable_interface (struct batman_if *batman_if,char *iface_name); +void hardif_disable_interface (struct batman_if *batman_if); +void hardif_remove_interfaces (void ); +int batman_skb_recv (struct sk_buff *skb, +struct net_device *dev, +struct packet_type *ptype, +struct net_device *orig_dev); +int hardif_min_mtu (struct net_device *soft_iface); +void update_min_mtu (struct net_device *soft_iface); + +#endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */ net/batman-adv/hash.c new file +306
-0@@ -0,0 +1,306 @@ +/* +* Copyright (C) 2006-2010 B.A.T.M.A.N. contributors: +* +* Simon Wunderlich, Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#include "main.h" +#include "hash.h" + +/* clears the hash */ +static void hash_init (struct hashtable_t *hash) +{ +int i; + + hash->elements =0 ; + +for (i =0 ; i < hash->size; i++) + hash->table[i] =NULL ; +} + +/* remove the hash structure. if hashdata_free_cb != NULL, this function will be +* called to remove the elements inside of the hash. if you don't remove the +* elements, memory might be leaked. */ +void hash_delete (struct hashtable_t *hash,hashdata_free_cb free_cb,void *arg) +{ +struct element_t *bucket, *last_bucket; +int i; + +for (i =0 ; i < hash->size; i++) { + bucket = hash->table[i]; + +while (bucket !=NULL ) { +if (free_cb !=NULL ) +free_cb (bucket->data, arg); + + last_bucket = bucket; + bucket = bucket->next; +kfree (last_bucket); + } + } + +hash_destroy (hash); +} + +/* free only the hashtable and the hash itself. */ +void hash_destroy (struct hashtable_t *hash) +{ +kfree (hash->table); +kfree (hash); +} + +/* iterate though the hash. First element is selected if an iterator +* initialized with HASHIT() is supplied as iter. Use the returned +* (or supplied) iterator to access the elements until hash_iterate returns +* NULL. */ + +struct hash_it_t *hash_iterate (struct hashtable_t *hash, +struct hash_it_t *iter) +{ +if (!hash) +return NULL ; +if (!iter) +return NULL ; + +/* sanity checks first (if our bucket got deleted in the last +* iteration): */ +if (iter->bucket !=NULL ) { +if (iter->first_bucket !=NULL ) { +/* we're on the first element and it got removed after +* the last iteration. */ +if ((*iter->first_bucket) != iter->bucket) { +/* there are still other elements in the list */ +if ((*iter->first_bucket) !=NULL ) { + iter->prev_bucket =NULL ; + iter->bucket = (*iter->first_bucket); + iter->first_bucket = + &hash->table[iter->index]; +return iter; + }else { + iter->bucket =NULL ; + } + } + }else if (iter->prev_bucket !=NULL ) { +/* +* we're not on the first element, and the bucket got +* removed after the last iteration. the last bucket's +* next pointer is not pointing to our actual bucket +* anymore. select the next. +*/ +if (iter->prev_bucket->next != iter->bucket) + iter->bucket = iter->prev_bucket; + } + } + +/* now as we are sane, select the next one if there is some */ +if (iter->bucket !=NULL ) { +if (iter->bucket->next !=NULL ) { + iter->prev_bucket = iter->bucket; + iter->bucket = iter->bucket->next; + iter->first_bucket =NULL ; +return iter; + } + } + +/* if not returned yet, we've reached the last one on the index and have +* to search forward */ + iter->index++; +/* go through the entries of the hash table */ +while (iter->index < hash->size) { +if ((hash->table[iter->index]) !=NULL ) { + iter->prev_bucket =NULL ; + iter->bucket = hash->table[iter->index]; + iter->first_bucket = &hash->table[iter->index]; +return iter; + }else { + iter->index++; + } + } + +/* nothing to iterate over anymore */ +return NULL ; +} + +/* allocates and clears the hash */ +struct hashtable_t *hash_new (int size,hashdata_compare_cb compare, +hashdata_choose_cb choose) +{ +struct hashtable_t *hash; + + hash =kmalloc (sizeof (struct hashtable_t ) ,GFP_ATOMIC ); + +if (hash ==NULL ) +return NULL ; + + hash->size = size; + hash->table =kmalloc (sizeof (struct element_t *) * size,GFP_ATOMIC ); + +if (hash->table ==NULL ) { +kfree (hash); +return NULL ; + } + +hash_init (hash); + + hash->compare = compare; + hash->choose = choose; + +return hash; +} + +/* adds data to the hashtable. returns 0 on success, -1 on error */ +int hash_add (struct hashtable_t *hash,void *data) +{ +int index; +struct element_t *bucket, *prev_bucket =NULL ; + +if (!hash) +return -1 ; + + index = hash->choose (data, hash->size); + bucket = hash->table[index]; + +while (bucket !=NULL ) { +if (hash->compare (bucket->data, data)) +return -1 ; + + prev_bucket = bucket; + bucket = bucket->next; + } + +/* found the tail of the list, add new element */ + bucket =kmalloc (sizeof (struct element_t ),GFP_ATOMIC ); + +if (bucket ==NULL ) +return -1 ; + + bucket->data = data; + bucket->next =NULL ; + +/* and link it */ +if (prev_bucket ==NULL ) + hash->table[index] = bucket; +else + prev_bucket->next = bucket; + + hash->elements++; +return 0 ; +} + +/* finds data, based on the key in keydata. returns the found data on success, +* or NULL on error */ +void *hash_find (struct hashtable_t *hash,void *keydata) +{ +int index; +struct element_t *bucket; + +if (!hash) +return NULL ; + + index = hash->choose (keydata , hash->size); + bucket = hash->table[index]; + +while (bucket !=NULL ) { +if (hash->compare (bucket->data, keydata)) +return bucket->data; + + bucket = bucket->next; + } + +return NULL ; +} + +/* remove bucket (this might be used in hash_iterate() if you already found the +* bucket you want to delete and don't need the overhead to find it again with +* hash_remove(). But usually, you don't want to use this function, as it +* fiddles with hash-internals. */ +void *hash_remove_bucket (struct hashtable_t *hash,struct hash_it_t *hash_it_t) +{ +void *data_save; + + data_save = hash_it_t->bucket->data; + +if (hash_it_t->prev_bucket !=NULL ) + hash_it_t->prev_bucket->next = hash_it_t->bucket->next; +else if (hash_it_t->first_bucket !=NULL ) + (*hash_it_t->first_bucket) = hash_it_t->bucket->next; + +kfree (hash_it_t->bucket); + hash->elements--; + +return data_save; +} + +/* removes data from hash, if found. returns pointer do data on success, so you +* can remove the used structure yourself, or NULL on error . data could be the +* structure you use with just the key filled, we just need the key for +* comparing. */ +void *hash_remove (struct hashtable_t *hash,void *data) +{ +struct hash_it_t hash_it_t; + + hash_it_t.index = hash->choose (data, hash->size); + hash_it_t.bucket = hash->table[hash_it_t.index]; + hash_it_t.prev_bucket =NULL ; + +while (hash_it_t.bucket !=NULL ) { +if (hash->compare (hash_it_t.bucket->data, data)) { + hash_it_t.first_bucket = + (hash_it_t.bucket == + hash->table[hash_it_t.index] ? + &hash->table[hash_it_t.index] :NULL ); +return hash_remove_bucket (hash, &hash_it_t); + } + + hash_it_t.prev_bucket = hash_it_t.bucket; + hash_it_t.bucket = hash_it_t.bucket->next; + } + +return NULL ; +} + +/* resize the hash, returns the pointer to the new hash or NULL on +* error. removes the old hash on success. */ +struct hashtable_t *hash_resize (struct hashtable_t *hash,int size) +{ +struct hashtable_t *new_hash; +struct element_t *bucket; +int i; + +/* initialize a new hash with the new size */ + new_hash =hash_new (size, hash->compare, hash->choose); + +if (new_hash ==NULL ) +return NULL ; + +/* copy the elements */ +for (i =0 ; i < hash->size; i++) { + bucket = hash->table[i]; + +while (bucket !=NULL ) { +hash_add (new_hash, bucket->data); + bucket = bucket->next; + } + } + +/* remove hash and eventual overflow buckets but not the content +* itself. */ +hash_delete (hash,NULL ,NULL ); + +return new_hash; +}net/batman-adv/hash.h new file +100
-0@@ -0,0 +1,100 @@ +/* +* Copyright (C) 2006-2010 B.A.T.M.A.N. contributors: +* +* Simon Wunderlich, Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#ifndef _NET_BATMAN_ADV_HASH_H_ +#define _NET_BATMAN_ADV_HASH_H_ + +#define HASHIT (name) struct hash_it_t name = { \ + .index = -1, .bucket = NULL, \ + .prev_bucket = NULL, \ + .first_bucket = NULL } + + +typedef int (*hashdata_compare_cb )(void *,void *); +typedef int (*hashdata_choose_cb )(void *,int ); +typedef void (*hashdata_free_cb )(void *,void *); + +struct element_t { +void *data;/* pointer to the data */ +struct element_t *next;/* overflow bucket pointer */ +}; + +struct hash_it_t { +int index; +struct element_t *bucket; +struct element_t *prev_bucket; +struct element_t **first_bucket; +}; + +struct hashtable_t { +struct element_t **table;/* the hashtable itself, with the buckets */ +int elements;/* number of elements registered */ +int size;/* size of hashtable */ +hashdata_compare_cb compare;/* callback to a compare function. should +* compare 2 element datas for their keys, +* return 0 if same and not 0 if not +* same */ +hashdata_choose_cb choose;/* the hashfunction, should return an index +* based on the key in the data of the first +* argument and the size the second */ +}; + +/* allocates and clears the hash */ +struct hashtable_t *hash_new (int size,hashdata_compare_cb compare, +hashdata_choose_cb choose); + +/* remove bucket (this might be used in hash_iterate() if you already found the +* bucket you want to delete and don't need the overhead to find it again with +* hash_remove(). But usually, you don't want to use this function, as it +* fiddles with hash-internals. */ +void *hash_remove_bucket (struct hashtable_t *hash,struct hash_it_t *hash_it_t); + +/* remove the hash structure. if hashdata_free_cb != NULL, this function will be +* called to remove the elements inside of the hash. if you don't remove the +* elements, memory might be leaked. */ +void hash_delete (struct hashtable_t *hash,hashdata_free_cb free_cb,void *arg); + +/* free only the hashtable and the hash itself. */ +void hash_destroy (struct hashtable_t *hash); + +/* adds data to the hashtable. returns 0 on success, -1 on error */ +int hash_add (struct hashtable_t *hash,void *data); + +/* removes data from hash, if found. returns pointer do data on success, so you +* can remove the used structure yourself, or NULL on error . data could be the +* structure you use with just the key filled, we just need the key for +* comparing. */ +void *hash_remove (struct hashtable_t *hash,void *data); + +/* finds data, based on the key in keydata. returns the found data on success, +* or NULL on error */ +void *hash_find (struct hashtable_t *hash,void *keydata); + +/* resize the hash, returns the pointer to the new hash or NULL on +* error. removes the old hash on success */ +struct hashtable_t *hash_resize (struct hashtable_t *hash,int size); + +/* iterate though the hash. first element is selected with iter_in NULL. use +* the returned iterator to access the elements until hash_it_t returns NULL. */ +struct hash_it_t *hash_iterate (struct hashtable_t *hash, +struct hash_it_t *iter_in); + +#endif /* _NET_BATMAN_ADV_HASH_H_ */ net/batman-adv/icmp_socket.c new file +356
-0@@ -0,0 +1,356 @@ +/* +* Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA +* +*/ + +#include "main.h" +#include <linux/debugfs.h> +#include <linux/slab.h> +#include "icmp_socket.h" +#include "send.h" +#include "types.h" +#include "hash.h" +#include "hard-interface.h" + + +static struct socket_client *socket_client_hash[256 ]; + +static void bat_socket_add_packet (struct socket_client *socket_client, +struct icmp_packet_rr *icmp_packet, +size_t icmp_len); + +void bat_socket_init (void ) +{ +memset (socket_client_hash,0 ,sizeof (socket_client_hash)); +} + +static int bat_socket_open (struct inode *inode,struct file *file) +{ +unsigned int i; +struct socket_client *socket_client; + + socket_client =kmalloc (sizeof (struct socket_client ),GFP_KERNEL ); + +if (!socket_client) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (socket_client_hash); i++) { +if (!socket_client_hash[i]) { + socket_client_hash[i] = socket_client; +break ; + } + } + +if (i ==ARRAY_SIZE (socket_client_hash)) { +pr_err ("Error - can't add another packet client: " +"maximum number of clients reached\n" ); +kfree (socket_client); +return -EXFULL ; + } + +INIT_LIST_HEAD (&socket_client->queue_list); + socket_client->queue_len =0 ; + socket_client->index = i; + socket_client->bat_priv = inode->i_private; +spin_lock_init (&socket_client->lock); +init_waitqueue_head (&socket_client->queue_wait); + + file->private_data = socket_client; + +inc_module_count (); +return 0 ; +} + +static int bat_socket_release (struct inode *inode,struct file *file) +{Lines of this file are not shown. View the raw message.
net/batman-adv/soft-interface.c new file +395
-0Lines of this file are not shown. View the raw message.
net/batman-adv/soft-interface.h new file +32
-0Lines of this file are not shown. View the raw message.
net/batman-adv/translation-table.c new file +513
-0Lines of this file are not shown. View the raw message.
net/batman-adv/translation-table.h new file +45
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Part of the diff is not shown here. View the raw message.
Thanks for your comment. I removed the parts you don't refer to (makes it lot easier to find the actual comment).
Quoted 14 lines · Paul E. McKenney
Quoted 14 lines
net/batman-adv/hard-interface.c new file +14
-0+ +#include <linux/if_arp.h> + +#define MIN (x, y) ((x) < (y) ? (x) : (y)) + +struct batman_if *get_batman_if_by_netdev (struct net_device *net_dev) +{ +struct batman_if *batman_if; + +rcu_read_lock (); +list_for_each_entry_rcu (batman_if, &if_list, list) { +if (batman_if->net_dev == net_dev) + goto out; + }
Quoted 8 lines
net/batman-adv/hard-interface.c line 49
Quoted 5 lines
net/batman-adv/hard-interface.c new file +5
-0+ + batman_if =NULL ; + +out: +rcu_read_unlock ();Here we are leaking an RCU-protected pointer outside of the RCU read-side critical section. Why is this safe?
First thing: Their is another rcu related problem with a call_rcu and the missing explicit (so not done implizit by another function) synchronize_rcu before the shutdown. This was fixed right after this patch was send for a review... bad timing, but ok.
Quoted 17 lines
Here is the sequence of events that I am concerned about:
1. CPU 0 executes the code above, obtains a pointer, and is about
ready to return.2. CPU 1 executes
hardif_remove_interface(), and calls
hardif_disable_interface(), which callshardif_deactivate_interface(), which sets ->if_status toIF_INACTIVE. Thenhardif_disable_interface()sets ->if_status toIF_NOT_IN_USE. Thenhardif_remove_interface()frees the interface viacall_rcu().3. Of course,
call_rcu()waits for an RCU grace period to elapse,
but we are no longer in an RCU read-side critical section, so there is nothing stopping the grace period from completing before we are done with thebatman_ifpointer.
Quoted 4 lines
Or am I missing some other interlock that prevents
hardif_remove_interface()from freeing this structure?I have similar concerns with your other RCU read-side critical sections.
Looks to me like a valid point. I have to think a little bit how to solve it correctly. Feel free to add more comments about other rcu cruelties in it.
thanks,
Sven
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · Sven Eckelmann
Thanks for your comment. I removed the parts you don't refer to (makes it lot easier to find the actual comment).
I guess I can always refer to the original to see the related code. ;-)
Quoted 24 lines
Quoted 14 lines · Paul E. McKenney
Quoted 14 lines
net/batman-adv/hard-interface.c new file +14
-0+ +#include <linux/if_arp.h> + +#define MIN (x, y) ((x) < (y) ? (x) : (y)) + +struct batman_if *get_batman_if_by_netdev (struct net_device *net_dev) +{ +struct batman_if *batman_if; + +rcu_read_lock (); +list_for_each_entry_rcu (batman_if, &if_list, list) { +if (batman_if->net_dev == net_dev) + goto out; + }Quoted 8 lines
net/batman-adv/hard-interface.c line 49
Quoted 5 lines
net/batman-adv/hard-interface.c new file +5
-0+ + batman_if =NULL ; + +out: +rcu_read_unlock ();Here we are leaking an RCU-protected pointer outside of the RCU read-side critical section. Why is this safe?
Quoted 4 lines
First thing: Their is another rcu related problem with a
call_rcuand the missing explicit (so not done implizit by another function)synchronize_rcubefore the shutdown. This was fixed right after this patch was send for a review... bad timing, but ok.
Fair enough!
Quoted 17 lines
Quoted 17 lines
Here is the sequence of events that I am concerned about:
1. CPU 0 executes the code above, obtains a pointer, and is about
ready to return.2. CPU 1 executes
hardif_remove_interface(), and calls
hardif_disable_interface(), which callshardif_deactivate_interface(), which sets ->if_status toIF_INACTIVE. Thenhardif_disable_interface()sets ->if_status toIF_NOT_IN_USE. Thenhardif_remove_interface()frees the interface viacall_rcu().3. Of course,
call_rcu()waits for an RCU grace period to elapse,
but we are no longer in an RCU read-side critical section, so there is nothing stopping the grace period from completing before we are done with thebatman_ifpointer.
Quoted 7 lines
Quoted 4 lines
Or am I missing some other interlock that prevents
hardif_remove_interface()from freeing this structure?I have similar concerns with your other RCU read-side critical sections.
Looks to me like a valid point. I have to think a little bit how to solve it correctly. Feel free to add more comments about other rcu cruelties in it.
One approach would be to extend the RCU read-side critical section to cover all uses of the RCU-protected pointer. Another approach would be to take a reference count (or something similar) before the pointer leaves the RCU read-side critical section.
Could you please take a look at Documentation/RCU/checklist.txt?
Because I am not familiar with the BATMAN device, it is all too easy for me to miss subtleties in the code.
Thanx, Paul
A message that is not in the archive (sent off-list or not yet received): 20100907181000.GF2448-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Paul E. McKenney wrote:
[..]
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
I have similar concerns with your other RCU read-side critical sections.
Looks to me like a valid point. I have to think a little bit how to solve it correctly. Feel free to add more comments about other rcu cruelties in it.
One approach would be to extend the RCU read-side critical section to cover all uses of the RCU-protected pointer. Another approach would be to take a reference count (or something similar) before the pointer leaves the RCU read-side critical section.
I am not the author of the rcu related functionality (it was one of the actual
maintainers: Simon Wunderlich), but would guess that the rcu protected "critical section" will be extended.
Quoted 4 lines
Could you please take a look at
Documentation/RCU/checklist.txt?Because I am not familiar with the BATMAN device, it is all too easy for me to miss subtleties in the code.
Yes, will be done (will probably end in reading all the rcu documentation). But it is really nice that you checked the code for your area of interest.
thanks,
Sven
Quoted 4 lines · Sven Eckelmann
B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is a routing protocol for multi-hop ad-hoc mesh networks. The networks may be wired or wireless. See http://www.open-mesh.org/ for more information and user space tools.
It seems rather unusual to have the complete routing protocol in kernel. And this is a lot of code. The normal way to do such things is to have the routing policy etc. in a user daemon and only let the kernel provide some services to this.
Could you elaborate a bit why this approach was not chosen?
I assume if it needs a switch it could have a switching "hot path" layer in kernel and the policy somewhere else.
You write
Documentation/networking/batman-adv.txt line 18
Quoted 2 lines
Documentation/networking/batman-adv.txt new file +2
-0+Batman advanced was implemented as a Linux kernel driver to re- +duce the overhead to a minimum. It does not depend on any (other)
What overhead exactly?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Hi,
here are some raw references without any judgment. Maybe Marek will send some more information about that topic later.
Quoted 11 lines · Andi Kleen
Quoted 4 lines · Sven Eckelmann
B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is a routing protocol for multi-hop ad-hoc mesh networks. The networks may be wired or wireless. See http://www.open-mesh.org/ for more information and user space tools.
It seems rather unusual to have the complete routing protocol in kernel. And this is a lot of code. The normal way to do such things is to have the routing policy etc. in a user daemon and only let the kernel provide some services to this.
Quoted 4 lines
Could you elaborate a bit why this approach was not chosen?
I assume if it needs a switch it could have a switching "hot path" layer in kernel and the policy somewhere else.
https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-July/003119.html
https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-July/003120.html
https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-July/003121.html
Just as note: the mentioned parts which move to the userspace or stays inside the kernel doesn't include the parts which must be added as interface for other kernel modules/userspace daemon.
Quoted 6 lines
You write
Documentation/networking/batman-adv.txt line 18
Quoted 2 lines
Documentation/networking/batman-adv.txt new file +2
-0+Batman advanced was implemented as a Linux kernel driver to re- +duce the overhead to a minimum. It does not depend on any (other)What overhead exactly?
https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2010-June/003029.html
So the mentioned overhead was related to throughput and latency of the actual data packets send over the complete userspace implementation (receiving stuff, getting stuff from kernel, modifying it, putting it back in the kernel, sending it).
Best regards,
Sven
Quoted 21 lines · Sven Eckelmann
Hi,
here are some raw references without any judgment. Maybe Marek will send some more information about that topic later.
Quoted 15 lines · Andi Kleen
Quoted 4 lines · Sven Eckelmann
B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is a routing protocol for multi-hop ad-hoc mesh networks. The networks may be wired or wireless. See http://www.open-mesh.org/ for more information and user space tools.
It seems rather unusual to have the complete routing protocol in kernel. And this is a lot of code. The normal way to do such things is to have the routing policy etc. in a user daemon and only let the kernel provide some services to this.
Could you elaborate a bit why this approach was not chosen?
I assume if it needs a switch it could have a switching "hot path" layer in kernel and the policy somewhere else.
Potentially one way to do this is to build on top of Open vSwitch. It contains a pretty generic flow-based kernel module for forwarding data packets and making simple modifications. Control packets can be sent to userspace to handle the routing logic, while data packets remain in the kernel for performance. This would dramatically reduce the amount of code that needs to be in the kernel and may even help performance by simplifying the fast path.
I don't know the details of your protocol well enough to know if this is feasible but it seems like something you might want to look into. Open vSwitch is currently in the process of finalizing its interfaces to prepare for upstreaming.
A message that is not in the archive (sent off-list or not yet received): AANLkTimnBqkiO26wqEQOm+AgSJgQLtQmAe8R-kB6CqtZ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 1 line · Jesse Gross
On Wed, Sep 8, 2010 at 2:42 AM, Sven Eckelmann <[email protected]>
Quoted 30 lines · wrote:
Quoted 21 lines
Hi,
here are some raw references without any judgment. Maybe Marek will send some more information about that topic later.
Quoted 15 lines · Andi Kleen
Quoted 4 lines · Sven Eckelmann
B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is a routing protocol for multi-hop ad-hoc mesh networks. The networks may be wired or wireless. See http://www.open-mesh.org/ for more information and user space tools.
It seems rather unusual to have the complete routing protocol in kernel. And this is a lot of code. The normal way to do such things is to have the routing policy etc. in a user daemon and only let the kernel provide some services to this.
Could you elaborate a bit why this approach was not chosen?
I assume if it needs a switch it could have a switching "hot path" layer in kernel and the policy somewhere else.
Potentially one way to do this is to build on top of Open vSwitch. It contains a pretty generic flow-based kernel module for forwarding data packets and making simple modifications. Control packets can be sent to userspace to handle the routing logic, while data packets remain in the kernel for performance. This would dramatically reduce the amount of code that needs to be in the kernel and may even help performance by simplifying the fast path.
Quoted 4 lines
I don't know the details of your protocol well enough to know if this is feasible but it seems like something you might want to look into. Open vSwitch is currently in the process of finalizing its interfaces to prepare for upstreaming.
It sounds interesting. I haven't looked into it yet, but maybe you could easily answer some questions:
* Does it allow to generate multiple net_devices on the system?
* Does it allow to attach multiple net_devices to a single openvswitch device?
* Does the attaching of a net_device to a openvswitch device prevent it to be added to another openvswitch device?
* Does it propagate the information about the incoming device to the userspace in case of the not routed packets (everything which should
* Does it allow to append extra header information to the packet?
* Does it allow fragmentation of packets (not real fragmentation, but more single split)?
* Does it allow to define outgoing patterns (on which attached interface goes the thing out again) on packet number or incoming device (the real hardware device it was coming in)?
* Is it possible to define rules like: "If this is a broadcast of an udp/ip packet with target port 123 which may or may not have a vlan tag, but is coming directly from the virtual device and is not routed by us, then change the mac address to following"?
* Can it be backported to old kernels (~2.6.21 - yes, their are "customers" who need even older kernels due to the fantastic vendors out their)?
Thanks,
Sven
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Sven Eckelmann
Quoted 8 lines · Jesse Gross
Potentially one way to do this is to build on top of Open vSwitch. It contains a pretty generic flow-based kernel module for forwarding data packets and making simple modifications. Control packets can be sent to userspace to handle the routing logic, while data packets remain in the kernel for performance. This would dramatically reduce the amount of code that needs to be in the kernel and may even help performance by simplifying the fast path.
Quoted 8 lines
Quoted 4 lines
I don't know the details of your protocol well enough to know if this is feasible but it seems like something you might want to look into. Open vSwitch is currently in the process of finalizing its interfaces to prepare for upstreaming.
It sounds interesting. I haven't looked into it yet, but maybe you could easily answer some questions:
* Does it allow to generate multiplenet_deviceson the system?
Yes.
Quoted 2 lines
* Does it allow to attach multiple
net_devicesto a single openvswitch device?
Yes.
Quoted 2 lines
* Does the attaching of a
net_deviceto a openvswitch device prevent it to be added to another openvswitch device?
It can be set up in different ways, depending on the desired behavior.
Quoted 2 lines
* Does it propagate the information about the incoming device to the userspace in case of the not routed packets (everything which should
I think the last part of your question got cut off. However, packets do include metadata about the input device. Userspace would then be able to use the normal Linux mechanisms to find out whatever it needs (or look at its own information).
Quoted 3 lines
* Does it allow to append extra header information to the packet?
* Does it allow fragmentation of packets (not real fragmentation, but more single split)?
I'm assuming that both of these questions are for tunneling. Open vSwitch currently supports a few different L2 over L3 tunneling mechanisms and has a tunnel library that makes adding additional protocols easy. It probably can't do exactly what you need right now, but it should be fairly easy to extend.
Quoted 3 lines
* Does it allow to define outgoing patterns (on which attached interface goes the thing out again) on packet number or incoming device (the real hardware device it was coming in)?
I'm not sure what you mean by "packet number". It does allow you to specify the output interface based on a number of factors, include the input device.
Quoted 4 lines
* Is it possible to define rules like: "If this is a broadcast of an udp/ip packet with target port 123 which may or may not have a vlan tag, but is coming directly from the virtual device and is not routed by us, then change the mac address to following"?
Yes.
Quoted 2 lines
* Can it be backported to old kernels (~2.6.21 - yes, their are "customers" who need even older kernels due to the fantastic vendors out their)?
The kernel module currently supports 2.6.18+.
A message that is not in the archive (sent off-list or not yet received): AANLkTi=FVyLE6OHTd+_qDbzSLk6fY5j6wBOWkYA810Dj-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Jesse Gross wrote:
[...]
Quoted 4 lines
Quoted 2 lines
* Does it propagate the information about the incoming device to the userspace in case of the not routed packets (everything which should
I think the last part of your question got cut off.
Or I simple was distracted and didn't finish the sentence. :)
Quoted 9 lines
However, packets
do include metadata about the input device. Userspace would then be able to use the normal Linux mechanisms to find out whatever it needs (or look at its own information).Quoted 3 lines
* Does it allow to append extra header information to the packet?
* Does it allow fragmentation of packets (not real fragmentation, but
more single split)?
Quoted 5 lines
I'm assuming that both of these questions are for tunneling. Open vSwitch currently supports a few different L2 over L3 tunneling mechanisms and has a tunnel library that makes adding additional protocols easy. It probably can't do exactly what you need right now, but it should be fairly easy to extend.
Hm, low overhead tunneling is one of the main parts, but if you think that it is easy to extend then fine.
Quoted 7 lines
Quoted 3 lines
* Does it allow to define outgoing patterns (on which attached interface goes the thing out again) on packet number or incoming device (the real hardware device it was coming in)?
I'm not sure what you mean by "packet number". It does allow you to specify the output interface based on a number of factors, include the input device.
It would mean that for example 5 packets goes over device 1, the next 5 packets goes over
Quoted 1 line
Quoted 1 line
* directly influence the traffic flow, i.e., ARQ for broadcasts,
Could you please comment on that one (taken from Mareks mail). Think about that one:
* A Broadcast packet must be send over wifi (adhoc)
* This packet is probably dropped due to some interferences. So each node must transmit the broadcast more than one time to be (with a good chance successful). This is quite essential on l2 based adhoc wifi mesh networks (as tests showed - but please ask Marek for the actual test setups)
Quoted 4 lines
There are three basic components that you need running for Open
vSwitch: the main daemon, ovs-vswitchd, a lightweight configuration manager, ovsdb-server, and the kernel module,openvswitch_mod. You would then be able to write a userspace process to communicate with
Quoted 8 lines
the daemons to handle the above. As I mentioned, the encapsulation would likely require some small additions to the kernel module for your particular type of tunneling (unless you are flexible and can use one of the existing mechanisms). However, that would be significantly less kernel code than this patch. As a starting point, I would recommend playing around with Open vSwitch as a normal switch to get a feeling for its operation (see the INSTALL.Linux file in the source distribution for instructions).
Without checking any facts: This sounds a little bit heavy - does it only sound heavy and in reality is extreme slim? The problem is that it must run on those low end, "please don't run code on me, because I cannot crunch numbers and have no ram" machines like the FON2100 or WRT54GL.
thanks,
Sven
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Sven Eckelmann
Jesse Gross wrote:
[...]Quoted 4 lines
I'm not sure what you mean by "packet number". It does allow you to specify the output interface based on a number of factors, include the input device.
It would mean that for example 5 packets goes over device 1, the next 5 packets goes over
I should stop writing mails as I get to easily distracted right now:
... goes over the device 2, the next 5 packets goes over device 3 and the next 5 packets goes over device 1, ...
Maybe other things like "5 over device one, 10 over device 2, 2 over device 3" could be imagined.
thanks,
Sven
Quoted 4 lines · Sven Eckelmann
Without checking any facts: This sounds a little bit heavy - does it only sound heavy and in reality is extreme slim? The problem is that it must run on those low end, "please don't run code on me, because I cannot crunch numbers and have no ram" machines like the FON2100 or WRT54GL.
We used to run early versions of Open vSwitch on the WRTSL54GS (which is only a bit beefier than the WRT54GL) and didn't have any problems. My guess is that it would run even better now, since the code has gone through a number of optimizations. If packets are hitting the kernel cache, it's really only header parsing and a hash lookup, which is pretty cheap.
--Justin
Quoted 4 lines · Sven Eckelmann
Quoted 4 lines
Quoted 3 lines
* Does it allow to append extra header information to the packet?
* Does it allow fragmentation of packets (not real fragmentation, but more single split)?
Quoted 8 lines
Quoted 5 lines
I'm assuming that both of these questions are for tunneling. Open vSwitch currently supports a few different L2 over L3 tunneling mechanisms and has a tunnel library that makes adding additional protocols easy. It probably can't do exactly what you need right now, but it should be fairly easy to extend.
Hm, low overhead tunneling is one of the main parts, but if you think that it is easy to extend then fine.
I understand that tunneling needs to go in the kernel. However, as I said, several tunneling mechanisms already exist in Open vSwitch (maybe one of them even already meets your needs) and adding another one would certainly be less code than the approximately 9000 lines that this patch entails.
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
* Does it allow to define outgoing patterns (on which attached interface goes the thing out again) on packet number or incoming device (the real hardware device it was coming in)?
I'm not sure what you mean by "packet number". It does allow you to specify the output interface based on a number of factors, include the input device.
It would mean that for example 5 packets goes over device 1, the next 5 packets goes over
I'm assuming that those packets are from different higher level flows, right? Otherwise you will have significant reordering issues. Assuming that is the case, then yes, this is possible and is how Open vSwitch implements bonding purely in userspace.
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
* directly influence the traffic flow, i.e., ARQ for broadcasts,
Could you please comment on that one (taken from Mareks mail). Think about that one:
* A Broadcast packet must be send over wifi (adhoc)
* This packet is probably dropped due to some interferences. So each node must transmit the broadcast more than one time to be (with a good chance successful). This is quite essential on l2 based adhoc wifi mesh networks (as tests showed - but please ask Marek for the actual test setups)
This isn't something that Open vSwitch currently has support for since it expects the properties of Ethernet, which is best effort, and assumes the upper layers will do any retransmission if desired. However, I know that for lossy wireless networks sometimes this is not sufficient. Open vSwitch has a virtual port abstraction in the kernel that works well for this type of application specific code and is where I would expect you to put your tunneling protocol. I suspect that this may fit in there as well. Again, I understand that there are some areas where the existing Open vSwitch does not exactly fit all of your needs. However, I think that you will find that the parts of the kernel that require extension are actually quite small and well abstracted.
A message that is not in the archive (sent off-list or not yet received): AANLkTim-jswWzG=H0AQP5Z3byxoR1uXoV-ZhdaZ7+Sqd-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Hello,
thank you for your comments. As already said, splitting batman-advanced into a kernel space part for switching and a user space part for making route decision is an already discussed idea which is quite interesting. I wouldn't say that it's completely unusual to decide routing in the kernel, as we see other mesh protocols like 802.11s/HWMP or STP (not really a mesh protocol) integrated in the kernel as well. We have discussed a possible openvswitch port internally with some of the main contributors, and we see the following issues:
Looking at openvswitch, it seems that the target application is very different. batman-adv is targeted to support 802.11 WiFi networks on low-end hardware, while openvswitch was designed as switching environment for virtual machines. This implies different design decisions - batman-adv should be able to run without any additional userspace applications if needed, while openvswitch comes with quite a big, rich featured environment required for operation.
Next to this fact, one thing which worries us is that openvswitch seems to replace quite some standard linux tools/facilities (e.g. the bridge module), which is often used in most of the APs we have seen, along with ebtables and the configuration interfaces it provides. Changing to openvswitch would imply to change the configuration interfaces and firmwares plus educating all our users which depend on those standard tools.
Porting batman-adv to the openvswitch framework would of course require an enormous effort itself. batman-adv as a software which is already "finished", well tested and integrated in various products/firmwares and ready for kernel integration. Porting to openvswitch would mean a step backwards for our project as it is not predictable for us when openvswitch will be finished or integrated in the kernel.
Maybe we should move forward in this direction after openvswitch is settled as the way to go for layer 2 tunneling/abstraction in the Linux kernel, but currently we don't see the benefit for us to port it.
best regards,
Simon
Quoted 7 lines · On Wednesday 08 September 2010 20:22:42 Jesse Gross wrote:
Potentially one way to do this is to build on top of Open vSwitch. It contains a pretty generic flow-based kernel module for forwarding data packets and making simple modifications. Control packets can be sent to userspace to handle the routing logic, while data packets remain in the kernel for performance. This would dramatically reduce the amount of code that needs to be in the kernel and may even help performance by simplifying the fast path.
Thanks for your input.
I had a quick look at the website to get an idea but I had to notice that there is quite a collection of daemons, kernel modules and apps. As you seem involved in this project, could you point us to the collection of tools that you think we would need to achieve the following:
* sending protocol traffic
* transmitting the routing logic
* encapsulation of the various packet types (see http://www.open-mesh.org/browser/trunk/batman-adv/packet.h to get an idea)
* directly influence the traffic flow, i.e., ARQ for broadcasts, interface alternating, bonding, forward error correction, etc
* layer 2 fragmentation
Cheers,
Marek
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 16 lines · Marek Lindner
Quoted 7 lines · On Wednesday 08 September 2010 20:22:42 Jesse Gross wrote:
Potentially one way to do this is to build on top of Open vSwitch. It contains a pretty generic flow-based kernel module for forwarding data packets and making simple modifications. Control packets can be sent to userspace to handle the routing logic, while data packets remain in the kernel for performance. This would dramatically reduce the amount of code that needs to be in the kernel and may even help performance by simplifying the fast path.
Thanks for your input.
I had a quick look at the website to get an idea but I had to notice that there is quite a collection of daemons, kernel modules and apps. As you seem involved in this project, could you point us to the collection of tools that you think we would need to achieve the following:
Quoted 7 lines
* sending protocol traffic
* transmitting the routing logic
* encapsulation of the various packet types (see http://www.open-mesh.org/browser/trunk/batman-adv/packet.hto get an idea)
* directly influence the traffic flow, i.e., ARQ for broadcasts, interface alternating, bonding, forward error correction, etc
* layer 2 fragmentation
There are three basic components that you need running for Open
vSwitch: the main daemon, ovs-vswitchd, a lightweight configuration manager, ovsdb-server, and the kernel module, openvswitch_mod. You would then be able to write a userspace process to communicate with the daemons to handle the above. As I mentioned, the encapsulation would likely require some small additions to the kernel module for your particular type of tunneling (unless you are flexible and can use one of the existing mechanisms). However, that would be significantly less kernel code than this patch. As a starting point, I would recommend playing around with Open vSwitch as a normal switch to get a feeling for its operation (see the INSTALL.Linux file in the source distribution for instructions).