Package: gogoc
Version: 1:1.2-2
Severity: wishlist
Tags: patch

I implemented a feature for my own usage which I would like to share. It 
enables gogoc to advertise subnets of the assigned network on multiple 
interfaces.

The confiuration is placed in /etc/gogoc/interfaces.conf. All interfaces listed 
there will get a subnet assigned in numeric order.


-- System Information:
Debian Release: 6.0.3
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.32-5-686-bigmem (SMP w/1 CPU core)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash

Versions of packages gogoc depends on:
ii  iproute                 20100519-3       networking and traffic control too
ii  libc6                   2.11.2-10        Embedded GNU C Library: Shared lib
ii  libgcc1                 1:4.4.5-8        GCC support library
ii  libssl0.9.8             0.9.8o-4squeeze4 SSL shared libraries
ii  libstdc++6              4.4.5-8          The GNU Standard C++ Library v3
ii  net-tools               1.60-23          The NET-3 networking toolkit

Versions of packages gogoc recommends:
ii  radvd                         1:1.6-1.1  Router Advertisement Daemon

gogoc suggests no packages.

-- Configuration Files:
/etc/gogoc/gogoc.conf changed [not included]
/etc/init.d/gogoc changed [not included]

-- no debconf information
--- /usr/share/gogoc/template/linux.sh.vanilla  2010-04-26 14:47:03.000000000 
+0200
+++ /usr/share/gogoc/template/linux.sh  2011-12-07 02:29:28.000000000 +0100
@@ -70,6 +70,31 @@
    $* # Execute command
 }
 
+SubInterfaces()
+{
+   if [ -f /etc/gogoc/interfaces.conf ] ; then
+       cat /etc/gogoc/interfaces.conf | sed -e 's/#.*$//' -e 
's/[[:space:]]*$//' -e 's/^[[:space:]]//' -e '/^$/d' | nl -n ln
+   fi
+}
+
+SubNet()
+{
+   net="$1"
+   mask=64
+   test -z "$3" || mask="$3"
+   sub="$2"
+
+   subnet="`sipcalc -S "$mask" "$net" | grep '^Network' | sed -e 
's/^Network[[:space:]]*-[[:space:]]//' -e 's/[[:space:]]*-[[:space:]]*$//'`"
+   if [ "$sub" -ne 0 ] ; then
+      pref="`echo "$subnet" | tail -n +2 | head -n "$sub" | tail -n 1`"
+   else
+      pref="`echo "$subnet" | head -n 1`"
+   fi
+   test -z "$pref" && return 1
+   echo "$pref" | sed 's/:0000:0000:0000:0000$//'
+}
+
+
 # Program localization 
 
 Display 1 "--- Start of configuration script. ---"
@@ -138,6 +163,12 @@
 
     # Remove address from TSP HOME INTERFACE
     ExecNoCheck $ifconfig $TSP_HOME_INTERFACE inet6 del $TSP_PREFIX::1/64
+
+    subif="`SubInterfaces`"
+    echo "$subif" | while read sub int ; do
+       PREF="`SubNet "${TSP_PREFIX}::0/${TSP_PREFIXLEN}" "$sub"`"
+       ExecNoCheck $ifconfig "$int" inet6 del ${PREF}::1/64
+    done
   fi
 
   # Delete default IPv6 route(s).
@@ -245,6 +276,18 @@
    Display 1 "Adding prefix to $TSP_HOME_INTERFACE"
    Exec $ifconfig $TSP_HOME_INTERFACE add $TSP_PREFIX::1/64
 
+   subif="`SubInterfaces`"
+   echo "$subif" | while read sub int ; do
+      PREF=`echo $TSP_PREFIX | sed 's/00$//'`
+      OLDADDR=`$ifconfig "$int" | grep "inet6.* $PREF" | sed -e "s/^.*inet6 
addr: //" -e "s/ Scope.*\$//"`
+      if [ ! -z $OLDADDR ]; then
+         Display 1 "Removing old IPv6 address $OLDADDR from $int"
+         Exec $ifconfig "$int" inet6 del $OLDADDR
+      fi
+      PREF="`SubNet "${TSP_PREFIX}::0/${TSP_PREFIXLEN}" "$sub"`"
+      Display 1 "Adding prefix ${PREF} to $int"
+      Exec $ifconfig "$int" inet6 add "${PREF}::1/64"
+   done
 
    # Stop radvd daemon if it was running. Twice.
    /etc/init.d/radvd stop
@@ -267,6 +310,22 @@
 };
 EOF
 
+   echo "$subif" | while read sub int ; do
+      PREF="`SubNet "${TSP_PREFIX}::0/${TSP_PREFIXLEN}" "$sub"`"
+      cat >> "$rtadvdconfigfile" <<EOF
+interface $int
+{
+  AdvSendAdvert on;
+  AdvLinkMTU 1280;
+  prefix ${PREF}::/64
+  {
+    AdvOnLink on;
+    AdvAutonomous on;
+  };
+};
+EOF
+   done
+
    # Start the radvd daemon.
    Display 1 "Starting radvd: $rtadvd -u radvd -C $rtadvdconfigfile"
    Exec $rtadvd -u radvd -p $rtadvd_pid -C $rtadvdconfigfile
--- /dev/null   2011-11-27 19:14:56.647041867 +0100
+++ /etc/gogoc/interfaces.conf  2011-12-07 02:37:02.000000000 +0100
@@ -0,0 +1,8 @@
+#
+# Use this file to list interfaces which should get an IPv6 network
+# assigned beside the if_prefix setting in gogoc.conf
+#
+
+# Guest networks
+#eth1  # well known guests
+

Reply via email to