1
0

ifup 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 ${IFACE} 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. if [ "$IFACE" = "" ]; then
  67. log_failure_msg2 "${file} does not define an interface [IFACE]."
  68. exit 1
  69. fi
  70. # Do not process this service if started by boot, and ONBOOT
  71. # is not set to yes
  72. if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
  73. log_info_msg2 "skipped"
  74. exit 0
  75. fi
  76. for S in ${SERVICE}; do
  77. if [ ! -x "/lib/services/${S}" ]; then
  78. MSG="\nUnable to process ${file}. Either "
  79. MSG="${MSG}the SERVICE '${S} was not present "
  80. MSG="${MSG}or cannot be executed."
  81. log_failure_msg "$MSG"
  82. exit 1
  83. fi
  84. done
  85. # Create/configure the interface
  86. for S in ${SERVICE}; do
  87. IFCONFIG=${file} /lib/services/${S} ${IFACE} up
  88. done
  89. # Bring up the interface and any components
  90. for I in $IFACE $INTERFACE_COMPONENTS; do up $I; done
  91. # Set MTU if requested. Check if MTU has a "good" value.
  92. if test -n "${MTU}"; then
  93. if [[ ${MTU} =~ ^[0-9]+$ ]] && [[ $MTU -ge 68 ]] ; then
  94. for I in $IFACE $INTERFACE_COMPONENTS; do
  95. ip link set dev $I mtu $MTU;
  96. done
  97. else
  98. log_info_msg2 "Invalid MTU $MTU"
  99. fi
  100. fi
  101. # Set the route default gateway if requested
  102. if [ -n "${GATEWAY}" ]; then
  103. if ip route | grep -q default; then
  104. log_warning_msg "\nGateway already setup; skipping."
  105. else
  106. log_info_msg "Setting up default gateway..."
  107. ip route add default via ${GATEWAY} dev ${IFACE}
  108. evaluate_retval
  109. fi
  110. fi
  111. # End /sbin/ifup