truly use all DNS results for NS lookup
authorChristian Grothoff <christian@grothoff.org>
Sun, 13 May 2018 17:01:30 +0000 (19:01 +0200)
committerChristian Grothoff <christian@grothoff.org>
Sun, 13 May 2018 17:01:30 +0000 (19:01 +0200)
src/dns/dnsstub.c
src/gns/gnunet-service-gns_resolver.c
src/gnsrecord/gnsrecord.c

index 6eb3612c27f96dafff54b09f33ede5b70517bb1b..647ce70cc965c215608213d983c79bf377496703 100644 (file)
@@ -508,9 +508,10 @@ transmit_query (void *cls)
                                     sa,
                                     salen))
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-               _("Failed to send DNS request to %s\n"),
+               _("Failed to send DNS request to %s: %s\n"),
                GNUNET_a2s (sa,
-                            salen));
+                            salen),
+                STRERROR (errno));
   else
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                _("Sent DNS request to %s\n"),
index 92e03bc6935b4ccb4c4caff15e0aeff81e61f4b7..71d4e95d83dcdf695d996eadd5453a50c8901382 100644 (file)
@@ -109,6 +109,11 @@ struct Gns2DnsPending
    * Handle for DNS resolution of the DNS nameserver.
    */
   struct GNUNET_RESOLVER_RequestHandle *dns_rh;
+
+  /**
+   * How many results did we get?
+   */
+  unsigned int num_results;
 };
 
 
@@ -1494,26 +1499,48 @@ handle_gns2dns_ip (void *cls,
 {
   struct Gns2DnsPending *gp = cls;
   struct AuthorityChain *ac = gp->ac;
+  struct sockaddr_storage ss;
+  struct sockaddr_in *v4;
+  struct sockaddr_in6 *v6;
 
-  GNUNET_RESOLVER_request_cancel (gp->dns_rh);
-  GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
-                               ac->authority_info.dns_authority.gp_tail,
-                               gp);
-  GNUNET_free (gp);
   if (NULL == addr)
   {
-    /* DNS resolution failed */
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Failed to use DNS to resolve name of DNS resolver\n");
+    /* DNS resolution finished */
+    if (0 == gp->num_results)
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "Failed to use DNS to resolve name of DNS resolver\n");
+    GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
+                                 ac->authority_info.dns_authority.gp_tail,
+                                 gp);
+    GNUNET_free (gp);
+    continue_with_gns2dns (ac);
+    return;
   }
-  else
+  memcpy (&ss,
+          addr,
+          addrlen);
+  switch (ss.ss_family)
   {
-    if (GNUNET_OK ==
-        GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
-                                   addr))
-      ac->authority_info.dns_authority.found = GNUNET_YES;
+  case AF_INET:
+    v4 = (struct sockaddr_in *) &ss;
+    v4->sin_port = htons (53);
+    gp->num_results++;
+    break;
+  case AF_INET6:
+    v6 = (struct sockaddr_in6 *) &ss;
+    v6->sin6_port = htons (53);
+    gp->num_results++;
+    break;
+  default:
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unsupported AF %d\n",
+                ss.ss_family);
+    return;
   }
-  continue_with_gns2dns (ac);
+  if (GNUNET_OK ==
+      GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
+                                 (struct sockaddr *) &ss))
+    ac->authority_info.dns_authority.found = GNUNET_YES;
 }
 
 
index 35005b5ca826354cac6c2deffe7d78820d8030fb..8fc039fc6ace5e60d4a17c4d677b8e32f076c4e2 100644 (file)
@@ -207,7 +207,6 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type,
 uint32_t
 GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
 {
-  unsigned int i;
   struct Plugin *plugin;
   uint32_t ret;
 
@@ -215,7 +214,7 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
                        "ANY"))
     return GNUNET_GNSRECORD_TYPE_ANY;
   init ();
-  for (i = 0; i < num_plugins; i++)
+  for (unsigned int i = 0; i < num_plugins; i++)
   {
     plugin = gns_plugins[i];
     if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,