From 4c9fe60693c9e30af30987115f84007d9dca4e51 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Sun, 14 Feb 2010 18:08:16 +0000 Subject: [PATCH] Fixed ARP input processing: only add a new entry if a request was directed as us (RFC 826, Packet Reception), otherwise only update existing entries; internalized some functions --- CHANGELOG | 5 +++++ src/include/netif/etharp.h | 3 --- src/netif/etharp.c | 21 +++++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e09ad3ba..1ba0154c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -131,6 +131,11 @@ HISTORY ++ Bugfixes: + 2010-02-14: Simon Goldschmidt + * etharp.c/.h: Fixed ARP input processing: only add a new entry if a + request was directed as us (RFC 826, Packet Reception), otherwise + only update existing entries; internalized some functions + 2010-02-14: Simon Goldschmidt * netif.h, etharp.c, tcpip.c: Fixed bug #28183 (ARP and TCP/IP cannot be disabled on netif used for PPPoE) by adding a new netif flag diff --git a/src/include/netif/etharp.h b/src/include/netif/etharp.h index 63b66d7a..3eb0604f 100644 --- a/src/include/netif/etharp.h +++ b/src/include/netif/etharp.h @@ -163,9 +163,6 @@ struct etharp_q_entry { void etharp_tmr(void); s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr, struct eth_addr **eth_ret, ip_addr_t **ip_ret); -void etharp_ip_input(struct netif *netif, struct pbuf *p); -void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, - struct pbuf *p); err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr); err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q); err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr); diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 79872f56..d64bafc4 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -344,10 +344,10 @@ find_entry(ip_addr_t *ipaddr, u8_t flags) } /* { we have no match } => try to create a new entry */ - /* no empty entry found and not allowed to recycle? */ - if (((empty == ARP_TABLE_SIZE) && ((flags & ETHARP_TRY_HARD) == 0)) - /* or don't create new entry, only search? */ - || ((flags & ETHARP_FIND_ONLY) != 0)) { + /* don't create new entry, only search? */ + if (((flags & ETHARP_FIND_ONLY) != 0) || + /* or no empty entry found and not allowed to recycle? */ + ((empty == ARP_TABLE_SIZE) && ((flags & ETHARP_TRY_HARD) == 0))) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: no empty entry found and not allowed to recycle\n")); return (s8_t)ERR_MEM; } @@ -565,6 +565,7 @@ etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr, return -1; } +#if ETHARP_TRUST_IP_MAC /** * Updates the ARP table using the given IP packet. * @@ -580,7 +581,7 @@ etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr, * * @see pbuf_free() */ -void +static void etharp_ip_input(struct netif *netif, struct pbuf *p) { struct eth_hdr *ethhdr; @@ -604,12 +605,12 @@ etharp_ip_input(struct netif *netif, struct pbuf *p) } LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_ip_input: updating ETHARP table.\n")); - /* update ARP table */ + /* update the source IP address in the cache, if present */ /* @todo We could use ETHARP_TRY_HARD if we think we are going to talk * back soon (for example, if the destination IP address is ours. */ - update_arp_entry(netif, &(iphdr->src), &(ethhdr->src), 0); + update_arp_entry(netif, &(iphdr->src), &(ethhdr->src), ETHARP_FIND_ONLY); } - +#endif /* ETHARP_TRUST_IP_MAC */ /** * Responds to ARP requests to us. Upon ARP replies to us, add entry to cache @@ -626,7 +627,7 @@ etharp_ip_input(struct netif *netif, struct pbuf *p) * * @see pbuf_free() */ -void +static void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) { struct etharp_hdr *hdr; @@ -704,7 +705,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) /* ARP message not directed to us? */ } else { /* update the source IP address in the cache, if present */ - update_arp_entry(netif, &sipaddr, &(hdr->shwaddr), 0); + update_arp_entry(netif, &sipaddr, &(hdr->shwaddr), ETHARP_FIND_ONLY); } /* now act on the message itself */