tdns changes - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 49a1496cbbb871bc623cfd0925566628e246c9ba
parent 772b39cd98587a1ac72a4876bb5aac9e7a498f36
Author: rsc 
Date:   Mon, 20 Feb 2006 19:38:29 +0000

dns changes

Diffstat:
  M src/cmd/ndb/dn.c                    |       2 +-
  M src/cmd/ndb/dnresolve.c             |      35 +++++++++++++++++--------------
  M src/cmd/ndb/dns.c                   |      39 ++++++++++++++++++++++---------
  M src/cmd/ndb/dns.h                   |       6 ++++--
  M src/cmd/ndb/dnsdebug.c              |      12 +++---------
  M src/cmd/ndb/dnsquery.c              |       2 +-
  M src/cmd/ndb/dnstcp.c                |       3 ++-
  M src/cmd/ndb/dntcpserver.c           |       6 ++----
  M src/cmd/ndb/dnudpserver.c           |       4 +---

9 files changed, 61 insertions(+), 48 deletions(-)
---
diff --git a/src/cmd/ndb/dn.c b/src/cmd/ndb/dn.c
t@@ -1183,8 +1183,8 @@ warning(char *fmt, ...)
 void
 dncheck(void *p, int dolock)
 {
-        int i;
         DN *dp;
+        int i;
         RR *rp;
 
         if(p != nil){
diff --git a/src/cmd/ndb/dnresolve.c b/src/cmd/ndb/dnresolve.c
t@@ -278,17 +278,6 @@ mkreq(DN *dp, int type, uchar *buf, int flags, ushort reqno)
         return len;
 }
 
-/* for alarms in readreply */
-static void
-ding(void *x, char *msg)
-{
-        USED(x);
-        if(strcmp(msg, "alarm") == 0)
-                noted(NCONT);
-        else
-                noted(NDFLT);
-}
-
 static void
 freeanswers(DNSmsg *mp)
 {
t@@ -301,6 +290,7 @@ freeanswers(DNSmsg *mp)
 /*
  *  read replies to a request.  ignore any of the wrong type.  wait at most 5 seconds.
  */
+static int udpreadtimeout(int, Udphdr*, void*, int, int);
 static int
 readreply(int fd, DN *dp, int type, ushort req,
           uchar *ibuf, DNSmsg *mp, ulong endtime, Request *reqp)
t@@ -310,17 +300,13 @@ readreply(int fd, DN *dp, int type, ushort req,
         ulong now;
         RR *rp;
 
-        notify(ding);
-
         for(; ; freeanswers(mp)){
                 now = time(0);
                 if(now >= endtime)
                         return -1;        /* timed out */
 
                 /* timed read */
-                alarm((endtime - now) * 1000);
-                len = udpread(fd, (Udphdr*)ibuf, ibuf+Udphdrsize, Maxudpin);
-                alarm(0);
+                len = udpreadtimeout(fd, (Udphdr*)ibuf, ibuf+Udphdrsize, Maxudpin, (endtime-now)*1000);
                 if(len < 0)
                         return -1;        /* timed out */
                 
t@@ -365,6 +351,23 @@ readreply(int fd, DN *dp, int type, ushort req,
         return 0;        /* never reached */
 }
 
+static int
+udpreadtimeout(int fd, Udphdr *h, void *data, int n, int ms)
+{
+        fd_set rd;
+        struct timeval tv;
+        
+        FD_ZERO(&rd);
+        FD_SET(fd, &rd);
+        
+        tv.tv_sec = ms/1000;
+        tv.tv_usec = (ms%1000)*1000;
+        
+        if(select(fd+1, &rd, 0, 0, &tv) != 1)
+                return -1;
+        return udpread(fd, h, data, n);
+}
+
 /*
  *        return non-0 if first list includes second list
  */
diff --git a/src/cmd/ndb/dns.c b/src/cmd/ndb/dns.c
t@@ -96,7 +96,8 @@ Job*        newjob(void);
 void        freejob(Job*);
 void        setext(char*, int, char*);
 
-char         *portname = "domain";
+char *tcpaddr = "tcp!*!dns";
+char *udpaddr = "udp!*!dns";
 char        *logfile = "dns";
 char        *dbfile;
 char        mntpt[Maxpath];
t@@ -105,11 +106,22 @@ char        *LOG;
 void
 usage(void)
 {
-        fprint(2, "usage: dns [-dnrstT] [-a maxage] [-f ndb-file] [-p port] [-x service] [-z zoneprog]\n");
+        fprint(2, "usage: dns [-dnrst] [-a maxage] [-f ndb-file] [-p port] [-T tcpaddr] [-U udpaddr] [-x service] [-z zoneprog]\n");
         threadexitsall("usage");
 }
 
 void
+checkaddress(void)
+{
+        char *u, *t;
+
+        u = strchr(udpaddr, '!');
+        t = strchr(tcpaddr, '!');
+        if(u && t && strcmp(u, t) != 0)
+                fprint(2, "warning: announce mismatch %s %s\n", udpaddr, tcpaddr);
+}
+
+void
 threadmain(int argc, char *argv[])
 {
         int serveudp, servetcp;
t@@ -136,28 +148,33 @@ threadmain(int argc, char *argv[])
                 serveudp = 1;
                 cachedb = 1;
                 break;
-        case 'T':
+        case 't':
                 servetcp = 1;
                 cachedb = 1;
                 break;
         case 'a':
                 maxage = atoi(EARGF(usage()));
                 break;
-        case 't':
-                testing = 1;
-                break;
         case 'z':
                 zonerefreshprogram = EARGF(usage());
                 break;
-        case 'p':
-                portname = EARGF(usage());
-                break;
         case 'n':
                 sendnotifies = 1;
                 break;
+        case 'U':
+                udpaddr = estrdup(netmkaddr(EARGF(usage()), "udp", "dns"));
+                break;
+        case 'T':
+                tcpaddr = estrdup(netmkaddr(EARGF(usage()), "tcp", "dns"));
+                break;
+        default:
+                usage();
         }ARGEND
-        USED(argc);
-        USED(argv);
+        
+        if(argc)
+                usage();
+        if(serveudp && servetcp)
+                checkaddress();
 
         rfork(RFNOTEG);
 
diff --git a/src/cmd/ndb/dns.h b/src/cmd/ndb/dns.h
t@@ -402,8 +402,10 @@ extern ulong        now;                /* time base */
 extern Area        *owned;
 extern Area        *delegated;
 
-extern char        *portname;
+extern char        *udpaddr;
+extern char        *tcpaddr;
 
+#ifdef VARARGCK
 #pragma        varargck        type        "R"        RR*
 #pragma        varargck        type        "Q"        RR*
-
+#endif
diff --git a/src/cmd/ndb/dnsdebug.c b/src/cmd/ndb/dnsdebug.c
t@@ -33,7 +33,8 @@ char        *logfile = "dns";
 char        *dbfile;
 char        mntpt[Maxpath];
 char        *zonerefreshprogram;
-char *portname = "domain";
+char *tcpaddr;
+char *udpaddr;
 
 int prettyrrfmt(Fmt*);
 void preloadserveraddrs(void);
t@@ -45,7 +46,7 @@ void docmd(int, char**);
 void
 usage(void)
 {
-        fprint(2, "usage: dnsdebug -rxf [-p port] [query ...]\n");
+        fprint(2, "usage: dnsdebug [-fr] [query ...]\n");
         threadexitsall("usage");
 }
 
t@@ -63,16 +64,9 @@ threadmain(int argc, char *argv[])
         case 'r':
                 resolver = 1;
                 break;
-        case 'x':
-                dbfile = "/lib/ndb/external";
-                strcpy(mntpt, "/net.alt");
-                break;
         case 'f':
                 dbfile = EARGF(usage());
                 break;
-        case 'p':
-                portname = EARGF(usage());
-                break;
         default:
                 usage();
         }ARGEND
diff --git a/src/cmd/ndb/dnsquery.c b/src/cmd/ndb/dnsquery.c
t@@ -10,7 +10,7 @@
 void
 usage(void)
 {
-        fprint(2, "usage: dnsquery [-x dns]\n");
+        fprint(2, "usage: dnsquery [-x service]\n");
         threadexitsall("usage");
 }
 
diff --git a/src/cmd/ndb/dnstcp.c b/src/cmd/ndb/dnstcp.c
t@@ -25,7 +25,8 @@ int        maxage;
 uchar        ipaddr[IPaddrlen];        /* my ip address */
 char        *LOG;
 char        *zonerefreshprogram;
-char        *portname = "domain";
+char        *tcpaddr;
+char        *udpaddr;
 
 void
 usage(void)
diff --git a/src/cmd/ndb/dntcpserver.c b/src/cmd/ndb/dntcpserver.c
t@@ -269,12 +269,10 @@ static int
 tcpannounce(char *mntpt)
 {
         int fd;
-        char an[40];
         
         USED(mntpt);
-        snprint(an, sizeof an, "tcp!*!%s", portname);
-        if((fd=announce(an, adir)) < 0)
-                warning("announce %s: %r", an);
+        if((fd=announce(tcpaddr, adir)) < 0)
+                warning("announce %s: %r", tcpaddr);
         return fd;
 }
 
diff --git a/src/cmd/ndb/dnudpserver.c b/src/cmd/ndb/dnudpserver.c
t@@ -160,11 +160,9 @@ udpannounce(char *mntpt)
 {
         int fd;
         char buf[40];
-        
         USED(mntpt);
 
-        snprint(buf, sizeof buf, "udp!*!%s", portname);
-        if((fd=announce(buf, buf)) < 0)
+        if((fd=announce(udpaddr, buf)) < 0)
                 warning("announce %s: %r", buf);
         return fd;
 }