2012-11-29 20:14:28 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright (c) 2012 OpenWrt.org
|
|
|
|
. /lib/ipv6/support.sh
|
|
|
|
. /lib/netifd/netifd-proto.sh
|
|
|
|
|
|
|
|
local device="$1"
|
|
|
|
local state="$2"
|
|
|
|
local network=""
|
|
|
|
|
|
|
|
resolve_network network "$device"
|
|
|
|
|
|
|
|
# Unknown network
|
|
|
|
[ -z "$network" ] && exit 0
|
|
|
|
|
2013-01-02 23:05:44 +00:00
|
|
|
if [ "$state" == "started" ]; then
|
|
|
|
# Start border
|
|
|
|
set_forward_border "$network" "$device" enable
|
|
|
|
|
|
|
|
# Configure device
|
|
|
|
conf_set "$device" accept_ra 2
|
|
|
|
conf_set "$device" forwarding 2
|
|
|
|
|
|
|
|
# Trigger RS
|
|
|
|
conf_set "$device" disable_ipv6 1
|
|
|
|
conf_set "$device" disable_ipv6 0
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
elif [ "$state" == "stopped" ]; then
|
|
|
|
# Deconfigure device
|
|
|
|
conf_set "$device" accept_ra 1
|
|
|
|
conf_set "$device" forwarding 1
|
|
|
|
|
|
|
|
# Disable border
|
|
|
|
set_forward_border "$network" "$device" disable
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
2012-11-29 20:14:28 +00:00
|
|
|
|
|
|
|
# Announce prefixes
|
|
|
|
for prefix in $PREFIXES; do
|
2012-12-27 14:10:17 +00:00
|
|
|
announce_prefix "$prefix" "$network" "$device"
|
2012-11-29 20:14:28 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for prefix in $PREFIXES_LOST; do
|
2012-12-27 14:10:17 +00:00
|
|
|
announce_prefix "$prefix" "$network" "$device" delprefix
|
2012-11-29 20:14:28 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
|
2013-01-02 23:05:44 +00:00
|
|
|
# Enable relaying if requested and we didn't get a prefix, disable otherwise
|
2012-12-09 13:54:22 +00:00
|
|
|
local fallback="stop"
|
|
|
|
[ -z "$PREFIXES" -a "$state" != "unbound" ] && fallback="start"
|
|
|
|
setup_prefix_fallback "$fallback" "$network" "$device"
|
2012-11-29 20:14:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Operations in case of success
|
2012-12-31 09:38:59 +00:00
|
|
|
[ "$state" == "timeout" -o "$state" == "unbound" ] && exit 0
|
2012-11-29 20:14:28 +00:00
|
|
|
|
2013-01-02 23:05:44 +00:00
|
|
|
# Handshake completed, disable forwarding border
|
|
|
|
set_forward_border "$network" "$device" disable
|
|
|
|
|
2012-11-29 20:14:28 +00:00
|
|
|
local peerdns
|
2012-12-29 10:12:31 +00:00
|
|
|
config_get_bool peerdns "$network" peerdns 1
|
2012-12-06 20:52:40 +00:00
|
|
|
[ "$peerdns" -eq "1" ] && {
|
2012-11-29 20:14:28 +00:00
|
|
|
proto_init_update "*" 1
|
2012-12-06 20:52:40 +00:00
|
|
|
proto_set_keep 1
|
2012-11-29 20:14:28 +00:00
|
|
|
for server in $RDNSS; do
|
|
|
|
proto_add_dns_server "$server"
|
|
|
|
done
|
|
|
|
for domain in $DOMAINS; do
|
|
|
|
proto_add_dns_search "$domain"
|
|
|
|
done
|
|
|
|
proto_send_update "$network"
|
|
|
|
}
|
|
|
|
|