ifdown 1.7 KB

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