Root/package/base-files/files/sbin/ifdown

1#!/bin/sh
2# Copyright (C) 2006-2011 OpenWrt.org
3
4. /etc/functions.sh
5[ $# = 0 ] && { echo " $0 <group>"; exit; }
6
7case "$1" in
8    "-a")
9        [ -e "/tmp/resolv.conf.auto" ] && rm /tmp/resolv.conf.auto
10        config_cb() {
11            [ interface != "$1" -o -z "$2" ] || eval "$0 -w $2"
12        }
13        config_load network
14        exit 0
15    ;;
16    "-w") shift ;;
17esac
18
19include /lib/network
20scan_interfaces
21
22cfg=$1
23debug "### ifdown $cfg ###"
24
25config_get proto "$cfg" proto
26[ -z "$proto" ] && { echo "interface not found."; exit; }
27
28config_get iface "$cfg" device
29[ "static" = "$proto" -o "none" = "$proto" ] && {
30    env -i ACTION="ifdown" INTERFACE="$cfg" DEVICE="$iface" PROTO="$proto" /sbin/hotplug-call "iface"
31}
32
33# call interface stop handler
34( type "stop_interface_$proto" ) >/dev/null 2>/dev/null && eval "stop_interface_$proto '$cfg'"
35
36config_get ifname "$cfg" ifname
37config_get device "$cfg" device
38
39[ ."$device" != ."$ifname" ] || device=
40for dev in $ifname $device; do
41    ifconfig "$dev" 0.0.0.0 down >/dev/null 2>/dev/null
42done
43
44config_get iftype "$cfg" type
45[ "bridge" = "$iftype" ] && brctl delbr "$ifname" >/dev/null 2>/dev/null
46
47# remove the interface's dns entries
48remove_dns "$cfg"
49
50# remove the interface's network state
51uci_revert_state network "$1"
52
53# revert aliases state as well
54config_get aliases "$1" aliases
55for config in $aliases; do
56    uci_revert_state network "$config"
57done
58

Archive Download this file



interactive