From owner-freebsd-net@FreeBSD.ORG Fri Apr 13 18:03:52 2012 Return-Path: Delivered-To: freebsd-net@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 4F6BF1065849; Fri, 13 Apr 2012 18:03:52 +0000 (UTC) (envelope-from ume@mahoroba.org) Received: from mail.mahoroba.org (ent.mahoroba.org [IPv6:2001:2f0:104:8010::1]) by mx1.freebsd.org (Postfix) with ESMTP id 21E778FC17; Fri, 13 Apr 2012 18:03:50 +0000 (UTC) Received: from yuga.mahoroba.org (ume@yuga.mahoroba.org [IPv6:2001:2f0:104:8010:7258:12ff:fe22:d94b]) (user=ume mech=DIGEST-MD5 bits=0) by mail.mahoroba.org (8.14.5/8.14.5) with ESMTP/inet6 id q3DI3ao6098811 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 14 Apr 2012 03:03:40 +0900 (JST) (envelope-from ume@mahoroba.org) Date: Sat, 14 Apr 2012 03:03:36 +0900 Message-ID: From: Hajimu UMEMOTO To: Andrew Thompson In-Reply-To: References: <20120413064142.10640@gmx.net> User-Agent: xcite1.60> Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?ISO-2022-JP-2?B?R29qGyQoRCtXGyhC?=) APEL/10.8 Emacs/23.4 (i386-portbld-freebsd9.0) MULE/6.0 (HANACHIRUSATO) X-Operating-System: FreeBSD 9.0-STABLE X-PGP-Key: http://www.imasy.or.jp/~ume/publickey.asc X-PGP-Fingerprint: 1F00 0B9E 2164 70FC 6DC5 BF5F 04E9 F086 BF90 71FE Organization: Internet Mutual Aid Society, YOKOHAMA MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Sat_Apr_14_03:03:35_2012-1" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (mail.mahoroba.org [IPv6:2001:2f0:104:8010::1]); Sat, 14 Apr 2012 03:03:40 +0900 (JST) X-Virus-Scanned: clamav-milter 0.97.4 at asuka.mahoroba.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on asuka.mahoroba.org Cc: freebsd-net@FreeBSD.org, Rainer Bredehorn Subject: Re: getifaddrs & ipv6 scope X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Apr 2012 18:03:52 -0000 --Multipart_Sat_Apr_14_03:03:35_2012-1 Content-Type: text/plain; charset=US-ASCII Hi, >>>>> On Fri, 13 Apr 2012 20:01:39 +1200 >>>>> Andrew Thompson said: thompsa> On 13 April 2012 18:41, Rainer Bredehorn wrote: > Hi! > >> I have noticed that getifaddrs() does not have sin6_scope_id set to >> the interface id for link local addresses on AF_INET6 types. Running >> the following program gives different results on Linux > > ifconfig shows the scopeid according to the interface: > > inet6 fe80::208:9bff:fe13:784e%fxp1 prefixlen 64 scopeid 0x2 > > Are you talking about the scope value of an multicast address or > the scopeid for link local addresses? thompsa> I am talking about the scopeid for link local addresses which (as far thompsa> as I understand) is the interface index. The issue you mentioned comes from an implementation decision of the KAME IPv6 stack. The attached patch should address it. However, it may break the applications which expect that getifaddrs() returns a link-local address with KAME's embeded scopeid representation. I'm not sure there are such applications, for now. Sincerely, --Multipart_Sat_Apr_14_03:03:35_2012-1 Content-Type: text/x-patch; type=patch; charset=US-ASCII Content-Disposition: attachment; filename="getifaddrs.c-scopeid.diff" Content-Transfer-Encoding: 7bit Index: lib/libc/net/getifaddrs.c diff -u -p lib/libc/net/getifaddrs.c.orig lib/libc/net/getifaddrs.c --- lib/libc/net/getifaddrs.c.orig 2011-09-23 09:51:37.000000000 +0900 +++ lib/libc/net/getifaddrs.c 2012-04-14 02:49:11.000000000 +0900 @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD: src/lib/libc/net/get #include #include #endif +#include #include #include @@ -87,6 +88,8 @@ __FBSDID("$FreeBSD: src/lib/libc/net/get #define MAX_SYSCTL_TRY 5 +static void in6_fillscopeid(struct sockaddr_in6 *); + int getifaddrs(struct ifaddrs **pif) { @@ -341,6 +344,8 @@ getifaddrs(struct ifaddrs **pif) (struct sockaddr *)(void *)data; memcpy(data, p, len); data += len; + if (ift->ifa_addr->sa_family == AF_INET6) + in6_fillscopeid((struct sockaddr_in6 *)ift->ifa_addr); break; case RTAX_NETMASK: @@ -416,3 +421,15 @@ freeifaddrs(struct ifaddrs *ifp) free(ifp); } + +static void +in6_fillscopeid(struct sockaddr_in6 *sin6) +{ +#if defined(__KAME__) + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { + sin6->sin6_scope_id = + ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]); + sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0; + } +#endif +} --Multipart_Sat_Apr_14_03:03:35_2012-1 Content-Type: text/plain; charset=US-ASCII -- Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan ume@mahoroba.org ume@{,jp.}FreeBSD.org http://www.imasy.org/~ume/ --Multipart_Sat_Apr_14_03:03:35_2012-1--