source: projects/initscripts/tags/initscripts-8.91.0/sysconfig/network-scripts/ifdown-eth @ 2576

Revision 2576, 4.9 KB checked in by daisuke, 13 years ago (diff)

tagging as initscripts-8.91.0

Line 
1#!/bin/bash
2# Network Interface Configuration System
3# Copyright (c) 1996-2005 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
20cd /etc/sysconfig/network-scripts
21. /etc/sysconfig/network-scripts/network-functions
22
23[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
24
25CONFIG=${1}
26
27source_config
28
29if [ -n "${BRIDGE}" -a -x /usr/sbin/brctl ]; then
30      /sbin/ip link set dev ${DEVICE} down
31      /usr/sbin/brctl delif ${BRIDGE} ${DEVICE}
32      # Upon removing a device from a bridge,
33      # it's necessary to make radvd reload its config
34      [ -r /var/run/radvd/radvd.pid ] && kill -HUP `cat /var/run/radvd/radvd.pid`
35      if LC_ALL=C /usr/sbin/brctl show | LC_ALL=C grep -q "^${BRIDGE}   .*can't get port info"; then
36          /usr/sbin/brctl delbr ${BRIDGE}
37      fi
38      exit 0
39fi
40
41. /etc/sysconfig/network
42
43# Check to make sure the device is actually up
44check_device_down ${DEVICE} && [ "$BOOTPROTO" != "dhcp" -a "$BOOTPROTO" != "bootp" ] && [ -n "$VLAN" -a "$VLAN" != "yes" ] && exit 0
45
46if [ "${SLAVE}" != "yes" -o -z "${MASTER}" ]; then
47if [ -n "${HWADDR}" -a -z "${MACADDR}" ]; then
48    FOUNDMACADDR=`get_hwaddr ${REALDEVICE}`
49    if [ -n "${FOUNDMACADDR}" -a "${FOUNDMACADDR}" != "${HWADDR}" ]; then
50        NEWCONFIG=`get_config_by_hwaddr ${FOUNDMACADDR}`
51        if [ -n "${NEWCONFIG}" ]; then
52           eval $(LANG=C fgrep "DEVICE=" $NEWCONFIG)
53        else
54           echo $"Device ${DEVICE} has MAC address ${FOUNDMACADDR}, instead of configured address ${HWADDR}. Ignoring."
55           exit 1
56        fi
57        if [ -n "${NEWCONFIG}" -a "${NEWCONFIG##*/}" != "${CONFIG##*/}" -a "${DEVICE}" = "${REALDEVICE}" ]; then
58           exec /sbin/ifdown ${NEWCONFIG}
59        else
60           echo $"Device ${DEVICE} has MAC address ${FOUNDMACADDR}, instead of configured address ${HWADDR}. Ignoring."
61           exit 1
62        fi
63    fi
64fi
65fi
66
67if is_bonding_device ${DEVICE} ; then
68    for device in `LANG=C grep -l "^[[:space:]]*MASTER=${DEVICE}" /etc/sysconfig/network-scripts/ifcfg-*` ; do
69        is_ignored_file "$device" && continue
70        /sbin/ifdown ${device##*/}
71    done
72
73fi
74
75/etc/sysconfig/network-scripts/ifdown-ipv6 ${CONFIG}
76if [[ "${DHCPV6C}" = [Yy1]* ]] && [ -f /var/run/dhcp6c_${DEVICE}.pid ]; then
77        kill `cat /var/run/dhcp6c_${DEVICE}.pid`;
78        rm -f /var/run/dhcp6c_${DEVICE}.pid;
79fi
80
81retcode=0
82[ -n "`pidof -x dhclient`" ] && {
83        if [ -f "/var/run/dhclient-${DEVICE}.pid" ]; then
84                dhcpid=`cat /var/run/dhclient-${DEVICE}.pid`
85                if [[ "$DHCPRELEASE" = [yY1]* ]];  then
86                        /sbin/dhclient -r -lf /var/lib/dhclient/dhclient-${DEVICE}.leases -pf /var/run/dhclient-${DEVICE}.pid ${DEVICE} >/dev/null 2>&1
87                        retcode=$?
88                else
89                        kill $dhcpid >/dev/null 2>&1
90                        retcode=$?
91                        reason=STOP interface=${DEVICE} /sbin/dhclient-script
92                fi
93                if [ -f "/var/run/dhclient-${DEVICE}.pid" ]; then
94                        rm -f /var/run/dhclient-${DEVICE}.pid
95                        kill $dhcpid >/dev/null 2>&1
96                fi     
97        fi
98}       
99# we can't just delete the configured address because that address
100# may have been changed in the config file since the device was
101# brought up.  Flush all addresses associated with this
102# instance instead.
103if [ -d "/sys/class/net/${REALDEVICE}" ]; then
104        if [ "${REALDEVICE}" = "${DEVICE}" ]; then
105                ip addr flush dev ${REALDEVICE} 2>/dev/null
106        else
107                ip addr flush dev ${REALDEVICE} label ${DEVICE} 2>/dev/null
108        fi
109       
110        if [ "${SLAVE}" = "yes" -a -n "${MASTER}" ]; then
111                echo "-${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
112        fi
113
114        if [ "${REALDEVICE}" = "${DEVICE}" ]; then
115                ip link set dev ${DEVICE} down 2>/dev/null
116        fi
117fi
118[ "$retcode" = "0" ] && retcode=$?
119
120# wait up to 5 seconds for device to actually come down...
121waited=0
122while ! check_device_down ${DEVICE} && [ "$waited" -lt 50 ] ; do
123    usleep 10000
124    waited=$(($waited+1))
125done
126
127# don't leave an outdated key sitting around
128if [ -n "${WIRELESS_ENC_KEY}" -a -x /sbin/iwconfig ]; then
129    /sbin/iwconfig ${DEVICE} enc 0 >/dev/null 2>&1
130fi
131
132if [ "$retcode" = 0 ] ; then
133    /etc/sysconfig/network-scripts/ifdown-post $CONFIG
134    # do NOT use $? because ifdown should return whether or not
135    # the interface went down.
136fi
137
138if [ -n "$VLAN" -a -x /sbin/vconfig ]; then
139    # 802.1q VLAN
140    if echo ${DEVICE} | LANG=C egrep -v '(:)' | LANG=C egrep -q '(eth|bond)[0-9][0-9]*\.[0-9][0-9]?[0-9]?[0-9]?' \
141        || echo ${DEVICE} | LANG=C egrep -q 'vlan[0-9][0-9]?[0-9]?[0-9]?' ; then
142        [ -f /proc/net/vlan/${DEVICE} ] && {
143            /sbin/vconfig rem ${DEVICE}
144        }
145    fi
146fi
147
148exit $retcode
Note: See TracBrowser for help on using the repository browser.