ifup 3.7 KB

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