/[baselayout]/trunk/net.Linux/ip6to4.sh
Gentoo

Contents of /trunk/net.Linux/ip6to4.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2683 - (show annotations) (download) (as text)
Thu May 3 12:19:18 2007 UTC (7 years, 3 months ago) by uberlord
File MIME type: text/x-sh
File size: 2378 byte(s)
Only use any when >1 interface
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 _config_vars="$_config_vars link suffix relay"
5
6 ip6to4_depend() {
7 after interface
8 }
9
10 ip6to4_start() {
11 case " ${MODULES} " in
12 *" ifconfig "*)
13 if [ "${IFACE}" != "sit0" ] ; then
14 eerror "ip6to4 can only work on the sit0 interface using ifconfig"
15 eerror "emerge sys-apps/iproute2 to use other interfaces"
16 return 1
17 fi
18 esac
19
20 local host= suffix= relay= addr= iface=${IFACE} new= localip=
21 eval host=\$link_${IFVAR}
22 if [ -z "${host}" ] ; then
23 eerror "link_${IFVAR} not set"
24 return 1
25 fi
26
27 eval suffix=\${suffix_${IFVAR}:-1}
28 eval relay=\${relay_${IFVAR}:-192.88.99.1}
29
30 IFACE=${host}
31 addrs=$(_get_inet_addresses)
32 IFACE=${iface}
33 if [ -z "${addrs}" ] ; then
34 eerror "${host} is not configured with an IPv4 address"
35 return 1
36 fi
37
38 for addr in ${addrs} ; do
39 # Strip the subnet
40 local ip="${addr%/*}" subnet="${addr#*/}"
41 # We don't work on private IPv4 addresses
42 case "${ip}" in
43 127.*) continue ;;
44 10.*) continue ;;
45 192.168.*) continue ;;
46 172.*)
47 local i=16
48 while [ ${i} -lt 32 ] ; do
49 case "${ip}" in
50 172.${i}.*) break ;;
51 esac
52 i=$((${i} + 1))
53 done
54 [ ${i} -lt 32 ] && continue
55 ;;
56 esac
57
58 veinfo "IPv4 address on ${host}: ${ip}/${subnet}"
59 local OIFS=$IFS SIFS=${IFS-y} ipa= ip6=
60 IFS="${IFS}."
61 for i in ${ip} ; do
62 ipa="${ipa} ${i}"
63 done
64 if [ "${SIFS}" = "y" ] ; then
65 IFS=$OIFS
66 else
67 unset IFS
68 fi
69 eval ip6="$(printf "2002:%02x%02x:%02x%02x::%s" ${ipa} ${suffix})"
70 veinfo "Derived IPv6 address: ${ip6}"
71
72 # Now apply our IPv6 address to our config
73 new="${new}${new:+ }${ip6}/16"
74
75 if [ -n "${localip}" ] ; then
76 localip="any"
77 else
78 localip="${ip}"
79 fi
80 done
81
82 if [ -z "${new}" ] ; then
83 eerror "No global IPv4 addresses found on interface ${host}"
84 return 1
85 fi
86
87 if [ "${IFACE}" != "sit0" ] ; then
88 ebegin "Creating 6to4 tunnel on ${IFACE}"
89 _tunnel add "${IFACE}" mode sit ttl 255 remote any local "${localip}"
90 eend $? || return 1
91 _up
92 fi
93
94 # Now apply our config
95 eval config_${config_index}=\'"${new}"\'
96 config_index=$((${config_index} - 1))
97
98 # Add a route for us, ensuring we don't delete anything else
99 eval $(_get_array "routes_${IFVAR}")
100 eval routes_${IFVAR}="\"$@ '2003::/3 via ::${relay} metric 2147483647'\""
101 }
102
103 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20