#!/bin/sh
# Copyright (c) 2008 TAKANO Yuji <takachan@running-dog.net>
# 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.
#
# IPv6Route.sh - IPv6 route settings. 

HOME=/
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin/:/usr/local/bin
export HOME PATH

DEBUG=0

v6tunaddr="3ffe:505:1411::"
fletsaddr="2001:c90::"

v6tunprefix="-prefixlen 64"
fletsprefix="-prefixlen 32"

llif=`netstat -nr -f inet6 | grep default | awk '{print $4}'`

v6tungw="fe80::20d:bff:fe48:ef52%${llif}"
fletsgw="fe80::217:fff:fe1c:501a%${llif}"

if [ ! -z $DEBUG ]; then
    echo "route delete -inet6 default"
    echo "route delete -inet6 ${v6tunaddr}"
    echo "route add    -inet6 default ${v6tungw}"
    echo "route delete -inet6 ${fletsaddr} ${fletsprefix}"
    echo "route add    -inet6 ${fletsaddr} ${fletsprefix} ${fletsgw}"
    exit;
fi
# default gw delete 
route delete -inet6 default  > /dev/null 2>&1

# IPv6 TunnelE gw delete
route delete -inet6 ${v6tunaddr} > /dev/null 2>&1

# default gw add
route add -inet6 default ${v6tungw} > /dev/null 2>&1

# IPv6 Flets static route add
route delete -inet6 ${fletsaddr} > /dev/null 2>&1
route add -inet6 ${fletsaddr} ${fletsprefix} ${fletsgw} > /dev/null 2>&1

echo
echo "---> kame.net ping testing."
ping6 -c 3 -q www.kame.net

echo
echo "---> flets-v6.jp ping testing."
ping6 -c 3 -q flets-v6.jp

echo
echo "---> xcast6 && flets-v6.jp routing end."
echo

