4 |
- |
1 |
#!/bin/bash
|
|
|
2 |
# Network Interface Configuration System
|
|
|
3 |
# Copyright (c) 1996-2010 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 |
# Old BOOTP variable
|
|
|
32 |
if [ "${BOOTP}" = "yes" ]; then
|
|
|
33 |
BOOTPROTO=bootp
|
|
|
34 |
fi
|
|
|
35 |
|
|
|
36 |
if [ "${BOOTPROTO}" = "bootp" -o "${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 |
# bail out, if the MAC does not fit
|
|
|
45 |
if [ -n "${HWADDR}" ]; then
|
|
|
46 |
FOUNDMACADDR=$(get_hwaddr ${REALDEVICE})
|
|
|
47 |
if [ "${FOUNDMACADDR}" != "${HWADDR}" -a "${FOUNDMACADDR}" != "${MACADDR}" ]; then
|
|
|
48 |
net_log $"Device ${DEVICE} has different MAC address than expected, ignoring."
|
|
|
49 |
exit 1
|
|
|
50 |
fi
|
|
|
51 |
fi
|
|
|
52 |
|
|
|
53 |
# If the device is a bridge, create it with brctl, if available.
|
|
|
54 |
if [ "${TYPE}" = "Bridge" ]; then
|
|
|
55 |
if [ ! -x /usr/sbin/brctl ]; then
|
|
|
56 |
net_log $"Bridge support not available: brctl not found"
|
|
|
57 |
exit 1
|
|
|
58 |
fi
|
|
|
59 |
if [ ! -d /sys/class/net/${DEVICE}/bridge ]; then
|
|
|
60 |
/usr/sbin/brctl addbr ${DEVICE} || exit 1
|
|
|
61 |
fi
|
|
|
62 |
[ -n "${DELAY}" ] && /usr/sbin/brctl setfd ${DEVICE} ${DELAY}
|
|
|
63 |
[ -n "${STP}" ] && /usr/sbin/brctl stp ${DEVICE} ${STP}
|
9 |
- |
64 |
[ -n "${PRIO}" ] && /usr/sbin/brctl setbridgeprio ${DEVICE} ${PRIO}
|
|
|
65 |
[ -n "${AGEING}" ] && /usr/sbin/brctl setageing ${DEVICE} ${AGEING}
|
4 |
- |
66 |
# add the bits to setup driver parameters here
|
|
|
67 |
for arg in $BRIDGING_OPTS ; do
|
|
|
68 |
key=${arg%%=*};
|
|
|
69 |
value=${arg##*=};
|
58 |
- |
70 |
if [ "${key}" != "multicast_router" -a "${key}" != "hash_max" -a "${key}" != "multicast_snooping" ]; then
|
|
|
71 |
echo $value > /sys/class/net/${DEVICE}/bridge/$key
|
|
|
72 |
fi
|
4 |
- |
73 |
done
|
|
|
74 |
fi
|
|
|
75 |
|
|
|
76 |
# If the device is a tap device, create it with tunctl, if available.
|
|
|
77 |
if [ "${TYPE}" = "Tap" ]; then
|
|
|
78 |
if [ ! -x /usr/sbin/tunctl ]; then
|
|
|
79 |
net_log $"Tap support not available: tunctl not found"
|
|
|
80 |
exit 1
|
|
|
81 |
fi
|
|
|
82 |
[ -n "${OWNER}" ] && OWNER="-u ${OWNER}"
|
|
|
83 |
/usr/sbin/tunctl ${OWNER} -t ${DEVICE} > /dev/null
|
|
|
84 |
fi
|
|
|
85 |
|
|
|
86 |
# now check the real state
|
|
|
87 |
is_available ${REALDEVICE} || {
|
|
|
88 |
if [ -n "$alias" ]; then
|
|
|
89 |
net_log $"$alias device ${DEVICE} does not seem to be present, delaying initialization."
|
|
|
90 |
else
|
|
|
91 |
net_log $"Device ${DEVICE} does not seem to be present, delaying initialization."
|
|
|
92 |
fi
|
|
|
93 |
exit 1
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
# this isn't the same as the MAC in the configuration filename. It is
|
|
|
98 |
# available as a configuration option in the config file, forcing the kernel
|
|
|
99 |
# to think an ethernet card has a different MAC address than it really has.
|
|
|
100 |
if [ -n "${MACADDR}" ]; then
|
|
|
101 |
ip link set dev ${DEVICE} address ${MACADDR}
|
|
|
102 |
fi
|
|
|
103 |
if [ -n "${MTU}" ]; then
|
|
|
104 |
ip link set dev ${DEVICE} mtu ${MTU}
|
|
|
105 |
fi
|
|
|
106 |
|
|
|
107 |
# is the device wireless? If so, configure wireless device specifics
|
|
|
108 |
is_wireless_device ${DEVICE} && . ./ifup-wireless
|
|
|
109 |
|
|
|
110 |
# slave device?
|
|
|
111 |
if [ "${SLAVE}" = yes -a "${ISALIAS}" = no -a "${MASTER}" != "" ]; then
|
|
|
112 |
install_bonding_driver ${MASTER}
|
|
|
113 |
grep -wq "${DEVICE}" /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null || {
|
|
|
114 |
/sbin/ip link set dev ${DEVICE} down
|
|
|
115 |
echo "+${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
|
|
|
116 |
}
|
|
|
117 |
ethtool_set
|
|
|
118 |
|
|
|
119 |
exit 0
|
|
|
120 |
fi
|
|
|
121 |
|
|
|
122 |
# Bonding initialization. For DHCP, we need to enslave the devices early,
|
|
|
123 |
# so it can actually get an IP.
|
|
|
124 |
if [ "$ISALIAS" = no ] && is_bonding_device ${DEVICE} ; then
|
|
|
125 |
install_bonding_driver ${DEVICE}
|
|
|
126 |
/sbin/ip link set dev ${DEVICE} up
|
58 |
- |
127 |
for device in $(LANG=C grep -l "^[[:space:]]*MASTER=['\"]\?${DEVICE}['\"]\?\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-*) ; do
|
4 |
- |
128 |
is_ignored_file "$device" && continue
|
58 |
- |
129 |
/sbin/ifup ${device##*/} || net_log "Unable to start slave device ${device##*/} for master ${DEVICE}." warning
|
4 |
- |
130 |
done
|
|
|
131 |
|
|
|
132 |
[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
|
|
|
133 |
|
|
|
134 |
# add the bits to setup the needed post enslavement parameters
|
|
|
135 |
for arg in $BONDING_OPTS ; do
|
|
|
136 |
key=${arg%%=*};
|
|
|
137 |
value=${arg##*=};
|
|
|
138 |
if [ "${key}" = "primary" ]; then
|
|
|
139 |
echo $value > /sys/class/net/${DEVICE}/bonding/$key
|
|
|
140 |
fi
|
|
|
141 |
done
|
|
|
142 |
fi
|
|
|
143 |
|
|
|
144 |
# If the device is part of a bridge, add the device to the bridge
|
|
|
145 |
if [ -n "${BRIDGE}" -a -x /usr/sbin/brctl ]; then
|
|
|
146 |
if [ ! -d /sys/class/net/${BRIDGE}/bridge ]; then
|
|
|
147 |
/usr/sbin/brctl addbr ${BRIDGE} 2>/dev/null
|
|
|
148 |
fi
|
|
|
149 |
/sbin/ip addr flush dev ${DEVICE} 2>/dev/null
|
|
|
150 |
/sbin/ip link set dev ${DEVICE} up
|
|
|
151 |
ethtool_set
|
|
|
152 |
[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
|
|
|
153 |
/usr/sbin/brctl addif ${BRIDGE} ${DEVICE}
|
|
|
154 |
# add the bits to setup driver parameters here
|
|
|
155 |
for arg in $BRIDGING_OPTS ; do
|
|
|
156 |
key=${arg%%=*};
|
|
|
157 |
value=${arg##*=};
|
|
|
158 |
echo $value > /sys/class/net/${DEVICE}/brport/$key
|
|
|
159 |
done
|
|
|
160 |
# Upon adding a device to a bridge,
|
|
|
161 |
# it's necessary to make radvd reload its config
|
|
|
162 |
[ -r /var/run/radvd/radvd.pid ] && kill -HUP $(cat /var/run/radvd/radvd.pid)
|
|
|
163 |
exit 0
|
|
|
164 |
fi
|
|
|
165 |
|
|
|
166 |
if [ -n "${DYNCONFIG}" -a -x /sbin/dhclient ]; then
|
|
|
167 |
if [[ "${PERSISTENT_DHCLIENT}" = [yY1]* ]]; then
|
|
|
168 |
ONESHOT="";
|
|
|
169 |
else
|
|
|
170 |
ONESHOT="-1";
|
|
|
171 |
fi;
|
|
|
172 |
generate_config_file_name
|
|
|
173 |
# copy any lease obtained by the initrd
|
|
|
174 |
for file in /dev/.dhclient-${DEVICE}.leases /dev/.initramfs/net.${DEVICE}.lease ; do
|
|
|
175 |
if [ -f "${file}" ]; then
|
|
|
176 |
mv -f $file /var/lib/dhclient/dhclient-${DEVICE}.leases
|
|
|
177 |
[ -x /sbin/restorecon ] && restorecon /var/lib/dhclient/dhclient-${DEVICE}.leases > /dev/null 2>&1
|
|
|
178 |
fi
|
|
|
179 |
done
|
97 |
- |
180 |
|
|
|
181 |
if is_hostname_set; then
|
|
|
182 |
# We already have the hostname ->> send it to DHCP:
|
|
|
183 |
DHCLIENTARGS="${DHCLIENTARGS} -H ${DHCP_HOSTNAME:-${HOSTNAME%%.*}} ${ONESHOT} -q ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient-${DEVICE}.leases -pf /var/run/dhclient-${DEVICE}.pid"
|
|
|
184 |
else
|
|
|
185 |
# We need to acquire the hostname:
|
|
|
186 |
DHCLIENTARGS="${DHCLIENTARGS} ${DHCP_HOSTNAME:+-H $DHCP_HOSTNAME} ${ONESHOT} -q ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient-${DEVICE}.leases -pf /var/run/dhclient-${DEVICE}.pid"
|
|
|
187 |
fi
|
|
|
188 |
|
4 |
- |
189 |
echo
|
|
|
190 |
echo -n $"Determining IP information for ${DEVICE}..."
|
|
|
191 |
if [[ "${PERSISTENT_DHCLIENT}" != [yY1]* ]] && check_link_down ${DEVICE}; then
|
|
|
192 |
echo $" failed; no link present. Check cable?"
|
|
|
193 |
exit 1
|
|
|
194 |
fi
|
|
|
195 |
|
|
|
196 |
ethtool_set
|
|
|
197 |
|
|
|
198 |
if /sbin/dhclient ${DHCLIENTARGS} ${DEVICE} ; then
|
|
|
199 |
echo $" done."
|
|
|
200 |
dhcpipv4="good"
|
|
|
201 |
else
|
|
|
202 |
echo $" failed."
|
|
|
203 |
if [[ "${IPV4_FAILURE_FATAL}" = [Yy1]* ]] ; then
|
|
|
204 |
exit 1
|
|
|
205 |
fi
|
|
|
206 |
if [[ "$IPV6INIT" != [yY1]* && "$DHCPV6C" != [yY1]* ]] ; then
|
|
|
207 |
exit 1
|
|
|
208 |
fi
|
|
|
209 |
net_log "Unable to obtain IPv4 DHCP address ${DEVICE}." warning
|
|
|
210 |
fi
|
|
|
211 |
# end dynamic device configuration
|
|
|
212 |
else
|
|
|
213 |
if [ -z "${IPADDR}" -a -z "${IPADDR0}" -a -z "${IPADDR1}" -a -z "${IPADDR2}" ]; then
|
|
|
214 |
# enable device without IP, useful for e.g. PPPoE
|
|
|
215 |
ip link set dev ${REALDEVICE} up
|
|
|
216 |
ethtool_set
|
|
|
217 |
[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
|
|
|
218 |
else
|
|
|
219 |
|
|
|
220 |
expand_config
|
|
|
221 |
|
|
|
222 |
[ -n "${ARP}" ] && \
|
|
|
223 |
ip link set dev ${REALDEVICE} $(toggle_value arp $ARP)
|
|
|
224 |
|
|
|
225 |
if ! ip link set dev ${REALDEVICE} up ; then
|
|
|
226 |
net_log $"Failed to bring up ${DEVICE}."
|
|
|
227 |
exit 1
|
|
|
228 |
fi
|
|
|
229 |
|
|
|
230 |
ethtool_set
|
|
|
231 |
|
|
|
232 |
[ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY}
|
|
|
233 |
|
|
|
234 |
if [ "${DEVICE}" = "lo" ]; then
|
|
|
235 |
SCOPE="scope host"
|
|
|
236 |
else
|
|
|
237 |
SCOPE=${SCOPE:-}
|
|
|
238 |
fi
|
|
|
239 |
|
|
|
240 |
if [ -n "$SRCADDR" ]; then
|
|
|
241 |
SRC="src $SRCADDR"
|
|
|
242 |
else
|
|
|
243 |
SRC=
|
|
|
244 |
fi
|
|
|
245 |
|
|
|
246 |
# set IP address(es)
|
|
|
247 |
for idx in {0..256} ; do
|
|
|
248 |
if [ -z "${ipaddr[$idx]}" ]; then
|
|
|
249 |
break
|
|
|
250 |
fi
|
|
|
251 |
|
|
|
252 |
if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; then
|
|
|
253 |
if [ "${REALDEVICE}" != "lo" ] && [ "${arpcheck[$idx]}" != "no" ] ; then
|
|
|
254 |
echo $"Determining if ip address ${ipaddr[$idx]} is already in use for device ${REALDEVICE}..."
|
58 |
- |
255 |
if ! ARPING=$(/sbin/arping -c 2 -w ${ARPING_WAIT:-3} -D -I ${REALDEVICE} ${ipaddr[$idx]}) ; then
|
|
|
256 |
ARPINGMAC=$(echo $ARPING | sed -ne 's/.*\[\(.*\)\].*/\1/p')
|
|
|
257 |
net_log $"Error, some other host ($ARPINGMAC) already uses address ${ipaddr[$idx]}."
|
4 |
- |
258 |
exit 1
|
|
|
259 |
fi
|
|
|
260 |
fi
|
|
|
261 |
|
|
|
262 |
if ! ip addr add ${ipaddr[$idx]}/${prefix[$idx]} \
|
|
|
263 |
brd ${broadcast[$idx]:-+} dev ${REALDEVICE} ${SCOPE} label ${DEVICE}; then
|
|
|
264 |
net_log $"Error adding address ${ipaddr[$idx]} for ${DEVICE}."
|
|
|
265 |
fi
|
|
|
266 |
fi
|
|
|
267 |
|
|
|
268 |
if [ -n "$SRCADDR" ]; then
|
|
|
269 |
sysctl -w "net.ipv4.conf.${SYSCTLDEVICE}.arp_filter=1" >/dev/null 2>&1
|
|
|
270 |
fi
|
|
|
271 |
|
|
|
272 |
# update ARP cache of neighboring computers
|
|
|
273 |
if [ "${REALDEVICE}" != "lo" ]; then
|
|
|
274 |
/sbin/arping -q -A -c 1 -I ${REALDEVICE} ${ipaddr[$idx]}
|
|
|
275 |
( sleep 2;
|
|
|
276 |
/sbin/arping -q -U -c 1 -I ${REALDEVICE} ${ipaddr[$idx]} ) > /dev/null 2>&1 < /dev/null &
|
|
|
277 |
fi
|
|
|
278 |
done
|
|
|
279 |
|
|
|
280 |
# Set a default route.
|
|
|
281 |
if [ "${DEFROUTE}" != "no" ] && [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then
|
|
|
282 |
# set up default gateway. replace if one already exists
|
|
|
283 |
if [ -n "${GATEWAY}" ] && [ "$(ipcalc --network ${GATEWAY} ${netmask[0]} 2>/dev/null)" = "NETWORK=${NETWORK}" ]; then
|
|
|
284 |
ip route replace default ${METRIC:+metric $METRIC} \
|
|
|
285 |
via ${GATEWAY} ${WINDOW:+window $WINDOW} ${SRC} \
|
|
|
286 |
${GATEWAYDEV:+dev $GATEWAYDEV} ||
|
|
|
287 |
net_log $"Error adding default gateway ${GATEWAY} for ${DEVICE}."
|
|
|
288 |
elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; then
|
|
|
289 |
ip route replace default ${METRIC:+metric $METRIC} \
|
|
|
290 |
${SRC} ${WINDOW:+window $WINDOW} dev ${REALDEVICE} ||
|
|
|
291 |
net_log $"Erorr adding default gateway for ${REALDEVICE}."
|
|
|
292 |
fi
|
|
|
293 |
fi
|
|
|
294 |
fi
|
|
|
295 |
fi
|
|
|
296 |
|
|
|
297 |
# Add Zeroconf route.
|
|
|
298 |
if [ -z "${NOZEROCONF}" -a "${ISALIAS}" = "no" -a "${REALDEVICE}" != "lo" ]; then
|
|
|
299 |
ip route add 169.254.0.0/16 dev ${REALDEVICE} metric $((1000 + $(cat /sys/class/net/${REALDEVICE}/ifindex))) scope link
|
|
|
300 |
fi
|
|
|
301 |
|
9 |
- |
302 |
if [ "${TYPE}" = "Bridge" ]; then
|
|
|
303 |
for arg in $BRIDGING_OPTS ; do
|
|
|
304 |
key=${arg%%=*};
|
|
|
305 |
value=${arg##*=};
|
11 |
- |
306 |
if [ "${key}" = "multicast_router" -o "${key}" = "hash_max" -o "${key}" = "multicast_snooping" ]; then
|
9 |
- |
307 |
echo $value > /sys/class/net/${DEVICE}/bridge/$key
|
|
|
308 |
fi
|
|
|
309 |
done
|
|
|
310 |
fi
|
|
|
311 |
|
4 |
- |
312 |
# IPv6 initialisation?
|
|
|
313 |
/etc/sysconfig/network-scripts/ifup-ipv6 ${CONFIG}
|
|
|
314 |
if [[ "${DHCPV6C}" = [Yy1]* ]] && [ -x /sbin/dhclient ]; then
|
|
|
315 |
generate_config_file_name 6
|
|
|
316 |
echo
|
|
|
317 |
echo -n $"Determining IPv6 information for ${DEVICE}..."
|
97 |
- |
318 |
|
|
|
319 |
if is_hostname_set; then
|
|
|
320 |
# We already have the hostname ->> send it to DHCP:
|
|
|
321 |
DHCLIENTARGS="-6 -1 ${DHCPV6C_OPTIONS} ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient6-${DEVICE}.leases -pf /var/run/dhclient6-${DEVICE}.pid -H ${DHCP_HOSTNAME:-${HOSTNAME%%.*}} ${DEVICE}"
|
|
|
322 |
else
|
|
|
323 |
# We need to acquire the hostname:
|
|
|
324 |
DHCLIENTARGS="-6 -1 ${DHCPV6C_OPTIONS} ${DHCLIENTCONF} -lf /var/lib/dhclient/dhclient6-${DEVICE}.leases -pf /var/run/dhclient6-${DEVICE}.pid ${DHCP_HOSTNAME:+-H $DHCP_HOSTNAME} ${DEVICE}"
|
|
|
325 |
fi
|
|
|
326 |
|
|
|
327 |
if /sbin/dhclient $DHCLIENTARGS; then
|
4 |
- |
328 |
echo $" done."
|
|
|
329 |
else
|
|
|
330 |
echo $" failed."
|
|
|
331 |
if [ "${dhcpipv4}" = "good" -o -n "${IPADDR}" ]; then
|
|
|
332 |
net_log "Unable to obtain IPv6 DHCP address ${DEVICE}." warning
|
|
|
333 |
else
|
|
|
334 |
exit 1
|
|
|
335 |
fi
|
|
|
336 |
fi
|
|
|
337 |
fi
|
|
|
338 |
|
|
|
339 |
exec /etc/sysconfig/network-scripts/ifup-post ${CONFIG} ${2}
|
|
|
340 |
|