[Midnightbsd-cvs] src [11790] trunk/etc/network.subr: update network logic

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Jul 11 19:59:24 EDT 2018


Revision: 11790
          http://svnweb.midnightbsd.org/src/?rev=11790
Author:   laffer1
Date:     2018-07-11 19:59:23 -0400 (Wed, 11 Jul 2018)
Log Message:
-----------
update network logic

Modified Paths:
--------------
    trunk/etc/network.subr

Property Changed:
----------------
    trunk/etc/network.subr

Modified: trunk/etc/network.subr
===================================================================
--- trunk/etc/network.subr	2018-07-11 23:58:09 UTC (rev 11789)
+++ trunk/etc/network.subr	2018-07-11 23:59:23 UTC (rev 11790)
@@ -22,8 +22,10 @@
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 #
-# $MidnightBSD: src/etc/network.subr,v 1.4 2013/01/11 00:35:31 laffer1 Exp $
+# $MidnightBSD$
 #
+IFCONFIG_CMD="/sbin/ifconfig"
+: ${netif_ipexpand_max:=2048}
 
 #
 # Subroutines commonly used from network startup scripts.
@@ -44,9 +46,11 @@
 
 	ifscript_up ${ifn} && cfg=0
 	ifconfig_up ${ifn} && cfg=0
-	afexists inet && ipv4_up ${ifn} && cfg=0
-	afexists inet6 && ipv6_up ${ifn} && cfg=0
-	afexists ipx && ipx_up ${ifn} && cfg=0
+	if ! noafif $ifn; then
+		afexists inet && ipv4_up ${ifn} && cfg=0
+		afexists inet6 && ipv6_up ${ifn} && cfg=0
+		afexists ipx && ipx_up ${ifn} && cfg=0
+	fi
 	childif_create ${ifn} && cfg=0
 
 	return $cfg
@@ -64,9 +68,11 @@
 
 	[ -z "$ifn" ] && err 1 "ifn_stop called without an interface"
 
-	afexists ipx && ipx_down ${ifn} && cfg=0
-	afexists inet6 && ipv6_down ${ifn} && cfg=0
-	afexists inet && ipv4_down ${ifn} && cfg=0
+	if ! noafif $ifn; then
+		afexists ipx && ipx_down ${ifn} && cfg=0
+		afexists inet6 && ipv6_down ${ifn} && cfg=0
+		afexists inet && ipv4_down ${ifn} && cfg=0
+	fi
 	ifconfig_down ${ifn} && cfg=0
 	ifscript_down ${ifn} && cfg=0
 	childif_destroy ${ifn} && cfg=0
@@ -74,6 +80,41 @@
 	return $cfg
 }
 
+# ifn_vnetup ifn
+#	Move ifn to the specified vnet jail.
+#
+ifn_vnetup()
+{
+
+	ifn_vnet0 $1 vnet
+}
+
+# ifn_vnetdown ifn
+#	Reclaim ifn from the specified vnet jail.
+#
+ifn_vnetdown()
+{
+
+	ifn_vnet0 $1 -vnet
+}
+
+# ifn_vnet0 ifn action
+#	Helper function for ifn_vnetup and ifn_vnetdown.
+#
+ifn_vnet0()
+{
+	local _ifn _cfg _action _vnet
+	_ifn="$1"
+	_action="$2"
+	_cfg=1
+
+	if _vnet=$(vnetif $_ifn); then
+		${IFCONFIG_CMD} $_ifn $_action $_vnet && _cfg=0
+	fi
+
+	return $_cfg
+}
+
 # ifconfig_up if
 #	Evaluate ifconfig(8) arguments for interface $if and
 #	run ifconfig(8) with those arguments. It returns 0 if
@@ -83,7 +124,7 @@
 #
 ifconfig_up()
 {
-	local _cfg _ipv6_opts ifconfig_args
+	local _cfg _ifconfig_descr _ipv6_opts ifconfig_args 
 	_cfg=1
 
 	# Make sure lo0 always comes up.
@@ -91,15 +132,8 @@
 		_cfg=0
 	fi
 
-	# ifconfig_IF
-	ifconfig_args=`ifconfig_getargs $1`
-	if [ -n "${ifconfig_args}" ]; then
-		eval ifconfig $1 ${ifconfig_args}
-		_cfg=0
-	fi
-
 	# inet6 specific
-	if afexists inet6; then
+	if ! noafif $1 && afexists inet6; then
 		if checkyesno ipv6_activate_all_interfaces; then
 			_ipv6_opts="-ifdisabled"
 		elif [ "$1" != "lo0" ]; then
@@ -109,10 +143,19 @@
 		# backward compatibility: $ipv6_enable
 		case $ipv6_enable in
 		[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
-			if ! checkyesno ipv6_gateway_enable; then
-				_ipv6_opts="${_ipv6_opts} accept_rtadv"
-			fi
+			case $1 in
+			bridge[0-9]*)
+				# No accept_rtadv by default on if_bridge(4)
+				# to avoid a conflict with the member
+				# interfaces.
 			;;
+			*)
+				if ! checkyesno ipv6_gateway_enable; then
+					_ipv6_opts="${_ipv6_opts} accept_rtadv"
+				fi
+			;;
+			esac
+		;;
 		esac
 
 		case $ipv6_cpe_wanif in
@@ -122,9 +165,19 @@
 		esac
 
 		if [ -n "${_ipv6_opts}" ]; then
-			ifconfig $1 inet6 ${_ipv6_opts}
+			${IFCONFIG_CMD} $1 inet6 ${_ipv6_opts}
 		fi
+	fi
 
+	# ifconfig_IF
+	ifconfig_args=`ifconfig_getargs $1`
+	if [ -n "${ifconfig_args}" ]; then
+		eval ${IFCONFIG_CMD} $1 ${ifconfig_args}
+		_cfg=0
+	fi
+
+	# inet6 specific
+	if ! noafif $1 && afexists inet6; then
 		# ifconfig_IF_ipv6
 		ifconfig_args=`ifconfig_getargs $1 ipv6`
 		if [ -n "${ifconfig_args}" ]; then
@@ -131,39 +184,58 @@
 			# backward compatibility: inet6 keyword
 			case "${ifconfig_args}" in
 			:*|[0-9a-fA-F]*:*)
-				warn "\$ifconfig_$1_ipv6 needs " \
+				warn "\$ifconfig_$1_ipv6 needs leading" \
 				    "\"inet6\" keyword for an IPv6 address."
 				ifconfig_args="inet6 ${ifconfig_args}"
 			;;
 			esac
-			ifconfig $1 inet6 -ifdisabled
-			eval ifconfig $1 ${ifconfig_args}
+			${IFCONFIG_CMD} $1 inet6 -ifdisabled
+			eval ${IFCONFIG_CMD} $1 ${ifconfig_args}
 			_cfg=0
 		fi
 
