[Olsr-dev] OLSRd V2 - [PATCH] [openwrt] add uci-fication and hotplug-script
Bastian Bittorf
(spam-protected)
Thu May 22 11:25:46 CEST 2014
OLSRd V2 - [openwrt] add uci-fication and hotplug-script
implementing a small subset for a working native-olsrd2 config-file.
the file is created during startup into ramdisc and during hotplug-events
we _restart_ the daemon if needed. this is generated on my end from
the included uci-file:
(spam-protected):~ cat /var/etc/olsrd2.conf
[global]
fork true
failfast no
[log]
stderr true
syslog true
file /var/log/olsrd2.log
[domain=0]
table 234
[telnet]
port 2007
[interface=lo] # loopback
[interface=eth0.2] # wan
[interface=eth0.1] # lan
[interface=wlan0] # wlanadhoc
[interface=wlan1] # wlanadhocRADIO1
Signed-off-by: Bastian Bittorf <(spam-protected)>
---
openwrt/olsrd2-git/Makefile | 10 +++--
openwrt/olsrd2-git/files/olsrd2.conf | 13 ------
openwrt/olsrd2-git/files/olsrd2.hotplug | 71 +++++++++++++++++++++++++++++++++
openwrt/olsrd2-git/files/olsrd2.uci | 22 ++++++++++
4 files changed, 100 insertions(+), 16 deletions(-)
delete mode 100644 openwrt/olsrd2-git/files/olsrd2.conf
create mode 100755 openwrt/olsrd2-git/files/olsrd2.hotplug
create mode 100644 openwrt/olsrd2-git/files/olsrd2.uci
diff --git a/openwrt/olsrd2-git/Makefile b/openwrt/olsrd2-git/Makefile
index 8be848f..05f9425 100644
--- a/openwrt/olsrd2-git/Makefile
+++ b/openwrt/olsrd2-git/Makefile
@@ -77,6 +77,7 @@ TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include
define Package/olsrd2-git/install
$(INSTALL_DIR) $(1)/etc
$(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
$(INSTALL_DIR) $(1)/usr
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) \
@@ -85,13 +86,16 @@ define Package/olsrd2-git/install
$(INSTALL_BIN) \
./files/olsrd2.init \
$(1)/etc/init.d/olsrd2
+ $(INSTALL_BIN) \
+ ./files/olsrd2.hotplug \
+ $(1)/etc/hotplug.d/iface/50-olsrd2
$(INSTALL_DATA) \
- ./files/olsrd2.conf \
- $(1)/etc
+ ./files/olsrd2.uci \
+ $(1)/etc/config/olsrd2
endef
define Package/olsrd2-git/conffiles
-/etc/olsrd2.conf
+/etc/config/olsrd2
endef
#define Package/olsrd2-git-plugin-ff-ett/install
diff --git a/openwrt/olsrd2-git/files/olsrd2.conf b/openwrt/olsrd2-git/files/olsrd2.conf
deleted file mode 100644
index a855b00..0000000
--- a/openwrt/olsrd2-git/files/olsrd2.conf
+++ /dev/null
@@ -1,13 +0,0 @@
-#[global]
-# fork no
-# failfast no
-
-[log]
-# file /var/log/olsrd2.log
- stderr true
- syslog true
-# info all
-# debug all
-#
-
-[interface=wlan0]
diff --git a/openwrt/olsrd2-git/files/olsrd2.hotplug b/openwrt/olsrd2-git/files/olsrd2.hotplug
new file mode 100755
index 0000000..8ead809
--- /dev/null
+++ b/openwrt/olsrd2-git/files/olsrd2.hotplug
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+olsrd2_log()
+{
+ local prio="$1"
+ local message="$2"
+
+ logger -t olsrd2_hotplug -p daemon.$prio "$message"
+}
+
+olsrd2_list_configured_interfaces()
+{
+ local i=0
+ local interface
+
+ while interface="$( uci -q get (spam-protected)[$i].ifname )"; do {
+ case "$( uci -q get (spam-protected)[$i].ignore )" in
+ 1|on|true|enabled|yes)
+ # must be ignored
+ ;;
+ *)
+ echo "$interface" # e.g. 'lan wan wifi'
+ ;;
+ esac
+
+ i=$(( $i + 1 ))
+ } done
+}
+
+olsrd2_interface_already_in_config()
+{
+ if grep ^"\[interface=${DEVICE}\]" '/var/etc/olsrd2.conf'; then
+ olsrd2_log debug "[OK] already_active: '$INTERFACE' => '$DEVICE'"
+ return 0
+ else
+ olsrd2_log info "[OK] ifup/adding: '$INTERFACE' => '$DEVICE'"
+ return 1
+ fi
+}
+
+olsrd2_interface_needs_adding()
+{
+ local interface
+
+ # likely and cheap operation:
+ olsrd_interface_already_in_config && return 1
+
+ for interface in $(olsrd2_list_configured_interfaces); do {
+ [ "$interface" = "$INTERFACE" ] && {
+ olsrd2_interface_already_in_config || return 0
+ }
+ } done
+
+ olsrd2_log debug "[OK] interface '$INTERFACE' => '$DEVICE' not used for olsrd"
+ return 1
+}
+
+case "$ACTION" in
+ ifup)
+ # only work after the first normal startup
+ # also: no need to test, if enabled
+ [ -e '/var/etc/olsrd2.conf' ] && {
+ # used global vars:
+ # INTERFACE = e.g. 'wlanadhocRADIO1' or 'cfg144d8f'
+ # DEVICE = e.g. 'wlan1-1'
+ olsrd2_interface_needs_adding && {
+ . /etc/rc.common /etc/init.d/olsrd2 restart
+ }
+ }
+ ;;
+esac
diff --git a/openwrt/olsrd2-git/files/olsrd2.uci b/openwrt/olsrd2-git/files/olsrd2.uci
new file mode 100644
index 0000000..cdd7cb5
--- /dev/null
+++ b/openwrt/olsrd2-git/files/olsrd2.uci
@@ -0,0 +1,22 @@
+config global
+ option 'fork' 'yes'
+ option 'failfast' 'no'
+ option 'table' '234'
+
+config log
+ option 'file' '/var/log/olsrd2.log'
+ option 'stderr' 'true'
+ option 'syslog' 'true'
+# option 'info' 'all'
+# option 'debug' 'all'
+
+config plugin
+ option 'name' 'telnet'
+ option 'port' '2007'
+
+config interface
+ option 'ifname' 'loopback'
+# option 'ignore' '1'
+
+config interface
+ list 'ifname' 'wan lan wlanadhoc wlanadhocRADIO1'
--
1.8.1.2
More information about the Olsr-dev
mailing list