Mistake on this page?
Report an issue in GitHub or email us
snmp.h
Go to the documentation of this file.
1 /**
2  * @file
3  * SNMP support API for implementing netifs and statitics for MIB2
4  */
5 
6 /*
7  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  *
32  * This file is part of the lwIP TCP/IP stack.
33  *
34  * Author: Dirk Ziegelmeier <dziegel@gmx.de>
35  *
36  */
37 #ifndef LWIP_HDR_SNMP_H
38 #define LWIP_HDR_SNMP_H
39 
40 #include "lwip/opt.h"
41 #include "lwip/ip_addr.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 struct udp_pcb;
48 struct netif;
49 
50 /**
51  * @defgroup netif_mib2 MIB2 statistics
52  * @ingroup netif
53  */
54 
55 /* MIB2 statistics functions */
56 #if MIB2_STATS /* don't build if not configured for use in lwipopts.h */
57 /**
58  * @ingroup netif_mib2
59  * @see RFC1213, "MIB-II, 6. Definitions"
60  */
61 enum snmp_ifType {
62  snmp_ifType_other=1, /* none of the following */
63  snmp_ifType_regular1822,
64  snmp_ifType_hdh1822,
65  snmp_ifType_ddn_x25,
66  snmp_ifType_rfc877_x25,
67  snmp_ifType_ethernet_csmacd,
68  snmp_ifType_iso88023_csmacd,
69  snmp_ifType_iso88024_tokenBus,
70  snmp_ifType_iso88025_tokenRing,
71  snmp_ifType_iso88026_man,
72  snmp_ifType_starLan,
73  snmp_ifType_proteon_10Mbit,
74  snmp_ifType_proteon_80Mbit,
75  snmp_ifType_hyperchannel,
76  snmp_ifType_fddi,
77  snmp_ifType_lapb,
78  snmp_ifType_sdlc,
79  snmp_ifType_ds1, /* T-1 */
80  snmp_ifType_e1, /* european equiv. of T-1 */
81  snmp_ifType_basicISDN,
82  snmp_ifType_primaryISDN, /* proprietary serial */
83  snmp_ifType_propPointToPointSerial,
84  snmp_ifType_ppp,
85  snmp_ifType_softwareLoopback,
86  snmp_ifType_eon, /* CLNP over IP [11] */
87  snmp_ifType_ethernet_3Mbit,
88  snmp_ifType_nsip, /* XNS over IP */
89  snmp_ifType_slip, /* generic SLIP */
90  snmp_ifType_ultra, /* ULTRA technologies */
91  snmp_ifType_ds3, /* T-3 */
92  snmp_ifType_sip, /* SMDS */
93  snmp_ifType_frame_relay
94 };
95 
96 /** This macro has a precision of ~49 days because sys_now returns u32_t. \#define your own if you want ~490 days. */
97 #ifndef MIB2_COPY_SYSUPTIME_TO
98 #define MIB2_COPY_SYSUPTIME_TO(ptrToVal) (*(ptrToVal) = (sys_now() / 10))
99 #endif
100 
101 /**
102  * @ingroup netif_mib2
103  * Increment stats member for SNMP MIB2 stats (struct stats_mib2_netif_ctrs)
104  */
105 #define MIB2_STATS_NETIF_INC(n, x) do { ++(n)->mib2_counters.x; } while(0)
106 /**
107  * @ingroup netif_mib2
108  * Add value to stats member for SNMP MIB2 stats (struct stats_mib2_netif_ctrs)
109  */
110 #define MIB2_STATS_NETIF_ADD(n, x, val) do { (n)->mib2_counters.x += (val); } while(0)
111 
112 /**
113  * @ingroup netif_mib2
114  * Init MIB2 statistic counters in netif
115  * @param netif Netif to init
116  * @param type one of enum @ref snmp_ifType
117  * @param speed your link speed here (units: bits per second)
118  */
119 #define MIB2_INIT_NETIF(netif, type, speed) do { \
120  (netif)->link_type = (type); \
121  (netif)->link_speed = (speed);\
122  (netif)->ts = 0; \
123  (netif)->mib2_counters.ifinoctets = 0; \
124  (netif)->mib2_counters.ifinucastpkts = 0; \
125  (netif)->mib2_counters.ifinnucastpkts = 0; \
126  (netif)->mib2_counters.ifindiscards = 0; \
127  (netif)->mib2_counters.ifinerrors = 0; \
128  (netif)->mib2_counters.ifinunknownprotos = 0; \
129  (netif)->mib2_counters.ifoutoctets = 0; \
130  (netif)->mib2_counters.ifoutucastpkts = 0; \
131  (netif)->mib2_counters.ifoutnucastpkts = 0; \
132  (netif)->mib2_counters.ifoutdiscards = 0; \
133  (netif)->mib2_counters.ifouterrors = 0; } while(0)
134 #else /* MIB2_STATS */
135 #ifndef MIB2_COPY_SYSUPTIME_TO
136 #define MIB2_COPY_SYSUPTIME_TO(ptrToVal)
137 #endif
138 #define MIB2_INIT_NETIF(netif, type, speed)
139 #define MIB2_STATS_NETIF_INC(n, x)
140 #define MIB2_STATS_NETIF_ADD(n, x, val)
141 #endif /* MIB2_STATS */
142 
143 /* LWIP MIB2 callbacks */
144 #if LWIP_MIB2_CALLBACKS /* don't build if not configured for use in lwipopts.h */
145 /* network interface */
146 void mib2_netif_added(struct netif *ni);
147 void mib2_netif_removed(struct netif *ni);
148 
149 #if LWIP_IPV4 && LWIP_ARP
150 /* ARP (for atTable and ipNetToMediaTable) */
151 void mib2_add_arp_entry(struct netif *ni, ip4_addr_t *ip);
152 void mib2_remove_arp_entry(struct netif *ni, ip4_addr_t *ip);
153 #else /* LWIP_IPV4 && LWIP_ARP */
154 #define mib2_add_arp_entry(ni,ip)
155 #define mib2_remove_arp_entry(ni,ip)
156 #endif /* LWIP_IPV4 && LWIP_ARP */
157 
158 /* IP */
159 #if LWIP_IPV4
160 void mib2_add_ip4(struct netif *ni);
161 void mib2_remove_ip4(struct netif *ni);
162 void mib2_add_route_ip4(u8_t dflt, struct netif *ni);
163 void mib2_remove_route_ip4(u8_t dflt, struct netif *ni);
164 #endif /* LWIP_IPV4 */
165 
166 /* UDP */
167 #if LWIP_UDP
168 void mib2_udp_bind(struct udp_pcb *pcb);
169 void mib2_udp_unbind(struct udp_pcb *pcb);
170 #endif /* LWIP_UDP */
171 
172 #else /* LWIP_MIB2_CALLBACKS */
173 /* LWIP_MIB2_CALLBACKS support not available */
174 /* define everything to be empty */
175 
176 /* network interface */
177 #define mib2_netif_added(ni)
178 #define mib2_netif_removed(ni)
179 
180 /* ARP */
181 #define mib2_add_arp_entry(ni,ip)
182 #define mib2_remove_arp_entry(ni,ip)
183 
184 /* IP */
185 #define mib2_add_ip4(ni)
186 #define mib2_remove_ip4(ni)
187 #define mib2_add_route_ip4(dflt, ni)
188 #define mib2_remove_route_ip4(dflt, ni)
189 
190 /* UDP */
191 #define mib2_udp_bind(pcb)
192 #define mib2_udp_unbind(pcb)
193 #endif /* LWIP_MIB2_CALLBACKS */
194 
195 /* for source-code compatibility reasons only, can be removed (not used internally) */
196 #define NETIF_INIT_SNMP MIB2_INIT_NETIF
197 #define snmp_add_ifinoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifinoctets, value)
198 #define snmp_inc_ifinucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinucastpkts)
199 #define snmp_inc_ifinnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinnucastpkts)
200 #define snmp_inc_ifindiscards(ni) MIB2_STATS_NETIF_INC(ni, ifindiscards)
201 #define snmp_inc_ifinerrors(ni) MIB2_STATS_NETIF_INC(ni, ifinerrors)
202 #define snmp_inc_ifinunknownprotos(ni) MIB2_STATS_NETIF_INC(ni, ifinunknownprotos)
203 #define snmp_add_ifoutoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifoutoctets, value)
204 #define snmp_inc_ifoutucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutucastpkts)
205 #define snmp_inc_ifoutnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutnucastpkts)
206 #define snmp_inc_ifoutdiscards(ni) MIB2_STATS_NETIF_INC(ni, ifoutdiscards)
207 #define snmp_inc_ifouterrors(ni) MIB2_STATS_NETIF_INC(ni, ifouterrors)
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 
213 #endif /* LWIP_HDR_SNMP_H */
lwIP Options Configuration
Generic data structure used for all lwIP network interfaces.
IP address structure for passing IP addresses by value.
Definition: nsapi_types.h:235
IP address API (common IPv4 and IPv6)
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.