ifdown 1.3 KB

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