5748954 [rkeene@sledge /home/rkeene/projects/6to4]$ cat -n ipv6.sh
  1 #!/bin/bash
  2 
  3 # IP (IPv6) suffix for your local machine (the prefix will be
  4 # automatically determined by your IP address)
  5 LOCAL_V6_ADDR="::1"
  6 
  7 # # Specify other network cards to assign IP (IPv6) addresses to
  8 # # (they will get a /64 size prefix)
  9 # V6NET[0]=eth1
 10 # V6NET[1]=eth2
 11 
 12 # Enable verbose messages about the 6to4 configuration
 13 VERBOSE=1
 14 
 15 # Enable this to enable a double check of your IP from a
 16 # remote host, used if you are behind a NAT.
 17 CHECKIP=0
 18 
 19 # # Specify a relay, if none-specified, the automatic one will
 20 # # be used.
 21 # RELAY=128.107.240.254
 22 
 23 # # Bypass automatic configuration of the interface:
 24 # # (note: Both or none should be set.)
 25 # LOCALIF=eth0
 26 # LOCAL4=1.2.3.4
 27 
 28 
 29 ######################################################################
 30 # The script begins.
 31 ######################################################################
 32 MAGIC="This line automatically added by ipv6"
 33 PATH="/sbin:usr/sbin:/usr/bin:/bin:/usr/local/v6/sbin:/usr/local/v6/bin:${PATH}"
 34 export PATH
 35 if [ \( -z "${VERBOSE}" -o "${VERBOSE}" = 0 \) -a "$1" = "start" ]; then
 36     $0 forked $1 &
 37     exit 0
 38 fi
 39 if [ "$1" = "forked" ]; then
 40     shift
 41 fi
 42 
 43 
 44 case "$1" in
 45     start)
 46     if [ "${CHECKIP}" = "1" ]; then
 47         echo "217.160.252.81    www.rkeene.org # ${MAGIC}" >> /etc/hosts
 48     fi
 49     while true; do
 50         if [ -z "$LOCAL4" ]; then
 51             if [ -z "$LOCAL_IF" ]; then
 52                 LOCAL_IF=$(route -n | grep '^0\.0\.0\.0 ' | sed -e s/'^.* '// )
 53             fi
 54             LOCAL4=$(ifconfig ${LOCAL_IF} | grep "^ *inet addr:" | sed s/'^ *inet addr:\([0-9.]\+\).*'/'\1'/g )
 55             if [ "${CHECKIP}" = "1" ]; then
 56                 LOCAL4_ALT=`lynx -dump http://www.rkeene.org/whatismyip/ | sed 's@^ *Your IP:@@g;t x;d;:x'`
 57                 if [ ! "${LOCAL4}" = "${LOCAL4_ALT}" ]; then
 58                     if [ "${VERBOSE}" = "1" ]; then
 59                         echo "Warning: IPs conflict, local says: ${LOCAL4}, remote says ${LOCAL4_ALT}"
 60                     fi
 61                     LOCAL4="${LOCAL4_ALT}"
 62                 fi
 63             fi
 64             if [ -z "$LOCAL4" ]; then
 65                 echo "Cannot find the IP assigned to $LOCAL_IF"
 66                 exit 1
 67             fi
 68         fi
 69         if [ ! "${LOCAL4}" = "127.0.0.1" ]; then break; fi
 70         sleep 10
 71     done
 72     if grep "# ${MAGIC}$" /etc/hosts >/dev/null; then
 73         grep -v "# ${MAGIC}$" /etc/hosts > /etc/hosts.new
 74         cat /etc/hosts.new > /etc/hosts
 75         rm /etc/hosts.new
 76     fi
 77 
 78     LOCAL6=2002:$(printf "%x%02x:%x%02x" $(echo $LOCAL4 | sed -e 's/\./ /g'))
 79     for ((i=0;i<${#V6NET[*]};i++)) {
 80         LOCAL6NET[${i}]="${LOCAL6}:$[${i}+1]::1/64"
 81     }
 82     LOCAL6_IP=${LOCAL6}${LOCAL_V6_ADDR}
 83     LOCAL6="${LOCAL6}${LOCAL_V6_ADDR}/48"
 84 
 85     modprobe ipv6 2>/dev/null >/dev/null
 86 
 87     if [ "${VERBOSE}" = "1" ]; then
 88         echo "Starting IPv6 routing policies: ${LOCAL6} on sit0"
 89     fi
 90 
 91     echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
 92 
 93     [ "$RELAY" ] || RELAY=192.88.99.1
 94 
 95     if [ "$VERBOSE" = "1" ]; then
 96         echo "Local v4 address: $LOCAL4, ${LOCAL4_ALT}"
 97         echo "Local v6 address: $LOCAL6"
 98         echo "Local v6net addresses: ${LOCAL6NET[*]}"
 99         echo "6to4 Relay address: $RELAY"
100     fi
101     ifconfig sit0 up
102     ifconfig sit0 add ${LOCAL6}
103     for ((i=0;i<${#V6NET[*]};i++)) {
104         ifconfig ${V6NET[${i}]} add ${LOCAL6NET[${i}]}
105     }
106     route -A inet6 add 2000::/3 gw ::$RELAY
107 
108     if [ ! "${#V6NET[*]}" = "0" ]; then
109         rm /etc/radvd.conf
110         for ((i=0;i<${#V6NET[*]};i++)) {
111             cat <<EOF >> /etc/radvd.conf
112 interface ${V6NET[${i}]} {
113         AdvSendAdvert on;
114     prefix ${LOCAL6NET[${i}]} {
115                 Base6to4Interface ${LOCAL_IF}; 
116                 AdvOnLink on;
117                 AdvAutonomous on;
118         };
119 };
120 
121 EOF
122         }
123         radvd
124     fi
125     echo -e "${LOCAL6_IP}   `hostname`  # ${MAGIC}" >> /etc/hosts 
126 
127     if [ "$VERBOSE" = "1" ]; then echo "Done!"; fi
128     ;;
129     stop)
130     echo 0 > /proc/sys/net/ipv6/conf/all/forwarding
131     ifconfig sit0 down
132     for ((i=0;i<${#V6NET[*]};i++)) {
133         IFACE=${V6NET[${i}]}
134         ADDRS=`ifconfig ${IFACE} | grep "^ *inet6 addr: .* Scope:Global" |awk '{ print $3 }'`
135         for addr in ${ADDRS}; do
136             ifconfig ${IFACE} del ${addr}
137         done
138     }
139     killall radvd 2>/dev/null
140     if grep "# ${MAGIC}$" /etc/hosts >/dev/null; then
141         grep -v "# ${MAGIC}$" /etc/hosts > /etc/hosts.new
142         cat /etc/hosts.new > /etc/hosts
143         rm /etc/hosts.new
144     fi
145     rmmod ipv6
146     ;;
147     *)
148     echo "Usage: $0 {start|stop}"
149     exit 1
150     ;;
151 esac
152 
153 exit 0

ipv6.sh est mon manuscrit d'init de la configuration "6to4".
5748955 [rkeene@sledge /home/rkeene/projects/6to4]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2006-07-05 16:24:24