shithub: riscv

Download patch

ref: 1984f6813cc216e3c98e402ce3f381a531faf1b1
parent: be3809866ce89d2dcac0b02f2ec7b49b5393cb56
parent: ad7390dda820db424821b19c572a44b4cc0838e8
author: aiju <devnull@localhost>
date: Thu May 24 09:41:08 EDT 2018

merge

--- a/sys/man/8/ndb
+++ b/sys/man/8/ndb
@@ -49,7 +49,7 @@
 .B -s
 ]
 [
-.I server
+.I /net/cs
 [
 .I addr...
 ]
@@ -91,6 +91,8 @@
 .B ndb/dnsquery
 [
 .B -x
+] [
+.I /net/dns
 ]
 .br
 .B ndb/dnsdebug
--- a/sys/src/9/pc64/main.c
+++ b/sys/src/9/pc64/main.c
@@ -535,7 +535,7 @@
 	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 @@
 		 * 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 @@
 		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;
 }
--- a/sys/src/cmd/ip/tftpd.c
+++ b/sys/src/cmd/ip/tftpd.c
@@ -542,9 +542,9 @@
 		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;
--- a/sys/src/cmd/ndb/dnsdebug.c
+++ b/sys/src/cmd/ndb/dnsdebug.c
@@ -121,6 +121,32 @@
 	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 @@
 doquery(char *name, char *tstr)
 {
 	int len, type, rooted;
-	char *p, *np;
 	char buf[1024];
 	RR *rr, *rp;
 	Request req;
@@ -387,6 +412,13 @@
 		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 @@
 		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);
--- a/sys/src/cmd/ndb/dnsquery.c
+++ b/sys/src/cmd/ndb/dnsquery.c
@@ -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 @@
 	}
 }
 
+/*
+ *  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 @@
 				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 @@
 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);
 }