Subject: uruk: autodetect non-routable nets

From: Joost van Baal-Ilić <[email-masked]>
Date: Sat, 6 Apr 2013 06:35:57 +0200

Package: uruk
Tags: patch, upstream

Hoi,

Thanks for your bugreport.  I am submitting it to the Debian BTS, so
it won't get lost.  Please reply to <bugnr>@bugs.debian.org if you have
any more remarks on this issue.

O!  On which uruk-version are you working?

Groet!

Joost

Op Fri  5 Apr 2013 om 05:14:13 +0200 schreef Casper Gielen:
> Hoi Joost,
> hierbij een patch voor uruk.
> Precies één keer getest (op zomo).
> 
> ip-autodetectie werkt niet als je een interface hebt in een non-routable
> netwerk. Het netmask moet eigenlijk worden aangepast.
> 192.168.123.0/24 -> 192.168.0.0/16
> Onderstaande code zorgt daar voor. Na het weekend hoop ik het op een
> tweede systeem te testen.
> 
> 
> --- autodetect-ips      2013-04-05 17:10:44.000000000 +0200
> +++ autodetect-ips.old  2013-04-05 16:49:16.000000000 +0200
> @@ -30,25 +30,6 @@
>  ###############################################
> 
>  # For each interface <if> in interfaces, ip_<if> should be defined.
> -# if an autodetected address is in a non-routable range,
> -# then net_<iface>_default should expand to contain the entire range.
> -expandnet4()
> -{
> -       case "$1" in
> -               192.168.*) echo "192.168.0.0/24" ;;
> -               172.16.*)  echo "172.16.0.0/12"  ;;
> -               *)         echo "$1" ;;
> -       esac
> -}
> -
> -expandnet6()
> -{
> -       case "$1" in
> -               fc00:*)    echo "fc00::/7" ;;
> -               fec0:*)    echo "fec0::/10"  ;;
> -               *)         echo "$1" ;;
> -       esac
> -}
> 
>  # First try Red Hat's init scripts
>  for f in /etc/sysconfig/network-scripts/ifcfg-*
> @@ -60,12 +41,10 @@
>      esac
>      eval "$(
>          . $f
> -       net=$(expandnet4   $IPADDR/$NETMASK)
> -       net6=$(expandnet6 $IPADDR/$NETMASK)
>          echo ip_${i}_default=$IPADDR
> -        echo net_${i}_default=$net
> +        echo net_${i}_default=$IPADDR/$NETMASK
>          echo ip6_${i}_default=${IPV6ADDR%/*}
> -        echo net6_${i}_default=$net6
> +        echo net6_${i}_default=$IPV6ADDR
>      )"
>  done
> 
> @@ -92,13 +71,11 @@
>              esac
>              case $iface,$address,$netmask in ?*,?*,?*)
>                  case $type in inet)
> -                   net=$(expandnet4  $address/$netmask)
>                      echo ip_${iface}_default=$address
> -                    echo net_${iface}_default=$net
> +                    echo net_${iface}_default=$address/$netmask
>                  ;; inet6)
> -                   net6=$(expandnet6 $address/$netmask)
>                      echo ip6_${iface}_default=$address
> -                    echo net6_${iface}_default=$net6
> +                    echo net6_${iface}_default=$address/$netmask
>                  esac
>                  iface=
>                  type=
>

---

From: Casper Gielen <[email-masked]>
Date: Mon, 08 Apr 2013 16:57:39 +0200

> O!  On which uruk-version are you working?

20130226-1

-- 
Casper Gielen <[email-masked]> | LIS UNIX
PGP fingerprint = 16BD 2C9F 8156 C242 F981  63B8 2214 083C F80E 4AF7

Universiteit van Tilburg | Postbus 90153, 5000 LE
Warandelaan 2 | Telefoon 013 466 4100 | G 236 | http://www.uvt.nl

---

From: Joost van Baal-Ilić <[email-masked]>
Date: Tue, 9 Apr 2013 15:35:38 +0200

Hoi,

> > O!  On which uruk-version are you working?

That's current latest upstream, OK thanks.

your patch contains:

 -       case "$1" in

it misses some ranges:

joostvb@janacopoulos:~/git/uruk/uruk% grep \^ip._noroute_ranges script/uruk
ip4_noroute_ranges='127.0.0.1/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16'
ip6_noroute_ranges='::1/128 ffff:0:0::/96 fc00::/7 fec0::/10 0200::/7 2001:0db8::/32'

Furthermore, 172.16.0.0/12 is 172.16.0.0 - 172.31.255.255.  Your code would
wrongly place 172.32.0.1 in 172.16.0.0/12.

Care to fix that?

Hrm, there might be an easier way to work around the problem btw.  We could
e.g. state that autodetect-ips doesn't support that situation, and tell people
to use another trick.  The patch would update documentation only.  I am not
sure yet what's the best solution.

Anyway, thanks for your work!

Bye,

Joost

---

From: Casper Gielen <[email-masked]>
Date: Thu, 11 Apr 2013 14:32:06 +0200

Improvements over the last patch:

- more networkranges recognized
- proper regex for 172.16/16
- deal with combined ipv6addr/netmask on RHEL

Tested on zeneco, zuniran, zomo & zonozu.

--- autodetect-ips.old	2013-04-05 16:49:16.000000000 +0200
+++ autodetect-ips	2013-04-11 14:30:12.000000000 +0200
@@ -31,6 +31,31 @@

+# If an autodetected address is in a non-routable range,
+# then net_<iface>_default should expand to contain the entire range.
+expandnet4()
+{
+	case "$1" in
+		10.*)                                echo "10.0.0/8"  ;;
+		192.168.*)           		     echo "192.168.0.0/24" ;;
+                172.1[6-9].*|172.2?.*|172.3[0-1].*)  echo "172.16.0.0/12"  ;;
+		*)                                   echo "$1" ;;
+	esac
+}
+
+expandnet6()
+{
+	# Matching IPv6 with regexes is really hard.
+	# The code below assumes that the usual conventions for writing IPv6-adresses are followed.
+	case "$1" in
+		fc00:*)       echo "fc00::/7" ;;
+		fec0:*)       echo "fec0::/10"  ;;
+		::ffff:*:*)   echo "::ffff:0:0/96" ;;		
+		2001:0db8::*) echo "2001:0db8::/32" ;; 
+		*)            echo "$1" ;;
+	esac
+}
+
 # First try Red Hat's init scripts
 for f in /etc/sysconfig/network-scripts/ifcfg-*
 do
@@ -41,10 +66,12 @@
     esac
     eval "$(
         . $f
+	net4=$(expandnet4 $IPADDR/$NETMASK)
+	net6=$(expandnet6 $IPV6ADDR)  # netmask is deel van IPV6ADDR
         echo ip_${i}_default=$IPADDR
-        echo net_${i}_default=$IPADDR/$NETMASK
+        echo net_${i}_default=$net4
         echo ip6_${i}_default=${IPV6ADDR%/*}
-        echo net6_${i}_default=$IPV6ADDR
+        echo net6_${i}_default=$net6
     )"
 done
 
@@ -71,11 +98,13 @@
             esac
             case $iface,$address,$netmask in ?*,?*,?*)
                 case $type in inet)
+		    net=$(expandnet4 $address/$netmask)
                     echo ip_${iface}_default=$address
-                    echo net_${iface}_default=$address/$netmask
+                    echo net_${iface}_default=$net
                 ;; inet6)
+		    net=$(expandnet6 $address/$netmask)
                     echo ip6_${iface}_default=$address
-                    echo net6_${iface}_default=$address/$netmask
+                    echo net6_${iface}_default=$net
                 esac
                 iface=
                 type=