Date: Tue, 07 Feb 2012 23:24:17 +0900 (JST) From: Hiroki Sato <hrs@FreeBSD.org> To: erdgeist@erdgeist.org, se@FreeBSD.org Cc: freebsd-rc@FreeBSD.org Subject: Re: Proposal ipv6_addrs_common Message-ID: <20120207.232417.487789017555472392.hrs@allbsd.org> In-Reply-To: <20120207.170255.161251905285915806.hrs@allbsd.org> <4F3100C3.4040700@freebsd.org> References: <20120207.072925.1861639312875773760.hrs@allbsd.org> <4F3088C8.9090505@erdgeist.org> <20120207.170255.161251905285915806.hrs@allbsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
----Security_Multipart0(Tue_Feb__7_23_24_17_2012_986)-- Content-Type: Multipart/Mixed; boundary="--Next_Part(Tue_Feb__7_23_24_17_2012_022)--" Content-Transfer-Encoding: 7bit ----Next_Part(Tue_Feb__7_23_24_17_2012_022)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Dirk Engling <erdgeist@erdgeist.org> wrote in <4F3088C8.9090505@erdgeist.org>: er> You can just accept them as positional paramters in a function, and er> then shift them out one by one, matching inet and inet6, switching er> state and returning an expanded string to be executed by the caller. Stefan Esser <se@freebsd.org> wrote in <4F3100C3.4040700@freebsd.org>: se> Dirk Engling suggested to use white space as separator and to interpret se> "inet" and "inet6" as (optional) AF indicators. I like this idea a lot! se> se> You could omit inet/inet6 for all numeric addresses (any parameter with se> a colon is an IPv6 address) and just use inet/inet6 if an address is se> specified by name (e.g. a host name that can be resolved during system se> start and for which IPv4 and IPv6 addresses exist, e.g. in /etc/hosts). The attached patch is my first shot for this direction. This includes a new variable, $ifconfig_IF_aliases, but not includes the address range expansion yet. This is because I would like to get it reviewed first and go forward step-by-step. The goals are: - Keep backward compatibility. $ifconfig_IF_aliasN and $ipv6_ifconfig_IF_aliasN should work as before. - When an AF keyword is missing in ifconfig_IF_aliasN, try to recover by prepending "inet" automatically. Display a warning message only when adding an alias. - Remove duplicate code in network.subr as mush as possible. - Two bugfixes: return status of ifalias_up() and alias removal order in ipv4_down(). Configuration for testing is the following: ---- cloned_interfaces="tap0" ifconfig_tap0="up" ifconfig_tap0_alias0="10.9.1.1/24" ifconfig_tap0_alias1="10.9.2.1/24" ifconfig_tap0_alias3="10.9.3.1/24" ipv6_prefix_tap0="2001:db8:6666:2 2001:db8:7777:0" ipv6_ifconfig_tap0_alias0="2001:db8:7707:1::1 prefixlen 64" ipv6_ifconfig_tap0_alias1="2001:db8:7717:1:: prefixlen 64 eui64" ipv6_ifconfig_tap0_alias3="2001:db8:7737:1:: prefixlen 64 eui64" ifconfig_tap0_aliases="inet6 2001:db8:8888:2::1/64 inet6 2001:db8:9999:3::1/64 inet 10.8.1.1/24" ---- The results were: ---- hrs@dev1 % sudo /etc/rc.d/netif start tap0 /etc/rc.d/netif: WARNING: $ifconfig_tap0_alias0 needs "inet" keyword for an IPv4 address. /etc/rc.d/netif: WARNING: $ifconfig_tap0_alias1 needs "inet" keyword for an IPv4 address. /etc/rc.d/netif: WARNING: $ipv6_ifconfig_tap0_alias0 is obsolete. Use ifconfig_tap0_aliasN instead. /etc/rc.d/netif: WARNING: $ipv6_ifconfig_tap0_alias1 is obsolete. Use ifconfig_tap0_aliasN instead. Starting Network: tap0. tap0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=80000<LINKSTATE> ether 00:bd:bf:28:00:00 inet6 fe80::2bd:bfff:fe28:0%tap0 prefixlen 64 scopeid 0xb inet 10.8.1.1 netmask 0xffffff00 broadcast 10.8.1.255 inet 10.9.1.1 netmask 0xffffff00 broadcast 10.9.1.255 inet 10.9.2.1 netmask 0xffffff00 broadcast 10.9.2.255 inet6 2001:db8:8888:2::1 prefixlen 64 inet6 2001:db8:9999:3::1 prefixlen 64 inet6 2001:db8:7707:1::1 prefixlen 64 inet6 2001:db8:7717:1:2bd:bfff:fe28:0 prefixlen 64 inet6 2001:db8:6666:2:2bd:bfff:fe28:0 prefixlen 64 inet6 2001:db8:7777:0:2bd:bfff:fe28:0 prefixlen 64 nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL> hrs@dev1 % sudo /etc/rc.d/netif stop tap0 Stopping Network: tap0. tap0: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=80000<LINKSTATE> ether 00:bd:bf:28:00:00 nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL> ---- Comments are welcome. I am moving onto implementing address range expansion to this framework. -- Hiroki ----Next_Part(Tue_Feb__7_23_24_17_2012_022)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="network.subr.20120207-1.diff" Index: etc/network.subr =================================================================== --- etc/network.subr (revision 231128) +++ etc/network.subr (working copy) @@ -553,7 +553,7 @@ ifconfig ${_if} inet 127.0.0.1/8 alias fi fi - ifalias_up ${_if} inet && _ret=0 + ifalias ${_if} inet alias && _ret=0 ipv4_addrs_common ${_if} alias && _ret=0 return $_ret @@ -571,7 +571,7 @@ return 0 fi - ifalias_up ${_if} inet6 && _ret=0 + ifalias ${_if} inet6 alias && _ret=0 ipv6_prefix_hostid_addr_common ${_if} alias && _ret=0 ipv6_accept_rtadv_up ${_if} && _ret=0 @@ -587,6 +587,9 @@ _ifs="^" _ret=1 + ifalias ${_if} inet -alias && _ret=0 + ipv4_addrs_common ${_if} -alias && _ret=0 + inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`" oldifs="$IFS" @@ -604,9 +607,6 @@ done IFS="$oldifs" - ifalias_down ${_if} inet && _ret=0 - ipv4_addrs_common ${_if} -alias && _ret=0 - return $_ret } @@ -625,7 +625,7 @@ ipv6_accept_rtadv_down ${_if} && _ret=0 ipv6_prefix_hostid_addr_common ${_if} -alias && _ret=0 - ifalias_down ${_if} inet6 && _ret=0 + ifalias ${_if} inet6 -alias && _ret=0 inetList="`ifconfig ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`" @@ -690,191 +690,101 @@ return $_ret } -# ifalias_up if af -# Configure aliases for network interface $if. +# ifalias if af action +# Configure or remove aliases for network interface $if. # It returns 0 if at least one alias was configured or -# 1 if there were none. +# removed, or 1 if there were none. # -ifalias_up() +ifalias() { local _ret _ret=1 + afexists $2 || return $_ret + case "$2" in - inet) - _ret=`ifalias_ipv4_up "$1"` + inet|inet6) + ifalias_af_common $1 $2 $3 && _ret=0 ;; - inet6) - _ret=`ifalias_ipv6_up "$1"` - ;; esac return $_ret } -# ifalias_ipv4_up if -# Helper function for ifalias_up(). Handles IPv4. +# ifalias_af_common if af action +# Helper function for ifalias(). # -ifalias_ipv4_up() +ifalias_af_common() { - local _ret alias ifconfig_args + local _ret alias ifconfig_args _aliasn _L _tmpargs _if _af _action _ret=1 + _aliasn= + _if=$1 + _af=$2 + _action=$3 - # ifconfig_IF_aliasN which starts with "inet" + # ifconfig_IF_aliasN which starts with ${_af} alias=0 while : ; do - ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - inet\ *) - ifconfig $1 ${ifconfig_args} alias && _ret=0 + ifconfig_args=`get_if_var ${_if} ifconfig_IF_alias${alias}` + case ${_af}:${_action}:"${ifconfig_args}" in + ${_af}:*:${_af}\ *) + _aliasn="${_aliasn} ${ifconfig_args}" ;; - inet6\ *) - ;; - "") + ${_af}:*:"") break ;; - *) - warn "\$ifconfig_$1_alias${alias} needs " \ + inet:alias:*) + _aliasn="${_aliasn} inet ${ifconfig_args}" + warn "\$ifconfig_${_if}_alias${alias} needs " \ "\"inet\" keyword for an IPv4 address." - ifconfig $1 ${ifconfig_args} alias && _ret=0 - ;; esac alias=$((${alias} + 1)) done - return $_ret -} - -# ifalias_ipv6_up if -# Helper function for ifalias_up(). Handles IPv6. -# -ifalias_ipv6_up() -{ - local _ret alias ifconfig_args - _ret=1 - - # ifconfig_IF_aliasN which starts with "inet6" - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - inet6\ *) - ifconfig $1 ${ifconfig_args} alias && _ret=0 - ;; - "") - break - ;; - esac - alias=$((${alias} + 1)) - done - # backward compatibility: ipv6_ifconfig_IF_aliasN. - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - "") - break + case ${_af} in + inet6) + alias=0 + while : ; do + ifconfig_args=`get_if_var ${_if} ipv6_ifconfig_IF_alias${alias}` + case ${_action}:"${ifconfig_args}" in + *:"") + break ;; - *) - ifconfig $1 inet6 ${ifconfig_args} alias && _ret=0 - warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \ - " Use ifconfig_$1_aliasN instead." + alias:*) + _aliasn="${_aliasn} inet6 ${ifconfig_args}" + warn "\$ipv6_ifconfig_${_if}_alias${alias} " \ + "is obsolete. Use ifconfig_$1_aliasN " \ + "instead." ;; - esac - alias=$((${alias} + 1)) - done - - return $_ret -} - -# ifalias_down if af -# Remove aliases for network interface $if. -# It returns 0 if at least one alias was removed or -# 1 if there were none. -# -ifalias_down() -{ - local _ret - _ret=1 - - case "$2" in - inet) - _ret=`ifalias_ipv4_down "$1"` - ;; - inet6) - _ret=`ifalias_ipv6_down "$1"` - ;; + esac + alias=$((${alias} + 1)) + done esac - return $_ret -} - -# ifalias_ipv4_down if -# Helper function for ifalias_down(). Handles IPv4. -# -ifalias_ipv4_down() -{ - local _ret alias ifconfig_args - _ret=1 - - # ifconfig_IF_aliasN which starts with "inet" - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - inet\ *) - ifconfig $1 ${ifconfig_args} -alias && _ret=0 + # Handle both ifconfig_IF_aliases and ifconfig_IF_aliasN + _tmpargs= + for _L in `get_if_var ${_if} ifconfig_IF_aliases` ${_aliasn}; do + case ${_L} in + inet|inet6|ipx) + case ${_tmpargs} in + ${_af}\ *) + eval ifconfig $1 ${_tmpargs} ${_action} && _ret=0 ;; - "") - break - ;; - esac - alias=$((${alias} + 1)) - done - - return $_ret -} - -# ifalias_ipv6_down if -# Helper function for ifalias_down(). Handles IPv6. -# -ifalias_ipv6_down() -{ - local _ret alias ifconfig_args - _ret=1 - - # ifconfig_IF_aliasN which starts with "inet6" - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - inet6\ *) - ifconfig $1 ${ifconfig_args} -alias && _ret=0 - ;; - "") - break - ;; - esac - alias=$((${alias} + 1)) - done - - # backward compatibility: ipv6_ifconfig_IF_aliasN. - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - "") - break - ;; + esac + _tmpargs=${_L} + ;; *) - ifconfig $1 inet6 ${ifconfig_args} -alias && _ret=0 - warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \ - " Use ifconfig_$1_aliasN instead." - ;; + _tmpargs="${_tmpargs} ${_L}" esac - alias=$((${alias} + 1)) done + # ifconfig_IF_aliases: last component + case ${_tmpargs} in + ${_af}\ *) + eval ifconfig $1 ${_tmpargs} ${_action} && _ret=0 + ;; + esac return $_ret } ----Next_Part(Tue_Feb__7_23_24_17_2012_022)---- ----Security_Multipart0(Tue_Feb__7_23_24_17_2012_986)-- Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEABECAAYFAk8xNBEACgkQTyzT2CeTzy1+ZACgr4Q/qKXH8LdEx6VzU+mhwkxR TqcAoJQDShk40wFz/vX21FUBbsjqS+OZ =7xWP -----END PGP SIGNATURE----- ----Security_Multipart0(Tue_Feb__7_23_24_17_2012_986)----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120207.232417.487789017555472392.hrs>