3 * MIB2 callback functions called from throughout the stack to integrate a MIB2
4 * into lwIP (together with MIB2_STATS).
8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
14 * 1. Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 * This file is part of the lwIP TCP/IP stack.
35 * Author: Dirk Ziegelmeier <dziegel@gmx.de>
38 #ifndef LWIP_HDR_SNMP_MIB2_H
39 #define LWIP_HDR_SNMP_MIB2_H
42 #include "lwip/ip_addr.h"
51 /* MIB2 statistics functions */
52 #if MIB2_STATS /* don't build if not configured for use in lwipopts.h */
54 * @see RFC1213, "MIB-II, 6. Definitions"
57 snmp_ifType_other=1, /* none of the following */
58 snmp_ifType_regular1822,
61 snmp_ifType_rfc877_x25,
62 snmp_ifType_ethernet_csmacd,
63 snmp_ifType_iso88023_csmacd,
64 snmp_ifType_iso88024_tokenBus,
65 snmp_ifType_iso88025_tokenRing,
66 snmp_ifType_iso88026_man,
68 snmp_ifType_proteon_10Mbit,
69 snmp_ifType_proteon_80Mbit,
70 snmp_ifType_hyperchannel,
74 snmp_ifType_ds1, /* T-1 */
75 snmp_ifType_e1, /* european equiv. of T-1 */
76 snmp_ifType_basicISDN,
77 snmp_ifType_primaryISDN, /* proprietary serial */
78 snmp_ifType_propPointToPointSerial,
80 snmp_ifType_softwareLoopback,
81 snmp_ifType_eon, /* CLNP over IP [11] */
82 snmp_ifType_ethernet_3Mbit,
83 snmp_ifType_nsip, /* XNS over IP */
84 snmp_ifType_slip, /* generic SLIP */
85 snmp_ifType_ultra, /* ULTRA technologies */
86 snmp_ifType_ds3, /* T-3 */
87 snmp_ifType_sip, /* SMDS */
88 snmp_ifType_frame_relay
91 /* This macro has a precision of ~49 days because sys_now returns u32_t. #define your own if you want ~490 days. */
92 #ifndef MIB2_COPY_SYSUPTIME_TO
93 #define MIB2_COPY_SYSUPTIME_TO(ptrToVal) (*(ptrToVal) = (sys_now() / 10))
96 #define MIB2_STATS_NETIF_INC(n, x) do { ++(n)->mib2_counters.x; } while(0)
97 #define MIB2_STATS_NETIF_ADD(n, x, val) do { (n)->mib2_counters.x += (val); } while(0)
99 #define MIB2_INIT_NETIF(netif, type, speed) do { \
100 /* use "snmp_ifType" enum from snmp_mib2.h for "type", snmp_ifType_ethernet_csmacd by example */ \
101 (netif)->link_type = (type); \
102 /* your link speed here (units: bits per second) */ \
103 (netif)->link_speed = (speed);\
105 (netif)->mib2_counters.ifinoctets = 0; \
106 (netif)->mib2_counters.ifinucastpkts = 0; \
107 (netif)->mib2_counters.ifinnucastpkts = 0; \
108 (netif)->mib2_counters.ifindiscards = 0; \
109 (netif)->mib2_counters.ifinerrors = 0; \
110 (netif)->mib2_counters.ifinunknownprotos = 0; \
111 (netif)->mib2_counters.ifoutoctets = 0; \
112 (netif)->mib2_counters.ifoutucastpkts = 0; \
113 (netif)->mib2_counters.ifoutnucastpkts = 0; \
114 (netif)->mib2_counters.ifoutdiscards = 0; \
115 (netif)->mib2_counters.ifouterrors = 0; } while(0)
116 #else /* MIB2_STATS */
117 #ifndef MIB2_COPY_SYSUPTIME_TO
118 #define MIB2_COPY_SYSUPTIME_TO(ptrToVal)
120 #define MIB2_INIT_NETIF(netif, type, speed)
121 #define MIB2_STATS_NETIF_INC(n, x)
122 #define MIB2_STATS_NETIF_ADD(n, x, val)
123 #endif /* MIB2_STATS */
125 /* LWIP MIB2 callbacks */
126 #if LWIP_MIB2_CALLBACKS /* don't build if not configured for use in lwipopts.h */
127 /* network interface */
128 void mib2_netif_added(struct netif *ni);
129 void mib2_netif_removed(struct netif *ni);
131 #if LWIP_IPV4 && LWIP_ARP
132 /* ARP (for atTable and ipNetToMediaTable) */
133 void mib2_add_arp_entry(struct netif *ni, ip4_addr_t *ip);
134 void mib2_remove_arp_entry(struct netif *ni, ip4_addr_t *ip);
135 #else /* LWIP_IPV4 && LWIP_ARP */
136 #define mib2_add_arp_entry(ni,ip)
137 #define mib2_remove_arp_entry(ni,ip)
138 #endif /* LWIP_IPV4 && LWIP_ARP */
141 void mib2_add_ip4(struct netif *ni);
142 void mib2_remove_ip4(struct netif *ni);
143 void mib2_add_route_ip4(u8_t dflt, struct netif *ni);
144 void mib2_remove_route_ip4(u8_t dflt, struct netif *ni);
147 void mib2_udp_bind(struct udp_pcb *pcb);
148 void mib2_udp_unbind(struct udp_pcb *pcb);
150 #else /* LWIP_MIB2_CALLBACKS */
151 /* LWIP_MIB2_CALLBACKS support not available */
152 /* define everything to be empty */
154 /* network interface */
155 #define mib2_netif_added(ni)
156 #define mib2_netif_removed(ni)
159 #define mib2_add_arp_entry(ni,ip)
160 #define mib2_remove_arp_entry(ni,ip)
163 #define mib2_add_ip4(ni)
164 #define mib2_remove_ip4(ni)
165 #define mib2_add_route_ip4(dflt, ni)
166 #define mib2_remove_route_ip4(dflt, ni)
169 #define mib2_udp_bind(pcb)
170 #define mib2_udp_unbind(pcb)
171 #endif /* LWIP_MIB2_CALLBACKS */
173 /* for source-code compatibility reasons only, can be removed (not used internally) */
174 #define NETIF_INIT_SNMP MIB2_INIT_NETIF
175 #define snmp_add_ifinoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifinoctets, value)
176 #define snmp_inc_ifinucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinucastpkts)
177 #define snmp_inc_ifinnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinnucastpkts)
178 #define snmp_inc_ifindiscards(ni) MIB2_STATS_NETIF_INC(ni, ifindiscards)
179 #define snmp_inc_ifinerrors(ni) MIB2_STATS_NETIF_INC(ni, ifinerrors)
180 #define snmp_inc_ifinunknownprotos(ni) MIB2_STATS_NETIF_INC(ni, ifinunknownprotos)
181 #define snmp_add_ifoutoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifoutoctets, value)
182 #define snmp_inc_ifoutucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutucastpkts)
183 #define snmp_inc_ifoutnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutnucastpkts)
184 #define snmp_inc_ifoutdiscards(ni) MIB2_STATS_NETIF_INC(ni, ifoutdiscards)
185 #define snmp_inc_ifouterrors(ni) MIB2_STATS_NETIF_INC(ni, ifouterrors)
191 #endif /* LWIP_HDR_SNMP_MIB2_H */