4 |
- |
1 |
#!/bin/bash
|
|
|
2 |
# Network Interface Configuration System
|
|
|
3 |
# Copyright (c) 1996-2009 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 |
source_config
|
|
|
28 |
|
|
|
29 |
. /etc/sysconfig/network
|
|
|
30 |
|
|
|
31 |
# Check to make sure the device is actually up
|
|
|
32 |
check_device_down ${DEVICE} && [ "$BOOTPROTO" != "dhcp" -a "$BOOTPROTO" != "bootp" ] && [ -n "$VLAN" -a "$VLAN" != "yes" ] && exit 0
|
|
|
33 |
|
|
|
34 |
if [ "${SLAVE}" != "yes" -o -z "${MASTER}" ]; then
|
|
|
35 |
if [ -n "${HWADDR}" -a -z "${MACADDR}" ]; then
|
|
|
36 |
FOUNDMACADDR=$(get_hwaddr ${REALDEVICE})
|
|
|
37 |
if [ -n "${FOUNDMACADDR}" -a "${FOUNDMACADDR}" != "${HWADDR}" ]; then
|
|
|
38 |
NEWCONFIG=$(get_config_by_hwaddr ${FOUNDMACADDR})
|
|
|
39 |
if [ -n "${NEWCONFIG}" ]; then
|
|
|
40 |
eval $(LANG=C fgrep "DEVICE=" $NEWCONFIG)
|
|
|
41 |
else
|
|
|
42 |
net_log $"Device ${DEVICE} has MAC address ${FOUNDMACADDR}, instead of configured address ${HWADDR}. Ignoring."
|
|
|
43 |
exit 1
|
|
|
44 |
fi
|
|
|
45 |
if [ -n "${NEWCONFIG}" -a "${NEWCONFIG##*/}" != "${CONFIG##*/}" -a "${DEVICE}" = "${REALDEVICE}" ]; then
|
|
|
46 |
exec /sbin/ifdown ${NEWCONFIG}
|
|
|
47 |
else
|
|
|
48 |
net_log $"Device ${DEVICE} has MAC address ${FOUNDMACADDR}, instead of configured address ${HWADDR}. Ignoring."
|
|
|
49 |
exit 1
|
|
|
50 |
fi
|
|
|
51 |
fi
|
|
|
52 |
fi
|
|
|
53 |
fi
|
|
|
54 |
|
|
|
55 |
if is_bonding_device ${DEVICE} ; then
|
58 |
- |
56 |
for device in $(LANG=C grep -l "^[[:space:]]*MASTER=['\"]\?${DEVICE}['\"]\?\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-*) ; do
|
4 |
- |
57 |
is_ignored_file "$device" && continue
|
|
|
58 |
/sbin/ifdown ${device##*/}
|
|
|
59 |
done
|
|
|
60 |
for arg in $BONDING_OPTS ; do
|
|
|
61 |
key=${arg%%=*};
|
|
|
62 |
[[ "${key}" != "arp_ip_target" ]] && continue
|
|
|
63 |
value=${arg##*=};
|
|
|
64 |
if [ "${value:0:1}" != "" ]; then
|
|
|
65 |
OLDIFS=$IFS;
|
|
|
66 |
IFS=',';
|
|
|
67 |
for arp_ip in $value; do
|
|
|
68 |
if grep -q $arp_ip /sys/class/net/${DEVICE}/bonding/arp_ip_target; then
|
|
|
69 |
echo "-$arp_ip" > /sys/class/net/${DEVICE}/bonding/arp_ip_target
|
|
|
70 |
fi
|
|
|
71 |
done
|
|
|
72 |
IFS=$OLDIFS;
|
|
|
73 |
else
|
|
|
74 |
value=${value#+};
|
|
|
75 |
if grep -q $value /sys/class/net/${DEVICE}/bonding/arp_ip_target; then
|
|
|
76 |
echo "-$value" > /sys/class/net/${DEVICE}/bonding/arp_ip_target
|
|
|
77 |
fi
|
|
|
78 |
fi
|
|
|
79 |
done
|
|
|
80 |
fi
|
|
|
81 |
|
|
|
82 |
/etc/sysconfig/network-scripts/ifdown-ipv6 ${CONFIG}
|
|
|
83 |
|
|
|
84 |
retcode=0
|
|
|
85 |
[ -n "$(pidof -x dhclient)" ] && {
|
|
|
86 |
for VER in "" 6 ; do
|
|
|
87 |
if [ -f "/var/run/dhclient$VER-${DEVICE}.pid" ]; then
|
|
|
88 |
dhcpid=$(cat /var/run/dhclient$VER-${DEVICE}.pid)
|
|
|
89 |
if [[ "$DHCPRELEASE" = [yY1]* ]]; then
|
|
|
90 |
/sbin/dhclient -r -lf /var/lib/dhclient/dhclient$VER-${DEVICE}.leases -pf /var/run/dhclient$VER-${DEVICE}.pid ${DEVICE} >/dev/null 2>&1
|
|
|
91 |
retcode=$?
|
|
|
92 |
else
|
|
|
93 |
kill $dhcpid >/dev/null 2>&1
|
|
|
94 |
retcode=$?
|
|
|
95 |
reason=STOP$VER interface=${DEVICE} /sbin/dhclient-script
|
|
|
96 |
fi
|
|
|
97 |
if [ -f "/var/run/dhclient$VER-${DEVICE}.pid" ]; then
|
|
|
98 |
rm -f /var/run/dhclient$VER-${DEVICE}.pid
|
|
|
99 |
kill $dhcpid >/dev/null 2>&1
|
|
|
100 |
fi
|
|
|
101 |
fi
|
|
|
102 |
done
|
|
|
103 |
}
|
|
|
104 |
# we can't just delete the configured address because that address
|
|
|
105 |
# may have been changed in the config file since the device was
|
|
|
106 |
# brought up. Flush all addresses associated with this
|
|
|
107 |
# instance instead.
|
|
|
108 |
if [ -d "/sys/class/net/${REALDEVICE}" ]; then
|
42 |
- |
109 |
LABEL=
|
45 |
- |
110 |
if [ "${REALDEVICE}" != "${DEVICE}" ]; then
|
42 |
- |
111 |
LABEL="label ${DEVICE}"
|
|
|
112 |
fi
|
34 |
- |
113 |
if [ "${REALDEVICE}" = "lo" ]; then
|
42 |
- |
114 |
ip addr flush dev ${REALDEVICE} ${LABEL} scope host 2>/dev/null
|
34 |
- |
115 |
else
|
42 |
- |
116 |
ip addr flush dev ${REALDEVICE} ${LABEL} scope global 2>/dev/null
|
|
|
117 |
ip -4 addr flush dev ${REALDEVICE} ${LABEL} scope host 2>/dev/null
|
34 |
- |
118 |
fi
|
4 |
- |
119 |
|
|
|
120 |
if [ "${SLAVE}" = "yes" -a -n "${MASTER}" ]; then
|
|
|
121 |
echo "-${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
|
|
|
122 |
fi
|
|
|
123 |
|
|
|
124 |
if [ "${REALDEVICE}" = "${DEVICE}" ]; then
|
|
|
125 |
ip link set dev ${DEVICE} down 2>/dev/null
|
|
|
126 |
fi
|
|
|
127 |
fi
|
|
|
128 |
[ "$retcode" = "0" ] && retcode=$?
|
|
|
129 |
|
|
|
130 |
if [ -n "${BRIDGE}" -a -x /usr/sbin/brctl ]; then
|
|
|
131 |
/sbin/ip link set dev ${DEVICE} down
|
|
|
132 |
/usr/sbin/brctl delif ${BRIDGE} ${DEVICE}
|
|
|
133 |
# Upon removing a device from a bridge,
|
|
|
134 |
# it's necessary to make radvd reload its config
|
|
|
135 |
[ -r /var/run/radvd/radvd.pid ] && kill -HUP $(cat /var/run/radvd/radvd.pid)
|
|
|
136 |
if [ -d /sys/class/net/${BRIDGE}/brif ] && [ $(ls -1 /sys/class/net/${BRIDGE}/brif | wc -l) -eq 0 ]; then
|
|
|
137 |
/usr/sbin/brctl delbr ${BRIDGE}
|
|
|
138 |
fi
|
|
|
139 |
fi
|
|
|
140 |
|
|
|
141 |
if [ "${TYPE}" = "Tap" ]; then
|
|
|
142 |
tunctl -d "${DEVICE}" >/dev/null
|
|
|
143 |
fi
|
|
|
144 |
|
9 |
- |
145 |
# wait up to 5 seconds for device to actually come down if it is not an alias
|
|
|
146 |
if [ ${DEVICE} == ${DEVICE%:*} ]; then
|
|
|
147 |
waited=0
|
|
|
148 |
while ! check_device_down ${DEVICE} && [ "$waited" -lt 50 ] ; do
|
|
|
149 |
usleep 10000
|
|
|
150 |
waited=$(($waited+1))
|
|
|
151 |
done
|
|
|
152 |
fi
|
4 |
- |
153 |
|
|
|
154 |
# don't leave an outdated key sitting around
|
|
|
155 |
if [ -n "${WIRELESS_ENC_KEY}" -a -x /sbin/iwconfig ]; then
|
|
|
156 |
/sbin/iwconfig ${DEVICE} enc 0 >/dev/null 2>&1
|
|
|
157 |
fi
|
|
|
158 |
|
|
|
159 |
if [ "$retcode" = 0 ] ; then
|
|
|
160 |
/etc/sysconfig/network-scripts/ifdown-post $CONFIG
|
|
|
161 |
# do NOT use $? because ifdown should return whether or not
|
|
|
162 |
# the interface went down.
|
|
|
163 |
fi
|
|
|
164 |
|
|
|
165 |
if [ -n "$VLAN" ]; then
|
|
|
166 |
# 802.1q VLAN
|
|
|
167 |
if [ -f /proc/net/vlan/${DEVICE} ]; then
|
|
|
168 |
ip link delete ${DEVICE} type vlan
|
|
|
169 |
fi
|
|
|
170 |
fi
|
|
|
171 |
|
|
|
172 |
exit $retcode
|