Gentoo Archives: gentoo-dev

From: Asfand Yar Qazi <ayqazi@×××××.com>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] More options for /lib/rcscripts/net/ip6to4.sh script
Date: Wed, 06 Dec 2006 19:12:33
Message-Id: 79328ea80612061107n140da358x472aea0626be6a8e@mail.gmail.com
Hi, I sent this to the newsgroup, but it doesn't seem to have got
there, so I'm posting it here - sorry if it's posted twice

I needed some more flexibility for setting up my 6to4 tunnel
(which still doesn't work - argh!)

So I wrote this patch to /lib/rcscripts/net/ip6to4.sh.  Note I know
hardly anything about Gentoo scripts, and little more about Bash
scripting - so please forgive any errors.  Also, I'm sure some options
can be renamed/deleted/refactored/etc. so please don't hesitate to
share how they could be fixed.  In particular, the 'suffix' variable
(i.e. what to add after 2002:XXXX:XXXX:) could be renamed?  I didn't
know what to call it

Here's what's in my /etc/conf.d/net file:

link_6to4="ppp0"
config_6to4=( "ip6to4" )
suffix_6to4=:ff
relay_6to4=194.73.82.244 # 6to4.ipv6.bt.com
metric_6to4=16
RC_NEED_6to4="net.ppp0"

It gives me:
$ ip -6 addr
...
87: 6to4@NONE: <NOARP,UP,10000> mtu 1480
    inet6 2002:5991:d010::ff/16 scope global
       valid_lft forever preferred_lft forever
    inet6 ::89.145.208.16/128 scope global
       valid_lft forever preferred_lft forever

$ ip -6 route
...
2000::/3 via ::194.73.82.244 dev 6to4  metric 1 expires
  21323996sec (null) 1480 ssthresh 1420 advmss 4294967295
...

Obviously, leaving out any of the options make them default to
their original values.  Did I do that right in the script?  As
I said, I'm not really that much into bash scripting, so I'd
gladly accept criticism.

-------------------------cut here-------------------------
--- .ip6to4-orig.sh     2006-12-05 18:16:23.000000000 +0000
+++ ip6to4.sh   2006-12-06 00:58:31.000000000 +0000
@@ -3,6 +3,7 @@
 # Distributed under the terms of the GNU General Public License v2

 # Contributed by Roy Marples (uberlord@g.o)
+# Additions by Asfand Yar Qazi (ayqazi@×××××.com)

 # void ip6to4_depend(void)
 #
@@ -16,7 +17,7 @@
 #
 # Expose variables that can be configured
 ip6to4_expose() {
-       variables link
+       variables link suffix relay metric
 }

 # bool ip6to4_start(char *interface)
@@ -40,7 +41,29 @@
               eerror "link_${ifvar} is not set"
               return 1
       fi
-
+
+       local suffix="suffix_${ifvar}"
+       if [[ -z ${!suffix} ]] ; then
+               suffix=:1
+       else
+               suffix=${!suffix}
+       fi
+
+       local relay="relay_${ifvar}"
+       if [[ -z ${!relay} ]] ; then
+               relay="192.88.99.1"
+       else
+               relay=${!relay}
+       fi
+
+       # metric is 1 by default?!
+       local metric="metric_${ifvar}"
+       if [[ ${!metric} -eq 1 ]] ; then
+               metric="2147483647"
+       else
+               metric=${!metric}
+       fi
+
       interface_exists "${!host}" true || return 1

       # An interface can have more than 1 ip address
@@ -66,7 +89,8 @@
               [[ ${i} -lt 32 ]] && continue

               veinfo "IPv4 address on ${!host}: ${ip}"
-               local ip6=$(printf "2002:%02x%02x:%02x%02x::1" ${ip//./ })
+               # local ip6=$(printf "2002:%02x%02x:%02x%02x::1" ${ip//./ } )
+               local ip6=$(printf "2002:%02x%02x:%02x%02x:%s"
${ip//./ } ${suffix} )
               veinfo "Derived IPv6 address: ${ip6}"

               # Now apply our IPv6 address to our config
@@ -89,8 +113,10 @@

       # Add a route for us, ensuring we don't delete anything else
       local routes="routes_${ifvar}[@]"
+       # eval "routes_${ifvar}=( \"\${!routes}\" \
+       #               \"2003::/3 via ::192.88.99.1 metric 2147483647\" )"
       eval "routes_${ifvar}=( \"\${!routes}\" \
-                       \"2003::/3 via ::192.88.99.1 metric 2147483647\" )"
+                       \"2003::/3 via ::${relay} metric ${metric}\" )"
 }

 # vim:ts=4
-------------------------cut here-------------------------
-- 
gentoo-dev@g.o mailing list