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.0
|
---|
12 | #
|
---|
13 | # Notes : The ${file} 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 |
|
---|
19 | RELEASE="7.0"
|
---|
20 |
|
---|
21 | USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
|
---|
22 | VERSTR="LFS ifup, version ${RELEASE}"
|
---|
23 |
|
---|
24 | while [ $# -gt 0 ]; do
|
---|
25 | case "$1" in
|
---|
26 | --help | -h) help="y"; break ;;
|
---|
27 |
|
---|
28 | --version | -V) echo "${VERSTR}"; exit 0 ;;
|
---|
29 |
|
---|
30 | -*) echo "ifup: ${1}: invalid option" >&2
|
---|
31 | echo "${USAGE}" >& 2
|
---|
32 | exit 2 ;;
|
---|
33 |
|
---|
34 | *) break ;;
|
---|
35 | esac
|
---|
36 | done
|
---|
37 |
|
---|
38 | if [ -n "$help" ]; then
|
---|
39 | echo "${VERSTR}"
|
---|
40 | echo "${USAGE}"
|
---|
41 | echo
|
---|
42 | cat << HERE_EOF
|
---|
43 | ifup is used to bring up a network interface. The interface
|
---|
44 | parameter, e.g. eth0 or eth0:2, must match the trailing part of the
|
---|
45 | interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2.
|
---|
46 |
|
---|
47 | HERE_EOF
|
---|
48 | exit 0
|
---|
49 | fi
|
---|
50 |
|
---|
51 | file=/etc/sysconfig/ifconfig.${1}
|
---|
52 |
|
---|
53 | # Skip backup files
|
---|
54 | [ "${file}" = "${file%""~""}" ] || exit 0
|
---|
55 |
|
---|
56 | . /lib/lsb/init-functions
|
---|
57 |
|
---|
58 | if [ ! -r "${file}" ]; then
|
---|
59 | log_warning_msg "\n${file} is missing or cannot be accessed."
|
---|
60 | exit 1
|
---|
61 | fi
|
---|
62 |
|
---|
63 | . $file
|
---|
64 |
|
---|
65 | # Do not process this service if started by boot, and ONBOOT
|
---|
66 | # is not set to yes
|
---|
67 | if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
|
---|
68 | log_info_msg2 "skipped\n"
|
---|
69 | exit 0
|
---|
70 | fi
|
---|
71 |
|
---|
72 | log_info_msg "Bringing up the ${1} interface... "
|
---|
73 |
|
---|
74 | if [ -z "$PHYS" ]; then
|
---|
75 | log_failure_msg "\n${file} does not define any physical interfaces [PHYS]."
|
---|
76 | exit 1
|
---|
77 | fi
|
---|
78 |
|
---|
79 | for S in ${SERVICE}; do
|
---|
80 | if [ ! -n "${S}" -o ! -x "/lib/services/${S}" ]; then
|
---|
81 | MSG="\nUnable to process ${file}. Either"
|
---|
82 | MSG="${MSG} the SERVICE variable was not set"
|
---|
83 | MSG="${MSG} or the specified service cannot be executed."
|
---|
84 | log_failure_msg "$MSG"
|
---|
85 | exit 1
|
---|
86 | fi
|
---|
87 | done
|
---|
88 |
|
---|
89 | PHY_IDX=0
|
---|
90 | for PHY in $PHYS ; do
|
---|
91 | if [ -z "${CHECK_LINK}" -o \
|
---|
92 | "${CHECK_LINK}" = "y" -o \
|
---|
93 | "${CHECK_LINK}" = "yes" -o \
|
---|
94 | "${CHECK_LINK}" = "1" ]; then
|
---|
95 |
|
---|
96 | # Bring up the interface
|
---|
97 | if ip link show ${PHY} > /dev/null 2>&1; then
|
---|
98 | link_status=`ip link show ${PHY}`
|
---|
99 |
|
---|
100 | if [ -n "${link_status}" ]; then
|
---|
101 | if ! echo "${link_status}" | grep -q UP; then
|
---|
102 | ip link set ${PHY} up
|
---|
103 | fi
|
---|
104 | fi
|
---|
105 |
|
---|
106 | else
|
---|
107 | log_warning_msg "\nInterface ${PHY} doesn't exist."
|
---|
108 | exit 0
|
---|
109 | fi
|
---|
110 |
|
---|
111 | # Link is up, so set MTU
|
---|
112 | if test -n "${MTU}"; then
|
---|
113 | # Use the proper MTU if there are multiple MTUs set in ${MTU}.
|
---|
114 | M=$(echo $MTU | awk -v idx=$PHY_IDX '{printf("%s", $idx);}')
|
---|
115 |
|
---|
116 | # If there is only one ${MTU}, but multiple ${PHYS}, use ${MTU}.
|
---|
117 | test -z ${M} && M="${MTU}"
|
---|
118 |
|
---|
119 | # Check if MTU has a "good" value.
|
---|
120 | if [ ${M} -gt 0 ] ; then
|
---|
121 | ip link set dev ${PHY} mtu ${M}
|
---|
122 | else
|
---|
123 | echo "Invalid MTU ${M}"
|
---|
124 | fi
|
---|
125 | fi
|
---|
126 | fi
|
---|
127 |
|
---|
128 | PHY_IDX=$((1 + ${PHY_IDX}))
|
---|
129 | done
|
---|
130 |
|
---|
131 | for S in ${SERVICE}; do
|
---|
132 | /lib/services/${S} ${file} up
|
---|
133 | done
|
---|
134 |
|
---|
135 | # End /sbin/ifup
|
---|