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

@@ -51,7 +51,7 @@
#include "lwip/def.h"
#include "lwip/ip.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/snmp_mib2.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "netif/etharp.h"
@@ -184,7 +184,7 @@ static void
etharp_free_entry(int i)
{
/* remove from SNMP ARP index tree */
snmp_delete_arpidx_tree(arp_table[i].netif, &arp_table[i].ipaddr);
mib2_remove_arp_entry(arp_table[i].netif, &arp_table[i].ipaddr);
/* and empty packet queue */
if (arp_table[i].q != NULL) {
/* remove all queued packets */
@@ -512,7 +512,7 @@ etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct et
/* record network interface */
arp_table[i].netif = netif;
/* insert in SNMP ARP index tree */
snmp_insert_arpidx_tree(netif, &arp_table[i].ipaddr);
mib2_add_arp_entry(netif, &arp_table[i].ipaddr);
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_update_arp_entry: updating stable entry %"S16_F"\n", (s16_t)i));
/* update address */

View File

@@ -51,7 +51,7 @@
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/snmp_mib2.h"
#include "lwip/ethip6.h"
#include "netif/etharp.h"
#include "netif/ppp/pppoe.h"
@@ -309,7 +309,7 @@ ethernetif_init(struct netif *netif)
* The last argument should be replaced with your link speed, in units
* of bits per second.
*/
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
netif->state = ethernetif;
netif->name[0] = IFNAME0;

View File

@@ -87,7 +87,7 @@
#include "lwip/sys.h"
#include "lwip/tcpip.h"
#include "lwip/api.h"
#include "lwip/snmp.h"
#include "lwip/snmp_mib2.h"
#include "lwip/sio.h"
#include "lwip/sys.h"
#include "lwip/ip4.h" /* for ip4_input() */
@@ -503,7 +503,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protoc
PPPDEBUG(LOG_WARNING, ("pppos_netif_output[%d]: bad IP packet\n", pcb->netif->num));
LINK_STATS_INC(link.proterr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(pcb->netif);
MIB2_STATS_NETIF_INC(pcb->netif, ifoutdiscards);
return ERR_VAL;
}
}
@@ -521,7 +521,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protoc
if ((err = mppe_compress(pcb, &pcb->mppe_comp, &pb, protocol)) != ERR_OK) {
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(netif);
MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
return err;
}
@@ -540,7 +540,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protoc
err_rte_drop:
LINK_STATS_INC(link.rterr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(netif);
MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
return ERR_RTE;
}
@@ -727,8 +727,8 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) {
pbuf_header(pb, -(s16_t)sizeof(protocol));
LINK_STATS_INC(link.recv);
snmp_inc_ifinucastpkts(pcb->netif);
snmp_add_ifinoctets(pcb->netif, pb->tot_len);
MIB2_STATS_NETIF_INC(pcb->netif, ifinucastpkts);
MIB2_STATS_NETIF_ADD(pcb->netif, ifinoctets, pb->tot_len);
/*
* Toss all non-LCP packets unless LCP is OPEN.
@@ -908,7 +908,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) {
drop:
LINK_STATS_INC(link.drop);
snmp_inc_ifindiscards(pcb->netif);
MIB2_STATS_NETIF_INC(pcb->netif, ifindiscards);
out:
pbuf_free(pb);

View File

@@ -79,7 +79,7 @@
#include "lwip/timers.h"
#include "lwip/memp.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/snmp_mib2.h"
#include "netif/ppp/ppp_impl.h"
#include "netif/ppp/lcp.h"
@@ -206,11 +206,11 @@ static err_t pppoe_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) {
struct pppoe_softc *sc = (struct pppoe_softc *)ctx;
struct pbuf *ph; /* Ethernet + PPPoE header */
err_t ret;
#if LWIP_SNMP
#if MIB2_STATS
u16_t tot_len;
#else /* LWIP_SNMP */
#else /* MIB2_STATS */
LWIP_UNUSED_ARG(ppp);
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
/* skip address & flags */
pbuf_header(p, -(s16_t)2);
@@ -219,26 +219,26 @@ static err_t pppoe_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) {
if(!ph) {
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.proterr);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
pbuf_free(p);
return ERR_MEM;
}
pbuf_header(ph, -(s16_t)PPPOE_HEADERLEN); /* hide PPPoE header */
pbuf_cat(ph, p);
#if LWIP_SNMP
#if MIB2_STATS
tot_len = ph->tot_len;
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
ret = pppoe_xmit(sc, ph);
if (ret != ERR_OK) {
LINK_STATS_INC(link.err);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
return ret;
}
snmp_add_ifoutoctets(ppp->netif, (u16_t)tot_len);
snmp_inc_ifoutucastpkts(ppp->netif);
MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, (u16_t)tot_len);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts);
LINK_STATS_INC(link.xmit);
return ERR_OK;
}
@@ -249,18 +249,18 @@ static err_t pppoe_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_short
struct pbuf *pb;
u8_t *pl;
err_t err;
#if LWIP_SNMP
#if MIB2_STATS
u16_t tot_len;
#else /* LWIP_SNMP */
#else /* MIB2_STATS */
LWIP_UNUSED_ARG(ppp);
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
/* @todo: try to use pbuf_header() here! */
pb = pbuf_alloc(PBUF_LINK, PPPOE_HEADERLEN + sizeof(protocol), PBUF_RAM);
if(!pb) {
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.proterr);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
return ERR_MEM;
}
@@ -270,18 +270,18 @@ static err_t pppoe_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_short
PUTSHORT(protocol, pl);
pbuf_chain(pb, p);
#if LWIP_SNMP
#if MIB2_STATS
tot_len = pb->tot_len;
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
if( (err = pppoe_xmit(sc, pb)) != ERR_OK) {
LINK_STATS_INC(link.err);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
return err;
}
snmp_add_ifoutoctets(ppp->netif, tot_len);
snmp_inc_ifoutucastpkts(ppp->netif);
MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, tot_len);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts);
LINK_STATS_INC(link.xmit);
return ERR_OK;
}

