ifdown 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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} ${NETWORK_DEVICES}/ifconfig.${1}/${file}"
  22. done
  23. elif [ -d "${NETWORK_DEVICES}/ifconfig.${1}" ]; then
  24. FILES=`echo ${NETWORK_DEVICES}/ifconfig.${1}/*`
  25. else
  26. FILES="${NETWORK_DEVICES}/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. . ${file}
  45. # Will not process this service if started by boot, and ONBOOT
  46. # is not set to yes
  47. if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
  48. continue
  49. fi
  50. # Will not process this service if started by hotplug, and
  51. # ONHOTPLUG is not set to yes
  52. if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" ]; then
  53. continue
  54. fi
  55. # This will run the service script, if SERVICE is set
  56. if [ -n "${SERVICE}" -a -x "${NETWORK_DEVICES}/services/${SERVICE}" ]; then
  57. if ip link show ${1} > /dev/null 2>&1
  58. then
  59. IFCONFIG=${file} ${NETWORK_DEVICES}/services/${SERVICE} ${1} down
  60. else
  61. message="Interface ${1} doesn't exist."
  62. log_warning_msg
  63. fi
  64. else
  65. echo -e "${FAILURE}Unable to process ${file}. Either"
  66. echo -e "${FAILURE}the SERVICE variable was not set,"
  67. echo -e "${FAILURE}or the specified service cannot be executed."
  68. message=""
  69. log_failure_msg
  70. fi
  71. )
  72. done
  73. if [ -z "${2}" ]; then
  74. link_status=`ip link show $1`
  75. if [ -n "${link_status}" ]; then
  76. if echo "${link_status}" | grep -q UP; then
  77. message="Bringing down the ${1} interface..."
  78. ip link set ${1} down
  79. evaluate_retval standard
  80. fi
  81. fi
  82. fi
  83. # End $NETWORK_DEVICES/ifdown