1 #!/bin/sh /etc/rc.common
2 # Copyright (c) 2011-2012 OpenWrt.org
4 . /lib/functions/network.sh
5 . /lib/functions/service.sh
14 SERVICE_PID_FILE="/var/run/6relayd-$cfg.pid"
15 [ -f "$SERVICE_PID_FILE" ] && {
16 if grep -q 6relayd "/proc/$(cat $SERVICE_PID_FILE)/cmdline"; then
19 rm -f "$SERVICE_PID_FILE"
23 # Detect master interface
25 config_get masterif "$cfg" master
26 network_get_device master "$masterif"
27 [ -z "$master" ] && master="."
29 # Detect slave interfaces
32 config_get slaveifs "$cfg" network
33 for slaveif in $slaveifs; do
35 network_get_device slave "$slaveif"
36 # Compatibility with old config format
37 if [ "$mode" = "relay" -a "$master" = "." ]; then
38 [ -z "$slave" ] && return 0
41 [ -n "$slave" ] && append slaves "$slave"
45 # Bail if no slaves are active
46 [ -z "$slaves" ] && return 0
50 config_get rd "$cfg" rd
51 config_get dhcpv6 "$cfg" dhcpv6
52 config_get ndp "$cfg" ndp
54 # Test for fallback mode
55 local fallback fallback_relay
56 config_get fallback_relay "$cfg" fallback_relay
58 if [ -n "$fallback_relay" -a "$master" != "." ]; then
60 network_get_prefix6 prefix "$masterif"
61 [ -z "$prefix" ] && fallback=1
64 if [ -n "$fallback" ]; then
65 for service in $fallback_relay; do
70 # Configure feature options
71 local always_rewrite_dns
72 config_get_bool always_rewrite_dns "$cfg" always_rewrite_dns 0
73 [ "$always_rewrite_dns" -eq 1 ] && append args "-n"
75 local always_assume_default
76 config_get_bool always_assume_default "$cfg" always_assume_default 0
77 [ "$always_assume_default" -eq 1 ] && append args "-u"
79 [ "$ndp" = "relay" ] && append args "-N -s -l"
80 [ "$rd" = "relay" ] && append args "-Rrelay"
81 [ "$rd" = "server" ] && append args "-Rserver"
82 [ "$dhcpv6" = "relay" ] && append args "-Drelay"
83 [ "$dhcpv6" = "server" ] && append args "-Dserver"
84 [ "$ndp" != "relay" -a "$rd" != "relay" -a "$dhcpv6" != "relay" ] && master="."
86 service_start /usr/sbin/6relayd $args $master $slaves
89 restart_affected_6relayd() {
95 config_get master "$cfg" master
96 config_get slaves "$cfg" network
98 for iface in $master $slaves; do
99 if [ "$iface" = "$net" ]; then
100 SERVICE_PID_FILE="/var/run/6relayd-$cfg.pid"
101 service_stop /usr/sbin/6relayd
102 rm -f "$SERVICE_PID_FILE"
103 start_6relayd "$cfg" "$mode"
111 config_foreach restart_affected_6relayd server "$net"
112 config_foreach restart_affected_6relayd relay "$net" "relay"
116 for pid in /var/run/6relayd-*.pid; do
117 SERVICE_PID_FILE="$pid"
118 service_stop /usr/sbin/6relayd
119 rm -f "$SERVICE_PID_FILE"
125 config_foreach start_6relayd server
126 config_foreach start_6relayd relay relay