odhcp6c: Send RS on start
[openwrt/openwrt.git] / package / network / ipv6 / odhcp6c / files / dhcpv6.script
1 #!/bin/sh
2 [ -z "$2" ] && echo "Error: should be run by odhcpc6c" && exit 1
3 . /lib/functions.sh
4 . /lib/netifd/netifd-proto.sh
5
6 ipv6_conf() {
7 echo "$3" > "/proc/sys/net/ipv6/conf/$1/$2"
8 }
9
10 # RFC 6204 requires us to block forwarding until address acquisition is complete
11 ipv6_block_forwarding() {
12 ip6tables "-$2" forwarding_rule -o "$1" -j REJECT --reject-with no-route 2>/dev/null
13 }
14
15 prepare_interface() {
16 local device="$1"
17
18 ipv6_block_forwarding "$device" A
19
20 ipv6_conf "$device" accept_ra 2
21 ipv6_conf "$device" forwarding 2
22
23 # Send RS
24 [ -x /usr/sbin/6relayd ] && /usr/sbin/6relayd -s "$device"
25 }
26
27 cleanup_interface() {
28 local device="$1"
29 ipv6_conf "$device" accept_ra 1
30 ipv6_conf "$device" forwarding 1
31 ipv6_block_forwarding "$device" D
32 }
33
34 setup_interface () {
35 local device="$1"
36 ipv6_block_forwarding "$device" D
37
38 proto_init_update "*" 1
39
40 for dns in $RDNSS; do
41 proto_add_dns_server "$dns"
42 done
43
44 for domain in $DOMAINS; do
45 proto_add_dns_search "$domain"
46 done
47
48 for prefix in $PREFIXES; do
49 proto_add_ipv6_prefix "$prefix"
50 done
51
52 proto_send_update "$INTERFACE"
53
54 # TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
55 }
56
57 teardown_interface() {
58 proto_init_update "*" 0
59 proto_send_update "$INTERFACE"
60 }
61
62 case "$2" in
63 started)
64 prepare_interface "$1"
65 ;;
66 stopped)
67 cleanup_interface "$1"
68 ;;
69 informed|bound|updated|rebound)
70 setup_interface "$1"
71 ;;
72 unbound|timeout)
73 teardown_interface "$1"
74 ;;
75 esac
76
77 # user rules
78 [ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user
79
80 exit 0