Date: Tue, 6 Jan 1998 12:16:12 +0100 (CET) From: sparky@tccn.cs.kun.nl To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/5444: ypserv uses wrong dns lookup order Message-ID: <199801061116.MAA26525@tccn.cs.kun.nl> Resent-Message-ID: <199801082231.OAA09587@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 5444 >Category: bin >Synopsis: ypserv uses wrong dns lookup order >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Jan 8 14:31:55 PST 1998 >Last-Modified: >Originator: Franc Grootjen and Kees Jan Koster >Organization: University of Nijmegen, The Netherlands >Release: FreeBSD 2.2.2-RELEASE i386 >Environment: A local network (at home) with a few arcane architectures (PDP11, Sun3, VAX), a up to date Pentium FreeBSD server (DNS, NIS) and a masquerading gateway to the internet. >Description: A ping to a (short named) local host on a NIS client leads to an unreasonable long timeout. A fully qualified hostname (that is including the local domainname) works without problems. >How-To-Repeat: Set up a FreeBSD NIS server (use ypserv -n). Configure a NIS client so that it will _not_ perform DNS queries on its own (a Sun3 always uses NIS or YP to resolve hosts). Ping a local (short named) host on your local net (for example 'charon'). Watch the debug output from 'named' running on your FreeBSD machine. You'll see ypserv querying 'charon' and 'charon.my.domain' in that order. If you configured your local name server to resolve '.my.domain' hosts, and forward all other queries to a name server on the internet, this particular search order can lead to long timeouts (especially if the gateway is not connected to the internet). Ping a local (short named) host on your FreeBSD box. You'll notice that the libc resolver routines will first try to resolv 'charon.my.domain' and if that fails 'charon'. >Fix: Inspection of the ypserv code reveals that ypserv does _not_ use libc to resolve dns queries (to prevent recursion), but calls 'named' on its own. The following patch to yp_dnslookup.c will change the query order (first the specified search domains from /etc/resolv.conf, followed by the plain name). *** yp_dnslookup.c.orig Sun Jan 4 00:39:27 1998 --- yp_dnslookup.c Sun Jan 4 00:44:44 1998 *************** *** 382,401 **** hent = __dns_getanswer(buf, rval, q->name, q->type); /* ! * If the lookup failed, try appending one of the domains ! * from resolv.conf. If we have no domains to test, the * query has failed. */ if (hent == NULL) { ! if (h_errno == TRY_AGAIN && q->domain && *q->domain) { ! snprintf(retrybuf, sizeof(retrybuf), "%s.%s", ! q->name, *q->domain); ! if (debug) ! yp_error("Retrying with: %s", retrybuf); ! q->id = yp_send_dns_query(retrybuf, q->type); ! q->ttl = DEF_TTL; ! q->domain++; ! return; } } else { if (q->type == T_PTR) { --- 382,411 ---- hent = __dns_getanswer(buf, rval, q->name, q->type); /* ! * If the lookup failed, try appending one of the other domains ! * from resolv.conf. End the search trying the plain name. ! * If we have no domains to test (q->domain==NULL), the * query has failed. */ if (hent == NULL) { ! if (h_errno == TRY_AGAIN && q->domain) ! { ! if(*q->domain) /* domains left? */ ! { ! snprintf(retrybuf, sizeof(retrybuf), "%s.%s",q->name, *q->domain); ! q->domain++; ! if (debug) ! yp_error("Retrying with: %s", retrybuf); ! } else /* try plain name */ ! { ! strcpy(retrybuf,q->name); ! q->domain=NULL; ! if(debug) ! yp_error("Last resort: %s", retrybuf); ! } ! q->id = yp_send_dns_query(retrybuf, q->type); ! q->ttl = DEF_TTL; ! return; } } else { if (q->type == T_PTR) { *************** *** 426,431 **** --- 436,442 ---- { register struct circleq_dnsentry *q; int type, len; + char buf[MAXHOSTNAMELEN]; /* Check for SOCK_DGRAM or SOCK_STREAM -- we need to know later */ type = -1; len = sizeof(type); *************** *** 451,461 **** if (q->prot_type == SOCK_DGRAM) q->xid = svcudp_get_xid(q->xprt); q->client_addr = q->xprt->xp_raddr; if (!strchr(name, '.')) q->domain = _res.dnsrch; ! else q->domain = NULL; ! q->id = yp_send_dns_query(name, q->type); if (q->id == 0) { yp_error("DNS query failed"); --- 462,491 ---- if (q->prot_type == SOCK_DGRAM) q->xid = svcudp_get_xid(q->xprt); q->client_addr = q->xprt->xp_raddr; + if (!strchr(name, '.')) + { /* Dotless hostname */ q->domain = _res.dnsrch; ! if(*q->domain) ! { /* There is a search domain... add first */ ! snprintf(buf, sizeof(buf), "%s.%s",name, *q->domain); ! q->domain++; ! } else /* No search domain, use name */ ! { ! strcpy(buf,name); ! q->domain=NULL; ! } ! } ! else /* hostname with dot(s), use name */ ! { ! strcpy(buf,name); q->domain = NULL; ! } ! ! if (debug) ! yp_error("Trying: %s", buf); ! ! q->id = yp_send_dns_query(buf, q->type); if (q->id == 0) { yp_error("DNS query failed"); >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199801061116.MAA26525>