shithub: riscv

Download patch

ref: d2b3e2f55a52df45c8e9c0b043763809f0001e69
parent: 72a840b31dd2ffc600dcffec7170eef76d7bb5ee
parent: dbfb76673539e5b59dac437c6b2a2159c896731c
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Sep 25 11:06:13 EDT 2018

merge

--- a/sys/src/cmd/ip/dhcp.h
+++ b/sys/src/cmd/ip/dhcp.h
@@ -111,6 +111,8 @@
 	ODtftpserver=		66,
 	ODbootfile=		67,
 
+	ODdnsdomain=		119,
+
 	/* plan9 vendor info options, v4 addresses only (deprecated) */
 	OP9fsv4=		128,	/* plan9 file servers */
 	OP9authv4=		129,	/* plan9 auth servers */
--- a/sys/src/cmd/ip/dhcpd/dhcpd.c
+++ b/sys/src/cmd/ip/dhcpd/dhcpd.c
@@ -161,6 +161,7 @@
 [ODclientid]		"cid",
 [ODtftpserver]		"tftpserver",
 [ODbootfile]		"bf",
+[ODdnsdomain]		"dnsdomain",
 };
 
 void	addropt(Req*, int, uchar*);
@@ -177,6 +178,7 @@
 void	miscoptions(Req*, uchar*);
 int	openlisten(char *net);
 void	p9addrsopt(Req *rp, int t, uchar **ip, int i);
+void	dnsnamesopt(Req *rp, int t, char *attr, Ndbtuple *nt);
 void	parseoptions(Req*);
 void	proto(Req*, int);
 void	rcvdecline(Req*);
@@ -1170,6 +1172,7 @@
 	a = attr;
 	if(*rp->ii.domain == 0)
 		a[na++] = "dom";
+	a[na++] = "dnsdomain";
 	for(i = 0; i < sizeof(rp->requested); i++)
 		switch(rp->requested[i]){
 		case OBrouter:
@@ -1228,6 +1231,9 @@
 			if(p != nil)
 				stringopt(rp, OBdomainname, p+1);
 			break;
+		case ODdnsdomain:
+			dnsnamesopt(rp, ODdnsdomain, "dnsdomain", t);
+			break;
 		case OBnetbiosns:
 			j = lookupserver("wins", addrs, nelem(addrs), t);
 			addrsopt(rp, OBnetbiosns, addrs, j);
@@ -1573,6 +1579,40 @@
 	}
 
 	op = seprint(op, oe, "%s(%s)", optname[t], str);
+}
+
+void
+dnsnamesopt(Req *rp, int t, char *attr, Ndbtuple *nt)
+{
+	char *s;
+	uchar *d;
+	int n, l;
+
+	for(; nt != nil; nt = nt->entry){
+		if(strcmp(nt->attr, attr) != 0)
+			continue;
+		d = &rp->p[2];
+		for(s = nt->val; *s != 0; s++){
+			for(l = 0; *s != 0 && *s != '.'; l++)
+				s++;
+			if(l > 077)
+				goto Skip;
+			d += l+1;
+			if(d >= rp->max)
+				return;
+			d[-l-1] = l;
+			memmove(d-l, s-l, l);
+		}
+		*d++ = 0;
+		n = d - &rp->p[2];
+		if(n > 255)
+			continue;
+		rp->p[0] = t;
+		rp->p[1] = n;
+		rp->p = d;
+		op = seprint(op, oe, "%s(%s)", optname[t], nt->val);
+	Skip:;
+	}
 }
 
 void
--- a/sys/src/cmd/ip/ipconfig/dhcp.c
+++ b/sys/src/cmd/ip/ipconfig/dhcp.c
@@ -17,6 +17,7 @@
 	Tbyte,
 	Tulong,
 	Tvec,
+	Tnames,
 };
 
 typedef struct Option Option;
@@ -107,10 +108,11 @@
 [ODclientid]		{ "clientid",		Tvec },
 [ODtftpserver]		{ "tftp",		Taddr },
 [ODbootfile]		{ "bootfile",		Tstr },
+[ODdnsdomain]		{ "dnsdomain",		Tnames },
 };
 
 static uchar defrequested[] = {
-	OBmask, OBrouter, OBdnserver, OBhostname, OBdomainname, OBntpserver,
+	OBmask, OBrouter, OBdnserver, OBhostname, OBdomainname, ODdnsdomain, OBntpserver,
 };
 
 static uchar	requested[256];
@@ -139,6 +141,7 @@
 static ulong	optgetulong(uchar*, int);
 static int	optgetvec(uchar*, int, uchar*, int);
 static char*	optgetx(uchar*, uchar);
+static int	optgetnames(uchar*, int, char*, int);
 
 static void	getoptions(uchar*);
 static int	parseoptions(uchar *p, int n);
@@ -513,10 +516,15 @@
 			DEBUG("ntp=%I ", conf.ntp + i*IPaddrlen);
 
 		/* get names */
-		optgetstr(bp->optdata, OBhostname,
-			conf.hostname, sizeof conf.hostname);
-		optgetstr(bp->optdata, OBdomainname,
-			conf.domainname, sizeof conf.domainname);
+		if(optgetstr(bp->optdata, OBhostname,
+			conf.hostname, sizeof conf.hostname))
+			DEBUG("hostname=%s ", conf.hostname);
+		if(optgetstr(bp->optdata, OBdomainname,
+			conf.domainname, sizeof conf.domainname))
+			DEBUG("domainname=%s ", conf.domainname);
+		if(optgetnames(bp->optdata, ODdnsdomain,
+			conf.dnsdomain, sizeof conf.dnsdomain))
+			DEBUG("dnsdomain=%s ", conf.dnsdomain);
 
 		/* get anything else we asked for */
 		getoptions(bp->optdata);
