Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Feb 2014 17:17:42 -0800
From:      <dteske@FreeBSD.org>
To:        "'John Nielsen'" <lists@jnielsen.net>
Cc:        'Jason Hellenthal' <jhellenthal@dataix.net>, rc@freebsd.org, 'Devin Teske' <dteske@freebsd.org>
Subject:   RE: network.subr _aliasN handling
Message-ID:  <11c101cf2f6b$e3aee5d0$ab0cb170$@FreeBSD.org>
In-Reply-To: <7EAEF3AC-DB1B-4D3E-A156-E1E76B765990@jnielsen.net>
References:  <20131228055324.GA72764@aim7400.DataIX.local> <A7699871-A170-4AD5-B740-ED8BE17C7107@fisglobal.com> <9498BE8E-8090-4E7A-8317-18D29B1DDC08@dataix.net> <7DBA7D58-E925-47BC-967C-F653348426A6@fisglobal.com> <A15FAFBD-4597-4D8D-A014-0D486573894C@dataix.net> <AFFFCC9A-8C21-4C0B-A8D9-457E4C26DDA3@fisglobal.com> <7EAEF3AC-DB1B-4D3E-A156-E1E76B765990@jnielsen.net>

next in thread | previous in thread | raw e-mail | index | archive | help
------=_NextPart_000_11C2_01CF2F28.D58BA5D0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit



> -----Original Message-----
> From: John Nielsen [mailto:lists@jnielsen.net]
> Sent: Friday, February 21, 2014 9:06 AM
> To: Devin Teske
> Cc: Jason Hellenthal; rc@freebsd.org; net@freebsd.org
> Subject: Re: network.subr _aliasN handling
> 
> On Jan 4, 2014, at 4:25 AM, Teske, Devin <Devin.Teske@fisglobal.com>
wrote:
> 
> > On Jan 4, 2014, at 2:59 AM, Jason Hellenthal wrote:
> >
> >> I believe I know what you mean by that but in a way scares me when
you say
> sort as in mixing up the original order they appear in which I would
find to be
> really unattractive to most.
> >
> > It's not as scary as it sounds.
> >
> > The issue is that the variables are sorted alphabetically, instead of
> > numerically.
> >
> > Let's take four words: foo1, foo2, foo10, and foo20.
> > If you sort them alphabetically, you get:
> >
> > 	foo1
> > 	foo10
> > 	foo2
> > 	foo20
> >
> > You'll notice this when doing a directory listing, as that too is
> > sorted alphabetically.
> >
> > This is why "alias14" is run before "alias8" and "alias9". Because
> > they are processed in alphabetically sorted order. I didn't do
> > anything to sort the values, they came pre-sorted in alphabetic order.
> >
> > If I simply throw in a "| sort -n", then it will change it to
numerically sorted.
> > As you might expect, numerically sorting the above list would result
in:
> >
> > 	foo1
> > 	foo2
> > 	foo10
> > 	foo20
> >
> > Trivial really. I'll throw a patch at you when I get some cycles
(soon).
> 
> Hi Devin, Jason-
> 
> I've been behind on my mailing list e-mail for a while, but I really
like the idea
> and the patch proposed here. I don't see anything like it in head yet,
so ... Ping?
> :)
> 
> JN
> 
[Devin Teske] 

*** this time with attached patch.txt ***

Hi JN, here's a new patch that incorporates numerical sorting as well as
what
the original patch set out to do ... make "gaps" possible (so that you
could
comment out an alias without having to renumber all the ones following).

Give it a look, let me know what you think.
-- 
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_11C2_01CF2F28.D58BA5D0
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=
@@ -1027,9 +1027,10 @@ ifalias_af_common()=0A=
 	_action=3D$3=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 +1052,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 +1072,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_11C2_01CF2F28.D58BA5D0--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?11c101cf2f6b$e3aee5d0$ab0cb170$>