-		# backward compatiblity: $ipv6_ifconfig_IF
+		# $ipv6_prefix_IF will be handled in
+		# ipv6_prefix_hostid_addr_common().
+		ifconfig_args=`get_if_var $1 ipv6_prefix_IF`
+		if [ -n "${ifconfig_args}" ]; then
+			${IFCONFIG_CMD} $1 inet6 -ifdisabled
+			_cfg=0
+		fi
+
+		# backward compatibility: $ipv6_ifconfig_IF
 		ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF`
 		if [ -n "${ifconfig_args}" ]; then
 			warn "\$ipv6_ifconfig_$1 is obsolete." \
 			    "  Use ifconfig_$1_ipv6 instead."
-			ifconfig $1 inet6 -ifdisabled
-			eval ifconfig $1 inet6 ${ifconfig_args}
+			${IFCONFIG_CMD} $1 inet6 -ifdisabled
+			eval ${IFCONFIG_CMD} $1 inet6 ${ifconfig_args}
 			_cfg=0
 		fi
 	fi
 
+	ifalias $1 link alias
+	ifalias $1 ether alias
+
 	if [ ${_cfg} -eq 0 ]; then
-		ifconfig $1 up
+		${IFCONFIG_CMD} $1 up
 	fi
 
+	_ifconfig_descr=`get_if_var $1 ifconfig_IF_descr`
+	if [ -n "${_ifconfig_descr}" ]; then
+		${IFCONFIG_CMD} $1 description "${_ifconfig_descr}"
+	fi
+
 	if wpaif $1; then
 		/etc/rc.d/wpa_supplicant start $1
 		_cfg=0		# XXX: not sure this should count
+	elif hostapif $1; then
+		/etc/rc.d/hostapd start $1
+		_cfg=0
 	fi
 
 	if dhcpif $1; then
 		if [ $_cfg -ne 0 ] ; then
-			ifconfig $1 up
+			${IFCONFIG_CMD} $1 up
 		fi
 		if syncdhcpif $1; then
 			/etc/rc.d/dhclient start $1
@@ -186,6 +258,9 @@
 	if wpaif $1; then
 		/etc/rc.d/wpa_supplicant stop $1
 		_cfg=0
+	elif hostapif $1; then
+		/etc/rc.d/hostapd stop $1
+		_cfg=0
 	fi
 
 	if dhcpif $1; then
@@ -194,7 +269,7 @@
 	fi
 
 	if ifexists $1; then
-		ifconfig $1 down
+		${IFCONFIG_CMD} $1 down
 		_cfg=0
 	fi
 
@@ -216,10 +291,8 @@
 	fi
 
 	_if=$1
-	_punct=". - / +"
-	for _punct_c in $_punct; do
-		_if=`ltr ${_if} ${_punct_c} '_'`
-	done
+	_punct=".-/+"
+	ltr ${_if} "${_punct}" '_' _if
 	_var=$2
 	_default=$3
 
@@ -250,23 +323,27 @@
 #	args such as DHCP and WPA.
 ifconfig_getargs()
 {
-	local _tmpargs _arg _args
+	local _tmpargs _arg _args _vnet
 	_tmpargs=`_ifconfig_getargs $1 $2`
 	if [ $? -eq 1 ]; then
 		return 1
 	fi
 	_args=
+	_vnet=0
 
 	for _arg in $_tmpargs; do
-		case $_arg in
-		[Dd][Hh][Cc][Pp]) ;;
-		[Nn][Oo][Aa][Uu][Tt][Oo]) ;;
-		[Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;;
-		[Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;;
-		[Ww][Pp][Aa]) ;;
-		*)
+		case $_arg:$_vnet in
+		[Dd][Hh][Cc][Pp]:0) ;;
+		[Nn][Oo][Aa][Uu][Tt][Oo]:0) ;;
+		[Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]:0) ;;
+		[Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]:0) ;;
+		[Ww][Pp][Aa]:0) ;;
+		[Hh][Oo][Ss][Tt][Aa][Pp]:0) ;;
+		vnet:0)	_vnet=1 ;;
+		*:1)	_vnet=0 ;;
+		*:0)
 			_args="$_args $_arg"
-			;;
+		;;
 		esac
 	done
 
@@ -299,6 +376,15 @@
 	local _tmpargs _arg
 	_tmpargs=`_ifconfig_getargs $1`
 
+	case $1 in
+	lo[0-9]*|\
+	stf[0-9]*|\
+	faith[0-9]*|\
+	lp[0-9]*|\
+	sl[0-9]*)
+		return 1
+		;;
+	esac
 	if noafif $1; then
 		return 1
 	fi
@@ -364,6 +450,43 @@
 	return 1
 }
 
+# hostapif if
+#	Returns 0 if the interface is a HOSTAP interface and 1 otherwise.
+hostapif()
+{
+	local _tmpargs _arg
+	_tmpargs=`_ifconfig_getargs $1`
+
+	for _arg in $_tmpargs; do
+		case $_arg in
+		[Hh][Oo][Ss][Tt][Aa][Pp])
+			return 0
+			;;
+		esac
+	done
+
+	return 1
+}
+
+# vnetif if
+#	Returns 0 and echo jail if "vnet" keyword is specified on the
+#	interface, and 1 otherwise.
+vnetif()
+{
+	local _tmpargs _arg _vnet
+	_tmpargs=`_ifconfig_getargs $1`
+
+	_vnet=0
+	for _arg in $_tmpargs; do
+		case $_arg:$_vnet in
+		vnet:0)	_vnet=1 ;;
+		*:1)	echo $_arg; return 0 ;;
+		esac
+	done
+
+	return 1
+}
+
 # afexists af
 #	Returns 0 if the address family is enabled in the kernel
 #	1 otherwise.
@@ -386,6 +509,9 @@
 			return 1
 		fi
 		;;
+	link|ether)
+		return 0
+		;;
 	*)
 		err 1 "afexists(): Unsupported address family: $_af"
 		;;
@@ -402,6 +528,7 @@
 	case $_if in
 	pflog[0-9]*|\
 	pfsync[0-9]*|\
+	usbus[0-9]*|\
 	an[0-9]*|\
 	ath[0-9]*|\
 	ipw[0-9]*|\
@@ -446,6 +573,12 @@
 			return 0
 		fi
 
+		# True if $ipv6_prefix_IF is defined.
+		_tmpargs=`get_if_var $_if ipv6_prefix_IF`
+		if [ -n "${_tmpargs}" ]; then
+			return 0
+		fi
+
 		# backward compatibility: True if $ipv6_ifconfig_IF is defined.
 		_tmpargs=`get_if_var $_if ipv6_ifconfig_IF`
 		if [ -n "${_tmpargs}" ]; then
@@ -466,7 +599,7 @@
 	_if=$1
 
 	case $_if in
-	lo0|\
+	lo[0-9]*|\
 	stf[0-9]*|\
 	faith[0-9]*|\
 	lp[0-9]*|\
@@ -492,9 +625,18 @@
 	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
 		if checkyesno ipv6_gateway_enable; then
 			return 1
-		else
+		fi
+		case $1 in
+		bridge[0-9]*)
+			# No accept_rtadv by default on if_bridge(4)
+			# to avoid a conflict with the member
+			# interfaces.
+			return 1
+		;;
+		*)
 			return 0
-		fi
+		;;
+		esac
 	;;
 	esac
 
@@ -525,7 +667,7 @@
 ifexists()
 {
 	[ -z "$1" ] && return 1
-	ifconfig -n $1 > /dev/null 2>&1
+	${IFCONFIG_CMD} -n $1 > /dev/null 2>&1
 }
 
 # ipv4_up if
@@ -540,11 +682,10 @@
 	if [ "${_if}" = "lo0" ]; then
 		ifconfig_args=`get_if_var ${_if} ifconfig_IF`
 		if [ -z "${ifconfig_args}" ]; then
-			ifconfig ${_if} inet 127.0.0.1/8 alias
+			${IFCONFIG_CMD} ${_if} inet 127.0.0.1/8 alias
 		fi
 	fi
-	ifalias_up ${_if} inet && _ret=0
-	ipv4_addrs_common ${_if} alias && _ret=0
+	ifalias ${_if} inet alias && _ret=0
 
 	return $_ret
 }
@@ -561,14 +702,10 @@
 		return 0
 	fi
 
-	ifalias_up ${_if} inet6 && _ret=0
+	ifalias ${_if} inet6 alias && _ret=0
 	ipv6_prefix_hostid_addr_common ${_if} alias && _ret=0
 	ipv6_accept_rtadv_up ${_if} && _ret=0
 
-	# wait for DAD
-	sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
-	sleep 1
-
 	return $_ret
 }
 
@@ -581,26 +718,28 @@
 	_ifs="^"
 	_ret=1
 
-	inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`"
+	ifalias ${_if} inet -alias && _ret=0
 
