Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
source_config
28
 
29
# Allow the user to override the detection of our physical device by passing
30
# it in.  No checking is done, if the user gives us a bogus dev, it's
31
# their problem.
32
[ -n "${PHYSDEV}" ] && REALDEVICE="$PHYSDEV"
33
 
34
. /etc/sysconfig/network
35
 
36
# Check to make sure the device is actually up
37
check_device_down ${DEVICE} && exit 0
38
 
39
# If we are a P_Key device, we need to munge a few things
40
if [ "${PKEY}" = yes ]; then
41
	[ -z "${PKEY_ID}" ] && {
42
	        net_log $"InfiniBand IPoIB device: PKEY=yes requires a PKEY_ID"
43
	        exit 1
44
	}
45
	[ -z "${PHYSDEV}" ] && {
46
	        net_log $"InfiniBand IPoIB device: PKEY=yes requires a PHYSDEV"
47
	        exit 1
48
	}
49
	# Normalize our PKEY_ID to have the high bit set
50
	NEW_PKEY_ID=`printf "0x%04x" $(( 0x8000 | ${PKEY_ID} ))`
51
	NEW_PKEY_NAME=`printf "%04x" ${NEW_PKEY_ID}`
52
	[ "${DEVICE}" != "${PHYSDEV}.${NEW_PKEY_NAME}" ] && {
53
                net_log $"Configured DEVICE name does not match what new device name would be.  This
54
is most likely because once the PKEY_ID was normalized, it no longer
55
resulted in the expected device naming, and so the DEVICE entry in the
56
config file needs to be updated to match. This can also be caused by
57
giving PKEY_ID as a hex number but without using the mandatory 0x prefix.
58
	Configured DEVICE=$DEVICE
59
        Configured PHYSDEV=$PHYSDEV
60
        Configured PKEY_ID=$PKEY_ID
61
        Calculated PKEY_ID=$NEW_PKEY_ID
62
        Calculated name=${PHYSDEV}.${NEW_PKEY_NAME}"
63
                exit 1
64
        }
65
        [ -d "/sys/class/net/${DEVICE}" ] || exit 0
66
        # When we get to downing the IP address, we need REALDEVICE to
67
        # point to our PKEY device
68
        REALDEVICE="${DEVICE}"
69
fi
70
 
71
 
72
if [ "${SLAVE}" != "yes" -o -z "${MASTER}" ]; then
73
if [ -n "${HWADDR}" -a -z "${MACADDR}" ]; then
74
    HWADDR=$(echo $HWADDR | tail -c 24)
75
    FOUNDMACADDR=$(get_hwaddr ${REALDEVICE} | tail -c 24)
76
    if [ -n "${FOUNDMACADDR}" -a "${FOUNDMACADDR}" != "${HWADDR}" ]; then
77
        NEWCONFIG=$(get_config_by_hwaddr ${FOUNDMACADDR})
78
	if [ -n "${NEWCONFIG}" ]; then
79
	   eval $(LANG=C grep -F "DEVICE=" $NEWCONFIG)
80
	else
81
	   net_log $"Device ${DEVICE} has MAC address ${FOUNDMACADDR}, instead of configured address ${HWADDR}. Ignoring."
82
	   exit 1
83
	fi
84
	if [ -n "${NEWCONFIG}" -a "${NEWCONFIG##*/}" != "${CONFIG##*/}" -a "${DEVICE}" = "${REALDEVICE}" ]; then
85
	   exec /sbin/ifdown ${NEWCONFIG}
86
	else
87
	   net_log $"Device ${DEVICE} has MAC address ${FOUNDMACADDR}, instead of configured address ${HWADDR}. Ignoring."
88
	   exit 1
89
	fi
90
    fi
91
fi
92
fi
93
 
