mirror of
https://github.com/apache/nuttx.git
synced 2025-12-16 17:56:38 +08:00
net/arp: reducing unnecessary ARP requests can mitigate
Some checks failed
Build Documentation / build-html (push) Has been cancelled
Some checks failed
Build Documentation / build-html (push) Has been cancelled
network congestion and avoid packet delays caused by waiting for ARP responses Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
This commit is contained in:
@@ -425,7 +425,7 @@ void arp_notify(in_addr_t ipaddr);
|
||||
|
||||
struct ether_addr; /* Forward reference */
|
||||
int arp_find(in_addr_t ipaddr, FAR uint8_t *ethaddr,
|
||||
FAR struct net_driver_s *dev);
|
||||
FAR struct net_driver_s *dev, bool check_expiry);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arp_delete
|
||||
@@ -620,7 +620,7 @@ void arp_acd_setup(FAR struct net_driver_s *dev);
|
||||
# define arp_wait_cancel(n) (0)
|
||||
# define arp_wait(n,t) (0)
|
||||
# define arp_notify(i)
|
||||
# define arp_find(i,e,d) (-ENOSYS)
|
||||
# define arp_find(i,e,d,u) (-ENOSYS)
|
||||
# define arp_delete(i,d) (-ENOSYS)
|
||||
# define arp_cleanup(d)
|
||||
# define arp_update(d,i,m);
|
||||
|
||||
@@ -262,7 +262,7 @@ void arp_out(FAR struct net_driver_s *dev)
|
||||
|
||||
/* Check if we already have this destination address in the ARP table */
|
||||
|
||||
ret = arp_find(ipaddr, ethaddr.ether_addr_octet, dev);
|
||||
ret = arp_find(ipaddr, ethaddr.ether_addr_octet, dev, false);
|
||||
if (ret < 0)
|
||||
{
|
||||
ninfo("ARP request for IP %08lx\n", (unsigned long)ipaddr);
|
||||
|
||||
@@ -314,7 +314,7 @@ int arp_send(in_addr_t ipaddr)
|
||||
* issue.
|
||||
*/
|
||||
|
||||
ret = arp_find(ipaddr, NULL, dev);
|
||||
ret = arp_find(ipaddr, NULL, dev, true);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* We have it! Break out with success */
|
||||
|
||||
@@ -186,6 +186,7 @@ arp_return_old_entry(FAR struct arp_entry_s *e1, FAR struct arp_entry_s *e2)
|
||||
* Input Parameters:
|
||||
* ipaddr - Refers to an IP address in network order
|
||||
* dev - Device structure
|
||||
* check_expiry - Expiry check
|
||||
*
|
||||
* Assumptions:
|
||||
* The network is locked to assure exclusive access to the ARP table.
|
||||
@@ -194,7 +195,8 @@ arp_return_old_entry(FAR struct arp_entry_s *e1, FAR struct arp_entry_s *e2)
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct arp_entry_s *arp_lookup(in_addr_t ipaddr,
|
||||
FAR struct net_driver_s *dev)
|
||||
FAR struct net_driver_s *dev,
|
||||
bool check_expiry)
|
||||
{
|
||||
FAR struct arp_entry_s *tabptr;
|
||||
int i;
|
||||
@@ -205,10 +207,23 @@ static FAR struct arp_entry_s *arp_lookup(in_addr_t ipaddr,
|
||||
{
|
||||
tabptr = &g_arptable[i];
|
||||
if (tabptr->at_dev == dev &&
|
||||
net_ipv4addr_cmp(ipaddr, tabptr->at_ipaddr) &&
|
||||
clock_systime_ticks() - tabptr->at_time <= ARP_MAXAGE_TICK)
|
||||
net_ipv4addr_cmp(ipaddr, tabptr->at_ipaddr))
|
||||
{
|
||||
return tabptr;
|
||||
/* Find matching entries */
|
||||
|
||||
if (!check_expiry)
|
||||
{
|
||||
return tabptr; /* Ignore expiration time */
|
||||
}
|
||||
|
||||
/* Check if it has expired */
|
||||
|
||||
if (clock_systime_ticks() - tabptr->at_time <= ARP_MAXAGE_TICK)
|
||||
{
|
||||
return tabptr;
|
||||
}
|
||||
|
||||
return NULL; /* Expired */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,6 +416,7 @@ void arp_hdr_update(FAR struct net_driver_s *dev, FAR uint16_t *pipaddr,
|
||||
* used simply to determine if the Ethernet MAC address is
|
||||
* available.
|
||||
* dev - Device structure
|
||||
* check_expiry - Expiry check
|
||||
*
|
||||
* Assumptions
|
||||
* The network is locked to assure exclusive access to the ARP table.
|
||||
@@ -408,14 +424,14 @@ void arp_hdr_update(FAR struct net_driver_s *dev, FAR uint16_t *pipaddr,
|
||||
****************************************************************************/
|
||||
|
||||
int arp_find(in_addr_t ipaddr, FAR uint8_t *ethaddr,
|
||||
FAR struct net_driver_s *dev)
|
||||
FAR struct net_driver_s *dev, bool check_expiry)
|
||||
{
|
||||
FAR struct arp_entry_s *tabptr;
|
||||
struct arp_table_info_s info;
|
||||
|
||||
/* Check if the IPv4 address is already in the ARP table. */
|
||||
|
||||
tabptr = arp_lookup(ipaddr, dev);
|
||||
tabptr = arp_lookup(ipaddr, dev, check_expiry);
|
||||
if (tabptr != NULL)
|
||||
{
|
||||
/* Addresses that have failed to be searched will return a special
|
||||
@@ -485,7 +501,7 @@ int arp_delete(in_addr_t ipaddr, FAR struct net_driver_s *dev)
|
||||
#endif
|
||||
/* Check if the IPv4 address is in the ARP table. */
|
||||
|
||||
tabptr = arp_lookup(ipaddr, dev);
|
||||
tabptr = arp_lookup(ipaddr, dev, false);
|
||||
if (tabptr != NULL)
|
||||
{
|
||||
/* Notify to netlink */
|
||||
|
||||
@@ -128,7 +128,8 @@ netdev_prefixlen_findby_lipv4addr(in_addr_t lipaddr, FAR int8_t *prefixlen)
|
||||
|
||||
if (len > bestpref
|
||||
#ifdef CONFIG_NET_ARP
|
||||
|| (len == bestpref && arp_find(lipaddr, NULL, dev) == OK)
|
||||
|| (len == bestpref
|
||||
&& arp_find(lipaddr, NULL, dev, true) == OK)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
|
||||
@@ -1452,7 +1452,7 @@ static int netdev_arp_ioctl(FAR struct socket *psock, int cmd,
|
||||
req->arp_pa.sa_family == AF_INET)
|
||||
{
|
||||
ret = arp_find(addr->sin_addr.s_addr,
|
||||
(FAR uint8_t *)req->arp_ha.sa_data, dev);
|
||||
(FAR uint8_t *)req->arp_ha.sa_data, dev, true);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Return the mapped hardware address. */
|
||||
|
||||
Reference in New Issue
Block a user