ifupdown-scripts-zg2 (0.6-1) debian-changes

Summary

 scripts/ifupdown-scripts-zg2.d/address          |   29 ++++++++++++++++++++++--
 scripts/ifupdown-scripts-zg2.d/common-functions |    9 ++++---
 2 files changed, 33 insertions(+), 5 deletions(-)

    
download this patch

Patch contents

Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 ifupdown-scripts-zg2 (0.6-1) unstable; urgency=low
 .
   * add IPv6 support for addresses and routes
Author: Marc Haber <mh+debian-packages@zugschlus.de>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- ifupdown-scripts-zg2-0.6.orig/scripts/ifupdown-scripts-zg2.d/common-functions
+++ ifupdown-scripts-zg2-0.6/scripts/ifupdown-scripts-zg2.d/common-functions
@@ -16,7 +16,10 @@ me="$0"
 [ ${IF_DEBUG:-} ] && echo "$me $IFACE $MODE debug"
 
 [ "$METHOD" = "manual" ] || exit 0
-[ "$ADDRFAM" = "inet" ] || exit 0
+
+if [ "$ADDRFAM" != "inet" ] && [ "$ADDRFAM" != "inet6" ]; then
+  exit 0
+fi
 
 # common functions for interface scripts
 
@@ -277,10 +280,10 @@ get_if_mac()
 addrtype()
 {
   ADDR="$1"
-  if echo $ADDR | grep -q '^[0-9\.]\+$'; then
+  if echo $ADDR | grep -q '^[0-9\./]\+$'; then
     echo "v4"
     return 0
-  elif echo $ADDR | grep -q '^[0-9a-fA-F\:]\+$'; then
+  elif echo $ADDR | grep -q '^[0-9a-fA-F\:/]\+$'; then
     echo "v6"
     return 0
   else
--- ifupdown-scripts-zg2-0.6.orig/scripts/ifupdown-scripts-zg2.d/address
+++ ifupdown-scripts-zg2-0.6/scripts/ifupdown-scripts-zg2.d/address
@@ -10,18 +10,43 @@
 # IF_BRD     = broadcast address (all1 default, all0/none allowed)
 # IF_FLAGS   = "secondary"
 # IF_LABEL   = set label (1 default)
+# IF_FORCE_IPV6_RD  = force IPv6 Router Discovery before initializing
 # IF_WAIT_TENTATIVE = wait for non-tentative IP addresses (1 default)
 # IF_PREFLFT = preferred lifetime
 
 . /etc/network/ifupdown-scripts-zg2.d/common-functions
 
 # check that an address has been configured for this interface
-# TODO: Maybe check if it actually looks like an IP address?
 [ -z "${IF_ADDRESS:-}" ] && exit 0
+ADDRTYPE="$(addrtype $IF_ADDRESS)"
+if [ "$ADDRTYPE" != "v4" ] && [ "$ADDRTYPE" != "v6" ]; then
+  abort "address $IF_ADDRESS does not look like an IP address"
+fi
 
 case "$MODE" in
   start)
-  
+
+    # send IPv6 router discovery, making sure that we learn addresses
+    if [ "${IF_FORCE_IPV6_RD:-0}" = "1" ]; then
+      if command -v rdisc6 > /dev/null; then
+        loop=2
+        while ! rdisc6 --retry 1 --wait 2000 --single --quiet $IF_DEVICE >/dev/null 2>/dev/null; do
+	  if [ $loop -eq 2 ]; then
+            verbose "retrying IPv6 RD"
+          fi
+          if [ $loop -eq 0 ]; then
+            verbose "giving up on IPv6 RD"
+	    rdisc6 --retry 1 --wait 2000 --single $IF_DEVICE 
+	    break
+          fi
+          sleep 1
+          loop=$(($loop-1))
+        done
+      else
+        abort "force-ipv6-rd needs the ndisc6 package"
+      fi
+    fi
+
     # build address parameters, parse flags
   
     ADDRPARM="dev $IF_DEVICE"