The Pedigree Project  0.1
snmp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
25 /*
26  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without modification,
30  * are permitted provided that the following conditions are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright notice,
33  * this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright notice,
35  * this list of conditions and the following disclaimer in the documentation
36  * and/or other materials provided with the distribution.
37  * 3. The name of the author may not be used to endorse or promote products
38  * derived from this software without specific prior written permission.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49  * OF SUCH DAMAGE.
50  *
51  * This file is part of the lwIP TCP/IP stack.
52  *
53  * Author: Dirk Ziegelmeier <dziegel@gmx.de>
54  *
55  */
56 #ifndef LWIP_HDR_SNMP_H
57 #define LWIP_HDR_SNMP_H
58 
59 #include "lwip/opt.h"
60 #include "lwip/ip_addr.h"
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 struct udp_pcb;
67 struct netif;
68 
74 /* MIB2 statistics functions */
75 #if MIB2_STATS /* don't build if not configured for use in lwipopts.h */
76 
80 enum snmp_ifType {
81  snmp_ifType_other=1, /* none of the following */
82  snmp_ifType_regular1822,
83  snmp_ifType_hdh1822,
84  snmp_ifType_ddn_x25,
85  snmp_ifType_rfc877_x25,
86  snmp_ifType_ethernet_csmacd,
87  snmp_ifType_iso88023_csmacd,
88  snmp_ifType_iso88024_tokenBus,
89  snmp_ifType_iso88025_tokenRing,
90  snmp_ifType_iso88026_man,
91  snmp_ifType_starLan,
92  snmp_ifType_proteon_10Mbit,
93  snmp_ifType_proteon_80Mbit,
94  snmp_ifType_hyperchannel,
95  snmp_ifType_fddi,
96  snmp_ifType_lapb,
97  snmp_ifType_sdlc,
98  snmp_ifType_ds1, /* T-1 */
99  snmp_ifType_e1, /* european equiv. of T-1 */
100  snmp_ifType_basicISDN,
101  snmp_ifType_primaryISDN, /* proprietary serial */
102  snmp_ifType_propPointToPointSerial,
103  snmp_ifType_ppp,
104  snmp_ifType_softwareLoopback,
105  snmp_ifType_eon, /* CLNP over IP [11] */
106  snmp_ifType_ethernet_3Mbit,
107  snmp_ifType_nsip, /* XNS over IP */
108  snmp_ifType_slip, /* generic SLIP */
109  snmp_ifType_ultra, /* ULTRA technologies */
110  snmp_ifType_ds3, /* T-3 */
111  snmp_ifType_sip, /* SMDS */
112  snmp_ifType_frame_relay
113 };
114 
116 #ifndef MIB2_COPY_SYSUPTIME_TO
117 #define MIB2_COPY_SYSUPTIME_TO(ptrToVal) (*(ptrToVal) = (sys_now() / 10))
118 #endif
119 
124 #define MIB2_STATS_NETIF_INC(n, x) do { ++(n)->mib2_counters.x; } while(0)
125 
129 #define MIB2_STATS_NETIF_ADD(n, x, val) do { (n)->mib2_counters.x += (val); } while(0)
130 
138 #define MIB2_INIT_NETIF(netif, type, speed) do { \
139  (netif)->link_type = (type); \
140  (netif)->link_speed = (speed);\
141  (netif)->ts = 0; \
142  (netif)->mib2_counters.ifinoctets = 0; \
143  (netif)->mib2_counters.ifinucastpkts = 0; \
144  (netif)->mib2_counters.ifinnucastpkts = 0; \
145  (netif)->mib2_counters.ifindiscards = 0; \
146  (netif)->mib2_counters.ifinerrors = 0; \
147  (netif)->mib2_counters.ifinunknownprotos = 0; \
148  (netif)->mib2_counters.ifoutoctets = 0; \
149  (netif)->mib2_counters.ifoutucastpkts = 0; \
150  (netif)->mib2_counters.ifoutnucastpkts = 0; \
151  (netif)->mib2_counters.ifoutdiscards = 0; \
152  (netif)->mib2_counters.ifouterrors = 0; } while(0)
153 #else /* MIB2_STATS */
154 #ifndef MIB2_COPY_SYSUPTIME_TO
155 #define MIB2_COPY_SYSUPTIME_TO(ptrToVal)
156 #endif
157 #define MIB2_INIT_NETIF(netif, type, speed)
158 #define MIB2_STATS_NETIF_INC(n, x)
159 #define MIB2_STATS_NETIF_ADD(n, x, val)
160 #endif /* MIB2_STATS */
161 
162 /* LWIP MIB2 callbacks */
163 #if LWIP_MIB2_CALLBACKS /* don't build if not configured for use in lwipopts.h */
164 /* network interface */
165 void mib2_netif_added(struct netif *ni);
166 void mib2_netif_removed(struct netif *ni);
167 
168 #if LWIP_IPV4 && LWIP_ARP
169 /* ARP (for atTable and ipNetToMediaTable) */
170 void mib2_add_arp_entry(struct netif *ni, ip4_addr_t *ip);
171 void mib2_remove_arp_entry(struct netif *ni, ip4_addr_t *ip);
172 #else /* LWIP_IPV4 && LWIP_ARP */
173 #define mib2_add_arp_entry(ni,ip)
174 #define mib2_remove_arp_entry(ni,ip)
175 #endif /* LWIP_IPV4 && LWIP_ARP */
176 
177 /* IP */
178 #if LWIP_IPV4
179 void mib2_add_ip4(struct netif *ni);
180 void mib2_remove_ip4(struct netif *ni);
181 void mib2_add_route_ip4(u8_t dflt, struct netif *ni);
182 void mib2_remove_route_ip4(u8_t dflt, struct netif *ni);
183 #endif /* LWIP_IPV4 */
184 
185 /* UDP */
186 #if LWIP_UDP
187 void mib2_udp_bind(struct udp_pcb *pcb);
188 void mib2_udp_unbind(struct udp_pcb *pcb);
189 #endif /* LWIP_UDP */
190 
191 #else /* LWIP_MIB2_CALLBACKS */
192 /* LWIP_MIB2_CALLBACKS support not available */
193 /* define everything to be empty */
194 
195 /* network interface */
196 #define mib2_netif_added(ni)
197 #define mib2_netif_removed(ni)
198 
199 /* ARP */
200 #define mib2_add_arp_entry(ni,ip)
201 #define mib2_remove_arp_entry(ni,ip)
202 
203 /* IP */
204 #define mib2_add_ip4(ni)
205 #define mib2_remove_ip4(ni)
206 #define mib2_add_route_ip4(dflt, ni)
207 #define mib2_remove_route_ip4(dflt, ni)
208 
209 /* UDP */
210 #define mib2_udp_bind(pcb)
211 #define mib2_udp_unbind(pcb)
212 #endif /* LWIP_MIB2_CALLBACKS */
213 
214 /* for source-code compatibility reasons only, can be removed (not used internally) */
215 #define NETIF_INIT_SNMP MIB2_INIT_NETIF
216 #define snmp_add_ifinoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifinoctets, value)
217 #define snmp_inc_ifinucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinucastpkts)
218 #define snmp_inc_ifinnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinnucastpkts)
219 #define snmp_inc_ifindiscards(ni) MIB2_STATS_NETIF_INC(ni, ifindiscards)
220 #define snmp_inc_ifinerrors(ni) MIB2_STATS_NETIF_INC(ni, ifinerrors)
221 #define snmp_inc_ifinunknownprotos(ni) MIB2_STATS_NETIF_INC(ni, ifinunknownprotos)
222 #define snmp_add_ifoutoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifoutoctets, value)
223 #define snmp_inc_ifoutucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutucastpkts)
224 #define snmp_inc_ifoutnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutnucastpkts)
225 #define snmp_inc_ifoutdiscards(ni) MIB2_STATS_NETIF_INC(ni, ifoutdiscards)
226 #define snmp_inc_ifouterrors(ni) MIB2_STATS_NETIF_INC(ni, ifouterrors)
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif /* LWIP_HDR_SNMP_H */
Definition: netif.h:244