Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Feb 2014 09:04:16 -0800
From:      <dteske@FreeBSD.org>
To:        "'Hiroki Sato'" <hrs@FreeBSD.org>
Cc:        jhellenthal@dataix.net, rc@FreeBSD.org, dteske@FreeBSD.org
Subject:   RE: network.subr _aliasN handling
Message-ID:  <156001cf33dd$f3b5a330$db20e990$@FreeBSD.org>
In-Reply-To: <20140224.125955.1719844232391066.hrs@allbsd.org>
References:  <11c101cf2f6b$e3aee5d0$ab0cb170$@FreeBSD.org>	<20140222.141935.520275210006153242.hrs@allbsd.org>	<122101cf2f94$bfd81b30$3f885190$@FreeBSD.org> <20140224.125955.1719844232391066.hrs@allbsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
------=_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
> 
> <dteske@FreeBSD.org> 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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?156001cf33dd$f3b5a330$db20e990$>