From owner-freebsd-current@FreeBSD.ORG Mon Jul 22 14:38:07 2013 Return-Path: Delivered-To: current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 7838CDB5; Mon, 22 Jul 2013 14:38:07 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from mail.allbsd.org (gatekeeper.allbsd.org [IPv6:2001:2f0:104:e001::32]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AE94D223D; Mon, 22 Jul 2013 14:38:06 +0000 (UTC) Received: from alph.d.allbsd.org (p2049-ipbf1102funabasi.chiba.ocn.ne.jp [122.26.101.49]) (authenticated bits=128) by mail.allbsd.org (8.14.5/8.14.5) with ESMTP id r6MEbmN1014935 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 22 Jul 2013 23:37:59 +0900 (JST) (envelope-from hrs@FreeBSD.org) Received: from localhost (localhost [IPv6:::1]) (authenticated bits=0) by alph.d.allbsd.org (8.14.5/8.14.5) with ESMTP id r6MEbl1T030354; Mon, 22 Jul 2013 23:37:48 +0900 (JST) (envelope-from hrs@FreeBSD.org) Date: Mon, 22 Jul 2013 23:37:04 +0900 (JST) Message-Id: <20130722.233704.43939809189059350.hrs@allbsd.org> To: current@FreeBSD.org, freebsd-rc@FreeBSD.org Subject: Re: CFT: cloned_interfaces and gifconfig in rc.d/netif From: Hiroki Sato In-Reply-To: <20130722.024513.95685108976349294.hrs@allbsd.org> References: <20130722.024513.95685108976349294.hrs@allbsd.org> X-PGPkey-fingerprint: BDB3 443F A5DD B3D0 A530 FFD7 4F2C D3D8 2793 CF2D X-Mailer: Mew version 6.5 on Emacs 24.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Multipart/Signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="--Security_Multipart0(Mon_Jul_22_23_37_04_2013_579)--" Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.97.4 at gatekeeper.allbsd.org X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (mail.allbsd.org [133.31.130.32]); Mon, 22 Jul 2013 23:37:59 +0900 (JST) X-Spam-Status: No, score=-90.4 required=13.0 tests=CONTENT_TYPE_PRESENT, DIRECTOCNDYN,DYN_PBL,QENCPTR2,RCVD_IN_PBL,SPF_SOFTFAIL,USER_IN_WHITELIST autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on gatekeeper.allbsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: freebsd-rc@FreeBSD.org List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Jul 2013 14:38:07 -0000 ----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 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)----