1334ee8218310b16f487756801c6f314b247e99d
[openwrt/openwrt.git] / openwrt / 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 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
16 pid="$(cat /var/run/ppp-${cfg}.pid 2>/dev/null)"
17 [ -n "$pid" -a -d "/proc/$pid" ] && {
18 kill $pid
19 sleep 1
20 [ -d "/proc/$pid" ] && kill -9 $pid
21 }
22
23 # kill any other process associated with the interface
24 config_get ifname "$cfg" ifname
25 pid="$(cat /var/run/${ifname}.pid 2>/dev/null)"
26 [ -n "$pid" -a -d "/proc/$pid" ] && kill -9 $pid
27
28 config_get ifname "$cfg" ifname
29 ifconfig "$ifname" >/dev/null 2>/dev/null && {
30 ifconfig "$ifname" 0.0.0.0 down
31
32 config_get iftype "$cfg" type
33 [ "$iftype" = "bridge" ] && brctl delbr "$ifname"
34 }