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
1 Hi, I sent this to the newsgroup, but it doesn't seem to have got
2 there, so I'm posting it here - sorry if it's posted twice
3
4 I needed some more flexibility for setting up my 6to4 tunnel
5 (which still doesn't work - argh!)
6
7 So I wrote this patch to /lib/rcscripts/net/ip6to4.sh. Note I know
8 hardly anything about Gentoo scripts, and little more about Bash
9 scripting - so please forgive any errors. Also, I'm sure some options
10 can be renamed/deleted/refactored/etc. so please don't hesitate to
11 share how they could be fixed. In particular, the 'suffix' variable
12 (i.e. what to add after 2002:XXXX:XXXX:) could be renamed? I didn't
13 know what to call it
14
15 Here's what's in my /etc/conf.d/net file:
16
17 link_6to4="ppp0"
18 config_6to4=( "ip6to4" )
19 suffix_6to4=:ff
20 relay_6to4=194.73.82.244 # 6to4.ipv6.bt.com
21 metric_6to4=16
22 RC_NEED_6to4="net.ppp0"
23
24 It gives me:
25 $ ip -6 addr
26 ...
27 87: 6to4@NONE: <NOARP,UP,10000> mtu 1480
28 inet6 2002:5991:d010::ff/16 scope global
29 valid_lft forever preferred_lft forever
30 inet6 ::89.145.208.16/128 scope global
31 valid_lft forever preferred_lft forever
32
33 $ ip -6 route
34 ...
35 2000::/3 via ::194.73.82.244 dev 6to4 metric 1 expires
36 21323996sec (null) 1480 ssthresh 1420 advmss 4294967295
37 ...
38
39 Obviously, leaving out any of the options make them default to
40 their original values. Did I do that right in the script? As
41 I said, I'm not really that much into bash scripting, so I'd
42 gladly accept criticism.
43
44 -------------------------cut here-------------------------
45 --- .ip6to4-orig.sh 2006-12-05 18:16:23.000000000 +0000
46 +++ ip6to4.sh 2006-12-06 00:58:31.000000000 +0000
47 @@ -3,6 +3,7 @@
48 # Distributed under the terms of the GNU General Public License v2
49
50 # Contributed by Roy Marples (uberlord@g.o)
51 +# Additions by Asfand Yar Qazi (ayqazi@×××××.com)
52
53 # void ip6to4_depend(void)
54 #
55 @@ -16,7 +17,7 @@
56 #
57 # Expose variables that can be configured
58 ip6to4_expose() {
59 - variables link
60 + variables link suffix relay metric
61 }
62
63 # bool ip6to4_start(char *interface)
64 @@ -40,7 +41,29 @@
65 eerror "link_${ifvar} is not set"
66 return 1
67 fi
68 -
69 +
70 + local suffix="suffix_${ifvar}"
71 + if [[ -z ${!suffix} ]] ; then
72 + suffix=:1
73 + else
74 + suffix=${!suffix}
75 + fi
76 +
77 + local relay="relay_${ifvar}"
78 + if [[ -z ${!relay} ]] ; then
79 + relay="192.88.99.1"
80 + else
81 + relay=${!relay}
82 + fi
83 +
84 + # metric is 1 by default?!
85 + local metric="metric_${ifvar}"
86 + if [[ ${!metric} -eq 1 ]] ; then
87 + metric="2147483647"
88 + else
89 + metric=${!metric}
90 + fi
91 +
92 interface_exists "${!host}" true || return 1
93
94 # An interface can have more than 1 ip address
95 @@ -66,7 +89,8 @@
96 [[ ${i} -lt 32 ]] && continue
97
98 veinfo "IPv4 address on ${!host}: ${ip}"
99 - local ip6=$(printf "2002:%02x%02x:%02x%02x::1" ${ip//./ })
100 + # local ip6=$(printf "2002:%02x%02x:%02x%02x::1" ${ip//./ } )
101 + local ip6=$(printf "2002:%02x%02x:%02x%02x:%s"
102 ${ip//./ } ${suffix} )
103 veinfo "Derived IPv6 address: ${ip6}"
104
105 # Now apply our IPv6 address to our config
106 @@ -89,8 +113,10 @@
107
108 # Add a route for us, ensuring we don't delete anything else
109 local routes="routes_${ifvar}[@]"
110 + # eval "routes_${ifvar}=( \"\${!routes}\" \
111 + # \"2003::/3 via ::192.88.99.1 metric 2147483647\" )"
112 eval "routes_${ifvar}=( \"\${!routes}\" \
113 - \"2003::/3 via ::192.88.99.1 metric 2147483647\" )"
114 + \"2003::/3 via ::${relay} metric ${metric}\" )"
115 }
116
117 # vim:ts=4
118 -------------------------cut here-------------------------
119 --
120 gentoo-dev@g.o mailing list