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