| 1 | #!/bin/sh |
| 2 | # Copyright (C) 2006-2011 OpenWrt.org |
| 3 | |
| 4 | . /etc/functions.sh |
| 5 | [ $# = 0 ] && { echo " $0 <group>"; exit; } |
| 6 | |
| 7 | case "$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 ;; |
| 17 | esac |
| 18 | |
| 19 | include /lib/network |
| 20 | scan_interfaces |
| 21 | |
| 22 | cfg=$1 |
| 23 | debug "### ifdown $cfg ###" |
| 24 | |
| 25 | config_get proto "$cfg" proto |
| 26 | [ -z "$proto" ] && { echo "interface not found."; exit; } |
| 27 | |
| 28 | config_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 | |
| 36 | config_get ifname "$cfg" ifname |
| 37 | config_get device "$cfg" device |
| 38 | |
| 39 | [ ."$device" != ."$ifname" ] || device= |
| 40 | for dev in $ifname $device; do |
| 41 | ifconfig "$dev" 0.0.0.0 down >/dev/null 2>/dev/null |
| 42 | done |
| 43 | |
| 44 | config_get iftype "$cfg" type |
| 45 | [ "bridge" = "$iftype" ] && brctl delbr "$ifname" >/dev/null 2>/dev/null |
| 46 | |
| 47 | # remove the interface's dns entries |
| 48 | remove_dns "$cfg" |
| 49 | |
| 50 | # remove the interface's network state |
| 51 | uci_revert_state network "$1" |
| 52 | |
| 53 | # revert aliases state as well |
| 54 | config_get aliases "$1" aliases |
| 55 | for config in $aliases; do |
| 56 | uci_revert_state network "$config" |
| 57 | done |
| 58 | |