2 [ -z "$2" ] && echo "Error: should be run by odhcpc6c" && exit 1
4 . /lib/netifd/netifd-proto.sh
8 proto_init_update "*" 1
11 for radns in $RA_DNS; do
14 [ "$radns" = "$dns" ] && duplicate=1
16 [ "$duplicate" = 0 ] && RDNSS="$RDNSS $radns"
20 proto_add_dns_server "$dns"
23 for radomain in $RA_DOMAINS; do
25 for domain in $DOMAINS; do
26 [ "$radomain" = "$domain" ] && duplicate=1
28 [ "$duplicate" = 0 ] && DOMAINS="$DOMAINS $radomain"
31 for domain in $DOMAINS; do
32 proto_add_dns_search "$domain"
35 for prefix in $PREFIXES; do
36 proto_add_ipv6_prefix "$prefix"
37 local entry="${prefix#*/}"
40 local valid="${entry%%,*}"
42 if [ -z "$RA_ADDRESSES" -a -z "$RA_ROUTES" -a \
43 -z "$RA_DNS" -a "$FAKE_ROUTES" = 1 ]; then
44 RA_ROUTES="::/0,$SERVER,$valid,4096"
48 [ -n "$USERPREFIX" ] && proto_add_ipv6_prefix "$USERPREFIX"
51 for entry in $RA_ADDRESSES; do
53 local addr="${entry%%/*}"
54 for dentry in $ADDRESSES; do
55 local daddr="${dentry%%/*}"
56 [ "$addr" = "$daddr" ] && duplicate=1
58 [ "$duplicate" = "0" ] && ADDRESSES="$ADDRESSES $entry"
61 for entry in $ADDRESSES; do
62 local addr="${entry%%/*}"
64 local mask="${entry%%,*}"
66 local preferred="${entry%%,*}"
68 local valid="${entry%%,*}"
70 proto_add_ipv6_address "$addr" "$mask" "$preferred" "$valid" 1
72 if [ -z "$RA_ADDRESSES" -a -z "$RA_ROUTES" -a \
73 -z "$RA_DNS" -a "$FAKE_ROUTES" = 1 ]; then
74 RA_ROUTES="::/0,$SERVER,$valid,4096"
78 for entry in $RA_ROUTES; do
79 local addr="${entry%%/*}"
81 local mask="${entry%%,*}"
83 local gw="${entry%%,*}"
85 local valid="${entry%%,*}"
87 local metric="${entry%%,*}"
89 if [ -z "$SOURCE_ROUTING" -o -z "$gw" ]; then
90 proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid"
92 proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid" "::/128"
93 for prefix in $PREFIXES $ADDRESSES; do
94 local paddr="${prefix%%,*}"
95 proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid" "$paddr"
101 [ -n "$CER" ] && json_add_string cer "$CER"
102 [ -n "$PASSTHRU" ] && json_add_string passthru "$PASSTHRU"
103 [ -n "$ZONE" ] && json_add_string zone "$ZONE"
106 proto_send_update "$INTERFACE"
111 if [ -n "$MAPE" -a -f /lib/netifd/proto/map.sh ]; then
114 elif [ -n "$MAPT" -a -f /lib/netifd/proto/map.sh -a -f /proc/net/nat46/control ]; then
117 elif [ -n "$LW4O6" -a -f /lib/netifd/proto/map.sh ]; then
122 [ -n "$ZONE" ] || ZONE=$(fw3 -q network $INTERFACE)
124 if [ "$IFACE_MAP" != 0 -a -n "$MAPTYPE" -a -n "$MAPRULE" ]; then
125 [ -z "$IFACE_MAP" -o "$IFACE_MAP" = 1 ] && IFACE_MAP=${INTERFACE}_4
127 json_add_string name "$IFACE_MAP"
128 json_add_string ifname "@$INTERFACE"
129 json_add_string proto map
130 json_add_string type "$MAPTYPE"
131 json_add_string rule "$MAPRULE"
132 json_add_string tunlink "$INTERFACE"
133 [ -n "$ZONE_MAP" ] || ZONE_MAP=$ZONE
134 [ -n "$ZONE_MAP" ] && json_add_string zone "$ZONE_MAP"
135 [ -n "$IFACE_MAP_DELEGATE" ] && json_add_boolean delegate "$IFACE_MAP_DELEGATE"
137 ubus call network add_dynamic "$(json_dump)"
138 elif [ -n "$AFTR" -a "$IFACE_DSLITE" != 0 -a -f /lib/netifd/proto/dslite.sh ]; then
139 [ -z "$IFACE_DSLITE" -o "$IFACE_DSLITE" = 1 ] && IFACE_DSLITE=${INTERFACE}_4
141 json_add_string name "$IFACE_DSLITE"
142 json_add_string ifname "@$INTERFACE"
143 json_add_string proto "dslite"
144 json_add_string peeraddr "$AFTR"
145 json_add_string tunlink "$INTERFACE"
146 [ -n "$ZONE_DSLITE" ] || ZONE_DSLITE=$ZONE
147 [ -n "$ZONE_DSLITE" ] && json_add_string zone "$ZONE_DSLITE"
148 [ -n "$IFACE_DSLITE_DELEGATE" ] && json_add_boolean delegate "$IFACE_DSLITE_DELEGATE"
150 ubus call network add_dynamic "$(json_dump)"
151 elif [ "$IFACE_464XLAT" != 0 -a -f /lib/netifd/proto/464xlat.sh ]; then
152 [ -z "$IFACE_464XLAT" -o "$IFACE_464XLAT" = 1 ] && IFACE_464XLAT=${INTERFACE}_4
154 json_add_string name "$IFACE_464XLAT"
155 json_add_string ifname "@$INTERFACE"
156 json_add_string proto "464xlat"
157 json_add_string tunlink "$INTERFACE"
158 [ -n "$ZONE_464XLAT" ] || ZONE_464XLAT=$ZONE
159 [ -n "$ZONE_464XLAT" ] && json_add_string zone "$ZONE_464XLAT"
160 [ -n "$IFACE_464XLAT_DELEGATE" ] && json_add_boolean delegate "$IFACE_464XLAT_DELEGATE"
162 ubus call network add_dynamic "$(json_dump)"
165 # Apply IPv6 / ND configuration
166 HOPLIMIT=$(cat /proc/sys/net/ipv6/conf/$device/hop_limit)
167 [ -n "$RA_HOPLIMIT" -a -n "$HOPLIMIT" ] && [ "$RA_HOPLIMIT" -gt "$HOPLIMIT" ] && echo "$RA_HOPLIMIT" > /proc/sys/net/ipv6/conf/$device/hop_limit
168 [ -n "$RA_MTU" ] && [ "$RA_MTU" -gt 0 ] && echo "$RA_MTU" > /proc/sys/net/ipv6/conf/$device/mtu
169 [ -n "$RA_REACHABLE" ] && [ "$RA_REACHABLE" -gt 0 ] && echo "$RA_REACHABLE" > /proc/sys/net/ipv6/neigh/$device/base_reachable_time_ms
170 [ -n "$RA_RETRANSMIT" ] && [ "$RA_RETRANSMIT" -gt 0 ] && echo "$RA_RETRANSMIT" > /proc/sys/net/ipv6/neigh/$device/retrans_time_ms
172 # TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
175 teardown_interface() {
176 proto_init_update "*" 0
177 proto_send_update "$INTERFACE"
182 teardown_interface "$1"
185 informed|updated|rebound)
189 [ -n "$ADDRESSES$RA_ADDRESSES$PREFIXES$USERPREFIX" ] && setup_interface "$1"
191 started|stopped|unbound)
192 teardown_interface "$1"
197 [ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user