summaryrefslogtreecommitdiffstats
path: root/package/network/ipv6/ipv6-support/files/dhcpv6.sh
blob: 5a668cd9b1ab6f905e7b9343cbc28ec23d31224a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/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

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

	# Send RS on interface
	[ -x /usr/sbin/6relayd ] && /usr/sbin/6relayd -s "$device"

	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

# Announce prefixes
for prefix in $PREFIXES; do
	announce_prefix "$prefix" "$network" "$device"
done

for prefix in $PREFIXES_LOST; do
	announce_prefix "$prefix" "$network" "$device" delprefix
done


# Enable relaying if requested and we didn't get a prefix, disable otherwise
local fallback="stop"
[ -z "$PREFIXES" -a "$state" != "unbound" ] && fallback="start"
setup_prefix_fallback "$fallback" "$network" "$device"


# Operations in case of success
[ "$state" == "timeout" -o "$state" == "unbound" ] && exit 0

# Handshake completed, disable forwarding border
set_forward_border "$network" "$device" disable

local peerdns
config_get_bool peerdns "$network" peerdns 1
[ "$peerdns" -eq "1" ] && {
	proto_init_update "*" 1
	proto_set_keep 1
	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"
}