]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/ndb/dnresolve.c
ndb/dns: double Maxretries for long cname redirection chains
[plan9front.git] / sys / src / cmd / ndb / dnresolve.c
index 7ca39619b211df88054a02538f47282e269dcfbc..3e700e5b60e422146b8b6701d1a8d60178eba536 100644 (file)
@@ -20,20 +20,14 @@ enum
 
        Maxdest=        24,     /* maximum destinations for a request message */
        Maxoutstanding= 15,     /* max. outstanding queries per domain name */
-       Remntretry=     15,     /* min. sec.s between /net.alt remount tries */
 
        /*
         * these are the old values; we're trying longer timeouts now
         * primarily for the benefit of remote nameservers querying us
         * during times of bad connectivity.
         */
-//     Maxtrans=       3,      /* maximum transmissions to a server */
-//     Maxretries=     3, /* cname+actual resends: was 32; have pity on user */
-//     Maxwaitms=      1000,   /* wait no longer for a remote dns query */
-//     Minwaitms=      100,    /* willing to wait for a remote dns query */
-
        Maxtrans=       5,      /* maximum transmissions to a server */
-       Maxretries=     5, /* cname+actual resends: was 32; have pity on user */
+       Maxretries=     10,     /* cname+actual resends: was 32; have pity on user */
        Maxwaitms=      5000,   /* wait no longer for a remote dns query */
        Minwaitms=      500,    /* willing to wait for a remote dns query */
 };
