From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13020 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: getaddrinfo(3) / AI_ADDRCONFIG Date: Wed, 11 Jul 2018 12:44:17 -0400 Message-ID: <20180711164417.GX1392@brightrain.aerifal.cx> References: <20180710005943.GT1392@brightrain.aerifal.cx> <20180710150854.GU1392@brightrain.aerifal.cx> <20180711003816.GV1392@brightrain.aerifal.cx> <20180711012640.GW1392@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="l06SQqiZYCi8rTKz" X-Trace: blaine.gmane.org 1531327347 31435 195.159.176.226 (11 Jul 2018 16:42:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 11 Jul 2018 16:42:27 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13036-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jul 11 18:42:23 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fdIC7-00084J-I7 for gllmg-musl@m.gmane.org; Wed, 11 Jul 2018 18:42:23 +0200 Original-Received: (qmail 23599 invoked by uid 550); 11 Jul 2018 16:44:30 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 23578 invoked from network); 11 Jul 2018 16:44:30 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13020 Archived-At: --l06SQqiZYCi8rTKz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Jul 11, 2018 at 06:12:31AM -0400, Christopher Friedt wrote: > On Tue, Jul 10, 2018 at 9:26 PM Rich Felker wrote: > > Pulling in large amounts of additional code and O(n) runtime cost > > Latest patch [1] addresses > > 1) not ignoring loopback > 2) using routability of udp packets vs O(n) lookup on network interfaces > > Any other concerns, Rich? You seem to have deleted the original patch and replaced it with a new version. My first concern is *please* send all patches as attachments to the list, not transient links like github or pastebins. Even if it were still there now, it would likely not be there 5 years later when someone is reading list archives. I'm attaching your v2 patch here now for reference. With that said, it still makes sprawling changes and intraduces a gratuitous new file with external interface for something that fundamentally takes only a few lines in one place and no external interface at all. Formatting is also inconsistent with musl (spaces after opening and before closing paren, etc.). And addition of the nonstandard EAI_NODATA is an independent change that, if it makes sense at all, needs to be discussed separately, and would need corresponding changes elsewhere (e.g. gai_strerror). Rich --l06SQqiZYCi8rTKz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v2.diff" diff --git a/include/netdb.h b/include/netdb.h index adde2c5e..73d850f6 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -44,6 +44,7 @@ struct addrinfo { #define EAI_NONAME -2 #define EAI_AGAIN -3 #define EAI_FAIL -4 +#define EAI_NODATA -5 #define EAI_FAMILY -6 #define EAI_SOCKTYPE -7 #define EAI_SERVICE -8 diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c index b9439f77..2bfba18f 100644 --- a/src/network/getaddrinfo.c +++ b/src/network/getaddrinfo.c @@ -19,6 +19,7 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru struct sockaddr_in6 sin6; } sa; } *out; + struct addrconfig addrconfig; if (!host && !serv) return EAI_NONAME; @@ -33,6 +34,10 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru if ((flags & mask) != flags) return EAI_BADFLAGS; + if (flags & AI_ADDRCONFIG) { + __lookup_addrconfig(&addrconfig); + } + switch (family) { case AF_INET: case AF_INET6: @@ -61,30 +66,43 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru outcanon = 0; } - for (k=i=0; iai; diff --git a/src/network/lookup.h b/src/network/lookup.h index 0468edbc..32afd545 100644 --- a/src/network/lookup.h +++ b/src/network/lookup.h @@ -1,6 +1,7 @@ #ifndef LOOKUP_H #define LOOKUP_H +#include #include #include @@ -30,9 +31,15 @@ struct resolvconf { #define MAXADDRS 48 #define MAXSERVS 2 +struct addrconfig { + bool af_inet : 1; + bool af_inet6 : 1; +}; + int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags); int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags); int __lookup_ipliteral(struct address buf[static 1], const char *name, int family); +void __lookup_addrconfig( struct addrconfig *cfg ); int __get_resolv_conf(struct resolvconf *, char *, size_t); diff --git a/src/network/lookup_addrconfig.c b/src/network/lookup_addrconfig.c new file mode 100644 index 00000000..427d9299 --- /dev/null +++ b/src/network/lookup_addrconfig.c @@ -0,0 +1,40 @@ +#include "lookup.h" + +#include +#include +#include +#include +#include + +void __lookup_addrconfig( struct addrconfig *cfg ) { + int r; + int fd; + + struct sockaddr_in sai = { + .sin_family = AF_INET, + .sin_port = htons( 42 ), + .sin_addr.s_addr = INADDR_LOOPBACK, + }; + cfg->af_inet = false; + r = socket( AF_INET, SOCK_DGRAM, 0 ); + if ( -1 != r ) { + fd = r; + r = connect( fd, (struct sockaddr *) & sai, sizeof( sai ) ); + cfg->af_inet = 0 == r; + close( fd ); + } + + struct sockaddr_in6 sai6 = { + .sin6_family = AF_INET6, + .sin6_port = htons( 42 ), + .sin6_addr = IN6ADDR_LOOPBACK_INIT, + }; + cfg->af_inet6 = false; + r = socket( AF_INET6, SOCK_DGRAM, 0 ); + if ( -1 != r ) { + fd = r; + r = connect( fd, (struct sockaddr *) & sai6, sizeof( sai6 ) ); + cfg->af_inet6 = 0 == r; + close( fd ); + } +} --l06SQqiZYCi8rTKz--