odhcp6c: Add preliminary proto-handler
[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
24 cleanup_interface() {
25 local device="$1"
26 ipv6_conf "$device" accept_ra 1
27 ipv6_conf "$device" forwarding 1
28 ipv6_block_forwarding "$device" D
29 }
30
31 setup_interface () {
32 local device="$1"
33 ipv6_block_forwarding "$device" D
34
35 proto_init_update "*" 1
36
37 for dns in $RDNSS; do
38 proto_add_dns_server "$dns"
39 done
40
41 for domain in $DOMAINS; do
42 proto_add_dns_search "$domain"
43 done
44
45 for prefix in $PREFIXES; do
46 proto_add_ipv6_prefix "$prefix"
47 done
48
49 proto_send_update "$INTERFACE"
50
51 # TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
52 }
53
54 teardown_interface() {
55 proto_init_update "*" 0
56 proto_send_update "$INTERFACE"
57 }
58
59 case "$2" in
60 started)
61 prepare_interface "$1"
62 ;;
63 stopped)
64 cleanup_interface "$1"
65 ;;
66 informed|bound|updated|rebound)
67 setup_interface "$1"
68 ;;
69 unbound|timeout)
70 teardown_interface "$1"
71 ;;
72 esac
73
74 # user rules
75 [ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user
76
77 exit 0