From owner-freebsd-rc@FreeBSD.ORG Thu Feb 27 17:04:34 2014 Return-Path: Delivered-To: rc@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 054B78F0; Thu, 27 Feb 2014 17:04:34 +0000 (UTC) Received: from mx1.fisglobal.com (mx1.fisglobal.com [199.200.24.190]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BF01F1C6F; Thu, 27 Feb 2014 17:04:33 +0000 (UTC) Received: from smarthost.fisglobal.com ([10.132.206.192]) by ltcfislmsgpa03.fnfis.com (8.14.5/8.14.5) with ESMTP id s1RH4L3Z012594 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Thu, 27 Feb 2014 11:04:21 -0600 Received: from THEMADHATTER (10.242.181.54) by smarthost.fisglobal.com (10.132.206.192) with Microsoft SMTP Server id 14.3.174.1; Thu, 27 Feb 2014 11:04:18 -0600 From: Sender: Devin Teske To: "'Hiroki Sato'" References: <11c101cf2f6b$e3aee5d0$ab0cb170$@FreeBSD.org> <20140222.141935.520275210006153242.hrs@allbsd.org> <122101cf2f94$bfd81b30$3f885190$@FreeBSD.org> <20140224.125955.1719844232391066.hrs@allbsd.org> In-Reply-To: <20140224.125955.1719844232391066.hrs@allbsd.org> Subject: RE: network.subr _aliasN handling Date: Thu, 27 Feb 2014 09:04:16 -0800 Message-ID: <156001cf33dd$f3b5a330$db20e990$@FreeBSD.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_1561_01CF339A.E592D860" X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQHttkVtKbJQZ7hszActUMJnbew5kAHwlHOYAhb5coEB8/98xZpXwQnQ Content-Language: en-us X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.11.87, 1.0.14, 0.0.0000 definitions=2014-02-27_06:2014-02-27,2014-02-27,1970-01-01 signatures=0 Cc: jhellenthal@dataix.net, rc@FreeBSD.org, dteske@FreeBSD.org X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Feb 2014 17:04:34 -0000 ------=_NextPart_000_1561_01CF339A.E592D860 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit > -----Original Message----- > From: Hiroki Sato [mailto:hrs@FreeBSD.org] > Sent: Sunday, February 23, 2014 8:00 PM > To: dteske@FreeBSD.org > Cc: jhellenthal@dataix.net; lists@jnielsen.net; rc@FreeBSD.org > Subject: Re: network.subr _aliasN handling > > wrote > in <122101cf2f94$bfd81b30$3f885190$@FreeBSD.org>: > > dt> > +list_vars() > dt> > +{ > dt> > + set | { while read LINE; do > dt> > + var="${LINE%%=*}" > dt> > + case "$var" in > dt> > + "$LINE"|*[!a-zA-Z0-9_]*) continue ;; > dt> > + $1) echo $var > dt> > + esac > dt> > + done; } > dt> > +} > dt> > > dt> > This can be inconsistent with normalization of $_if in get_if_var() when > dt> [.-/+] > dt> > is included. > dt> > > dt> [Devin Teske] > dt> > dt> I'm not sure what you mean by "when [.-/+] is included". The line of code > > get_if_var() normalizes IF part in the variable name before eval: > > | _if=$1 > | _punct=". - / +" > | for _punct_c in $_punct; do > | _if=`ltr ${_if} ${_punct_c} '_'` > | done > > while list_vars ifconfig_${_if}_alias[0-9]\* does not. > > I think this breaks the following configuration, for example: > > ifconfig_bge0_name="ext.1" > ifconfig_ext_1="inet 192.168.0.1/24" > ifconfig_ext_1_alias0="inet 192.168.1.1/24" > Thanks! Didn't know about that feature. I've attached an updated patch for review which takes this normalization into account (and does it more efficiently than the get_if_var function). NB: Calling "ltr" in a sub-shell to catch the output on stdout just to assign back to the original string is an unnecessary use of sub-shells. See attached patch for a recipe that doesn't fork or use sub-shells to replace the _punct characters in $_if with the underscore `_' (thus sanitizing the name before extending it to list_vars as a pattern (containing glob(7) characters). -- Devin _____________ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. ------=_NextPart_000_1561_01CF339A.E592D860 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch.txt" Index: etc/network.subr=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= --- etc/network.subr (revision 255712)=0A= +++ etc/network.subr (working copy)=0A= @@ -1019,6 +1019,7 @@ ifalias_af_common_handler()=0A= ifalias_af_common()=0A= {=0A= local _ret _if _af _action alias ifconfig_args _aliasn _c _tmpargs _iaf=0A= + local _punct=3D".-/+"=0A= =0A= _ret=3D1=0A= _aliasn=3D=0A= @@ -1026,10 +1027,16 @@ ifalias_af_common()=0A= _af=3D$2=0A= _action=3D$3=0A= =0A= + # Normalize $_if before using it in a pattern to list_vars()=0A= + while case "$_if" in *[$_punct]*) true;; *) false; esac; do=0A= + _if=3D"${_if%%[$_punct]*}_${_if#*[$_punct]}"=0A= + done=0A= +=0A= # ifconfig_IF_aliasN which starts with $_af=0A= - alias=3D0=0A= - while : ; do=0A= - ifconfig_args=3D`get_if_var $_if ifconfig_IF_alias${alias}`=0A= + for alias in `list_vars ifconfig_${_if}_alias[0-9]\* |=0A= + sort -nk1.$((9+${#_if}+7))`=0A= + do=0A= + eval ifconfig_args=3D\"\$$alias\"=0A= _iaf=3D=0A= case $ifconfig_args in=0A= inet\ *) _iaf=3Dinet ;;=0A= @@ -1051,15 +1058,15 @@ ifalias_af_common()=0A= warn "\$ifconfig_${_if}_alias${alias} needs " \=0A= "\"inet\" keyword for an IPv4 address."=0A= esac=0A= - alias=3D$(($alias + 1))=0A= done=0A= =0A= # backward compatibility: ipv6_ifconfig_IF_aliasN.=0A= case $_af in=0A= inet6)=0A= - alias=3D0=0A= - while : ; do=0A= - ifconfig_args=3D`get_if_var $_if ipv6_ifconfig_IF_alias${alias}`=0A= + for alias in `list_vars ipv6_ifconfig_${_if}_alias[0-9]\* |=0A= + sort -nk1.$((14+${#_if}+7))`=0A= + do=0A= + eval ifconfig_args=3D\"\$$alias\"=0A= case ${_action}:"${ifconfig_args}" in=0A= *:"")=0A= break=0A= @@ -1071,7 +1078,6 @@ ifalias_af_common()=0A= "instead."=0A= ;;=0A= esac=0A= - alias=3D$(($alias + 1))=0A= done=0A= esac=0A= =0A= Index: etc/rc.subr=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= --- etc/rc.subr (revision 255712)=0A= +++ etc/rc.subr (working copy)=0A= @@ -54,6 +54,20 @@ JID=3D`$PS -p $$ -o jid=3D`=0A= # functions=0A= # ---------=0A= =0A= +# list_vars pattern=0A= +# List vars matching pattern.=0A= +# =0A= +list_vars()=0A= +{=0A= + set | { while read LINE; do=0A= + var=3D"${LINE%%=3D*}"=0A= + case "$var" in=0A= + "$LINE"|*[!a-zA-Z0-9_]*) continue ;;=0A= + $1) echo $var=0A= + esac=0A= + done; }=0A= +}=0A= +=0A= # set_rcvar_obsolete oldvar [newvar] [msg]=0A= # Define obsolete variable.=0A= # Global variable $rcvars_obsolete is used.=0A= ------=_NextPart_000_1561_01CF339A.E592D860--