aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/ipv6/odhcp6c/files
diff options
context:
space:
mode:
Diffstat (limited to 'package/network/ipv6/odhcp6c/files')
-rwxr-xr-xpackage/network/ipv6/odhcp6c/files/dhcpv6.script219
-rwxr-xr-xpackage/network/ipv6/odhcp6c/files/dhcpv6.sh103
2 files changed, 322 insertions, 0 deletions
diff --git a/package/network/ipv6/odhcp6c/files/dhcpv6.script b/package/network/ipv6/odhcp6c/files/dhcpv6.script
new file mode 100755
index 0000000..c307d09
--- /dev/null
+++ b/package/network/ipv6/odhcp6c/files/dhcpv6.script
@@ -0,0 +1,219 @@
+#!/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"
+ local prefsig=""
+ local addrsig=""
+ 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 radomain in $RA_DOMAINS; do
+ local duplicate=0
+ for domain in $DOMAINS; do
+ [ "$radomain" = "$domain" ] && duplicate=1
+ done
+ [ "$duplicate" = 0 ] && DOMAINS="$DOMAINS $radomain"
+ done
+
+ for domain in $DOMAINS; do
+ proto_add_dns_search "$domain"
+ done
+
+ for prefix in $PREFIXES; do
+ proto_add_ipv6_prefix "$prefix"
+ prefsig="$prefsig ${prefix%%,*}"
+ local entry="${prefix#*/}"
+ entry="${entry#*,}"
+ entry="${entry#*,}"
+ local valid="${entry%%,*}"
+
+ if [ -z "$RA_ADDRESSES" -a -z "$RA_ROUTES" -a \
+ -z "$RA_DNS" -a "$FAKE_ROUTES" = 1 ]; then
+ RA_ROUTES="::/0,$SERVER,$valid,4096"
+ fi
+ 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
+ addrsig="$addrsig $addr/$mask"
+
+ if [ -z "$RA_ADDRESSES" -a -z "$RA_ROUTES" -a \
+ -z "$RA_DNS" -a "$FAKE_ROUTES" = 1 ]; then
+ RA_ROUTES="::/0,$SERVER,$valid,4096"
+ fi
+
+ # RFC 7278
+ if [ "$mask" -eq 64 -a -z "$PREFIXES" -a -n "$EXTENDPREFIX" ]; then
+ proto_add_ipv6_prefix "$addr/$mask,$preferred,$valid"
+ fi
+ done
+
+ for entry in $RA_ROUTES; do
+ local duplicate=$NOSOURCEFILTER
+ local addr="${entry%%/*}"
+ entry="${entry#*/}"
+ local mask="${entry%%,*}"
+ entry="${entry#*,}"
+ local gw="${entry%%,*}"
+ entry="${entry#*,}"
+ local valid="${entry%%,*}"
+ entry="${entry#*,}"
+ local metric="${entry%%,*}"
+
+ for xentry in $RA_ROUTES; do
+ local xprefix="${xentry%%,*}"
+ xentry="${xentry#*,}"
+ local xgw="${xentry%%,*}"
+
+ [ -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"
+ else
+ 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"
+ [ -n "$PASSTHRU" ] && json_add_string passthru "$PASSTHRU"
+ [ -n "$ZONE" ] && json_add_string zone "$ZONE"
+ proto_close_data
+
+ proto_send_update "$INTERFACE"
+
+ MAPTYPE=""
+ MAPRULE=""
+
+ if [ -n "$MAPE" -a -f /lib/netifd/proto/map.sh ]; then
+ MAPTYPE="map-e"
+ MAPRULE="$MAPE"
+ elif [ -n "$MAPT" -a -f /lib/netifd/proto/map.sh -a -f /proc/net/nat46/control ]; then
+ MAPTYPE="map-t"
+ MAPRULE="$MAPT"
+ elif [ -n "$LW4O6" -a -f /lib/netifd/proto/map.sh ]; then
+ MAPTYPE="lw4o6"
+ MAPRULE="$LW4O6"
+ fi
+
+ [ -n "$ZONE" ] || ZONE=$(fw3 -q network $INTERFACE 2>/dev/null)
+
+ if [ "$IFACE_MAP" != 0 -a -n "$MAPTYPE" -a -n "$MAPRULE" ]; then
+ [ -z "$IFACE_MAP" -o "$IFACE_MAP" = 1 ] && IFACE_MAP=${INTERFACE}_4
+ 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 _prefsig "$prefsig"
+ [ "$MAPTYPE" = lw4o6 ] && json_add_string _addrsig "$addrsig"
+ json_add_string rule "$MAPRULE"
+ json_add_string tunlink "$INTERFACE"
+ [ -n "$ZONE_MAP" ] || ZONE_MAP=$ZONE
+ [ -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)"
+ elif [ -n "$AFTR" -a "$IFACE_DSLITE" != 0 -a -f /lib/netifd/proto/dslite.sh ]; then
+ [ -z "$IFACE_DSLITE" -o "$IFACE_DSLITE" = 1 ] && IFACE_DSLITE=${INTERFACE}_4
+ json_init
+ json_add_string name "$IFACE_DSLITE"
+ json_add_string ifname "@$INTERFACE"
+ json_add_string proto "dslite"
+ json_add_string peeraddr "$AFTR"
+ 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)"
+ elif [ "$IFACE_464XLAT" != 0 -a -f /lib/netifd/proto/464xlat.sh ]; then
+ [ -z "$IFACE_464XLAT" -o "$IFACE_464XLAT" = 1 ] && IFACE_464XLAT=${INTERFACE}_4
+ json_init
+ json_add_string name "$IFACE_464XLAT"
+ json_add_string ifname "@$INTERFACE"
+ json_add_string proto "464xlat"
+ json_add_string tunlink "$INTERFACE"
+ json_add_string _addrsig "$addrsig"
+ [ -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)"
+ fi
+
+ # Apply IPv6 / ND configuration
+ HOPLIMIT=$(cat /proc/sys/net/ipv6/conf/$device/hop_limit)
+ [ -n "$RA_HOPLIMIT" -a -n "$HOPLIMIT" ] && [ "$RA_HOPLIMIT" -gt "$HOPLIMIT" ] && echo "$RA_HOPLIMIT" > /proc/sys/net/ipv6/conf/$device/hop_limit
+ [ -n "$RA_MTU" ] && [ "$RA_MTU" -gt 0 ] && echo "$RA_MTU" > /proc/sys/net/ipv6/conf/$device/mtu
+ [ -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
+
+ # 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)
+ setup_interface "$1"
+ ;;
+ ra-updated)
+ [ -n "$ADDRESSES$RA_ADDRESSES$PREFIXES$USERPREFIX" ] && setup_interface "$1"
+ ;;
+ started|stopped|unbound)
+ teardown_interface "$1"
+ ;;
+esac
+
+# user rules
+[ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user
+
+exit 0
diff --git a/package/network/ipv6/odhcp6c/files/dhcpv6.sh b/package/network/ipv6/odhcp6c/files/dhcpv6.sh
new file mode 100755
index 0000000..6c47399
--- /dev/null
+++ b/package/network/ipv6/odhcp6c/files/dhcpv6.sh
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto "$@"
+
+proto_dhcpv6_init_config() {
+ renew_handler=1
+
+ proto_config_add_string 'reqaddress:or("try","force","none")'
+ proto_config_add_string 'reqprefix:or("auto","no",range(0, 64))'
+ proto_config_add_string clientid
+ proto_config_add_string 'reqopts:list(uinteger)'
+ proto_config_add_string 'noslaaconly:bool'
+ proto_config_add_string 'forceprefix:bool'
+ proto_config_add_string 'extendprefix:bool'
+ proto_config_add_string 'norelease:bool'
+ proto_config_add_string 'ip6prefix:ip6addr'
+ proto_config_add_string iface_dslite
+ proto_config_add_string zone_dslite
+ proto_config_add_string iface_map
+ proto_config_add_string zone_map
+ proto_config_add_string iface_464xlat
+ proto_config_add_string zone_464xlat
+ proto_config_add_string zone
+ proto_config_add_string 'ifaceid:ip6addr'
+ proto_config_add_string "userclass"
+ proto_config_add_string "vendorclass"
+ proto_config_add_boolean delegate
+ proto_config_add_int "soltimeout"
+ proto_config_add_boolean fakeroutes
+ proto_config_add_boolean sourcefilter
+}
+
+proto_dhcpv6_setup() {
+ local config="$1"
+ local iface="$2"
+
+ local reqaddress reqprefix clientid reqopts noslaaconly forceprefix extendprefix norelease ip6prefix iface_dslite iface_map iface_464xlat ifaceid userclass vendorclass delegate zone_dslite zone_map zone_464xlat zone soltimeout fakeroutes sourcefilter
+ json_get_vars reqaddress reqprefix clientid reqopts noslaaconly forceprefix extendprefix norelease ip6prefix iface_dslite iface_map iface_464xlat ifaceid userclass vendorclass delegate zone_dslite zone_map zone_464xlat zone soltimeout fakeroutes sourcefilter
+
+
+ # Configure
+ local opts=""
+ [ -n "$reqaddress" ] && append opts "-N$reqaddress"
+
+ [ -z "$reqprefix" -o "$reqprefix" = "auto" ] && reqprefix=0
+ [ "$reqprefix" != "no" ] && append opts "-P$reqprefix"
+
+ [ -n "$clientid" ] && append opts "-c$clientid"
+
+ [ "$noslaaconly" = "1" ] && append opts "-S"
+
+ [ "$forceprefix" = "1" ] && append opts "-F"
+
+ [ "$norelease" = "1" ] && append opts "-k"
+
+ [ -n "$ifaceid" ] && append opts "-i$ifaceid"
+
+ [ -n "$vendorclass" ] && append opts "-V$vendorclass"
+
+ [ -n "$userclass" ] && append opts "-u$userclass"
+
+ for opt in $reqopts; do
+ append opts "-r$opt"
+ done
+
+ append opts "-t${soltimeout:-120}"
+
+ [ -n "$ip6prefix" ] && proto_export "USERPREFIX=$ip6prefix"
+ [ -n "$iface_dslite" ] && proto_export "IFACE_DSLITE=$iface_dslite"
+ [ -n "$iface_map" ] && proto_export "IFACE_MAP=$iface_map"
+ [ -n "$iface_464xlat" ] && proto_export "IFACE_464XLAT=$iface_464xlat"
+ [ "$delegate" = "0" ] && proto_export "IFACE_DSLITE_DELEGATE=0"
+ [ "$delegate" = "0" ] && proto_export "IFACE_MAP_DELEGATE=0"
+ [ -n "$zone_dslite" ] && proto_export "ZONE_DSLITE=$zone_dslite"
+ [ -n "$zone_map" ] && proto_export "ZONE_MAP=$zone_map"
+ [ -n "$zone_464xlat" ] && proto_export "ZONE_464XLAT=$zone_464xlat"
+ [ -n "$zone" ] && proto_export "ZONE=$zone"
+ [ "$fakeroutes" != "0" ] && proto_export "FAKE_ROUTES=1"
+ [ "$sourcefilter" = "0" ] && proto_export "NOSOURCEFILTER=1"
+ [ "$extendprefix" = "1" ] && proto_export "EXTENDPREFIX=1"
+
+ proto_export "INTERFACE=$config"
+ proto_run_command "$config" odhcp6c \
+ -s /lib/netifd/dhcpv6.script \
+ $opts $iface
+}
+
+proto_dhcpv6_renew() {
+ local interface="$1"
+ # SIGUSR1 forces odhcp6c to renew its lease
+ local sigusr1="$(kill -l SIGUSR1)"
+ [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1
+}
+
+proto_dhcpv6_teardown() {
+ local interface="$1"
+ proto_kill_command "$interface"
+}
+
+add_protocol dhcpv6
+