/[vps]/baselayout-vserver/trunk/net-scripts/net.modules.d/ip6to4
Gentoo

Contents of /baselayout-vserver/trunk/net-scripts/net.modules.d/ip6to4

Parent Directory Parent Directory | Revision Log Revision Log


Revision 236 - (show annotations) (download)
Tue Feb 14 13:00:44 2006 UTC (8 years, 9 months ago) by phreak
File size: 2485 byte(s)
Merging r1881
1 #!/bin/bash
2 # Copyright (c) 2004-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # void ip6to4_depend(void)
8 #
9 # Sets up the dependancies for the module
10 ip6to4_depend() {
11 after interface
12 functions interface_exists interface_get_address interface_tunnel
13 variables link
14 }
15
16 # bool ip6to4_start(char *interface)
17 #
18 # Configures IPv6 addresses to be added to the tunnel based on a IPv4
19 # addresses on a pre-configured interface.
20 # Returns 0 on success, otherwise 1.
21 ip6to4_start() {
22 local iface="$1" addr=""
23 local ifvar="$(bash_variable "${iface}")"
24
25 # Ensure the interface is sit0 if we're using ifconfig
26 if [[ " ${MODULES[@]} " == *" ifconfig "* && ${iface} != "sit0" ]] ; then
27 eerror "ip6to4 can only on interface sit0 using ifconfig"
28 eerror "emerge sys-apps/iproute2 to use other interfaces"
29 return 1
30 fi
31
32 local host="link_${ifvar}"
33 if [[ -z ${!host} ]] ; then
34 eerror "link_${ifvar} is not set"
35 return 1
36 fi
37
38 interface_exists "${!host}" true || return 1
39
40 # An interface can have more than 1 ip address
41 local -a addrs=( $(interface_get_address "${!host}") )
42 if [[ -z ${addrs} ]] ; then
43 eerror "${!host} is not configured with an IPv4 address"
44 return 1
45 fi
46
47 local -a new=()
48 local addr=""
49 for addr in "${addrs[@]}" ; do
50 # Strip the subnet
51 local ip="${addr%/*}" subnet="${addr#*/}"
52 # We don't work on private IPv4 addresses
53 [[ ${ip} == "127."* ]] && continue
54 [[ ${ip} == "10."* ]] && continue
55 [[ ${ip} == "192.168."* ]] && continue
56 local i
57 for ((i=16; i<32; i++)); do
58 [[ ${ip} == "172.${i}."* ]] && break
59 done
60 [[ ${i} -lt 32 ]] && continue
61
62 veinfo "IPv4 address on ${!host}: ${ip}"
63 local ip6="$(printf "2002:%02x%02x:%02x%02x::1" ${ip//./ })"
64 veinfo "Derived IPv6 address: ${ip6}"
65
66 # Now apply our IPv6 address to our config
67 new=( "${new[@]}" "${ip6}/16" )
68 done
69
70 if [[ -z ${new} ]] ; then
71 eerror "No global IPv4 addresses found on interface ${!host}"
72 return 1
73 fi
74
75 if [[ ${iface} != "sit0" ]] ; then
76 ebegin "Creating 6to4 tunnel on ${iface}"
77 interface_tunnel add "${iface}" mode sit ttl 255 remote any local "${ip}"
78 eend $? || return 1
79 fi
80
81 # Now apply our config
82 config=( "${config[@]}" "${new[@]}" )
83
84 # Add a route for us, ensuring we don't delete anything else
85 local routes="routes_${ifvar}[@]"
86 eval "routes_${ifvar}=( \"\${!routes}\" \
87 \"2003::/3 via ::192.88.99.1 metric 2147483647\" )"
88 }
89
90 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20