net/arp: support ARP entry learned on gratuitous ARP response

learn arp when received gratuitiout arp

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
This commit is contained in:
wenquan1
2025-09-11 14:24:25 +08:00
committed by archer
parent 7e4c3f4a60
commit 1f5cd930a4
+17
View File
@@ -181,6 +181,23 @@ static int arp_in(FAR struct net_driver_s *dev)
arp_notify(net_ip4addr_conv32(arp->ah_sipaddr));
}
#ifdef CONFIG_NET_ARP_GRATUITOUS
else if (net_ipv4addr_cmp(sipaddr, ipaddr) &&
!net_ipv4addr_cmp(sipaddr, INADDR_ANY))
{
/* Gratuitous arp sender ip should same with target ip,
* and ignore IPv4 duplicate address detection packet (RFC2131)
*/
/* Gratuitous request arp the sender ip should be a unicast ip */
if (net_ipv4addr_cmp(sipaddr, dev->d_draddr) ||
net_ipv4addr_maskcmp(sipaddr, dev->d_ipaddr, dev->d_netmask))
{
arp_hdr_update(dev, arp->ah_sipaddr, arp->ah_shwaddr);
}
}
#endif /* CONFIG_NET_ARP_GRATUITOUS */
break;
}