This commit is contained in:
aiju 2018-05-24 13:41:08 +01:00
commit 1984f6813c
5 changed files with 90 additions and 99 deletions

View file

@ -49,7 +49,7 @@ query, ipquery, mkhash, mkdb, mkhosts, cs, csquery, dns, dnstcp, dnsquery, dnsde
.B -s
]
[
.I server
.I /net/cs
[
.I addr...
]
@ -91,6 +91,8 @@ query, ipquery, mkhash, mkdb, mkhosts, cs, csquery, dns, dnstcp, dnsquery, dnsde
.B ndb/dnsquery
[
.B -x
] [
.I /net/dns
]
.br
.B ndb/dnsdebug

View file

@ -535,7 +535,7 @@ mathemu(Ureg *ureg, void*)
case FPinit:
fpinit();
index = up->fpstate >> FPindexs;
if(index < 0 || index > FPindexm)
if(index < 0 || index > (FPindexm>>FPindexs))
panic("fpslot index overflow: %d", index);
if(userureg(ureg)){
if(index != 0)
@ -684,7 +684,7 @@ procsave(Proc *p)
* emulation fault to activate the FPU.
*/
fpsave(p->fpsave);
p->fpstate = FPinactive | (p->fpstate & (FPpush|FPnouser|FPkernel|FPindexm));
p->fpstate = FPinactive | (p->fpstate & ~FPactive);
break;
}
@ -729,7 +729,8 @@ fpurestore(int ostate)
if((astate & ~(FPnouser|FPkernel|FPindexm)) == FPactive)
_stts();
up->fpsave = up->fpslot[ostate>>FPindexs];
ostate = FPinactive | (ostate & (FPillegal|FPpush|FPnouser|FPkernel|FPindexm));
if(ostate & FPactive)
ostate = FPinactive | (ostate & ~FPactive);
}
up->fpstate = ostate;
}

View file

@ -542,9 +542,9 @@ awaitack(int fd, int block)
if (Debug)
syslog(dbg, flog, "tftpd %d read ack of %d bytes "
"for block %d", pid, al, ackblock);
if(ackblock == block)
if(ackblock == (block & 0xffff))
return Ackok; /* for block just sent */
else if(ackblock == block + 1) /* intel pxe eof bug */
else if(ackblock == (block + 1 & 0xffff)) /* intel pxe eof bug */
return Ackok;
else if(ackblock == 0xffff)
return Ackrexmit;

View file

