diff --git a/CHANGELOG b/CHANGELOG index f39acfa3..c6c73355 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,9 @@ HISTORY ++ New features: + 2007-11-28 Simon Goldschmidt + * etharp.c, stats.c, stats.h, opt.h: Introduced ETHARP_STATS + 2007-11-25 Simon Goldschmidt * dhcp.c: dhcp_unfold_reply() uses pbuf_copy_partial instead of its own copy algorithm. diff --git a/src/core/stats.c b/src/core/stats.c index e693d869..7309e2cb 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -91,7 +91,6 @@ stats_display_mem(struct stats_mem *mem, char *name) LWIP_PLATFORM_DIAG(("used: %"MEM_SIZE_F"\n\t", mem->used)); LWIP_PLATFORM_DIAG(("max: %"MEM_SIZE_F"\n\t", mem->max)); LWIP_PLATFORM_DIAG(("err: %"MEM_SIZE_F"\n", mem->err)); - } void @@ -107,6 +106,9 @@ stats_display(void) #if LINK_STATS stats_display_proto(&lwip_stats.link, "LINK"); #endif +#if ETHARP_STATS + stats_display_proto(&lwip_stats.etharp, "ETHARP"); +#endif #if IPFRAG_STATS stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG"); #endif diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index c79aec9f..32827dc0 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1007,6 +1007,13 @@ #define LINK_STATS 1 #endif +/** + * ETHARP_STATS==1: Enable etharp stats. + */ +#ifndef ETHARP_STATS +#define ETHARP_STATS (LWIP_ARP) +#endif + /** * IP_STATS==1: Enable IP stats. */ diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h index ee319b24..755092ec 100644 --- a/src/include/lwip/stats.h +++ b/src/include/lwip/stats.h @@ -105,6 +105,9 @@ struct stats_ { #if LINK_STATS struct stats_proto link; #endif +#if ETHARP_STATS + struct stats_proto etharp; +#endif #if IPFRAG_STATS struct stats_proto ip_frag; #endif @@ -180,6 +183,12 @@ extern struct stats_ lwip_stats; #define IPFRAG_STATS_INC(x) #endif +#if ETHARP_STATS +#define ETHARP_STATS_INC(x) STATS_INC(x) +#else +#define ETHARP_STATS_INC(x) +#endif + #if LINK_STATS #define LINK_STATS_INC(x) STATS_INC(x) #else diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 40775848..093ad97f 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -251,6 +251,7 @@ find_entry(struct ip_addr *ipaddr, u8_t flags) /* the per-pcb-cached entry is stable */ if (ip_addr_cmp(ipaddr, &arp_table[per_pcb_cache].ipaddr)) { /* per-pcb cached entry was the right one! */ + ETHARP_STATS_INC(etharp.cachehit); return per_pcb_cache; } } @@ -260,6 +261,7 @@ find_entry(struct ip_addr *ipaddr, u8_t flags) /* the cached entry is stable */ if (ip_addr_cmp(ipaddr, &arp_table[etharp_cached_entry].ipaddr)) { /* cached entry was the right one! */ + ETHARP_STATS_INC(etharp.cachehit); return etharp_cached_entry; } } @@ -624,6 +626,8 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) since a struct etharp_hdr is pointed to p->payload, so it musn't be chained! */ if (p->len < sizeof(struct etharp_hdr)) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 1, ("etharp_arp_input: packet dropped, too short (%"S16_F"/%"S16_F")\n", p->tot_len, (s16_t)sizeof(struct etharp_hdr))); + ETHARP_STATS_INC(etharp.lenerr); + ETHARP_STATS_INC(etharp.drop); pbuf_free(p); return; } @@ -638,15 +642,17 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 1, ("etharp_arp_input: packet dropped, wrong hw type, hwlen, proto, protolen or ethernet type (%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F")\n", hdr->hwtype, ARPH_HWLEN(hdr), hdr->proto, ARPH_PROTOLEN(hdr), hdr->ethhdr.type)); + ETHARP_STATS_INC(etharp.proterr); + ETHARP_STATS_INC(etharp.drop); pbuf_free(p); return; } + ETHARP_STATS_INC(etharp.recv); #if LWIP_AUTOIP /* We have to check if a host already has configured our random * created link local address and continously check if there is - * a host with this IP-address so we can detect collisions - * */ + * a host with this IP-address so we can detect collisions */ autoip_arp_reply(netif, hdr); #endif /* LWIP_AUTOIP */ @@ -728,13 +734,13 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) /* DHCP wants to know about ARP replies from any host with an * IP address also offered to us by the DHCP server. We do not * want to take a duplicate IP address on a single network. - * @todo How should we handle redundant (fail-over) interfaces? - * */ + * @todo How should we handle redundant (fail-over) interfaces? */ dhcp_arp_reply(netif, &sipaddr); #endif break; default: LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: ARP unknown opcode type %"S16_F"\n", htons(hdr->opcode))); + ETHARP_STATS_INC(etharp.err); break; } /* free ARP packet */ @@ -742,7 +748,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) } /** - * Resolve and fill-in Ethernet address header for outgoing packet. + * Resolve and fill-in Ethernet address header for outgoing IP packet. * * For IP multicast and broadcast, corresponding Ethernet addresses * are selected and the packet is transmitted on the link. @@ -874,8 +880,10 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q) /* could not find or create entry? */ if (i < 0) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not create ARP entry\n")); - if (q) + if (q) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: packet dropped\n")); + ETHARP_STATS_INC(etharp.memerr); + } return (err_t)i; } @@ -969,6 +977,7 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q) /* { result == ERR_MEM } through initialization */ } } else { + ETHARP_STATS_INC(etharp.memerr); LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not queue a copy of PBUF_REF packet %p (out of memory)\n", (void *)q)); /* { result == ERR_MEM } through initialization */ } @@ -1017,6 +1026,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, /* could allocate a pbuf for an ARP request? */ if (p == NULL) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 2, ("etharp_raw: could not allocate pbuf for ARP request.\n")); + ETHARP_STATS_INC(etharp.memerr); return ERR_MEM; } LWIP_ASSERT("check that first pbuf can hold struct etharp_hdr", @@ -1050,6 +1060,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, hdr->ethhdr.type = htons(ETHTYPE_ARP); /* send ARP query */ result = netif->linkoutput(netif, p); + ETHARP_STATS_INC(etharp.xmit); /* free ARP query packet */ pbuf_free(p); p = NULL;