2013-01-14 01:35:09 +08: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"
|
|
|
|
proto_init_update "*" 1
|
|
|
|
|
2013-02-01 20:28:39 +08: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-14 01:35:09 +08:00
|
|
|
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
|
|
|
|
|
2013-02-12 16:23:54 +08:00
|
|
|
[ -n "$USERPREFIX" ] && proto_add_ipv6_prefix "$USERPREFIX"
|
|
|
|
|
2013-02-01 20:28:39 +08: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 17:06:25 +08:00
|
|
|
proto_add_ipv6_address "$addr" "$mask" "$preferred" "$valid" 1
|
2013-02-01 20:28:39 +08:00
|
|
|
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%%,*}"
|
|
|
|
|
2013-12-16 03:10:20 +08:00
|
|
|
if [ -z "$SOURCE_ROUTING" -o -z "$gw" ]; then
|
2014-02-12 16:54:43 +08:00
|
|
|
proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid"
|
2013-12-16 03:10:20 +08:00
|
|
|
else
|
|
|
|
proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid" "::/128"
|
2014-01-17 22:00:04 +08:00
|
|
|
for prefix in $PREFIXES $ADDRESSES; do
|
2013-12-16 03:10:20 +08:00
|
|
|
local paddr="${prefix%%,*}"
|
|
|
|
proto_add_ipv6_route "$addr" "$mask" "$gw" "$metric" "$valid" "$paddr"
|
|
|
|
done
|
|
|
|
fi
|
2013-02-01 20:28:39 +08:00
|
|
|
done
|
|
|
|
|
2014-03-31 14:43:50 +08:00
|
|
|
proto_add_data
|
|
|
|
[ -n "$CER" ] && json_add_string cer "$CER"
|
2014-05-23 14:26:23 +08:00
|
|
|
[ -n "$PASSTHRU" ] && json_add_string passthru "$PASSTHRU"
|
2014-07-24 22:17:41 +08:00
|
|
|
[ -n "$ZONE" ] && json_add_string zone "$ZONE"
|
2014-03-31 14:43:50 +08:00
|
|
|
proto_close_data
|
|
|
|
|
2013-01-14 01:35:09 +08:00
|
|
|
proto_send_update "$INTERFACE"
|
|
|
|
|
2014-04-30 23:52:30 +08:00
|
|
|
MAPTYPE=""
|
|
|
|
MAPRULE=""
|
|
|
|
|
2014-07-24 22:17:41 +08:00
|
|
|
if [ -n "$MAPE" -a -f /lib/netifd/proto/map.sh ]; then
|
2014-04-30 23:52:30 +08:00
|
|
|
MAPTYPE="map-e"
|
|
|
|
MAPRULE="$MAPE"
|
2014-07-24 22:17:41 +08:00
|
|
|
elif [ -n "$MAPT" -a -f /lib/netifd/proto/map.sh -a -f /proc/net/nat46/control ]; then
|
2014-04-30 23:52:30 +08:00
|
|
|
MAPTYPE="map-t"
|
|
|
|
MAPRULE="$MAPT"
|
2014-07-24 22:17:41 +08:00
|
|
|
elif [ -n "$LW4O6" -a -f /lib/netifd/proto/map.sh ]; then
|
2014-04-30 23:52:30 +08:00
|
|
|
MAPTYPE="lw4o6"
|
|
|
|
MAPRULE="$LW4O6"
|
|
|
|
fi
|
|
|
|
|
2014-07-26 20:23:28 +08:00
|
|
|
[ -n "$ZONE" ] || ZONE=$(fw3 -q network $INTERFACE)
|
2014-07-24 22:17:41 +08:00
|
|
|
|
|
|
|
if [ "$IFACE_MAP" != 0 -a -n "$MAPTYPE" -a -n "$MAPRULE" ]; then
|
|
|
|
[ -z "$IFACE_MAP" -o "$IFACE_MAP" = 1 ] && IFACE_MAP=${INTERFACE}_map
|
2014-04-30 23:52:30 +08:00
|
|
|
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"
|
2014-05-08 17:17:55 +08:00
|
|
|
json_add_string tunlink "$INTERFACE"
|
2014-07-24 22:17:41 +08:00
|
|
|
[ -n "$ZONE_MAP" ] || ZONE_MAP=$ZONE
|
2014-04-30 23:52:30 +08: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)"
|
2014-07-24 22:17:41 +08:00
|
|
|
elif [ -n "$AFTR_IP " -a "$IFACE_DSLITE" != 0 -a -f /lib/netifd/proto/dslite.sh ]; then
|
|
|
|
[ -z "$IFACE_DSLITE" -o "$IFACE_DSLITE" = 1 ] && IFACE_DSLITE=${INTERFACE}_dslite
|
|
|
|
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" ] || 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)"
|
2014-04-30 23:52:30 +08:00
|
|
|
fi
|
|
|
|
|
2013-01-14 01:35:09 +08: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 18:20:43 +08:00
|
|
|
bound)
|
|
|
|
teardown_interface "$1"
|
|
|
|
setup_interface "$1"
|
|
|
|
;;
|
|
|
|
informed|updated|rebound|ra-updated)
|
2013-01-14 01:35:09 +08:00
|
|
|
setup_interface "$1"
|
|
|
|
;;
|
2013-01-28 21:53:43 +08:00
|
|
|
started|stopped|unbound)
|
2013-01-14 01:35:09 +08:00
|
|
|
teardown_interface "$1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# user rules
|
|
|
|
[ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user
|
|
|
|
|
|
|
|
exit 0
|