call interface stop handler on ifdown
[openwrt.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 # call interface stop handler
16 ( type "stop_interface_$proto" ) >/dev/null 2>/dev/null && eval "stop_interface_$proto '$cfg'"
17
18 # make sure all locks are removed
19 for lock in "/var/lock/dhcp-$iface" "/var/lock/ppp-$iface"; do
20 [ -f "$lock" ] && {
21 lock -u "$lock"
22 sleep 1
23 }
24 done
25
26 # kill active ppp daemon and other processes
27 config_get ifname "$cfg" ifname
28 pids="$(cat /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid 2>/dev/null)"
29 for pid in $pids; do
30 [ -d "/proc/$pid" ] && {
31 kill $pid
32 [ -d "/proc/$pid" ] && {
33 sleep 1
34 kill -9 $pid 2>/dev/null >/dev/null
35 }
36 }
37 done
38 rm -f /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid
39
40 config_get ifname "$cfg" ifname
41 config_get device "$cfg" ifname
42
43 [ ."$device" != ."$ifname" ] || device=
44 for dev in $ifname $device; do
45 ifconfig "$ifname" 0.0.0.0 down >/dev/null 2>/dev/null
46 done
47
48 config_get iftype "$cfg" type
49 [ "$iftype" = "bridge" ] && brctl delbr "$ifname" >/dev/null 2>/dev/null
50
This page took 0.043669 seconds and 5 git commands to generate.