View File

@@ -57,7 +57,7 @@
#include "lwip/memp.h"
#include "lwip/netif.h"
#include "lwip/udp.h"
#include "lwip/snmp.h"
#include "lwip/snmp_mib2.h"
#include "netif/ppp/ppp_impl.h"
#include "netif/ppp/lcp.h"
@@ -175,36 +175,36 @@ static err_t pppol2tp_write(ppp_pcb *ppp, void *ctx, struct pbuf *p) {
pppol2tp_pcb *l2tp = (pppol2tp_pcb *)ctx;
struct pbuf *ph; /* UDP + L2TP header */
err_t ret;
#if LWIP_SNMP
#if MIB2_STATS
u16_t tot_len;
#else /* LWIP_SNMP */
#else /* MIB2_STATS */
LWIP_UNUSED_ARG(ppp);
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
ph = pbuf_alloc(PBUF_TRANSPORT, (u16_t)(PPPOL2TP_OUTPUT_DATA_HEADER_LEN), PBUF_RAM);
if(!ph) {
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.proterr);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
pbuf_free(p);
return ERR_MEM;
}
pbuf_header(ph, -(s16_t)PPPOL2TP_OUTPUT_DATA_HEADER_LEN); /* hide L2TP header */
pbuf_cat(ph, p);
#if LWIP_SNMP
#if MIB2_STATS
tot_len = ph->tot_len;
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
ret = pppol2tp_xmit(l2tp, ph);
if (ret != ERR_OK) {
LINK_STATS_INC(link.err);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
return ret;
}
snmp_add_ifoutoctets(ppp->netif, (u16_t)tot_len);
snmp_inc_ifoutucastpkts(ppp->netif);
MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, (u16_t)tot_len);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts);
LINK_STATS_INC(link.xmit);
return ERR_OK;
}
@@ -215,18 +215,18 @@ static err_t pppol2tp_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_sh
struct pbuf *pb;
u8_t *pl;
err_t err;
#if LWIP_SNMP
#if MIB2_STATS
u16_t tot_len;
#else /* LWIP_SNMP */
#else /* MIB2_STATS */
LWIP_UNUSED_ARG(ppp);
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
/* @todo: try to use pbuf_header() here! */
pb = pbuf_alloc(PBUF_TRANSPORT, PPPOL2TP_OUTPUT_DATA_HEADER_LEN + sizeof(protocol), PBUF_RAM);
if(!pb) {
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.proterr);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
return ERR_MEM;
}
@@ -236,18 +236,18 @@ static err_t pppol2tp_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, u_sh
PUTSHORT(protocol, pl);
pbuf_chain(pb, p);
#if LWIP_SNMP
#if MIB2_STATS
tot_len = pb->tot_len;
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
if( (err = pppol2tp_xmit(l2tp, pb)) != ERR_OK) {
LINK_STATS_INC(link.err);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
return err;
}
snmp_add_ifoutoctets(ppp->netif, tot_len);
snmp_inc_ifoutucastpkts(ppp->netif);
MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, tot_len);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts);
LINK_STATS_INC(link.xmit);
return ERR_OK;
}