94
if is_bonding_device ${DEVICE} ; then
95
    for device in $(LANG=C grep -l "^[[:space:]]*MASTER=\"\?${DEVICE}\"\?\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-*) ; do
96
	is_ignored_file "$device" && continue
97
	/sbin/ifdown ${device##*/}
98
    done
99
    for arg in $BONDING_OPTS ; do
100
	key=${arg%%=*};
101
	[[ "${key}" != "arp_ip_target" ]] && continue
102
	value=${arg##*=};
103
	if [ "${value:0:1}" != "" ]; then
104
            OLDIFS=$IFS;
105
            IFS=',';
106
            for arp_ip in $value; do
107
		if grep -q $arp_ip /sys/class/net/${DEVICE}/bonding/arp_ip_target; then
108
                    echo "-$arp_ip" > /sys/class/net/${DEVICE}/bonding/arp_ip_target
109
		fi
110
            done
111
            IFS=$OLDIFS;
112
	else
113
	    value=${value#+};
114
	    if grep -q $value /sys/class/net/${DEVICE}/bonding/arp_ip_target; then
115
                echo "-$value" > /sys/class/net/${DEVICE}/bonding/arp_ip_target
116
	    fi
117
	fi
118
    done
119
fi
120
 
121
/etc/sysconfig/network-scripts/ifdown-ipv6 ${CONFIG}
122
 
123
retcode=0
124
[ -n "$(pidof -x dhclient)" ] && {
125
   for VER in "" 6 ; do
126
	if [ -f "/var/run/dhclient$VER-${DEVICE}.pid" ]; then
127
		dhcpid=$(cat /var/run/dhclient$VER-${DEVICE}.pid)
128
		if [[ "$DHCPRELEASE" = [yY1]* ]];  then
129
			/sbin/dhclient -r -lf /var/lib/dhclient/dhclient$VER-${DEVICE}.leases -pf /var/run/dhclient-${DEVICE}.pid ${DEVICE} >/dev/null 2>&1
130
			retcode=$?
131
		else
132
			kill $dhcpid >/dev/null 2>&1
133
			retcode=$?
134
			reason=STOP$VER interface=${DEVICE} /sbin/dhclient-script
135
		fi
136
		if [ -f "/var/run/dhclient$VER-${DEVICE}.pid" ]; then
137
			rm -f /var/run/dhclient$VER-${DEVICE}.pid
138
			kill $dhcpid >/dev/null 2>&1
139
		fi
140
	fi
141
    done
142
}
143
# we can't just delete the configured address because that address
144
# may have been changed in the config file since the device was
145
# brought up.  Flush all addresses associated with this
146
# instance instead.
147
if [ -d "/sys/class/net/${REALDEVICE}" ]; then
148
	if [ "${REALDEVICE}" = "${DEVICE}" ]; then
149
		ip addr flush dev ${REALDEVICE} scope global 2>/dev/null
150
	else
151
		ip addr flush dev ${REALDEVICE} label ${DEVICE} scope global 2>/dev/null
152
	fi
153
 
154
	if [ "${SLAVE}" = "yes" -a -n "${MASTER}" ]; then
155
		echo "-${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
156
	fi
157
 
158
	if [ "${REALDEVICE}" = "${DEVICE}" ]; then
159
  		ip link set dev ${DEVICE} down 2>/dev/null
160
	fi
161
fi
162
[ "$retcode" = "0" ] && retcode=$?
163
 
164
# wait up to 5 seconds for device to actually come down...
165
waited=0
166
while ! check_device_down ${DEVICE} && [ "$waited" -lt 50 ] ; do
167
    usleep 10000
168
    waited=$(($waited+1))
169
done
170
 
171
if [ "$retcode" = 0 ] ; then
172
    /etc/sysconfig/network-scripts/ifdown-post $CONFIG
173
    # do NOT use $? because ifdown should return whether or not
174
    # the interface went down.
175
fi
176
 
177
if [ -n "$PKEY" ]; then
178
    # PKey PKEY
179
    echo "$NEW_PKEY_ID" > /sys/class/net/${PHYSDEV}/delete_child
180
fi
181
 
182
exit $retcode