mirror of
https://github.com/apache/nuttx.git
synced 2026-09-13 14:10:18 +00:00
net/arp: clean the arp table when netdev carrier off
Fix the arp address changed if netdev renew, since the arp table should be cleared when the netdev carrier off Signed-off-by: songlinzhang <songlinzhang@xiaomi.com>
This commit is contained in:
parent
4db9513658
commit
22df553443
7 changed files with 104 additions and 18 deletions
|
|
@ -1222,6 +1222,40 @@ static int netdev_imsf_ioctl(FAR struct socket *psock, int cmd,
|
|||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_arp_callback
|
||||
*
|
||||
* Description:
|
||||
* This is a callback that checks if the Ethernet network device has the
|
||||
* indicated name
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev Ethernet driver device structure
|
||||
* req The argument of the ioctl cmd
|
||||
*
|
||||
* Returned Value:
|
||||
* 1 on success
|
||||
* 0 on error
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ARP
|
||||
static int netdev_arp_callback(FAR struct net_driver_s *dev, FAR void *arg)
|
||||
{
|
||||
FAR struct arpreq *req = arg;
|
||||
FAR struct sockaddr_in *addr = (FAR struct sockaddr_in *)&req->arp_pa;
|
||||
|
||||
if (strncmp(dev->d_ifname, (FAR const char *)req->arp_dev,
|
||||
sizeof(dev->d_ifname)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
arp_update(dev, addr->sin_addr.s_addr,
|
||||
(FAR uint8_t *)req->arp_ha.sa_data);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netdev_arp_ioctl
|
||||
*
|
||||
|
|
@ -1256,15 +1290,11 @@ static int netdev_arp_ioctl(FAR struct socket *psock, int cmd,
|
|||
req->arp_pa.sa_family == AF_INET &&
|
||||
req->arp_ha.sa_family == ARPHRD_ETHER)
|
||||
{
|
||||
FAR struct sockaddr_in *addr =
|
||||
(FAR struct sockaddr_in *)&req->arp_pa;
|
||||
|
||||
/* Update any existing ARP table entry for this protocol
|
||||
* address -OR- add a new ARP table entry if there is not.
|
||||
*/
|
||||
|
||||
ret = arp_update(addr->sin_addr.s_addr,
|
||||
(FAR uint8_t *)req->arp_ha.sa_data);
|
||||
ret = netdev_foreach(netdev_arp_callback, req) ? OK : -EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue