#!/bin/sh
#----------------------------------------------------------------------------
# /etc/ppp/ipv6-down - called whenever a (i)ppp connection has disappeared
#
# Creation:        26.09.2009  zone42
# Last Update:     $Id: ipv6-down 27226 2013-04-19 23:46:27Z kristov $
#----------------------------------------------------------------------------

run_ipv6pre_down ()
{
    case $interface in
    ppp0)           # it's DSL, map interface
        case $tty in
        "" | eth*| br* | bond* | /dev/ttyp0 | /dev/ttyS[0-4] | /dev/ttyUSB[0-4] | /dev/capi/0 | /dev/ttyACM0 | /dev/ttyHS[0-3] | /dev/gsmmodem )
            # empty: PPPoE, eth[0-9] in_kernel, else PPTP
            interface=pppoe
            # kristov: pppoe-status cannot currently handle a dual-stack IPv4+IPv6 connection properly
            rm -f /var/run/pppoe.up
        ;;
        esac
    ;;
    *)
        rm -f /var/run/$interface.up
    ;;
    esac
    if [ -f /var/run/imond.pid ]
    then
        /usr/local/bin/imond-stat "$real_interface down"
    fi

    read default_route_interface < /var/run/online.ipv6

    if [ "$default_route_interface" = "$interface" ]
    then
        echo "default interface '$interface' goes down"
        rm -f /var/run/online.ipv6
        is_default_route='yes'
    else
        is_default_route='no'
    fi

    # Call all custom ipv6-downs
    for j in /etc/ppp/ipv6pre-down[0-9][0-9][0-9].*
    do
        if [ -f $j ]
        then
             echo "executing $j"
             . $j
        fi
    done
}

ip=ipv6pre
script_op=down
. /etc/ppp/ip-up-down
