#! /bin/sh # # 6to4 Script to configure a 6to4 "tunnel" device # # Written by Daniel Lawson PATH=/sbin:/bin:/usr/sbin:/usr/bin test -f $DAEMON || exit 0 # Source configuration file . /etc/default/6to4 start_6to4_tunnel() { # GET EXTIF IP Address PPPIP=`ip -4 addr list $EXTIF | grep inet | awk '{ print $2'}` # From IanKumlien: # If you get a /netmask-bits suffix, then change the PPPIP line to: # PPPIP=`ip -4 addr list $EXTIF | grep inet | awk '{ print $2 }' | cut -d/ -f1` echo $PPPIP # Set up the tunnel ip tunnel add ${IF} mode sit remote any local $PPPIP ttl 255 ip link set dev ${IF} mtu 1472 up } start_routes() { # Route outgoing 6to4 via the tunnel ip -6 route add 2002::/16 dev ${IF} # If this is your only IPv6 connection, add some more routes as well: if [ ${ONLYCONN} == "yes" ]; then # This line seems necessary, but I've never found documented # anywhere. Try without if you can. ip -6 route add ::/96 dev ${IF} metric 1 # Add a route toe the 6to4 Anycast address? ip -6 route add 2000::/3 via ::${GWADDR} dev tun6to4 metric 1 fi } start_local_network() { # Add a 6to4 Address to ${INTIF} if [ -n ${INTIF} ]; then ip -6 addr add $(printf "2002:%02x%02x:%02x%02x::1/64" $(echo ${PPPIP} | tr '.' ' ')) dev ${INTIF} fi } stop_local_network() { if [ -n ${INTIF} ]; then # GET the *old* tunnel ip OLDIP=`ip -6 addr list dev ${IF} | grep inet6 | cut -d ":" -f 3 | cut -d '/' -f 1` # Remove the route via ${INTIF} ip -6 route del $(printf "2002:%02x%02x:%02x%02x::/64" $(echo ${OLDIP} | tr '.' ' ')) dev ${INTIF} # Remove the 6to4 IP assigned to ${INTIF} ip -6 addr del $(printf "2002:%02x%02x:%02x%02x::1/64" $(echo ${OLDIP} | tr '.' ' ')) dev ${INTIF} fi } stop_routes() { ip -6 route del 2002::/16 dev ${IF} if [ ${ONLYCONN} == "yes" ]; then ip -6 route del ::/96 dev ${IF} metric 1 ip -6 route del 2000::/3 via ::${GWADDR} dev ${IF} metric 1 fi } stop_6to4_tunnel() { ip -6 route flush dev ${IF} ip link set dev ${IF} down ip tunnel del ${IF} } restart_6to4_ad () { [ "yes" == "${RADVD}" ] && killall -1 radvd } case "$1" in start) echo -n "Setting up 6to4 IPv6 tunnel ($IF): " start_6to4_tunnel start_routes start_local_network restart_6to4_ad ;; stop) echo -n "Shutting down 6to4 IPv6 tunnel ($IF): " stop_local_network stop_routes stop_6to4_tunnel restart_6to4_ad ;; restart|force-reload) echo -n "Resetting 6to4 IPv6 tunnel ($IF): " stop_local_network stop_routes stop_6to4_tunnel start_6to4_tunnel start_routes start_local_network restart_6to4_ad ;; *) echo "Usage: $0 {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0