2013-01-13 17:35:09 +00:00
|
|
|
#!/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"
|
2015-07-29 06:13:15 +00:00
|
|
|
local prefsig=""
|
|
|
|
local addrsig=""
|
2013-01-13 17:35:09 +00:00
|
|
|
proto_init_update "*" 1
|
|
|
|
|
2013-02-01 12:28:39 +00:00
|
|
|
# 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
|
|
|
|
|
2013-01-13 17:35:09 +00:00
|
|
|
for dns in $RDNSS; do
|
|
|
|
proto_add_dns_server "$dns"
|
|
|
|
done
|
|
|
|
|
2015-04-14 08:31:53 +00:00
|
|
|
for radomain in $RA_DOMAINS; do
|
|
|
|
local duplicate=0
|
|
|
|
for domain in $DOMAINS; do
|
|
|
|
[ "$radomain" = "$domain" ] && duplicate=1
|
|
|
|
done
|
|
|
|
[ "$duplicate" = 0 ] && DOMAINS="$DOMAINS $radomain"
|
|
|
|
done
|
|
|
|
|
2013-01-13 17:35:09 +00:00
|
|
|
for domain in $DOMAINS; do
|
|
|
|
proto_add_dns_search "$domain"
|
|
|
|
done
|
|
|
|
|
|
|
|
for prefix in $PREFIXES; do
|
|
|
|
proto_add_ipv6_prefix "$prefix"
|
2015-07-29 06:13:15 +00:00
|
|
|
prefsig="$prefsig ${prefix%%,*}"
|
2015-04-28 14:57:52 +00:00
|
|
|
local entry="${prefix#*/}"
|
|
|
|
entry="${entry#*,}"
|
|
|
|
entry="${entry#*,}"
|
|
|
|
local valid="${entry%%,*}"
|
2014-10-06 11:19:33 +00:00
|
|
|
|
|
|
|
if [ -z "$RA_ADDRESSES" -a -z "$RA_ROUTES" -a \
|
|
|
|
-z "$RA_DNS" -a "$FAKE_ROUTES" = 1 ]; then
|
|
|
|
RA_ROUTES="::/0,$SERVER,$valid,4096"
|
|
|
|
fi
|
2013-01-13 17:35:09 +00:00
|
|
|
done
|
|
|
|
|
2018-02-14 13:58:07 +00:00
|
|
|
for prefix in $USERPREFIX; do
|
|
|
|
proto_add_ipv6_prefix "$prefix"
|
|
|
|
done
|
2013-02-12 08:23:54 +00:00
|
|
|
|
2013-02-01 12:28:39 +00:00
|
|
|
# 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%%,*}"
|
|
|
|
|
2014-02-03 09:06:25 +00:00
|
|
|
proto_add_ipv6_address "$addr" "$mask" "$preferred" "$valid" 1
|
2015-07-29 06:13:15 +00:00
|
|
|
addrsig="$addrsig $addr/$mask"
|
2014-10-06 11:19:33 +00:00
|
|
|
|
2015-04-28 14:57:52 +00:00
|
|
|
if [ -z "$RA_ADDRESSES" -a -z "$RA_ROUTES" -a \
|
|
|
|
-z "$RA_DNS" -a "$FAKE_ROUTES" = 1 ]; then
|
|
|
|
RA_ROUTES="::/0,$SERVER,$valid,4096"
|
|
|
|
fi
|
2015-09-03 15:53:33 +00:00
|
|
|
|
|
|
|
# RFC 7278
|
|
|
|
if [ "$mask" -eq 64 -a -z "$PREFIXES" -a -n "$EXTENDPREFIX" ]; then
|
2015-09-04 06:29:36 +00:00
|
|
|
proto_add_ipv6_prefix "$addr/$mask,$preferred,$valid"
|
2017-09-05 12:33:01 +00:00
|
|
|
|
|
|
|
local raroutes=""
|
|
|
|
for route in $RA_ROUTES; do
|
|
|
|
local prefix="${route%%/*}"
|
|
|
|
local entry="${route#*/}"
|
|
|
|
local pmask="${entry%%,*}"
|
|
|
|
entry="${entry#*,}"
|
|
|
|
local gw="${entry%%,*}"
|
|
|
|
|
|
|
|
[ -z "$gw" -a "$mask" = "$pmask" ] && {
|
|
|
|
case "$addr" in
|
|
|
|
"${prefix%*::}"*) continue;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
raroutes="$raroutes $route"
|
|
|
|
done
|
|
|
|
RA_ROUTES="$raroutes"
|
2015-09-03 15:53:33 +00:00
|
|
|
fi
|
2013-02-01 12:28:39 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for entry in $RA_ROUTES; do
|
2015-07-18 05:44:50 +00:00
|
|
|
local duplicate=$NOSOURCEFILTER
|
2013-02-01 12:28:39 +00:00
|
|
|
local addr="${entry%%/*}"
|
|
|
|
entry="${entry#*/}"
|
|
|
|
local mask="${entry%%,*}"
|
|
|
|
entry="${entry#*,}"
|
|
|
|
local gw="${entry%%,*}"
|
|
|
|
entry="${entry#*,}"
|
|
|
|
local valid="${entry%%,*}"
|
|
|
|
entry="${entry#*,}"
|
|
|
|
local metric="${entry%%,*}"
|
|
|
|
|
2015-07-13 21:51:38 +00:00
|
|
|
for xentry in $RA_ROUTES; do
|
|
|
|
local xprefix="${xentry%%,*}"
|
|
|
|
xentry="${xentry#*,}"
|
|
|
|
local xgw="${xentry%%,*}"
|
2015-06-10 15:54:24 +00:00
|
|
|
|
2015-07-13 21:51:38 +00:00
|
|
|
[ -n "$gw" -a -z "$xgw" -a "$addr/$mask" = "$xprefix" ] && duplicate=1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$gw" -o "$duplicate" = 1 ]; then
|
|
|
|
proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid"
|
2013-12-15 19:10:20 +00:00
|
|
|
else
|
2014-01-17 14:00:04 +00:00
|
|
|
for prefix in $PREFIXES $ADDRESSES; do
|
2013-12-15 19:10:20 +00:00
|
|
|
local paddr="${prefix%%,*}"
|
|
|
|
proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid" "$paddr"
|
|
|
|
done
|
|
|
|
fi
|
2013-02-01 12:28:39 +00:00
|
|
|
done
|
|
|
|
|
2014-03-31 06:43:50 +00:00
|
|
|
proto_add_data
|
|
|
|
[ -n "$CER" ] && json_add_string cer "$CER"
|
2014-05-23 06:26:23 +00:00
|
|
|
[ -n "$PASSTHRU" ] && json_add_string passthru "$PASSTHRU"
|
2014-07-24 14:17:41 +00:00
|
|
|
[ -n "$ZONE" ] && json_add_string zone "$ZONE"
|
2014-03-31 06:43:50 +00:00
|
|
|
proto_close_data
|
|
|
|
|
2013-01-13 17:35:09 +00:00
|
|
|
proto_send_update "$INTERFACE"
|
|
|
|
|
2014-04-30 15:52:30 +00:00
|
|
|
MAPTYPE=""
|
|
|
|
MAPRULE=""
|
|
|
|
|
2014-07-24 14:17:41 +00:00
|
|
|
if [ -n "$MAPE" -a -f /lib/netifd/proto/map.sh ]; then
|
2014-04-30 15:52:30 +00:00
|
|
|
MAPTYPE="map-e"
|
|
|
|
MAPRULE="$MAPE"
|
2014-07-24 14:17:41 +00:00
|
|
|
elif [ -n "$MAPT" -a -f /lib/netifd/proto/map.sh -a -f /proc/net/nat46/control ]; then
|
2014-04-30 15:52:30 +00:00
|
|
|
MAPTYPE="map-t"
|
|
|
|
MAPRULE="$MAPT"
|
2014-07-24 14:17:41 +00:00
|
|
|
elif [ -n "$LW4O6" -a -f /lib/netifd/proto/map.sh ]; then
|
2014-04-30 15:52:30 +00:00
|
|
|
MAPTYPE="lw4o6"
|
|
|
|
MAPRULE="$LW4O6"
|
|
|
|
fi
|
|
|
|
|
2015-06-01 08:31:13 +00:00
|
|
|
[ -n "$ZONE" ] || ZONE=$(fw3 -q network $INTERFACE 2>/dev/null)
|
2014-07-24 14:17:41 +00:00
|
|
|
|
|
|
|
if [ "$IFACE_MAP" != 0 -a -n "$MAPTYPE" -a -n "$MAPRULE" ]; then
|
2015-04-17 13:10:19 +00:00
|
|
|
[ -z "$IFACE_MAP" -o "$IFACE_MAP" = 1 ] && IFACE_MAP=${INTERFACE}_4
|
2014-04-30 15:52:30 +00:00
|
|
|
json_init
|
|
|
|
json_add_string name "$IFACE_MAP"
|
|
|
|
json_add_string ifname "@$INTERFACE"
|
|
|
|
json_add_string proto map
|
|
|
|
json_add_string type "$MAPTYPE"
|
2015-07-29 06:13:15 +00:00
|
|
|
json_add_string _prefsig "$prefsig"
|
|
|
|
[ "$MAPTYPE" = lw4o6 ] && json_add_string _addrsig "$addrsig"
|
2014-04-30 15:52:30 +00:00
|
|
|
json_add_string rule "$MAPRULE"
|
2014-05-08 09:17:55 +00:00
|
|
|
json_add_string tunlink "$INTERFACE"
|
2014-07-24 14:17:41 +00:00
|
|
|
[ -n "$ZONE_MAP" ] || ZONE_MAP=$ZONE
|
2014-04-30 15:52:30 +00:00
|
|
|
[ -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)"
|
2015-04-09 08:17:32 +00:00
|
|
|
elif [ -n "$AFTR" -a "$IFACE_DSLITE" != 0 -a -f /lib/netifd/proto/dslite.sh ]; then
|
2015-04-17 13:10:19 +00:00
|
|
|
[ -z "$IFACE_DSLITE" -o "$IFACE_DSLITE" = 1 ] && IFACE_DSLITE=${INTERFACE}_4
|
2014-07-24 14:17:41 +00:00
|
|
|
json_init
|
|
|
|
json_add_string name "$IFACE_DSLITE"
|
|
|
|
json_add_string ifname "@$INTERFACE"
|
|
|
|
json_add_string proto "dslite"
|
2015-04-09 08:17:32 +00:00
|
|
|
json_add_string peeraddr "$AFTR"
|
2014-07-24 14:17:41 +00:00
|
|
|
json_add_string tunlink "$INTERFACE"
|
|
|
|
[ -n "$ZONE_DSLITE" ] || ZONE_DSLITE=$ZONE
|
|
|
|
[ -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)"
|
2015-04-09 08:17:32 +00:00
|
|
|
elif [ "$IFACE_464XLAT" != 0 -a -f /lib/netifd/proto/464xlat.sh ]; then
|
2015-04-17 13:10:19 +00:00
|
|
|
[ -z "$IFACE_464XLAT" -o "$IFACE_464XLAT" = 1 ] && IFACE_464XLAT=${INTERFACE}_4
|
2015-04-09 08:17:32 +00:00
|
|
|
json_init
|
|
|
|
json_add_string name "$IFACE_464XLAT"
|
|
|
|
json_add_string ifname "@$INTERFACE"
|
|
|
|
json_add_string proto "464xlat"
|
|
|
|
json_add_string tunlink "$INTERFACE"
|
2015-07-29 06:13:15 +00:00
|
|
|
json_add_string _addrsig "$addrsig"
|
2015-04-09 08:17:32 +00:00
|
|
|
[ -n "$ZONE_464XLAT" ] || ZONE_464XLAT=$ZONE
|
|
|
|
[ -n "$ZONE_464XLAT" ] && json_add_string zone "$ZONE_464XLAT"
|
|
|
|
[ -n "$IFACE_464XLAT_DELEGATE" ] && json_add_boolean delegate "$IFACE_464XLAT_DELEGATE"
|
|
|
|
json_close_object
|
|
|
|
ubus call network add_dynamic "$(json_dump)"
|
2014-04-30 15:52:30 +00:00
|
|
|
fi
|
|
|
|
|
2015-04-10 11:33:15 +00:00
|
|
|
# Apply IPv6 / ND configuration
|
|
|
|
HOPLIMIT=$(cat /proc/sys/net/ipv6/conf/$device/hop_limit)
|
2015-04-15 14:04:17 +00:00
|
|
|
[ -n "$RA_HOPLIMIT" -a -n "$HOPLIMIT" ] && [ "$RA_HOPLIMIT" -gt "$HOPLIMIT" ] && echo "$RA_HOPLIMIT" > /proc/sys/net/ipv6/conf/$device/hop_limit
|
2016-03-20 18:48:59 +00:00
|
|
|
[ -n "$RA_MTU" ] && [ "$RA_MTU" -ge 1280 ] && echo "$RA_MTU" > /proc/sys/net/ipv6/conf/$device/mtu 2>/dev/null
|
2015-04-15 14:04:17 +00:00
|
|
|
[ -n "$RA_REACHABLE" ] && [ "$RA_REACHABLE" -gt 0 ] && echo "$RA_REACHABLE" > /proc/sys/net/ipv6/neigh/$device/base_reachable_time_ms
|
|
|
|
[ -n "$RA_RETRANSMIT" ] && [ "$RA_RETRANSMIT" -gt 0 ] && echo "$RA_RETRANSMIT" > /proc/sys/net/ipv6/neigh/$device/retrans_time_ms
|
2015-04-10 11:33:15 +00:00
|
|
|
|
2013-01-13 17:35:09 +00:00
|
|
|
# TODO: $SNTP_IP $SIP_IP $SNTP_FQDN $SIP_DOMAIN
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown_interface() {
|
|
|
|
proto_init_update "*" 0
|
|
|
|
proto_send_update "$INTERFACE"
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$2" in
|
2013-05-06 10:20:43 +00:00
|
|
|
bound)
|
|
|
|
teardown_interface "$1"
|
|
|
|
setup_interface "$1"
|
|
|
|
;;
|
2014-10-08 15:27:17 +00:00
|
|
|
informed|updated|rebound)
|
2013-01-13 17:35:09 +00:00
|
|
|
setup_interface "$1"
|
|
|
|
;;
|
2014-10-08 15:16:19 +00:00
|
|
|
ra-updated)
|
|
|
|
[ -n "$ADDRESSES$RA_ADDRESSES$PREFIXES$USERPREFIX" ] && setup_interface "$1"
|
|
|
|
;;
|
2013-01-28 13:53:43 +00:00
|
|
|
started|stopped|unbound)
|
2013-01-13 17:35:09 +00:00
|
|
|
teardown_interface "$1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# user rules
|
2017-06-29 07:41:59 +00:00
|
|
|
[ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user "$@"
|
2013-01-13 17:35:09 +00:00
|
|
|
|
|
|
|
exit 0
|