#!/bin/bash
# pppd ip-down script for all-to-tunnel routing

# name of primary network interface (before tunnel)
PRIMARY=eth0

# server ip address (for tunnel)
SERVER=$5

# gateway ip address (before tunnel - adsl router ip address)
GATEWAY="192.168.1.1"

# provided by pppd: string to identify connection aka ipparam option
CONNECTION=$6
if [ "${CONNECTION}" = "" ]; then CONNECTION=${PPP_IPPARAM}; fi

# provided by pppd: interface name
TUNNEL=$1
if [ "${TUNNEL}" = "" ]; then TUNNEL=${PPP_IFACE}; fi

# if we are being called as part of the tunnel shutdown
if [ "${CONNECTION}" = "Ipredator" ] ; then

  # direct packets back to the original interface
  route del default ${TUNNEL}
  route del ${SERVER} dev eth0
  if [ "${GATEWAY}" = "" ] ; then
    route add default dev ${PRIMARY}
  else
    route add default gw ${GATEWAY} dev ${PRIMARY}
  fi
fi

