NetBSD Problem Report #44777

From cheusov@tut.by  Sun Mar 27 18:58:28 2011
Return-Path: <cheusov@tut.by>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 6685F63BFDC
	for <gnats-bugs@gnats.netbsd.org>; Sun, 27 Mar 2011 18:58:28 +0000 (UTC)
Message-Id: <87tyeomlv5.fsf@asrock.chizhovka.net>
Date: Sun, 27 Mar 2011 21:58:22 +0300
From: cheusov@tut.by
To: gnats-bugs@gnats.NetBSD.org
Subject: NetBSD lacks AI_ADDRCONFIG
X-Send-Pr-Version: 3.95

>Number:         44777
>Category:       standards
>Synopsis:       NetBSD lacks AI_ADDRCONFIG and others
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    standards-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 27 19:00:00 +0000 2011
>Closed-Date:    Sun Oct 09 22:08:39 +0000 2016
>Last-Modified:  Sun Oct 09 22:08:39 +0000 2016
>Originator:     Aleksey Cheusov
>Release:        NetBSD 5.1
>Organization:
>Environment:
System: NetBSD asrock.chizhovka.net 5.1 NetBSD 5.1 (GENERIC) #0: Mon Jan 31 23:53:52 EET 2011 cheusov@asrock.chizhovka.net:/srv/obj/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
According to

http://pubs.opengroup.org/onlinepubs/009695399/basedefs/netdb.h.html

and

http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html

AI_ADDRCONFIG is a constant that shall be provided by netdb.h and
accepted by getaddrinfo(3).
But it is not provided by NetBSD-current. Due to this some software fails
to build on it. The same for AI_NUMERICHOST, AI_V4MAPPED and some others.

>How-To-Repeat:
man getaddrinfo

>Fix:

Unknown
>Release-Note:

>Audit-Trail:
From: "Jukka Ruohonen" <jruoho@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/44777 CVS commit: src
Date: Sun, 10 Apr 2011 10:49:44 +0000

 Module Name:	src
 Committed By:	jruoho
 Date:		Sun Apr 10 10:49:44 UTC 2011

 Modified Files:
 	src/distrib/sets/lists/tests: mi
 	src/tests/include: Makefile
 Added Files:
 	src/tests/include: t_netdb.c

 Log Message:
 Formally verify PR standards/44777.


 To generate a diff of this commit:
 cvs rdiff -u -r1.306 -r1.307 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.4 -r1.5 src/tests/include/Makefile
 cvs rdiff -u -r0 -r1.1 src/tests/include/t_netdb.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Pierre Pronchery <khorben@defora.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: standards/44777: NetBSD lacks AI_ADDRCONFIG
