diff options
author | Steven Barth <cyrus@openwrt.org> | 2013-01-13 17:25:38 +0000 |
---|---|---|
committer | Steven Barth <cyrus@openwrt.org> | 2013-01-13 17:25:38 +0000 |
commit | fde5b934fd2cdbaa179329030b8a16c34b11ffea (patch) | |
tree | ff9e94d5994282beda8d2dd859015bcf4be1ee3d | |
parent | 1474359bd3426864a7d844c39b8f2dedf26c2119 (diff) | |
download | master-31e0f0ae-fde5b934fd2cdbaa179329030b8a16c34b11ffea.tar.gz master-31e0f0ae-fde5b934fd2cdbaa179329030b8a16c34b11ffea.tar.bz2 master-31e0f0ae-fde5b934fd2cdbaa179329030b8a16c34b11ffea.zip |
6relayd: Rewrite init-script logic
SVN-Revision: 35133
-rw-r--r-- | package/network/ipv6/6relayd/Makefile | 4 | ||||
-rw-r--r-- | package/network/ipv6/6relayd/files/6relayd.config | 8 | ||||
-rw-r--r-- | package/network/ipv6/6relayd/files/6relayd.hotplug | 6 | ||||
-rw-r--r-- | package/network/ipv6/6relayd/files/6relayd.init | 124 |
4 files changed, 95 insertions, 47 deletions
diff --git a/package/network/ipv6/6relayd/Makefile b/package/network/ipv6/6relayd/Makefile index c391e5b68b..412033ea9c 100644 --- a/package/network/ipv6/6relayd/Makefile +++ b/package/network/ipv6/6relayd/Makefile @@ -8,14 +8,14 @@ include $(TOPDIR)/rules.mk PKG_NAME:=6relayd -PKG_VERSION:=2013-01-02 +PKG_VERSION:=2013-01-13 PKG_RELEASE=$(PKG_SOURCE_VERSION) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_SOURCE_URL:=git://github.com/sbyx/6relayd.git PKG_SOURCE_PROTO:=git -PKG_SOURCE_VERSION:=9bf44b802547d71b75c7e505b8018d35c8fe4016 +PKG_SOURCE_VERSION:=9c1415f2361184482eeae9f252cc77c70f16be40 PKG_MAINTAINER:=Steven Barth <steven@midlink.org> diff --git a/package/network/ipv6/6relayd/files/6relayd.config b/package/network/ipv6/6relayd/files/6relayd.config index c5431d31b2..34fee0af4e 100644 --- a/package/network/ipv6/6relayd/files/6relayd.config +++ b/package/network/ipv6/6relayd/files/6relayd.config @@ -1,8 +1,9 @@ # Example #1: Create a relay for several networks in proxy mode # This can be used to proxy Router Discovery, DHCPv6 and NDP. -#config relay -# option network 'wan lan' +#config server examplerelay +# option master 'wan' +# option network 'lan' # option rd 'relay' # option dhcpv6 'relay' # option ndp 'relay' @@ -11,7 +12,8 @@ # Example #2: Provide Router Discovery and stateless DHCPv6 in server mode # This can be used as a small radvd and stateless DHCPv6-server replacement. -#config server +#config server exampleserver # option network 'lan' # option rd 'server' # option dhcpv6 'server' + diff --git a/package/network/ipv6/6relayd/files/6relayd.hotplug b/package/network/ipv6/6relayd/files/6relayd.hotplug index e29a34a09e..79052822f6 100644 --- a/package/network/ipv6/6relayd/files/6relayd.hotplug +++ b/package/network/ipv6/6relayd/files/6relayd.hotplug @@ -1,2 +1,6 @@ #!/bin/sh -/etc/init.d/6relayd enabled && /etc/init.d/6relayd start +/etc/init.d/6relayd enabled || exit 0 +[ -n "$INTERFACE" ] || exit 0 + +. /etc/init.d/6relayd +restart_affected "$INTERFACE" 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 } |