shithub: riscv

Download patch

ref: e4d0a7628998cf99bacbbef8a60fc721a985d461
parent: 183ab18dfcb048318241b92510a3f6614fa62ca4
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Sep 9 11:38:53 EDT 2018

ndb/cs: don't do dns lookups when all we got is loopback or link local addresses

--- a/sys/src/cmd/ndb/cs.c
+++ b/sys/src/cmd/ndb/cs.c
@@ -179,6 +179,7 @@
 QLock ipifclock;
 Ipifc *ipifcs;
 int confipvers;
+int dnsipvers;
 int lookipvers = V4|V6;
 
 char *mysysname;
@@ -984,26 +985,59 @@
 	_exits(0);
 }
 
+static uchar loopbacknet[IPaddrlen] = {
+	0, 0, 0, 0,
+	0, 0, 0, 0,
+	0, 0, 0xff, 0xff,
+	127, 0, 0, 0
+};
+static uchar loopbackmask[IPaddrlen] = {
+	0xff, 0xff, 0xff, 0xff,
+	0xff, 0xff, 0xff, 0xff,
+	0xff, 0xff, 0xff, 0xff,
+	0xff, 0, 0, 0
+};
+static uchar loopback6[IPaddrlen] = {
+	0, 0, 0, 0,
+	0, 0, 0, 0,
+	0, 0, 0, 0,
+	0, 0, 0, 1
+};
+
 void
 readipinterfaces(void)
 {
+	uchar mynet[IPaddrlen];
 	Ipifc *ifc;
 	Iplifc *lifc;
-	int v;
+	int conf, dns;
 
-	v = 0;
+	conf = dns = 0;
 	qlock(&ipifclock);
 	ipifcs = readipifc(mntpt, ipifcs, -1);
 	for(ifc = ipifcs; ifc != nil; ifc = ifc->next){
 		for(lifc = ifc->lifc; lifc != nil; lifc = lifc->next){
-			if(isv4(lifc->ip))
-				v |= V4;
-			else
-				v |= V6;
+			if(ipcmp(lifc->ip, IPnoaddr) == 0)
+				continue;
+			if(isv4(lifc->ip)){
+				conf |= V4;
+				maskip(lifc->ip, loopbackmask, mynet);
+				if(ipcmp(mynet, loopbacknet) == 0)
+					continue;
+				dns |= V4;
+			} else {
+				conf |= V6;
+				if(ISIPV6LINKLOCAL(lifc->ip))
+					continue;
+				if(ipcmp(lifc->ip, loopback6) == 0)
+					continue;
+				dns |= V6;
+			}
 		}
 	}
 	qunlock(&ipifclock);
-	confipvers = v;
+	confipvers = conf;
+	dnsipvers = dns;
 }
 
 /*
@@ -1703,7 +1737,7 @@
 	char buf[Maxreply];
 	Ndbtuple *t;
 
-	ipvers &= confipvers & lookipvers;
+	ipvers &= dnsipvers & lookipvers;
 	if(ipvers == 0){
 		werrstr("no ip address");
 		return nil;