diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2022-09-28 18:20:20 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2022-09-28 18:20:20 +0000 |
commit | 23e378a960f6027f8daba93f34ebeb1ae3d00517 (patch) | |
tree | 7df4fc8192aa9a0f7b31e053057a0a8d86644df8 /sys/src/9/ip | |
parent | 4b3a0ca15911333d92389daa47220c8742855f1f (diff) |
arp: move arp expire logic into own function
Add arphit() function, handling validation and checking
for maximum life-time of the enty as well as copying
out the mac address.
Diffstat (limited to 'sys/src/9/ip')
-rw-r--r-- | sys/src/9/ip/arp.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/sys/src/9/ip/arp.c b/sys/src/9/ip/arp.c index 0bef6d08d..c1dce39c0 100644 --- a/sys/src/9/ip/arp.c +++ b/sys/src/9/ip/arp.c @@ -177,6 +177,21 @@ arplookup(Arp *arp, Ipifc *ifc, uchar *ip) return nil; } +static int +arphit(Arpent *a, uchar *mac, int maclen, Routehint *rh) +{ + if(a->state == AOK){ + memmove(mac, a->mac, maclen); + a->utime = NOW; + if(a->utime - a->ctime < MAXAGE_TIMER){ + if(rh != nil) + rh->a = a; + return 1; + } + } + return 0; +} + /* * fill in the media address if we have it. Otherwise return an * Arpent that represents the state of the address resolution FSM @@ -196,33 +211,29 @@ arpget(Arp *arp, Block *bp, int version, Ipifc *ifc, uchar *ip, uchar *mac, Rout if(rh != nil && (a = rh->a) != nil - && a->state == AOK && a->ifc == ifc && a->ifcid == ifc->ifcid - && ipcmp(ip, a->ip) == 0){ - memmove(mac, a->mac, ifc->m->maclen); - a->utime = NOW; - if(a->utime - a->ctime < MAXAGE_TIMER) - return nil; - } + && ipcmp(ip, a->ip) == 0 + && arphit(a, mac, ifc->m->maclen, nil)) + return nil; rlock(arp); - if((a = arplookup(arp, ifc, ip)) != nil && a->state == AOK){ - memmove(mac, a->mac, ifc->m->maclen); - a->utime = NOW; - if(a->utime - a->ctime < MAXAGE_TIMER){ - if(rh != nil) - rh->a = a; - runlock(arp); - return nil; - } + if((a = arplookup(arp, ifc, ip)) != nil + && arphit(a, mac, ifc->m->maclen, rh)){ + runlock(arp); + return nil; } if(rh != nil) rh->a = nil; runlock(arp); + wlock(arp); if((a = arplookup(arp, ifc, ip)) == nil) a = newarpent(arp, ip, ifc); + else if(arphit(a, mac, ifc->m->maclen, rh)){ + wunlock(arp); + return nil; + } a->state = AWAIT; a->utime = NOW; if(bp != nil){ |