We had a problem whereby multiple DNS queries were being made against the same host, even if a negative result was returned the first time. This patch attempts to fix this by keeping track of which hosts returned negative responses in the retry loop in__dns_lookup(). It can significantly reduce corresponding network traffic in large networks.

Patch made against svn 22530 and included as an attachment as well as inline for review.

/Ricard



Index: libc/inet/resolv.c
===================================================================
--- libc/inet/resolv.c  (revision 22530)
+++ libc/inet/resolv.c  (working copy)
@@ -757,6 +757,7 @@
 #ifdef __UCLIBC_HAS_IPV4__
        struct sockaddr_in sa;
 #endif
+       bool negative_results[MAX_SEARCH + 1] = { 0 };

        fd = -1;

@@ -812,6 +813,9 @@
                __UCLIBC_MUTEX_UNLOCK(__resolv_lock);

                DPRINTF("lookup name: %s\n", lookup);
+               /* Do not try the same lookup again. */
+               if (variant < (MAX_SEARCH + 1) && negative_results[variant + 1])
+                       goto again;
                q.dotted = (char *)lookup;
                q.qtype = type;
                q.qclass = C_IN; /* CLASS_IN */
@@ -924,6 +928,8 @@

                if ((h.rcode) || (h.ancount < 1)) {
                        /* negative result, not present */
+                       if (variant < (MAX_SEARCH + 1))
+                               negative_results[variant + 1] = true;
                        goto again;
                }

--
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
Index: libc/inet/resolv.c
===================================================================
--- libc/inet/resolv.c	(revision 22530)
+++ libc/inet/resolv.c	(working copy)
@@ -757,6 +757,7 @@
 #ifdef __UCLIBC_HAS_IPV4__
 	struct sockaddr_in sa;
 #endif
+	bool negative_results[MAX_SEARCH + 1] = { 0 };
 
 	fd = -1;
 
@@ -812,6 +813,9 @@
 		__UCLIBC_MUTEX_UNLOCK(__resolv_lock);
 
 		DPRINTF("lookup name: %s\n", lookup);
+		/* Do not try the same lookup again. */
+		if (variant < (MAX_SEARCH + 1) && negative_results[variant + 1])
+			goto again;
 		q.dotted = (char *)lookup;
 		q.qtype = type;
 		q.qclass = C_IN; /* CLASS_IN */
@@ -924,6 +928,8 @@
 
 		if ((h.rcode) || (h.ancount < 1)) {
 			/* negative result, not present */
+			if (variant < (MAX_SEARCH + 1))
+				negative_results[variant + 1] = true;
 			goto again;
 		}
 
_______________________________________________
uClibc mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/uclibc

Reply via email to