+	inetList="`${IFCONFIG_CMD} ${_if} | grep 'inet ' | tr "\n\t" "$_ifs"`"
+
 	oldifs="$IFS"
 	IFS="$_ifs"
 	for _inet in $inetList ; do
 		# get rid of extraneous line
-		[ -z "$_inet" ] && break
+		case $_inet in
+		inet\ *)	;;
+		*)		continue ;;
+		esac
 
 		_inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
 
 		IFS="$oldifs"
-		ifconfig ${_if} ${_inet} delete
+		${IFCONFIG_CMD} ${_if} ${_inet} delete
 		IFS="$_ifs"
 		_ret=0
 	done
 	IFS="$oldifs"
 
-	ifalias_down ${_if} inet && _ret=0
-	ipv4_addrs_common ${_if} -alias && _ret=0
-
 	return $_ret
 }
 
@@ -619,20 +758,23 @@
 
 	ipv6_accept_rtadv_down ${_if} && _ret=0
 	ipv6_prefix_hostid_addr_common ${_if} -alias && _ret=0
-	ifalias_down ${_if} inet6 && _ret=0
+	ifalias ${_if} inet6 -alias && _ret=0
 
-	inetList="`ifconfig ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`"
+	inetList="`${IFCONFIG_CMD} ${_if} | grep 'inet6 ' | tr "\n\t" "$_ifs"`"
 
 	oldifs="$IFS"
 	IFS="$_ifs"
 	for _inet6 in $inetList ; do
 		# get rid of extraneous line
-		[ -z "$_inet6" ] && break
+		case $_inet6 in
+		inet6\ *)	;;
+		*)		continue ;;
+		esac
 
 		_inet6=`expr "$_inet6" : '.*\(inet6 \([0-9a-f:]*\)\).*'`
 
 		IFS="$oldifs"
-		ifconfig ${_if} ${_inet6} -alias
+		${IFCONFIG_CMD} ${_if} ${_inet6} -alias
 		IFS="$_ifs"
 		_ret=0
 	done
@@ -641,234 +783,394 @@
 	return $_ret
 }
 
-# ipv4_addrs_common if action
-#	Evaluate the ifconfig_if_ipv4 arguments for interface $if and
-#	use $action to add or remove IPv4 addresses from $if.
-ipv4_addrs_common()
-{
-	local _ret _if _action _cidr _cidr_addr
-	local _ipaddr _netmask _range _ipnet _iplow _iphigh _ipcount
-	_ret=1
-	_if=$1
-	_action=$2
-
-	# get ipv4-addresses
-	cidr_addr=`get_if_var $_if ipv4_addrs_IF`
-
-	for _cidr in ${cidr_addr}; do
-		_ipaddr=${_cidr%%/*}
-		_netmask="/"${_cidr##*/}
-		_range=${_ipaddr##*.}
-		_ipnet=${_ipaddr%.*}
-		_iplow=${_range%-*}
-		_iphigh=${_range#*-}
-
-		# clear netmask when removing aliases
-		if [ "${_action}" = "-alias" ]; then
-			_netmask=""
-		fi
-
-		_ipcount=${_iplow}
-		while [ "${_ipcount}" -le "${_iphigh}" ]; do
-			eval "ifconfig ${_if} ${_action} ${_ipnet}.${_ipcount}${_netmask}"
-			_ipcount=$((${_ipcount}+1))
-			_ret=0
-
-			# only the first ipaddr in a subnet need the real netmask
-			if [ "${_action}" != "-alias" ]; then
-				_netmask="/32"
-			fi
-		done
-	done
-
-	return $_ret
-}
-
-# ifalias_up if af
-#	Configure aliases for network interface $if.
+# ifalias if af action
+#	Configure or remove aliases for network interface $if.
 #	It returns 0 if at least one alias was configured or
-#	1 if there were none.
+#	removed, or 1 if there were none.
 #
-ifalias_up()
+ifalias()
 {
 	local _ret
 	_ret=1
 
+	afexists $2 || return $_ret
+
 	case "$2" in
-	inet)
-		_ret=`ifalias_ipv4_up "$1"`
+	inet|inet6|link|ether)
+		ifalias_af_common $1 $2 $3 && _ret=0
 		;;
-	inet6)
-		_ret=`ifalias_ipv6_up "$1"`
-		;;
 	esac
 
 	return $_ret
 }
 
-# ifalias_ipv4_up if
-#	Helper function for ifalias_up().  Handles IPv4.
+# ifalias_expand_addr af action addr
+#	Expand address range ("N-M") specification in addr.
+#	"addr" must not include an address-family keyword.
+#	The results will include an address-family keyword.
 #
