Introduce a new function, ifexists and use it to avoid attempting to

touch interfaces that don't actually exist in the stop case.  In the
process move some IPv4 specific code from ifconfig_down to ipv4_down.

This should solve problems with ifconfig: error messages on boot when
interfaces are renamed.
This commit is contained in:
Brooks Davis 2006-08-17 03:03:38 +00:00
parent 3095bda433
commit 4e7ff69a4c
2 changed files with 42 additions and 27 deletions

View File

@ -70,35 +70,14 @@ ifconfig_up()
}
# ifconfig_down if
# Remove all inet entries from the $if interface. It returns
# 0 if inet entries were found and removed. It returns 1 if
# no entries were found or they could not be removed.
#
# XXX: should not be only inet
# returns 1 if wpa_supplicant or dhclient was stopped or
# the interface exists.
#
ifconfig_down()
{
[ -z "$1" ] && return 1
_ifs="^"
_cfg=1
inetList="`ifconfig $1 | grep 'inet ' | tr "\n" "$_ifs"`"
oldifs="$IFS"
IFS="$_ifs"
for _inet in $inetList ; do
# get rid of extraneous line
[ -z "$_inet" ] && break
_inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
IFS="$oldifs"
ifconfig $1 ${_inet} delete
IFS="$_ifs"
_cfg=0
done
IFS="$oldifs"
if wpaif $1; then
/etc/rc.d/wpa_supplicant stop $1
_cfg=0
@ -109,7 +88,10 @@ ifconfig_down()
_cfg=0
fi
ifconfig $1 down
if ifexists $1; then
ifconfig $1 down
_cfg=0
fi
return $_cfg
}
@ -255,6 +237,13 @@ wpaif()
return 1
}
# ifexists if
# Returns 0 if the interface exists and 1 otherwise.
ifexists()
{
ifconfig $1 > /dev/null 2>&1
}
# ipv4_up if
# add IPv4 addresses to the interface $if
ipv4_up()
@ -269,8 +258,32 @@ ipv4_up()
ipv4_down()
{
_if=$1
ifalias_down ${_if}
ipv4_addrs_common ${_if} -alias
_ifs="^"
_ret=1
ifexists ${_if} || return 1
inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
oldifs="$IFS"
IFS="$_ifs"
for _inet in $inetList ; do
# get rid of extraneous line
[ -z "$_inet" ] && break
_inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
IFS="$oldifs"
ifconfig ${_if} ${_inet} delete
IFS="$_ifs"
_ret=0
done
IFS="$oldifs"
ifalias_down ${_if} && _ret=0
ipv4_addrs_common ${_if} -alias && _ret=0
return $_ret
}
# ipv4_addrs_common if action
@ -466,6 +479,8 @@ ipx_down()
_ifs="^"
_ret=1
ifexists $1 || return 1
ipxList="`ifconfig $1 | grep 'ipx ' | tr "\n" "$_ifs"`"
oldifs="$IFS"

View File

@ -101,7 +101,7 @@ pccard_ether_stop()
/etc/rc.d/netif stop $ifn
# clean ARP table
arp -d -a
ifexists $ifn && arp -d -i $ifn -a
# Clean the routing table
if checkyesno removable_route_flush; then