package/busybox: udhcpc.script: wait for ipv6 default route from RA for stateful...
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 21 May 2019 02:54:28 +0000 (12:54 +1000)
committerPeter Korsgaard <peter@korsgaard.com>
Sun, 27 Oct 2019 19:24:33 +0000 (20:24 +0100)
udhcpc6 implements "stateful" DHCPv6 for explicitly requesting an address
and other configuration information. A major difference between DHCPv4
and DHCPv6 is that DHCPv6 does *not* advertise a default route; this is
determined by normal IPv6 autoconfiguration.

Add logic to wait up to IF_WAIT_DELAY seconds for the IPv6 route to be
configured; as above this doesn't come from DHCPv6 but rather the IPv6
Router Advertisement (RA) which happens independently from udhcpc6.  The
intent here is to try and ensure that the interface is route-able upon the
script's completion as it would be if called from udhcpc.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
package/busybox/udhcpc.script

index c2804a3b5a240af395e8e28802d997ae6837dbdc..711963f974e31a5e932c7154da0895a20a65d354 100755 (executable)
@@ -11,6 +11,24 @@ RESOLV_CONF="/etc/resolv.conf"
 # Handle stateful DHCPv6 like DHCPv4
 [ -n "$ipv6" ] && ip="$ipv6/128"
 
+if [ -z "${IF_WAIT_DELAY}" ]; then
+       IF_WAIT_DELAY=10
+fi
+
+wait_for_ipv6_default_route() {
+       printf "Waiting for IPv6 default route to appear"
+       while [ $IF_WAIT_DELAY -gt 0 ]; do
+               if [ -z "$(ip -6 route list | grep default)" ]; then
+                       printf "\n"
+                       return
+               fi
+               sleep 1
+               printf "."
+               : $((IF_WAIT_DELAY -= 1))
+       done
+       printf " timeout!\n"
+}
+
 case "$1" in
        deconfig)
                /sbin/ifconfig $interface up
@@ -39,6 +57,9 @@ case "$1" in
                        /usr/sbin/avahi-autoipd -k $interface
                fi
                /sbin/ifconfig $interface $ip $BROADCAST $NETMASK
+               if [ -n "$ipv6" ] ; then
+                       wait_for_ipv6_default_route
+               fi
 
                if [ -n "$router" ] ; then
                        echo "deleting routers"