ifdown 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin $NETWORK_DEVICES/ifdown
  4. #
  5. # Description : Interface Down
  6. #
  7. # Authors : Nathan Coulson - nathan@linuxfromscratch.org
  8. # Kevin P. Fleming - kpfleming@linuxfromscratch.org
  9. #
  10. # Version : 00.01
  11. #
  12. # Notes : the IFCONFIG variable is passed to the scripts found
  13. # in the services directory, to indicate what file the
  14. # service should source to get environmental variables.
  15. #
  16. ########################################################################
  17. . /lib/lsb/init-functions
  18. # Collect a list of configuration files for our interface
  19. if [ -n "${2}" ]; then
  20. for file in ${@#$1}; do # All parameters except $1
  21. FILES="${FILES} /run/network/ifconfig.${1}/${file}"
  22. done
  23. elif [ -d "/run/network/ifconfig.${1}" ]; then
  24. FILES=`echo /run/network/ifconfig.${1}/*`
  25. else
  26. FILES="/run/network/ifconfig.${1}"
  27. fi
  28. # Reverse the order configuration files are processed in
  29. for file in ${FILES}; do
  30. FILES2="${file} ${FILES2}"
  31. done
  32. FILES=${FILES2}
  33. # Process each configuration file
  34. for file in ${FILES}; do
  35. # skip backup files
  36. if [ "${file}" != "${file%""~""}" ]; then
  37. continue
  38. fi
  39. if [ ! -f "${file}" ]; then
  40. message="${file} is not a network configuration file or directory."
  41. log_warning_msg
  42. fi
  43. (
  44. if [ ! -d "${file}" ]; then
  45. . ${file}
  46. fi
  47. # Will not process this service if started by boot, and ONBOOT
  48. # is not set to yes
  49. if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
  50. continue
  51. fi
  52. # Will not process this service if started by hotplug, and
  53. # ONHOTPLUG is not set to yes
  54. if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" ]; then
  55. continue
  56. fi
  57. # This will run the service script, if SERVICE is set
  58. if [ -n "${SERVICE}" -a -x "/lib/network-services/${SERVICE}" ]; then
  59. if ip link show ${1} > /dev/null 2>&1
  60. then
  61. IFCONFIG=${file} /lib/network-services/${SERVICE} ${1} down &&
  62. if [ -f "${file}" ]; then
  63. rm ${file}
  64. fi
  65. else
  66. message="Interface ${1} doesn't exist."
  67. log_warning_msg
  68. fi
  69. else
  70. echo -e "${FAILURE}Unable to process ${file}. Either"
  71. echo -e "${FAILURE}the SERVICE variable was not set,"
  72. echo -e "${FAILURE}or the specified service cannot be executed."
  73. message=""
  74. log_failure_msg
  75. fi
  76. )
  77. done
  78. if [ -z "${2}" ]; then
  79. link_status=`ip link show $1`
  80. if [ -n "${link_status}" ]; then
  81. if echo "${link_status}" | grep -q UP; then
  82. message="Bringing down the ${1} interface..."
  83. ip link set ${1} down
  84. evaluate_retval standard
  85. fi
  86. fi
  87. fi
  88. # End $NETWORK_DEVICES/ifdown