MIB2_STATS: moved netif related mib2 counters into a struct (defined in stats.h), added ifInErrors/ifInUnkownProtos (now handled in etharp.c) and ifOutErrors

This commit is contained in:
goldsimon 2015-09-28 08:50:21 +02:00
parent dbe703cfb0
commit 94625a8fa8
5 changed files with 53 additions and 33 deletions

View File

@ -2141,64 +2141,66 @@ ifentry_get_value(struct obj_def *od, u16_t len, void *value)
case 10: /* ifInOctets */ case 10: /* ifInOctets */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->ifinoctets; *uint_ptr = netif->mib2_counters.ifinoctets;
} }
break; break;
case 11: /* ifInUcastPkts */ case 11: /* ifInUcastPkts */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->ifinucastpkts; *uint_ptr = netif->mib2_counters.ifinucastpkts;
} }
break; break;
case 12: /* ifInNUcastPkts */ case 12: /* ifInNUcastPkts */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->ifinnucastpkts; *uint_ptr = netif->mib2_counters.ifinnucastpkts;
} }
break; break;
case 13: /* ifInDiscarts */ case 13: /* ifInDiscards */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->ifindiscards; *uint_ptr = netif->mib2_counters.ifindiscards;
} }
break; break;
case 14: /* ifInErrors */ case 14: /* ifInErrors */
case 15: /* ifInUnkownProtos */
/** @todo add these counters! */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = 0; *uint_ptr = netif->mib2_counters.ifinerrors;
}
case 15: /* ifInUnkownProtos */
{
u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->mib2_counters.ifinunknownprotos;
} }
break; break;
case 16: /* ifOutOctets */ case 16: /* ifOutOctets */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->ifoutoctets; *uint_ptr = netif->mib2_counters.ifoutoctets;
} }
break; break;
case 17: /* ifOutUcastPkts */ case 17: /* ifOutUcastPkts */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->ifoutucastpkts; *uint_ptr = netif->mib2_counters.ifoutucastpkts;
} }
break; break;
case 18: /* ifOutNUcastPkts */ case 18: /* ifOutNUcastPkts */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->ifoutnucastpkts; *uint_ptr = netif->mib2_counters.ifoutnucastpkts;
} }
break; break;
case 19: /* ifOutDiscarts */ case 19: /* ifOutDiscarts */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = netif->ifoutdiscards; *uint_ptr = netif->mib2_counters.ifoutdiscards;
} }
break; break;
case 20: /* ifOutErrors */ case 20: /* ifOutErrors */
/** @todo add this counter! */
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t*)value;
*uint_ptr = 0; *uint_ptr = netif->mib2_counters.ifouterrors;
} }
break; break;
case 21: /* ifOutQLen */ case 21: /* ifOutQLen */

View File

