summaryrefslogtreecommitdiff
path: root/package/network/ipv6/6relayd/files/6relayd.init
diff options
context:
space:
mode:
authorcyrus <cyrus@3c298f89-4303-0410-b956-a3cf2f4a3e73>2013-01-13 17:25:38 +0000
committercyrus <cyrus@3c298f89-4303-0410-b956-a3cf2f4a3e73>2013-01-13 17:25:38 +0000
commitc30cb2cb1dd138ba5748852d4e7f00d49f4dcef0 (patch)
tree47992d85a3fdac0251e917cf38c5a3cb8575eb68 /package/network/ipv6/6relayd/files/6relayd.init
parent94fff5b28525052875304acbd8b1207e7d9b3547 (diff)
6relayd: Rewrite init-script logic
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@35133 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/network/ipv6/6relayd/files/6relayd.init')
-rw-r--r--package/network/ipv6/6relayd/files/6relayd.init124
1 files changed, 83 insertions, 41 deletions
diff --git a/package/network/ipv6/6relayd/files/6relayd.init b/package/network/ipv6/6relayd/files/6relayd.init
index 8c50336d0c..790396e574 100644
--- a/package/network/ipv6/6relayd/files/6relayd.init
+++ b/package/network/ipv6/6relayd/files/6relayd.init
@@ -1,26 +1,13 @@
#!/bin/sh /etc/rc.common
# Copyright (c) 2011-2012 OpenWrt.org
START=80
-
-resolve_ifname() {
- grep -qs "^ *$1:" /proc/net/dev && {
- append ifaces "$1"
- }
-}
-
-resolve_network() {
- local ifn
- fixup_interface "$1"
- config_get ifn "$1" ifname
- [ -z "$ifn" ] && return 1
- resolve_ifname "$ifn"
-}
+. /lib/functions/network.sh
+. /lib/functions/service.sh
start_6relayd() {
local cfg="$1"
local mode="$2"
- local args="-s -l"
- local ifaces=""
+ local args=""
SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
@@ -33,40 +20,96 @@ start_6relayd() {
fi
}
- local net networks
- config_get networks "$cfg" network
- for net in $networks; do
- resolve_network "$net" || {
- return 1
- }
- done
+ # Detect master interface
+ local master masterif
+ config_get masterif "$cfg" master
+ network_get_device master "$masterif"
+ [ -z "$master" ] && master="."
- local ifn ifnames
- config_get ifnames "$cfg" ifname
- for ifn in $ifnames; do
- resolve_ifname "$ifn"
+ # Detect slave interfaces
+ local slaves=""
+ local slaveifs
+ config_get slaveifs "$cfg" network
+ for slaveif in $slaveifs; do
+ local slave
+ network_get_device slave "$slaveif"
+ # Compatibility with old config format
+ if [ "$mode" = "relay" -a "$master" = "." ]; then
+ [ -z "$slave" ] && return 0
+ master="$slave"
+ else
+ [ -n "$slave" ] && append slaves "$slave"
+ fi
done
- local rd
- config_get rd "$cfg" rd
- [ -n "$rd" ] && append args "-R$rd"
+ # Bail if no slaves are active
+ [ -z "$slaves" ] && return 0
- local dhcpv6
+ # Configure services
+ local rd dhcpv6 ndp
+ config_get rd "$cfg" rd
config_get dhcpv6 "$cfg" dhcpv6
- [ -n "$dhcpv6" ] && append args "-D$dhcpv6"
-
- local ndp
config_get ndp "$cfg" ndp
- [ "$ndp" == "relay" ] && append args "-N -r"
+ # Test for fallback mode
+ local fallback fallback_relay
+ config_get fallback_relay "$cfg" fallback_relay
+
+ if [ -n "$fallback_relay" -a "$master" != "." ]; then
+ local prefix
+ network_get_prefix6 prefix "$masterif"
+ [ -z "$prefix" ] && fallback=1
+ fi
+
+ if [ -n "$fallback" ]; then
+ for service in $fallback_relay; do
+ eval "$service=relay"
+ done
+ fi
+
+ # Configure feature options
local always_rewrite_dns
config_get_bool always_rewrite_dns "$cfg" always_rewrite_dns 0
- [ $always_rewrite_dns -eq 1 ] && append args "-n"
+ [ "$always_rewrite_dns" -eq 1 ] && append args "-n"
+
+ local always_assume_default
+ config_get_bool always_assume_default "$cfg" always_assume_default 0
+ [ "$always_assume_default" -eq 1 ] && append args "-u"
+
+ [ "$ndp" = "relay" ] && append args "-N -s -l"
+ [ "$rd" = "relay" ] && append args "-Rrelay"
+ [ "$rd" = "server" ] && append args "-Rserver"
+ [ "$dhcpv6" = "relay" ] && append args "-Drelay"
+ [ "$dhcpv6" = "server" ] && append args "-Dserver"
+ [ "$ndp" != "relay" -a "$rd" != "relay" -a "$dhcpv6" != "relay" ] && master="."
+
+ service_start /usr/sbin/6relayd $args $master $slaves
+}
+
+restart_affected_6relayd() {
+ local cfg="$1"
+ local net="$2"
+ local mode="$3"
- # In server mode the first interface needs to be passed twice
- [ "$mode" == "server" ] && ifaces=". $ifaces"
+ local master slaves
+ config_get master "$cfg" master
+ config_get slaves "$cfg" network
- service_start /usr/sbin/6relayd $args $ifaces
+ for iface in $master $slaves; do
+ if [ "$iface" = "$net" ]; then
+ SERVICE_PID_FILE="/var/run/6relayd-$cfg.pid"
+ service_stop /usr/sbin/6relayd
+ rm -f "$SERVICE_PID_FILE"
+ start_6relayd "$cfg" "$mode"
+ fi
+ done
+}
+
+restart_affected() {
+ local net="$1"
+ config_load 6relayd
+ config_foreach restart_affected_6relayd server "$net"
+ config_foreach restart_affected_6relayd relay "$net" "relay"
}
stop() {
@@ -78,8 +121,7 @@ stop() {
}
start() {
- include /lib/network
config_load 6relayd
+ config_foreach start_6relayd server
config_foreach start_6relayd relay relay
- config_foreach start_6relayd server server
}