Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Jul 2013 02:45:13 +0900 (JST)
From:      Hiroki Sato <hrs@FreeBSD.org>
To:        current@FreeBSD.org, freebsd-rc@FreeBSD.org
Subject:   CFT: cloned_interfaces and gifconfig in rc.d/netif
Message-ID:  <20130722.024513.95685108976349294.hrs@allbsd.org>

next in thread | raw e-mail | index | archive | help
----Security_Multipart0(Mon_Jul_22_02_45_13_2013_666)--
Content-Type: Multipart/Mixed;
 boundary="--Next_Part(Mon_Jul_22_02_45_13_2013_191)--"
Content-Transfer-Encoding: 7bit

----Next_Part(Mon_Jul_22_02_45_13_2013_191)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

 The attached patch allows rc.d/netif to create IFs in
 $cloned_interfaces when interface name(s) is specified.  For example,
 when the following lines are in rc.conf:

  cloned_interfaces="bridge0 bridge1"
  ifconfig_bridge0="..."
  ifconfig_bridge1="..."

 The following commands create the interfaces and destroy them.

  # /etc/rc.d/netif start bridge0 bridge1
  # /etc/rc.d/netif stop bridge0 bridge1

 netif cloneup/clonedown does this without the patch, but it cannot
 configure the interfaces and does not support clean teardown.

 Also, routines which handle $gif_interfaces are merged into ones for
 $cloned_interfaces.  ifconfig_gifN and other variants did not work
 with gif interfaces defined in $gif_interfaces.  The patch solves
 this issue.

 Basically there should be no functionality regression for the
 existing configurations.  Can anyone who are using $gif_interfaces
 and/or $cloned_interfaces test this?  I would like to know if there is
 regression or not.

-- Hiroki

----Next_Part(Mon_Jul_22_02_45_13_2013_191)--
Content-Type: Text/X-Patch; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="network.subr.gifconfig.20130722-1.diff"

Index: etc/network.subr
===================================================================
--- etc/network.subr	(revision 253520)
+++ etc/network.subr	(working copy)
@@ -660,6 +660,11 @@
 	IFS="$_ifs"
 	for _inet in $inetList ; do
 		# get rid of extraneous line
+		case $_inet in
+		"")		break ;;
+		inet\ *)	;;
+		*)		continue ;;
+		esac
 		[ -z "$_inet" ] && break

 		_inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'`
@@ -1192,12 +1197,17 @@
 #
 clone_up()
 {
-	local _prefix _list ifn
+	local _prefix _list ifn _iflist _n tmpargs
 	_prefix=
 	_list=
+	_iflist=$*

 	# create_args_IF
 	for ifn in ${cloned_interfaces}; do
+		case $_iflist in
+		""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn)	;;
+		*)	continue ;;
+		esac
 		${IFCONFIG_CMD} ${ifn} create `get_if_var ${ifn} create_args_IF`
 		if [ $? -eq 0 ]; then
 			_list="${_list}${_prefix}${ifn}"
@@ -1204,6 +1214,30 @@
 			[ -z "$_prefix" ] && _prefix=' '
 		fi
 	done
+	if [ -n "$gif_interfaces" ]; then
+		warn "\$gif_interfaces is obsolete.  Use \$cloned_interfaces instead."
+	fi
+	for ifn in ${gif_interfaces}; do
+		case $_iflist in
+		""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn)	;;
+		*)	continue ;;
+		esac
+		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=' '
+		fi
+		tmpargs=$(get_if_var $ifn gifconfig_IF)
+		eval ifconfig_${ifn}=\"tunnel \$tmpargs\"
+	done
 	debug "Cloned: ${_list}"
 }

@@ -1213,11 +1247,16 @@
 #
 clone_down()
 {
-	local _prefix _list ifn
+	local _prefix _list ifn _iflist
 	_prefix=
 	_list=
+	_iflist=$*

-	for ifn in ${cloned_interfaces}; do
+	for ifn in ${cloned_interfaces} ${gif_interfaces}; do
+		case $_iflist in
+		""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn)	;;
+		*)	continue ;;
+		esac
 		${IFCONFIG_CMD} -n ${ifn} destroy
 		if [ $? -eq 0 ]; then
 			_list="${_list}${_prefix}${ifn}"
@@ -1224,6 +1263,9 @@
 			[ -z "$_prefix" ] && _prefix=' '
 		fi
 	done
+	if [ -n "${_list}" ]; then
+		echo "Destroyed clone interfaces: ${_list}."
+	fi
 	debug "Destroyed clones: ${_list}"
 }

@@ -1347,32 +1389,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_CMD} $i create >/dev/null 2>&1
-			else
-				gif=`${IFCONFIG_CMD} gif create`
-				${IFCONFIG_CMD} $gif name $i
-			fi
-			${IFCONFIG_CMD} $i tunnel ${peers}
-			${IFCONFIG_CMD} $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.
Index: etc/rc.d/netif
===================================================================
--- etc/rc.d/netif	(revision 253505)
+++ etc/rc.d/netif	(working copy)
@@ -60,18 +60,15 @@
 		# disable SIGINT (Ctrl-c) when running at startup
 		trap : 2

-		# Create cloned interfaces
-		clone_up
-
 		# Create Fast EtherChannel interfaces
 		fec_up
+	fi

-		# Create IPv6<-->IPv4 tunnels
-		gif_up
+	# Create cloned interfaces
+	clone_up $cmdifn

-		# Rename interfaces.
-		ifnet_rename
-	fi
+	# Rename interfaces.
+	ifnet_rename $cmdifn

 	# Configure the interface(s).
 	network_common ifn_start
@@ -101,6 +98,9 @@
 	# Deconfigure the interface(s)
 	network_common ifn_stop

+	# Destroy cloned interfaces
+	clone_down $cmdifn
+
 	if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
 		for _if in $cmdifn; do
 			/etc/rc.d/routing stop any $_if

----Next_Part(Mon_Jul_22_02_45_13_2013_191)----

----Security_Multipart0(Mon_Jul_22_02_45_13_2013_666)--
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (FreeBSD)

iEYEABECAAYFAlHsHikACgkQTyzT2CeTzy0BogCdE5YAjK6IoMYAGLRNQtJb85kO
uusAoIAK/yibxY5FiY3h67CIL1oXaOjB
=uK+4
-----END PGP SIGNATURE-----

----Security_Multipart0(Mon_Jul_22_02_45_13_2013_666)----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130722.024513.95685108976349294.hrs>