From be316e81a70616d618bc83c630e340862e6a5cb1 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 4 May 2007 19:31:27 +0000 Subject: [PATCH] Introduced fast one-entry-cache to speed up ARP lookup when sending multiple packets to the same host. --- CHANGELOG | 4 ++++ src/netif/etharp.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 7221e02e..35c69379 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,10 @@ HISTORY ++ New features: + 2007-05-04 Simon Goldschmidt (Atte Kojo) + * etharp.c: Introduced fast one-entry-cache to speed up ARP lookup when sending + multiple packets to the same host. + 2007-05-04 Frédéric Bernon, Jonathan Larmour * sockets.c, api.h, api_lib.c, api_msg.h, api_msg.c: Fix bug #19162 "lwip_sento: a possible to corrupt remote addr/port connection state". Reduce problems "not enought memory" with diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 73d679d2..87f6e17b 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -104,6 +104,7 @@ struct etharp_entry { static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; static struct etharp_entry arp_table[ARP_TABLE_SIZE]; +static u8_t etharp_cached_entry = 0; /** * Try hard to create a new entry - we want the IP address to appear in @@ -232,6 +233,19 @@ static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags) u8_t age_queue = 0; #endif + /* First, test if the last call to this function asked for the + * same address. If so, we're really fast! */ + if (ipaddr) { + /* ipaddr to search for was given */ + if (arp_table[etharp_cached_entry].state == ETHARP_STATE_STABLE) { + /* the cached entry is stable */ + if (ip_addr_cmp(ipaddr, &arp_table[etharp_cached_entry].ipaddr)) { + /* cached entry was the right one! */ + return etharp_cached_entry; + } + } + } + /** * a) do a search through the cache, remember candidates * b) select candidate entry @@ -260,6 +274,7 @@ static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags) if (ipaddr && ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: found matching pending entry %"U16_F"\n", (u16_t)i)); /* found exact IP address match, simply bail out */ + etharp_cached_entry = i; return i; #if ARP_QUEUEING /* pending with queued packets? */ @@ -283,6 +298,7 @@ static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags) if (ipaddr && ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: found matching stable entry %"U16_F"\n", (u16_t)i)); /* found exact IP address match, simply bail out */ + etharp_cached_entry = i; return i; /* remember entry with oldest stable entry in oldest, its age in maxtime */ } else if (arp_table[i].ctime >= age_stable) { @@ -357,6 +373,7 @@ static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags) ip_addr_set(&arp_table[i].ipaddr, ipaddr); } arp_table[i].ctime = 0; + etharp_cached_entry = i; return (err_t)i; }