#!/bin/sh # # Copyright (c) 2002-2004 Hajimu UMEMOTO # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $Mahoroba$ # # Usage: # 6to4.sh ipv4addr ipv6_defaultrouter # Example of host configuration in /etc/rc.conf: # ipv6_enable="YES" # Example of network configuration in /etc/rc.conf: # ipv6_enable="YES" # ipv6_gateway_enable="YES" # rtadvd_enable="YES" # rtadvd_interfaces="fxp0" # stf_network_ipv6_interface="fxp0" # stf_network_ipv6_slaid="1" # default # TODO: # - Multiple local side interfaces if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi stf_interface_ipv4addr="$1" ipv6_defaultrouter="$2" case ${ipv6_enable} in [Yy][Ee][Ss]) if [ -r /etc/rc.network6 ]; then . /etc/rc.network6 else . /etc/network.subr fi # 6to4 setup ifconfig stf0 create >/dev/null 2>&1 oldaddrs=`ifconfig stf0 inet6 | awk '/inet6 2002:/ {print $2}'` for oaddr in ${oldaddrs}; do ifconfig stf0 inet6 ${oaddr} -alias done network6_stf_setup # setup static routes if [ -n "${ipv6_defaultrouter}" ]; then route delete -inet6 default >/dev/null 2>&1 route add -inet6 default ${ipv6_defaultrouter} fi # setup local side case ${stf_network_ipv6_interface} in [Nn][Oo] | '') ;; *) oldaddrs=`ifconfig ${stf_network_ipv6_interface} inet6 | awk '/inet6 2002:/ {print $2}'` for oaddr in ${oldaddrs}; do ifconfig ${stf_network_ipv6_interface} inet6 ${oaddr} -alias done OIFS="$IFS" IFS=".$IFS" set ${stf_interface_ipv4addr} IFS="$OIFS" ipv4_in_hexformat=`printf "%x:%x\n" \ $(($1*256 + $2)) $(($3*256 + $4))` eval ipv6_prefix_${stf_network_ipv6_interface}=\"2002:${ipv4_in_hexformat}:${stf_network_ipv6_slaid:-1}\" network6_interface_setup ${stf_network_ipv6_interface} ;; esac ;; esac