Repository : ssh://git@open-mesh.org/openwrt-feed-batman-adv
On branch : master
commit e035d4c433b4d2414fb025d4b9bfbac30992e62f Author: Filippo Sallemi tonyputi@gmail.com Date: Thu Nov 24 07:36:35 2011 +0000
batman-adv-devel: hotplug rewrite
The batman-adv-devel package now uses hotplug to enable / disable its interfaces and to load the mesh configuration settings. The previously used batman-adv init script isn't needed any longer. To still offer a convenient way of reloading the batman-adv config the batman-adv script is provided.
Signed-off-by: Filippo Sallemi tonyputi@gmail.com
e035d4c433b4d2414fb025d4b9bfbac30992e62f batman-adv-devel/Makefile | 34 ++--- batman-adv-devel/files/etc/config/batman-adv | 3 + .../files/etc/hotplug.d/net/99-batman-adv | 15 ++ batman-adv-devel/files/etc/init.d/batman-adv | 28 ---- batman-adv-devel/files/lib/batman-adv/config.sh | 148 +++++++------------- batman-adv-devel/files/usr/sbin/batman-adv | 46 ++++++ 6 files changed, 131 insertions(+), 143 deletions(-)
diff --git a/batman-adv-devel/Makefile b/batman-adv-devel/Makefile index 285b807..f54c5da 100644 --- a/batman-adv-devel/Makefile +++ b/batman-adv-devel/Makefile @@ -33,7 +33,7 @@ define KernelPackage/batman-adv-devel URL:=http://www.open-mesh.org/ MAINTAINER:=Marek Lindner lindner_marek@yahoo.de SUBMENU:=Network Support - DEPENDS:=@!LINUX_2_4 +kmod-crc16 + DEPENDS:=+kmod-lib-crc16 TITLE:=B.A.T.M.A.N. Adv devel FILES:=$(PKG_BUILD_DIR)/batman-adv.$(LINUX_KMOD_SUFFIX) AUTOLOAD:=$(call AutoLoad,50,batman-adv) @@ -78,9 +78,10 @@ define Download/batctl endef $(eval $(call Download,batctl))
-EXTRACT_BATCTL = tar xzf "$(DL_DIR)/$(PKG_BATCTL_FNAME)" -C "$(BUILD_DIR)/$(PKG_NAME)" -PATCH_BATCTL = $(call Build/DoPatch,"$(PKG_BATCTL_BUILD_DIR)","$(PATCH_DIR)","*batctl*") -BUILD_BATCTL = $(MAKE) -C $(PKG_BATCTL_BUILD_DIR) $(MAKE_BATCTL_ARGS) +BATCTL_EXTRACT = tar xzf "$(DL_DIR)/$(PKG_BATCTL_FNAME)" -C "$(BUILD_DIR)/$(PKG_NAME)" +BATCTL_PATCH = $(call Build/DoPatch,"$(PKG_BATCTL_BUILD_DIR)","$(PATCH_DIR)","*batctl*") +BATCTL_BUILD = $(MAKE) -C $(PKG_BATCTL_BUILD_DIR) $(MAKE_BATCTL_ARGS) +BATCTL_INSTALL = $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/local/sbin/batctl $(1)/usr/sbin/ endif
KPATCH ?= $(PATCH) @@ -94,36 +95,27 @@ endef
define Build/Patch $(call Build/DoPatch,"$(PKG_BUILD_DIR)","$(PATCH_DIR)","*batman*") - $(EXTRACT_BATCTL) - $(PATCH_BATCTL) + $(BATCTL_EXTRACT) + $(BATCTL_PATCH) endef
define Build/Compile cp $(PKG_BUILD_DIR)/Makefile.kbuild $(PKG_BUILD_DIR)/Makefile $(MAKE) -C "$(LINUX_DIR)" $(MAKE_BATMAN_ADV_ARGS) - $(BUILD_BATCTL) + $(BATCTL_BUILD) endef
define Build/Clean rm -rf $(BUILD_DIR)/$(PKG_NAME)/ endef
-ifneq ($(DEVELOPER)$(CONFIG_KMOD_BATMAN_ADV_DEVEL_BATCTL),) define KernelPackage/batman-adv-devel/install - $(INSTALL_DIR) $(1)/etc/config $(1)/etc/init.d $(1)/lib/batman-adv - $(INSTALL_BIN) ./files/etc/init.d/batman-adv $(1)/etc/init.d - $(INSTALL_BIN) ./files/lib/batman-adv/config.sh $(1)/lib/batman-adv + $(INSTALL_DIR) $(1)/etc/config $(1)/etc/hotplug.d/net $(1)/lib/batman-adv $(1)/usr/sbin $(INSTALL_DATA) ./files/etc/config/batman-adv $(1)/etc/config - $(INSTALL_DIR) $(1)/usr/sbin - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/local/sbin/batctl $(1)/usr/sbin/ + $(INSTALL_DATA) ./files/lib/batman-adv/config.sh $(1)/lib/batman-adv + $(INSTALL_BIN) ./files/etc/hotplug.d/net/99-batman-adv $(1)/etc/hotplug.d/net + $(INSTALL_BIN) ./files/usr/sbin/batman-adv $(1)/usr/sbin + $(BATCTL_INSTALL) endef -else -define KernelPackage/batman-adv-devel/install - $(INSTALL_DIR) $(1)/etc/config $(1)/etc/init.d $(1)/lib/batman-adv - $(INSTALL_BIN) ./files/etc/init.d/batman-adv $(1)/etc/init.d - $(INSTALL_BIN) ./files/lib/batman-adv/config.sh $(1)/lib/batman-adv - $(INSTALL_DATA) ./files/etc/config/batman-adv $(1)/etc/config -endef -endif
$(eval $(call KernelPackage,batman-adv-devel)) diff --git a/batman-adv-devel/files/etc/config/batman-adv b/batman-adv-devel/files/etc/config/batman-adv index 414b119..5197820 100644 --- a/batman-adv-devel/files/etc/config/batman-adv +++ b/batman-adv-devel/files/etc/config/batman-adv @@ -12,3 +12,6 @@ config 'mesh' 'bat0' option 'orig_interval' option 'vis_mode'
+# yet another batX instance +# config 'mesh' 'bat5' +# option 'interfaces' 'second_mesh' diff --git a/batman-adv-devel/files/etc/hotplug.d/net/99-batman-adv b/batman-adv-devel/files/etc/hotplug.d/net/99-batman-adv new file mode 100644 index 0000000..2ad83cf --- /dev/null +++ b/batman-adv-devel/files/etc/hotplug.d/net/99-batman-adv @@ -0,0 +1,15 @@ +#!/bin/sh + +. /lib/batman-adv/config.sh + +config_load batman-adv + +case "$ACTION" in + add) + [ -d /sys/class/net/$INTERFACE/mesh/ ] && config_bat "$INTERFACE" + [ -d /sys/class/net/$INTERFACE/batman_adv/ ] && config_foreach bat_add_interface mesh "$INTERFACE" + ;; + remove) + [ -d /sys/class/net/$INTERFACE/batman_adv/ ] && config_foreach bat_del_interface mesh "$INTERFACE" + ;; +esac diff --git a/batman-adv-devel/files/etc/init.d/batman-adv b/batman-adv-devel/files/etc/init.d/batman-adv deleted file mode 100644 index f0f6789..0000000 --- a/batman-adv-devel/files/etc/init.d/batman-adv +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2011 OpenWrt.org - -START=90 - -. /lib/batman-adv/config.sh - -# can also be used with "batman-adv start bat0" -start() { - config_load batman-adv - - if [ -n "$1" ]; then - start_mesh $1 - else - config_foreach start_mesh mesh - fi -} - -# can also be used with "batman-adv stop bat0" -stop () { - config_load batman-adv - - if [ -n "$1" ]; then - stop_mesh $1 - else - config_foreach stop_mesh mesh - fi -} diff --git a/batman-adv-devel/files/lib/batman-adv/config.sh b/batman-adv-devel/files/lib/batman-adv/config.sh index 58a01d2..500665e 100644 --- a/batman-adv-devel/files/lib/batman-adv/config.sh +++ b/batman-adv-devel/files/lib/batman-adv/config.sh @@ -1,103 +1,63 @@ #!/bin/sh -# Copyright (C) 2011 OpenWrt.org
-is_module_loaded() { - - if [ ! -d "/sys/module/batman_adv" ]; then - echo "batman-adv module directory not found - was the kernel module loaded ?" >&2 - return 0 - fi - - return 1 +bat_config(){ + local mesh="$1" + local aggregated_ogms bonding fragmentation gw_bandwidth gw_mode gw_sel_class log_level orig_interval vis_mode + + logger -st batman-adv "config_bat: mesh = $mesh" + + config_get aggregated_ogms "$mesh" aggregated_ogms + config_get bonding "$mesh" bonding + config_get fragmentation "$mesh" fragmentation + config_get gw_bandwidth "$mesh" gw_bandwidth + config_get gw_mode "$mesh" gw_mode + config_get gw_sel_class "$mesh" gw_sel_class + config_get log_level "$mesh" log_level + config_get orig_interval "$mesh" orig_interval + config_get vis_mode "$mesh" vis_mode + + [ -n "$orig_interval" ] && echo $orig_interval > /sys/class/net/$mesh/mesh/orig_interval + [ -n "$log_level" ] && echo $log_level > /sys/class/net/$mesh/mesh/log_level 2>&- + [ -n "$aggregate_ogms" ] && echo $aggregate_ogms > /sys/class/net/$mesh/mesh/aggregate_ogms + [ -n "$bonding" ] && echo $bonding > /sys/class/net/$mesh/mesh/bonding + [ -n "$fragmentation" ] && echo $fragmentation > /sys/class/net/$mesh/mesh/fragmentation + [ -n "$gw_bandwidth" ] && echo $gw_bandwidth > /sys/class/net/$mesh/mesh/gw_bandwidth + [ -n "$gw_mode" ] && echo $gw_mode > /sys/class/net/$mesh/mesh/gw_mode + [ -n "$gw_sel_class" ] && echo $gw_sel_class > /sys/class/net/$mesh/mesh/gw_sel_class + [ -n "$vis_mode" ] && echo $vis_mode > /sys/class/net/$mesh/mesh/vis_mode }
-start_mesh () { - local meshif="$1" - local interfaces aggregated_ogms ap_isolation bonding fragmentation gw_bandwidth gw_mode gw_sel_class log_level orig_interval vis_mode - - is_module_loaded - [ $? -ne 1 ] && return - - config_get interfaces "$meshif" interfaces - config_get aggregated_ogms "$meshif" aggregated_ogms - config_get ap_isolation "$meshif" ap_isolation - config_get bonding "$meshif" bonding - config_get fragmentation "$meshif" fragmentation - config_get gw_bandwidth "$meshif" gw_bandwidth - config_get gw_mode "$meshif" gw_mode - config_get gw_sel_class "$meshif" gw_sel_class - config_get log_level "$meshif" log_level - config_get orig_interval "$meshif" orig_interval - config_get vis_mode "$meshif" vis_mode - - if [ "$interfaces" = "" ]; then - echo Error, you must specify at least a network interface - return - fi - - for interface in $interfaces - do - ifname=$(uci -P /var/state get network.$interface.ifname 2>&-) - [ ! -f "/sys/class/net/$ifname/batman_adv/mesh_iface" ] && { - ifname=${interface} - [ ! -f "/sys/class/net/$ifname/batman_adv/mesh_iface" ] && echo "Can't add interface $ifname - ignoring" && continue - } - - echo $meshif > /sys/class/net/$ifname/batman_adv/mesh_iface - done - - if [ $orig_interval ]; then - echo $orig_interval > /sys/class/net/$meshif/mesh/orig_interval - fi - - if [ $log_level ]; then - echo $log_level > /sys/class/net/$meshif/mesh/log_level 2>&- - fi - - if [ $aggregated_ogms ]; then - echo $aggregated_ogms > /sys/class/net/$meshif/mesh/aggregated_ogms - fi - - if [ $ap_isolation ]; then - echo $ap_isolation > /sys/class/net/$meshif/mesh/ap_isolation - fi - - if [ $bonding ]; then - echo $bonding > /sys/class/net/$meshif/mesh/bonding - fi - - if [ $fragmentation ]; then - echo $fragmentation > /sys/class/net/$meshif/mesh/fragmentation - fi - - if [ $gw_bandwidth ]; then - echo $gw_bandwidth > /sys/class/net/$meshif/mesh/gw_bandwidth - fi - - if [ $gw_mode ]; then - echo $gw_mode > /sys/class/net/$meshif/mesh/gw_mode - fi - - if [ $gw_sel_class ]; then - echo $gw_sel_class > /sys/class/net/$meshif/mesh/gw_sel_class - fi - - if [ $vis_mode ]; then - echo $vis_mode > /sys/class/net/$meshif/mesh/vis_mode - fi +bat_add_interface(){ + local mesh="$1" + local interface="$2" + local interfaces + + sleep 3s # some device (ath) is very lazy to start + config_get interfaces $mesh interfaces + logger -st batman-adv "add_interface: mesh = $mesh, iface = $interface, ifaces = $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 + } + + logger -st batman-adv "add_interface: $iface == $interface -> mesh = $mesh" + [ "$iface" = "$interface" ] && echo $mesh > /sys/class/net/$iface/batman_adv/mesh_iface + done }
-stop_mesh() { - local meshif="$1" - - is_module_loaded - [ $? -ne 1 ] && return +bat_del_interface(){ + local mesh="$1" + local interface="$2" + local interfaces
- for iface in $(ls /sys/class/net/*) - do - [ ! -f "$iface/batman_adv/mesh_iface" ] && continue - [ "$(head -1 $iface/batman_adv/mesh_iface)" != "$meshif" ] && continue + 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 + }
- echo "none" > $iface/batman_adv/mesh_iface - done + [ "$iface" = "$interface" ] && echo none > /sys/class/net/$iface/batman_adv/mesh_iface + done } diff --git a/batman-adv-devel/files/usr/sbin/batman-adv b/batman-adv-devel/files/usr/sbin/batman-adv new file mode 100644 index 0000000..4f17991 --- /dev/null +++ b/batman-adv-devel/files/usr/sbin/batman-adv @@ -0,0 +1,46 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2011 OpenWrt.org + +. /lib/batman-adv/config.sh + +start_mesh() { + local mesh="$1" + local ifaces=$(awk -F':' '{if (NR > 2) print $1}' /proc/net/dev) + + for iface in $ifaces; do + [ -d /sys/class/net/$iface/batman_adv/ ] && bat_add_interface "$mesh" "$iface" + done + + bat_config "$mesh" +} + +stop_mesh() { + local mesh="$1" + local ifaces=$(awk -F':' '{if (NR > 2) print $1}' /proc/net/dev) + + for iface in $ifaces; do + [ -d /sys/class/net/$iface/batman_adv/ ] && bat_del_interface "$mesh" "$iface" + done +} + +# can also be used with "batman-adv start bat0" +start() { + config_load batman-adv + + if [ -n "$1" ]; then + start_mesh $1 + else + config_foreach start_mesh mesh + fi +} + +# can also be used with "batman-adv stop bat0" +stop () { + config_load batman-adv + + if [ -n "$1" ]; then + stop_mesh $1 + else + config_foreach stop_mesh mesh + fi +}