From c8bfc4b243780c0a8c3d71f5cfaf1325e042d873 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 5 Feb 2012 18:40:44 +0000 Subject: [PATCH] [packages_10.03.2] batman-adv: actually merge r30272, the previous commit missed it SVN-Revision: 30313 --- net/batman-adv/Makefile | 40 ++--- net/batman-adv/files/etc/config/batman-adv | 3 + .../files/etc/hotplug.d/net/99-batman-adv | 15 ++ net/batman-adv/files/etc/init.d/batman-adv | 28 ---- net/batman-adv/files/lib/batman-adv/config.sh | 144 +++++++----------- net/batman-adv/files/usr/sbin/batman-adv | 46 ++++++ 6 files changed, 131 insertions(+), 145 deletions(-) create mode 100644 net/batman-adv/files/etc/hotplug.d/net/99-batman-adv delete mode 100644 net/batman-adv/files/etc/init.d/batman-adv create mode 100644 net/batman-adv/files/usr/sbin/batman-adv diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile index 8547b31256..73f3f098d2 100644 --- a/net/batman-adv/Makefile +++ b/net/batman-adv/Makefile @@ -9,10 +9,10 @@ include $(TOPDIR)/rules.mk PKG_NAME:=batman-adv -PKG_VERSION:=2011.4.0 -BATCTL_VERSION:=2011.4.0 -PKG_MD5SUM:=3987d693bd26d8057506b542c3635910 -BATCTL_MD5SUM:=325b25dbb8261f7fa19c6e1d9bfba6e1 +PKG_VERSION:=2012.0.0 +BATCTL_VERSION:=2012.0.0 +PKG_MD5SUM:=f1de23457a47ca4369ee1f0e0b7fc405 +BATCTL_MD5SUM:=27991c2921e18657c7262e917d45106a PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://downloads.open-mesh.org/batman/releases/batman-adv-$(PKG_VERSION) @@ -73,9 +73,10 @@ define Download/batctl endef $(eval $(call Download,batctl)) -EXTRACT_BATCTL = tar xzf "$(DL_DIR)/batctl-$(BATCTL_VERSION).tar.gz" -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)/batctl-$(BATCTL_VERSION).tar.gz" -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) @@ -89,36 +90,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_BATCTL),) define KernelPackage/batman-adv/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/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)) diff --git a/net/batman-adv/files/etc/config/batman-adv b/net/batman-adv/files/etc/config/batman-adv index 414b119663..5197820422 100644 --- a/net/batman-adv/files/etc/config/batman-adv +++ b/net/batman-adv/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/net/batman-adv/files/etc/hotplug.d/net/99-batman-adv b/net/batman-adv/files/etc/hotplug.d/net/99-batman-adv new file mode 100644 index 0000000000..2ad83cf4e6 --- /dev/null +++ b/net/batman-adv/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/net/batman-adv/files/etc/init.d/batman-adv b/net/batman-adv/files/etc/init.d/batman-adv deleted file mode 100644 index f0f678904e..0000000000 --- a/net/batman-adv/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/net/batman-adv/files/lib/batman-adv/config.sh b/net/batman-adv/files/lib/batman-adv/config.sh index 58a01d2bc1..d0569bc77d 100644 --- a/net/batman-adv/files/lib/batman-adv/config.sh +++ b/net/batman-adv/files/lib/batman-adv/config.sh @@ -1,103 +1,61 @@ #!/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 hop_penalty vis_mode + + 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 hop_penalty "$mesh" hop_penalty + config_get vis_mode "$mesh" vis_mode + + [ -n "$orig_interval" ] && echo $orig_interval > /sys/class/net/$mesh/mesh/orig_interval + [ -n "$hop_penalty" ] && echo $hop_penalty > /sys/class/net/$mesh/mesh/hop_penalty + [ -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 +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 + 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 + } - 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 + [ "$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/net/batman-adv/files/usr/sbin/batman-adv b/net/batman-adv/files/usr/sbin/batman-adv new file mode 100644 index 0000000000..4f17991711 --- /dev/null +++ b/net/batman-adv/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 +} -- 2.30.2