From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:21:44 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id BDBC54F6; Wed, 16 Oct 2013 08:21:44 +0000 (UTC) (envelope-from ae@FreeBSD.org) 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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id ABB2529E2; Wed, 16 Oct 2013 08:21:44 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8Li91071591; Wed, 16 Oct 2013 08:21:44 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8LiqR071590; Wed, 16 Oct 2013 08:21:44 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160821.r9G8LiqR071590@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 08:21:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256595 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 08:21:44 -0000 Author: ae Date: Wed Oct 16 08:21:44 2013 New Revision: 256595 URL: http://svnweb.freebsd.org/changeset/base/256595 Log: Add in6_srcaddrscope() function. It is similar to in6_addrscope(), but returns link-local scope for IPv4-mapped addresses from 169.254/16 and 127/8 networks. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:19:58 2013 (r256594) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:21:44 2013 (r256595) @@ -143,6 +143,7 @@ static int walk_addrsel_policy(int (*)(s void *); static int dump_addrsel_policyent(struct in6_addrpolicy *, void *); static struct in6_addrpolicy *match_addrsel_policy(struct sockaddr_in6 *); +static int in6_srcaddrscope(const struct in6_addr *); /* * Return an IPv6 address, which is the most appropriate for a given @@ -1184,3 +1185,20 @@ match_addrsel_policy(struct sockaddr_in6 return (bestpol); } + +/* + * This function is similar to in6_addrscope, but has some difference, + * specific for the source address selection algorithm (RFC 6724). + */ +static int +in6_srcaddrscope(const struct in6_addr *addr) +{ + + /* 169.254/16 and 127/8 have link-local scope */ + if (IN6_IS_ADDR_V4MAPPED(addr)) { + if (addr->s6_addr[12] == 127 || ( + addr->s6_addr[12] == 169 && addr->s6_addr[13] == 254)) + return (IPV6_ADDR_SCOPE_LINKLOCAL); + } + return (in6_addrscope(addr)); +}