shithub: riscv

Download patch

ref: 93ab48008e6574a7b790c85e1f81c97ef088d7c7
parent: c4603260f8736dbea8d7f47c46e8db0cf1a23fa0
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Apr 14 20:07:42 EDT 2018

ip/ipconfig: use unique ip/ipmask/ipgw values close to match for ndbconfig

--- a/sys/src/cmd/ip/ipconfig/ipconfig.h
+++ b/sys/src/cmd/ip/ipconfig/ipconfig.h
@@ -25,7 +25,7 @@
 	uchar	dns[2*IPaddrlen];
 	uchar	fs[2*IPaddrlen];
 	uchar	auth[2*IPaddrlen];
-	uchar	ntp[IPaddrlen];
+	uchar	ntp[2*IPaddrlen];
 	int	mtu;
 
 	/* dhcp specific */
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -1776,11 +1776,29 @@
 	free(cmdname);
 }
 
+static Ndbtuple*
+uniquent(Ndbtuple *t)
+{
+	Ndbtuple **l, *x;
+
+	l = &t->entry;
+	while((x = *l) != nil){
+		if(strcmp(t->attr, x->attr) != 0){
+			l = &x->entry;
+			continue;
+		}
+		*l = x->entry;
+		x->entry = nil;
+		ndbfree(x);
+	}
+	return t;
+}
+
 /* get everything out of ndb */
 void
 ndbconfig(void)
 {
-	int nattr, nauth = 0, ndns = 0, nfs = 0, ok;
+	int nattr, nauth = 0, ndns = 0, nfs = 0, nntp = 0, ok;
 	char etheraddr[32];
 	char *attrs[10];
 	Ndb *db;
@@ -1806,19 +1824,19 @@
 	for(nt = t; nt != nil; nt = nt->entry) {
 		ok = 1;
 		if(strcmp(nt->attr, "ip") == 0)
-			ok = parseip(conf.laddr, nt->val);
+			ok = parseip(conf.laddr, uniquent(nt)->val);
 		else if(strcmp(nt->attr, "ipmask") == 0)
-			parseipmask(conf.mask, nt->val);  /* could be -1 */
+			parseipmask(conf.mask, uniquent(nt)->val);  /* could be -1 */
 		else if(strcmp(nt->attr, "ipgw") == 0)
-			ok = parseip(conf.gaddr, nt->val);
-		else if(ndns < 2 && strcmp(nt->attr, "dns") == 0)
-			ok = parseip(conf.dns+IPaddrlen*ndns, nt->val);
-		else if(strcmp(nt->attr, "ntp") == 0)
-			ok = parseip(conf.ntp, nt->val);
-		else if(nfs < 2 && strcmp(nt->attr, "fs") == 0)
-			ok = parseip(conf.fs+IPaddrlen*nfs, nt->val);
-		else if(nauth < 2 && strcmp(nt->attr, "auth") == 0)
-			ok = parseip(conf.auth+IPaddrlen*nauth, nt->val);
+			ok = parseip(conf.gaddr, uniquent(nt)->val);
+		else if(ndns < sizeof(conf.dns)/IPaddrlen && strcmp(nt->attr, "dns") == 0)
+			ok = parseip(conf.dns+IPaddrlen*ndns++, nt->val);
+		else if(nntp < sizeof(conf.ntp)/IPaddrlen && strcmp(nt->attr, "ntp") == 0)
+			ok = parseip(conf.ntp+IPaddrlen*nntp++, nt->val);
+		else if(nfs < sizeof(conf.fs)/IPaddrlen && strcmp(nt->attr, "fs") == 0)
+			ok = parseip(conf.fs+IPaddrlen*nfs++, nt->val);
+		else if(nauth < sizeof(conf.auth)/IPaddrlen && strcmp(nt->attr, "auth") == 0)
+			ok = parseip(conf.auth+IPaddrlen*nauth++, nt->val);
 		if (!ok)
 			fprint(2, "%s: bad %s address in ndb: %s\n", argv0,
 				nt->attr, nt->val);