ifdown 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. . /etc/sysconfig/rc
  18. . ${rc_functions}
  19. # Collect a list of configuration files for our interface
  20. if [ -n "${2}" ]; then
  21. for file in ${@#$1}; do # All parameters except $1
  22. FILES="${FILES} ${network_devices}/ifconfig.${1}/${file}"
  23. done
  24. elif [ -d "${network_devices}/ifconfig.${1}" ]; then
  25. FILES=`echo ${network_devices}/ifconfig.${1}/*`
  26. else
  27. FILES="${network_devices}/ifconfig.${1}"
  28. fi
  29. # Reverse the order configuration files are processed in
  30. for file in ${FILES}; do
  31. FILES2="${file} ${FILES2}"
  32. done
  33. FILES=${FILES2}
  34. # Process each configuration file
  35. for file in ${FILES}; do
  36. # skip backup files
  37. if [ "${file}" != "${file%""~""}" ]; then
  38. continue
  39. fi
  40. if [ ! -f "${file}" ]; then
  41. boot_mesg "${file} is not a network configuration file or directory." ${WARNING}
  42. echo_warning
  43. continue
  44. fi
  45. (
  46. . ${file}
  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 "${network_devices}/services/${SERVICE}" ]; then
  59. if ip link show ${1} > /dev/null 2>&1
  60. then
  61. IFCONFIG=${file} ${network_devices}/services/${SERVICE} ${1} down
  62. else
  63. boot_mesg "Interface ${1} doesn't exist." ${WARNING}
  64. echo_warning
  65. fi
  66. else
  67. boot_mesg -n "Unable to process ${file}. Either" ${FAILURE}
  68. boot_mesg -n " the SERVICE variable was not set,"
  69. boot_mesg " or the specified service cannot be executed."
  70. echo_failure
  71. continue
  72. fi
  73. )
  74. done
  75. if [ -z "${2}" ]; then
  76. link_status=`ip link show $1`
  77. if [ -n "${link_status}" ]; then
  78. if echo "${link_status}" | grep -q UP; then
  79. boot_mesg "Bringing down the ${1} interface..."
  80. ip link set ${1} down
  81. evaluate_retval
  82. fi
  83. fi
  84. fi
  85. # End $network_devices/ifdown