[1108] | 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 | |
---|
| 20 | cd /etc/sysconfig/network-scripts |
---|
[2573] | 21 | . /etc/sysconfig/network-scripts/network-functions |
---|
[1108] | 22 | |
---|
[2573] | 23 | [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network |
---|
[1108] | 24 | |
---|
| 25 | CONFIG=${1} |
---|
| 26 | |
---|
| 27 | source_config |
---|
| 28 | |
---|
| 29 | if [ -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 |
---|
| 39 | fi |
---|
| 40 | |
---|
| 41 | . /etc/sysconfig/network |
---|
| 42 | |
---|
| 43 | # Check to make sure the device is actually up |
---|
| 44 | check_device_down ${DEVICE} && [ "$BOOTPROTO" != "dhcp" -a "$BOOTPROTO" != "bootp" ] && [ -n "$VLAN" -a "$VLAN" != "yes" ] && exit 0 |
---|
| 45 | |
---|
| 46 | if [ "${SLAVE}" != "yes" -o -z "${MASTER}" ]; then |
---|
| 47 | if [ -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 |
---|
| 64 | fi |
---|
| 65 | fi |
---|
| 66 | |
---|
| 67 | if 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 | |
---|
| 73 | fi |
---|
| 74 | |
---|
| 75 | /etc/sysconfig/network-scripts/ifdown-ipv6 ${CONFIG} |
---|
| 76 | if [[ "${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; |
---|
| 79 | fi |
---|
| 80 | |
---|
| 81 | retcode=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. |
---|
| 103 | if [ -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 |
---|
| 117 | fi |
---|
| 118 | [ "$retcode" = "0" ] && retcode=$? |
---|
| 119 | |
---|
| 120 | # wait up to 5 seconds for device to actually come down... |
---|
| 121 | waited=0 |
---|
| 122 | while ! check_device_down ${DEVICE} && [ "$waited" -lt 50 ] ; do |
---|
| 123 | usleep 10000 |
---|
| 124 | waited=$(($waited+1)) |
---|
| 125 | done |
---|
| 126 | |
---|
| 127 | # don't leave an outdated key sitting around |
---|
| 128 | if [ -n "${WIRELESS_ENC_KEY}" -a -x /sbin/iwconfig ]; then |
---|
| 129 | /sbin/iwconfig ${DEVICE} enc 0 >/dev/null 2>&1 |
---|
| 130 | fi |
---|
| 131 | |
---|
| 132 | if [ "$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. |
---|
| 136 | fi |
---|
| 137 | |
---|
| 138 | if [ -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 |
---|
| 146 | fi |
---|
| 147 | |
---|
| 148 | exit $retcode |
---|