View File

@@ -41,7 +41,7 @@
#include "lwip/sys.h"
#include "lwip/memp.h"
#include "lwip/netif.h"
#include "lwip/snmp.h"
#include "lwip/snmp_mib2.h"
#include "lwip/tcpip.h"
#include "lwip/api.h"
#include "lwip/sio.h"
@@ -211,7 +211,7 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p)
PPPDEBUG(LOG_WARNING, ("pppos_write[%d]: alloc fail\n", ppp->netif->num));
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
pbuf_free(p);
return ERR_MEM;
}
@@ -257,7 +257,7 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u16_t protocol)
PPPDEBUG(LOG_WARNING, ("pppos_netif_output[%d]: alloc fail\n", ppp->netif->num));
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
return ERR_MEM;
}
@@ -575,7 +575,7 @@ pppos_input(ppp_pcb *ppp, u8_t *s, int l)
PPPDEBUG(LOG_ERR, ("pppos_input[%d]: tcpip_callback() failed, dropping packet\n", ppp->netif->num));
pbuf_free(inp);
LINK_STATS_INC(link.drop);
snmp_inc_ifindiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifindiscards);
}
#else /* PPP_INPROC_IRQ_SAFE */
ppp_input(ppp, inp);
@@ -736,7 +736,7 @@ static void pppos_input_callback(void *arg) {
drop:
LINK_STATS_INC(link.drop);
snmp_inc_ifindiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifindiscards);
pbuf_free(pb);
}
#endif /* PPP_INPROC_IRQ_SAFE */
@@ -838,7 +838,7 @@ pppos_input_drop(pppos_pcb *pppos)
#endif /* VJ_SUPPORT */
LINK_STATS_INC(link.drop);
snmp_inc_ifindiscards(pppos->ppp->netif);
MIB2_STATS_NETIF_INC(pppos->ppp->netif, ifindiscards);
}
/*
@@ -884,9 +884,9 @@ pppos_output_append(pppos_pcb *pppos, err_t err, struct pbuf *nb, u8_t c, u8_t a
static err_t
pppos_output_last(pppos_pcb *pppos, err_t err, struct pbuf *nb, u16_t *fcs)
{
#if LWIP_SNMP
#if MIB2_STATS
ppp_pcb *ppp = pppos->ppp;
#endif /* LWIP_SNMP */
#endif /* MIB2_STATS */
/* Add FCS and trailing flag. */
err = pppos_output_append(pppos, err, nb, ~(*fcs) & 0xFF, 1, NULL);
@@ -907,8 +907,8 @@ pppos_output_last(pppos_pcb *pppos, err_t err, struct pbuf *nb, u16_t *fcs)
}
pppos->last_xmit = sys_jiffies();
snmp_add_ifoutoctets(ppp->netif, nb->tot_len);
snmp_inc_ifoutucastpkts(ppp->netif);
MIB2_STATS_NETIF_ADD(ppp->netif, ifoutoctets, nb->tot_len);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutucastpkts);
LINK_STATS_INC(link.xmit);
pbuf_free(nb);
return ERR_OK;
@@ -917,7 +917,7 @@ failed:
pppos->last_xmit = 0; /* prepend PPP_FLAG to next packet */
LINK_STATS_INC(link.err);
LINK_STATS_INC(link.drop);
snmp_inc_ifoutdiscards(ppp->netif);
MIB2_STATS_NETIF_INC(ppp->netif, ifoutdiscards);
pbuf_free(nb);
return err;
}

View File

@@ -63,7 +63,7 @@
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/snmp_mib2.h"
#include "lwip/sys.h"
#include "lwip/sio.h"
@@ -396,7 +396,7 @@ slipif_init(struct netif *netif)
netif->state = priv;
/* initialize the snmp variables and counters inside the struct netif */
NETIF_INIT_SNMP(netif, snmp_ifType_slip, SLIP_SIO_SPEED(priv->sd));
MIB2_INIT_NETIF(netif, snmp_ifType_slip, SLIP_SIO_SPEED(priv->sd));
#if SLIP_USE_RX_THREAD
/* Create a thread to poll the serial line. */