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
dncheck(void *p, int dolock)
{
int i;
DN *dp;
int i;
RR *rp;
if(p != nil){

View file

@ -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)
{
@ -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)
@ -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 */
@ -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
*/

View file

@ -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];
@ -105,10 +106,21 @@ 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[])
{
@ -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);

View file

@ -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

View file

@ -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);
@ -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");
}
@ -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

View file

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

View file

@ -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)

View file

@ -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;
}

View file

@ -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;
}