@@ -679,9 +687,8 @@
 			continue;
 		}
 		if(np != nil){
-			if(*np > len) {
+			if(*np > len)
 				return 0;
-			}
 			*np = len;
 		}
 		return p;
@@ -799,6 +806,28 @@
 	return len;
 }
 
+static int
+optgetnames(uchar *p, int op, char *s, int n)
+{
+	uchar buf[256];
+	int nbuf, len;
+
+	for(nbuf=0;;p+=len,nbuf+=len){
+		len = 1;
+		p = optget(p, op, &len);
+		if(p == nil)
+			break;
+		if(nbuf+len > sizeof(buf))
+			return 0;
+		memmove(buf+nbuf, p, len);
+	}
+	if((len = gnames(s, n, buf, nbuf)) < 0){
+		memset(s, 0, n);
+		return 0;
+	}
+	return len;
+}
+
 int
 addoption(char *opt)
 {
@@ -865,7 +894,6 @@
 	case Tvec:
 		n = optgetvec(p, opt, vec, sizeof vec);
 		if(n > 0)
-			/* what's %H?  it's not installed */
 			s = smprint("%s=%.*H", o->name, n, vec);
 		break;
 	}
--- a/sys/src/cmd/ip/ipconfig/ipconfig.h
+++ b/sys/src/cmd/ip/ipconfig/ipconfig.h
@@ -127,6 +127,8 @@
 int	countaddrs(uchar *a, int len);
 void	addaddrs(uchar *to, int nto, uchar *from, int nfrom);
 void	addnames(char *d, char *s, int len);
+int	pnames(uchar*, int, char*);
+int	gnames(char*, int, uchar*, int);
 Ndb*	opendatabase(void);
 void	ndb2conf(Ndb *db, uchar *ip);
 void	putndb(void);
--- a/sys/src/cmd/ip/ipconfig/ipv6.c
+++ b/sys/src/cmd/ip/ipconfig/ipv6.c
@@ -544,66 +544,6 @@
 		*mask = ~((1<<(8-len))-1);
 }
 
-static int
-pnames(uchar *d, int nd, char *s)
-{
-	uchar *de = d + nd;
-	int l;
-
-	if(nd < 1)
-		return -1;
-	for(; *s != 0; s++){
-		for(l = 0; *s != 0 && *s != '.' && *s != ' '; l++)
-			s++;
-
-		d += l+1;
-		if(d >= de || l > 077)
-			return -1;
-
-		d[-l-1] = l;
-		memmove(d-l, s-l, l);
-
-		if(*s != '.')
-			*d++ = 0;
-	}
-	return d - (de - nd);
-}
-
-static int
-gnames(char *d, int nd, uchar *s, int ns)
-{
-	uchar *se = s + ns;
-	char  *de = d + nd;
-	int l;
-
-	if(nd < 1 || ns < 1)
-		return -1;
-	l = *s++ & 077;
-	while(l > 0){
-		if(d + l >= de || s + l >= se)
-			return -1;
-
-		memmove(d, s, l);
-		d += l;
-		s += l;
-
-		l = *s++ & 077;
-		if(l > 0)
-			*d++ = '.';
-		else {
-			if(s >= se)
-				break;
-
-			l = *s++ & 077;
-			if(l == 0)
-				break;
-			*d++ = ' ';
-		}
-	}
-	*d = 0;
-	return d - (de - nd);
-}
-
 typedef struct Route Route;
 struct Route
 {
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -61,6 +61,7 @@
 init(void)
 {
 	srand(truerand());
+	fmtinstall('H', encodefmt);
 	fmtinstall('E', eipfmt);
 	fmtinstall('I', eipfmt);
 	fmtinstall('M', eipfmt);
@@ -893,6 +894,77 @@
 		if(*s == 0)
 			break;
 	}
+}
+
+int
+pnames(uchar *d, int nd, char *s)
+{
+	uchar *de = d + nd;
+	int l;
+
+	if(nd < 1)
+		return -1;
+	for(; *s != 0; s++){
+		for(l = 0; *s != 0 && *s != '.' && *s != ' '; l++)
+			s++;
+
+		d += l+1;
+		if(d >= de || l > 077)
+			return -1;
+
+		d[-l-1] = l;
+		memmove(d-l, s-l, l);
+
+		if(*s != '.')
+			*d++ = 0;
+	}
+	return d - (de - nd);
+}
+
+int
+gnames(char *d, int nd, uchar *s, int ns)
+{
+	char  *de = d + nd;
+	uchar *se = s + ns;
+	uchar *c = nil;
+	int l, p = 0;
+
+	if(ns < 1 || nd < 1)
+		return -1;
+	while(s < se){
+		l = *s++;
+		if((l & 0300) == 0300){
+			if(++p > 100 || s >= se)
+				break;
+			l = (l & 077)<<8 | *s++;
+			if(c == nil)
+				c = s;
+			s = (se - ns) + l;
+			continue;
+		}
+		l &= 077;
+		if(l == 0){
+			if(d <= de - nd)
+				break;
+			d[-1] = ' ';
+			if(c != nil){
+				s = c;
+				c = nil;
+				p = 0;
+			}
+			continue;
+		}
+		if(s+l >= se || d+l >= de)
+			break;
+		memmove(d, s, l);
+		s += l;
+		d += l;
+		*d++ = '.';
+	}
+	if(p != 0 || s != se || d <= de - nd || d[-1] != ' ')
+		return -1;
+	*(--d) = 0;
+	return d - (de - nd);
 }
 
 static Ndbtuple*