ifup 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin /sbin/ifup
  4. #
  5. # Description : Interface Up
  6. #
  7. # Authors : Nathan Coulson - nathan@linuxfromscratch.org
  8. # Kevin P. Fleming - kpfleming@linuxfromscratch.org
  9. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.2
  12. #
  13. # Notes : The IFCONFIG variable is passed to the SERVICE script
  14. # in the /lib/services directory, to indicate what file the
  15. # service should source to get interface specifications.
  16. #
  17. ########################################################################
  18. up()
  19. {
  20. if ip link show $1 > /dev/null 2>&1; then
  21. link_status=`ip link show $1`
  22. if [ -n "${link_status}" ]; then
  23. if ! echo "${link_status}" | grep -q UP; then
  24. ip link set $1 up
  25. fi
  26. fi
  27. else
  28. log_failure_msg "\nInterface ${1} doesn't exist."
  29. exit 1
  30. fi
  31. }
  32. RELEASE="7.2"
  33. USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
  34. VERSTR="LFS ifup, version ${RELEASE}"
  35. while [ $# -gt 0 ]; do
  36. case "$1" in
  37. --help | -h) help="y"; break ;;
  38. --version | -V) echo "${VERSTR}"; exit 0 ;;
  39. -*) echo "ifup: ${1}: invalid option" >&2
  40. echo "${USAGE}" >& 2
  41. exit 2 ;;
  42. *) break ;;
  43. esac
  44. done
  45. if [ -n "$help" ]; then
  46. echo "${VERSTR}"
  47. echo "${USAGE}"
  48. echo
  49. cat << HERE_EOF
  50. ifup is used to bring up a network interface. The interface
  51. parameter, e.g. eth0 or eth0:2, must match the trailing part of the
  52. interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2.
  53. HERE_EOF
  54. exit 0
  55. fi
  56. file=/etc/sysconfig/ifconfig.${1}
  57. # Skip backup files
  58. [ "${file}" = "${file%""~""}" ] || exit 0
  59. . /lib/lsb/init-functions
  60. log_info_msg "Bringing up the ${1} interface... "
  61. if [ ! -r "${file}" ]; then
  62. log_failure_msg2 "${file} is missing or cannot be accessed."
  63. exit 1
  64. fi
  65. . $file
  66. # Do not process this service if started by boot, and ONBOOT
  67. # is not set to yes
  68. if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
  69. log_info_msg2 "skipped"
  70. exit 0
  71. fi
  72. for S in ${SERVICE}; do
  73. if [ ! -x "/lib/services/${S}" ]; then
  74. MSG="\nUnable to process ${file}. Either "
  75. MSG="${MSG}the SERVICE '${S} was not present "
  76. MSG="${MSG}or cannot be executed."
  77. log_failure_msg "$MSG"
  78. exit 1
  79. fi
  80. done
  81. # Create/configure the interface
  82. for S in ${SERVICE}; do
  83. IFCONFIG=${file} /lib/services/${S} ${1} up
  84. done
  85. # Bring up the interface and any components
  86. for I in $1 $INTERFACE_COMPONENTS; do up $I; done
  87. # Set MTU if requested. Check if MTU has a "good" value.
  88. if test -n "${MTU}"; then
  89. if [[ ${MTU} =~ ^[0-9]+$ ]] && [[ $MTU -ge 68 ]] ; then
  90. for I in $1 $INTERFACE_COMPONENTS; do
  91. ip link set dev $I mtu $MTU;
  92. done
  93. else
  94. log_info_msg2 "Invalid MTU $MTU"
  95. fi
  96. fi
  97. # Set the route default gateway if requested
  98. if [ -n "${GATEWAY}" ]; then
  99. if ip route | grep -q default; then
  100. log_warning_msg "\nGateway already setup; skipping."
  101. else
  102. log_info_msg "Setting up default gateway..."
  103. ip route add default via ${GATEWAY} dev ${1}
  104. evaluate_retval
  105. fi
  106. fi
  107. # End /sbin/ifup