Separate mib2 counter/table callbacks from snmp agent. This both cleans up the code and should allow integration of a 3rd party agent/mib2.

This commit is contained in:
goldsimon
2015-09-08 09:47:30 +02:00
parent 1e4f312352
commit 8a0fb03e21
25 changed files with 639 additions and 1035 deletions

View File

@@ -48,7 +48,6 @@
#include "lwip/ip.h"
#include "lwip/def.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include <string.h>
@@ -87,7 +86,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
ip4_addr_t* src;
ICMP_STATS_INC(icmp.recv);
snmp_inc_icmpinmsgs();
MIB2_STATS_INC(mib2.icmpinmsgs);
iphdr_in = ip4_current_header();
hlen = IPH_HL(iphdr_in) * 4;
@@ -138,7 +137,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n"));
pbuf_free(p);
ICMP_STATS_INC(icmp.chkerr);
snmp_inc_icmpinerrors();
MIB2_STATS_INC(mib2.icmpinerrors);
return;
}
}
@@ -223,9 +222,9 @@ icmp_input(struct pbuf *p, struct netif *inp)
ICMP_STATS_INC(icmp.xmit);
/* increase number of messages attempted to send */
snmp_inc_icmpoutmsgs();
MIB2_STATS_INC(mib2.icmpoutmsgs);
/* increase number of echo replies attempted to send */
snmp_inc_icmpoutechoreps();
MIB2_STATS_INC(mib2.icmpoutechoreps);
/* send an ICMP packet */
ret = ip4_output_if(p, src, IP_HDRINCL,
@@ -246,13 +245,13 @@ icmp_input(struct pbuf *p, struct netif *inp)
lenerr:
pbuf_free(p);
ICMP_STATS_INC(icmp.lenerr);
snmp_inc_icmpinerrors();
MIB2_STATS_INC(mib2.icmpinerrors);
return;
#if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN || !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING
icmperr:
pbuf_free(p);
ICMP_STATS_INC(icmp.err);
snmp_inc_icmpinerrors();
MIB2_STATS_INC(mib2.icmpinerrors);
return;
#endif /* LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN || !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING */
}
@@ -344,9 +343,9 @@ icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
#endif
ICMP_STATS_INC(icmp.xmit);
/* increase number of messages attempted to send */
snmp_inc_icmpoutmsgs();
MIB2_STATS_INC(mib2.icmpoutmsgs);
/* increase number of destination unreachable messages attempted to send */
snmp_inc_icmpouttimeexcds();
MIB2_STATS_INC(mib2.icmpouttimeexcds);
ip4_addr_copy(iphdr_src, iphdr->src);
ip4_output_if(q, NULL, &iphdr_src, ICMP_TTL, 0, IP_PROTO_ICMP, netif);
}

View File

