For loopback packets, adjust the stats- and snmp-counters for the loopback netif.

This commit is contained in:
goldsimon 2010-02-09 17:00:57 +00:00
parent 3f8e6c423c
commit b1250f003d
2 changed files with 35 additions and 2 deletions

View File

@ -99,6 +99,10 @@ HISTORY
++ Bugfixes: ++ Bugfixes:
2010-02-09: Simon Goldschmidt
* netif.c: For loopback packets, adjust the stats- and snmp-counters
for the loopback netif.
2010-02-08: Simon Goldschmidt 2010-02-08: Simon Goldschmidt
* igmp.c/.h, ip.h: Moved most defines from igmp.h to igmp.c for clarity * igmp.c/.h, ip.h: Moved most defines from igmp.h to igmp.c for clarity
since they are not used anywhere else. since they are not used anywhere else.

View File

@ -45,6 +45,7 @@
#include "lwip/snmp.h" #include "lwip/snmp.h"
#include "lwip/igmp.h" #include "lwip/igmp.h"
#include "netif/etharp.h" #include "netif/etharp.h"
#include "lwip/stats.h"
#if ENABLE_LOOPBACK #if ENABLE_LOOPBACK
#include "lwip/sys.h" #include "lwip/sys.h"
#if LWIP_NETIF_LOOPBACK_MULTITHREADING #if LWIP_NETIF_LOOPBACK_MULTITHREADING
@ -583,11 +584,21 @@ netif_loop_output(struct netif *netif, struct pbuf *p,
u8_t clen = 0; u8_t clen = 0;
#endif /* LWIP_LOOPBACK_MAX_PBUFS */ #endif /* LWIP_LOOPBACK_MAX_PBUFS */
SYS_ARCH_DECL_PROTECT(lev); SYS_ARCH_DECL_PROTECT(lev);
/* If we have a loopif, SNMP counters are adjusted for it,
* if not they are adjusted for 'netif'. */
#if LWIP_HAVE_LOOPIF
struct netif *stats_if = &loop_netif;
#else /* LWIP_HAVE_LOOPIF */
struct netif *stats_if = netif;
#endif /* LWIP_HAVE_LOOPIF */
LWIP_UNUSED_ARG(ipaddr); LWIP_UNUSED_ARG(ipaddr);
/* Allocate a new pbuf */ /* Allocate a new pbuf */
r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM); r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
if (r == NULL) { if (r == NULL) {
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(stats_if);
return ERR_MEM; return ERR_MEM;
} }
#if LWIP_LOOPBACK_MAX_PBUFS #if LWIP_LOOPBACK_MAX_PBUFS
@ -596,7 +607,9 @@ netif_loop_output(struct netif *netif, struct pbuf *p,
if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) || if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) { ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) {
pbuf_free(r); pbuf_free(r);
r = NULL; LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(stats_if);
return ERR_MEM; return ERR_MEM;
} }
netif->loop_cnt_current += clen; netif->loop_cnt_current += clen;
@ -605,7 +618,9 @@ netif_loop_output(struct netif *netif, struct pbuf *p,
/* Copy the whole pbuf queue p into the single pbuf r */ /* Copy the whole pbuf queue p into the single pbuf r */
if ((err = pbuf_copy(r, p)) != ERR_OK) { if ((err = pbuf_copy(r, p)) != ERR_OK) {
pbuf_free(r); pbuf_free(r);
r = NULL; LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(stats_if);
return err; return err;
} }
@ -626,6 +641,10 @@ netif_loop_output(struct netif *netif, struct pbuf *p,
} }
SYS_ARCH_UNPROTECT(lev); SYS_ARCH_UNPROTECT(lev);
LINK_STATS_INC(link.xmit);
snmp_add_ifoutoctets(stats_if, p->tot_len);
snmp_inc_ifoutucastpkts(stats_if);
#if LWIP_NETIF_LOOPBACK_MULTITHREADING #if LWIP_NETIF_LOOPBACK_MULTITHREADING
/* For multithreading environment, schedule a call to netif_poll */ /* For multithreading environment, schedule a call to netif_poll */
tcpip_callback((tcpip_callback_fn)netif_poll, netif); tcpip_callback((tcpip_callback_fn)netif_poll, netif);
@ -644,6 +663,13 @@ void
netif_poll(struct netif *netif) netif_poll(struct netif *netif)
{ {
struct pbuf *in; struct pbuf *in;
/* If we have a loopif, SNMP counters are adjusted for it,
* if not they are adjusted for 'netif'. */
#if LWIP_HAVE_LOOPIF
struct netif *stats_if = &loop_netif;
#else /* LWIP_HAVE_LOOPIF */
struct netif *stats_if = netif;
#endif /* LWIP_HAVE_LOOPIF */
SYS_ARCH_DECL_PROTECT(lev); SYS_ARCH_DECL_PROTECT(lev);
do { do {
@ -678,6 +704,9 @@ netif_poll(struct netif *netif)
SYS_ARCH_UNPROTECT(lev); SYS_ARCH_UNPROTECT(lev);
if (in != NULL) { if (in != NULL) {
LINK_STATS_INC(link.recv);
snmp_add_ifinoctets(stats_if, in->tot_len);
snmp_inc_ifinucastpkts(stats_if);
/* loopback packets are always IP packets! */ /* loopback packets are always IP packets! */
if (ip_input(in, netif) != ERR_OK) { if (ip_input(in, netif) != ERR_OK) {
pbuf_free(in); pbuf_free(in);