34 |
- |
1 |
#!/bin/bash
|
|
|
2 |
# Network Interface Configuration System
|
|
|
3 |
# Copyright (c) 1996-2013 Red Hat, Inc. all rights reserved.
|
|
|
4 |
#
|
|
|
5 |
# This program is free software; you can redistribute it and/or modify
|
|
|
6 |
# it under the terms of the GNU General Public License, version 2,
|
|
|
7 |
# as published by the Free Software Foundation.
|
|
|
8 |
#
|
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
# GNU General Public License for more details.
|
|
|
13 |
#
|
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
|
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
17 |
|
|
|
18 |
. /etc/init.d/functions
|
|
|
19 |
|
|
|
20 |
cd /etc/sysconfig/network-scripts
|
|
|
21 |
. ./network-functions
|
|
|
22 |
|
|
|
23 |
[ -f ../network ] && . ../network
|
|
|
24 |
|
|
|
25 |
CONFIG="${1}"
|
|
|
26 |
|
|
|
27 |
need_config "${CONFIG}"
|
|
|
28 |
|
|
|
29 |
source_config
|
|
|
30 |
|
|
|
31 |
# Allow the user to override the detection of our physical device by passing
|
|
|
32 |
# it in. No checking is done, if the user gives us a bogus dev, it's
|
|
|
33 |
# their problem.
|
|
|
34 |
[ -n "${PHYSDEV}" ] && REALDEVICE="$PHYSDEV"
|
|
|
35 |
|
|
|
36 |
if [ "${BOOTPROTO}" = "dhcp" ]; then
|
|
|
37 |
DYNCONFIG=true
|
|
|
38 |
fi
|
|
|
39 |
|
|
|
40 |
# load the module associated with that device
|
|
|
41 |
# /sbin/modprobe ${REALDEVICE}
|
|
|
42 |
is_available ${REALDEVICE}
|
|
|
43 |
|
|
|
44 |
# remap, if the device is bound with a MAC address and not the right device num
|
|
|
45 |
# bail out, if the MAC does not fit
|
|
|
46 |
if [ -n "${HWADDR}" ]; then
|
|
|
47 |
HWADDR=$(echo $HWADDR | tail -c 24)
|
|
|
48 |
FOUNDMACADDR=`get_hwaddr ${REALDEVICE} | tail -c 24`
|
|
|
49 |
if [ "${FOUNDMACADDR}" != "${HWADDR}" ]; then
|
|
|
50 |
curdev=`get_device_by_hwaddr ${HWADDR}`
|
|
|
51 |
if [ -n "$curdev" ]; then
|
|
|
52 |
ip link set dev "$curdev" name "${REALDEVICE}" || {
|
|
|
53 |
net_log $"Device ${DEVICE} has different MAC address than expected, ignoring."
|
|
|
54 |
exit 1
|
|
|
55 |
}
|
|
|
56 |
fi
|
|
|
57 |
fi
|
|
|
58 |
fi
|
|
|
59 |
|
|
|
60 |
# now check the real state
|
|
|
61 |
is_available ${REALDEVICE} || {
|
|
|
62 |
if [ -n "$alias" ]; then
|
|
|
63 |
net_log $"$alias device ${DEVICE} does not seem to be present, delaying initialization."
|
|
|
64 |
else
|
|
|
65 |
net_log $"Device ${DEVICE} does not seem to be present, delaying initialization."
|
|
|
66 |
fi
|
|
|
67 |
exit 1
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
# if we are a P_Key device, create the device if needed
|
|
|
71 |
if [ "${PKEY}" = yes ]; then
|
|
|
72 |
[ -z "${PKEY_ID}" ] && {
|
|
|
73 |
net_log $"InfiniBand IPoIB device: PKEY=yes requires a PKEY_ID"
|
|
|
74 |
exit 1
|
|
|
75 |
}
|
|
|
76 |
[ -z "${PHYSDEV}" ] && {
|
|
|
77 |
net_log $"InfiniBand IPoIB device: PKEY=yes requires a PHYSDEV"
|
|
|
78 |
exit 1
|
|
|
79 |
}
|
|
|
80 |
# Normalize our PKEY_ID to have the high bit set
|
|
|
81 |
NEW_PKEY_ID=`printf "0x%04x" $(( 0x8000 | ${PKEY_ID} ))`
|
|
|
82 |
NEW_PKEY_NAME=`printf "%04x" ${NEW_PKEY_ID}`
|
|
|
83 |
[ "${DEVICE}" != "${PHYSDEV}.${NEW_PKEY_NAME}" ] && {
|
|
|
84 |
net_log $"Configured DEVICE name does not match what new device name would be. This
|
|
|
85 |
is most likely because once the PKEY_ID was normalized, it no longer
|
|
|
86 |
resulted in the expected device naming, and so the DEVICE entry in the
|
|
|
87 |
config file needs to be updated to match. This can also be caused by
|
|
|
88 |
giving PKEY_ID as a hex number but without using the mandatory 0x prefix.
|
|
|
89 |
Configured DEVICE=$DEVICE
|
|
|
90 |
Configured PHYSDEV=$PHYSDEV
|
|
|
91 |
Configured PKEY_ID=$PKEY_ID
|
|
|
92 |
Calculated PKEY_ID=$NEW_PKEY_ID
|
|
|
93 |
Calculated name=${PHYSDEV}.${NEW_PKEY_NAME}"
|
|
|
94 |
exit 1
|
|
|
95 |
}
|
|
|
96 |
[ -d "/sys/class/net/${DEVICE}" ] ||
|
|
|
97 |
echo "${NEW_PKEY_ID}" > "/sys/class/net/${PHYSDEV}/create_child"
|
|
|
98 |
[ -d "/sys/class/net/${DEVICE}" ] || {
|
|
|
99 |
echo "Failed to create child device $NEW_PKEY_ID of $PHYSDEV"
|
|
|
100 |
exit 1
|
|
|
101 |
}
|
|
|
102 |
# When we get to setting up the IP address, we need REALDEVICE to
|
|
|
103 |
# point to our new PKEY device
|
|
|
104 |
REALDEVICE="${DEVICE}"
|
|
|
105 |
fi
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
if [ -n "${MACADDR}" ]; then
|
|
|
109 |
net_log $"IPoIB devices do not support setting the MAC address of the interface"
|
|
|
110 |
# ip link set dev ${DEVICE} address ${MACADDR}
|
|
|
111 |
fi
|
|
|
112 |
|
|
|
113 |
# First, do we even support setting connected mode?
|
|
|
114 |
if [ -e /sys/class/net/${DEVICE}/mode ]; then
|
|
|
115 |
# OK, set the mode in all cases, that way it gets reset on a down/up
|
|
|
116 |
# cycle, allowing people to change the mode without rebooting
|
|
|
117 |
if [ "${CONNECTED_MODE}" = yes ]; then
|
|
|
118 |
echo connected > /sys/class/net/${DEVICE}/mode
|
|
|
119 |
# cap the MTU where we should based upon mode
|
|
|
120 |
[ -z "$MTU" ] && MTU=65520
|
|
|
121 |
[ "$MTU" -gt 65520 ] && MTU=65520
|
|
|
122 |
else
|
|
|
123 |
echo datagram > /sys/class/net/${DEVICE}/mode
|
|
|
124 |
# cap the MTU where we should based upon mode
|
|
|
125 |
[ -z "$MTU" ] && MTU=4092
|
|
|
126 |
[ "$MTU" -gt 4092 ] && MTU=4092
|
|
|
127 |
fi
|
|
|
128 |
fi
|
|
|
129 |
|
|
|
130 |
if [ -n "${MTU}" ]; then
|
|
|
131 |
ip link set dev ${DEVICE} mtu ${MTU}
|
|
|
132 |
fi
|
|
|
133 |
|
|
|
134 |
# slave device?
|
|
|
135 |
if [ "${SLAVE}" = yes -a "${ISALIAS}" = no -a "${MASTER}" != "" ]; then
|
|
|
136 |
install_bonding_driver ${MASTER}
|
|
|
137 |
grep -wq "${DEVICE}" /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null || {
|
|
|
138 |
/sbin/ip link set dev ${DEVICE} down
|
|
|
139 |
echo "+${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
|
|
|
140 |
}
|
|
|
141 |
ethtool_set
|
|
|
142 |
|
|
|
143 |
exit 0
|
|
|
144 |
fi
|
|
|
145 |
|
|
|
146 |
# Bonding initialization. For DHCP, we need to enslave the devices early,
|
|
|
147 |
# so it can actually get an IP.
|
|
|
148 |
if [ "$ISALIAS" = no ] && is_bonding_device ${DEVICE} ; then
|
|
|
149 |
install_bonding_driver ${DEVICE}
|
|
|
150 |
/sbin/ip link set dev ${DEVICE} up
|
|
|
151 |
for device in $(LANG=C grep -l "^[[:space:]]*MASTER=\"\?${DEVICE}\"\?\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-*) ; do
|
|
|
152 |
is_ignored_file "$device" && continue
|
|
|
153 |
/sbin/ifup ${device##*/}
|
|
|
154 |
done
|
|
|
155 |
|
|
|
156 |
[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
|
|
|
157 |
|
|
|
158 |
# add the bits to setup the needed post enslavement parameters
|
|
|
159 |
for arg in $BONDING_OPTS ; do
|
|
|
160 |
key=${arg%%=*};
|
|
|
161 |
value=${arg##*=};
|
|
|
162 |
if [ "${key}" = "primary" ]; then
|
|
|
163 |
echo $value > /sys/class/net/${DEVICE}/bonding/$key
|
|
|
164 |
fi
|
|
|
165 |
done
|
|
|
166 |
fi
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
if [ -n "${DYNCONFIG}" -a -x /sbin/dhclient ]; then
|
|
|
170 |
# Remove any temporary references which were previously added to dhclient config
|
|
|
171 |
if [ -w /etc/dhclient-${DEVICE}.conf ] ; then
|
|
|
172 |
LC_ALL=C grep -v "# temporary RHL ifup addition" /etc/dhclient-${DEVICE}.conf > /etc/dhclient-${DEVICE}.conf.ifupnew 2> /dev/null
|
|
|
173 |
cat /etc/dhclient-${DEVICE}.conf.ifupnew > /etc/dhclient-${DEVICE}.conf
|
|
|
174 |
rm -f /etc/dhclient-${DEVICE}.conf.ifupnew
|
|
|
175 |
fi
|
|
|
176 |
if [[ "${PERSISTENT_DHCLIENT}" = [yY1]* ]]; then
|
|
|
177 |
ONESHOT="";
|
|
|
178 |
else
|
|
|
179 |
ONESHOT="-1";
|
|
|
180 |
fi;
|
|
|
181 |
if [ -n "${DHCP_HOSTNAME}" ]; then
|
|
|
182 |
# Send a host-name to the DHCP server (requ. by some dhcp servers).
|
|
|
183 |
if [ -w /etc/dhclient-${DEVICE}.conf ] ; then
|
|
|
184 |
if ! LC_ALL=C grep "send *host-name *\"${DHCP_HOSTNAME}\"" /etc/dhclient-${DEVICE}.conf > /dev/null 2>&1 ; then
|
|
|
185 |
echo "send host-name \"${DHCP_HOSTNAME}\"; # temporary RHL ifup addition" >> /etc/dhclient-${DEVICE}.conf
|
|
|
186 |
fi
|
|
|
187 |
elif ! [ -e /etc/dhclient-${DEVICE}.conf ] ; then
|
|
|
188 |
echo "send host-name \"${DHCP_HOSTNAME}\"; # temporary RHL ifup addition" >> /etc/dhclient-${DEVICE}.conf
|
|
|
189 |
fi
|
|
|
190 |
fi
|
|
|
191 |
# allow users to use generic '/etc/dhclient.conf' (as documented in manpage!)
|
|
|
192 |
# if per-device file doesn't exist or is empty
|
|
|
193 |
if [ -s /etc/dhclient-${DEVICE}.conf ]; then
|
|
|
194 |
DHCLIENTCONF="-cf /etc/dhclient-${DEVICE}.conf";
|
|
|
195 |
else
|
|
|
196 |
DHCLIENTCONF='';
|
|
|
197 |
fi;
|
|
|
198 |
# copy any lease obtained by the initrd
|
|
|
199 |
if [ -f /dev/.dhclient-${DEVICE}.leases ] ; then
|
|
|
200 |
mv -f /dev/.dhclient-${DEVICE}.leases /var/lib/dhclient/dhclient-${DEVICE}.leases
|
|
|
201 |
[ -x /sbin/restorecon ] && restorecon /var/lib/dhclient/dhclient-${DEVICE}.leases > /dev/null 2>&1
|
|
|
202 |
fi
|
|
|
203 |
DHCLIENTARGS="${DHCLIENTARGS} ${ONESHOT} -q ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient-${DEVICE}.leases -pf /var/run/dhclient-${DEVICE}.pid"
|
|
|
204 |
echo
|
|
|
205 |
echo -n $"Determining IP information for ${DEVICE}..."
|
|
|
206 |
if check_link_down ${DEVICE}; then
|
|
|
207 |
echo $" failed; no link present. Check cable?"
|
|
|
208 |
ip link set dev ${DEVICE} down >/dev/null 2>&1
|
|
|
209 |
exit 1
|
|
|
210 |
fi
|
|
|
211 |
|
|
|
212 |
ethtool_set
|
|
|
213 |
|
|
|
214 |
if /sbin/dhclient ${DHCLIENTARGS} ${DEVICE} ; then
|
|
|
215 |
echo $" done."
|
|
|
216 |
dhcpipv4="good"
|
|
|
217 |
else
|
|
|
218 |
echo $" failed."
|
|
|
219 |
if [[ "${IPV4_FAILURE_FATAL}" = [Yy1]* ]] ; then
|
|
|
220 |
exit 1
|
|
|
221 |
fi
|
|
|
222 |
if [[ "$IPV6INIT" != [yY1]* && "$DHCPV6C" != [yY1]* ]] ; then
|
|
|
223 |
exit 1
|
|
|
224 |
fi
|
|
|
225 |
net_log "Unable to obtain IPv4 DHCP address ${DEVICE}." warning
|
|
|
226 |
fi
|
|
|
227 |
# end dynamic device configuration
|
|
|
228 |
else
|
|
|
229 |
if [ -z "${IPADDR}" -a -z "${IPADDR0}" -a -z "${IPADDR1}" -a -z "${IPADDR2}" ]; then
|
|
|
230 |
# enable device without IP, useful for e.g. PPPoE
|
|
|
231 |
ip link set dev ${REALDEVICE} up
|
|
|
232 |
ethtool_set
|
|
|
233 |
[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
|
|
|
234 |
else
|
|
|
235 |
|
|
|
236 |
expand_config
|
|
|
237 |
|
|
|
238 |
[ -n "${ARP}" ] && \
|
|
|
239 |
ip link set dev ${REALDEVICE} $(toggle_value arp $ARP)
|
|
|
240 |
|
|
|
241 |
if ! ip link set dev ${REALDEVICE} up ; then
|
|
|
242 |
net_log $"Failed to bring up ${DEVICE}."
|
|
|
243 |
exit 1
|
|
|
244 |
fi
|
|
|
245 |
|
|
|
246 |
ethtool_set
|
|
|
247 |
|
|
|
248 |
[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
|
|
|
249 |
|
|
|
250 |
if [ "${DEVICE}" = "lo" ]; then
|
|
|
251 |
SCOPE="scope host"
|
|
|
252 |
else
|
|
|
253 |
SCOPE=${SCOPE:-}
|
|
|
254 |
fi
|
|
|
255 |
|
|
|
256 |
if [ -n "$SRCADDR" ]; then
|
|
|
257 |
SRC="src $SRCADDR"
|
|
|
258 |
else
|
|
|
259 |
SRC=
|
|
|
260 |
fi
|
|
|
261 |
|
|
|
262 |
# set IP address(es)
|
|
|
263 |
for idx in {0..256} ; do
|
|
|
264 |
if [ -z "${ipaddr[$idx]}" ]; then
|
|
|
265 |
break
|
|
|
266 |
fi
|
|
|
267 |
|
|
|
268 |
if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; then
|
|
|
269 |
[ "${REALDEVICE}" != "lo" ] && [ "${arpcheck[$idx]}" != "no" ] && \
|
|
|
270 |
/sbin/arping -q -c 2 -w 3 -D -I ${REALDEVICE} ${ipaddr[$idx]}
|
|
|
271 |
if [ $? = 1 ]; then
|
|
|
272 |
net_log $"Error, some other host already uses address ${ipaddr[$idx]}."
|
|
|
273 |
exit 1
|
|
|
274 |
fi
|
|
|
275 |
|
|
|
276 |
if ! ip addr add ${ipaddr[$idx]}/${prefix[$idx]} \
|
|
|
277 |
brd ${broadcast[$idx]:-+} dev ${REALDEVICE} ${SCOPE} label ${DEVICE}; then
|
|
|
278 |
net_log $"Error adding address ${ipaddr[$idx]} for ${DEVICE}."
|
|
|
279 |
fi
|
|
|
280 |
fi
|
|
|
281 |
|
|
|
282 |
if [ -n "$SRCADDR" ]; then
|
|
|
283 |
sysctl -w "net.ipv4.conf.${REALDEVICE}.arp_filter=1" >/dev/null 2>&1
|
|
|
284 |
fi
|
|
|
285 |
|
|
|
286 |
# update ARP cache of neighboring computers
|
|
|
287 |
if [ "${REALDEVICE}" != "lo" ]; then
|
|
|
288 |
/sbin/arping -q -A -c 1 -I ${REALDEVICE} ${ipaddr[$idx]}
|
|
|
289 |
( sleep 2;
|
|
|
290 |
/sbin/arping -q -U -c 1 -I ${REALDEVICE} ${ipaddr[$idx]} ) > /dev/null 2>&1 < /dev/null &
|
|
|
291 |
fi
|
|
|
292 |
done
|
|
|
293 |
|
|
|
294 |
# Set a default route.
|
|
|
295 |
if [ "${DEFROUTE}" != "no" ] && [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then
|
|
|
296 |
# set up default gateway. replace if one already exists
|
|
|
297 |
if [ -n "${GATEWAY}" ] && [ "$(ipcalc --network ${GATEWAY} ${netmask[0]} 2>/dev/null)" = "NETWORK=${NETWORK}" ]; then
|
|
|
298 |
ip route replace default ${METRIC:+metric $METRIC} \
|
|
|
299 |
via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} \
|
|
|
300 |
${GATEWAYDEV:+dev $GATEWAYDEV} ||
|
|
|
301 |
net_log $"Error adding default gateway ${GATEWAY} for ${DEVICE}."
|
|
|
302 |
elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; then
|
|
|
303 |
ip route replace default ${METRIC:+metric $METRIC} \
|
|
|
304 |
${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE} ||
|
|
|
305 |
net_log $"Erorr adding default gateway for ${REALDEVICE}."
|
|
|
306 |
fi
|
|
|
307 |
fi
|
|
|
308 |
fi
|
|
|
309 |
fi
|
|
|
310 |
|
|
|
311 |
# Add Zeroconf route.
|
|
|
312 |
if [ -z "${NOZEROCONF}" -a "${ISALIAS}" = "no" -a "${REALDEVICE}" != "lo" ]; then
|
|
|
313 |
ip route add 169.254.0.0/16 dev ${REALDEVICE} metric $((1000 + $(cat /sys/class/net/${REALDEVICE}/ifindex))) scope link
|
|
|
314 |
fi
|
|
|
315 |
|
|
|
316 |
# IPv6 initialisation?
|
|
|
317 |
if [ "${NETWORKING_IPV6}" = "yes" ]; then
|
|
|
318 |
/etc/sysconfig/network-scripts/ifup-ipv6 ${CONFIG}
|
|
|
319 |
if [[ "${DHCPV6C}" = [Yy1]* ]] && [ -x /sbin/dhcp6c ]; then
|
|
|
320 |
/sbin/dhcp6c ${DEVICE};
|
|
|
321 |
dhcp6_pid=(`/bin/ps -eo 'pid,args' | /bin/grep "dhcp6c ${DEVICE}" | egrep -v grep`);
|
|
|
322 |
echo ${dhcp6_pid[0]} > /var/run/dhcp6c_${DEVICE}.pid
|
|
|
323 |
fi;
|
|
|
324 |
fi
|
|
|
325 |
|
|
|
326 |
exec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2}
|
|
|
327 |
|