public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function
  2017-09-05 16:06 [RFC][PATCH 0/4][BZ 17083] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses Łukasz Stelmach
@ 2017-09-05 16:06 ` Łukasz Stelmach
  2017-09-12 10:03   ` Florian Weimer
  2017-09-05 16:06 ` [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives Łukasz Stelmach
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-05 16:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: Łukasz Stelmach

Add af (address family) to the list of arguments of gethostbyname4_r
function in files, dns, nis and nisplus module and rename the function to
gethostbyname5_r. Pass the af value to the underlying parsing functions.
Define gethostbyname4_r as a wrapper for the former passing af set
to AF_UNSPEC.

Signed-off-by: Łukasz Stelmach <stlman@poczta.fm>
---
 nis/Versions                    |  3 ++-
 nis/nss_nis/nis-hosts.c         | 13 +++++++++++--
 nis/nss_nisplus/nisplus-hosts.c | 13 +++++++++++--
 nss/Versions                    |  1 +
 nss/nss_files/files-hosts.c     | 13 +++++++++++--
 resolv/Versions                 |  2 +-
 resolv/nss_dns/dns-host.c       | 32 ++++++++++++++++++++++++++++++--
 7 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/nis/Versions b/nis/Versions
index ef9a512417..537f0aa3c0 100644
--- a/nis/Versions
+++ b/nis/Versions
@@ -96,6 +96,7 @@ libnss_nis {
     _nss_nis_setnetgrent; _nss_nis_setprotoent; _nss_nis_setpwent;
     _nss_nis_setrpcent; _nss_nis_setservent; _nss_nis_setspent;
     _nss_nis_initgroups_dyn; _nss_nis_gethostbyname4_r;
+    _nss_nis_gethostbyname5_r;
   }
 }
 
@@ -126,6 +127,6 @@ libnss_nisplus {
     _nss_nisplus_setnetent; _nss_nisplus_setnetgrent; _nss_nisplus_setprotoent;
     _nss_nisplus_setpwent; _nss_nisplus_setrpcent; _nss_nisplus_setservent;
     _nss_nisplus_setspent; _nss_nisplus_initgroups_dyn;
-    _nss_nisplus_gethostbyname4_r;
+    _nss_nisplus_gethostbyname4_r; _nss_nisplus_gethostbyname5_r;
   }
 }
diff --git a/nis/nss_nis/nis-hosts.c b/nis/nss_nis/nis-hosts.c
index f64dbdaecb..3a156aa7ee 100644
--- a/nis/nss_nis/nis-hosts.c
+++ b/nis/nss_nis/nis-hosts.c
@@ -454,7 +454,7 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
 
 
 enum nss_status
-_nss_nis_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
+_nss_nis_gethostbyname5_r (const char *name, int af, struct gaih_addrtuple **pat,
 			   char *buffer, size_t buflen, int *errnop,
 			   int *herrnop, int32_t *ttlp)
 {
@@ -530,7 +530,7 @@ _nss_nis_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
   buflen -= pad;
 
   struct hostent host;
-  int parse_res = parse_line (result, &host, data, buflen, errnop, AF_UNSPEC,
+  int parse_res = parse_line (result, &host, data, buflen, errnop, af,
 			      0);
   if (__glibc_unlikely (parse_res < 1))
     {
@@ -565,3 +565,12 @@ _nss_nis_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
 
   return NSS_STATUS_SUCCESS;
 }
+
+enum nss_status
+_nss_nis_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
+			   char *buffer, size_t buflen, int *errnop,
+			   int *herrnop, int32_t *ttlp)
+{
+  return _nss_nis_gethostbyname5_r (name, AF_UNSPEC, pat, buffer, buflen,
+				    errnop, herrnop, ttlp);
+}
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
index 31dfd31fbd..d9c5d7a974 100644
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ b/nis/nss_nisplus/nisplus-hosts.c
@@ -579,13 +579,13 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
 
 
 enum nss_status
-_nss_nisplus_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
+_nss_nisplus_gethostbyname5_r (const char *name, int af, struct gaih_addrtuple **pat,
 			       char *buffer, size_t buflen, int *errnop,
 			       int *herrnop, int32_t *ttlp)
 {
   struct hostent host;
 
-  enum nss_status status = internal_gethostbyname2_r (name, AF_UNSPEC, &host,
+  enum nss_status status = internal_gethostbyname2_r (name, af, &host,
 						      buffer, buflen,
 						      errnop, herrnop, 0);
   if (__glibc_likely (status == NSS_STATUS_SUCCESS))
@@ -617,3 +617,12 @@ _nss_nisplus_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
 
   return status;
 }
+
+enum nss_status
+_nss_nisplus_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
+			       char *buffer, size_t buflen, int *errnop,
+			       int *herrnop, int32_t *ttlp)
+{
+  return _nss_nisplus_gethostbyname5_r (name, AF_UNSPEC, pat, buffer,
+					buflen, errnop, herrnop, ttlp);
+}
diff --git a/nss/Versions b/nss/Versions
index 50268ed9b5..72adf4c806 100644
--- a/nss/Versions
+++ b/nss/Versions
@@ -44,6 +44,7 @@ libnss_files {
     _nss_files_gethostbyname2_r;
     _nss_files_gethostbyname3_r;
     _nss_files_gethostbyname4_r;
+    _nss_files_gethostbyname5_r;
     _nss_files_gethostbyname_r;
     _nss_files_gethostent_r;
 
diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
index 28eb73fb2d..c6067cc641 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -404,7 +404,7 @@ _nss_files_gethostbyname2_r (const char *name, int af, struct hostent *result,
 }
 
 enum nss_status
-_nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
+_nss_files_gethostbyname5_r (const char *name, int af, struct gaih_addrtuple **pat,
 			     char *buffer, size_t buflen, int *errnop,
 			     int *herrnop, int32_t *ttlp)
 {
@@ -428,7 +428,7 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
 
 	  struct hostent result;
 	  status = internal_getent (stream, &result, buffer, buflen, errnop,
-				    herrnop, AF_UNSPEC, 0, &in6_zone_id);
+				    herrnop, af, 0, &in6_zone_id);
 	  if (status != NSS_STATUS_SUCCESS)
 	    break;
 
@@ -518,3 +518,12 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
 
   return status;
 }
+
+enum nss_status
+_nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
+			     char *buffer, size_t buflen, int *errnop,
+			     int *herrnop, int32_t *ttlp)
+{
+  return _nss_files_gethostbyname5_r (name, AF_UNSPEC, pat, buffer, buflen,
+				      errnop, herrnop, ttlp);
+}
diff --git a/resolv/Versions b/resolv/Versions
index b05778d965..2ae1048908 100644
--- a/resolv/Versions
+++ b/resolv/Versions
@@ -96,7 +96,7 @@ libnss_dns {
     _nss_dns_gethostbyname_r; _nss_dns_getnetbyaddr_r;
     _nss_dns_getnetbyname_r; _nss_dns_getcanonname_r;
     _nss_dns_gethostbyaddr2_r;
-    _nss_dns_gethostbyname4_r;
+    _nss_dns_gethostbyname4_r; _nss_dns_gethostbyname5_r;
   }
 }
 
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 7cd54ab504..dddb8f4bef 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -308,7 +308,7 @@ _nss_dns_gethostbyname_r (const char *name, struct hostent *result,
 
 
 enum nss_status
-_nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
+_nss_dns_gethostbyname5_r (const char *name, int af, struct gaih_addrtuple **pat,
 			   char *buffer, size_t buflen, int *errnop,
 			   int *herrnop, int32_t *ttlp)
 {
@@ -344,10 +344,28 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
   int nans2p = 0;
   int resplen2 = 0;
   int ans2p_malloced = 0;
+  int type;
 
   int olderr = errno;
   enum nss_status status;
-  int n = __res_context_search (ctx, name, C_IN, T_QUERY_A_AND_AAAA,
+
+  switch (af) {
+  case AF_UNSPEC:
+    type = T_QUERY_A_AND_AAAA;
+    break;
+  case AF_INET:
+    type = T_A;
+    break;
+  case AF_INET6:
+    type = T_AAAA;
+    break;
+  default:
+    *herrnop = NO_DATA;
+    *errnop = EAFNOSUPPORT;
+    return NSS_STATUS_UNAVAIL;
+  }
+
+  int n = __res_context_search (ctx, name, C_IN, type,
 				host_buffer.buf->buf, 2048, &host_buffer.ptr,
 				&ans2p, &nans2p, &resplen2, &ans2p_malloced);
   if (n >= 0)
@@ -397,6 +415,16 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
 }
 
 
+enum nss_status
+_nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
+			   char *buffer, size_t buflen, int *errnop,
+			   int *herrnop, int32_t *ttlp)
+{
+  return _nss_dns_gethostbyname5_r (name, AF_UNSPEC, pat, buffer, buflen,
+				    errnop, herrnop,ttlp);
+}
+
+
 extern enum nss_status _nss_dns_gethostbyaddr2_r (const void *addr,
 						  socklen_t len, int af,
 						  struct hostent *result,
-- 
2.11.0

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts
  2017-09-05 16:06 [RFC][PATCH 0/4][BZ 17083] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses Łukasz Stelmach
                   ` (2 preceding siblings ...)
  2017-09-05 16:06 ` [RFC][PATCH 4/4][BZ 17083] getaddrinfo: Use the new getaddrinfo5_r NSS function Łukasz Stelmach
@ 2017-09-05 16:06 ` Łukasz Stelmach
  2017-09-12 10:00   ` Florian Weimer
  2017-09-06  5:43 ` [RFC][PATCH 0/4] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses [BZ #17083] Łukasz Stelmach
  4 siblings, 1 reply; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-05 16:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: Łukasz Stelmach

Parse link-local IPv6 addresses in /etc/hosts, which contain zone
identifiers as described in RFC 4007.

Signed-off-by: Łukasz Stelmach <stlman@poczta.fm>
---
 nss/nss_files/files-hosts.c | 54 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 8 deletions(-)

diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
index bccb6a5780..28eb73fb2d 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -33,8 +33,8 @@
 #define DATABASE	"hosts"
 #define NEED_H_ERRNO
 
-#define EXTRA_ARGS	 , af, flags
-#define EXTRA_ARGS_DECL	 , int af, int flags
+#define EXTRA_ARGS	 , af, flags, in6_zone_id
+#define EXTRA_ARGS_DECL	 , int af, int flags, uint32_t *in6_zone_id
 
 #define ENTDATA hostent_data
 struct hostent_data
@@ -53,6 +53,9 @@ LINE_PARSER
 
    STRING_FIELD (addr, isspace, 1);
 
+   if (in6_zone_id != NULL)
+     *in6_zone_id = 0;
+
    /* Parse address.  */
    if (inet_pton (af == AF_UNSPEC ? AF_INET : af, addr, entdata->host_addr)
        > 0)
@@ -80,6 +83,40 @@ LINE_PARSER
        else if (af == AF_UNSPEC
 		&& inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
 	 af = AF_INET6;
+       else if (strchr(addr, SCOPE_DELIMITER) != NULL)
+	 {
+	   /* Parse a zone identifier RFC 4007 11. */
+	   struct addrinfo hints;
+	   struct addrinfo *res;
+	   struct sockaddr_in6 *sa;
+	   int ret;
+
+	   /* Only IPv6 link-local addresses can have zone identifiers. */
+	   af = AF_INET6;
+
+	   memset(&hints, 0, sizeof(struct addrinfo));
+	   /* Don't perform any lookups. */
+	   hints.ai_flags = AI_NUMERICHOST;
+	   hints.ai_family = AF_INET6;
+
+	   ret = getaddrinfo(addr, NULL, &hints, &res);
+	   if (ret != 0)
+	     return 0;
+
+	   sa = (struct sockaddr_in6*)res->ai_addr;
+
+	   /* Zone identifiers makes sense only for link-local addresses. */
+	   if (!IN6_IS_ADDR_LINKLOCAL(sa->sin6_addr.s6_addr)) {
+	     freeaddrinfo(res);
+	     return 0;
+	   }
+
+	   if (in6_zone_id != NULL)
+	     *in6_zone_id = sa->sin6_scope_id;
+
+	   memcpy(entdata->host_addr, &sa->sin6_addr, IN6ADDRSZ);
+	   freeaddrinfo(res);
+	 }
        else
 	 /* Illegal address: ignore line.  */
 	 return 0;
@@ -99,14 +136,14 @@ LINE_PARSER
 
 #define EXTRA_ARGS_VALUE \
   , (res_use_inet6 () ? AF_INET6 : AF_INET),		      \
-  (res_use_inet6 () ? AI_V4MAPPED : 0)
+  (res_use_inet6 () ? AI_V4MAPPED : 0), NULL
 #include "files-XXX.c"
 #undef EXTRA_ARGS_VALUE
 
 /* We only need to consider IPv4 mapped addresses if the input to the
    gethostbyaddr() function is an IPv6 address.  */
 #define EXTRA_ARGS_VALUE \
-  , af, (len == IN6ADDRSZ ? AI_V4MAPPED : 0)
+  , af, (len == IN6ADDRSZ ? AI_V4MAPPED : 0), NULL
 DB_LOOKUP (hostbyaddr, ,,,
 	   {
 	     if (result->h_length == (int) len
@@ -135,7 +172,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
       int flags = (res_use_inet6 () ? AI_V4MAPPED : 0);
 
       while ((status = internal_getent (stream, result, buffer, buflen, errnop,
-					herrnop, af, flags))
+					herrnop, af, flags, NULL))
 	     == NSS_STATUS_SUCCESS)
 	{
 	  LOOKUP_NAME_CASE (h_name, h_aliases)
@@ -163,7 +200,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
 	again:
 	  while ((status = internal_getent (stream, &tmp_result_buf, tmp_buffer,
 					    tmp_buflen, errnop, herrnop, af,
-					    flags))
+					    flags, NULL))
 		 == NSS_STATUS_SUCCESS)
 	    {
 	      int matches = 1;
@@ -385,12 +422,13 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
 	  /* Align the buffer for the next record.  */
 	  uintptr_t pad = (-(uintptr_t) buffer
 			   % __alignof__ (struct hostent_data));
+	  uint32_t in6_zone_id = 0;
 	  buffer += pad;
 	  buflen = buflen > pad ? buflen - pad : 0;
 
 	  struct hostent result;
 	  status = internal_getent (stream, &result, buffer, buflen, errnop,
-				    herrnop, AF_UNSPEC, 0);
+				    herrnop, AF_UNSPEC, 0, &in6_zone_id);
 	  if (status != NSS_STATUS_SUCCESS)
 	    break;
 
@@ -448,7 +486,7 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
 	  got_canon = true;
 	  (*pat)->family = result.h_addrtype;
 	  memcpy ((*pat)->addr, result.h_addr_list[0], result.h_length);
-	  (*pat)->scopeid = 0;
+	  (*pat)->scopeid = in6_zone_id;
 
 	  pat = &((*pat)->next);
 
-- 
2.11.0

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC][PATCH 4/4][BZ 17083] getaddrinfo: Use the new getaddrinfo5_r NSS function
  2017-09-05 16:06 [RFC][PATCH 0/4][BZ 17083] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses Łukasz Stelmach
  2017-09-05 16:06 ` [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function Łukasz Stelmach
  2017-09-05 16:06 ` [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives Łukasz Stelmach
@ 2017-09-05 16:06 ` Łukasz Stelmach
  2017-09-05 16:06 ` [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts Łukasz Stelmach
  2017-09-06  5:43 ` [RFC][PATCH 0/4] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses [BZ #17083] Łukasz Stelmach
  4 siblings, 0 replies; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-05 16:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: Łukasz Stelmach

Signed-off-by: Łukasz Stelmach <stlman@poczta.fm>
---
 sysdeps/posix/getaddrinfo.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 4b4e192e89..38e231091a 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -302,6 +302,10 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
  }
 
 
+typedef enum nss_status (*nss_gethostbyname5_r)
+  (const char *name, int af, struct gaih_addrtuple **pat,
+   char *buffer, size_t buflen, int *errnop,
+   int *h_errnop, int32_t *ttlp);
 typedef enum nss_status (*nss_gethostbyname4_r)
   (const char *name, struct gaih_addrtuple **pat,
    char *buffer, size_t buflen, int *errnop,
@@ -777,19 +781,27 @@ gaih_inet (const char *name, const struct gaih_service *service,
 	      no_data = 0;
 	      nss_gethostbyname4_r fct4 = NULL;
 
+	      /* gethostbyname5_r accepts af argument and returns
+		 gaih_addrtupple. What more do we need? */
+	      nss_gethostbyname5_r fct5 = __nss_lookup_function (nip, "gethostbyname5_r");
 	      /* gethostbyname4_r sends out parallel A and AAAA queries and
 		 is thus only suitable for PF_UNSPEC.  */
-	      if (req->ai_family == PF_UNSPEC)
+	      if (req->ai_family == PF_UNSPEC && fct5 == NULL)
 		fct4 = __nss_lookup_function (nip, "gethostbyname4_r");
-
-	      if (fct4 != NULL)
+	      if (fct5 != NULL || fct4 != NULL)
 		{
 		  while (1)
 		    {
-		      status = DL_CALL_FCT (fct4, (name, pat,
-						   tmpbuf->data, tmpbuf->length,
-						   &errno, &h_errno,
-						   NULL));
+		      if (fct5 != NULL)
+			status = DL_CALL_FCT (fct5, (name, req->ai_family, pat,
+						     tmpbuf->data, tmpbuf->length,
+						     &errno, &h_errno,
+						     NULL));
+		      else
+			status = DL_CALL_FCT (fct4, (name, pat,
+						     tmpbuf->data, tmpbuf->length,
+						     &errno, &h_errno,
+						     NULL));
 		      if (status == NSS_STATUS_SUCCESS)
 			break;
 		      if (status != NSS_STATUS_TRYAGAIN
-- 
2.11.0

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC][PATCH 0/4][BZ 17083] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses
@ 2017-09-05 16:06 Łukasz Stelmach
  2017-09-05 16:06 ` [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function Łukasz Stelmach
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-05 16:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: Łukasz Stelmach

Hello,

The aim of the following patches is to enable retrieving zone
(interface) information stored in /etc/hosts along with link-local IPv6
addresses. This requires changes in several places in resolver and NSS.

First the parse_line() function needs to detect the scope delimiter,
parse what follows and find the network interface index, that later is
going to be assigned to sin6_scope_id field of a sockaddr_in6 structure.
The easiest way to do this is to use getaddrinfo(3) with AI_NUMERICHOST
flag that prevents any DB queries.

There is a slight mismatch in naming of variables. The field in the
sockaddr_in6 structure is sin6_scope_id while I've decided to use
in6_zone_id which better corresponds with the terms used in IPv6 related
RFCs. If you think the term "scope" should be used instead of "zone", I
am fine with it.

When parsed, the zone information needs to be delivered to
getaddrinfo(3). It calls NSS functions gethostbyname4_r,
gethostbyname3_r and gethostbyname2_r. Only the first of them can return
the information because it uses ritcher gaih_addrtupple structure
instead of an old hostent. However, gethostname4_r is used only if
ai_family hint is set to PF_UNSPEC. Which makes the whole API work weird
a bit. With the following entries in /etc/hosts

--8<---------------cut here---------------start------------->8---
192.168.0.1 foo
fe80::0203:04ff:fe05:0607%eth0 foo
--8<---------------cut here---------------end--------------->8---

querying for AF_INET6 address of host foo won't return any results,
which is counterintuitive if not plain wrong. The comment in
getaddrinfo.c suggests, that getaddrinfo4_r should not be used unless
ai_family is set to PF_UNSPEC, to avoid unnecessary DNS queries.

The only way to solve the problem of less capable gethostbyname[23]_r
and too verbose gethosbyname4_r is to introduce gethostbynamet5_r which
accepts all the arguments of gethostbyname4_r AND an address family
(af). So I renamed gethostbyname4_r to gethostbyname5_r and defined
gethostbyname4_r as a wrapper for gethostbyname5_r in all four glibc NSS
modlues (i.e. files, dns, nis and nisplus). gethostbyname5_r passes the
af argument to respective underlying "parsers". Unfotunately I was
unable to test NIS/NIS+ modules, so please do it for me.

The last bit is to make getaddrinfo(3) call gethostbyname5_r. In theory,
with the new function in place, all other code paths are
unnecessary. However, as I understand, different non-glibc NSS modules
provide different sets of functions so I've left the code paths intact.

Łukasz Stelmach (4):
  getaddrinfo: Add comments for #else and #endif directives
  NSS: Parse zone identifier of IPv6 addresses in /etc/hosts
  NSS: Introduce gethostbyname5_r function
  getaddrinfo: Use the new getaddrinfo5_r NSS function

 nis/Versions                    |  3 +-
 nis/nss_nis/nis-hosts.c         | 13 ++++++--
 nis/nss_nisplus/nisplus-hosts.c | 13 ++++++--
 nss/Versions                    |  1 +
 nss/nss_files/files-hosts.c     | 66 +++++++++++++++++++++++++++++++++++------
 resolv/Versions                 |  2 +-
 resolv/nss_dns/dns-host.c       | 32 ++++++++++++++++++--
 sysdeps/posix/getaddrinfo.c     | 54 ++++++++++++++++++++-------------
 8 files changed, 146 insertions(+), 38 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives
  2017-09-05 16:06 [RFC][PATCH 0/4][BZ 17083] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses Łukasz Stelmach
  2017-09-05 16:06 ` [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function Łukasz Stelmach
@ 2017-09-05 16:06 ` Łukasz Stelmach
  2017-09-11 20:01   ` DJ Delorie
  2017-09-05 16:06 ` [RFC][PATCH 4/4][BZ 17083] getaddrinfo: Use the new getaddrinfo5_r NSS function Łukasz Stelmach
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-05 16:06 UTC (permalink / raw)
  To: libc-alpha; +Cc: Łukasz Stelmach

Add comments after #else and #endif directives to help matching them
with appropriate #ifdef lines.

Fix a typo in a comment block.

Signed-off-by: Łukasz Stelmach <stlman@poczta.fm>
---
 sysdeps/posix/getaddrinfo.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index ce099bdf9c..4b4e192e89 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -90,7 +90,7 @@ extern int __idna_to_ascii_lz (const char *input, char **output, int flags);
 extern int __idna_to_unicode_lzlz (const char *input, char **output,
 				   int flags);
 # include <libidn/idna.h>
-#endif
+#endif	/* HAVE_LIBIDN */
 
 struct gaih_service
   {
@@ -129,14 +129,14 @@ static const struct gaih_typeproto gaih_inet_typeproto[] =
   { SOCK_DGRAM, IPPROTO_UDP, 0, true, "udp" },
 #if defined SOCK_DCCP && defined IPPROTO_DCCP
   { SOCK_DCCP, IPPROTO_DCCP, 0, false, "dccp" },
-#endif
+#endif	/* SOCK_DCCP && IPPROTO_DCCP */
 #ifdef IPPROTO_UDPLITE
   { SOCK_DGRAM, IPPROTO_UDPLITE, 0, false, "udplite" },
-#endif
+#endif	/* IPPROTO_UDPLITE */
 #ifdef IPPROTO_SCTP
   { SOCK_STREAM, IPPROTO_SCTP, 0, false, "sctp" },
   { SOCK_SEQPACKET, IPPROTO_SCTP, 0, false, "sctp" },
-#endif
+#endif	/* IPPROTO_SCTP */
   { SOCK_RAW, 0, GAI_PROTO_PROTOANY|GAI_PROTO_NOSERVICE, true, "raw" },
   { 0, 0, 0, false, "" }
 };
@@ -505,7 +505,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
 	      malloc_name = true;
 	    }
 	}
-#endif
+#endif	/* HAVE_LIBIDN */
 
       if (__inet_aton (name, (struct in_addr *) at->addr) != 0)
 	{
@@ -753,7 +753,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
 		  goto free_and_return;
 		}
 	    }
-#endif
+#endif	/* USE_NSCD */
 
 	  if (__nss_hosts_database == NULL)
 	    no_more = __nss_database_lookup ("hosts", NULL,
@@ -1060,11 +1060,11 @@ gaih_inet (const char *name, const struct gaih_service *service,
 		canon = out;
 	      }
 	    else
-#endif
+#endif	/* HAVE_LIBIDN */
 	      {
 #ifdef HAVE_LIBIDN
 	      make_copy:
-#endif
+#endif	/* HAVE_LIBIDN */
 		if (canonbuf != NULL)
 		  /* We already allocated the string using malloc, but
 		     the buffer is now owned by canon.  */
@@ -1193,9 +1193,9 @@ struct sort_result_combo
 
 #if __BYTE_ORDER == __BIG_ENDIAN
 # define htonl_c(n) n
-#else
+#else  /* __BYTE_ORDER == __BIG_ENDIAN */
 # define htonl_c(n) __bswap_constant_32 (n)
-#endif
+#endif	/* __BYTE_ORDER == __BIG_ENDIAN */
 
 static const struct scopeentry
 {
@@ -1297,7 +1297,7 @@ static const struct prefixentry default_labels[] =
       }, 96, 4 },
     /* The next two entries differ from RFC 3484.  We need to treat
        IPv6 site-local addresses special because they are never NATed,
-       unlike site-locale IPv4 addresses.  If this would not happen, on
+       unlike site-local IPv4 addresses.  If this would not happen, on
        machines which have only IPv4 and IPv6 site-local addresses, the
        sorting would prefer the IPv6 site-local addresses, causing
        unnecessary delays when trying to connect to a global IPv6 address
@@ -1715,7 +1715,7 @@ check_gaiconf_mtime (const struct stat64 *st)
           && st->st_mtim.tv_nsec == gaiconf_mtime.tv_nsec);
 }
 
-#else
+#else  /* _STATBUF_ST_NSEC */
 
 static time_t gaiconf_mtime;
 
@@ -1731,7 +1731,7 @@ check_gaiconf_mtime (const struct stat64 *st)
   return st->st_mtime == gaiconf_mtime;
 }
 
-#endif
+#endif	/* _STATBUF_ST_NSEC */
 
 
 libc_freeres_fn(fini)
@@ -2228,7 +2228,7 @@ getaddrinfo (const char *name, const char *service,
 #ifdef HAVE_LIBIDN
 	  |AI_IDN|AI_CANONIDN|AI_IDN_ALLOW_UNASSIGNED
 	  |AI_IDN_USE_STD3_ASCII_RULES
-#endif
+#endif	/* HAVE_LIBIDN */
 	  |AI_NUMERICSERV|AI_ALL))
     return EAI_BADFLAGS;
 
