devip: add gratious arp ctl message to /net/arp

writing "garp <ip>" will send a gratious arp for
the provided ip address (if it can be found on
any interface).
This commit is contained in:
cinap_lenrek 2023-07-23 22:22:09 +00:00
parent 8a1c1c9510
commit 934d81ae4e

View file

@ -501,9 +501,9 @@ arpwrite(Fs *fs, char *s, int len)
}
runlock(ifc);
} else if(strcmp(f[0], "del") == 0){
if (n != 2)
if(n != 2)
error(Ebadarg);
if (parseip(ip, f[1]) == -1)
if(parseip(ip, f[1]) == -1)
error(Ebadip);
wlock(arp);
for(a = arp->hash[hashipa(ip)]; a != nil; a = x){
@ -512,6 +512,26 @@ arpwrite(Fs *fs, char *s, int len)
cleanarpent(arp, a);
}
wunlock(arp);
} else if(strcmp(f[0], "garp") == 0){
Iplifc *lifc;
if(n != 2)
error(Ebadarg);
if(parseip(ip, f[1]) == -1)
error(Ebadip);
if((ifc = findipifc(fs, ip, ip, Runi)) == nil)
error("no interface");
rlock(ifc);
if(waserror()){
runlock(ifc);
nexterror();
}
if(ifc->m != nil && ifc->m->areg != nil && (lifc = iplocalonifc(ifc, ip)) != nil)
(*ifc->m->areg)(fs, ifc, lifc, ip);
runlock(ifc);
poperror();
} else
error(Ebadarp);