ref: 70c6bd03970c52d27a95c459b57943397caa3f6c
parent: 4a92a8f6b2502750a69e87d398ffb2f069103bf4
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Sep 23 15:09:48 EDT 2018
devip: valid and prefered life-time should be unsigned, add remove6 ctl command
--- a/sys/man/3/ip
+++ b/sys/man/3/ip
@@ -286,6 +286,10 @@
.RE
.PD
.TP
+.B remove6
+Remove local IPv6 addresses that have expired ther
+valid life-time.
+.TP
.BI "ra6 " "keyword value ..."
Set IPv6 router advertisement (RA) parameter
.IR keyword 's
--- a/sys/src/9/ip/ip.h
+++ b/sys/src/9/ip/ip.h
@@ -262,9 +262,9 @@
uchar tentative; /* =1 => v6 dup disc on, =0 => confirmed unique */
uchar onlink; /* =1 => onlink, =0 offlink. */
uchar autoflag; /* v6 autonomous flag */
- long validlt; /* v6 valid lifetime */
- long preflt; /* v6 preferred lifetime */
- long origint; /* time when addr was added */
+ ulong validlt; /* v6 valid lifetime */
+ ulong preflt; /* v6 preferred lifetime */
+ ulong origint; /* time when addr was added */
Iplink *link; /* addresses linked to this lifc */
Iplifc *next;
};
@@ -675,6 +675,7 @@
extern char* ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp);
extern long ipselftabread(Fs*, char *a, ulong offset, int n);
extern char* ipifcadd6(Ipifc *ifc, char**argv, int argc);
+extern char* ipifcremove6(Ipifc *ifc, char**argv, int argc);
/*
* ip.c
*/
--- a/sys/src/9/ip/ipifc.c
+++ b/sys/src/9/ip/ipifc.c
@@ -84,7 +84,7 @@
return globalv6;
}
-#define v6addrcurr(lifc) ((lifc)->preflt == ~0L || \
+#define v6addrcurr(lifc) ((lifc)->preflt == ~0UL || \
(lifc)->origint + (lifc)->preflt >= NOW/1000)
static int
@@ -177,16 +177,10 @@
ifc->maxtu = ifc->m->maxtu;
if(ifc->m->unbindonclose == 0)
ifc->conv->inuse++;
- ifc->rp.mflag = 0; /* default not managed */
- ifc->rp.oflag = 0;
- ifc->rp.maxraint = 600000; /* millisecs */
- ifc->rp.minraint = 200000;
- ifc->rp.linkmtu = 0; /* no mtu sent */
- ifc->rp.reachtime = 0;
- ifc->rp.rxmitra = 0;
- ifc->rp.ttl = MAXTTL;
- ifc->rp.routerlt = 3 * ifc->rp.maxraint;
+ /* default router paramters */
+ ifc->rp = c->p->f->v6p->rp;
+
/* any ancillary structures (like routes) no longer pertain */
ifc->ifcid++;
@@ -248,9 +242,9 @@
return nil;
}
-char sfixedformat[] = "device %s maxtu %d sendra %d recvra %d mflag %d oflag"
-" %d maxraint %d minraint %d linkmtu %d reachtime %d rxmitra %d ttl %d routerlt"
-" %d pktin %lud pktout %lud errin %lud errout %lud speed %d delay %d\n";
+char sfixedformat[] = "device %s maxtu %d sendra %d recvra %d mflag %d oflag %d"
+" maxraint %d minraint %d linkmtu %d reachtime %d rxmitra %d ttl %d routerlt %d"
+" pktin %lud pktout %lud errin %lud errout %lud speed %d delay %d\n";
char slineformat[] = " %-40I %-10M %-40I %-12lud %-12lud\n";
@@ -545,7 +539,7 @@
lifc->origint = lifcp->origint;
} else { /* default values */
lifc->onlink = lifc->autoflag = 1;
- lifc->validlt = lifc->preflt = ~0L;
+ lifc->validlt = lifc->preflt = ~0UL;
lifc->origint = NOW / 1000;
}
lifc->next = nil;
@@ -768,13 +762,13 @@
while (argsleft > 1) {
if(strcmp(argv[i], "recvra") == 0)
- recvra = (atoi(argv[i+1]) != 0);
+ recvra = atoi(argv[i+1]) != 0;
else if(strcmp(argv[i], "sendra") == 0)
- sendra = (atoi(argv[i+1]) != 0);
+ sendra = atoi(argv[i+1]) != 0;
else if(strcmp(argv[i], "mflag") == 0)
- rp.mflag = (atoi(argv[i+1]) != 0);
+ rp.mflag = atoi(argv[i+1]) != 0;
else if(strcmp(argv[i], "oflag") == 0)
- rp.oflag = (atoi(argv[i+1]) != 0);
+ rp.oflag = atoi(argv[i+1]) != 0;
else if(strcmp(argv[i], "maxraint") == 0)
rp.maxraint = atoi(argv[i+1]);
else if(strcmp(argv[i], "minraint") == 0)
@@ -849,6 +843,8 @@
}
else if(strcmp(argv[0], "add6") == 0)
return ipifcadd6(ifc, argv, argc);
+ else if(strcmp(argv[0], "remove6") == 0)
+ return ipifcremove6(ifc, argv, argc);
else if(strcmp(argv[0], "ra6") == 0)
return ipifcra6(ifc, argv, argc);
return "unsupported ctl";
@@ -1605,16 +1601,15 @@
lifc.onlink = 1;
lifc.autoflag = 1;
- lifc.validlt = ~0L;
- lifc.preflt = ~0L;
+ lifc.validlt = lifc.preflt = ~0UL;
lifc.origint = NOW / 1000;
switch(argc) {
case 7:
- lifc.preflt = atoi(argv[6]);
+ lifc.preflt = strtoul(argv[6], 0, 10);
/* fall through */
case 6:
- lifc.validlt = atoi(argv[5]);
+ lifc.validlt = strtoul(argv[5], 0, 10);
/* fall through */
case 5:
lifc.autoflag = atoi(argv[4]) != 0;
@@ -1647,4 +1642,26 @@
params[2] = preflen;
return ipifcadd(ifc, params, 3, 0, &lifc);
+}
+
+char*
+ipifcremove6(Ipifc *ifc, char**, int argc)
+{
+ Iplifc *lifc, **l;
+
+ if(argc != 1)
+ return Ebadarg;
+
+ wlock(ifc);
+ for(l = &ifc->lifc; (lifc = *l) != nil;) {
+ if((lifc->type & Rv4) == 0)
+ if(lifc->validlt != ~0UL && lifc->origint + lifc->validlt < NOW/1000){
+ if(ipifcremlifc(ifc, l) == nil)
+ continue;
+ }
+ l = &lifc->next;
+ }
+ wunlock(ifc);
+
+ return nil;
}