From c604d823266eb2488c02af215c5d62d8d75cff91 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 10 Mar 2003 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2003-03-10 --- ip/arp.c | 37 +++++++++++++++++++++---------------- ip/ethermedium.c | 10 +++++----- ip/ip.h | 6 +++--- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/ip/arp.c b/ip/arp.c index 1353f32137dec98d793043af16bd13b5c7760f94..c4879e1f3ca0ac69e9e5110d94632aa15cdb30f8 100644 --- a/ip/arp.c +++ b/ip/arp.c @@ -75,10 +75,10 @@ newarp6(Arp *arp, uchar *ip, Ipifc *ifc, int addrxt) /* find oldest entry */ e = &arp->cache[NCACHE]; a = arp->cache; - t = a->used; + t = a->utime; for(f = a; f < e; f++){ - if(f->used < t){ - t = f->used; + if(f->utime < t){ + t = f->utime; a = f; } } @@ -124,11 +124,11 @@ newarp6(Arp *arp, uchar *ip, Ipifc *ifc, int addrxt) *l = a; memmove(a->ip, ip, sizeof(a->ip)); - a->used = NOW; - a->time = 0; + a->utime = NOW; + a->ctime = a->utime; a->type = m; - a->rxtat = NOW + ReTransTimer; + a->rtime = NOW + ReTransTimer; a->rxtsrem = MAX_MULTICAST_SOLICIT; a->ifc = ifc; a->ifcid = ifc->ifcid; @@ -165,8 +165,8 @@ cleanarpent(Arp *arp, Arpent *a) { Arpent *f, **l; - a->used = 0; - a->time = 0; + a->utime = 0; + a->ctime = 0; a->type = 0; a->state = 0; @@ -227,7 +227,7 @@ arpget(Arp *arp, Block *bp, int version, Ipifc *ifc, uchar *ip, uchar *mac) a = newarp6(arp, ip, ifc, (version != V4)); a->state = AWAIT; } - a->used = NOW; + a->utime = NOW; if(a->state == AWAIT){ if(bp != nil){ if(a->hold) @@ -241,6 +241,11 @@ arpget(Arp *arp, Block *bp, int version, Ipifc *ifc, uchar *ip, uchar *mac) } memmove(mac, a->mac, a->type->maclen); + + /* remove old entries */ + if(NOW - a->ctime > 15*60*1000) + cleanarpent(arp, a); + qunlock(arp); return nil; } @@ -280,7 +285,7 @@ arpresolve(Arp *arp, Arpent *a, Medium *type, uchar *mac) memmove(a->mac, mac, type->maclen); a->type = type; a->state = AOK; - a->used = NOW; + a->utime = NOW; bp = a->hold; a->hold = nil; qunlock(arp); @@ -375,7 +380,8 @@ arpenter(Fs *fs, int version, uchar *ip, uchar *mac, int n, int refresh) freeb(bp); bp = next; } - a->used = NOW; + a->utime = NOW; + a->ctime = a->utime; return; } } @@ -421,7 +427,7 @@ arpwrite(Fs *fs, char *s, int len) memset(a->mac, 0, sizeof(a->mac)); a->hash = nil; a->state = 0; - a->used = 0; + a->utime = 0; while(a->hold != nil){ bp = a->hold->list; freeblist(a->hold); @@ -532,7 +538,7 @@ rxmitsols(Arp *arp) nrxt = 0; goto dodrops; //return nrxt; } - nrxt = a->rxtat - NOW; + nrxt = a->rtime - NOW; if(nrxt > 3*ReTransTimer/4) goto dodrops; //return nrxt; @@ -589,14 +595,13 @@ rxmitsols(Arp *arp) *l = a; a->rxtsrem--; a->nextrxt = nil; - a->time = NOW; - a->rxtat = NOW + ReTransTimer; + a->rtime = NOW + ReTransTimer; a = arp->rxmt; if(a==nil) nrxt = 0; else - nrxt = a->rxtat - NOW; + nrxt = a->rtime - NOW; dodrops: xp = arp->dropf; diff --git a/ip/ethermedium.c b/ip/ethermedium.c index 394babc8adbffa493cdbe1d5e1a603f2df753199..ad4676a9680590e2a7e7d8b65ffca95cc73e3fb6 100644 --- a/ip/ethermedium.c +++ b/ip/ethermedium.c @@ -453,7 +453,7 @@ sendarp(Ipifc *ifc, Arpent *a) Etherrock *er = ifc->arg; /* don't do anything if it's been less than a second since the last */ - if(NOW - a->time < 1000){ + if(NOW - a->ctime < 1000){ arprelease(er->f->arp, a); return; } @@ -467,7 +467,7 @@ sendarp(Ipifc *ifc, Arpent *a) } /* try to keep it around for a second more */ - a->time = NOW; + a->ctime = NOW; arprelease(er->f->arp, a); n = sizeof(Etherarp); @@ -504,7 +504,7 @@ resolveaddr6(Ipifc *ifc, Arpent *a) uchar ipsrc[IPaddrlen]; /* don't do anything if it's been less than a second since the last */ - if(NOW - a->time < ReTransTimer){ + if(NOW - a->ctime < ReTransTimer){ arprelease(er->f->arp, a); return; } @@ -518,8 +518,8 @@ resolveaddr6(Ipifc *ifc, Arpent *a) } /* try to keep it around for a second more */ - a->time = NOW; - a->rxtat = NOW + ReTransTimer; + a->ctime = NOW; + a->rtime = NOW + ReTransTimer; if(a->rxtsrem <= 0) { arprelease(er->f->arp, a); return; diff --git a/ip/ip.h b/ip/ip.h index 158b139969ced89a9bd97bbe0d03b5a854b5adb9..acfe839185022678e51d5e3d06d8f56afa4e1f76 100644 --- a/ip/ip.h +++ b/ip/ip.h @@ -523,11 +523,11 @@ struct Arpent Arpent* hash; Block* hold; Block* last; - uint time; - uint used; + uint ctime; /* time entry was created or refreshed */ + uint utime; /* time entry was last used */ uchar state; Arpent *nextrxt; /* re-transmit chain */ - uint rxtat; + uint rtime; /* time for next retransmission */ uchar rxtsrem; Ipifc *ifc; uchar ifcid; /* must match ifc->id */