#!/bin/sh
# ip-up <interface> <myaddr> <daemon-pid> <local> <remote> \
    <network-addr> <netmask> <arg>

# Sample of the ip-up script.
# This is called when the CIPE interface is opened.
# Arguments:
#  $1 interface     the CIPE interface
#  $2 myaddr        our UDP address
#  $3 daemon-pid    the daemon's process ID
#  $4 local         IP address of our CIPE device
#  $5 remote        IP address of the remote CIPE device
#  $6 network-addr  network address of interface
#  $7 netmask       netmask of interface
#  $6 arg           argument supplied via options

# Purposes for this script: set up routes, set up proxy-arps, etc.
# start daemons, logging...

umask 022
PATH=/sbin:/bin:/usr/sbin:/usr/bin

# A minimal route to the remote CIPE is needed, or we won't talk to anyone.
# Note that ciped, unlike pppd, doesn't set any routes.
# route add -host $5 dev $1
# or if the interface is configured for broadcast (this will also give a host
# route for a point to point link
route add -net $6 netmask $7 dev $1 

# If this becomes our default route...
#route add default gw $5

# just a logging example
echo "UP $*" >> /tmp/cipe

# many systems like these pid files
echo $3 > /var/run/$1.pid

# Trigger the key exchange procedure, important when we're using SOCKS
# This _must_ run delayed and in the background
#(sleep 10; ping -c5 $5) &

# The following are just ideas for further consideration

# Interconnect two 10. subnets through the Internet!
# Assuming $4 is in 10.1 and $5 in 10.2
#route add -net 10.2.0.0 netmask 255.255.0.0 gw $5

# Proxy-ARP the peer's address on eth0
#arp -s $5 -D eth0 pub

# Evil tricks department: masquerade the CIPE peer's /24 network to our IP
#NA=`expr $5 : '\([0-9]*\.[0-9]*\.[0-9]*\.\)'`
#ipfwadm -F -a accept -m -b -S $NA.0/24 -D 0.0.0.0/0
# the usual way for this would be a case selection on $5 or $6, however


exit 0