@ -42,6 +42,8 @@
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/stats.h"
#if LWIP_DHCP #if LWIP_DHCP
struct dhcp; struct dhcp;
#endif #endif
@ -49,7 +51,7 @@ struct dhcp;
struct autoip; struct autoip;
#endif #endif
#if LWIP_IPV6_DHCP6 #if LWIP_IPV6_DHCP6
#include "lwip/dhcp6.h" struct dhcp6;
#endif /* LWIP_IPV6_DHCP6 */ #endif /* LWIP_IPV6_DHCP6 */
#ifdef __cplusplus #ifdef __cplusplus
@ -277,14 +279,7 @@ struct netif {
/** timestamp at last change made (up/down) */ /** timestamp at last change made (up/down) */
u32_t ts; u32_t ts;
/** counters */ /** counters */
u32_t ifinoctets; struct stats_mib2_netif_ctrs mib2_counters;
u32_t ifinucastpkts;
u32_t ifinnucastpkts;
u32_t ifindiscards;
u32_t ifoutoctets;
u32_t ifoutucastpkts;
u32_t ifoutnucastpkts;
u32_t ifoutdiscards;
#endif /* MIB2_STATS */ #endif /* MIB2_STATS */
#if LWIP_IPV4 && LWIP_IGMP #if LWIP_IPV4 && LWIP_IGMP
/** This function could be called to add or delete an entry in the multicast /** This function could be called to add or delete an entry in the multicast

View File

@ -93,8 +93,8 @@ enum snmp_ifType {
#define MIB2_COPY_SYSUPTIME_TO(ptrToVal) (*(ptrToVal) = (sys_now() / 10)) #define MIB2_COPY_SYSUPTIME_TO(ptrToVal) (*(ptrToVal) = (sys_now() / 10))
#endif #endif
#define MIB2_STATS_NETIF_INC(n, x) do { ++(n)->x; } while(0) #define MIB2_STATS_NETIF_INC(n, x) do { ++(n)->mib2_counters.x; } while(0)
#define MIB2_STATS_NETIF_ADD(n, x, val) do { (n)->x += val; } while(0) #define MIB2_STATS_NETIF_ADD(n, x, val) do { (n)->mib2_counters.x += (val); } while(0)
#define MIB2_INIT_NETIF(netif, type, speed) do { \ #define MIB2_INIT_NETIF(netif, type, speed) do { \
/* use "snmp_ifType" enum from snmp_mib2.h for "type", snmp_ifType_ethernet_csmacd by example */ \ /* use "snmp_ifType" enum from snmp_mib2.h for "type", snmp_ifType_ethernet_csmacd by example */ \
@ -102,14 +102,17 @@ enum snmp_ifType {
/* your link speed here (units: bits per second) */ \ /* your link speed here (units: bits per second) */ \
(netif)->link_speed = (speed);\ (netif)->link_speed = (speed);\
(netif)->ts = 0; \ (netif)->ts = 0; \
(netif)->ifinoctets = 0; \ (netif)->mib2_counters.ifinoctets = 0; \
(netif)->ifinucastpkts = 0; \ (netif)->mib2_counters.ifinucastpkts = 0; \
(netif)->ifinnucastpkts = 0; \ (netif)->mib2_counters.ifinnucastpkts = 0; \
(netif)->ifindiscards = 0; \ (netif)->mib2_counters.ifindiscards = 0; \
(netif)->ifoutoctets = 0; \ (netif)->mib2_counters.ifinerrors = 0; \
(netif)->ifoutucastpkts = 0; \ (netif)->mib2_counters.ifinunknownprotos = 0; \
(netif)->ifoutnucastpkts = 0; \ (netif)->mib2_counters.ifoutoctets = 0; \
(netif)->ifoutdiscards = 0; } while(0) (netif)->mib2_counters.ifoutucastpkts = 0; \
(netif)->mib2_counters.ifoutnucastpkts = 0; \
(netif)->mib2_counters.ifoutdiscards = 0; \
(netif)->mib2_counters.ifouterrors = 0; } while(0)
#else /* MIB2_STATS */ #else /* MIB2_STATS */
#ifndef MIB2_COPY_SYSUPTIME_TO #ifndef MIB2_COPY_SYSUPTIME_TO
#define MIB2_COPY_SYSUPTIME_TO(ptrToVal) #define MIB2_COPY_SYSUPTIME_TO(ptrToVal)
@ -173,10 +176,13 @@ void mib2_udp_unbind(struct udp_pcb *pcb);
#define snmp_inc_ifinucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinucastpkts) #define snmp_inc_ifinucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinucastpkts)
#define snmp_inc_ifinnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinnucastpkts) #define snmp_inc_ifinnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinnucastpkts)
#define snmp_inc_ifindiscards(ni) MIB2_STATS_NETIF_INC(ni, ifindiscards) #define snmp_inc_ifindiscards(ni) MIB2_STATS_NETIF_INC(ni, ifindiscards)
#define snmp_inc_ifinerrors(ni) MIB2_STATS_NETIF_INC(ni, ifinerrors)
#define snmp_inc_ifinunknownprotos(ni) MIB2_STATS_NETIF_INC(ni, ifinunknownprotos)
#define snmp_add_ifoutoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifoutoctets, value) #define snmp_add_ifoutoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifoutoctets, value)
#define snmp_inc_ifoutucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutucastpkts) #define snmp_inc_ifoutucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutucastpkts)
#define snmp_inc_ifoutnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutnucastpkts) #define snmp_inc_ifoutnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutnucastpkts)
#define snmp_inc_ifoutdiscards(ni) MIB2_STATS_NETIF_INC(ni, ifoutdiscards) #define snmp_inc_ifoutdiscards(ni) MIB2_STATS_NETIF_INC(ni, ifoutdiscards)
#define snmp_inc_ifouterrors(ni) MIB2_STATS_NETIF_INC(ni, ifouterrors)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -176,6 +176,20 @@ struct stats_mib2 {
u32_t icmpoutaddrmaskreps; /* @todo: never incremented */ u32_t icmpoutaddrmaskreps; /* @todo: never incremented */
}; };
struct stats_mib2_netif_ctrs {
u32_t ifinoctets;
u32_t ifinucastpkts;
u32_t ifinnucastpkts;
u32_t ifindiscards;
u32_t ifinerrors;
u32_t ifinunknownprotos;
u32_t ifoutoctets;
u32_t ifoutucastpkts;
u32_t ifoutnucastpkts;
u32_t ifoutdiscards;
u32_t ifouterrors;
};
struct stats_ { struct stats_ {
#if LINK_STATS #if LINK_STATS
struct stats_proto link; struct stats_proto link;

View File

@ -1395,6 +1395,7 @@ ethernet_input(struct pbuf *p, struct netif *netif)
/* a packet with only an ethernet header (or less) is not valid for us */ /* a packet with only an ethernet header (or less) is not valid for us */
ETHARP_STATS_INC(etharp.proterr); ETHARP_STATS_INC(etharp.proterr);
ETHARP_STATS_INC(etharp.drop); ETHARP_STATS_INC(etharp.drop);
MIB2_STATS_NETIF_INC(netif, ifinerrors);
goto free_and_return; goto free_and_return;
} }
@ -1416,6 +1417,7 @@ ethernet_input(struct pbuf *p, struct netif *netif)
/* a packet with only an ethernet/vlan header (or less) is not valid for us */ /* a packet with only an ethernet/vlan header (or less) is not valid for us */
ETHARP_STATS_INC(etharp.proterr); ETHARP_STATS_INC(etharp.proterr);
ETHARP_STATS_INC(etharp.drop); ETHARP_STATS_INC(etharp.drop);
MIB2_STATS_NETIF_INC(netif, ifinerrors);
goto free_and_return; goto free_and_return;
} }
#if defined(LWIP_HOOK_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK_FN) /* if not, allow all VLANs */ #if defined(LWIP_HOOK_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK) || defined(ETHARP_VLAN_CHECK_FN) /* if not, allow all VLANs */
@ -1514,6 +1516,7 @@ ethernet_input(struct pbuf *p, struct netif *netif)
default: default:
ETHARP_STATS_INC(etharp.proterr); ETHARP_STATS_INC(etharp.proterr);
ETHARP_STATS_INC(etharp.drop); ETHARP_STATS_INC(etharp.drop);
MIB2_STATS_NETIF_INC(netif, ifinunknownprotos);
goto free_and_return; goto free_and_return;
} }