Date: Tue, 03 Apr 2012 20:18:49 +0200

 This is a multi-part message in MIME format.
 --------------090007060304070409040308
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit

 			Hi everyone,

 I've been stumbling on this issue as well, as building bitcoin (at least
 from git) requires AI_ADDRCONFIG to be set. It feels a bit sensitive to
 me, as there seems to be some gray area about how this value should be
 interpreted.

 From lib/libc/net/getaddrinfo.c:
 > 50  * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague.
 > 51  *   (1) what should we do against numeric hostname (2) what should we do
 > 52  *   against NULL hostname (3) what is AI_ADDRCONFIG itself.  AF not ready?
 > 53  *   non-loopback address configured?  global address configured?

 I have had a look at how FreeBSD solved this and adapted their patch.
 They have implemented AI_ADDRCONFIG (and added the other missing
 definitions) but left this comment in this same file as well.

 Please find the relevant patch attached here. However, I am not offering
 a fix to the underlying issue, or not even implementing RFC 2553, so
 this bug should be left opened regardless. Plus, I admit to have not
 checked for the correctness of this implementation.

 In any case, I could build bitcoin with this patch, and it would be
 great to get it pulled-up into the netbsd-6 branch if at all accepted.

 Cheers,
 -- 
 khorben

 --------------090007060304070409040308
 Content-Type: text/plain;
  name="patch-ai_addrinfo.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="patch-ai_addrinfo.diff"

 Index: include/netdb.h
 ===================================================================
 RCS file: /cvsroot/src/include/netdb.h,v
 retrieving revision 1.64
 diff -p -u -r1.64 netdb.h
 --- include/netdb.h	5 May 2010 17:12:29 -0000	1.64
 +++ include/netdb.h	3 Apr 2012 17:56:18 -0000
 @@ -272,6 +272,13 @@ struct addrinfo {
      (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)
  #endif

 +#define	AI_ALL		0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
 +#define	AI_V4MAPPED_CFG	0x00000200 /* accept IPv4-mapped if kernel supports */
 +#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
 +#define	AI_V4MAPPED	0x00000800 /* accept IPv4-mapped IPv6 address */
 +/* special recommended flags for getipnodebyname */
 +#define	AI_DEFAULT	(AI_V4MAPPED_CFG | AI_ADDRCONFIG)
 +
  #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
      defined(_NETBSD_SOURCE)
  /*%
 Index: lib/libc/net/getaddrinfo.c
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/net/getaddrinfo.c,v
 retrieving revision 1.96
 diff -p -u -r1.96 getaddrinfo.c
 --- lib/libc/net/getaddrinfo.c	15 Oct 2011 23:00:02 -0000	1.96
 +++ lib/libc/net/getaddrinfo.c	3 Apr 2012 17:56:24 -0000
 @@ -208,6 +208,7 @@ static int get_portmatch(const struct ad
  static int get_port(const struct addrinfo *, const char *, int,
      struct servent_data *);
  static const struct afd *find_afd(int);
 +static int addrconfig(struct addrinfo *);
  #ifdef INET6
  static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *);
  #endif
 @@ -367,7 +368,7 @@ getaddrinfo(const char *hostname, const 
  	pai->ai_canonname = NULL;
  	pai->ai_addr = NULL;
  	pai->ai_next = NULL;
 -	
 +
  	if (hostname == NULL && servname == NULL)
  		return EAI_NONAME;
  	if (hints) {
 @@ -486,6 +487,9 @@ getaddrinfo(const char *hostname, const 
  	if (pai->ai_flags & AI_NUMERICHOST)
  		ERR(EAI_NONAME);

 +	if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && !addrconfig(&ai0))
 +		ERR(EAI_FAIL);
 +
  	/*
  	 * hostname as alphabetical name.
  	 * we would like to prefer AF_INET6 than AF_INET, so we'll make a
 @@ -1006,6 +1010,48 @@ find_afd(int af)
  	return NULL;
  }

 +/*
 + * post-2553: AI_ADDRCONFIG check.  if we use getipnodeby* as backend, backend
 + * will take care of it.
 + * the semantics of AI_ADDRCONFIG is not defined well.  we are not sure
 + * if the code is right or not.
 + *
 + * XXX PF_UNSPEC -> PF_INET6 + PF_INET mapping needs to be in sync with
 + * _dns_getaddrinfo.
 + */
 +static int
 +addrconfig(struct addrinfo *pai)
 +{
 +	int s, af;
 +
 +	/*
 +	 * TODO:
 +	 * Note that implementation dependent test for address
 +	 * configuration should be done everytime called
 +	 * (or apropriate interval),
 +	 * because addresses will be dynamically assigned or deleted.
 +	 */
 +	af = pai->ai_family;
 +	if (af == AF_UNSPEC) {
 +		if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 +			af = AF_INET;
 +		else {
 +			close(s);
 +			if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
 +				af = AF_INET6;
 +			else
 +				close(s);
 +		}
 +	}
 +	if (af != AF_UNSPEC) {
 +		if ((s = socket(af, SOCK_DGRAM, 0)) < 0)
 +			return 0;
 +		close(s);
 +	}
 +	pai->ai_family = af;
 +	return 1;
 +}
 +
  #ifdef INET6
  /* convert a string to a scope identifier. XXX: IPv6 specific */
  static int

 --------------090007060304070409040308--

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, standards-manager@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, cheusov@tut.by
Cc: 
Subject: Re: standards/44777: NetBSD lacks AI_ADDRCONFIG
Date: Tue, 3 Apr 2012 14:45:46 -0400

 On Apr 3,  6:20pm, khorben@defora.org (Pierre Pronchery) wrote:
 -- Subject: Re: standards/44777: NetBSD lacks AI_ADDRCONFIG
 |  I've been stumbling on this issue as well, as building bitcoin (at least
 |  from git) requires AI_ADDRCONFIG to be set. It feels a bit sensitive to
 |  me, as there seems to be some gray area about how this value should be
 |  interpreted.
 |  
 |  From lib/libc/net/getaddrinfo.c:
 |  > 50  * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague.
 |  > 51  *   (1) what should we do against numeric hostname (2) what should we do
 |  > 52  *   against NULL hostname (3) what is AI_ADDRCONFIG itself.  AF not ready?
 |  > 53  *   non-loopback address configured?  global address configured?
 |  
 |  I have had a look at how FreeBSD solved this and adapted their patch.
 |  They have implemented AI_ADDRCONFIG (and added the other missing
 |  definitions) but left this comment in this same file as well.
 |  
 |  Please find the relevant patch attached here. However, I am not offering
 |  a fix to the underlying issue, or not even implementing RFC 2553, so
 |  this bug should be left opened regardless. Plus, I admit to have not
 |  checked for the correctness of this implementation.
 |  
 |  In any case, I could build bitcoin with this patch, and it would be
 |  great to get it pulled-up into the netbsd-6 branch if at all accepted.

 This patch is incorrect. It checks only if sockets can be created in the
 particular family to determine if the family is available, not if actual
 addresses of the particular family are configured in any system interface.

 The TOG requires:

     If the AI_ADDRCONFIG flag is specified, IPv4 addresses shall be
     returned only if an IPv4 address is configured on the local system,
     [IP6] [Option Start]  and IPv6 addresses shall be returned only if
     an IPv6 address is configured on the local system. [Option End]

 This has been implemented on head.

 christos

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 09 Oct 2016 22:08:39 +0000
State-Changed-Why:
AI_ADDRCONFIG is in -6.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.