dns changes

This commit is contained in:
rsc 2006-02-20 19:38:29 +00:00
parent 772b39cd98
commit 49a1496cbb
9 changed files with 61 additions and 48 deletions

View file

@ -1183,8 +1183,8 @@ warning(char *fmt, ...)
void void
dncheck(void *p, int dolock) dncheck(void *p, int dolock)
{ {
int i;
DN *dp; DN *dp;
int i;
RR *rp; RR *rp;
if(p != nil){ if(p != nil){

View file

@ -278,17 +278,6 @@ mkreq(DN *dp, int type, uchar *buf, int flags, ushort reqno)
return len; 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 static void
freeanswers(DNSmsg *mp) freeanswers(DNSmsg *mp)
{ {
@ -301,6 +290,7 @@ freeanswers(DNSmsg *mp)
/* /*
* read replies to a request. ignore any of the wrong type. wait at most 5 seconds. * 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 static int
readreply(int fd, DN *dp, int type, ushort req, readreply(int fd, DN *dp, int type, ushort req,
uchar *ibuf, DNSmsg *mp, ulong endtime, Request *reqp) uchar *ibuf, DNSmsg *mp, ulong endtime, Request *reqp)
@ -310,17 +300,13 @@ readreply(int fd, DN *dp, int type, ushort req,
ulong now; ulong now;
RR *rp; RR *rp;
notify(ding);
for(; ; freeanswers(mp)){ for(; ; freeanswers(mp)){
now = time(0); now = time(0);
if(now >= endtime) if(now >= endtime)
return -1; /* timed out */ return -1; /* timed out */
/* timed read */ /* timed read */
alarm((endtime - now) * 1000); len = udpreadtimeout(fd, (Udphdr*)ibuf, ibuf+Udphdrsize, Maxudpin, (endtime-now)*1000);
len = udpread(fd, (Udphdr*)ibuf, ibuf+Udphdrsize, Maxudpin);
alarm(0);
if(len < 0) if(len < 0)
return -1; /* timed out */ return -1; /* timed out */
@ -365,6 +351,23 @@ readreply(int fd, DN *dp, int type, ushort req,
return 0; /* never reached */ 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 * return non-0 if first list includes second list
*/ */

View file

@ -96,7 +96,8 @@ Job* newjob(void);
void freejob(Job*); void freejob(Job*);
void setext(char*, int, char*); void setext(char*, int, char*);
char *portname = "domain"; char *tcpaddr = "tcp!*!dns";
char *udpaddr = "udp!*!dns";
char *logfile = "dns"; char *logfile = "dns";
char *dbfile; char *dbfile;
char mntpt[Maxpath]; char mntpt[Maxpath];
@ -105,10 +106,21 @@ char *LOG;
void void
usage(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"); 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 void
threadmain(int argc, char *argv[]) threadmain(int argc, char *argv[])
{ {
@ -136,28 +148,33 @@ threadmain(int argc, char *argv[])
serveudp = 1; serveudp = 1;
cachedb = 1; cachedb = 1;
break; break;
case 'T': case 't':
servetcp = 1; servetcp = 1;
cachedb = 1; cachedb = 1;
break; break;
case 'a': case 'a':
maxage = atoi(EARGF(usage())); maxage = atoi(EARGF(usage()));
break; break;
case 't':
testing = 1;
break;
case 'z': case 'z':
zonerefreshprogram = EARGF(usage()); zonerefreshprogram = EARGF(usage());
break; break;
case 'p':
portname = EARGF(usage());
break;
case 'n': case 'n':
sendnotifies = 1; sendnotifies = 1;
break; break;
case 'U':
udpaddr = estrdup(netmkaddr(EARGF(usage()), "udp", "dns"));
break;
case 'T':
tcpaddr = estrdup(netmkaddr(EARGF(usage()), "tcp", "dns"));
break;
default:
usage();
}ARGEND }ARGEND
USED(argc);
USED(argv); if(argc)
usage();
if(serveudp && servetcp)
checkaddress();
rfork(RFNOTEG); rfork(RFNOTEG);

View file

@ -402,8 +402,10 @@ extern ulong now; /* time base */
extern Area *owned; extern Area *owned;
extern Area *delegated; extern Area *delegated;
extern char *portname; extern char *udpaddr;
extern char *tcpaddr;
#ifdef VARARGCK
#pragma varargck type "R" RR* #pragma varargck type "R" RR*
#pragma varargck type "Q" RR* #pragma varargck type "Q" RR*
#endif

View file

@ -33,7 +33,8 @@ char *logfile = "dns";
char *dbfile; char *dbfile;
char mntpt[Maxpath]; char mntpt[Maxpath];
char *zonerefreshprogram; char *zonerefreshprogram;
char *portname = "domain"; char *tcpaddr;
char *udpaddr;
int prettyrrfmt(Fmt*); int prettyrrfmt(Fmt*);
void preloadserveraddrs(void); void preloadserveraddrs(void);
@ -45,7 +46,7 @@ void docmd(int, char**);
void void
usage(void) usage(void)
{ {
fprint(2, "usage: dnsdebug -rxf [-p port] [query ...]\n"); fprint(2, "usage: dnsdebug [-fr] [query ...]\n");
threadexitsall("usage"); threadexitsall("usage");
} }
@ -63,16 +64,9 @@ threadmain(int argc, char *argv[])
case 'r': case 'r':
resolver = 1; resolver = 1;
break; break;
case 'x':
dbfile = "/lib/ndb/external";
strcpy(mntpt, "/net.alt");
break;
case 'f': case 'f':
dbfile = EARGF(usage()); dbfile = EARGF(usage());
break; break;
case 'p':
portname = EARGF(usage());
break;
default: default:
usage(); usage();
}ARGEND }ARGEND

View file

@ -10,7 +10,7 @@
void void
usage(void) usage(void)
{ {
fprint(2, "usage: dnsquery [-x dns]\n"); fprint(2, "usage: dnsquery [-x service]\n");
threadexitsall("usage"); threadexitsall("usage");
} }

View file

@ -25,7 +25,8 @@ int maxage;
uchar ipaddr[IPaddrlen]; /* my ip address */ uchar ipaddr[IPaddrlen]; /* my ip address */
char *LOG; char *LOG;
char *zonerefreshprogram; char *zonerefreshprogram;
char *portname = "domain"; char *tcpaddr;
char *udpaddr;
void void
usage(void) usage(void)

View file

@ -269,12 +269,10 @@ static int
tcpannounce(char *mntpt) tcpannounce(char *mntpt)
{ {
int fd; int fd;
char an[40];
USED(mntpt); USED(mntpt);
snprint(an, sizeof an, "tcp!*!%s", portname); if((fd=announce(tcpaddr, adir)) < 0)
if((fd=announce(an, adir)) < 0) warning("announce %s: %r", tcpaddr);
warning("announce %s: %r", an);
return fd; return fd;
} }

View file

@ -160,11 +160,9 @@ udpannounce(char *mntpt)
{ {
int fd; int fd;
char buf[40]; char buf[40];
USED(mntpt); USED(mntpt);
snprint(buf, sizeof buf, "udp!*!%s", portname); if((fd=announce(udpaddr, buf)) < 0)
if((fd=announce(buf, buf)) < 0)
warning("announce %s: %r", buf); warning("announce %s: %r", buf);
return fd; return fd;
} }