From 7b5ef3ae58e5df47401b8a0f412ad7b7d456080c Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 30 Sep 2015 15:05:52 +0200 Subject: [PATCH] implement/remove missing IP counters in stats_mib2 (see task #13731) --- src/core/ipv4/ip_frag.c | 23 ++++++++++++++--------- src/core/snmp/mib2.c | 5 ++--- src/include/lwip/stats.h | 5 ++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/core/ipv4/ip_frag.c b/src/core/ipv4/ip_frag.c index 4577cb71..a278ffe8 100644 --- a/src/core/ipv4/ip_frag.c +++ b/src/core/ipv4/ip_frag.c @@ -618,6 +618,8 @@ ip4_reass(struct pbuf *p) /* and adjust the number of pbufs currently queued for reassembly. */ ip_reass_pbufcount -= pbuf_clen(p); + MIB2_STATS_INC(mib2.ipreasmoks); + /* Return the pbuf chain */ return p; } @@ -717,7 +719,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) rambuf = pbuf_alloc(PBUF_LINK, 0, PBUF_REF); if (rambuf == NULL) { LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc(PBUF_LINK, 0, PBUF_REF) failed\n")); - return ERR_MEM; + goto memerr; } rambuf->tot_len = rambuf->len = mtu; rambuf->payload = LWIP_MEM_ALIGN((void *)buf); @@ -757,7 +759,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) #if LWIP_NETIF_TX_SINGLE_PBUF rambuf = pbuf_alloc(PBUF_IP, cop, PBUF_RAM); if (rambuf == NULL) { - return ERR_MEM; + goto memerr; } LWIP_ASSERT("this needs a pbuf in one piece!", (rambuf->len == rambuf->tot_len) && (rambuf->next == NULL)); @@ -765,7 +767,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) /* make room for the IP header */ if(pbuf_header(rambuf, IP_HLEN)) { pbuf_free(rambuf); - return ERR_MEM; + goto memerr; } /* fill in the IP header */ SMEMCPY(rambuf->payload, original_iphdr, IP_HLEN); @@ -778,7 +780,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) */ rambuf = pbuf_alloc(PBUF_LINK, IP_HLEN, PBUF_RAM); if (rambuf == NULL) { - return ERR_MEM; + goto memerr; } LWIP_ASSERT("this needs a pbuf in one piece!", (p->len >= (IP_HLEN))); @@ -801,14 +803,14 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) pcr = ip_frag_alloc_pbuf_custom_ref(); if (pcr == NULL) { pbuf_free(rambuf); - return ERR_MEM; + goto memerr; } /* Mirror this pbuf, although we might not need all of it. */ newpbuf = pbuf_alloced_custom(PBUF_RAW, newpbuflen, PBUF_REF, &pcr->pc, p->payload, newpbuflen); if (newpbuf == NULL) { ip_frag_free_pbuf_custom_ref(pcr); pbuf_free(rambuf); - return ERR_MEM; + goto memerr; } pbuf_ref(p); pcr->original = p; @@ -842,8 +844,8 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) pbuf_realloc(rambuf, left + IP_HLEN); } - /* This part is ugly: we alloc a RAM based pbuf for - * the link level header for each chunk and then + /* This part is ugly: we alloc a RAM based pbuf for + * the link level header for each chunk and then * free it. A PBUF_ROM style pbuf for which pbuf_header * worked would make things simpler. */ @@ -857,7 +859,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) } else { LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc() for header failed\n")); pbuf_free(rambuf); - return ERR_MEM; + goto memerr; } #else /* IP_FRAG_USES_STATIC_BUF */ /* No need for separate header pbuf - we allowed room for it in rambuf @@ -883,6 +885,9 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) #endif /* IP_FRAG_USES_STATIC_BUF */ MIB2_STATS_INC(mib2.ipfragoks); return ERR_OK; +memerr: + MIB2_STATS_INC(mib2.ipfragfails); + return ERR_MEM; } #endif /* IP_FRAG */ diff --git a/src/core/snmp/mib2.c b/src/core/snmp/mib2.c index bf1f0449..0c9d861c 100644 --- a/src/core/snmp/mib2.c +++ b/src/core/snmp/mib2.c @@ -2575,11 +2575,10 @@ ip_get_value(struct obj_def *od, u16_t len, void *value) *uint_ptr = STATS_GET(mib2.ipfragcreates); } break; - case 23: /* ipRoutingDiscards */ - /** @todo can lwIP discard routes at all?? hardwire this to 0?? */ + case 23: /* ipRoutingDiscards: not supported -> always 0 */ { u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.iproutingdiscards); + *uint_ptr = 0; } break; default: diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h index 1e68dd71..6078a2d1 100644 --- a/src/include/lwip/stats.h +++ b/src/include/lwip/stats.h @@ -120,12 +120,11 @@ struct stats_mib2 { u32_t ipoutrequests; u32_t ipoutdiscards; u32_t ipoutnoroutes; - u32_t ipreasmoks; /* @todo: never incremented */ + u32_t ipreasmoks; u32_t ipreasmfails; u32_t ipfragoks; - u32_t ipfragfails; /* @todo: never incremented */ + u32_t ipfragfails; u32_t ipfragcreates; - u32_t iproutingdiscards; /* @todo: never incremented */ u32_t ipreasmreqds; u32_t ipforwdatagrams; u32_t ipinreceives;