-ifalias_ipv4_up()
+ifalias_expand_addr()
 {
-	local _ret alias ifconfig_args
-	_ret=1
+	local _af _action
 
-	# ifconfig_IF_aliasN which starts with "inet"
-	alias=0
-	while : ; do
-		ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
-		case "${ifconfig_args}" in
-		inet\ *)
-			ifconfig $1 ${ifconfig_args} alias && _ret=0
-			;;
-		inet6\ *)
-			;;
-		"")
-			break
-			;;
-		*)
-			warn "\$ifconfig_$1_alias${alias} needs " \
-			    "\"inet\" keyword for an IPv4 address."
-			ifconfig $1 ${ifconfig_args} alias && _ret=0
-			;;
-		esac
-		alias=$((${alias} + 1))
-	done
+	_af=$1
+	_action=$2
+	shift 2
 
-	return $_ret
+	afexists $_af || return
+	ifalias_expand_addr_$_af $_action $*
 }
 
-# ifalias_ipv6_up if
-#	Helper function for ifalias_up().  Handles IPv6.
+# ifalias_expand_addr_inet action addr
+#	Helper function for ifalias_expand_addr().  Handles IPv4.
 #
-ifalias_ipv6_up()
+ifalias_expand_addr_inet()
 {
-	local _ret alias ifconfig_args
-	_ret=1
+	local _action _arg _cidr _cidr_addr _exargs
+	local _ipaddr _plen _range _iphead _iptail _iplow _iphigh _ipcount
+	local _retstr _c
+	_action=$1
+	_arg=$2
+	shift 2
+	_exargs=$*
+	_retstr=
 
-	# ifconfig_IF_aliasN which starts with "inet6"
-	alias=0
-	while : ; do
-		ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
-		case "${ifconfig_args}" in
-		inet6\ *)
-			ifconfig $1 ${ifconfig_args} alias && _ret=0
-			;;
-		"")
-			break
-			;;
+	case $_action:$_arg:$_exargs in
+	*:*--*)		return ;;	# invalid
+	tmp:*[0-9]-[0-9]*:*)		# to be expanded
+		_action="alias"
+	;;
+	*:*[0-9]-[0-9]*:*)		# to be expanded
+	;;
+	tmp:*:*netmask*)		# already expanded w/ netmask option
+		echo ${_arg%/[0-9]*} $_exargs && return
+	;;
+	tmp:*:*)			# already expanded w/o netmask option
+		echo $_arg $_exargs && return
+	;;
+	*:*:*netmask*)			# already expanded w/ netmask option
+		echo inet ${_arg%/[0-9]*} $_exargs && return
+	;;
+	*:*:*)				# already expanded w/o netmask option
+		echo inet $_arg $_exargs && return
+	;;
+	esac
+
+	for _cidr in $_arg; do
+		_ipaddr=${_cidr%%/*}
+		_plen=${_cidr##*/}
+		# When subnet prefix length is not specified, use /32.
+		case $_plen in
+		$_ipaddr)	_plen=32 ;;	# "/" character not found
 		esac
-		alias=$((${alias} + 1))
-	done
 
-	# backward compatibility: ipv6_ifconfig_IF_aliasN.
-	alias=0
-	while : ; do
-		ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
-		case "${ifconfig_args}" in
-		"")
-			break
+		OIFS=$IFS
+		IFS=. set -- $_ipaddr
+		_range=
+		_iphead=
+		_iptail=
+		for _c in $@; do
+			case $_range:$_c in
+			:[0-9]*-[0-9]*)
+				_range=$_c
 			;;
-		*)
-			ifconfig $1 inet6 ${ifconfig_args} alias && _ret=0
-			warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \
-			    "  Use ifconfig_$1_aliasN instead."
+			:*)
+				_iphead="${_iphead}${_iphead:+.}${_c}"
 			;;
-		esac
-		alias=$((${alias} + 1))
+			*:*)
+				_iptail="${_iptail}${_iptail:+.}${_c}"
+			;;
+			esac
+		done
+		IFS=$OIFS
+		_iplow=${_range%-*}
+		_iphigh=${_range#*-}
+
+		# clear netmask when removing aliases
+		if [ "$_action" = "-alias" ]; then
+			_plen=""
+		fi
+
+		_ipcount=$_iplow
+		while [ "$_ipcount" -le "$_iphigh" ]; do
+			_retstr="${_retstr} ${_iphead}${_iphead:+.}${_ipcount}${_iptail:+.}${_iptail}${_plen:+/}${_plen}"
+			if [ $_ipcount -gt $(($_iplow + $netif_ipexpand_max)) ]; then
+				warn "Range specification is too large (${_iphead}${_iphead:+.}${_iplow}${_iptail:+.}${_iptail}-${_iphead}${_iphead:+.}${_iphigh}${_iptail:+.}${_iptail}).  ${_iphead}${_iphead:+.}${_iplow}${_iptail:+.}${_iptail}-${_iphead}${_iphead:+.}${_ipcount}${_iptail:+.}${_iptail} was processed.  Increase \$netif_ipexpand_max in rc.conf."
+				break
+			else
+				_ipcount=$(($_ipcount + 1))
+			fi
+			# Forcibly set /32 for remaining aliases.
+			_plen=32
+		done
 	done
 
-	return $_ret
+	for _c in $_retstr; do
+		ifalias_expand_addr_inet $_action $_c $_exargs
+	done
 }
 
-# ifalias_down if af
-#	Remove aliases for network interface $if.
-#	It returns 0 if at least one alias was removed or
-#	1 if there were none.
+# ifalias_expand_addr_inet6 action addr
+#	Helper function for ifalias_expand_addr().  Handles IPv6.
 #
-ifalias_down()
+ifalias_expand_addr_inet6()
 {
-	local _ret
-	_ret=1
+	local _action _arg _cidr _cidr_addr _exargs
+	local _ipaddr _plen _ipleft _ipright _iplow _iphigh _ipcount
+	local _ipv4part
+	local _retstr _c
+	_action=$1
+	_arg=$2
+	shift 2
+	_exargs=$*
+	_retstr=
 
-	case "$2" in
-	inet)
-		_ret=`ifalias_ipv4_down "$1"`
-		;;
-	inet6)
-		_ret=`ifalias_ipv6_down "$1"`
-		;;
+	case $_action:$_arg:$_exargs in
+	*:*--*:*)	return ;;	# invalid
+	tmp:*[0-9a-zA-Z]-[0-9a-zA-Z]*:*)# to be expanded
+		_action="alias"
+	;;
+	*:*[0-9a-zA-Z]-[0-9a-zA-Z]*:*)	# to be expanded
+	;;
+	tmp:*:*prefixlen*)	# already expanded w/ prefixlen option
+		echo ${_arg%/[0-9]*} $_exargs && return
+	;;
+	tmp:*:*)		# already expanded w/o prefixlen option
+		echo $_arg $_exargs && return
+	;;
+	*:*:*prefixlen*)	# already expanded w/ prefixlen option
+		echo inet6 ${_arg%/[0-9]*} $_exargs && return
+	;;
+	*:*:*)			# already expanded w/o prefixlen option
+		echo inet6 $_arg $_exargs && return
+	;;
 	esac
 
