#!/bin/sh

# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

# $Id: 6201a71b607f1b4254268f35b0e28e3262cda64e $

aftr_start()
{
    sysctl -w net.ipv4.ip_forward=1
    sysctl -w net.ipv6.conf.all.forwarding=1
    sysctl -w net.ipv4.conf.all.rp_filter=0

    ip link set tun0 up
    ip addr add 192.0.0.1 peer 192.0.0.2 dev tun0
#   ip route add 149.20.74.64/28 dev tun0
    ip route add 149.20.74.65/32 dev tun0
    ip -6 route add 2001:db8::/64 dev tun0
}

aftr_stop()
{
    ip link set tun0 down
}

set -x

PUBLIC=`ip addr show dev eth0 | grep -w inet | \
   awk '{print $2}' | awk -F/ '{print $1}'`

case "$1" in
start)
	aftr_start
	;;
stop)
	aftr_stop
	;;
*)
	echo "Usage: $0 start|stop"
	exit 1
	;;
esac

exit 0
