2012-10-30 07:14:07 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (c) 2011-2012 OpenWrt.org
|
|
|
|
START=80
|
2013-05-17 14:44:07 +00:00
|
|
|
args=""
|
|
|
|
|
|
|
|
add_static_lease() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
|
|
|
local duid id
|
|
|
|
config_get duid "$cfg" duid
|
|
|
|
config_get id "$cfg" id
|
|
|
|
|
|
|
|
[ -n "$duid" -a -n "$id" ] && append args "-a$duid:$id"
|
|
|
|
|
|
|
|
}
|
2012-10-30 07:14:07 +00:00
|
|
|
|
|
|
|
start_6relayd() {
|
|
|
|
local cfg="$1"
|
2012-11-16 09:27:56 +00:00
|
|
|
local mode="$2"
|
2013-05-17 14:44:07 +00:00
|
|
|
args="-l/tmp/hosts/6relayd,/usr/sbin/6relayd-update"
|
2012-10-30 07:14:07 +00:00
|
|
|
|
|
|
|
SERVICE_DAEMONIZE=1
|
|
|
|
SERVICE_WRITE_PID=1
|
|
|
|
SERVICE_PID_FILE="/var/run/6relayd-$cfg.pid"
|
|
|
|
[ -f "$SERVICE_PID_FILE" ] && {
|
|
|
|
if grep -q 6relayd "/proc/$(cat $SERVICE_PID_FILE)/cmdline"; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
rm -f "$SERVICE_PID_FILE"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-01-13 17:25:38 +00:00
|
|
|
# Detect master interface
|
|
|
|
local master masterif
|
|
|
|
config_get masterif "$cfg" master
|
|
|
|
network_get_device master "$masterif"
|
2014-01-02 11:38:36 +00:00
|
|
|
[ -z "$master" -o "$master" = "$masterif" ] && master="."
|
2012-10-30 07:14:07 +00:00
|
|
|
|
2013-01-13 17:25:38 +00:00
|
|
|
# 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
|
2014-01-02 11:38:36 +00:00
|
|
|
[ -z "$slave" -o "$slave" = "$slaveif" ] && return 0
|
2013-01-13 17:25:38 +00:00
|
|
|
master="$slave"
|
|
|
|
else
|
2014-01-02 11:38:36 +00:00
|
|
|
[ -n "$slave" -o "$slave" = "$slaveif" ] && append slaves "$slave"
|
2013-01-13 17:25:38 +00:00
|
|
|
fi
|
2012-10-30 07:14:07 +00:00
|
|
|
done
|
|
|
|
|
2013-01-13 17:25:38 +00:00
|
|
|
# Bail if no slaves are active
|
|
|
|
[ -z "$slaves" ] && return 0
|
2012-10-30 07:14:07 +00:00
|
|
|
|
2013-01-13 17:25:38 +00:00
|
|
|
# Configure services
|
|
|
|
local rd dhcpv6 ndp
|
|
|
|
config_get rd "$cfg" rd
|
2012-11-16 09:27:56 +00:00
|
|
|
config_get dhcpv6 "$cfg" dhcpv6
|
|
|
|
config_get ndp "$cfg" ndp
|
2012-10-30 07:14:07 +00:00
|
|
|
|
2013-01-13 17:25:38 +00:00
|
|
|
# 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
|
2013-02-26 12:42:53 +00:00
|
|
|
local always_rewrite_dns rewrite_dns_addr
|
2012-10-30 07:14:07 +00:00
|
|
|
config_get_bool always_rewrite_dns "$cfg" always_rewrite_dns 0
|
2013-02-26 12:42:53 +00:00
|
|
|
config_get rewrite_dns_addr "$cfg" rewrite_dns_addr
|
2013-02-26 12:50:52 +00:00
|
|
|
[ "$always_rewrite_dns" -eq 1 -o -n "$rewrite_dns_addr" ] && append args "-n$rewrite_dns_addr"
|
2013-01-13 17:25:38 +00:00
|
|
|
|
|
|
|
local always_assume_default
|
|
|
|
config_get_bool always_assume_default "$cfg" always_assume_default 0
|
|
|
|
[ "$always_assume_default" -eq 1 ] && append args "-u"
|
|
|
|
|
2013-02-26 12:42:53 +00:00
|
|
|
local compat_ula
|
|
|
|
config_get_bool compat_ula "$cfg" compat_ula 0
|
|
|
|
[ "$compat_ula" -eq 1 ] && append args "-c"
|
|
|
|
|
2013-05-17 14:44:07 +00:00
|
|
|
local management_level
|
|
|
|
config_get management_level "$cfg" management_level
|
|
|
|
[ -n "$management_level" ] && append args "-m$management_level"
|
|
|
|
|
2013-06-11 20:52:27 +00:00
|
|
|
local management_offlink
|
|
|
|
config_get_bool management_offlink "$cfg" management_offlink 0
|
|
|
|
[ "$management_offlink" -eq 1 ] && append args "-o"
|
|
|
|
|
|
|
|
local management_preference
|
|
|
|
config_get management_preference "$cfg" management_preference
|
|
|
|
[ -n "$management_preference" ] && append args "-i$management_preference"
|
|
|
|
|
2013-05-17 14:44:07 +00:00
|
|
|
config_foreach add_static_lease lease
|
|
|
|
|
2013-04-22 19:39:55 +00:00
|
|
|
[ "$ndp" = "relay" ] && append args "-N -s"
|
2013-01-13 17:25:38 +00:00
|
|
|
[ "$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"
|
2012-10-30 07:14:07 +00:00
|
|
|
|
2013-01-13 17:25:38 +00:00
|
|
|
local master slaves
|
|
|
|
config_get master "$cfg" master
|
|
|
|
config_get slaves "$cfg" network
|
2012-11-16 09:27:56 +00:00
|
|
|
|
2013-01-13 17:25:38 +00:00
|
|
|
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() {
|
2013-01-21 11:27:03 +00:00
|
|
|
. /lib/functions/service.sh
|
|
|
|
. /lib/functions/network.sh
|
2013-01-13 17:25:38 +00:00
|
|
|
local net="$1"
|
|
|
|
config_load 6relayd
|
|
|
|
config_foreach restart_affected_6relayd server "$net"
|
|
|
|
config_foreach restart_affected_6relayd relay "$net" "relay"
|
2012-10-30 07:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2013-01-21 11:27:03 +00:00
|
|
|
. /lib/functions/service.sh
|
2012-10-30 07:14:07 +00:00
|
|
|
for pid in /var/run/6relayd-*.pid; do
|
|
|
|
SERVICE_PID_FILE="$pid"
|
|
|
|
service_stop /usr/sbin/6relayd
|
|
|
|
rm -f "$SERVICE_PID_FILE"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
2013-01-21 11:27:03 +00:00
|
|
|
. /lib/functions/service.sh
|
|
|
|
. /lib/functions/network.sh
|
2012-11-16 09:27:56 +00:00
|
|
|
config_load 6relayd
|
2013-01-13 17:25:38 +00:00
|
|
|
config_foreach start_6relayd server
|
2012-11-16 09:27:56 +00:00
|
|
|
config_foreach start_6relayd relay relay
|
2012-10-30 07:14:07 +00:00
|
|
|
}
|