odhcp6c: Fix a race-condition in RA-handling
[openwrt/svn-archive/archive.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 setup_interface () {
7 local device="$1"
8 proto_init_update "*" 1
9
10 # Merge RA-DNS
11 for radns in $RA_DNS; do
12 local duplicate=0
13 for dns in $RDNSS; do
14 [ "$radns" = "$dns" ] && duplicate=1
15 done
16 [ "$duplicate" = 0 ] && RDNSS="$RDNSS $radns"
17 done
18
19 for dns in $RDNSS; do
20 proto_add_dns_server "$dns"
21 done
22
23 for domain in $DOMAINS; do
24 proto_add_dns_search "$domain"
25 done
26
27 for prefix in $PREFIXES; do
28 proto_add_ipv6_prefix "$prefix"
29 done
30
31 [ -n "$USERPREFIX" ] && proto_add_ipv6_prefix "$USERPREFIX"
32
33 # Merge addresses
34 for entry in $RA_ADDRESSES; do
35 local duplicate=0
36 local addr="${entry%%/*}"
37 for dentry in $ADDRESSES; do
38 local daddr="${dentry%%/*}"
39 [ "$addr" = "$daddr" ] && duplicate=1
40 done
41 [ "$duplicate" = "0" ] && ADDRESSES="$ADDRESSES $entry"
42 done
43
44 for entry in $ADDRESSES; do
45 local addr="${entry%%/*}"
46 entry="${entry#*/}"
47 local mask="${entry%%,*}"
48 entry="${entry#*,}"
49 local preferred="${entry%%,*}"
50 entry="${entry#*,}"
51 local valid="${entry%%,*}"
52
53 proto_add_ipv6_address "$addr" "$mask" "$preferred" "$valid" 1
54 done
55
56 for entry in $RA_ROUTES; do
57 local addr="${entry%%/*}"
58 entry="${entry#*/}"
59 local mask="${entry%%,*}"
60 entry="${entry#*,}"
61 local gw="${entry%%,*}"
62 entry="${entry#*,}"
63 local valid="${entry%%,*}"
64 entry="${entry#*,}"
65 local metric="${entry%%,*}"
66
67 proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid"
68 done
69
70 proto_send_update "$INTERFACE"
71
72 # TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
73 }
74
75 teardown_interface() {
76 proto_init_update "*" 0
77 proto_send_update "$INTERFACE"
78 }
79
80 case "$2" in
81 informed|bound|updated|rebound|ra-updated)
82 setup_interface "$1"
83 ;;
84 started|stopped|unbound)
85 teardown_interface "$1"
86 ;;
87 esac
88
89 # user rules
90 [ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user
91
92 exit 0