#!/bin/sh

RCDLINKS="2,S45 3,S45 6,K45"
################################################################################
#   Script to create an ipip tunnel -- Shorewall 1.1 
#
#   Modified - Steve Cowles 5/9/2000
#     Incorporated init {start|stop} syntax and iproute2 usage
#    
#     This program is under GPL [http://www.gnu.org/copyleft/gpl.htm]         
#
#     (c) 2000, 2001 - Tom Eastep (teastep@evergo.net)
#
#   Modify the following variables to match your configuration
################################################################################

# Name of the tunnel
#

tunnel="dfw-bos"

# Address of the local system -- this is the address of one of your 
# local interfaces (or for a mobile host, the address that this system has
# when attached to the local network). 
#

myip="192.168.9.1"

# Address of the Remote system -- this is the address of one of the 
# remote system's local interfaces (or if the remote system is a mobile host, 
# the address that it uses when attached to the local network).

hisip="192.168.10.1"

# Internet address of the Remote system
#

gateway="x.x.x.x"

# Remote sub-network -- if the remote system is a gateway for a 
#                       private subnetwork that you wish to 
#                       access, enter it here. If the remote
#                       system is a stand-alone/mobile host, leave this
#                       empty

subnet="192.168.10.0/24"

PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin

case "$1" in
  start)

      #NOTE: Comment out the next two lines if you have built ipip into your kernel
      echo "Loading IP-ENCAP Module"
      modprobe ipip

      if [ -n "`ip link show $tunnel 2>/dev/null`" ]; then
          $0 stop
      fi

      echo "Adding $tunnel"

      ip tunnel add $tunnel mode ipip remote $gateway

      echo "Starting $tunnel" 

      ip addr add $myip peer $hisip dev $tunnel
      ip link set dev $tunnel up

      #
      # As with all interfaces, the 2.2 kernels will add the obvious host
      # route for this point-to-point interface
      #

      if [ -n "$subnet" ]; then
          echo "Adding Routes"
          ip route add $subnet via $gateway dev $tunnel onlink
      fi
    ;;
  stop)
      if [ -n "`ip link show $tunnel 2>/dev/null`" ]; then
          echo "Stopping $tunnel"
          ip link set dev $tunnel down
      fi

      if [ -n "`ip addr show $tunnel 2>/dev/null`" ]; then
          echo "Deleting $tunnel"
          ip tunnel del $tunnel
      fi
    ;;
  restart)
      $0 stop
      sleep 1
      $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
exit 0
