Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Dec 2013 04:24:02 +0000
From:      "Teske, Devin" <Devin.Teske@fisglobal.com>
To:        "<jhellenthal@dataix.net>" <jhellenthal@dataix.net>
Cc:        "rc@freebsd.org" <rc@freebsd.org>, Devin Teske <dteske@freebsd.org>, "net@freebsd.org" <net@freebsd.org>
Subject:   Re: network.subr _aliasN handling
Message-ID:  <A7699871-A170-4AD5-B740-ED8BE17C7107@fisglobal.com>
In-Reply-To: <20131228055324.GA72764@aim7400.DataIX.local>
References:  <20131228055324.GA72764@aim7400.DataIX.local>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]

On Dec 27, 2013, at 9:53 PM, <jhellenthal@dataix.net> wrote:

> Curious what everyone's opinion would be on modifying the handling of _aliasN functions or providing a wrapper around it to handle non-sequential ordering.
> 
> My goal on this is simple and based around groupings similiar to that of the way user id(1)'s in passwd and group are handled or denoted for use on modern systems.
> 
> I.e.: I would like to achieve this...
> 
> *_alias[1-99] = System type addresses "Importand addresses or internal"
> *_alias[100-199] = Aliases for interface 1
> *_alias[200-299] = Aliases for interface 2
> etc...
> 
> NOt looking to achieve some sort of prefered naming convention for the interface aliases, but loosen them so they may be defined by the user in whatever means neccesary to their benefit.
> 
> In a scheme similiar to above I attempted to set an address on every other 4th alias leaving 3 space rule room for insertion of further addresses but was surprised when the processing of the aliases ceased at the first non-sequential space.
> 
> So why not just grab every _aliasN no matter of what it is for the interface and shove them into an arrary to be processed by a "for" statement ? the order would still be kept without having to inspect every defintion of alias and incrementing prehistorically.
> 
> As well this could provide early loading of the addresses into their respective arrays so they may be processed and provided to any other functions that may need to access them earlier on in script fallthrough.
> 
> Looking at _alias'N' sequentialy feels like a neucense.

You mean something like the attached?
-- 
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.

[-- Attachment #2 --]
Index: etc/network.subr
===================================================================
--- etc/network.subr	(revision 255712)
+++ etc/network.subr	(working copy)
@@ -1027,9 +1027,8 @@ ifalias_af_common()
 	_action=$3
 
 	# ifconfig_IF_aliasN which starts with $_af
-	alias=0
-	while : ; do
-		ifconfig_args=`get_if_var $_if ifconfig_IF_alias${alias}`
+	for alias in `list_vars ifconfig_${_if}_alias[0-9]\*`; do
+		eval ifconfig_args=\"\$$alias\"
 		_iaf=
 		case $ifconfig_args in
 		inet\ *)	_iaf=inet ;;
@@ -1051,15 +1050,13 @@ ifalias_af_common()
 			warn "\$ifconfig_${_if}_alias${alias} needs " \
 			    "\"inet\" keyword for an IPv4 address."
 		esac
-		alias=$(($alias + 1))
 	done
 
 	# backward compatibility: ipv6_ifconfig_IF_aliasN.
 	case $_af in
 	inet6)
-		alias=0
-		while : ; do
-			ifconfig_args=`get_if_var $_if ipv6_ifconfig_IF_alias${alias}`
+		for alias in `list_vars ipv6_ifconfig_${_if}_alias[0-9]\*`; do
+			eval ifconfig_args=\"\$$alias\"
 			case ${_action}:"${ifconfig_args}" in
 			*:"")
 				break
@@ -1071,7 +1068,6 @@ ifalias_af_common()
 				    "instead."
 			;;
 			esac
-			alias=$(($alias + 1))
 		done
 	esac
 
Index: etc/rc.subr
===================================================================
--- etc/rc.subr	(revision 255712)
+++ etc/rc.subr	(working copy)
@@ -54,6 +54,20 @@ JID=`$PS -p $$ -o jid=`
 #	functions
 #	---------
 
+# list_vars pattern
+#	List vars matching pattern.
+# 
+list_vars()
+{
+	set | { while read LINE; do
+		var="${LINE%%=*}"
+		case "$var" in
+		"$LINE"|*[!a-zA-Z0-9_]*) continue ;;
+		$1) echo $var
+		esac
+	done; }
+}
+
 # set_rcvar_obsolete oldvar [newvar] [msg]
 #	Define obsolete variable.
 #	Global variable $rcvars_obsolete is used.

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A7699871-A170-4AD5-B740-ED8BE17C7107>