#!/bin/sh #---------------------------------------------------------------------------- # /etc/ppp/addr-down - called whenever a circuit loses a local IPv4 address # # Input: # $1 = network interface # $2 = circuit identifier # $3 = local IPv4 address # $4 = if non-empty, we are called from within ip-down # # Last Update: $Id$ #---------------------------------------------------------------------------- . /etc/boot.d/forking.inc . /etc/boot.d/lazy.inc . /etc/boot.d/locking.inc . /etc/boot.d/networking.inc script_name="$(basename $0)" script="$script_name[$$]" facility=$circuit_logfacility logmsgprio=$facility.notice . /usr/share/logfunc.sh export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin interface=$1 circ_id=$2 address=$3 ipdown=$4 { fork_call_handlers sync_lock_resource addrupdown-$circ_id "$script" echo "$circ_id[$interface]: IPv4 address $address has disappeared" is_default_route=no circuit_read_field $circ_id circ_nets_ipv4_n for i in $(seq 1 $circ_nets_ipv4_n) do circuit_read_field $circ_id circ_nets_ipv4_$i net if [ "$net" = "0.0.0.0/0" ] then is_default_route=yes break fi done if [ "$is_default_route" = yes ] then # a local address connected to a gateway is assumed to be externally # visible, so remove it from dynamic.ip regex=$(echo $address | sed 's/\./\\./g;s,/,\\/,g') sync_lock_resource dynamic.ip addr-down sed -i "/^$regex$/d" /var/run/dynamic.ip [ -s /var/run/dynamic.ip ] || rm -f /var/run/dynamic.ip sync_unlock_resource dynamic.ip addr-down fi circuit_deregister_local_address $circ_id ipv4 $address setup-dynamic-iptables.sh # Call all custom addr-downs lazy_begin for j in /etc/ppp/addr-down[0-9][0-9][0-9].* do if [ -f $j ] then echo "executing $j" . $j fi done lazy_end cur_addresses=$(circuit_get_local_addresses $circ_id ipv4) if [ -z "$cur_addresses" -a -z "$ipdown" ] then # call ip-down when the last address is about to disappear /etc/ppp/ip-down $interface /dev/null 0 $address "" $circ_id 1 & fi sync_unlock_resource addrupdown-$circ_id "$script" } 2>&1 | logmsg "$script" $logmsgprio