Subversion Repositories configs

Rev

Rev 58 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
90 - 114
                TIMEOUT=""
115
                [ -x /usr/bin/timeout ] && TIMEOUT="/usr/bin/timeout --signal=SIGQUIT 4"
116
		$TIMEOUT ip addr flush dev ${REALDEVICE} ${LABEL} scope global 2>/dev/null
117
		$TIMEOUT ip addr flush dev ${REALDEVICE} ${LABEL} scope host 2>/dev/null
34 - 118
	else
42 - 119
		ip addr flush dev ${REALDEVICE} ${LABEL} scope global 2>/dev/null
120
		ip -4 addr flush dev ${REALDEVICE} ${LABEL} scope host 2>/dev/null
34 - 121
	fi
4 - 122
 
123
	if [ "${SLAVE}" = "yes" -a -n "${MASTER}" ]; then
124
		echo "-${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
125
	fi
126
 
127
	if [ "${REALDEVICE}" = "${DEVICE}" ]; then
128
  		ip link set dev ${DEVICE} down 2>/dev/null
129
	fi
130
fi
131
[ "$retcode" = "0" ] && retcode=$?
132
 
133
if [ -n "${BRIDGE}" -a -x /usr/sbin/brctl ]; then
134
      /sbin/ip link set dev ${DEVICE} down
135
      /usr/sbin/brctl delif ${BRIDGE} ${DEVICE}
136
      # Upon removing a device from a bridge,
137
      # it's necessary to make radvd reload its config
138
      [ -r /var/run/radvd/radvd.pid ] && kill -HUP $(cat /var/run/radvd/radvd.pid)
139
      if [ -d /sys/class/net/${BRIDGE}/brif ] && [ $(ls -1 /sys/class/net/${BRIDGE}/brif | wc -l) -eq 0 ]; then
140
	  /usr/sbin/brctl delbr ${BRIDGE}
141
      fi
142
fi
143
 
144
if [ "${TYPE}" = "Tap" ]; then
145
	tunctl -d "${DEVICE}" >/dev/null
146
fi
147
 
9 - 148
# wait up to 5 seconds for device to actually come down if it is not an alias
149
if [ ${DEVICE} == ${DEVICE%:*} ]; then
150
    waited=0
151
    while ! check_device_down ${DEVICE} && [ "$waited" -lt 50 ] ; do
152
        usleep 10000
153
        waited=$(($waited+1))
154
    done
155
fi
4 - 156
 
157
# don't leave an outdated key sitting around
158
if [ -n "${WIRELESS_ENC_KEY}" -a -x /sbin/iwconfig ]; then
159
    /sbin/iwconfig ${DEVICE} enc 0 >/dev/null 2>&1
160
fi
161
 
162
if [ "$retcode" = 0 ] ; then
163
    /etc/sysconfig/network-scripts/ifdown-post $CONFIG
164
    # do NOT use $? because ifdown should return whether or not
165
    # the interface went down.
166
fi
167
 
168
if [ -n "$VLAN" ]; then
169
    # 802.1q VLAN
170
    if [ -f /proc/net/vlan/${DEVICE} ]; then
171
	    ip link delete ${DEVICE} type vlan
172
    fi
173
fi
174
 
175
exit $retcode