From owner-freebsd-rc@FreeBSD.ORG Wed Feb 1 04:04:44 2012 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BFE811065672 for ; Wed, 1 Feb 2012 04:04:44 +0000 (UTC) (envelope-from erdgeist@erdgeist.org) Received: from elektropost.org (elektropost.org [217.13.206.130]) by mx1.freebsd.org (Postfix) with ESMTP id 176398FC18 for ; Wed, 1 Feb 2012 04:04:43 +0000 (UTC) Received: (qmail 48126 invoked from network); 1 Feb 2012 04:07:33 -0000 Received: from elektropost.org (HELO elektropost.org) (erdgeist@erdgeist.org) by elektropost.org with CAMELLIA256-SHA encrypted SMTP; 1 Feb 2012 04:07:33 -0000 Message-ID: <4F28B9D7.4010602@erdgeist.org> Date: Wed, 01 Feb 2012 05:04:39 +0100 From: Dirk Engling User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: freebsd-rc@freebsd.org X-Enigmail-Version: 1.3.4 Content-Type: multipart/mixed; boundary="------------040100090500080408060203" Subject: Proposal ipv6_addrs_common X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 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: Wed, 01 Feb 2012 04:04:44 -0000 This is a multi-part message in MIME format. --------------040100090500080408060203 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Dear FreeBSD rc team, echoing Philipp Wuensches great ipv4_addrs patch I'd like to contribute the corresponding patch for v6 addresses, as their config clobbers my rc.conf considerably. The attached network6.subr is a shell script demonstrating the ipv6_addrs_common function inside, for playing around one can use some of the values the supplied get_if_var dummy function returns. The function handles one single range but allows it in any parts of the ip address, so 2002:50ed:991c-991f:50ed:c401::/64 2002:50ed:991c:50ed:c401-c409:: are both valid and work as expected. It can also parse ranges in v6mapped v4 addresses, again anywhere, so configuring a router that listens on all subnets on address .1 is possible: ::ffff:192.168.2-16.1 I would have the function called in ifn_start and ifn_stop. Feedback is very welcome. Thank you for your attention. erdgeist P.S.: Since I am not sure the .subr file will pass the mailing list filters, I copied the file to http://erdgeist.org/network6.subr --------------040100090500080408060203 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="network6.subr" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="network6.subr" #!/bin/sh get_if_var() { # echo "2002:50ed:991c:50ed:c401-c409::" # echo "2002:50ed:991c:50ed:c401-c409::c409" echo "::ffff:192.168.2-4.2/12" # echo "::ffff:192.168.2.23-25/12" # echo "::ffff:192.168.2.23/12" # echo "2002:50ed:991c:50ed:c401::" # echo "2002:50ed:991c-991f:50ed:c401::" } ipv6_addrs_common() { _ret=1 _if=$1 _action=$2 # get ipv6-addresses cidr_addr=`get_if_var $_if ipv6_addrs_IF` for _cidr in ${cidr_addr}; do _ipaddr="${_cidr%%/*}" [ "${_ipaddr}" != "${_cidr}" ] && _netmask="/"${_cidr##*/} || unset _netmask [ "$_action" = "-alias" ] && unset _netmask if [ "${_ipaddr%:*.*.*.*}" = "${_ipaddr}" ]; then _ipleft=${_ipaddr%-*} _ipright=${_ipaddr#*-} _iplow=${_ipleft##*:} _iphigh=${_ipright%%:*} _ipleft=${_ipleft%:*} _ipright=${_ipright#*:} [ "${_iphigh}" = "${_ipright}" ] && unset _ipright || _ipright=:$_ipright if [ "${_iplow}" ]; then while [ $(( 0x$_iplow )) -le $(( 0x$_iphigh )) ]; do echo ifconfig ${_if} inet6 ${_ipleft}:${_iplow}${_ipright}${_netmask} ${_action} _iplow=`printf %04x $(( 0x$_iplow + 1 ))` _ret=0 done else # no range echo ifconfig ${_if} inet6 ${_ipaddr}${_netmask} ${_action} _ret=0 fi else # v4 range _ipv6part=${_ipaddr%:*} _ipv4part=${_ipaddr##*:} _ipleft=${_ipv4part%-*} _ipright=${_ipv4part#*-} _iplow=${_ipleft##*.} _iphigh=${_ipright%%.*} _ipleft=${_ipleft%.*} _ipright=${_ipright#*.} [ "${_iphigh}" = "${_ipright}" ] && unset _ipright || _ipright=.$_ipright if [ "${_iplow}" ]; then while [ ${_iplow} -le ${_iphigh} ]; do echo ifconfig ${_if} inet6 ${_ipv6part}:${_ipleft}.${_iplow}${_ipright}${_netmask} ${_action} : $(( _iplow++ )) _ret=0 done else # no range echo ifconfig ${_if} inet6 ${_ipaddr}${_netmask} ${_action} _ret=0 fi fi done return $_ret } ipv6_addrs_common if0 alias --------------040100090500080408060203--