@ -121,6 +121,32 @@ longtime(long t)
return x;
}
/*
* convert address into a reverse lookup address
*/
static void
mkptrname(char *ip, char *rip, int rlen)
{
uchar a[IPaddrlen];
char *p, *e;
int i;
if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
snprint(rip, rlen, "%s", ip);
else if(isv4(a))
snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
a[15], a[14], a[13], a[12]);
else{
p = rip;
e = rip + rlen;
for(i = 15; i >= 0; i--){
p = seprint(p, e, "%ux.", a[i]&0xf);
p = seprint(p, e, "%ux.", a[i]>>4);
}
seprint(p, e, "ip6.arpa");
}
}
int
prettyrrfmt(Fmt *f)
{
@ -372,7 +398,6 @@ void
doquery(char *name, char *tstr)
{
int len, type, rooted;
char *p, *np;
char buf[1024];
RR *rr, *rp;
Request req;
@ -387,6 +412,13 @@ doquery(char *name, char *tstr)
else
tstr = "ip";
/* look it up */
type = rrtype(tstr);
if(type < 0){
print("!unknown type %s\n", tstr);
return;
}
/* if name end in '.', remove it */
len = strlen(name);
if(len > 0 && name[len-1] == '.'){
@ -396,34 +428,10 @@ doquery(char *name, char *tstr)
rooted = 0;
/* inverse queries may need to be permuted */
strncpy(buf, name, sizeof buf);
if(strcmp("ptr", tstr) == 0 && cistrstr(name, ".arpa") == nil){
/* TODO: reversing v6 addrs is harder */
for(p = name; *p; p++)
;
*p = '.';
np = buf;
len = 0;
while(p >= name){
len++;
p--;
if(*p == '.'){
memmove(np, p+1, len);
np += len;
len = 0;
}
}
memmove(np, p+1, len);
np += len;
strcpy(np, "in-addr.arpa"); /* TODO: ip6.arpa for v6 */
}
/* look it up */
type = rrtype(tstr);
if(type < 0){
print("!unknown type %s\n", tstr);
return;
}
if(type == Tptr)
mkptrname(name, buf, sizeof buf);
else
strncpy(buf, name, sizeof buf);
memset(&req, 0, sizeof req);
getactivity(&req, 0);

View file

@ -6,35 +6,6 @@
#include "dns.h"
#include "ip.h"
static int domount;
static char *mtpt, *dns, *srv;
static int
setup(int argc, char **argv)
{
int fd;
if(argc == 1){
domount = 0;
mtpt = argv[0];
}
fd = open(dns, ORDWR);
if(fd < 0){
if(domount == 0)
sysfatal("can't open %s: %r", dns);
fd = open(srv, ORDWR);
if(fd < 0)
sysfatal("can't open %s: %r", srv);
if(mount(fd, -1, mtpt, MBEFORE, "") < 0)
sysfatal("can't mount(%s, %s): %r", srv, mtpt);
fd = open(dns, ORDWR);
if(fd < 0)
sysfatal("can't open %s: %r", dns);
}
return fd;
}
static void
querydns(int fd, char *line, int n)
{
@ -52,11 +23,37 @@ querydns(int fd, char *line, int n)
}
}
/*
* convert address into a reverse lookup address
*/
static void
mkptrname(char *ip, char *rip, int rlen)
{
uchar a[IPaddrlen];
char *p, *e;
int i;
if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
snprint(rip, rlen, "%s", ip);
else if(isv4(a))
snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
a[15], a[14], a[13], a[12]);
else{
p = rip;
e = rip + rlen;
for(i = 15; i >= 0; i--){
p = seprint(p, e, "%ux.", a[i]&0xf);
p = seprint(p, e, "%ux.", a[i]>>4);
}
seprint(p, e, "ip6.arpa");
}
}
static void
query(int fd)
{
int n, len;
char *lp, *p, *np;
int n;
char *lp;
char buf[1024], line[1024];
Biobuf in;
@ -84,31 +81,10 @@ query(int fd)
n += 3;
}
/* inverse queries may need to be permuted */
if(n > 4 && strcmp(" ptr", &line[n-4]) == 0 &&
cistrstr(line, ".arpa") == nil){
/* TODO: reversing v6 addrs is harder */
for(p = line; *p; p++)
if(*p == ' '){
*p = '.';
break;
}
np = buf;
len = 0;
while(p >= line){
len++;
p--;
if(*p == '.'){
memmove(np, p+1, len);
np += len;
len = 0;
}
}
memmove(np, p+1, len);
np += len;
strcpy(np, "in-addr.arpa ptr"); /* TODO: ip6.arpa for v6 */
strcpy(line, buf);
n = strlen(line);
if(n > 4 && strcmp(" ptr", &line[n-4]) == 0){
line[n-4] = 0;
mkptrname(line, buf, sizeof buf);
n = snprint(line, sizeof line, "%s ptr", buf);
}
querydns(fd, line, n);
@ -119,21 +95,25 @@ query(int fd)
void
main(int argc, char *argv[])
{
mtpt = "/net";
dns = "/net/dns";
srv = "/srv/dns";
domount = 1;
char *dns = "/net/dns";
int fd;
ARGBEGIN {
case 'x':
mtpt = "/net.alt";
dns = "/net.alt/dns";
srv = "/srv/dns_net.alt";
break;
default:
fprint(2, "usage: %s [-x] [dns-mount-point]\n", argv0);
fprint(2, "usage: %s [-x] [/net/dns]\n", argv0);
exits("usage");
} ARGEND;
query(setup(argc, argv));
if(argc > 0)
dns = argv[0];
fd = open(dns, ORDWR);
if(fd < 0)
sysfatal("can't open %s: %r", dns);
query(fd);
exits(0);
}