1 /*
2  * interface data access header
3  *
4  * $Id$
5  */
6 #ifndef NETSNMP_ACCESS_INTERFACE_H
7 #define NETSNMP_ACCESS_INTERFACE_H
8 
9 #ifdef __cplusplus
10 extern          "C" {
11 #endif
12 
13 #if HAVE_PCRE_H
14 #include <pcre.h>
15 #elif HAVE_REGEX_H
16 #include <regex.h>
17 #endif
18 
19 /*
20  * define flags to indicate the availability of certain data
21  */
22 #define NETSNMP_INTERFACE_FLAGS_ACTIVE			0x00000001
23 #define NETSNMP_INTERFACE_FLAGS_HAS_BYTES		0x00000002
24 #define NETSNMP_INTERFACE_FLAGS_HAS_DROPS		0x00000004
25 #define NETSNMP_INTERFACE_FLAGS_HAS_MCAST_PKTS		0x00000008
26 #define NETSNMP_INTERFACE_FLAGS_HAS_HIGH_BYTES		0x00000010
27 #define NETSNMP_INTERFACE_FLAGS_HAS_HIGH_PACKETS	0x00000020
28 #define NETSNMP_INTERFACE_FLAGS_HAS_HIGH_SPEED		0x00000040
29 #define NETSNMP_INTERFACE_FLAGS_DYNAMIC_SPEED		0x00000080
30 #define NETSNMP_INTERFACE_FLAGS_HAS_LASTCHANGE		0x00000100
31 #define NETSNMP_INTERFACE_FLAGS_HAS_DISCONTINUITY	0x00000200
32 #define NETSNMP_INTERFACE_FLAGS_HAS_IF_FLAGS      	0x00000400
33 #define NETSNMP_INTERFACE_FLAGS_CAN_DOWN_PROTOCOL       0x00000800
34 #define NETSNMP_INTERFACE_FLAGS_HAS_IPV4                0x00001000
35 #define NETSNMP_INTERFACE_FLAGS_HAS_IPV6                0x00002000
36 #define NETSNMP_INTERFACE_FLAGS_HAS_V4_RETRANSMIT       0x00004000
37 #define NETSNMP_INTERFACE_FLAGS_HAS_V4_REASMMAX         0x00008000
38 #define NETSNMP_INTERFACE_FLAGS_HAS_V6_RETRANSMIT       0x00010000
39 #define NETSNMP_INTERFACE_FLAGS_HAS_V6_REASMMAX         0x00020000
40 #define NETSNMP_INTERFACE_FLAGS_HAS_V6_REACHABLE        0x00040000
41 #define NETSNMP_INTERFACE_FLAGS_HAS_V6_IFID             0x00080000
42 #define NETSNMP_INTERFACE_FLAGS_HAS_V6_FORWARDING       0x00100000
43 /* Some platforms, e.g.Linux, do not provide standalone counter
44  * for incoming unicast packets - they provide counter of all packets
45  * + separate counter for the multicast ones.
46  * That means the counter of all packets must watched and checked
47  * for overflows to reconstruct its 64-bit value (i.e. as usual
48  * for counter of unicast packets), and after its expansion to 64-bits,
49  * nr.of multicast packets must be substracted to get nr. of unicast
50  * packets.
51  * This flag marks stats of such platforms. Nr. of all incoming packets,
52  * provided by the platform, must be stored in
53  * netsnmp_interface_stats.iall and netsnmp_interface_stats.iucast will
54  * be automatically calculated later.
55  */
56 #define NETSNMP_INTERFACE_FLAGS_CALCULATE_UCAST         0x00200000
57 
58 /*************************************************************
59  * constants for enums for the MIB node
60  * ifAdminStatus (INTEGER / ASN_INTEGER)
61  *
62  * since a Textual Convention may be referenced more than once in a
63  * MIB, protect againt redifinitions of the enum values.
64  */
65 #ifndef ifAdminStatus_ENUMS
66 #define ifAdminStatus_ENUMS
67 
68 #define IFADMINSTATUS_UP  1
69 #define IFADMINSTATUS_DOWN  2
70 #define IFADMINSTATUS_TESTING  3
71 
72 #endif                          /* ifAdminStatus_ENUMS */
73 
74 /*************************************************************
75  * constants for enums for the MIB node
76  * ifOperStatus (INTEGER / ASN_INTEGER)
77  *
78  * since a Textual Convention may be referenced more than once in a
79  * MIB, protect againt redifinitions of the enum values.
80  */
81 #ifndef ifOperStatus_ENUMS
82 #define ifOperStatus_ENUMS
83 
84 #define IFOPERSTATUS_UP  1
85 #define IFOPERSTATUS_DOWN  2
86 #define IFOPERSTATUS_TESTING  3
87 #define IFOPERSTATUS_UNKNOWN  4
88 #define IFOPERSTATUS_DORMANT  5
89 #define IFOPERSTATUS_NOTPRESENT 6
90 #define IFOPERSTATUS_LOWERLAYERDOWN 7
91 
92 #endif                          /* ifOperStatus_ENUMS */
93 
94 /* nominal speed of network interface - used when the real speed is unknown */
95 #define NOMINAL_LINK_SPEED 10000000
96 
97 /**---------------------------------------------------------------------*/
98 /*
99  * structure definitions
100  *
101  * NOTE: if you add fields, update code dealing with
102  *       stats in interface_common.c, particularly
103  *       netsnmp_access_interface_entry_update_stats()
104  *
105  */
106 typedef struct netsnmp_interface_stats_s {
107     /*
108      *  "Dynamic" fields
109      *  Cached versions of byte/packet counters, etc
110      *  (saved as a 'struct counter64' even if the
111      *   high order half isn't actually used)
112      *
113      */
114    /** input */
115     struct counter64 ibytes;
116     /*
117      * nr. of all packets (to calculate iucast, when underlying platform does
118      * not provide it)
119      */
120     struct counter64 iall;
121     struct counter64 iucast;
122     struct counter64 imcast;
123     struct counter64 ibcast;
124     unsigned int     ierrors;
125     unsigned int     idiscards;
126     unsigned int     iunknown_protos;
127     unsigned int     inucast;
128    /** output */
129     struct counter64 obytes;
130     struct counter64 oucast;
131     struct counter64 omcast;
132     struct counter64 obcast;
133     unsigned int     oerrors;
134     unsigned int     odiscards;
135     unsigned int     oqlen;
136     unsigned int     collisions;
137     unsigned int     onucast;
138 } netsnmp_interface_stats;
139 
140 /*
141  *
142  * NOTE: if you add fields, update code dealing with
143  *       them in interface_common.c, particularly
144  *       netsnmp_access_interface_entry_copy().
145  */
146 typedef struct netsnmp_interface_entry_s {
147     netsnmp_index oid_index;
148 
149     u_int   ns_flags; /* net-snmp flags */
150     oid     index;
151 
152     /*
153      *  "Static" information
154      *  Typically constant for a given interface
155      */
156     char   *name;
157     char   *descr;
158     int     type;
159     u_int   speed;
160     u_int   speed_high;
161     char   *paddr;
162     u_int   paddr_len;
163     u_int   mtu;
164 
165     u_int   retransmit_v4; /* milliseconds */
166     u_int   retransmit_v6; /* milliseconds */
167 
168     u_int   reachable_time; /* ipv6 / milliseconds */
169 
170     u_long  lastchange;
171     time_t  discontinuity;
172 
173     uint16_t     reasm_max_v4; /* 0..65535 */
174     uint16_t     reasm_max_v6; /* 1500..65535 */
175     char  admin_status;
176     char  oper_status;
177 
178     /** booleans (not TruthValues!) */
179     char  promiscuous;
180     char  connector_present;
181     char  forwarding_v6;
182 
183     char    v6_if_id_len;
184     u_char  v6_if_id[8];
185 
186     /*-----------------------------------------------
187      * platform/arch/access specific data
188      */
189     u_int os_flags; /* iff NETSNMP_INTERFACE_FLAGS_HAS_IF_FLAGS */
190 
191     /*
192      * statistics
193      */
194     netsnmp_interface_stats stats;
195 
196     /** old_stats is used in netsnmp_access_interface_entry_update_stats */
197     netsnmp_interface_stats *old_stats;
198 
199 } netsnmp_interface_entry;
200 
201 /*
202  * conf file overrides
203  */
204 typedef struct _conf_if_list {
205     const char     *name;
206     int             type;
207     uint64_t speed;
208     struct _conf_if_list *next;
209 } netsnmp_conf_if_list;
210 
211     typedef netsnmp_conf_if_list conf_if_list; /* backwards compat */
212 
213 typedef struct _include_if_list {
214 #if HAVE_PCRE_H
215     pcre                    *regex_ptr;
216 #elif HAVE_REGEX_H
217     regex_t                 *regex_ptr;
218 #endif
219     char                    *name;
220     struct _include_if_list *next;
221 } netsnmp_include_if_list;
222 
223 /**---------------------------------------------------------------------*/
224 /*
225  * ACCESS function prototypes
226  */
227 void init_interface(void);
228 void netsnmp_access_interface_init(void);
229 
230 /*
231  * ifcontainer init
232  */
233 netsnmp_container * netsnmp_access_interface_container_init(u_int init_flags);
234 #define NETSNMP_ACCESS_INTERFACE_INIT_NOFLAGS               0x0000
235 #define NETSNMP_ACCESS_INTERFACE_INIT_ADDL_IDX_BY_NAME      0x0001
236 
237 /*
238  * ifcontainer load and free
239  */
240 netsnmp_container*
241 netsnmp_access_interface_container_load(netsnmp_container* container,
242                                         u_int load_flags);
243 #define NETSNMP_ACCESS_INTERFACE_LOAD_NOFLAGS               0x0000
244 #define NETSNMP_ACCESS_INTERFACE_LOAD_NO_STATS              0x0001
245 #define NETSNMP_ACCESS_INTERFACE_LOAD_IP4_ONLY              0x0002
246 #define NETSNMP_ACCESS_INTERFACE_LOAD_IP6_ONLY              0x0004
247 
248 void netsnmp_access_interface_container_free(netsnmp_container *container,
249                                              u_int free_flags);
250 #define NETSNMP_ACCESS_INTERFACE_FREE_NOFLAGS               0x0000
251 #define NETSNMP_ACCESS_INTERFACE_FREE_DONT_CLEAR            0x0001
252 
253 
254 /*
255  * create/free an ifentry
256  */
257 netsnmp_interface_entry *
258 netsnmp_access_interface_entry_create(const char *name, oid if_index);
259 
260 void netsnmp_access_interface_entry_free(netsnmp_interface_entry * entry);
261 
262 int
263 netsnmp_access_interface_entry_set_admin_status(netsnmp_interface_entry * entry,
264 	                                                int ifAdminStatus);
265 
266 /*
267  * find entry in container
268  */
269 netsnmp_interface_entry *
270 netsnmp_access_interface_entry_get_by_name(netsnmp_container *container,
271                                            const char *name);
272 netsnmp_interface_entry *
273 netsnmp_access_interface_entry_get_by_index(netsnmp_container *container,
274                                             oid index);
275 
276 /*
277  * find ifIndex for given interface. 0 == not found.
278  */
279 oid netsnmp_access_interface_index_find(const char *name);
280 
281 /*
282  * find name for given index
283  */
284 const char *netsnmp_access_interface_name_find(oid index);
285 
286 /*
287  * copy interface entry data
288  */
289 int netsnmp_access_interface_entry_copy(netsnmp_interface_entry * lhs,
290                                         netsnmp_interface_entry * rhs);
291 
292 /*
293  * utility routines
294  */
295 void netsnmp_access_interface_entry_guess_speed(netsnmp_interface_entry *);
296 void netsnmp_access_interface_entry_overrides(netsnmp_interface_entry *);
297 
298 
299 netsnmp_conf_if_list *
300 netsnmp_access_interface_entry_overrides_get(const char * name);
301 
302 int netsnmp_access_interface_include(const char * name);
303 int netsnmp_access_interface_max_reached(const char * name);
304 
305 /**---------------------------------------------------------------------*/
306 
307 #if defined( USING_IF_MIB_IFTABLE_IFTABLE_DATA_ACCESS_MODULE ) && \
308     ! defined( NETSNMP_NO_BACKWARDS_COMPATABILITY )
309 void
310 Interface_Scan_Init(void);
311 int
312 Interface_Scan_Next(short *index, char *name, netsnmp_interface_entry **entry,
313                     void *dc);
314 int
315 Interface_Scan_NextInt(int *index, char *name, netsnmp_interface_entry **entry,
316                     void *dc);
317 #endif
318 
319 /**---------------------------------------------------------------------*/
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 
325 #endif /* NETSNMP_ACCESS_INTERFACE_H */
326