Re: [B.A.T.M.A.N.] [RFC] batman-adv boot setup scheme on OpenWRT

Gui Iribarren
2012-12-02T13:19:44Z

[-- Attachment #1: Type: text/plain, Size: 2124 bytes --]

Really Sorry for the whitespace headaches :( hope to get it straight this time.

As we discussed on irc with Marek, here's a first stab at netifd integration.
I'm surprised at how simple it actually is to add a custom "proto" with netifd

No race condition with this approach, at least on the hardware i have
at hand (ubnt2 , and tplinks)

an example uci config scheme changes from

batman-adv.bat0=mesh
batman-adv.bat0.interfaces='mesh0 mesh1 mesh2'
batman-adv.bat0.bridge_loop_avoidance=1
network.mesh{0,1,2}=interface
network.mesh{0,1,2}.proto=none
network.mesh{0,1,2}.mtu=1528
wireless.@wifi-iface[]=wifi-iface
wireless.@wifi-iface[].network=mesh{0,1,2}
wireless.@wifi-iface[].mode=adhoc

to

batman-adv.bat0=mesh
batman-adv.bat0.bridge_loop_avoidance=1
network.mesh{0,1,2}=interface
network.mesh{0,1,2}.proto=batadv
network.mesh{0,1,2}.mesh=bat0
network.mesh{0,1,2}.mtu=1528
wireless.@wifi-iface[1]=wifi-iface
wireless.@wifi-iface[1].network=mesh{0,1,2}
wireless.@wifi-iface[1].mode=adhoc

So /etc/config/batman-adv now deals only with bat0 tweakable parameters,
/etc/config/network defines interfaces to be added to bat0
and /etc/config/wireless is unchanged

and netifd is responsible of avoiding race conditions
of course, this makes batman-adv package (on openwrt) depend on
netifd, but openwrt devs are pushing it that way (and it's finally
looking like an elegant move after all ;) )

Cheers!

On Mon, Nov 26, 2012 at 7:45 AM, Sven Eckelmann <sven@narfation.org> wrote:
> On Monday 26 November 2012 18:40:20 Marek Lindner wrote:
>> On Friday, November 23, 2012 22:00:47 Gui Iribarren wrote:
>> > Boring bootlog at http://pastebin.com/59FEPttY
>> >
>> > Proposed patch follows (against current batman-adv in openwrt 'packages'
>> > feed)
>> >
>> > Signed-off-by: Gui Iribarren <gui@altermundi.net>
>>
>> I made the necessary changes myself after I successfully de-scrambled your
>> patch. You will find the patch in OpenWrt trunk. Give it try!
>> Next time, please configure your mail client to not wrap lines.
>
> http://lxr.linux.no/linux+v2.6.30/Documentation/email-clients.txt
>
> Kind regards,
> Sven

[-- Attachment #2: batman-adv-netifd-proto-batadv.patch --]
[-- Type: application/octet-stream, Size: 3299 bytes --]

diff --git a/files/etc/config/batman-adv b/files/etc/config/batman-adv
index fb7b384..f775d80 100644
--- a/files/etc/config/batman-adv
+++ b/files/etc/config/batman-adv
@@ -1,6 +1,5 @@

config 'mesh' 'bat0'
- option 'interfaces' 'mesh'
option 'aggregated_ogms'
option 'ap_isolation'
option 'bonding'
diff --git a/files/etc/hotplug.d/iface/99-batman-adv b/files/etc/hotplug.d/iface/99-batman-adv
deleted file mode 100644
index 9206c42..0000000
--- a/files/etc/hotplug.d/iface/99-batman-adv
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-. /lib/batman-adv/config.sh
-
-bat_load_module
-config_load batman-adv
-
-case "$ACTION" in
- ifup)
- [ -d /sys/class/net/$DEVICE/batman_adv/ ] && config_foreach bat_add_interface mesh "$DEVICE"
- ;;
-esac
diff --git a/files/etc/hotplug.d/net/99-batman-adv b/files/etc/hotplug.d/net/99-batman-adv
index 47132c1..f0c391f 100644
--- a/files/etc/hotplug.d/net/99-batman-adv
+++ b/files/etc/hotplug.d/net/99-batman-adv
@@ -9,7 +9,4 @@ case "$ACTION" in
add)
[ -d /sys/class/net/$INTERFACE/mesh/ ] && bat_config "$INTERFACE"
;;
- remove)
- [ -d /sys/class/net/$INTERFACE/batman_adv/ ] && config_foreach bat_del_interface mesh "$INTERFACE"
- ;;
esac
diff --git a/files/lib/batman-adv/config.sh b/files/lib/batman-adv/config.sh
index 313dd3a..d0810b8 100644
--- a/files/lib/batman-adv/config.sh
+++ b/files/lib/batman-adv/config.sh
@@ -41,37 +41,3 @@ bat_config()
[ -n "$ap_isolation" ] && echo $ap_isolation > /sys/class/net/$mesh/mesh/ap_isolation
[ -n "$bridge_loop_avoidance" ] && echo $bridge_loop_avoidance > /sys/class/net/$mesh/mesh/bridge_loop_avoidance
}
-
-bat_add_interface()
-{
- local mesh="$1"
- local interface="$2"
- local interfaces
-
- config_get interfaces $mesh interfaces
- for iface in $interfaces; do
- [ -f "/sys/class/net/$iface/batman_adv/mesh_iface" ] || {
- iface=$(uci -q -P/var/state get network.$iface.ifname)
- [ -f "/sys/class/net/$iface/batman_adv/mesh_iface" ] || continue
- }
-
- [ "$iface" = "$interface" ] && echo $mesh > /sys/class/net/$iface/batman_adv/mesh_iface
- done
-}
-
-bat_del_interface()
-{
- local mesh="$1"
- local interface="$2"
- local interfaces
-
- config_get interfaces $mesh interfaces
- for iface in $interfaces; do
- [ -f "/sys/class/net/$iface/batman_adv/mesh_iface" ] || {
- iface=$(uci -q -P/var/state get network.$iface.ifname)
- [ -f "/sys/class/net/$iface/batman_adv/mesh_iface" ] || continue
- }
-
- [ "$iface" = "$interface" ] && echo none > /sys/class/net/$iface/batman_adv/mesh_iface
- done
-}
diff --git a/files/lib/netifd/proto/batadv.sh b/files/lib/netifd/proto/batadv.sh
new file mode 100755
index 0000000..632a209
--- /dev/null
+++ b/files/lib/netifd/proto/batadv.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto "$@"
+
+proto_batadv_init_config() {
+ proto_config_add_string "mesh"
+}
+
+proto_batadv_setup() {
+ local config="$1"
+ local iface="$2"
+
+ local mesh
+ json_get_vars mesh
+
+ echo "$mesh" > "/sys/class/net/$iface/batman_adv/mesh_iface"
+ proto_init_update "$iface" 1
+ proto_send_update "$config"
+}
+
+proto_batadv_teardown() {
+ local config="$1"
+ local iface="$2"
+
+ echo "none" > "/sys/class/net/$iface/batman_adv/mesh_iface" || true
+}
+
+add_protocol batadv