Skip to content

Commit 2256095

Browse files
nuttxsAlan C. Assis
authored andcommitted
net/arp: reducing unnecessary ARP requests can mitigate
network congestion and avoid packet delays caused by waiting for ARP responses Signed-off-by: nuttxs <[email protected]>
1 parent 571447b commit 2256095

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

net/arp/arp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ void arp_notify(in_addr_t ipaddr);
425425

426426
struct ether_addr; /* Forward reference */
427427
int arp_find(in_addr_t ipaddr, FAR uint8_t *ethaddr,
428-
FAR struct net_driver_s *dev);
428+
FAR struct net_driver_s *dev, bool check_expiry);
429429

430430
/****************************************************************************
431431
* Name: arp_delete
@@ -620,7 +620,7 @@ void arp_acd_setup(FAR struct net_driver_s *dev);
620620
# define arp_wait_cancel(n) (0)
621621
# define arp_wait(n,t) (0)
622622
# define arp_notify(i)
623-
# define arp_find(i,e,d) (-ENOSYS)
623+
# define arp_find(i,e,d,u) (-ENOSYS)
624624
# define arp_delete(i,d) (-ENOSYS)
625625
# define arp_cleanup(d)
626626
# define arp_update(d,i,m);

net/arp/arp_out.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void arp_out(FAR struct net_driver_s *dev)
262262

263263
/* Check if we already have this destination address in the ARP table */
264264

265-
ret = arp_find(ipaddr, ethaddr.ether_addr_octet, dev);
265+
ret = arp_find(ipaddr, ethaddr.ether_addr_octet, dev, false);
266266
if (ret < 0)
267267
{
268268
ninfo("ARP request for IP %08lx\n", (unsigned long)ipaddr);

net/arp/arp_send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int arp_send(in_addr_t ipaddr)
314314
* issue.
315315
*/
316316

317-
ret = arp_find(ipaddr, NULL, dev);
317+
ret = arp_find(ipaddr, NULL, dev, true);
318318
if (ret >= 0)
319319
{
320320
/* We have it! Break out with success */

net/arp/arp_table.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ arp_return_old_entry(FAR struct arp_entry_s *e1, FAR struct arp_entry_s *e2)
186186
* Input Parameters:
187187
* ipaddr - Refers to an IP address in network order
188188
* dev - Device structure
189+
* check_expiry - Expiry check
189190
*
190191
* Assumptions:
191192
* 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)
194195
****************************************************************************/
195196

196197
static FAR struct arp_entry_s *arp_lookup(in_addr_t ipaddr,
197-
FAR struct net_driver_s *dev)
198+
FAR struct net_driver_s *dev,
199+
bool check_expiry)
198200
{
199201
FAR struct arp_entry_s *tabptr;
200202
int i;
@@ -205,10 +207,23 @@ static FAR struct arp_entry_s *arp_lookup(in_addr_t ipaddr,
205207
{
206208
tabptr = &g_arptable[i];
207209
if (tabptr->at_dev == dev &&
208-
net_ipv4addr_cmp(ipaddr, tabptr->at_ipaddr) &&
209-
clock_systime_ticks() - tabptr->at_time <= ARP_MAXAGE_TICK)
210+
net_ipv4addr_cmp(ipaddr, tabptr->at_ipaddr))
210211
{
211-
return tabptr;
212+
/* Find matching entries */
213+
214+
if (!check_expiry)
215+
{
216+
return tabptr; /* Ignore expiration time */
217+
}
218+
219+
/* Check if it has expired */
220+
221+
if (clock_systime_ticks() - tabptr->at_time <= ARP_MAXAGE_TICK)
222+
{
223+
return tabptr;
224+
}
225+
226+
return NULL; /* Expired */
212227
}
213228
}
214229

@@ -401,21 +416,22 @@ void arp_hdr_update(FAR struct net_driver_s *dev, FAR uint16_t *pipaddr,
401416
* used simply to determine if the Ethernet MAC address is
402417
* available.
403418
* dev - Device structure
419+
* check_expiry - Expiry check
404420
*
405421
* Assumptions
406422
* The network is locked to assure exclusive access to the ARP table.
407423
*
408424
****************************************************************************/
409425

410426
int arp_find(in_addr_t ipaddr, FAR uint8_t *ethaddr,
411-
FAR struct net_driver_s *dev)
427+
FAR struct net_driver_s *dev, bool check_expiry)
412428
{
413429
FAR struct arp_entry_s *tabptr;
414430
struct arp_table_info_s info;
415431

416432
/* Check if the IPv4 address is already in the ARP table. */
417433

418-
tabptr = arp_lookup(ipaddr, dev);
434+
tabptr = arp_lookup(ipaddr, dev, check_expiry);
419435
if (tabptr != NULL)
420436
{
421437
/* 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)
485501
#endif
486502
/* Check if the IPv4 address is in the ARP table. */
487503

488-
tabptr = arp_lookup(ipaddr, dev);
504+
tabptr = arp_lookup(ipaddr, dev, false);
489505
if (tabptr != NULL)
490506
{
491507
/* Notify to netlink */

net/netdev/netdev_findbyaddr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ netdev_prefixlen_findby_lipv4addr(in_addr_t lipaddr, FAR int8_t *prefixlen)
128128

129129
if (len > bestpref
130130
#ifdef CONFIG_NET_ARP
131-
|| (len == bestpref && arp_find(lipaddr, NULL, dev) == OK)
131+
|| (len == bestpref
132+
&& arp_find(lipaddr, NULL, dev, true) == OK)
132133
#endif
133134
)
134135
{

net/netdev/netdev_ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ static int netdev_arp_ioctl(FAR struct socket *psock, int cmd,
14521452
req->arp_pa.sa_family == AF_INET)
14531453
{
14541454
ret = arp_find(addr->sin_addr.s_addr,
1455-
(FAR uint8_t *)req->arp_ha.sa_data, dev);
1455+
(FAR uint8_t *)req->arp_ha.sa_data, dev, true);
14561456
if (ret >= 0)
14571457
{
14581458
/* Return the mapped hardware address. */

0 commit comments

Comments
 (0)