-- 
2.11.0

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC][PATCH 0/4] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses [BZ #17083]
  2017-09-05 16:06 [RFC][PATCH 0/4][BZ 17083] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses Łukasz Stelmach
                   ` (3 preceding siblings ...)
  2017-09-05 16:06 ` [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts Łukasz Stelmach
@ 2017-09-06  5:43 ` Łukasz Stelmach
  4 siblings, 0 replies; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-06  5:43 UTC (permalink / raw)
  To: libc-alpha

Dnia 5 września 2017 18:05:26 CEST, "Łukasz Stelmach" <stlman@poczta.fm> napisał(a):
>Hello,
>
>The aim of the following patches is to enable retrieving zone
>(interface) information stored in /etc/hosts along with link-local IPv6
>addresses. This requires changes in several places in resolver and NSS.

Correct BZ reference in the subject (in case it matters).

-- 
Łukasz Stelmach z podróży

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives
  2017-09-05 16:06 ` [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives Łukasz Stelmach
@ 2017-09-11 20:01   ` DJ Delorie
  2017-09-12  8:13     ` Łukasz Stelmach
  2017-09-12 14:30     ` Joseph Myers
  0 siblings, 2 replies; 20+ messages in thread
From: DJ Delorie @ 2017-09-11 20:01 UTC (permalink / raw)
  To: stlman; +Cc: libc-alpha


ukasz Stelmach <stlman@poczta.fm> writes:
>  #if __BYTE_ORDER == __BIG_ENDIAN
>  # define htonl_c(n) n
> -#else
> +#else  /* __BYTE_ORDER == __BIG_ENDIAN */
>  # define htonl_c(n) __bswap_constant_32 (n)
> -#endif
> +#endif	/* __BYTE_ORDER == __BIG_ENDIAN */

What's our policy on inverting the logic sense in these comments when
they refer to the #else clause?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives
  2017-09-11 20:01   ` DJ Delorie
@ 2017-09-12  8:13     ` Łukasz Stelmach
  2017-09-12 14:30     ` Joseph Myers
  1 sibling, 0 replies; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-12  8:13 UTC (permalink / raw)
  To: DJ Delorie; +Cc: libc-alpha

Dnia 11 września 2017 22:01:10 CEST, DJ Delorie <dj@redhat.com> napisał(a):
>
>Łukasz Stelmach <stlman@poczta.fm> writes:
>>  #if __BYTE_ORDER == __BIG_ENDIAN
>>  # define htonl_c(n) n
>> -#else
>> +#else  /* __BYTE_ORDER == __BIG_ENDIAN */
>>  # define htonl_c(n) __bswap_constant_32 (n)
>> -#endif
>> +#endif	/* __BYTE_ORDER == __BIG_ENDIAN */
>
>What's our policy on inverting the logic sense in these comments when
>they refer to the #else clause?

If I were to answer that question (which I am not sure, because I was the first to ask a question and I don't like when people answer my questions with theirs) looking at the results of "git grep", I'd say, it is hard to tell. It appears #else-es' comments contain not-ted conditions, but the syntax is not clear.

Which one would you recommend?

/* Not __BYTE_ORDER == __BIG_ENDIAN */

/* !(__BYTE_ORDER == __BIG_ENDIAN) */

/* __BYTE_ORDER != __BIG_ENDIAN */


-- 
Łukasz Stelmach z podróży

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts
  2017-09-05 16:06 ` [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts Łukasz Stelmach
@ 2017-09-12 10:00   ` Florian Weimer
  2017-09-12 10:40     ` Łukasz Stelmach
  0 siblings, 1 reply; 20+ messages in thread
From: Florian Weimer @ 2017-09-12 10:00 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: libc-alpha

On 09/05/2017 06:05 PM, Łukasz Stelmach wrote:
> +	   ret = getaddrinfo(addr, NULL, &hints, &res);

That makes me rather nervous due to the potential for recursion.  Can we
factor out the AI_NUMERICHOST code into a separate function instead?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function
  2017-09-05 16:06 ` [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function Łukasz Stelmach
@ 2017-09-12 10:03   ` Florian Weimer
  2017-09-12 10:44     ` Łukasz Stelmach
  0 siblings, 1 reply; 20+ messages in thread
From: Florian Weimer @ 2017-09-12 10:03 UTC (permalink / raw)
  To: Łukasz Stelmach, libc-alpha

On 09/05/2017 06:05 PM, Łukasz Stelmach wrote:
> Add af (address family) to the list of arguments of gethostbyname4_r
> function in files, dns, nis and nisplus module and rename the function to
> gethostbyname5_r. Pass the af value to the underlying parsing functions.
> Define gethostbyname4_r as a wrapper for the former passing af set
> to AF_UNSPEC.

I'd prefer if we have a single ultimate name resolution function,
instead of doing function 5 now, and function 6 later, when we have
dealt with the malloc matters.

One way to deal with the dlmopen/static dlopen issue would be to define
a deallocation function which goes with the 5 function.  If this
function called free, it would automatically end up at the right definition.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts
  2017-09-12 10:00   ` Florian Weimer
@ 2017-09-12 10:40     ` Łukasz Stelmach
  2017-09-12 10:51       ` Florian Weimer
  0 siblings, 1 reply; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-12 10:40 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

Dnia 12 września 2017 12:00:28 CEST, Florian Weimer <fweimer@redhat.com> napisał(a):
>On 09/05/2017 06:05 PM, Łukasz Stelmach wrote:
>> +	   ret = getaddrinfo(addr, NULL, &hints, &res);
>
>That makes me rather nervous due to the potential for recursion.  Can
>we
>factor out the AI_NUMERICHOST code into a separate function instead?

It appears there is little code to be factored-out in gaih_inet(),
which is the workhorse. There several attempts to parse
a hostname as numeric and the flag prevents from going
further.

Yet another issue I can see, is that the factored out code
would have to be public (?) to be available to NSS module.

Now I can see there is __inet6_scopeid__pton(). I'll try it but I am
afraid  probably it won't be visible in the NSS module.

-- 
Łukasz Stelmach z podróży

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function
  2017-09-12 10:03   ` Florian Weimer
@ 2017-09-12 10:44     ` Łukasz Stelmach
  2017-09-12 11:00       ` Florian Weimer
  0 siblings, 1 reply; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-12 10:44 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

Dnia 12 września 2017 12:03:00 CEST, Florian Weimer <fweimer@redhat.com> napisał(a):
>On 09/05/2017 06:05 PM, Łukasz Stelmach wrote:
>> Add af (address family) to the list of arguments of gethostbyname4_r
>> function in files, dns, nis and nisplus module and rename the
>function to
>> gethostbyname5_r. Pass the af value to the underlying parsing
>functions.
>> Define gethostbyname4_r as a wrapper for the former passing af set
>> to AF_UNSPEC.
>
>I'd prefer if we have a single ultimate name resolution function,
>instead of doing function 5 now, and function 6 later, when we have
>dealt with the malloc matters.

This sounds like a major debate. Do you know who's in charge in this parts of glibc?

>One way to deal with the dlmopen/static dlopen issue would be to define
>a deallocation function which goes with the 5 function.  If this
>function called free, it would automatically end up at the right
>definition.

This means almost nothing to me (-; which means, probably I am not the right guy to do it. 


-- 
Łukasz Stelmach z podróży

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts
  2017-09-12 10:40     ` Łukasz Stelmach
@ 2017-09-12 10:51       ` Florian Weimer
  2017-09-13  8:19         ` Łukasz Stelmach
  0 siblings, 1 reply; 20+ messages in thread
From: Florian Weimer @ 2017-09-12 10:51 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: libc-alpha

On 09/12/2017 12:40 PM, Łukasz Stelmach wrote:
> Yet another issue I can see, is that the factored out code
> would have to be public (?) to be available to NSS module.

We have GLIBC_PRIVATE for that.

> Now I can see there is __inet6_scopeid__pton(). I'll try it but I am
> afraid  probably it won't be visible in the NSS module.

It's exported because getaddrinfo is also compiled into nscd (outside
libc) and it has to reference __inet6_scopeid__pton somehow.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function
  2017-09-12 10:44     ` Łukasz Stelmach
@ 2017-09-12 11:00       ` Florian Weimer
  2017-09-12 12:47         ` Łukasz Stelmach
  0 siblings, 1 reply; 20+ messages in thread
From: Florian Weimer @ 2017-09-12 11:00 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: libc-alpha

On 09/12/2017 12:44 PM, Łukasz Stelmach wrote:
> Dnia 12 września 2017 12:03:00 CEST, Florian Weimer <fweimer@redhat.com> napisał(a):
>> On 09/05/2017 06:05 PM, Łukasz Stelmach wrote:
>>> Add af (address family) to the list of arguments of gethostbyname4_r
>>> function in files, dns, nis and nisplus module and rename the
>> function to
>>> gethostbyname5_r. Pass the af value to the underlying parsing
>> functions.
>>> Define gethostbyname4_r as a wrapper for the former passing af set
>>> to AF_UNSPEC.
>>
>> I'd prefer if we have a single ultimate name resolution function,
>> instead of doing function 5 now, and function 6 later, when we have
>> dealt with the malloc matters.
> 
> This sounds like a major debate. Do you know who's in charge in this parts of glibc?

It's a community project.  We don't have strong component ownership.  I
have taken care of networking-related matters for some time now.

>> One way to deal with the dlmopen/static dlopen issue would be to define
>> a deallocation function which goes with the 5 function.  If this
>> function called free, it would automatically end up at the right
>> definition.
> 
> This means almost nothing to me (-; which means, probably I am not the right guy to do it. 

We currently pass a fixed-size buffer into the NSS service module.  The
NSS service module can fail with
NSS_STATUS_TRYAGAIN/NETDB_INTERNAL/ERANGE to indicate that the buffer is
too small.  The caller is supposed to try again with a larger buffer.

This is very inefficient.  It can result in a large number of DNS
queries if there are many addresses (A/AAAA over UDP, then over TCP).

We could avoid this if the NSS service module allocates space for the
result because it knows the required size.  But the module could use a
different malloc than the main program (like Windows DLLs, but for GNU,
this is a special case which does not apply to regular DSO usage).
There are two ways to fix this: The NSS module could provide a
deallocation function, or we could add a mechanism to the dynamic linker
that ensures the mallocs always match.  The second approach is quite
hard to implement.  The first approach has other benefits (e.g., the
service module could return a pointer into a cache and use reference
counting instead of direct malloc/free to manage the memory).

I don't see your name in the maintainers list on the wiki.  Since your
current patches already are substantial contribution, we need to discuss
the matter of copyright assignment:

https://sourceware.org/glibc/wiki/Contribution%20checklist#FSF_copyright_Assignment

I suggest you contact the FSF to eliminate that roadblock before working
on these patches further.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function
  2017-09-12 11:00       ` Florian Weimer
@ 2017-09-12 12:47         ` Łukasz Stelmach
  2017-09-12 17:00           ` Florian Weimer
  0 siblings, 1 reply; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-12 12:47 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

Dnia 12 września 2017 13:00:41 CEST, Florian Weimer <fweimer@redhat.com> napisał(a):

>I don't see your name in the maintainers list on the wiki.  Since your
>current patches already are substantial contribution, we need to
>discuss
>the matter of copyright assignment:
>
>https://sourceware.org/glibc/wiki/Contribution%20checklist#FSF_copyright_Assignment
>
>I suggest you contact the FSF to eliminate that roadblock before
>working
>on these patches further.

I suppose, I should send https://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/Copyright/request-assign.future. Am I right?


-- 
Łukasz Stelmach z podróży

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives
  2017-09-11 20:01   ` DJ Delorie
  2017-09-12  8:13     ` Łukasz Stelmach
@ 2017-09-12 14:30     ` Joseph Myers
  2017-09-12 14:41       ` Andreas Schwab
  1 sibling, 1 reply; 20+ messages in thread
From: Joseph Myers @ 2017-09-12 14:30 UTC (permalink / raw)
  To: DJ Delorie; +Cc: stlman, libc-alpha

On Mon, 11 Sep 2017, DJ Delorie wrote:

> ?ukasz Stelmach <stlman@poczta.fm> writes:
> >  #if __BYTE_ORDER == __BIG_ENDIAN
> >  # define htonl_c(n) n
> > -#else
> > +#else  /* __BYTE_ORDER == __BIG_ENDIAN */
> >  # define htonl_c(n) __bswap_constant_32 (n)
> > -#endif
> > +#endif	/* __BYTE_ORDER == __BIG_ENDIAN */
> 
> What's our policy on inverting the logic sense in these comments when
> they refer to the #else clause?

I'd expect comments to follow what the GNU Coding Standards say 
("@samp{#else} should have a comment describing the condition @emph{and 
sense} of the code that follows.").

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives
  2017-09-12 14:30     ` Joseph Myers
@ 2017-09-12 14:41       ` Andreas Schwab
  2017-09-12 14:51         ` Joseph Myers
  0 siblings, 1 reply; 20+ messages in thread
From: Andreas Schwab @ 2017-09-12 14:41 UTC (permalink / raw)
  To: Joseph Myers; +Cc: DJ Delorie, stlman, libc-alpha

On Sep 12 2017, Joseph Myers <joseph@codesourcery.com> wrote:

> On Mon, 11 Sep 2017, DJ Delorie wrote:
>
>> ?ukasz Stelmach <stlman@poczta.fm> writes:
>> >  #if __BYTE_ORDER == __BIG_ENDIAN
>> >  # define htonl_c(n) n
>> > -#else
>> > +#else  /* __BYTE_ORDER == __BIG_ENDIAN */
>> >  # define htonl_c(n) __bswap_constant_32 (n)
>> > -#endif
>> > +#endif	/* __BYTE_ORDER == __BIG_ENDIAN */
>> 
>> What's our policy on inverting the logic sense in these comments when
>> they refer to the #else clause?
>
> I'd expect comments to follow what the GNU Coding Standards say 
> ("@samp{#else} should have a comment describing the condition @emph{and 
> sense} of the code that follows.").

But in this case the comment only clutters the source.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives
  2017-09-12 14:41       ` Andreas Schwab
@ 2017-09-12 14:51         ` Joseph Myers
  0 siblings, 0 replies; 20+ messages in thread
From: Joseph Myers @ 2017-09-12 14:51 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: DJ Delorie, stlman, libc-alpha

On Tue, 12 Sep 2017, Andreas Schwab wrote:

> On Sep 12 2017, Joseph Myers <joseph@codesourcery.com> wrote:
> 
> > On Mon, 11 Sep 2017, DJ Delorie wrote:
> >
> >> ?ukasz Stelmach <stlman@poczta.fm> writes:
> >> >  #if __BYTE_ORDER == __BIG_ENDIAN
> >> >  # define htonl_c(n) n
> >> > -#else
> >> > +#else  /* __BYTE_ORDER == __BIG_ENDIAN */
> >> >  # define htonl_c(n) __bswap_constant_32 (n)
> >> > -#endif
> >> > +#endif	/* __BYTE_ORDER == __BIG_ENDIAN */
> >> 
> >> What's our policy on inverting the logic sense in these comments when
> >> they refer to the #else clause?
> >
> > I'd expect comments to follow what the GNU Coding Standards say 
> > ("@samp{#else} should have a comment describing the condition @emph{and 
> > sense} of the code that follows.").
> 
> But in this case the comment only clutters the source.

Yes, for a case like this where the #if contents are only one line, 
comments are unhelpful as they just duplicate the obviously visible 
semantics of the code.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function
  2017-09-12 12:47         ` Łukasz Stelmach
@ 2017-09-12 17:00           ` Florian Weimer
  0 siblings, 0 replies; 20+ messages in thread
From: Florian Weimer @ 2017-09-12 17:00 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: libc-alpha

On 09/12/2017 02:46 PM, Łukasz Stelmach wrote:
> Dnia 12 września 2017 13:00:41 CEST, Florian Weimer <fweimer@redhat.com> napisał(a):
> 
>> I don't see your name in the maintainers list on the wiki.  Since your
>> current patches already are substantial contribution, we need to
>> discuss
>> the matter of copyright assignment:
>>
>> https://sourceware.org/glibc/wiki/Contribution%20checklist#FSF_copyright_Assignment
>>
>> I suggest you contact the FSF to eliminate that roadblock before
>> working
>> on these patches further.
> 
> I suppose, I should send https://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/Copyright/request-assign.future. Am I right?

Yes, it's a valid option if you want to go that route.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts
  2017-09-12 10:51       ` Florian Weimer
@ 2017-09-13  8:19         ` Łukasz Stelmach
  0 siblings, 0 replies; 20+ messages in thread
From: Łukasz Stelmach @ 2017-09-13  8:19 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

Dnia 12 września 2017 12:51:19 CEST, Florian Weimer <fweimer@redhat.com> napisał(a):
>On 09/12/2017 12:40 PM, Łukasz Stelmach wrote:
>> Now I can see there is __inet6_scopeid__pton(). I'll try it but I am
>> afraid  probably it won't be visible in the NSS module.
>
>It's exported because getaddrinfo is also compiled into nscd (outside
>libc) and it has to reference __inet6_scopeid__pton somehow.

Yes it is visible.

I have identified the code that does what I need. This is more or less the else-if
in getaddrinfo.c:531 (commit 620ff9eea6).

Practical question: what would be the preferred way of (re)using thiscode in files-hosts.c?

-- 
Łukasz Stelmach z podróży

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2017-09-13  8:19 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 16:06 [RFC][PATCH 0/4][BZ 17083] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses Łukasz Stelmach
2017-09-05 16:06 ` [RFC][PATCH 3/4][BZ 17083] NSS: Introduce gethostbyname5_r function Łukasz Stelmach
2017-09-12 10:03   ` Florian Weimer
2017-09-12 10:44     ` Łukasz Stelmach
2017-09-12 11:00       ` Florian Weimer
2017-09-12 12:47         ` Łukasz Stelmach
2017-09-12 17:00           ` Florian Weimer
2017-09-05 16:06 ` [RFC][PATCH 1/4][BZ 17083] getaddrinfo: Add comments for #else and #endif directives Łukasz Stelmach
2017-09-11 20:01   ` DJ Delorie
2017-09-12  8:13     ` Łukasz Stelmach
2017-09-12 14:30     ` Joseph Myers
2017-09-12 14:41       ` Andreas Schwab
2017-09-12 14:51         ` Joseph Myers
2017-09-05 16:06 ` [RFC][PATCH 4/4][BZ 17083] getaddrinfo: Use the new getaddrinfo5_r NSS function Łukasz Stelmach
2017-09-05 16:06 ` [RFC][PATCH 2/4][BZ 17083] NSS: Parse zone identifier of IPv6 addresses in /etc/hosts Łukasz Stelmach
2017-09-12 10:00   ` Florian Weimer
2017-09-12 10:40     ` Łukasz Stelmach
2017-09-12 10:51       ` Florian Weimer
2017-09-13  8:19         ` Łukasz Stelmach
2017-09-06  5:43 ` [RFC][PATCH 0/4] Make getaddrinfo(3) return zone id from /etc/hosts for link-local IPv6 addresses [BZ #17083] Łukasz Stelmach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).