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

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

# address of tunnel server
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 startup
if [ "${CONNECTION}" = "Ipredator" ] ; then

  # direct tunnelled packets to the tunnel server
  route del ${SERVER} dev ${TUNNEL}
  if [ "${GATEWAY}" = "" ] ; then
    route add -host ${SERVER} dev ${PRIMARY}
  else
    route add -host ${SERVER} gw ${GATEWAY} dev ${PRIMARY}
  fi

  # direct all other packets into the tunnel
  route del default ${PRIMARY}
  route add default dev ${TUNNEL}
fi

