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

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

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

Hiroki Sato <hrs@freebsd.org> wrote
  in <20130722.024513.95685108976349294.hrs@allbsd.org>:

hr> Hi,
hr>
hr>  The attached patch allows rc.d/netif to create IFs in
hr>  $cloned_interfaces when interface name(s) is specified.  For example,
hr>  when the following lines are in rc.conf:
hr>
hr>   cloned_interfaces="bridge0 bridge1"
hr>   ifconfig_bridge0="..."
hr>   ifconfig_bridge1="..."
hr>
hr>  The following commands create the interfaces and destroy them.
hr>
hr>   # /etc/rc.d/netif start bridge0 bridge1
hr>   # /etc/rc.d/netif stop bridge0 bridge1
hr>
hr>  netif cloneup/clonedown does this without the patch, but it cannot
hr>  configure the interfaces and does not support clean teardown.
hr>
hr>  Also, routines which handle $gif_interfaces are merged into ones for
hr>  $cloned_interfaces.  ifconfig_gifN and other variants did not work
hr>  with gif interfaces defined in $gif_interfaces.  The patch solves
hr>  this issue.
hr>
hr>  Basically there should be no functionality regression for the
hr>  existing configurations.  Can anyone who are using $gif_interfaces
hr>  and/or $cloned_interfaces test this?  I would like to know if there is
hr>  regression or not.

 A revised version based on feedback which I received in private
 emails is attached.  This includes rc.conf(5) change explaining the
 new variables.  The following is a brief description of the changes:

-----
- Reimplement gif_interfaces as a variant of $cloned_interfaces.
  Newly-configured systems should use $cloned_interfaces.

- Call clone_{up,down}() in rc.d/netif {start,stop}.

- Add rc.d/netif clear.  The "clear" argument is basically equivalent to
  "stop" but it does not call clone_down().

- Add "ifname:sticky" keyword into $cloned_interfaces.  If :sticky is
  specified, the interface will not be destroyed in rc.d/netif stop.

- Add cloned_interfaces_sticky={YES,NO}.  This variable globally sets
  :sticky keyword above for all interfaces.  The default value is NO.
----

-- Hiroki

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

- Reimplement gif_interfaces as a variant of $cloned_interfaces.
  Newly-configured systems should use $cloned_interfaces.

- Call clone_{up,down}() in rc.d/netif {start,stop}.

- Add rc.d/netif clear.  The "clear" argument is basically equivalent to
  "stop" but it does not call clone_down().

- Add "ifname:sticky" keyword into $cloned_interfaces.  If :sticky is
  specified, the interface will not be destroyed in rc.d/netif stop.

- Add cloned_interfaces_sticky={YES,NO}.  This variable globally sets
  :sticky keyword above for all interfaces.  The default value is NO.

MFC after:      3 days
====
Index: etc/network.subr
===================================================================
--- etc/network.subr	(revision 253520)
+++ etc/network.subr	(working copy)
@@ -660,6 +660,11 @@ ipv4_down()
 	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,23 @@ ifscript_down()
 #
 clone_up()
 {
-	local _prefix _list ifn
+	local _prefix _list ifn ifopt _iflist _n tmpargs
 	_prefix=
 	_list=
+	_iflist=$*

 	# create_args_IF
 	for ifn in ${cloned_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
 		${IFCONFIG_CMD} ${ifn} create `get_if_var ${ifn} create_args_IF`
 		if [ $? -eq 0 ]; then
 			_list="${_list}${_prefix}${ifn}"
@@ -1204,6 +1220,39 @@ clone_up()
 			[ -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
+		# 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=' '
+		fi
+		tmpargs=$(get_if_var $ifn gifconfig_IF)
+		eval ifconfig_${ifn}=\"tunnel \$tmpargs\"
+	done
+	if [ -n "${_list}" ]; then
+		echo "Created clone interfaces: ${_list}."
+	fi
 	debug "Cloned: ${_list}"
 }

@@ -1213,11 +1262,29 @@ clone_up()
 #
 clone_down()
 {
-	local _prefix _list ifn
+	local _prefix _list ifn ifopt _iflist
 	_prefix=
 	_list=
+	_iflist=$*

-	for ifn in ${cloned_interfaces}; do
+	: ${cloned_interfaces_sticky:=NO}
+	if checkyesno cloned_interfaces_sticky; then
+		return 1
+	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 in
+		sticky)	continue ;;
+		esac
+		case $_iflist in
+		""|$ifn|$ifn\ *|*\ $ifn\ *|*\ $ifn)	;;
+		*)	continue ;;
+		esac
+		# 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}${_prefix}${ifn}"
@@ -1224,6 +1291,9 @@ clone_down()
 			[ -z "$_prefix" ] && _prefix=' '
 		fi
 	done
