#!/bin/sh # Copyright 2003 Konstantin Kabassanov LIP6 # Copyright 2003 Vincent Jardin 6WIND # 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. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Konstantin Kabassanov, LIP6 # This product includes software developed by Vincent Jardin, 6WIND # 4. Neither the name of the authors, of LIP6, of 6WIND nor the names of any # co-contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY LIP6 AND 6WIND 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 LIP6 OR 6WIND 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. # # Work funded by EuronetLab (http://www.euronetlab.net/). # $Id: teredo.relay,v 1.2 2003/10/22 23:17:22 vjardin Exp $ # $FreeBSD$ # This script sets up a Teredo Relay # # Here define the parameters of the relay # # 195.220.208.2 teredo.ipv6.6wind.com SERVER_IP=195.220.208.2 # Define a static global IPv6 address used to send the bubbles, # or let the script looking for an address. #SERVER_IP6="2001:660:3008:1970::2" SERVER_IP6="auto" # You should never change this value, otherwise update # ng_teredo.h # SERVER_UDP_PORT=3544 # Enforce IPv6 interfaces to get an IPv6 link-local address # sysctl -w net.inet6.ip6.auto_linklocal=1 # Create the interface node ``IFACE_TEREDO'' if it doesn't exist # already, otherwise just make sure it's not connected to anything. # IFACE_TEREDO="ng0" if ifconfig ${IFACE_TEREDO} >/dev/null 2>&1; then ifconfig ${IFACE_TEREDO} inet6 down delete >/dev/null 2>&1 ngctl shutdown ${IFACE_TEREDO}: fi ngctl mkpeer iface dummy inet6 # Attach the Teredo node socket to the ``inet6'' hook of the # interface node using the ng_iface(4) node type. # ngctl mkpeer ${IFACE_TEREDO}: teredo inet6 upstream NAME="ter0" ngctl name ${IFACE_TEREDO}:inet6 ${NAME} # Enable debugging information # ngctl msg ${NAME}: setverbose 0x03 # Set the origin address of the Relay # ngctl msg ${NAME}: setorigin ${SERVER_IP} # Set the IPv6 address # if [ "$SERVER_IP6" = "auto" ] ; then SERVER_IP6="`ifconfig -a | grep inet6 | awk '{ print $2 }' | grep -v fe80 | grep -v fec0 | grep -v "^::1" | head -1`" if [ "$SERVER_IP6" = "" ] ; then echo "Error: global IPv6 address not found. Please define one" >&2 exit 1 fi echo "Using $SERVER_IP6 to source the bubbles" else # Check if this static address is already set on an interface. # If not, configure it on our Teredo interface. TEST="`ifconfig -a | grep "$SERVER_IP6"`" if [ "${TEST}" = "" ] ; then ifconfig ${IFACE_TEREDO} inet6 ${SERVER_IP6}/128 fi fi ngctl msg ${NAME}: setglobal "$SERVER_IP6" # Wakeup the Teredo interface # ifconfig ${IFACE_TEREDO} up # XXX Set the linklocal address of the Teredo interface # LLIF=`ifconfig ${IFACE_TEREDO} inet6 | grep fe80 | head -1 | awk '{ print $2}' | cut -d "%" -f 1` if [ "${LLIF}" = "" ] ; then echo "error: ${IFACE_TEREDO} does not have a linklocal address" exit 1 fi ngctl msg ${NAME}: setlinklocal ${LLIF} # Attach a UDP socket to the ``downstream'' hook of the Teredo # node using the ng_ksocket(4) node type. # ngctl mkpeer ${NAME}: ksocket downstream inet/dgram/udp # Bind the UDP socket to the local relay IPv4 address # ngctl msg ${NAME}:downstream bind inet/${SERVER_IP}:${SERVER_UDP_PORT} # Enable IPv6 forwarding # sysctl -w net.inet6.ip6.forwarding=1 # Add the IPv6 Teredo route # route add -inet6 3ffe:831f:: -prefixlen 32 -iface ${IFACE_TEREDO}