mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08: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:
@@ -37,6 +37,7 @@
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "netlink/netlink.h"
|
||||
#include "arp/arp.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@@ -94,6 +95,7 @@ int netdev_carrier_off(FAR struct net_driver_s *dev)
|
||||
/* Notify clients that the network has been taken down */
|
||||
|
||||
devif_dev_event(dev, NULL, NETDEV_DOWN);
|
||||
arp_cleanup(dev);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user