+	if [ -n "${_list}" ]; then
+		echo "Destroyed clone interfaces: ${_list}."
+	fi
 	debug "Destroyed clones: ${_list}"
 }

@@ -1347,32 +1417,6 @@ ng_create_one()
 	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)
@@ -38,7 +38,8 @@ start_cmd="network_start"
 stop_cmd="network_stop"
 cloneup_cmd="clone_up"
 clonedown_cmd="clone_down"
-extra_commands="cloneup clonedown"
+clear_cmd="clear"
+extra_commands="cloneup clonedown clear"
 cmdifn=

 set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
@@ -60,18 +61,15 @@ network_start()
 		# 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
@@ -92,6 +90,18 @@ network_start()

 network_stop()
 {
+	_clone_down=1
+	network_stop0 $*
+}
+
+clear()
+{
+	_clone_down=
+	network_stop0 $*
+}
+
+network_stop0()
+{
 	local _if

 	# Set the list of interfaces to work on.
@@ -101,6 +111,11 @@ network_stop()
 	# Deconfigure the interface(s)
 	network_common ifn_stop

+	# Destroy cloned interfaces
+	if [ -n "$_clone_down" ]; then
+		clone_down $cmdifn
+	fi
+
 	if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
 		for _if in $cmdifn; do
 			/etc/rc.d/routing stop any $_if
@@ -142,6 +157,16 @@ network_common()
 	_fail=
 	_ok=
 	for ifn in ${_cooked_list}; do
+		# Skip if ifn does not exist.
+		case $_func in
+		ifn_stop)
+			if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
+				warn "$ifn does not exist.  Skipped."
+				_fail="${_fail} ${ifn}"
+				continue
+			fi
+		;;
+		esac
 		if ${_func} ${ifn} $2; then
 			_ok="${_ok} ${ifn}"
 			if ipv6if ${ifn}; then
Index: share/man/man5/rc.conf.5
===================================================================
--- share/man/man5/rc.conf.5	(revision 253545)
+++ share/man/man5/rc.conf.5	(working copy)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd July 12, 2013
+.Dd July 22, 2013
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -1651,11 +1651,29 @@ Further cloning arguments may be passed to the
 command for each interface by setting the
 .Va create_args_ Ns Aq Ar interface
 variable.
+If an interface name is specified with
+.Dq :sticky
+keyword,
+the interface will not be destroyed even when
+.Pa rc.d/netif
+script is invoked with
+.Dq stop
+argument.
+This is useful when reconfiguring the interface without destroying it.
 Entries in
 .Va cloned_interfaces
 are automatically appended to
 .Va network_interfaces
 for configuration.
+.It Va cloned_interfaces_sticky
+.Pq Vt bool
+This variable is to globally enable functionality of
+.Dq :sticky
+keyword in
+.Va cloned_interfaces
+for all interfaces.
+The default value is
+.Dq NO .
 .It Va fec_interfaces
 .Pq Vt str
 Set to the list of
@@ -1685,6 +1703,8 @@ ifconfig_fec0="DHCP"
 .Ed
 .It Va gif_interfaces
 .Pq Vt str
+This variable is deprecated in favor of
+.Va cloned_interfaces .
 Set to the list of
 .Xr gif 4
 tunnel interfaces to configure on this host.

----Next_Part(Mon_Jul_22_23_37_04_2013_233)----

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

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

iEYEABECAAYFAlHtQ5AACgkQTyzT2CeTzy3AyQCg0dtCgRIbHAiH+qim8X50xTBJ
RNcAn0OBevMIpxXxjMi0ZXf66CAAwOkp
=nMwt
-----END PGP SIGNATURE-----

----Security_Multipart0(Mon_Jul_22_23_37_04_2013_579)----



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