-	return $_ret
+	for _cidr in $_arg; do
+		_ipaddr="${_cidr%%/*}"
+		_plen="${_cidr##*/}"
+
+		case $_action:$_ipaddr:$_cidr in
+		-alias:*:*)		unset _plen ;;
+		*:$_cidr:$_ipaddr)	unset _plen ;;
+		esac
+
+		if [ "${_ipaddr%:*.*.*.*}" = "$_ipaddr" ]; then
+			# Handle !v4mapped && !v4compat addresses.
+
+			# The default prefix length is 64.
+			case $_ipaddr:$_cidr in
+			$_cidr:$_ipaddr)	_plen="64" ;;
+			esac
+			_ipleft=${_ipaddr%-*}
+			_ipright=${_ipaddr#*-}
+			_iplow=${_ipleft##*:}
+			_iphigh=${_ipright%%:*}
+			_ipleft=${_ipleft%:*}
+			_ipright=${_ipright#*:}
+
+			if [ "$_iphigh" = "$_ipright" ]; then
+				unset _ipright
+			else
+				_ipright=:$_ipright
+			fi
+
+			if [ -n "$_iplow" -a -n "$_iphigh" ]; then
+				_iplow=$((0x$_iplow))
+				_iphigh=$((0x$_iphigh))
+				_ipcount=$_iplow
+				while [ $_ipcount -le $_iphigh ]; do
+					_r=`printf "%s:%04x%s%s" \
+					    $_ipleft $_ipcount $_ipright \
+					    ${_plen:+/}$_plen`
+					_retstr="$_retstr $_r"
+					if [ $_ipcount -gt $(($_iplow + $netif_ipexpand_max)) ]
+					then
+						warn "Range specification is too large $(printf '(%s:%x%s-%s:%x%s)' "$_ipleft" "$_iplow" "$_ipright" "$_ipleft" "$_iphigh" "$_ipright"). $(printf '%s:%x%s-%s:%x%s' "$_ipleft" "$_iplow" "$_ipright" "$_ipleft" "$_ipcount" "$_ipright") was processed.  Increase \$netif_ipexpand_max in rc.conf."
+						break
+					else
+						_ipcount=$(($_ipcount + 1))
+					fi
+				done
+			else
+				_retstr="${_ipaddr}${_plen:+/}${_plen}"
+			fi
+
+			for _c in $_retstr; do
+				ifalias_expand_addr_inet6 $_action $_c $_exargs
+			done
+		else
+			# v4mapped/v4compat should handle as an IPv4 alias
+			_ipv4part=${_ipaddr##*:}
+
+			# Adjust prefix length if any.  If not, set the
+			# default prefix length as 32.
+			case $_ipaddr:$_cidr in
+			$_cidr:$_ipaddr)	_plen=32 ;;
+			*)			_plen=$(($_plen - 96)) ;;
+			esac
+
+			_retstr=`ifalias_expand_addr_inet \
+			    tmp ${_ipv4part}${_plen:+/}${_plen}`
+			for _c in $_retstr; do
+				ifalias_expand_addr_inet $_action $_c $_exargs
+			done
+		fi
+	done
 }
 
-# ifalias_ipv4_down if
-#	Helper function for ifalias_down().  Handles IPv4.
+# ifalias_af_common_handler if af action args
+#	Helper function for ifalias_af_common().
 #
-ifalias_ipv4_down()
+ifalias_af_common_handler()
 {
-	local _ret alias ifconfig_args
+	local _ret _if _af _action _args _c _tmpargs
+
 	_ret=1
+	_if=$1
+	_af=$2
+	_action=$3
+	shift 3
+	_args=$*
 
-	# ifconfig_IF_aliasN which starts with "inet"
-	alias=0
-	while : ; do
-		ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
-		case "${ifconfig_args}" in
-		inet\ *)
-			ifconfig $1 ${ifconfig_args} -alias && _ret=0
+	case $_args in
+	${_af}\ *)	;;
+	*)	return	;;
+	esac
+
+	# link(ether) does not support address removal.
+	case $_af:$_action in
+	link:-alias|ether:-alias)	return ;;
+	esac
+
+	_tmpargs=
+	for _c in $_args; do
+		case $_c in
+		${_af})
+			case $_tmpargs in
+			${_af}\ *[0-9a-fA-F]-*)
+				ifalias_af_common_handler $_if $_af $_action \
+				`ifalias_expand_addr $_af $_action ${_tmpargs#${_af}\ }`
 			;;
-		"")
-			break
+			${_af}\ *)
+				${IFCONFIG_CMD} $_if $_tmpargs $_action && _ret=0
 			;;
+			esac
+			_tmpargs=$_af
+		;;
+		*)
+			_tmpargs="$_tmpargs $_c"
+		;;
 		esac
-		alias=$((${alias} + 1))
 	done
+	# Process the last component if any.
+	if [ -n "$_tmpargs}" ]; then
+		case $_tmpargs in
+		${_af}\ *[0-9a-fA-F]-*)
+			ifalias_af_common_handler $_if $_af $_action \
+			`ifalias_expand_addr $_af $_action ${_tmpargs#${_af}\ }`
+		;;
+		${_af}\ *)
+			${IFCONFIG_CMD} $_if $_tmpargs $_action && _ret=0
+		;;
+		esac
+	fi
 
 	return $_ret
 }
 
-# ifalias_ipv6_down if
-#	Helper function for ifalias_down().  Handles IPv6.
+# ifalias_af_common if af action
+#	Helper function for ifalias().
 #
-ifalias_ipv6_down()
+ifalias_af_common()
 {
-	local _ret alias ifconfig_args
+	local _ret _if _af _action alias ifconfig_args _aliasn _c _tmpargs _iaf
+	local _vif _punct=".-/+"
+
 	_ret=1
+	_aliasn=
+	_if=$1
+	_af=$2
+	_action=$3
 
-	# ifconfig_IF_aliasN which starts with "inet6"
-	alias=0
-	while : ; do
-		ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}`
-		case "${ifconfig_args}" in
-		inet6\ *)
-			ifconfig $1 ${ifconfig_args} -alias && _ret=0
+	# Normalize $_if before using it in a pattern to list_vars()
+	ltr "$_if" "$_punct" "_" _vif
+
+	# ifconfig_IF_aliasN which starts with $_af
+	for alias in `list_vars ifconfig_${_vif}_alias[0-9]\* |
+		sort_lite -nk1.$((9+${#_vif}+7))`
+	do
+		eval ifconfig_args=\"\$$alias\"
+		_iaf=
+		case $ifconfig_args in
+		inet\ *)	_iaf=inet ;;
+		inet6\ *)	_iaf=inet6 ;;
+		ipx\ *)		_iaf=ipx ;;
+		link\ *)	_iaf=link ;;
+		ether\ *)	_iaf=ether ;;
+		esac
+
+		case ${_af}:${_action}:${_iaf}:"${ifconfig_args}" in
+		${_af}:*:${_af}:*)
+			_aliasn="$_aliasn $ifconfig_args"
 			;;
-		"")
+		${_af}:*:"":"")
 			break
 			;;
+		inet:alias:"":*)
+			_aliasn="$_aliasn inet $ifconfig_args"
+			warn "\$${alias} needs leading" \
+			    "\"inet\" keyword for an IPv4 address."
 		esac
-		alias=$((${alias} + 1))
 	done
 
 	# backward compatibility: ipv6_ifconfig_IF_aliasN.
-	alias=0
-	while : ; do
-		ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}`
-		case "${ifconfig_args}" in
-		"")
-			break
+	case $_af in
+	inet6)
+		for alias in `list_vars ipv6_ifconfig_${_vif}_alias[0-9]\* |
+			sort_lite -nk1.$((14+${#_vif}+7))`
+		do
+			eval ifconfig_args=\"\$$alias\"
+			case ${_action}:"${ifconfig_args}" in
+			*:"")
+				break
 			;;
+			alias:*)
+				_aliasn="${_aliasn} inet6 ${ifconfig_args}"
+				warn "\$${alias} is obsolete. " \
+				    "Use ifconfig_${_vif}_aliasN instead."
+			;;
+			esac
+		done
+	esac
+
+	# backward compatibility: ipv4_addrs_IF.
+	for _tmpargs in `get_if_var $_if ipv4_addrs_IF`; do
+		_aliasn="$_aliasn inet $_tmpargs"
+	done
+
+	# Handle ifconfig_IF_aliases, ifconfig_IF_aliasN, and the others.
+	_tmpargs=
+	for _c in `get_if_var $_if ifconfig_IF_aliases` $_aliasn; do
+		case $_c in
+		inet|inet6|ipx|link|ether)
+			case $_tmpargs in
+			${_af}\ *)
+				eval ifalias_af_common_handler $_if $_af $_action $_tmpargs && _ret=0
+			;;
+			esac
+			_tmpargs=$_c
+		;;
 		*)
-			ifconfig $1 inet6 ${ifconfig_args} -alias && _ret=0
-			warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \
-			    "  Use ifconfig_$1_aliasN instead."
-			;;
+			_tmpargs="$_tmpargs $_c"
 		esac
-		alias=$((${alias} + 1))
 	done
+	# Process the last component
+	case $_tmpargs in
+	${_af}\ *)
+		ifalias_af_common_handler $_if $_af $_action $_tmpargs && _ret=0
+	;;
+	esac
 
 	return $_ret
 }