@@ -177,7 +171,7 @@ dnresolve(char *name, int class, int type, Request *req, RR **cn, int depth,
         *  try the name directly
         */
        rp = dnresolve1(name, class, type, req, depth, recurse);
-       if(rp == nil && (dp = dnlookup(name, class, 0)) != nil) {
+       if(rp == nil && (dp = idnlookup(name, class, 0)) != nil) {
                /*
                 * try it as a canonical name if we weren't told
                 * that the name didn't exist
@@ -348,7 +342,7 @@ issuequery(Query *qp, char *name, int class, int depth, int recurse)
                }
 
                /* look for ns in cache */
-               nsdp = dnlookup(cp, class, 0);
+               nsdp = idnlookup(cp, class, 0);
                nsrp = nil;
                if(nsdp)
                        nsrp = randomize(rrlookup(nsdp, Tns, NOneg));
@@ -387,7 +381,7 @@ dnresolve1(char *name, int class, int type, Request *req, int depth,
        if(class != Cin)
                return nil;
 
-       dp = dnlookup(name, class, 1);
+       dp = idnlookup(name, class, 1);
 
        /*
         *  Try the cache first
@@ -814,6 +808,7 @@ serveraddrs(Query *qp, int nd, int depth)
         */
        if(arp == 0){
                for(rp = qp->nsrp; rp; rp = rp->next)
+                       if(rp->marker == 0)
                        if(queryloops(qp, rp))
                                /*
                                 * give up as we should have got the address
@@ -1228,11 +1223,12 @@ procansw(Query *qp, DNSmsg *mp, int depth, Dest *p)
        }
 
        /*
-        *  Any reply from an authoritative server,
+        *  Any reply from an authoritative server
+        *  that does not provide more nameservers,
         *  or a positive reply terminates the search.
         *  A negative response now also terminates the search.
         */
-       if(mp->an != nil || (mp->flags & Fauth)){
+       if(mp->an || (mp->flags & Fauth) && mp->ns == nil){
                if(isnegrname(mp))
                        qp->dp->respcode = Rname;
                else
@@ -1266,7 +1262,7 @@ procansw(Query *qp, DNSmsg *mp, int depth, Dest *p)
         *  if we're a pure resolver, don't recurse, we have
         *  to forward to a fixed set of named servers.
         */
-       if(!mp->ns || cfg.resolver && cfg.justforw)
+       if(mp->ns == nil || cfg.resolver && cfg.justforw)
                return Answnone;
        tp = rrlookup(ndp, Tns, NOneg);
        if(contains(qp->nsrp, tp)){
@@ -1325,16 +1321,22 @@ tcpquery(Query *qp, DNSmsg *mp, int depth, uchar *ibuf, uchar *obuf, int len,
 static int
 queryns(Query *qp, int depth, uchar *ibuf, uchar *obuf, ulong waitms, int inns)
 {
-       int ndest, len, replywaits, rv;
+       int ndest, len, replywaits, rv, flag;
        ushort req;
        uvlong endms;
        char buf[32];
        uchar srcip[IPaddrlen];
        Dest *p, *np, dest[Maxdest];
 
-       /* pack request into a udp message */
        req = rand();
-       len = mkreq(qp->dp, qp->type, obuf, Frecurse|Oquery, req);
+
+       /* request recursion only for local dns servers */
+       flag = Oquery;
+       if(strncmp(qp->nsrp->owner->name, "local#", 6) == 0)
+               flag |= Frecurse;
+
+       /* pack request into a udp message */
+       len = mkreq(qp->dp, qp->type, obuf, flag, req);
 
        /* no server addresses yet */
        memset(dest, 0, sizeof dest);
@@ -1419,31 +1421,6 @@ queryns(Query *qp, int depth, uchar *ibuf, uchar *obuf, ulong waitms, int inns)
        return Answnone;
 }
 
-/*
- *  run a command with a supplied fd as standard input
- */
-char *
-system(int fd, char *cmd)
-{
-       int pid, p, i;
-       static Waitmsg msg;
-
-       if((pid = fork()) == -1)
-               sysfatal("fork failed: %r");
-       else if(pid == 0){
-               dup(fd, 0);
-               close(fd);
-               for (i = 3; i < 200; i++)
-                       close(i);               /* don't leak fds */
-               execl("/bin/rc", "rc", "-c", cmd, nil);
-               sysfatal("exec rc: %r");
-       }
-       for(p = waitpid(); p >= 0; p = waitpid())
-               if(p == pid)
-                       return msg.msg;
-       return "lost child";
-}
-
 /* compute wait, weighted by probability of success, with bounds */
 static ulong
 weight(ulong ms, unsigned pcntprob)
@@ -1467,13 +1444,9 @@ static int
 udpquery(Query *qp, char *mntpt, int depth, int patient, int inns)
 {
        int fd, rv;
-       long now;
        ulong pcntprob;
        uvlong wait, reqtm;
-       char *msg;
        uchar *obuf, *ibuf;
-       static QLock mntlck;
-       static ulong lastmount;
 
        rv = -1;
 
@@ -1482,29 +1455,6 @@ udpquery(Query *qp, char *mntpt, int depth, int patient, int inns)
        obuf = emalloc(Maxudp+Udphdrsize);
 
        fd = udpport(mntpt);
-       while (fd < 0 && cfg.straddle && strcmp(mntpt, "/net.alt") == 0) {
-               /* HACK: remount /net.alt */
-               now = time(nil);
-               if (now < lastmount + Remntretry)
-                       sleep(S2MS(lastmount + Remntretry - now));
-               qlock(&mntlck);
-               fd = udpport(mntpt);    /* try again under lock */
-               if (fd < 0) {
-                       dnslog("[%d] remounting /net.alt", getpid());
-                       unmount(nil, "/net.alt");
-
-                       msg = system(open("/dev/null", ORDWR), "outside");
-
-                       lastmount = time(nil);
-                       if (msg && *msg) {
-                               dnslog("[%d] can't remount /net.alt: %s",
-                                       getpid(), msg);
-                               sleep(10*1000); /* don't spin remounting */
-                       } else
-                               fd = udpport(mntpt);
-               }
-               qunlock(&mntlck);
-       }
        if (fd < 0) {
                dnslog("can't get udpport for %s query of name %s: %r",
                        mntpt, qp->dp->name);