ref: e35246704f9925151a2b5ca759e7ed950d957999
parent: a93a4ec24bbee21290e6b3d5561f6c0fd53eef6e
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;
}
--
⑨