[PATCH] Fix multiple DNS queries when negative results returned
Ricard Wanderlof
ricard.wanderlof at axis.com
Fri Jun 27 11:35:16 UTC 2008
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: resolv.c.negresults.patch
Type: text/x-diff
Size: 865 bytes
Desc: Patch file
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20080627/32203b21/attachment.bin
More information about the uClibc
mailing list