7cc87deb77878b2bf0ef2c9dd70ccce02d2b5a2f
[openwrt.git] / package / base-files / files / sbin / ifdown
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3
4 . /etc/functions.sh
5 [ $# = 0 ] && { echo " $0 <group>"; exit; }
6 [ "x$1" = "x-a" ] && {
7 config_cb() {
8 [ interface != "$1" -o -z "$2" ] || eval "$0 $2"
9 }
10 config_load network
11 exit
12 }
13
14 include /lib/network
15 scan_interfaces
16
17 cfg=$1
18 debug "### ifdown $cfg ###"
19
20 config_get proto "$cfg" proto
21 [ -z "$proto" ] && { echo "interface not found."; exit; }
22
23 config_get iface "$cfg" device
24 [ "static" = "$proto" ] && {
25 env -i ACTION="ifdown" INTERFACE="$cfg" DEVICE="$iface" PROTO=static /sbin/hotplug-call "iface" &
26 }
27
28 # call interface stop handler
29 ( type "stop_interface_$proto" ) >/dev/null 2>/dev/null && eval "stop_interface_$proto '$cfg'"
30
31 # make sure all locks are removed
32 for lock in "/var/lock/dhcp-$iface" "/var/lock/ppp-$iface"; do
33 [ -f "$lock" ] && {
34 lock -u "$lock"
35 sleep 1
36 }
37 done
38
39 # kill active ppp daemon and other processes
40 config_get ifname "$cfg" ifname
41 pids="$(head -n1 -q /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid 2>/dev/null)"
42 for pid in $pids; do
43 [ -d "/proc/$pid" ] && {
44 kill $pid
45 [ -d "/proc/$pid" ] && {
46 sleep 1
47 kill -9 $pid 2>/dev/null >/dev/null
48 }
49 }
50 done
51 rm -f /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid
52
53 config_get ifname "$cfg" ifname
54 config_get device "$cfg" device
55
56 [ ."$device" != ."$ifname" ] || device=
57 for dev in $ifname $device; do
58 ifconfig "$dev" 0.0.0.0 down >/dev/null 2>/dev/null
59 done
60
61 config_get iftype "$cfg" type
62 [ "bridge" = "$iftype" ] && brctl delbr "$ifname" >/dev/null 2>/dev/null
63
64 # remove the interface's network state
65 uci_revert_state network "$1"
66
67
This page took 0.043404 seconds and 3 git commands to generate.