@@ -878,25 +1180,31 @@
 #
 ipv6_prefix_hostid_addr_common()
 {
-	local _if _action prefix laddr hostid j address
+	local _if _action prefix j
 	_if=$1
 	_action=$2
 	prefix=`get_if_var ${_if} ipv6_prefix_IF`
 
 	if [ -n "${prefix}" ]; then
-		laddr=`network6_getladdr ${_if}`
-		hostid=${laddr#fe80::}
-		hostid=${hostid%\%*}
-
 		for j in ${prefix}; do
-			address=$j\:${hostid}
-			ifconfig ${_if} inet6 ${address} prefixlen 64 ${_action}
+			# The default prefixlen is 64.
+			plen=${j#*/}
+			case $j:$plen in
+			$plen:$j)	plen=64 ;;
+			*)		j=${j%/*} ;;
+			esac
 
+			# Normalize the last part by removing ":"
+			j=${j%::*}
+			j=${j%:}
+			${IFCONFIG_CMD} ${_if} inet6 $j:: \
+				prefixlen $plen eui64 ${_action}
+
 			# if I am a router, add subnet router
 			# anycast address (RFC 2373).
 			if checkyesno ipv6_gateway_enable; then
-				ifconfig ${_if} inet6 $j:: prefixlen 64 \
-					${_action} anycast
+				${IFCONFIG_CMD} ${_if} inet6 $j:: \
+					prefixlen $plen ${_action} anycast
 			fi
 		done
 	fi
@@ -908,7 +1216,7 @@
 ipv6_accept_rtadv_up()
 {
 	if ipv6_autoconfif $1; then
-		ifconfig $1 inet6 accept_rtadv up
+		${IFCONFIG_CMD} $1 inet6 accept_rtadv up
 		if ! checkyesno rtsold_enable; then
 			rtsol ${rtsol_flags} $1
 		fi
@@ -920,7 +1228,7 @@
 ipv6_accept_rtadv_down()
 {
 	if ipv6_autoconfif $1; then
-		ifconfig $1 inet6 -accept_rtadv
+		${IFCONFIG_CMD} $1 inet6 -accept_rtadv
 	fi
 }
 
@@ -959,19 +1267,80 @@
 #
 clone_up()
 {
-	local _prefix _list ifn
-	_prefix=
+	local _list ifn ifopt _iflist _n tmpargs
 	_list=
+	_iflist=$*
 
 	# create_args_IF
 	for ifn in ${cloned_interfaces}; do
-		ifconfig ${ifn} create `get_if_var ${ifn} create_args_IF`
+		# Parse ifn:ifopt.
+		OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
+		case $_iflist in
+		""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn)	;;
+		*)	continue ;;
+		esac
+		case $ifn in
+		epair[0-9]*)
+			# epair(4) uses epair[0-9] for creation and
+			# epair[0-9][ab] for configuration.
+			#
+			# Skip if ${ifn}a or ${ifn}b already exist.
+			if ${IFCONFIG_CMD} ${ifn}a > /dev/null 2>&1; then
+				continue
+			elif ${IFCONFIG_CMD} ${ifn}b > /dev/null 2>&1; then
+				continue
+			fi
+			${IFCONFIG_CMD} ${ifn} create \
+			    `get_if_var ${ifn} create_args_IF`
+			if [ $? -eq 0 ]; then
+				_list="$_list ${ifn}a ${ifn}b"
+			fi
+		;;
+		*)
+			# Skip if ${ifn} already exists.
+			if ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
+				continue
+			fi
+			${IFCONFIG_CMD} ${ifn} create \
+			    `get_if_var ${ifn} create_args_IF`
+			if [ $? -eq 0 ]; then
+				_list="$_list $ifn"
+			fi
+		esac
+	done
+	if [ -n "$gif_interfaces" ]; then
+		warn "\$gif_interfaces is obsolete.  Use \$cloned_interfaces instead."
+	fi
+	for ifn in ${gif_interfaces}; do
+		# Parse ifn:ifopt.
+		OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
+		case $_iflist in
+		""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn)	;;
+		*)	continue ;;
+		esac
+		# Skip if ifn already exists.
+		if ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
+			continue
+		fi
+		case $ifn in
+		gif[0-9]*)
+			${IFCONFIG_CMD} $ifn create
+		;;
+		*)
+			_n=$(${IFCONFIG_CMD} gif create)
+			${IFCONFIG_CMD} $_n name $ifn
+		;;
+		esac
 		if [ $? -eq 0 ]; then
-			_list="${_list}${_prefix}${ifn}"
-			[ -z "$_prefix" ] && _prefix=' '
+			_list="$_list $ifn"
 		fi
+		tmpargs=$(get_if_var $ifn gifconfig_IF)
+		eval ifconfig_${ifn}=\"tunnel \$tmpargs\"
 	done
-	debug "Cloned: ${_list}"
+	if [ -n "${_list# }" ]; then
+		echo "Created clone interfaces: ${_list# }."
+	fi
+	debug "Cloned: ${_list# }"
 }
 
 # clone_down
@@ -980,18 +1349,62 @@
 #
 clone_down()
 {
-	local _prefix _list ifn
-	_prefix=
+	local _list ifn _difn ifopt _iflist _sticky
 	_list=
+	_iflist=$*
 
-	for ifn in ${cloned_interfaces}; do
-		ifconfig -n ${ifn} destroy
-		if [ $? -eq 0 ]; then
-			_list="${_list}${_prefix}${ifn}"
-			[ -z "$_prefix" ] && _prefix=' '
-		fi
+	: ${cloned_interfaces_sticky:=NO}
+	if checkyesno cloned_interfaces_sticky; then
+		_sticky=1
+	else
+		_sticky=0
+	fi
+	for ifn in ${cloned_interfaces} ${gif_interfaces}; do
+		# Parse ifn:ifopt.
+		OIFS=$IFS; IFS=:; set -- $ifn; ifn=$1; ifopt=$2; IFS=$OIFS
+		case $ifopt:$_sticky in
+		sticky:*)	continue ;;	# :sticky => not destroy
+		nosticky:*)	;;		# :nosticky => destroy
+		*:1)		continue ;;	# global sticky knob == 1
+		esac
+		case $_iflist in
+		""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn)	;;
+		*)	continue ;;
+		esac
+		case $ifn in
+		epair[0-9]*)
+			# Note: epair(4) uses epair[0-9] for removal and
+			# epair[0-9][ab] for configuration.
+			#
+			# Skip if both of ${ifn}a and ${ifn}b do not exist.
+			if ${IFCONFIG_CMD} ${ifn}a > /dev/null 2>&1; then
+				_difn=${ifn}a
+			elif ${IFCONFIG_CMD} ${ifn}b > /dev/null 2>&1; then
+				_difn=${ifn}b
+			else
+				continue
+			fi
+			${IFCONFIG_CMD} -n $_difn destroy
+			if [ $? -eq 0 ]; then
+				_list="$_list ${ifn}a ${ifn}b"
+			fi
+		;;
+		*)
+			# Skip if ifn does not exist.
+			if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
+				continue
+			fi
+			${IFCONFIG_CMD} -n ${ifn} destroy
+			if [ $? -eq 0 ]; then
+				_list="$_list $ifn"
+			fi
+		;;
+		esac
 	done
-	debug "Destroyed clones: ${_list}"
+	if [ -n "${_list# }" ]; then
+		echo "Destroyed clone interfaces: ${_list# }."
+	fi
+	debug "Destroyed clones: ${_list# }"
 }
 
 # childif_create
@@ -1012,16 +1425,16 @@
 		debug_flags="`get_if_var $child wlandebug_IF`"
 
 		if expr $child : 'wlan[0-9][0-9]*$' >/dev/null 2>&1; then
-			ifconfig $child create ${create_args} && cfg=0
+			${IFCONFIG_CMD} $child create ${create_args} && cfg=0
 			if [ -n "${debug_flags}" ]; then
 				wlandebug -i $child ${debug_flags}
 			fi
 		else
-			i=`ifconfig wlan create ${create_args}`
+			i=`${IFCONFIG_CMD} wlan create ${create_args}`
 			if [ -n "${debug_flags}" ]; then
 				wlandebug -i $i ${debug_flags}
 			fi
-			ifconfig $i name $child && cfg=0
+			${IFCONFIG_CMD} $i name $child && cfg=0
 		fi
 		if autoif $child; then
 			ifn_start $child
@@ -1039,14 +1452,14 @@
 		if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
 			child="${ifn}.${child}"
 			create_args=`get_if_var $child create_args_IF`
-			ifconfig $child create ${create_args} && cfg=0
+			${IFCONFIG_CMD} $child create ${create_args} && cfg=0
 		else
 			create_args="vlandev $ifn `get_if_var $child create_args_IF`"
 			if expr $child : 'vlan[0-9][0-9]*$' >/dev/null 2>&1; then
-				ifconfig $child create ${create_args} && cfg=0
+				${IFCONFIG_CMD} $child create ${create_args} && cfg=0
 			else
-				i=`ifconfig vlan create ${create_args}`
-				ifconfig $i name $child && cfg=0
+				i=`${IFCONFIG_CMD} vlan create ${create_args}`
+				${IFCONFIG_CMD} $i name $child && cfg=0
 			fi
 		fi
 		if autoif $child; then
@@ -1070,7 +1483,7 @@
 		if ! ifexists $child; then
 			continue
 		fi
-		ifconfig -n $child destroy && cfg=0
+		${IFCONFIG_CMD} -n $child destroy && cfg=0
 	done
 
 	child_vlans=`get_if_var $ifn vlans_IF`
@@ -1081,7 +1494,7 @@
 		if ! ifexists $child; then
 			continue
 		fi
-		ifconfig -n $child destroy && cfg=0
+		${IFCONFIG_CMD} -n $child destroy && cfg=0
 	done
 
 	return ${cfg}
@@ -1114,32 +1527,6 @@
 	done
 }
 
-# gif_up
-#	Create gif(4) tunnel interfaces.
-gif_up()
-{
-	local i peers
-
-	for i in ${gif_interfaces}; do
-		peers=`get_if_var $i gifconfig_IF`
-		case ${peers} in
-		'')
-			continue
-			;;
-		*)
-			if expr $i : 'gif[0-9][0-9]*$' >/dev/null 2>&1; then
-				ifconfig $i create >/dev/null 2>&1
-			else
-				gif=`ifconfig gif create`
-				ifconfig $gif name $i
-			fi
-			ifconfig $i tunnel ${peers}
-			ifconfig $i up
-			;;
-		esac
-	done
-}
-
 # ng_fec_create ifn
 #	Configure Fast EtherChannel for interface $ifn. Returns 0 if
 #	FEC arguments were found and configured; returns !0 otherwise.
@@ -1200,7 +1587,7 @@
 	# ifconfig_IF_ipx
 	ifconfig_args=`_ifconfig_getargs $ifn ipx`
 	if [ -n "${ifconfig_args}" ]; then
-		ifconfig ${ifn} ${ifconfig_args}
+		${IFCONFIG_CMD} ${ifn} ${ifconfig_args}
 		return 0
 	fi
 
@@ -1217,7 +1604,7 @@
 	_if=$1
 	_ifs="^"
 	_ret=1
-	ipxList="`ifconfig ${_if} | grep 'ipx ' | tr "\n" "$_ifs"`"
+	ipxList="`${IFCONFIG_CMD} ${_if} | grep 'ipx ' | tr "\n" "$_ifs"`"
 	oldifs="$IFS"
 
 	IFS="$_ifs"
@@ -1228,7 +1615,7 @@
 		_ipx=`expr "$_ipx" : '.*\(ipx [0-9a-h]\{1,8\}H*\.[0-9a-h]\{1,12\}\).*'`
 
 		IFS="$oldifs"
-		ifconfig ${_if} ${_ipx} delete
+		${IFCONFIG_CMD} ${_if} ${_ipx} delete
 		IFS="$_ifs"
 		_ret=0
 	done
@@ -1237,8 +1624,8 @@
 	return $_ret
 }
 
-# ifnet_rename
-#	Rename all requested interfaces.
+# ifnet_rename [ifname]
+#	Rename interfaces if ifconfig_IF_name is defined.
 #
 ifnet_rename()
 {
@@ -1245,10 +1632,10 @@
 	local _if _ifname
 
 	# ifconfig_IF_name
-	for _if in `ifconfig -l`; do
+	for _if in ${*:-$(${IFCONFIG_CMD} -l)}; do
 		_ifname=`get_if_var $_if ifconfig_IF_name`
 		if [ ! -z "$_ifname" ]; then
-			ifconfig $_if name $_ifname
+			${IFCONFIG_CMD} $_if name $_ifname
 		fi
 	done
 
@@ -1280,7 +1667,7 @@
 	_tmplist=
 	case ${network_interfaces} in
 	[Aa][Uu][Tt][Oo])
-		_autolist="`ifconfig -l`"
+		_autolist="`${IFCONFIG_CMD} -l`"
 		_lo=
 		for _if in ${_autolist} ; do
 			if autoif $_if; then
@@ -1292,17 +1679,33 @@
 			fi
 		done
 		_tmplist="${_lo}${_tmplist# }"
-		;;
+	;;
 	*)
-		_tmplist="${network_interfaces} ${cloned_interfaces}"
-
+		for _if in ${network_interfaces} ${cloned_interfaces}; do
+			# epair(4) uses epair[0-9] for creation and
+			# epair[0-9][ab] for configuration.
+			case $_if in
+			epair[0-9]*)
+				_tmplist="$_tmplist ${_if}a ${_if}b"
+			;;
+			*)
+				_tmplist="$_tmplist $_if"
+			;;
+			esac
+		done
+		#
 		# lo0 is effectively mandatory, so help prevent foot-shooting
 		#
 		case "$_tmplist" in
-		lo0|'lo0 '*|*' lo0'|*' lo0 '*) ;; # This is fine, do nothing
-		*)	_tmplist="lo0 ${_tmplist}" ;;
+		lo0|'lo0 '*|*' lo0'|*' lo0 '*)
+			# This is fine, do nothing
+			_tmplist="${_tmplist# }"
+		;;
+		*)
+			_tmplist="lo0 ${_tmplist# }"
+		;;
 		esac
-		;;
+	;;
 	esac
 
 	_list=
@@ -1314,7 +1717,7 @@
 				_list="${_list# } ${_if}"
 			fi
 		done
-		;;
+	;;
 	dhcp)
 		for _if in ${_tmplist} ; do
 			if dhcpif $_if; then
@@ -1321,7 +1724,7 @@
 				_list="${_list# } ${_if}"
 			fi
 		done
-		;;
+	;;
 	noautoconf)
 		for _if in ${_tmplist} ; do
 			if ! ipv6_autoconfif $_if && \
@@ -1329,7 +1732,7 @@
 				_list="${_list# } ${_if}"
 			fi
 		done
-		;;
+	;;
 	autoconf)
 		for _if in ${_tmplist} ; do
 			if ipv6_autoconfif $_if; then
@@ -1336,10 +1739,10 @@
 				_list="${_list# } ${_if}"
 			fi
 		done
-		;;
+	;;
 	*)
 		_list=${_tmplist}
-		;;
+	;;
 	esac
 
 	echo $_list
@@ -1388,7 +1791,7 @@
 {
 	local media
 
-	case `ifconfig $1 2>/dev/null` in
+	case `${IFCONFIG_CMD} $1 2>/dev/null` in
 	*media:?Ethernet*) media=Ethernet ;;
 	esac
 
@@ -1400,25 +1803,27 @@
 #	If flag is defined, tentative ones will be excluded.
 network6_getladdr()
 {
-	local proto addr rest
-	ifconfig $1 2>/dev/null | while read proto addr rest; do
-		case ${proto} in
-		inet6)
-			case ${addr} in
-			fe80::*)
-				if [ -z "$2" ]; then
-					echo ${addr}
-					return
-				fi
-				case ${rest} in
-				*tentative*)
-					continue
-					;;
-				*)
-					echo ${addr}
-					return
-				esac
-			esac
+	local _if _flag proto addr rest
+	_if=$1
+	_flag=$2
+
+	${IFCONFIG_CMD} $_if 2>/dev/null | while read proto addr rest; do
+		case "${proto}/${addr}/${_flag}/${rest}" in
+		inet6/fe80::*//*)
+			echo ${addr}
+		;;
+		inet6/fe80:://*tentative*)	# w/o flag
+			sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
+			network6_getladdr $_if $_flags
+		;;
+		inet6/fe80::/*/*tentative*)	# w/ flag
+			echo ${addr}
+		;;
+		*)
+			continue
+		;;
 		esac
+
+		return
 	done
 }


Property changes on: trunk/etc/network.subr
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property


More information about the Midnightbsd-cvs mailing list