make network scripts more robust, prevent multiple instances of pppd and udhcpc for...
[openwrt-10.03/.git] / package / base-files / default / sbin / ifdown
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3
4 [ $# = 0 ] && { echo "  $0 <group>"; exit; }
5 . /etc/functions.sh
6 include /lib/network
7 scan_interfaces
8
9 cfg=$1
10 debug "### ifdown $cfg ###"
11
12 config_get proto "$cfg" proto
13 [ -z "$proto" ] && { echo "interface not found."; exit; }
14
15 # kill active ppp daemon and other processes
16 config_get ifname "$cfg" ifname
17 pids="$(cat /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid 2>/dev/null)"
18 for pid in $pids; do 
19         [ -d "/proc/$pid" ] && {
20                 kill $pid
21                 sleep 1
22                 [ -d "/proc/$pid" ] && kill -9 $pid
23         }
24 done
25 rm -f /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid
26
27 config_get ifname "$cfg" ifname
28 config_get device "$cfg" ifname
29
30 [ ."$device" != ."$ifname" ] || device=
31 for dev in $ifname $device; do
32         ifconfig "$ifname" 0.0.0.0 down >/dev/null 2>/dev/null
33 done
34
35 config_get iftype "$cfg" type
36 [ "$iftype" = "bridge" ] && brctl delbr "$ifname" >/dev/null 2>/dev/null
37