From owner-freebsd-stable@FreeBSD.ORG Thu Dec 27 21:42:51 2012 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 54AEFE45; Thu, 27 Dec 2012 21:42:51 +0000 (UTC) (envelope-from schors@gmail.com) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com [209.85.215.43]) by mx1.freebsd.org (Postfix) with ESMTP id 92BE18FC0A; Thu, 27 Dec 2012 21:42:50 +0000 (UTC) Received: by mail-la0-f43.google.com with SMTP id z14so12949836lag.16 for ; Thu, 27 Dec 2012 13:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=rY4/kRfhW/8nWiUep3wxXOGt1IDoKwm2LwaiuDnPk2Y=; b=nhioA1NeZTaSYaSxe7QufuYFTcY8fpfbJdeEgeHkr7bC+GJZrKCTvobtYTIlksA/p9 /Nl2Kzwl+6Ppy6jo35SNU9+iC+X745B3NU99204s5dyhGwGw4X8/W9OYE+75lF21wTDQ wzB9LiUG9u4RSGjbGDtrWYDw5kHA6mj/eMRLQ8AEiWiiulYh++5X00sCz6yf/NovV2l0 EYquWhY38nMjVyMg30de5ZfUNqMOiOwDXTNlLqzPOt3BqE82AQPKqProgqnCeIzZa4i7 0rYeb02Xrnx6N436Wnhi4buBHr2BrjiL6cjXaJwiGMsROm4uJ66+I14Bub6UTnxLYJ0f kN+g== MIME-Version: 1.0 Received: by 10.112.99.197 with SMTP id es5mr9433383lbb.30.1356644568930; Thu, 27 Dec 2012 13:42:48 -0800 (PST) Received: by 10.114.5.138 with HTTP; Thu, 27 Dec 2012 13:42:48 -0800 (PST) In-Reply-To: References: <50D1C553.9060100@wasikowski.net> <20121220132750.GB99616@stack.nl> <50D4F2E4.7020600@wasikowski.net> <20121222171400.GA2399@anubis.morrow.me.uk> <50D5F296.9050109@wasikowski.net> Date: Fri, 28 Dec 2012 01:42:48 +0400 Message-ID: Subject: Re: ipv6_addrs_IF aliases in rc.conf(5) From: Phil Kulin To: Kimmo Paasiala Content-Type: text/plain; charset=UTF-8 Cc: FreeBSD current , freebsd-stable@freebsd.org X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Dec 2012 21:42:51 -0000 2012/12/26 Kimmo Paasiala : > I've revised the patch again and updated it at gihub, > https://gist.github.com/4362018. It can now be applied at top level > of sources (/usr/src typically). It now does the deconfiguration in > reverse order of the configuration, meaning the aliases configured > with ipv6_addrs_IF are removed before the ones configured with > ifconfig_IF_aliasN="inet6 ...". Adapted for FreeBSD 8.2, works fine: --- network.subr.orig 2011-02-17 05:19:39.000000000 +0300 +++ network.subr 2012-12-28 00:46:38.000000000 +0400 @@ -312,6 +312,12 @@ afexists() # 1 otherwise. ipv6if() { + # Test for $ipv6_addrs_IF. If it exists then the + # interface should be configured for IPv6 + _tmpargs=$(get_if_var $_if ipv6_addrs_IF) + if [ -n "${_tmpargs}" ]; then + return 0 + fi if ! checkyesno ipv6_enable; then return 1 fi @@ -948,7 +954,12 @@ network6_interface_setup() rtsol_interface=no ifconfig $i inet6 ${ipv6_ifconfig} alias fi - + ipv6_addrs=`get_if_var $i ipv6_addrs_IF` + if [ -n "${ipv6_addrs}" ]; then + rtsol_available=no + rtsol_interface=no + ipv6_addrs_common ${i} alias + fi # Wireless NIC cards are virtualized through the wlan interface if ! is_wired_interface ${i}; then case "${i}" in @@ -1178,3 +1189,39 @@ network6_getladdr() esac done } + +ipv6_addrs_common() +{ + local _ret _if _action _ip6prefix _ip6prefixes + local _ip6addr _prefixlen + local _range _ip6net _ip6low _ip6high + _ret=1 + _if=$1 + _action=$2 + # get the prefixes from ipv6_addrs_IF variable + _ip6prefixes=`get_if_var $_if ipv6_addrs_IF` + for _ip6prefix in ${_ip6prefixes}; do + _ip6addr=${_ip6prefix%%/*} + _prefixlen=${_ip6prefix##*/} + _range=${_ip6addr##*:} + _ip6net=${_ip6addr%:*} + _ip6low=${_range%-*} + _ip6high=${_range#*-} + # If deleting an alias, set _prefixlen to null string. + if [ "${_action}" = "-alias" ]; then + _prefixlen="" + else + _prefixlen="prefixlen $_prefixlen" + fi + _ip6high=$(("0x${_ip6high}")) + _ip6count=$(("0x${_ip6low}")) + while [ "${_ip6count}" -le "${_ip6high}" ]; do + # Re-uses the _ip6addr variable from above + _ip6addr=$(printf "%x" "${_ip6count}") + eval "ifconfig ${_if} inet6 ${_ip6net}:${_ip6addr} ${_prefixlen} ${_action}" + _ip6count=$((${_ip6count}+1)) + _ret=0 + done + done + return $_ret +} -- Non nobis Domine non nobis sed Nomini Tuo da gloriam Phil Kulin