1 /* Portions of this file are subject to the following copyright(s).  See
2  * the Net-SNMP's COPYING file for more details and other copyrights
3  * that may apply:
4  */
5 /*
6  * Portions of this file are copyrighted by:
7  * Copyright � 2003 Sun Microsystems, Inc. All rights reserved.
8  * Use is subject to license terms specified in the COPYING file
9  * distributed with the Net-SNMP package.
10  *
11  * Portions of this file are copyrighted by:
12  * Copyright (c) 2016 VMware, Inc. All rights reserved.
13  * Use is subject to license terms specified in the COPYING file
14  * distributed with the Net-SNMP package.
15  */
16 #ifndef SNMP_API_H
17 #define SNMP_API_H
18 
19 /*
20  * @file snmp_api.h - API for access to snmp.
21  *
22  * @addtogroup library
23  *
24  * Caution: when using this library in a multi-threaded application,
25  * the values of global variables "snmp_errno" and "snmp_detail"
26  * cannot be reliably determined.  Suggest using snmp_error()
27  * to obtain the library error codes.
28  *
29  * @{
30  */
31 
32 #include <net-snmp/types.h>
33 #include <net-snmp/varbind_api.h>
34 #include <net-snmp/output_api.h>
35 #include <net-snmp/pdu_api.h>
36 #include <net-snmp/session_api.h>
37 
38 #include <net-snmp/net-snmp-features.h>
39 
40 #ifndef DONT_SHARE_ERROR_WITH_OTHER_THREADS
41 #define SET_SNMP_ERROR(x) snmp_errno=(x)
42 #else
43 #define SET_SNMP_ERROR(x)
44 #endif
45 
46 
47 #ifdef __cplusplus
48 extern          "C" {
49 #endif
50 
51 /***********************************************************
52 	Copyright 1989 by Carnegie Mellon University
53 
54                       All Rights Reserved
55 
56 Permission to use, copy, modify, and distribute this software and its
57 documentation for any purpose and without fee is hereby granted,
58 provided that the above copyright notice appear in all copies and that
59 both that copyright notice and this permission notice appear in
60 supporting documentation, and that the name of CMU not be
61 used in advertising or publicity pertaining to distribution of the
62 software without specific, written prior permission.
63 
64 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
65 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
66 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
67 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
68 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
69 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
70 SOFTWARE.
71 ******************************************************************/
72 
73 struct timeval;
74 /*
75  * A list of all the outstanding requests for a particular session.
76  */
77 #ifdef SNMP_NEED_REQUEST_LIST
78 typedef struct request_list {
79     struct request_list *next_request;
80     long            request_id;     /* request id */
81     long            message_id;     /* message id */
82     netsnmp_callback callback;      /* user callback per request (NULL if unused) */
83     void           *cb_data;        /* user callback data per request (NULL if unused) */
84     int             retries;        /* Number of retries */
85     u_long          timeout;        /* length to wait for timeout */
86     struct timeval  timeM;   /* Time this request was made [monotonic clock] */
87     struct timeval  expireM; /* Time this request is due to expire [monotonic clock]. */
88     struct snmp_session *session;
89     netsnmp_pdu    *pdu;    /* The pdu for this request
90 			     * (saved so it can be retransmitted */
91 } netsnmp_request_list;
92 #endif                          /* SNMP_NEED_REQUEST_LIST */
93 
94     /*
95      * Set fields in session and pdu to the following to get a default or unconfigured value.
96      */
97 #define SNMP_DEFAULT_COMMUNITY_LEN  0   /* to get a default community name */
98 #define SNMP_DEFAULT_RETRIES	    -1
99 #define SNMP_DEFAULT_TIMEOUT	    -1
100 #define SNMP_DEFAULT_REMPORT	    0
101 #define SNMP_DEFAULT_REQID	    -1
102 #define SNMP_DEFAULT_MSGID	    -1
103 #define SNMP_DEFAULT_ERRSTAT	    -1
104 #define SNMP_DEFAULT_ERRINDEX	    -1
105 #define SNMP_DEFAULT_ADDRESS	    0
106 #define SNMP_DEFAULT_PEERNAME	    NULL
107 #define SNMP_DEFAULT_ENTERPRISE_LENGTH	0
108 #define SNMP_DEFAULT_TIME	    0
109 #define SNMP_DEFAULT_VERSION	    -1
110 #define SNMP_DEFAULT_SECMODEL	    -1
111 #define SNMP_DEFAULT_CONTEXT        ""
112 #ifndef NETSNMP_DISABLE_MD5
113 #define SNMP_DEFAULT_AUTH_PROTO     usmHMACMD5AuthProtocol
114 #else
115 #define SNMP_DEFAULT_AUTH_PROTO     usmHMACSHA1AuthProtocol
116 #endif
117 #define SNMP_DEFAULT_AUTH_PROTOLEN  OID_LENGTH(SNMP_DEFAULT_AUTH_PROTO)
118 #ifndef NETSNMP_DISABLE_DES
119 #define SNMP_DEFAULT_PRIV_PROTO     usmDESPrivProtocol
120 #else
121 #define SNMP_DEFAULT_PRIV_PROTO     usmAESPrivProtocol
122 #endif
123 #define SNMP_DEFAULT_PRIV_PROTOLEN  OID_LENGTH(SNMP_DEFAULT_PRIV_PROTO)
124 
125     NETSNMP_IMPORT void     snmp_set_detail(const char *);
126 
127 #define SNMP_MAX_RCV_MSG_SIZE      65536
128 #define SNMP_MAX_MSG_SIZE          1472 /* ethernet MTU minus IP/UDP header */
129 #define SNMP_MAX_MSG_V3_HDRS       (4+3+4+7+7+3+7+16)   /* fudge factor=16 */
130 #define SNMP_MAX_ENG_SIZE          32
131 #define SNMP_MAX_SEC_NAME_SIZE     256
132 #define SNMP_MAX_CONTEXT_SIZE      256
133 #define SNMP_SEC_PARAM_BUF_SIZE    256
134 
135     /*
136      * set to one to ignore unauthenticated Reports
137      */
138 #define SNMPV3_IGNORE_UNAUTH_REPORTS 0
139 
140     /*
141      * authoritative engine definitions
142      */
143 #define SNMP_SESS_NONAUTHORITATIVE 0    /* should be 0 to default to this */
144 #define SNMP_SESS_AUTHORITATIVE    1    /* don't learn engineIDs */
145 #define SNMP_SESS_UNKNOWNAUTH      2    /* sometimes (like NRs) */
146 
147     /*
148      * to determine type of Report from varbind_list
149      */
150 #define REPORT_STATS_LEN  9	/* Length of prefix for MPD/USM report statistic objects */
151 #define REPORT_STATS_LEN2 8	/* Length of prefix for Target report statistic objects */
152 /* From SNMP-MPD-MIB */
153 #define REPORT_snmpUnknownSecurityModels_NUM 1
154 #define REPORT_snmpInvalidMsgs_NUM           2
155 #define REPORT_snmpUnknownPDUHandlers_NUM    3
156 /* From SNMP-USER-BASED-SM-MIB */
157 #define REPORT_usmStatsUnsupportedSecLevels_NUM 1
158 #define REPORT_usmStatsNotInTimeWindows_NUM 2
159 #define REPORT_usmStatsUnknownUserNames_NUM 3
160 #define REPORT_usmStatsUnknownEngineIDs_NUM 4
161 #define REPORT_usmStatsWrongDigests_NUM     5
162 #define REPORT_usmStatsDecryptionErrors_NUM 6
163 /* From SNMP-TARGET-MIB */
164 #define REPORT_snmpUnavailableContexts_NUM  4
165 #define REPORT_snmpUnknownContexts_NUM      5
166 
167 #define SNMP_DETAIL_SIZE        512
168 
169 #define SNMP_FLAGS_UDP_BROADCAST   0x800
170 #define SNMP_FLAGS_RESP_CALLBACK   0x400      /* Additional callback on response */
171 #define SNMP_FLAGS_USER_CREATED    0x200      /* USM user has been created */
172 #define SNMP_FLAGS_DONT_PROBE      0x100      /* don't probe for an engineID */
173 #define SNMP_FLAGS_STREAM_SOCKET   0x80
174 #define SNMP_FLAGS_LISTENING       0x40 /* Server stream sockets only */
175 #define SNMP_FLAGS_SUBSESSION      0x20
176 #define SNMP_FLAGS_SHARED_SOCKET   0x10 /* subsession list=related sessions */
177 #define SNMP_FLAGS_STRIKE2         0x02
178 #define SNMP_FLAGS_STRIKE1         0x01
179 
180 #define CLEAR_SNMP_STRIKE_FLAGS(x) \
181 	x &= ~(SNMP_FLAGS_STRIKE2|SNMP_FLAGS_STRIKE1)
182 
183     /*
184      * returns '1' if the session is to be regarded as dead,
185      * otherwise set the strike flags appropriately, and return 0
186      */
187 #define SET_SNMP_STRIKE_FLAGS(x) \
188 	((   x & SNMP_FLAGS_STRIKE2 ) ? 1 :				\
189 	 ((( x & SNMP_FLAGS_STRIKE1 ) ? ( x |= SNMP_FLAGS_STRIKE2 ) :	\
190 	                                ( x |= SNMP_FLAGS_STRIKE1 )),	\
191 	                                0))
192 
193     /*
194      * Error return values.
195      *
196      * SNMPERR_SUCCESS is the non-PDU "success" code.
197      *
198      * XXX  These should be merged with SNMP_ERR_* defines and confined
199      *      to values < 0.  ???
200      */
201 #define SNMPERR_SUCCESS			(0)     /* XXX  Non-PDU "success" code. */
202 #define SNMPERR_GENERR			(-1)
203 #define SNMPERR_BAD_LOCPORT		(-2)
204 #define SNMPERR_BAD_ADDRESS		(-3)
205 #define SNMPERR_BAD_SESSION		(-4)
206 #define SNMPERR_TOO_LONG		(-5)
207 #define SNMPERR_NO_SOCKET		(-6)
208 #define SNMPERR_V2_IN_V1		(-7)
209 #define SNMPERR_V1_IN_V2		(-8)
210 #define SNMPERR_BAD_REPEATERS		(-9)
211 #define SNMPERR_BAD_REPETITIONS		(-10)
212 #define SNMPERR_BAD_ASN1_BUILD		(-11)
213 #define SNMPERR_BAD_SENDTO		(-12)
214 #define SNMPERR_BAD_PARSE		(-13)
215 #define SNMPERR_BAD_VERSION		(-14)
216 #define SNMPERR_BAD_SRC_PARTY		(-15)
217 #define SNMPERR_BAD_DST_PARTY		(-16)
218 #define SNMPERR_BAD_CONTEXT		(-17)
219 #define SNMPERR_BAD_COMMUNITY		(-18)
220 #define SNMPERR_NOAUTH_DESPRIV		(-19)
221 #define SNMPERR_BAD_ACL			(-20)
222 #define SNMPERR_BAD_PARTY		(-21)
223 #define SNMPERR_ABORT			(-22)
224 #define SNMPERR_UNKNOWN_PDU		(-23)
225 #define SNMPERR_TIMEOUT 		(-24)
226 #define SNMPERR_BAD_RECVFROM 		(-25)
227 #define SNMPERR_BAD_ENG_ID 		(-26)
228 #define SNMPERR_BAD_SEC_NAME 		(-27)
229 #define SNMPERR_BAD_SEC_LEVEL 		(-28)
230 #define SNMPERR_ASN_PARSE_ERR           (-29)
231 #define SNMPERR_UNKNOWN_SEC_MODEL 	(-30)
232 #define SNMPERR_INVALID_MSG             (-31)
233 #define SNMPERR_UNKNOWN_ENG_ID          (-32)
234 #define SNMPERR_UNKNOWN_USER_NAME 	(-33)
235 #define SNMPERR_UNSUPPORTED_SEC_LEVEL 	(-34)
236 #define SNMPERR_AUTHENTICATION_FAILURE 	(-35)
237 #define SNMPERR_NOT_IN_TIME_WINDOW 	(-36)
238 #define SNMPERR_DECRYPTION_ERR          (-37)
239 #define SNMPERR_SC_GENERAL_FAILURE	(-38)
240 #define SNMPERR_SC_NOT_CONFIGURED	(-39)
241 #define SNMPERR_KT_NOT_AVAILABLE	(-40)
242 #define SNMPERR_UNKNOWN_REPORT          (-41)
243 #define SNMPERR_USM_GENERICERROR		(-42)
244 #define SNMPERR_USM_UNKNOWNSECURITYNAME		(-43)
245 #define SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL	(-44)
246 #define SNMPERR_USM_ENCRYPTIONERROR		(-45)
247 #define SNMPERR_USM_AUTHENTICATIONFAILURE	(-46)
248 #define SNMPERR_USM_PARSEERROR			(-47)
249 #define SNMPERR_USM_UNKNOWNENGINEID		(-48)
250 #define SNMPERR_USM_NOTINTIMEWINDOW		(-49)
251 #define SNMPERR_USM_DECRYPTIONERROR		(-50)
252 #define SNMPERR_NOMIB			(-51)
253 #define SNMPERR_RANGE			(-52)
254 #define SNMPERR_MAX_SUBID		(-53)
255 #define SNMPERR_BAD_SUBID		(-54)
256 #define SNMPERR_LONG_OID		(-55)
257 #define SNMPERR_BAD_NAME		(-56)
258 #define SNMPERR_VALUE			(-57)
259 #define SNMPERR_UNKNOWN_OBJID		(-58)
260 #define SNMPERR_NULL_PDU		(-59)
261 #define SNMPERR_NO_VARS			(-60)
262 #define SNMPERR_VAR_TYPE		(-61)
263 #define SNMPERR_MALLOC			(-62)
264 #define SNMPERR_KRB5			(-63)
265 #define SNMPERR_PROTOCOL		(-64)
266 #define SNMPERR_OID_NONINCREASING       (-65)
267 #define SNMPERR_JUST_A_CONTEXT_PROBE    (-66)
268 #define SNMPERR_TRANSPORT_NO_CONFIG     (-67)
269 #define SNMPERR_TRANSPORT_CONFIG_ERROR  (-68)
270 #define SNMPERR_TLS_NO_CERTIFICATE      (-69)
271 
272 #define SNMPERR_MAX			(-69)
273 
274 
275     /*
276      * General purpose memory allocation functions. Use these functions to
277      * allocate memory that may be reallocated or freed by the Net-SNMP
278      * library or to reallocate or free memory that has been allocated by the
279      * Net-SNMP library, and when working in a context where there is more than
280      * one heap. Examples are:
281      * - Perl XSUB's.
282      * - MSVC or MinGW with the Net-SNMP library compiled as a DLL instead of
283      *   a static library.
284      */
285     NETSNMP_IMPORT void *netsnmp_malloc(size_t size);
286     NETSNMP_IMPORT void *netsnmp_calloc(size_t nelem, size_t elsize);
287     NETSNMP_IMPORT void *netsnmp_realloc(void *ptr, size_t size);
288     NETSNMP_IMPORT void netsnmp_free(void *ptr);
289     NETSNMP_IMPORT char *netsnmp_strdup(const char *s1);
290 
291     NETSNMP_IMPORT long int netsnmp_random(void);
292     NETSNMP_IMPORT void netsnmp_srandom(unsigned int seed);
293 
294     /*
295      * void
296      * snmp_free_pdu(pdu)
297      *     netsnmp_pdu *pdu;
298      *
299      * Frees the pdu and any malloc'd data associated with it.
300      */
301 
302     NETSNMP_IMPORT void snmp_free_var_internals(netsnmp_variable_list *);     /* frees contents only */
303 
304 
305     /*
306      * This routine must be supplied by the application:
307      *
308      * u_char *authenticator(pdu, length, community, community_len)
309      * u_char *pdu;         The rest of the PDU to be authenticated
310      * int *length;         The length of the PDU (updated by the authenticator)
311      * u_char *community;   The community name to authenticate under.
312      * int  community_len   The length of the community name.
313      *
314      * Returns the authenticated pdu, or NULL if authentication failed.
315      * If null authentication is used, the authenticator in snmp_session can be
316      * set to NULL(0).
317      */
318 
319 
320 
321     /*
322      * This routine must be supplied by the application:
323      *
324      * int callback(operation, session, reqid, pdu, magic)
325      * int operation;
326      * netsnmp_session *session;    The session authenticated under.
327      * int reqid;                       The request id of this pdu (0 for TRAP)
328      * netsnmp_pdu *pdu;        The pdu information.
329      * void *magic                      A link to the data for this routine.
330      *
331      * Returns 1 if request was successful, 0 if it should be kept pending.
332      * Any data in the pdu must be copied because it will be freed elsewhere.
333      * Operations are defined below:
334      */
335 
336 #define NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE	1
337 #define NETSNMP_CALLBACK_OP_TIMED_OUT		2
338 #define NETSNMP_CALLBACK_OP_SEND_FAILED		3
339 #define NETSNMP_CALLBACK_OP_CONNECT		4
340 #define NETSNMP_CALLBACK_OP_DISCONNECT		5
341 #define NETSNMP_CALLBACK_OP_RESEND		6
342 #define NETSNMP_CALLBACK_OP_SEC_ERROR		7
343 
344     NETSNMP_IMPORT
345     long            snmp_get_next_msgid(void);
346     NETSNMP_IMPORT
347     long            snmp_get_next_reqid(void);
348     NETSNMP_IMPORT
349     long            snmp_get_next_sessid(void);
350     NETSNMP_IMPORT
351     long            snmp_get_next_transid(void);
352 
353     NETSNMP_IMPORT
354     int             netsnmp_max_send_msg_size(void);
355 
356     NETSNMP_IMPORT
357     int             snmp_oid_compare(const oid *, size_t, const oid *,
358                                      size_t);
359     NETSNMP_IMPORT
360     int             snmp_oid_ncompare(const oid *, size_t, const oid *,
361                                       size_t, size_t);
362     NETSNMP_IMPORT
363     int             snmp_oidtree_compare(const oid *, size_t, const oid *,
364                                          size_t);
365     NETSNMP_IMPORT
366     int             snmp_oidsubtree_compare(const oid *, size_t, const oid *,
367                                          size_t);
368     NETSNMP_IMPORT
369     int             netsnmp_oid_compare_ll(const oid * in_name1,
370                                            size_t len1, const oid * in_name2,
371                                            size_t len2, size_t *offpt);
372     NETSNMP_IMPORT
373     int             netsnmp_oid_equals(const oid *, size_t, const oid *,
374                                        size_t);
375     NETSNMP_IMPORT
376     int             netsnmp_oid_tree_equals(const oid *, size_t, const oid *,
377                                             size_t);
378     NETSNMP_IMPORT
379     int             netsnmp_oid_is_subtree(const oid *, size_t, const oid *,
380                                            size_t);
381     NETSNMP_IMPORT
382     int             netsnmp_oid_find_prefix(const oid * in_name1, size_t len1,
383                                             const oid * in_name2, size_t len2);
384     NETSNMP_IMPORT
385     void            init_snmp(const char *);
386 
387     NETSNMP_IMPORT
388     int
389     snmp_build(u_char ** pkt, size_t * pkt_len, size_t * offset,
390                netsnmp_session * pss, netsnmp_pdu *pdu);
391 
392     NETSNMP_IMPORT
393     int
394     snmp_parse(struct session_list *sessp, netsnmp_session *pss,
395                netsnmp_pdu *pdu, u_char *data, size_t length);
396 
397     NETSNMP_IMPORT
398     u_char         *snmp_pdu_build(netsnmp_pdu *, u_char *, size_t *);
399 #ifdef NETSNMP_USE_REVERSE_ASNENCODING
400     NETSNMP_IMPORT
401     u_char         *snmp_pdu_rbuild(netsnmp_pdu *, u_char *, size_t *);
402 #endif
403     NETSNMP_IMPORT
404     int             snmpv3_parse(netsnmp_pdu *, u_char *, size_t *,
405                                  u_char **, netsnmp_session *);
406     NETSNMP_IMPORT
407     int             snmpv3_packet_build(netsnmp_session *,
408                                         netsnmp_pdu *pdu, u_char * packet,
409                                         size_t * out_length,
410                                         u_char * pdu_data,
411                                         size_t pdu_data_len);
412     NETSNMP_IMPORT
413     int             snmpv3_packet_rbuild(netsnmp_session *,
414                                          netsnmp_pdu *pdu, u_char * packet,
415                                          size_t * out_length,
416                                          u_char * pdu_data,
417                                          size_t pdu_data_len);
418     NETSNMP_IMPORT
419     int             snmpv3_make_report(netsnmp_pdu *pdu, int error);
420     NETSNMP_IMPORT
421     int             snmpv3_get_report_type(netsnmp_pdu *pdu);
422     NETSNMP_IMPORT
423     int             snmp_pdu_parse(netsnmp_pdu *pdu, u_char * data,
424                                    size_t * length);
425     NETSNMP_IMPORT
426     u_char         *snmpv3_scopedPDU_parse(netsnmp_pdu *pdu, u_char * cp,
427                                            size_t * length);
428     NETSNMP_IMPORT
429     void            snmp_store_needed(const char *type);
430     NETSNMP_IMPORT
431     void            snmp_store_if_needed(void);
432     NETSNMP_IMPORT
433     void            snmp_store(const char *type);
434     NETSNMP_IMPORT
435     void            snmp_shutdown(const char *type);
436     NETSNMP_IMPORT
437     int             snmp_add_var(netsnmp_pdu *, const oid *, size_t, char,
438                                  const char *);
439     NETSNMP_IMPORT
440     oid            *snmp_duplicate_objid(const oid * objToCopy, size_t);
441 
442 #ifndef NETSNMP_FEATURE_REMOVE_STATISTICS
443     NETSNMP_IMPORT
444     u_int           snmp_increment_statistic(int which);
445     NETSNMP_IMPORT
446     u_int           snmp_increment_statistic_by(int which, int count);
447     NETSNMP_IMPORT
448     u_int           snmp_get_statistic(int which);
449     NETSNMP_IMPORT
450     void            snmp_init_statistics(void);
451 #else /* NETSNMP_FEATURE_REMOVE_STATISTICS */
452 
453 /* allow code to continue referencing API even if statistics are removed */
454 #define snmp_increment_statistic(X)
455 #define snmp_increment_statistic_by(X,Y)
456 #define snmp_init_statistics()
457 
458 #endif
459 
460     NETSNMP_IMPORT
461     int             create_user_from_session(netsnmp_session * session);
462     NETSNMP_IMPORT
463     int snmpv3_probe_contextEngineID_rfc5343(struct session_list *slp,
464                                              netsnmp_session *session);
465 
466     /*
467      * New re-allocating reverse encoding functions.
468      */
469 #ifdef NETSNMP_USE_REVERSE_ASNENCODING
470 
471     NETSNMP_IMPORT
472     int        snmpv3_packet_realloc_rbuild(u_char ** pkt, size_t * pkt_len,
473                                      size_t * offset,
474                                      netsnmp_session * session,
475                                      netsnmp_pdu *pdu, u_char * pdu_data,
476                                      size_t pdu_data_len);
477 
478     NETSNMP_IMPORT
479     int        snmp_pdu_realloc_rbuild(u_char ** pkt, size_t * pkt_len,
480                                 size_t * offset, netsnmp_pdu *pdu);
481 #endif
482 
483 
484 
485 struct netsnmp_transport_s;
486 
487     /*
488      * Extended open; fpre_parse has changed.
489      */
490 
491     NETSNMP_IMPORT
492     netsnmp_session *snmp_open_ex(netsnmp_session *,
493                                   int (*fpre_parse) (netsnmp_session *,
494                                                      struct
495                                                      netsnmp_transport_s *,
496                                                      void *, int),
497                                   int (*fparse) (netsnmp_session *,
498                                                  netsnmp_pdu *, u_char *,
499                                                  size_t),
500                                   int (*fpost_parse) (netsnmp_session *,
501                                                       netsnmp_pdu *, int),
502                                   int (*fbuild) (netsnmp_session *,
503                                                  netsnmp_pdu *, u_char *,
504                                                  size_t *),
505                                   int (*frbuild) (netsnmp_session *,
506                                                   netsnmp_pdu *, u_char **,
507                                                   size_t *, size_t *),
508                                   int (*fcheck) (u_char *, size_t));
509 
510     /*
511      * provided for backwards compatability.  Don't use these functions.
512      * See snmp_debug.h and snmp_debug.c instead.
513      */
514 
515     NETSNMP_IMPORT
516     void            snmp_set_do_debugging(int);
517     NETSNMP_IMPORT
518     int             snmp_get_do_debugging(void);
519 
520 
521     NETSNMP_IMPORT
522     void            netsnmp_sess_log_error(int priority,
523                                            const char *prog_string,
524                                            netsnmp_session * ss);
525 
526     NETSNMP_IMPORT
527     const char *    snmp_pdu_type(int type);
528 
529     /*
530      * Return the netsnmp_transport structure associated with the given opaque
531      * pointer.
532      */
533 
534     NETSNMP_IMPORT
535     struct netsnmp_transport_s *snmp_sess_transport(void *);
536     NETSNMP_IMPORT
537     void            snmp_sess_transport_set(void *,
538 					    struct netsnmp_transport_s *);
539 
540     NETSNMP_IMPORT int
541     netsnmp_sess_config_transport(struct netsnmp_container_s *transport_configuration,
542                                   struct netsnmp_transport_s *transport);
543 
544     NETSNMP_IMPORT int
545     netsnmp_sess_config_and_open_transport(netsnmp_session *in_session,
546                                            struct netsnmp_transport_s *transport);
547 
548     /*
549      * EXTENDED SESSION API ------------------------------------------
550      *
551      * snmp_sess_add_ex, snmp_sess_add, snmp_add
552      *
553      * Analogous to snmp_open family of functions, but taking an
554      * netsnmp_transport pointer as an extra argument.  Unlike snmp_open et
555      * al. it doesn't attempt to interpret the in_session->peername as a
556      * transport endpoint specifier, but instead uses the supplied transport.
557      * JBPN
558      *
559      */
560 
561     NETSNMP_IMPORT
562     void           *snmp_sess_add_ex(netsnmp_session *,
563                                      struct netsnmp_transport_s *,
564                                      int (*fpre_parse) (netsnmp_session *,
565                                                         struct
566                                                         netsnmp_transport_s
567                                                         *, void *, int),
568                                      int (*fparse) (netsnmp_session *,
569                                                     struct snmp_pdu *,
570                                                     u_char *, size_t),
571                                      int (*fpost_parse) (netsnmp_session *,
572                                                          struct snmp_pdu *,
573                                                          int),
574                                      int (*fbuild) (netsnmp_session *,
575                                                     struct snmp_pdu *,
576                                                     u_char *, size_t *),
577                                      int (*frbuild) (netsnmp_session *,
578                                                      struct snmp_pdu *,
579                                                      u_char **, size_t *,
580                                                      size_t *),
581                                      int (*fcheck) (u_char *, size_t),
582                                      netsnmp_pdu *(*fcreate_pdu) (struct
583                                                                   netsnmp_transport_s
584                                                                   *,
585                                                                   void *,
586                                                                   size_t));
587 
588     NETSNMP_IMPORT
589     void           *snmp_sess_add(netsnmp_session *,
590                                   struct netsnmp_transport_s *,
591                                   int (*fpre_parse) (netsnmp_session *,
592                                                      struct
593                                                      netsnmp_transport_s *,
594                                                      void *, int),
595                                   int (*fpost_parse) (netsnmp_session *,
596                                                       netsnmp_pdu *, int));
597 
598     NETSNMP_IMPORT
599     netsnmp_session *snmp_add(netsnmp_session *,
600                               struct netsnmp_transport_s *,
601                               int (*fpre_parse) (netsnmp_session *,
602                                                  struct netsnmp_transport_s
603                                                  *, void *, int),
604                               int (*fpost_parse) (netsnmp_session *,
605                                                   netsnmp_pdu *, int));
606     NETSNMP_IMPORT
607     netsnmp_session *snmp_add_full(netsnmp_session * in_session,
608                                    struct netsnmp_transport_s *transport,
609                                    int (*fpre_parse) (netsnmp_session *,
610                                                       struct
611                                                       netsnmp_transport_s
612                                                       *, void *, int),
613                                    int (*fparse) (netsnmp_session *,
614                                                   netsnmp_pdu *, u_char *,
615                                                   size_t),
616                                    int (*fpost_parse) (netsnmp_session *,
617                                                        netsnmp_pdu *, int),
618                                    int (*fbuild) (netsnmp_session *,
619                                                   netsnmp_pdu *, u_char *,
620                                                   size_t *),
621                                    int (*frbuild) (netsnmp_session *,
622                                                    netsnmp_pdu *,
623                                                    u_char **, size_t *,
624                                                    size_t *),
625                                    int (*fcheck) (u_char *, size_t),
626                                    netsnmp_pdu *(*fcreate_pdu) (struct
627                                                                 netsnmp_transport_s
628                                                                 *, void *,
629                                                                 size_t)
630         );
631     /*
632      * end single session API
633      */
634 
635     /*
636      * generic statistic counters
637      */
638 
639     /*
640      * snmpv3 statistics
641      */
642 
643     /*
644      * mpd stats
645      */
646 #define   STAT_SNMPUNKNOWNSECURITYMODELS     0
647 #define   STAT_SNMPINVALIDMSGS               1
648 #define   STAT_SNMPUNKNOWNPDUHANDLERS        2
649 #define   STAT_MPD_STATS_START               STAT_SNMPUNKNOWNSECURITYMODELS
650 #define   STAT_MPD_STATS_END                 STAT_SNMPUNKNOWNPDUHANDLERS
651 
652     /*
653      * usm stats
654      */
655 #define   STAT_USMSTATSUNSUPPORTEDSECLEVELS  3
656 #define   STAT_USMSTATSNOTINTIMEWINDOWS      4
657 #define   STAT_USMSTATSUNKNOWNUSERNAMES      5
658 #define   STAT_USMSTATSUNKNOWNENGINEIDS      6
659 #define   STAT_USMSTATSWRONGDIGESTS          7
660 #define   STAT_USMSTATSDECRYPTIONERRORS      8
661 #define   STAT_USM_STATS_START               STAT_USMSTATSUNSUPPORTEDSECLEVELS
662 #define   STAT_USM_STATS_END                 STAT_USMSTATSDECRYPTIONERRORS
663 
664     /*
665      * snmp counters
666      */
667 #define  STAT_SNMPINPKTS                     9
668 #define  STAT_SNMPOUTPKTS                    10
669 #define  STAT_SNMPINBADVERSIONS              11
670 #define  STAT_SNMPINBADCOMMUNITYNAMES        12
671 #define  STAT_SNMPINBADCOMMUNITYUSES         13
672 #define  STAT_SNMPINASNPARSEERRS             14
673     /*
674      * #define  STAT_SNMPINBADTYPES              15
675      */
676 #define  STAT_SNMPINTOOBIGS                  16
677 #define  STAT_SNMPINNOSUCHNAMES              17
678 #define  STAT_SNMPINBADVALUES                18
679 #define  STAT_SNMPINREADONLYS                19
680 #define  STAT_SNMPINGENERRS                  20
681 #define  STAT_SNMPINTOTALREQVARS             21
682 #define  STAT_SNMPINTOTALSETVARS             22
683 #define  STAT_SNMPINGETREQUESTS              23
684 #define  STAT_SNMPINGETNEXTS                 24
685 #define  STAT_SNMPINSETREQUESTS              25
686 #define  STAT_SNMPINGETRESPONSES             26
687 #define  STAT_SNMPINTRAPS                    27
688 #define  STAT_SNMPOUTTOOBIGS                 28
689 #define  STAT_SNMPOUTNOSUCHNAMES             29
690 #define  STAT_SNMPOUTBADVALUES               30
691     /*
692      * #define  STAT_SNMPOUTREADONLYS            31
693      */
694 #define  STAT_SNMPOUTGENERRS                 32
695 #define  STAT_SNMPOUTGETREQUESTS             33
696 #define  STAT_SNMPOUTGETNEXTS                34
697 #define  STAT_SNMPOUTSETREQUESTS             35
698 #define  STAT_SNMPOUTGETRESPONSES            36
699 #define  STAT_SNMPOUTTRAPS                   37
700     /*
701      * AUTHTRAPENABLE                            38
702      */
703 #define  STAT_SNMPSILENTDROPS		     39
704 #define  STAT_SNMPPROXYDROPS		     40
705 #define  STAT_SNMP_STATS_START               STAT_SNMPINPKTS
706 #define  STAT_SNMP_STATS_END                 STAT_SNMPPROXYDROPS
707 
708     /*
709      * target mib counters
710      */
711 #define  STAT_SNMPUNAVAILABLECONTEXTS	     41
712 #define  STAT_SNMPUNKNOWNCONTEXTS	     42
713 #define  STAT_TARGET_STATS_START             STAT_SNMPUNAVAILABLECONTEXTS
714 #define  STAT_TARGET_STATS_END               STAT_SNMPUNKNOWNCONTEXTS
715 
716     /*
717      * TSM counters
718      */
719 #define  STAT_TSM_SNMPTSMINVALIDCACHES             43
720 #define  STAT_TSM_SNMPTSMINADEQUATESECURITYLEVELS  44
721 #define  STAT_TSM_SNMPTSMUNKNOWNPREFIXES           45
722 #define  STAT_TSM_SNMPTSMINVALIDPREFIXES           46
723 #define  STAT_TSM_STATS_START                 STAT_TSM_SNMPTSMINVALIDCACHES
724 #define  STAT_TSM_STATS_END                   STAT_TSM_SNMPTSMINVALIDPREFIXES
725 
726     /*
727      * TLSTM counters
728      */
729 #define  STAT_TLSTM_SNMPTLSTMSESSIONOPENS                      47
730 #define  STAT_TLSTM_SNMPTLSTMSESSIONCLIENTCLOSES               48
731 #define  STAT_TLSTM_SNMPTLSTMSESSIONOPENERRORS                 49
732 #define  STAT_TLSTM_SNMPTLSTMSESSIONACCEPTS                    50
733 #define  STAT_TLSTM_SNMPTLSTMSESSIONSERVERCLOSES               51
734 #define  STAT_TLSTM_SNMPTLSTMSESSIONNOSESSIONS                 52
735 #define  STAT_TLSTM_SNMPTLSTMSESSIONINVALIDCLIENTCERTIFICATES  53
736 #define  STAT_TLSTM_SNMPTLSTMSESSIONUNKNOWNSERVERCERTIFICATE   54
737 #define  STAT_TLSTM_SNMPTLSTMSESSIONINVALIDSERVERCERTIFICATES  55
738 #define  STAT_TLSTM_SNMPTLSTMSESSIONINVALIDCACHES              56
739 
740 #define  STAT_TLSTM_STATS_START                 STAT_TLSTM_SNMPTLSTMSESSIONOPENS
741 #define  STAT_TLSTM_STATS_END          STAT_TLSTM_SNMPTLSTMSESSIONINVALIDCACHES
742 
743     /* this previously was end+1; don't know why the +1 is needed;
744        XXX: check the code */
745 #define  NETSNMP_STAT_MAX_STATS              (STAT_TLSTM_STATS_END+1)
746 /** backwards compatability */
747 #define MAX_STATS NETSNMP_STAT_MAX_STATS
748 
749     /*
750      * Internal: The list of active/open sessions.
751      */
752     struct session_list {
753        struct session_list *next;
754        netsnmp_session *session;
755        netsnmp_transport *transport;
756        struct snmp_internal_session *internal;
757     };
758 
759 #ifdef __cplusplus
760 }
761 #endif
762 #endif                          /* SNMP_API_H */
763