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