shithub: riscv

Download patch

ref: 7ad08a8515f2579013c45a8473ba3c05701796da
parent: dbf165e1bdcc65d94ed9c0d70e5d24df5ad4fc8f
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Aug 26 17:09:57 EDT 2014

ipconfig: cleanup code duplication in ip6cfg()

--- a/sys/src/cmd/ip/ipconfig/ipv6.c
+++ b/sys/src/cmd/ip/ipconfig/ipv6.c
@@ -385,9 +385,8 @@
 int
 ip6cfg(int autoconf)
 {
-	int dupfound = 0, n;
-	char *p;
-	char buf[256];
+	int tentative, dupfound = 0, n;
+	char *p, buf[256];
 	uchar ethaddr[6];
 	Biobuf *bp;
 
@@ -397,7 +396,10 @@
 		ea2lla(conf.laddr, ethaddr);
 	}
 
-	if (dupl_disc)
+	tentative = dupl_disc;
+
+Again:
+	if (tentative)
 		n = sprint(buf, "try");
 	else
 		n = sprint(buf, "add");
@@ -417,7 +419,7 @@
 		return -1;
 	}
 
-	if (!dupl_disc)
+	if (!tentative)
 		return 0;
 
 	sleep(3000);
@@ -434,7 +436,6 @@
 	while(p = Brdline(bp, '\n')){
 		p[Blinelen(bp)-1] = 0;
 		if(cistrstr(p, buf) != 0) {
-			warning("found dup entry in arp cache");
 			dupfound = 1;
 			break;
 		}
@@ -441,18 +442,13 @@
 	}
 	Bterm(bp);
 
-	if (dupfound)
-		doremove();
-	else {
-		n = sprint(buf, "add %I %M", conf.laddr, conf.mask);
-		if(validip(conf.raddr)){
-			n += snprint(buf+n, sizeof buf-n, " %I", conf.raddr);
-			if(conf.mtu != 0)
-				n += snprint(buf+n, sizeof buf-n, " %d",
-					conf.mtu);
-		}
-		write(conf.cfd, buf, n);
+	if (!dupfound) {
+		tentative = 0;
+		goto Again;
 	}
+
+	warning("found dup entry in arp cache");
+	doremove();
 	return 0;
 }