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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#!/bin/sh
[ -z "$2" ] && echo "Error: should be run by odhcpc6c" && exit 1
. /lib/functions.sh
. /lib/netifd/netifd-proto.sh
setup_interface () {
local device="$1"
proto_init_update "*" 1
# Merge RA-DNS
for radns in $RA_DNS; do
local duplicate=0
for dns in $RDNSS; do
[ "$radns" = "$dns" ] && duplicate=1
done
[ "$duplicate" = 0 ] && RDNSS="$RDNSS $radns"
done
for dns in $RDNSS; do
proto_add_dns_server "$dns"
done
for domain in $DOMAINS; do
proto_add_dns_search "$domain"
done
for prefix in $PREFIXES; do
proto_add_ipv6_prefix "$prefix"
done
[ -n "$USERPREFIX" ] && proto_add_ipv6_prefix "$USERPREFIX"
# Merge addresses
for entry in $RA_ADDRESSES; do
local duplicate=0
local addr="${entry%%/*}"
for dentry in $ADDRESSES; do
local daddr="${dentry%%/*}"
[ "$addr" = "$daddr" ] && duplicate=1
done
[ "$duplicate" = "0" ] && ADDRESSES="$ADDRESSES $entry"
done
for entry in $ADDRESSES; do
local addr="${entry%%/*}"
entry="${entry#*/}"
local mask="${entry%%,*}"
entry="${entry#*,}"
local preferred="${entry%%,*}"
entry="${entry#*,}"
local valid="${entry%%,*}"
proto_add_ipv6_address "$addr" "$mask" "$preferred" "$valid" 1
done
for entry in $RA_ROUTES; do
local addr="${entry%%/*}"
entry="${entry#*/}"
local mask="${entry%%,*}"
entry="${entry#*,}"
local gw="${entry%%,*}"
entry="${entry#*,}"
local valid="${entry%%,*}"
entry="${entry#*,}"
local metric="${entry%%,*}"
if [ -z "$SOURCE_ROUTING" -o -z "$gw" ]; then
proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid"
else
proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid" "::/128"
for prefix in $PREFIXES $ADDRESSES; do
local paddr="${prefix%%,*}"
proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid" "$paddr"
done
fi
done
proto_add_data
[ -n "$CER" ] && json_add_string cer "$CER"
proto_close_data
proto_send_update "$INTERFACE"
if [ -n "$AFTR_IP " -a -n "$IFACE_DSLITE" ]; then
json_init
json_add_string name "$IFACE_DSLITE"
json_add_string ifname "@$INTERFACE"
json_add_string proto "dslite"
json_add_string peeraddr "$AFTR_IP"
json_add_string tunlink "$INTERFACE"
[ -n "$ZONE_DSLITE" ] && json_add_string zone "$ZONE_DSLITE"
[ -n "$IFACE_DSLITE_DELEGATE" ] && json_add_boolean delegate "$IFACE_DSLITE_DELEGATE"
json_close_object
ubus call network add_dynamic "$(json_dump)"
fi
MAPTYPE=""
MAPRULE=""
if [ -n "$MAPE" ]; then
MAPTYPE="map-e"
MAPRULE="$MAPE"
elif [ -n "$MAPT" ]; then
MAPTYPE="map-t"
MAPRULE="$MAPT"
elif [ -n "$LW4O6" ]; then
MAPTYPE="lw4o6"
MAPRULE="$LW4O6"
fi
if [ -n "$IFACE_MAP" -a -n "$MAPTYPE" -a -n "$MAPRULE" ]; then
json_init
json_add_string name "$IFACE_MAP"
json_add_string ifname "@$INTERFACE"
json_add_string proto map
json_add_string type "$MAPTYPE"
json_add_string rule "$MAPRULE"
[ -n "$ZONE_MAP" ] && json_add_string zone "$ZONE_MAP"
[ -n "$IFACE_MAP_DELEGATE" ] && json_add_boolean delegate "$IFACE_MAP_DELEGATE"
json_close_object
ubus call network add_dynamic "$(json_dump)"
fi
# TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
}
teardown_interface() {
proto_init_update "*" 0
proto_send_update "$INTERFACE"
}
case "$2" in
bound)
teardown_interface "$1"
setup_interface "$1"
;;
informed|updated|rebound|ra-updated)
setup_interface "$1"
;;
started|stopped|unbound)
teardown_interface "$1"
;;
esac
# user rules
[ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user
exit 0
|