@@ -53,7 +53,6 @@
#include "lwip/raw.h"
#include "lwip/udp.h"
#include "lwip/tcp_impl.h"
#include "lwip/snmp.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "lwip/stats.h"
@@ -188,7 +187,7 @@ ip4_route(const ip4_addr_t *dest)
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
IP_STATS_INC(ip.rterr);
snmp_inc_ipoutnoroutes();
MIB2_STATS_INC(mib2.ipoutnoroutes);
return NULL;
}
@@ -302,7 +301,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
IPH_TTL_SET(iphdr, IPH_TTL(iphdr) - 1);
/* send ICMP if TTL == 0 */
if (IPH_TTL(iphdr) == 0) {
snmp_inc_ipinhdrerrors();
MIB2_STATS_INC(mib2.ipinhdrerrors);
#if LWIP_ICMP
/* Don't send ICMP messages in response to ICMP messages */
if (IPH_PROTO(iphdr) != IP_PROTO_ICMP) {
@@ -324,8 +323,8 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
ip4_addr3_16(ip4_current_dest_addr()), ip4_addr4_16(ip4_current_dest_addr())));
IP_STATS_INC(ip.fw);
MIB2_STATS_INC(mib2.ipforwdatagrams);
IP_STATS_INC(ip.xmit);
snmp_inc_ipforwdatagrams();
PERF_STOP("ip_forward");
/* don't fragment if interface has mtu set to 0 [loopif] */
@@ -346,7 +345,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
netif->output(netif, p, ip4_current_dest_addr());
return;
return_noroute:
snmp_inc_ipoutnoroutes();
MIB2_STATS_INC(mib2.ipoutnoroutes);
}
#endif /* IP_FORWARD */
@@ -393,7 +392,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
#endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING || LWIP_IGMP */
IP_STATS_INC(ip.recv);
snmp_inc_ipinreceives();
MIB2_STATS_INC(mib2.ipinreceives);
/* identify the IP header */
iphdr = (struct ip_hdr *)p->payload;
@@ -403,7 +402,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
pbuf_free(p);
IP_STATS_INC(ip.err);
IP_STATS_INC(ip.drop);
snmp_inc_ipinhdrerrors();
MIB2_STATS_INC(mib2.ipinhdrerrors);
return ERR_OK;
}
@@ -442,7 +441,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
pbuf_free(p);
IP_STATS_INC(ip.lenerr);
IP_STATS_INC(ip.drop);
snmp_inc_ipindiscards();
MIB2_STATS_INC(mib2.ipindiscards);
return ERR_OK;
}
@@ -457,7 +456,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
pbuf_free(p);
IP_STATS_INC(ip.chkerr);
IP_STATS_INC(ip.drop);
snmp_inc_ipinhdrerrors();
MIB2_STATS_INC(mib2.ipinhdrerrors);
return ERR_OK;
}
}
@@ -577,8 +576,8 @@ ip4_input(struct pbuf *p, struct netif *inp)
/* free (drop) packet pbufs */
pbuf_free(p);
IP_STATS_INC(ip.drop);
snmp_inc_ipinaddrerrors();
snmp_inc_ipindiscards();
MIB2_STATS_INC(mib2.ipinaddrerrors);
MIB2_STATS_INC(mib2.ipindiscards);
return ERR_OK;
}
}
@@ -595,8 +594,8 @@ ip4_input(struct pbuf *p, struct netif *inp)
} else
#endif /* IP_FORWARD */
{
snmp_inc_ipinaddrerrors();
snmp_inc_ipindiscards();
MIB2_STATS_INC(mib2.ipinaddrerrors);
MIB2_STATS_INC(mib2.ipindiscards);
}
pbuf_free(p);
return ERR_OK;
@@ -620,7 +619,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
IP_STATS_INC(ip.opterr);
IP_STATS_INC(ip.drop);
/* unsupported protocol feature */
snmp_inc_ipinunknownprotos();
MIB2_STATS_INC(mib2.ipinunknownprotos);
return ERR_OK;
#endif /* IP_REASSEMBLY */
}
@@ -638,7 +637,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
IP_STATS_INC(ip.opterr);
IP_STATS_INC(ip.drop);
/* unsupported protocol feature */
snmp_inc_ipinunknownprotos();
MIB2_STATS_INC(mib2.ipinunknownprotos);
return ERR_OK;
}
#endif /* IP_OPTIONS_ALLOWED == 0 */
@@ -666,19 +665,19 @@ ip4_input(struct pbuf *p, struct netif *inp)
#if LWIP_UDPLITE
case IP_PROTO_UDPLITE:
#endif /* LWIP_UDPLITE */
snmp_inc_ipindelivers();
MIB2_STATS_INC(mib2.ipindelivers);
udp_input(p, inp);
break;
#endif /* LWIP_UDP */
#if LWIP_TCP
case IP_PROTO_TCP:
snmp_inc_ipindelivers();
MIB2_STATS_INC(mib2.ipindelivers);
tcp_input(p, inp);
break;
#endif /* LWIP_TCP */
#if LWIP_ICMP
case IP_PROTO_ICMP:
snmp_inc_ipindelivers();
MIB2_STATS_INC(mib2.ipindelivers);
icmp_input(p, inp);
break;
#endif /* LWIP_ICMP */
@@ -703,7 +702,7 @@ ip4_input(struct pbuf *p, struct netif *inp)
IP_STATS_INC(ip.proterr);
IP_STATS_INC(ip.drop);
snmp_inc_ipinunknownprotos();
MIB2_STATS_INC(mib2.ipinunknownprotos);
}
}
@@ -808,7 +807,7 @@ err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_add
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
snmp_inc_ipoutrequests();
MIB2_STATS_INC(mib2.ipoutrequests);
/* Should the IP header be generated or is it already included in p? */
if (dest != IP_HDRINCL) {
@@ -826,7 +825,7 @@ err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_add
if (pbuf_header(p, optlen_aligned)) {
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_output_if_opt: not enough room for IP options in pbuf\n"));
IP_STATS_INC(ip.err);
snmp_inc_ipoutdiscards();
MIB2_STATS_INC(mib2.ipoutdiscards);
return ERR_BUF;
}
MEMCPY(p->payload, ip_options, optlen);
@@ -846,7 +845,7 @@ err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_add
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_output: not enough room for IP header in pbuf\n"));
IP_STATS_INC(ip.err);
snmp_inc_ipoutdiscards();
MIB2_STATS_INC(mib2.ipoutdiscards);
return ERR_BUF;
}

View File

@@ -46,7 +46,6 @@
#include "lwip/def.h"
#include "lwip/inet_chksum.h"
#include "lwip/netif.h"
#include "lwip/snmp.h"
#include "lwip/stats.h"
#include "lwip/icmp.h"
@@ -170,7 +169,7 @@ ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *p
LWIP_ASSERT("prev->next == ipr", prev->next == ipr);
}
snmp_inc_ipreasmfails();
MIB2_STATS_INC(mib2.ipreasmfails);
#if LWIP_ICMP
iprh = (struct ip_reass_helper *)ipr->p->payload;
if (iprh->start == 0) {
@@ -489,8 +488,8 @@ ip4_reass(struct pbuf *p)
u8_t clen;
IPFRAG_STATS_INC(ip_frag.recv);
snmp_inc_ipreasmreqds();
MIB2_STATS_INC(mib2.ipreasmreqds);
fraghdr = (struct ip_hdr*)p->payload;
if ((IPH_HL(fraghdr) * 4) != IP_HLEN) {
@@ -853,7 +852,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
pbuf_chain(header, rambuf);
netif->output(netif, header, dest);
IPFRAG_STATS_INC(ip_frag.xmit);
snmp_inc_ipfragcreates();
MIB2_STATS_INC(mib2.ipfragcreates);
pbuf_free(header);
} else {
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc() for header failed\n"));
@@ -882,7 +881,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
#if IP_FRAG_USES_STATIC_BUF
pbuf_free(rambuf);
#endif /* IP_FRAG_USES_STATIC_BUF */
snmp_inc_ipfragoks();
MIB2_STATS_INC(mib2.ipfragoks);
return ERR_OK;
}
#endif /* IP_FRAG */