#!/bin/sh
#----------------------------------------------------------------------------
# /etc/ppp/ip-up - called whenever a (i)ppp connection has been come up
#
# Creation:        29.03.2000  fm
# Last Update:     $Id: ip-up 10994 2006-02-15 11:58:37Z jw5 $
#----------------------------------------------------------------------------
export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin

real_interface=$1
interface=$1
tty=$2
speed=$3
local=$4
remote=$5

# Wait for end of boot
while [ ! -f /var/run/boot_finished ]
do
      sleep 3
done

run_ip_up ()
{
    case $interface in
    ppp0)                # it's DSL, map interface
        case $tty in
        "" | eth*| br* | /dev/ttyp0 | /dev/ttyS[0-4] | /dev/ttyUSB0 | /dev/capi/0 | /dev/ttyACM0 )
            # empty: PPPoE, eth[0-9] in_kernel, else PPTP
            interface=pppoe
            >/var/run/pppoe.up
        ;;
        esac
    ;;
    esac

    echo $local >/var/run/$interface.ip		# store my own ip address

    if [ -f /etc/default-route-interface ]	# default route existing?
    then
        default_route_interface=`/bin/cat /etc/default-route-interface`
    else
	default_route_interface=`/sbin/route -n | grep '^0.0.0.0' | sed 's/.* //g'`
	case $default_route_interface in
	    ppp0) default_route_interface=pppoe ;;
	esac
    fi
    if [ "$default_route_interface" = "$interface" ]
    then
	> /var/run/online
        /sbin/route add -net default dev $real_interface 2>/dev/null
        is_default_route='yes'
    else
        is_default_route='no'
    fi

    if [ "$interface" = "pppoe" -a -f /var/run/imond.pid ]
    then
	/usr/local/bin/imond-stat "pppoe: up"
    fi

    # Call all custom ip-ups
    for j in /etc/ppp/ip-up[0-9][0-9][0-9].*
    do
        if [ -f $j ]
        then
            . $j
        fi
    done
}

if [ -f /etc/syslog.conf ]		# Log to syslog if available...
then
    run_ip_up >/tmp/$$.tmp 2>&1
    logger -t ip-up </tmp/$$.tmp
    rm /tmp/$$.tmp
else
    run_ip_up >/dev/console 2>&1
fi

exit 0
