summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2012-04-30 18:23:52 +0000
committerFelix Fietkau <nbd@openwrt.org>2012-04-30 18:23:52 +0000
commit8a790d97308153c345abfd27e5693b688fc3ba89 (patch)
treec15df09c2a32cdf661a107b609238647459de864 /package
parentcbfce5383188be93ec84d0c485aba8a48a784258 (diff)
downloadmtk-20170518-8a790d97308153c345abfd27e5693b688fc3ba89.zip
mtk-20170518-8a790d97308153c345abfd27e5693b688fc3ba89.tar.gz
mtk-20170518-8a790d97308153c345abfd27e5693b688fc3ba89.tar.bz2
relayd: use an init script instead of a legacy network proto handler (fixes #11276)
SVN-Revision: 31542
Diffstat (limited to 'package')
-rw-r--r--package/relayd/Makefile4
-rw-r--r--package/relayd/files/relay.hotplug36
-rw-r--r--package/relayd/files/relay.init97
-rw-r--r--package/relayd/files/relay.sh100
4 files changed, 100 insertions, 137 deletions
diff --git a/package/relayd/Makefile b/package/relayd/Makefile
index d70bd97..c8730a3 100644
--- a/package/relayd/Makefile
+++ b/package/relayd/Makefile
@@ -35,8 +35,8 @@ define Package/relayd/install
$(INSTALL_BIN) $(PKG_BUILD_DIR)/relayd $(1)/usr/sbin/relayd
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
$(INSTALL_DATA) ./files/relay.hotplug $(1)/etc/hotplug.d/iface/30-relay
- $(INSTALL_DIR) $(1)/lib/network
- $(INSTALL_DATA) ./files/relay.sh $(1)/lib/network/relay.sh
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/relay.init $(1)/etc/init.d/relayd
endef
$(eval $(call BuildPackage,relayd))
diff --git a/package/relayd/files/relay.hotplug b/package/relayd/files/relay.hotplug
index b992fca..afffbfe 100644
--- a/package/relayd/files/relay.hotplug
+++ b/package/relayd/files/relay.hotplug
@@ -1,36 +1,2 @@
#!/bin/sh
-
-# Break recursion
-[ "$PROTO" = "relay" ] && exit 0
-
-include /lib/network
-scan_interfaces
-
-restart_relayd() {
- local cfg="$1"
-
- local proto
- config_get proto "$1" proto
- [ "$proto" = "relay" ] || return 0
-
- local net networks
- config_get networks "$cfg" network
- for net in $networks; do
- [ "$net" = "$INTERFACE" ] && {
- env -i /sbin/ifup "$cfg" &
- return 0
- }
- done
-
- local ifn ifnames
- config_get ifnames "$cfg" ifname
- for ifn in $ifnames; do
- [ "$ifn" = "$DEVICE" ] && {
- env -i /sbin/ifup "$cfg" &
- return 0
- }
- done
-}
-
-config_foreach restart_relayd interface
-
+/etc/init.d/relayd enabled && /etc/init.d/relayd start
diff --git a/package/relayd/files/relay.init b/package/relayd/files/relay.init
new file mode 100644
index 0000000..98a38b4
--- /dev/null
+++ b/package/relayd/files/relay.init
@@ -0,0 +1,97 @@
+#!/bin/sh /etc/rc.common
+# Copyright (c) 2011-2012 OpenWrt.org
+START=80
+
+resolve_ifname() {
+ grep -qs "^ *$1:" /proc/net/dev && {
+ append args "-I $1"
+ append ifaces "$1"
+ }
+}
+
+resolve_network() {
+ local ifn
+ config_get ifn "$1" ifname
+ [ -z "$ifn" ] && return 1
+ resolve_ifname "$ifn"
+ return 0
+}
+
+start_relay() {
+ local cfg="$1"
+
+ local args=""
+ local ifaces=""
+
+ config_get proto "$cfg" proto
+ [[ "$proto" == relay ]] || return 0
+
+ SERVICE_DAEMONIZE=1
+ SERVICE_WRITE_PID=1
+ SERVICE_PID_FILE="/var/run/relay-$cfg.pid"
+ [ -f "$SERVICE_PID_FILE" ] && {
+ if grep -q relayd "/proc/$(cat $SERVICE_PID_FILE)/cmdline"; then
+ return 0
+ else
+ rm -f "$SERVICE_PID_FILE"
+ fi
+ }
+
+ local net networks
+ config_get networks "$cfg" network
+ for net in $networks; do
+ resolve_network "$net" || {
+ return 1
+ }
+ done
+
+ local ifn ifnames
+ config_get ifnames "$cfg" ifname
+ for ifn in $ifnames; do
+ resolve_ifname "$ifn"
+ done
+
+ local ipaddr
+ config_get ipaddr "$cfg" ipaddr
+ [ -n "$ipaddr" ] && append args "-L $ipaddr"
+
+ local gateway
+ config_get gateway "$cfg" gateway
+ [ -n "$gateway" ] && append args "-G $gateway"
+
+ local expiry # = 30
+ config_get expiry "$cfg" expiry
+ [ -n "$expiry" ] && append args "-t $expiry"
+
+ local retry # = 5
+ config_get retry "$cfg" retry
+ [ -n "$retry" ] && append args "-p $retry"
+
+ local table # = 16800
+ config_get table "$cfg" table
+ [ -n "$table" ] && append args "-T $table"
+
+ local fwd_bcast # = 1
+ config_get_bool fwd_bcast "$cfg" forward_bcast 1
+ [ $fwd_bcast -eq 1 ] && append args "-B"
+
+ local fwd_dhcp # = 1
+ config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
+ [ $fwd_dhcp -eq 1 ] && append args "-D"
+
+ service_start /usr/sbin/relayd $args
+}
+
+stop() {
+ for pid in /var/run/relay-*.pid; do
+ SERVICE_PID_FILE="$pid"
+ service_stop /usr/sbin/relayd
+ rm -f "$SERVICE_PID_FILE"
+ done
+}
+
+start() {
+ include /lib/network
+ scan_interfaces
+ config_foreach start_relay interface
+}
diff --git a/package/relayd/files/relay.sh b/package/relayd/files/relay.sh
deleted file mode 100644
index 9cfdbbb..0000000
--- a/package/relayd/files/relay.sh
+++ /dev/null
@@ -1,100 +0,0 @@
-# relay.sh - Abstract relayd protocol backend
-# Copyright (c) 2011 OpenWrt.org
-
-# Hook into scan_interfaces() to synthesize a .device option
-# This is needed for /sbin/ifup to properly dispatch control
-# to setup_interface_relay() even if no .ifname is set in
-# the configuration.
-scan_relay() {
- config_set "$1" device "relay-$1"
-}
-
-# No coldplugging needed, relayd will be restarted if one of
-# the member interfaces goes up or down
-#coldplug_interface_relay() {
-# setup_interface_relay "relay-$1" "$1"
-#}
-
-setup_interface_relay() {
- local iface="$1"
- local cfg="$2"
- local link="relay-$cfg"
-
- local args=""
- local ifaces=""
-
- resolve_ifname() {
- grep -qs "^ *$1:" /proc/net/dev && {
- append args "-I $1"
- append ifaces "$1"
- }
- }
-
- resolve_network() {
- local ifn
- config_get ifn "$1" ifname
- resolve_ifname "$ifn"
- }
-
- local net networks
- config_get networks "$cfg" network
- for net in $networks; do
- resolve_network "$net"
- done
-
- local ifn ifnames
- config_get ifnames "$cfg" ifname
- for ifn in $ifnames; do
- resolve_ifname "$ifn"
- done
-
- local ipaddr
- config_get ipaddr "$cfg" ipaddr
- [ -n "$ipaddr" ] && append args "-L $ipaddr"
-
- local gateway
- config_get gateway "$cfg" gateway
- [ -n "$gateway" ] && append args "-G $gateway"
-
- local expiry # = 30
- config_get expiry "$cfg" expiry
- [ -n "$expiry" ] && append args "-t $expiry"
-
- local retry # = 5
- config_get retry "$cfg" retry
- [ -n "$retry" ] && append args "-p $retry"
-
- local table # = 16800
- config_get table "$cfg" table
- [ -n "$table" ] && append args "-T $table"
-
- local fwd_bcast # = 1
- config_get_bool fwd_bcast "$cfg" forward_bcast 1
- [ $fwd_bcast -eq 1 ] && append args "-B"
-
- local fwd_dhcp # = 1
- config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
- [ $fwd_dhcp -eq 1 ] && append args "-D"
-
- SERVICE_DAEMONIZE=1 \
- SERVICE_WRITE_PID=1 \
- SERVICE_PID_FILE="/var/run/$link.pid" \
- service_start /usr/sbin/relayd $args
-
- uci_set_state network "$cfg" device "$ifaces"
-
- env -i ACTION="ifup" DEVICE="$link" INTERFACE="$cfg" PROTO="relay" \
- /sbin/hotplug-call iface
-}
-
-stop_interface_relay() {
- local cfg="$1"
- local link="relay-$cfg"
-
- env -i ACTION="ifdown" DEVICE="$link" INTERFACE="$cfg" PROTO="relay" \
- /sbin/hotplug-call iface
-
- SERVICE_PID_FILE="/var/run/$link.pid" \
- service_stop /usr/sbin/relayd
-}
-