From owner-svn-src-head@FreeBSD.ORG Tue Sep 9 10:52:52 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 56A4ABCA; Tue, 9 Sep 2014 10:52:52 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 424863BA; Tue, 9 Sep 2014 10:52:52 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s89Aqq8w090140; Tue, 9 Sep 2014 10:52:52 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s89AqppN090135; Tue, 9 Sep 2014 10:52:51 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201409091052.s89AqppN090135@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Tue, 9 Sep 2014 10:52:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271307 - in head: sbin/ifconfig sys/netinet6 usr.bin/netstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Sep 2014 10:52:52 -0000 Author: ae Date: Tue Sep 9 10:52:50 2014 New Revision: 271307 URL: http://svnweb.freebsd.org/changeset/base/271307 Log: Add the ability to set `prefer_source' flag to an IPv6 address. It affects the IPv6 source address selection algorithm (RFC 6724) and allows override the last rule ("longest matching prefix") for choosing among equivalent addresses. The address with `prefer_source' will be preferred source address. Obtained from: Yandex LLC MFC after: 1 month Sponsored by: Yandex LLC Modified: head/sbin/ifconfig/af_inet6.c head/sbin/ifconfig/ifconfig.8 head/sys/netinet6/in6_src.c head/sys/netinet6/in6_var.h head/usr.bin/netstat/inet6.c Modified: head/sbin/ifconfig/af_inet6.c ============================================================================== --- head/sbin/ifconfig/af_inet6.c Tue Sep 9 10:29:27 2014 (r271306) +++ head/sbin/ifconfig/af_inet6.c Tue Sep 9 10:52:50 2014 (r271307) @@ -254,6 +254,8 @@ in6_status(int s __unused, const struct printf("autoconf "); if ((flags6 & IN6_IFF_TEMPORARY) != 0) printf("temporary "); + if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) + printf("prefer_source "); if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) printf("scopeid 0x%x ", @@ -465,6 +467,8 @@ static struct cmd inet6_cmds[] = { DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED, setip6flags), DEF_CMD("autoconf", IN6_IFF_AUTOCONF, setip6flags), DEF_CMD("-autoconf", -IN6_IFF_AUTOCONF, setip6flags), + DEF_CMD("prefer_source",IN6_IFF_PREFER_SOURCE, setip6flags), + DEF_CMD("-prefer_source",-IN6_IFF_PREFER_SOURCE,setip6flags), DEF_CMD("accept_rtadv", ND6_IFF_ACCEPT_RTADV, setnd6flags), DEF_CMD("-accept_rtadv",-ND6_IFF_ACCEPT_RTADV, setnd6flags), DEF_CMD("no_radr", ND6_IFF_NO_RADR, setnd6flags), Modified: head/sbin/ifconfig/ifconfig.8 ============================================================================== --- head/sbin/ifconfig/ifconfig.8 Tue Sep 9 10:29:27 2014 (r271306) +++ head/sbin/ifconfig/ifconfig.8 Tue Sep 9 10:52:50 2014 (r271307) @@ -28,7 +28,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD$ .\" -.Dd June 5, 2014 +.Dd September 9, 2014 .Dt IFCONFIG 8 .Os .Sh NAME @@ -689,6 +689,19 @@ Clear a flag .Cm no_prefer_iface . .El .Pp +The following parameters are specific for IPv6 addresses. +Note that the address family keyword +.Dq Li inet6 +is needed for them: +.Bl -tag -width indent +.It Cm prefer_source +Set a flag to prefer address as a candidate of the source address for +outgoing packets. +.It Cm -prefer_source +Clear a flag +.Cm prefer_source . +.El +.Pp The following parameters are specific to cloning IEEE 802.11 wireless interfaces with the .Cm create Modified: head/sys/netinet6/in6_src.c ============================================================================== --- head/sys/netinet6/in6_src.c Tue Sep 9 10:29:27 2014 (r271306) +++ head/sys/netinet6/in6_src.c Tue Sep 9 10:52:50 2014 (r271307) @@ -452,6 +452,16 @@ in6_selectsrc(struct sockaddr_in6 *dstso NEXT(9); /* + * Rule 10: prefer address with `prefer_source' flag. + */ + if ((ia_best->ia6_flags & IN6_IFF_PREFER_SOURCE) == 0 && + (ia->ia6_flags & IN6_IFF_PREFER_SOURCE) != 0) + REPLACE(10); + if ((ia_best->ia6_flags & IN6_IFF_PREFER_SOURCE) != 0 && + (ia->ia6_flags & IN6_IFF_PREFER_SOURCE) == 0) + NEXT(10); + + /* * Rule 14: Use longest matching prefix. * Note: in the address selection draft, this rule is * documented as "Rule 8". However, since it is also Modified: head/sys/netinet6/in6_var.h ============================================================================== --- head/sys/netinet6/in6_var.h Tue Sep 9 10:29:27 2014 (r271306) +++ head/sys/netinet6/in6_var.h Tue Sep 9 10:52:50 2014 (r271307) @@ -498,6 +498,7 @@ struct in6_rrenumreq { */ #define IN6_IFF_AUTOCONF 0x40 /* autoconfigurable address. */ #define IN6_IFF_TEMPORARY 0x80 /* temporary (anonymous) address. */ +#define IN6_IFF_PREFER_SOURCE 0x0100 /* preferred address for SAS */ #define IN6_IFF_NOPFX 0x8000 /* skip kernel prefix management. * XXX: this should be temporary. */ Modified: head/usr.bin/netstat/inet6.c ============================================================================== --- head/usr.bin/netstat/inet6.c Tue Sep 9 10:29:27 2014 (r271306) +++ head/usr.bin/netstat/inet6.c Tue Sep 9 10:52:50 2014 (r271307) @@ -346,7 +346,7 @@ static const char *srcrule_str[] = { "public/temporary address", "alive interface", "better virtual status", - "rule #10", + "preferred source", "rule #11", "rule #12", "rule #13",