ref: 2f076f946fe7a5409cda7d83af5585442b294ec8
parent: ef17043327d999101009f85aae72f77399db15ac
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Sep 24 09:56:25 EDT 2018
ip/ipconfig: handle noconfig flag for router advertisement, add debug prints, cleanup
--- a/sys/src/cmd/ip/ipconfig/dhcp.c
+++ b/sys/src/cmd/ip/ipconfig/dhcp.c
@@ -243,6 +243,7 @@
t = secs;
if(t >= conf.lease){
conf.lease = 0;
+ DEBUG("couldn't renew IP lease");
if(!noconfig){
ipunconfig();
needconfig = 1;
--- a/sys/src/cmd/ip/ipconfig/ipv6.c
+++ b/sys/src/cmd/ip/ipconfig/ipv6.c
@@ -415,7 +415,7 @@
return 0;
else if(ifc->sendra6 > 0)
return IsRouter;
- else if(ifc->recvra6 > 0)
+ else if(ifc->recvra6 > 0 || noconfig)
return IsHostRecv;
else
return IsHostNoRecv;
@@ -712,6 +712,7 @@
break;
}
}
+
issuebasera6(&conf);
/* remove expired default routes */
@@ -722,10 +723,11 @@
|| r->prefixlt != ~0UL && r->prefixlt < now-r->time
|| r->routerlt != ~0UL && r->routerlt < now-r->time
|| ipcmp(r->src, ra->src) == 0 && r->routerlt != 0 && conf.routerlt == 0){
+ DEBUG("purging RA from %I on %s; pfx %I %M",
+ r->src, conf.dev, r->laddr, r->mask);
if(validip(r->gaddr))
removedefroute(r->gaddr, conf.lladdr, r->laddr, r->mask);
*rr = r->next;
- r->next = nil;
free(r);
continue;
}
@@ -774,7 +776,6 @@
&& ipcmp(r->laddr, conf.laddr) == 0){
seen = memcmp(r->hash, hash, SHA1dlen) == 0;
*rr = r->next;
- r->next = nil;
break;
}
}
@@ -805,6 +806,9 @@
if(!seen)
warning("igoring bogus prefix from %I on %s; pfx %I %M",
ra->src, conf.dev, conf.v6pref, conf.mask);
+
+ /* keep it arround so we wont comlain again */
+ r->prefixlt = r->routerlt = ~0UL;
continue;
}
@@ -821,6 +825,9 @@
if(validip(conf.gaddr))
adddefroute(conf.gaddr, conf.lladdr, conf.laddr, conf.mask);
+ if(noconfig)
+ continue;
+
if(beprimary)
putndb();
refresh();
@@ -892,7 +899,7 @@
exits(nil);
}
- if(recvra6on(ifc) == IsHostNoRecv){
+ if(recvra6on(ifc) == IsHostNoRecv || noconfig && sendrscnt < 0){
warning("recvra6: recvra off, quitting on %s", conf.dev);
if(sendrscnt >= 0)
rendezvous(recvra6, (void*)-1);
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -404,7 +404,7 @@
}
if(myifc < 0)
sysfatal("interface not found for: %s", conf.dev);
- } else {
+ } else if(!noconfig) {
/* open old interface */
binddevice();
}
@@ -484,6 +484,11 @@
{
if(!validip(conf.laddr))
sysfatal("remove requires an address");
+
+ DEBUG("removing address %I %M on %s", conf.laddr, conf.mask, conf.dev);
+ if(conf.cfd < 0)
+ return;
+
if(fprint(conf.cfd, "remove %I %M", conf.laddr, conf.mask) < 0)
warning("can't remove %I %M: %r", conf.laddr, conf.mask);
}
@@ -491,6 +496,9 @@
static void
dounbind(void)
{
+ if(conf.cfd < 0)
+ return;
+
if(fprint(conf.cfd, "unbind") < 0)
warning("can't unbind %s: %r", conf.dev);
}
@@ -589,11 +597,12 @@
if(!validip(conf.laddr))
return;
- DEBUG("couldn't renew IP lease, releasing %I", conf.laddr);
-
if(!validip(conf.mask))
ipmove(conf.mask, defmask(conf.laddr));
+ if(validip(conf.gaddr))
+ removedefroute(conf.gaddr, conf.laddr, conf.laddr, conf.mask);
+
doremove();
ipmove(conf.laddr, IPnoaddr);
@@ -713,6 +722,9 @@
ctl = "%s %I %M %I %I %I %M";
else
ctl = "%s %I %M %I %I";
+ DEBUG(ctl, cmd, dst, mask, gate, ia, src, smask);
+ if(conf.rfd < 0)
+ return;
fprint(conf.rfd, ctl, cmd, dst, mask, gate, ia, src, smask);
}