소스 검색

Imre Sunyi writes:

Hi Erik

I have corrected a bug in uClibc/libc/inet/resolv.c in function
__dns_lookup(). Have attaced a txt file with my diffs regarding to
uClibc 0.9.26.

If two nameservers are included in /etc/resolv.conf and the first one is
wrong and the secondary is correct the algorithm never
looked up the secondary one. Please review my diff and feel free to
submit the patch onto your CVS.

If reading manual page resolv.conf(5) under nameserver and how the
algorithm should work the previous dns_lookup did not fully followed
that.

Regards

Imre Sunyi
Eric Andersen 22 년 전
부모
커밋
48cfeab44c
1개의 변경된 파일16개의 추가작업 그리고 11개의 파일을 삭제
  1. 16 11
      libc/inet/resolv.c

+ 16 - 11
libc/inet/resolv.c

@@ -687,7 +687,7 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
 	ns %= nscount;
 	UNLOCK;
 
-	while (retries++ < MAX_RETRIES) {
+	while (retries < MAX_RETRIES) {
 		if (fd != -1)
 			close(fd);
 
@@ -732,7 +732,7 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
 		len = i + j;
 
 		DPRINTF("On try %d, sending query to port %d of machine %s\n",
-				retries, NAMESERVER_PORT, dns);
+				retries+1, NAMESERVER_PORT, dns);
 
 #ifdef __UCLIBC_HAS_IPV6__
 		v6 = inet_pton(AF_INET6, dns, &sa6.sin6_addr) > 0;
@@ -741,6 +741,7 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
 		fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 #endif
 		if (fd < 0) {
+                    retries++;
 		    continue;
 		}
 
@@ -766,6 +767,7 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
 			goto tryall;
 		    } else
 			/* retry */
+                        retries++;
 			continue;
 		}
 
@@ -783,7 +785,7 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
 
 			/* timed out, so retry send and receive, 
 			 * to next nameserver on queue */
-			goto again;
+			goto tryall;
 		}
 
 		i = recv(fd, packet, 512, 0);
@@ -861,14 +863,14 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
 		/* if there are other nameservers, give them a go,
 		   otherwise return with error */
 		{
-		    int sdomains;
-
-		    BIGLOCK;
-		    sdomains=__searchdomains;
-		    BIGUNLOCK;
 		    variant = 0;
-		    if (retries >= nscount*(sdomains+1))
-			goto fail;
+                    LOCK;
+                    ns = (ns + 1) % nscount;
+                    if (ns == 0)
+                      retries++;
+
+                    UNLOCK;
+                    continue;
 		}
 
 	  again:
@@ -879,13 +881,16 @@ int __dns_lookup(const char *name, int type, int nscount, char **nsip,
 		    sdomains=__searchdomains;
 		    BIGUNLOCK;
 
-		    if (variant < sdomains) {
+		    if (variant < ((sdomains - 1) && strchr(lookup, '.') == NULL)) {
 			/* next search */
 			variant++;
 		    } else {
 			/* next server, first search */
 			LOCK;
 			ns = (ns + 1) % nscount;
+                        if (ns == 0)
+                          retries++;
+
 			UNLOCK;
 			variant = 0;
 		    }