summaryrefslogtreecommitdiffstats
path: root/etc/network.subr
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2006-08-17 03:03:38 +0000
committerbrooks <brooks@FreeBSD.org>2006-08-17 03:03:38 +0000
commit753b3bce68b4863498f2eb4c8bd1d7fda84d1bc6 (patch)
tree05ac25c2ce4ac473a12fd1ba303cf9a1fbc4e8e6 /etc/network.subr
parent6e2c7c961f3ea9e2f7e5a01b8f6125e84808e826 (diff)
downloadFreeBSD-src-753b3bce68b4863498f2eb4c8bd1d7fda84d1bc6.zip
FreeBSD-src-753b3bce68b4863498f2eb4c8bd1d7fda84d1bc6.tar.gz
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.
Diffstat (limited to 'etc/network.subr')
-rw-r--r--etc/network.subr67
1 files changed, 41 insertions, 26 deletions
diff --git a/etc/network.subr b/etc/network.subr
index 5df0de5..cb00fbd1 100644
--- a/etc/network.subr
+++ b/etc/network.subr
@@ -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"
OpenPOWER on IntegriCloud