and added files
[bcm963xx.git] / userapps / opensource / net-snmp / include / net-snmp / library / snmp_api.h
1 #ifndef SNMP_API_H
2 #define SNMP_API_H
3
4 /*
5  * snmp_api.h - API for access to snmp.
6  *
7  * Caution: when using this library in a multi-threaded application,
8  * the values of global variables "snmp_errno" and "snmp_detail"
9  * cannot be reliably determined.  Suggest using snmp_error()
10  * to obtain the library error codes.
11  */
12
13 #ifndef DONT_SHARE_ERROR_WITH_OTHER_THREADS
14 #define SET_SNMP_ERROR(x) snmp_errno=(x)
15 #else
16 #define SET_SNMP_ERROR(x)
17 #endif
18
19
20 #ifdef __cplusplus
21 extern          "C" {
22 #endif
23
24 /***********************************************************
25         Copyright 1989 by Carnegie Mellon University
26
27                       All Rights Reserved
28
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of CMU not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
36
37 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43 SOFTWARE.
44 ******************************************************************/
45
46 struct variable_list;
47 typedef struct variable_list netsnmp_variable_list;
48 struct timeval;
49 struct netsnmp_transport_s;
50
51 #define USM_AUTH_KU_LEN     32
52 #define USM_PRIV_KU_LEN     32
53
54 typedef struct snmp_pdu {
55
56     /*
57      * Protocol-version independent fields
58      */
59     long            version;
60     int             command;        /* Type of this PDU */
61     long            reqid;  /* Request id - note: not incremented on retries */
62     long            msgid;  /* Message id for V3 messages 
63                              * note: incremented for each retry */
64     long            transid;        /* Unique ID for incoming transactions */
65     long            sessid;         /* Session id for AgentX messages */
66     long            errstat;        /* Error status (non_repeaters in GetBulk) */
67     long            errindex;       /* Error index (max_repetitions in GetBulk) */
68     u_long          time;   /* Uptime */
69     u_long          flags;
70
71     int             securityModel;
72     int             securityLevel;  /* noAuthNoPriv, authNoPriv, authPriv */
73     int             msgParseModel;
74
75     /*
76      * Transport-specific opaque data.  This replaces the IP-centric address
77      * field.  
78      */
79     
80     void           *transport_data;
81     int             transport_data_length;
82
83     /*
84      * The actual transport domain.  This SHOULD NOT BE FREE()D.  
85      */
86
87     const oid      *tDomain;
88     size_t          tDomainLen;
89
90     netsnmp_variable_list *variables;
91
92
93     /*
94      * SNMPv1 & SNMPv2c fields
95      */
96     u_char         *community;      /* community for outgoing requests. */
97     size_t          community_len;  /* Length of community name. */
98
99     /*
100      * Trap information
101      */
102     oid            *enterprise;     /* System OID */
103     size_t          enterprise_length;
104     long            trap_type;      /* trap type */
105     long            specific_type;  /* specific type */
106     unsigned char   agent_addr[4];  /* This is ONLY used for v1 TRAPs  */
107
108     /*
109      * SNMPv3 fields
110      */
111     u_char         *contextEngineID;        /* context snmpEngineID */
112     size_t          contextEngineIDLen;     /* Length of contextEngineID */
113     char           *contextName;    /* authoritative contextName */
114     size_t          contextNameLen; /* Length of contextName */
115     u_char         *securityEngineID;       /* authoritative snmpEngineID for security */
116     size_t          securityEngineIDLen;    /* Length of securityEngineID */
117     char           *securityName;   /* on behalf of this principal */
118     size_t          securityNameLen;        /* Length of securityName. */
119     
120     /*
121      * AgentX fields
122      *      (also uses SNMPv1 community field)
123      */
124     int             priority;
125     int             range_subid;
126     
127     void           *securityStateRef;
128 } netsnmp_pdu;
129
130 struct snmp_session;
131 typedef struct snmp_session netsnmp_session;
132
133 typedef int     (*snmp_callback) (int, netsnmp_session *, int,
134                                       netsnmp_pdu *, void *);
135 typedef int     (*netsnmp_callback) (int, netsnmp_session *, int,
136                                          netsnmp_pdu *, void *);
137
138 struct snmp_session {
139     /*
140      * Protocol-version independent fields
141      */
142     long            version;
143     int             retries;        /* Number of retries before timeout. */
144     long            timeout;        /* Number of uS until first timeout, then exponential backoff */
145     u_long          flags;
146     struct snmp_session *subsession;
147     struct snmp_session *next;
148
149     char           *peername;       /* Domain name or dotted IP address of default peer */
150     u_short         remote_port;    /* UDP port number of peer. */
151     u_short         local_port;     /* My UDP port number, 0 for default, picked randomly */
152     /*
153      * Authentication function or NULL if null authentication is used 
154      */
155     u_char         *(*authenticator) (u_char *, size_t *, u_char *, size_t);
156     netsnmp_callback callback;      /* Function to interpret incoming data */
157     /*
158      * Pointer to data that the callback function may consider important 
159      */
160     void           *callback_magic;
161
162     int             s_errno;        /* copy of system errno */
163     int             s_snmp_errno;   /* copy of library errno */
164     long            sessid; /* Session id - AgentX only */
165
166     /*
167      * SNMPv1 & SNMPv2c fields
168      */
169     u_char         *community;      /* community for outgoing requests. */
170     size_t          community_len;  /* Length of community name. */
171     
172     size_t          rcvMsgMaxSize;  /*  Largest message to try to receive.  */
173     size_t          sndMsgMaxSize;  /*  Largest message to try to send.  */
174
175     /*
176      * SNMPv3 fields
177      */
178     u_char          isAuthoritative;        /* are we the authoritative engine? */
179     u_char         *contextEngineID;        /* authoritative snmpEngineID */
180     size_t          contextEngineIDLen;     /* Length of contextEngineID */
181     u_int           engineBoots;    /* initial engineBoots for remote engine */
182     u_int           engineTime;     /* initial engineTime for remote engine */
183     char           *contextName;    /* authoritative contextName */
184     size_t          contextNameLen; /* Length of contextName */
185     u_char         *securityEngineID;       /* authoritative snmpEngineID */
186     size_t          securityEngineIDLen;    /* Length of contextEngineID */
187     char           *securityName;   /* on behalf of this principal */
188     size_t          securityNameLen;        /* Length of securityName. */
189     oid            *securityAuthProto;      /* auth protocol oid */
190     size_t          securityAuthProtoLen;   /* Length of auth protocol oid */
191     u_char          securityAuthKey[USM_AUTH_KU_LEN];       /* Ku for auth protocol XXX */
192     size_t          securityAuthKeyLen;     /* Length of Ku for auth protocol */
193     oid            *securityPrivProto;      /* priv protocol oid */
194     size_t          securityPrivProtoLen;   /* Length of priv protocol oid */
195     u_char          securityPrivKey[USM_PRIV_KU_LEN];       /* Ku for privacy protocol XXX */
196     size_t          securityPrivKeyLen;     /* Length of Ku for priv protocol */
197     int             securityModel;
198     int             securityLevel;  /* noAuthNoPriv, authNoPriv, authPriv */
199     
200     /*
201      * security module specific 
202      */
203     void           *securityInfo;
204
205     /*
206      * use as you want data 
207      */
208     void           *myvoid;
209 };
210
211 /*
212  * A list of all the outstanding requests for a particular session.
213  */
214 #ifdef SNMP_NEED_REQUEST_LIST
215 typedef struct request_list {
216     struct request_list *next_request;
217     long            request_id;     /* request id */
218     long            message_id;     /* message id */
219     netsnmp_callback callback;      /* user callback per request (NULL if unused) */
220     void           *cb_data;        /* user callback data per request (NULL if unused) */
221     int             retries;        /* Number of retries */
222     u_long          timeout;        /* length to wait for timeout */
223     struct timeval  time;   /* Time this request was made */
224     struct timeval  expire; /* time this request is due to expire */
225     struct snmp_session *session;
226     netsnmp_pdu    *pdu;    /* The pdu for this request
227                              * (saved so it can be retransmitted */
228 } netsnmp_request_list;
229 #endif                          /* SNMP_NEED_REQUEST_LIST */
230
231     /*
232      * Set fields in session and pdu to the following to get a default or unconfigured value.
233      */
234 #define SNMP_DEFAULT_COMMUNITY_LEN  0   /* to get a default community name */
235 #define SNMP_DEFAULT_RETRIES        -1
236 #define SNMP_DEFAULT_TIMEOUT        -1
237 #define SNMP_DEFAULT_REMPORT        0
238 #define SNMP_DEFAULT_REQID          -1
239 #define SNMP_DEFAULT_MSGID          -1
240 #define SNMP_DEFAULT_ERRSTAT        -1
241 #define SNMP_DEFAULT_ERRINDEX       -1
242 #define SNMP_DEFAULT_ADDRESS        0
243 #define SNMP_DEFAULT_PEERNAME       NULL
244 #define SNMP_DEFAULT_ENTERPRISE_LENGTH  0
245 #define SNMP_DEFAULT_TIME           0
246 #define SNMP_DEFAULT_VERSION        -1
247 #define SNMP_DEFAULT_SECMODEL       -1
248 #define SNMP_DEFAULT_CONTEXT        ""
249 #define SNMP_DEFAULT_AUTH_PROTO     usmHMACMD5AuthProtocol
250 #define SNMP_DEFAULT_AUTH_PROTOLEN  USM_LENGTH_OID_TRANSFORM
251 #define SNMP_DEFAULT_PRIV_PROTO     usmDESPrivProtocol
252 #define SNMP_DEFAULT_PRIV_PROTOLEN  USM_LENGTH_OID_TRANSFORM
253
254     extern const char *snmp_api_errstring(int);
255     extern void     snmp_perror(const char *);
256     extern void     snmp_set_detail(const char *);
257
258 #define SNMP_MAX_MSG_SIZE          1472 /* ethernet MTU minus IP/UDP header */
259 #define SNMP_MAX_MSG_V3_HDRS       (4+3+4+7+7+3+7+16)   /* fudge factor=16 */
260 #define SNMP_MAX_ENG_SIZE          32
261 #define SNMP_MAX_SEC_NAME_SIZE     256
262 #define SNMP_MAX_CONTEXT_SIZE      256
263 #define SNMP_SEC_PARAM_BUF_SIZE    256
264
265     /*
266      * set to one to ignore unauthenticated Reports 
267      */
268 #define SNMPV3_IGNORE_UNAUTH_REPORTS 0
269
270     /*
271      * authoritative engine definitions 
272      */
273 #define SNMP_SESS_NONAUTHORITATIVE 0    /* should be 0 to default to this */
274 #define SNMP_SESS_AUTHORITATIVE    1    /* don't learn engineIDs */
275 #define SNMP_SESS_UNKNOWNAUTH      2    /* sometimes (like NRs) */
276
277     /*
278      * to determine type of Report from varbind_list 
279      */
280 #define REPORT_STATS_LEN 9
281 #define REPORT_snmpUnknownSecurityModels_NUM 1
282 #define REPORT_snmpInvalidMsgs_NUM 2
283 #define REPORT_usmStatsUnsupportedSecLevels_NUM 1
284 #define REPORT_usmStatsNotInTimeWindows_NUM 2
285 #define REPORT_usmStatsUnknownUserNames_NUM 3
286 #define REPORT_usmStatsUnknownEngineIDs_NUM 4
287 #define REPORT_usmStatsWrongDigests_NUM 5
288 #define REPORT_usmStatsDecryptionErrors_NUM 6
289
290 #define SNMP_DETAIL_SIZE        512
291
292 #define SNMP_FLAGS_DONT_PROBE      0x100        /* don't probe for an engineID */
293 #define SNMP_FLAGS_STREAM_SOCKET   0x80
294 #define SNMP_FLAGS_LISTENING       0x40 /* Server stream sockets only */
295 #define SNMP_FLAGS_SUBSESSION      0x20
296 #define SNMP_FLAGS_STRIKE2         0x02
297 #define SNMP_FLAGS_STRIKE1         0x01
298
299 #define CLEAR_SNMP_STRIKE_FLAGS(x) \
300         x &= ~(SNMP_FLAGS_STRIKE2|SNMP_FLAGS_STRIKE1)
301
302     /*
303      * returns '1' if the session is to be regarded as dead,
304      * otherwise set the strike flags appropriately, and return 0
305      */
306 #define SET_SNMP_STRIKE_FLAGS(x) \
307         ((   x & SNMP_FLAGS_STRIKE2 ) ? 1 :                             \
308          ((( x & SNMP_FLAGS_STRIKE1 ) ? ( x |= SNMP_FLAGS_STRIKE2 ) :   \
309                                         ( x |= SNMP_FLAGS_STRIKE1 )),   \
310                                         0))
311
312     /*
313      * Error return values.
314      *
315      * SNMPERR_SUCCESS is the non-PDU "success" code.
316      *
317      * XXX  These should be merged with SNMP_ERR_* defines and confined
318      *      to values < 0.  ???
319      */
320 #define SNMPERR_SUCCESS                 (0)     /* XXX  Non-PDU "success" code. */
321 #define SNMPERR_GENERR                  (-1)
322 #define SNMPERR_BAD_LOCPORT             (-2)
323 #define SNMPERR_BAD_ADDRESS             (-3)
324 #define SNMPERR_BAD_SESSION             (-4)
325 #define SNMPERR_TOO_LONG                (-5)
326 #define SNMPERR_NO_SOCKET               (-6)
327 #define SNMPERR_V2_IN_V1                (-7)
328 #define SNMPERR_V1_IN_V2                (-8)
329 #define SNMPERR_BAD_REPEATERS           (-9)
330 #define SNMPERR_BAD_REPETITIONS         (-10)
331 #define SNMPERR_BAD_ASN1_BUILD          (-11)
332 #define SNMPERR_BAD_SENDTO              (-12)
333 #define SNMPERR_BAD_PARSE               (-13)
334 #define SNMPERR_BAD_VERSION             (-14)
335 #define SNMPERR_BAD_SRC_PARTY           (-15)
336 #define SNMPERR_BAD_DST_PARTY           (-16)
337 #define SNMPERR_BAD_CONTEXT             (-17)
338 #define SNMPERR_BAD_COMMUNITY           (-18)
339 #define SNMPERR_NOAUTH_DESPRIV          (-19)
340 #define SNMPERR_BAD_ACL                 (-20)
341 #define SNMPERR_BAD_PARTY               (-21)
342 #define SNMPERR_ABORT                   (-22)
343 #define SNMPERR_UNKNOWN_PDU             (-23)
344 #define SNMPERR_TIMEOUT                 (-24)
345 #define SNMPERR_BAD_RECVFROM            (-25)
346 #define SNMPERR_BAD_ENG_ID              (-26)
347 #define SNMPERR_BAD_SEC_NAME            (-27)
348 #define SNMPERR_BAD_SEC_LEVEL           (-28)
349 #define SNMPERR_ASN_PARSE_ERR           (-29)
350 #define SNMPERR_UNKNOWN_SEC_MODEL       (-30)
351 #define SNMPERR_INVALID_MSG             (-31)
352 #define SNMPERR_UNKNOWN_ENG_ID          (-32)
353 #define SNMPERR_UNKNOWN_USER_NAME       (-33)
354 #define SNMPERR_UNSUPPORTED_SEC_LEVEL   (-34)
355 #define SNMPERR_AUTHENTICATION_FAILURE  (-35)
356 #define SNMPERR_NOT_IN_TIME_WINDOW      (-36)
357 #define SNMPERR_DECRYPTION_ERR          (-37)
358 #define SNMPERR_SC_GENERAL_FAILURE      (-38)
359 #define SNMPERR_SC_NOT_CONFIGURED       (-39)
360 #define SNMPERR_KT_NOT_AVAILABLE        (-40)
361 #define SNMPERR_UNKNOWN_REPORT          (-41)
362 #define SNMPERR_USM_GENERICERROR                (-42)
363 #define SNMPERR_USM_UNKNOWNSECURITYNAME         (-43)
364 #define SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL    (-44)
365 #define SNMPERR_USM_ENCRYPTIONERROR             (-45)
366 #define SNMPERR_USM_AUTHENTICATIONFAILURE       (-46)
367 #define SNMPERR_USM_PARSEERROR                  (-47)
368 #define SNMPERR_USM_UNKNOWNENGINEID             (-48)
369 #define SNMPERR_USM_NOTINTIMEWINDOW             (-49)
370 #define SNMPERR_USM_DECRYPTIONERROR             (-50)
371 #define SNMPERR_NOMIB                   (-51)
372 #define SNMPERR_RANGE                   (-52)
373 #define SNMPERR_MAX_SUBID               (-53)
374 #define SNMPERR_BAD_SUBID               (-54)
375 #define SNMPERR_LONG_OID                (-55)
376 #define SNMPERR_BAD_NAME                (-56)
377 #define SNMPERR_VALUE                   (-57)
378 #define SNMPERR_UNKNOWN_OBJID           (-58)
379 #define SNMPERR_NULL_PDU                (-59)
380 #define SNMPERR_NO_VARS                 (-60)
381 #define SNMPERR_VAR_TYPE                (-61)
382 #define SNMPERR_MALLOC                  (-62)
383 #define SNMPERR_KRB5                    (-63)
384
385 #define SNMPERR_MAX                     (-63)
386
387 #define non_repeaters   errstat
388 #define max_repetitions errindex
389
390 struct variable_list {
391     struct variable_list *next_variable;    /* NULL for last variable */
392     oid            *name;   /* Object identifier of variable */
393     size_t          name_length;    /* number of subid's in name */
394     u_char          type;   /* ASN type of variable */
395     union {                 /* value of variable */
396         long           *integer;
397         u_char         *string;
398         oid            *objid;
399         u_char         *bitstring;
400         struct counter64 *counter64;
401 #ifdef OPAQUE_SPECIAL_TYPES
402         float          *floatVal;
403         double         *doubleVal;
404         /*
405          * t_union *unionVal; 
406          */
407 #endif                          /* OPAQUE_SPECIAL_TYPES */
408     } val;
409     size_t          val_len;
410     oid             name_loc[MAX_OID_LEN];  /* 90 percentile < 24. */
411     u_char          buf[40];        /* 90 percentile < 40. */
412     void           *data;   /* (Opaque) hook for additional data */
413     void            (*dataFreeHook)(void *);       /* callback to free above */
414     int             index;
415 };
416
417
418
419     /*
420      * netsnmp_session *snmp_open(session)
421      *      netsnmp_session *session;
422      *
423      * Sets up the session with the snmp_session information provided
424      * by the user.  Then opens and binds the necessary UDP port.
425      * A handle to the created session is returned (this is different than
426      * the pointer passed to snmp_open()).  On any error, NULL is returned
427      * and snmp_errno is set to the appropriate error code.
428      */
429     netsnmp_session *snmp_open(netsnmp_session *);
430
431     /*
432      * int snmp_close(session)
433      *     netsnmp_session *session;
434      *
435      * Close the input session.  Frees all data allocated for the session,
436      * dequeues any pending requests, and closes any sockets allocated for
437      * the session.  Returns 0 on error, 1 otherwise.
438      *
439      * snmp_close_sessions() does the same thing for all open sessions
440      */
441     int             snmp_close(netsnmp_session *);
442     int             snmp_close_sessions(void);
443
444
445     /*
446      * int snmp_send(session, pdu)
447      *     netsnmp_session *session;
448      *     netsnmp_pdu      *pdu;
449      *
450      * Sends the input pdu on the session after calling snmp_build to create
451      * a serialized packet.  If necessary, set some of the pdu data from the
452      * session defaults.  Add a request corresponding to this pdu to the list
453      * of outstanding requests on this session, then send the pdu.
454      * Returns the request id of the generated packet if applicable, otherwise 1.
455      * On any error, 0 is returned.
456      * The pdu is freed by snmp_send() unless a failure occured.
457      */
458     int             snmp_send(netsnmp_session *, netsnmp_pdu *);
459
460     /*
461      * int snmp_async_send(session, pdu, callback, cb_data)
462      *     netsnmp_session *session;
463      *     netsnmp_pdu      *pdu;
464      *     netsnmp_callback callback;
465      *     void   *cb_data;
466      *
467      * Sends the input pdu on the session after calling snmp_build to create
468      * a serialized packet.  If necessary, set some of the pdu data from the
469      * session defaults.  Add a request corresponding to this pdu to the list
470      * of outstanding requests on this session and store callback and data,
471      * then send the pdu.
472      * Returns the request id of the generated packet if applicable, otherwise 1.
473      * On any error, 0 is returned.
474      * The pdu is freed by snmp_send() unless a failure occured.
475      */
476     int             snmp_async_send(netsnmp_session *, netsnmp_pdu *,
477                                     netsnmp_callback, void *);
478
479
480     /*
481      * void snmp_read(fdset)
482      *     fd_set  *fdset;
483      *
484      * Checks to see if any of the fd's set in the fdset belong to
485      * snmp.  Each socket with it's fd set has a packet read from it
486      * and snmp_parse is called on the packet received.  The resulting pdu
487      * is passed to the callback routine for that session.  If the callback
488      * routine returns successfully, the pdu and it's request are deleted.
489      */
490     void            snmp_read(fd_set *);
491
492
493
494     /*
495      * void
496      * snmp_free_pdu(pdu)
497      *     netsnmp_pdu *pdu;
498      *
499      * Frees the pdu and any malloc'd data associated with it.
500      */
501     void            snmp_free_pdu(netsnmp_pdu *);
502
503     void            snmp_free_var(netsnmp_variable_list *);     /* frees just this one */
504
505     void            snmp_free_varbind(netsnmp_variable_list * var);     /* frees all in list */
506
507     /*
508      * int snmp_select_info(numfds, fdset, timeout, block)
509      * int *numfds;
510      * fd_set   *fdset;
511      * struct timeval *timeout;
512      * int *block;
513      *
514      * Returns info about what snmp requires from a select statement.
515      * numfds is the number of fds in the list that are significant.
516      * All file descriptors opened for SNMP are OR'd into the fdset.
517      * If activity occurs on any of these file descriptors, snmp_read
518      * should be called with that file descriptor set.
519      *
520      * The timeout is the latest time that SNMP can wait for a timeout.  The
521      * select should be done with the minimum time between timeout and any other
522      * timeouts necessary.  This should be checked upon each invocation of select.
523      * If a timeout is received, snmp_timeout should be called to check if the
524      * timeout was for SNMP.  (snmp_timeout is idempotent)
525      *
526      * Block is 1 if the select is requested to block indefinitely, rather than
527      * time out.  If block is input as 1, the timeout value will be treated as
528      * undefined, but it must be available for setting in snmp_select_info.  On
529      * return, if block is true, the value of timeout will be undefined.
530      *
531      * snmp_select_info returns the number of open sockets.  (i.e. The number
532      * of sessions open)
533      */
534     int             snmp_select_info(int *, fd_set *, struct timeval *,
535                                      int *);
536
537
538
539     /*
540      * void snmp_timeout();
541      *
542      * snmp_timeout should be called whenever the timeout from snmp_select_info
543      * expires, but it is idempotent, so snmp_timeout can be polled (probably a
544      * cpu expensive proposition).  snmp_timeout checks to see if any of the
545      * sessions have an outstanding request that has timed out.  If it finds one
546      * (or more), and that pdu has more retries available, a new packet is formed
547      * from the pdu and is resent.  If there are no more retries available, the
548      * callback for the session is used to alert the user of the timeout.
549      */
550
551     void            snmp_timeout(void);
552
553
554     /*
555      * This routine must be supplied by the application:
556      *
557      * u_char *authenticator(pdu, length, community, community_len)
558      * u_char *pdu;         The rest of the PDU to be authenticated
559      * int *length;         The length of the PDU (updated by the authenticator)
560      * u_char *community;   The community name to authenticate under.
561      * int  community_len   The length of the community name.
562      *
563      * Returns the authenticated pdu, or NULL if authentication failed.
564      * If null authentication is used, the authenticator in snmp_session can be
565      * set to NULL(0).
566      */
567
568
569
570     /*
571      * This routine must be supplied by the application:
572      *
573      * int callback(operation, session, reqid, pdu, magic)
574      * int operation;
575      * netsnmp_session *session;    The session authenticated under.
576      * int reqid;                       The request id of this pdu (0 for TRAP)
577      * netsnmp_pdu *pdu;        The pdu information.
578      * void *magic                      A link to the data for this routine.
579      *
580      * Returns 1 if request was successful, 0 if it should be kept pending.
581      * Any data in the pdu must be copied because it will be freed elsewhere.
582      * Operations are defined below:
583      */
584
585 #define NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE    1
586 #define NETSNMP_CALLBACK_OP_TIMED_OUT           2
587 #define NETSNMP_CALLBACK_OP_SEND_FAILED         3
588 #define NETSNMP_CALLBACK_OP_CONNECT             4
589 #define NETSNMP_CALLBACK_OP_DISCONNECT          5
590
591     long            snmp_get_next_msgid(void);
592     long            snmp_get_next_reqid(void);
593     long            snmp_get_next_sessid(void);
594     long            snmp_get_next_transid(void);
595
596     int             snmp_oid_compare(const oid *, size_t, const oid *,
597                                      size_t);
598     int             snmp_oid_ncompare(const oid *, size_t, const oid *,
599                                       size_t, size_t);
600     int             snmp_oidtree_compare(const oid *, size_t, const oid *,
601                                          size_t);
602     int             netsnmp_oid_equals(const oid *, size_t, const oid *,
603                                        size_t);
604     int             netsnmp_oid_tree_equals(const oid *, size_t, const oid *,
605                                             size_t);
606     int             netsnmp_oid_is_subtree(const oid *, size_t, const oid *,
607                                            size_t);
608     int             netsnmp_oid_find_prefix(const oid * in_name1, size_t len1,
609                                             const oid * in_name2, size_t len2);
610     void            init_snmp(const char *);
611     u_char         *snmp_pdu_build(netsnmp_pdu *, u_char *, size_t *);
612 #ifdef USE_REVERSE_ASNENCODING
613     u_char         *snmp_pdu_rbuild(netsnmp_pdu *, u_char *, size_t *);
614 #endif
615     int             snmpv3_parse(netsnmp_pdu *, u_char *, size_t *,
616                                  u_char **, netsnmp_session *);
617     int             snmpv3_packet_build(netsnmp_session *,
618                                         netsnmp_pdu *pdu, u_char * packet,
619                                         size_t * out_length,
620                                         u_char * pdu_data,
621                                         size_t pdu_data_len);
622     int             snmpv3_packet_rbuild(netsnmp_session *,
623                                          netsnmp_pdu *pdu, u_char * packet,
624                                          size_t * out_length,
625                                          u_char * pdu_data,
626                                          size_t pdu_data_len);
627     int             snmpv3_make_report(netsnmp_pdu *pdu, int error);
628     int             snmpv3_get_report_type(netsnmp_pdu *pdu);
629     int             snmp_pdu_parse(netsnmp_pdu *pdu, u_char * data,
630                                    size_t * length);
631     u_char         *snmpv3_scopedPDU_parse(netsnmp_pdu *pdu, u_char * cp,
632                                            size_t * length);
633     void            snmp_store(const char *type);
634     void            snmp_shutdown(const char *type);
635     netsnmp_variable_list *snmp_pdu_add_variable(netsnmp_pdu *, oid *,
636                                                  size_t, u_char, const u_char *,
637                                                  size_t);
638     netsnmp_variable_list *snmp_varlist_add_variable(netsnmp_variable_list
639                                                      ** varlist,
640                                                      oid * name,
641                                                      size_t name_length,
642                                                      u_char type,
643                                                      const u_char * value,
644                                                      size_t len);
645     int             snmp_add_var(netsnmp_pdu *, oid *, size_t, char,
646                                  const char *);
647     oid            *snmp_duplicate_objid(const oid * objToCopy, size_t);
648     u_int           snmp_increment_statistic(int which);
649     u_int           snmp_increment_statistic_by(int which, int count);
650     u_int           snmp_get_statistic(int which);
651     void            snmp_init_statistics(void);
652     int             create_user_from_session(netsnmp_session * session);
653
654     /*
655      * New re-allocating reverse encoding functions.  
656      */
657 #ifdef USE_REVERSE_ASNENCODING
658
659     int        snmpv3_packet_realloc_rbuild(u_char ** pkt, size_t * pkt_len,
660                                      size_t * offset,
661                                      netsnmp_session * session,
662                                      netsnmp_pdu *pdu, u_char * pdu_data,
663                                      size_t pdu_data_len);
664
665     int        snmp_pdu_realloc_rbuild(u_char ** pkt, size_t * pkt_len,
666                                 size_t * offset, netsnmp_pdu *pdu);
667 #endif
668
669
670
671     /*
672      * Extended open; fpre_parse has changed.  
673      */
674
675     netsnmp_session *snmp_open_ex(netsnmp_session *,
676                                   int (*fpre_parse) (netsnmp_session *,
677                                                      struct
678                                                      netsnmp_transport_s *,
679                                                      void *, int),
680                                   int (*fparse) (netsnmp_session *,
681                                                  netsnmp_pdu *, u_char *,
682                                                  size_t),
683                                   int (*fpost_parse) (netsnmp_session *,
684                                                       netsnmp_pdu *, int),
685                                   int (*fbuild) (netsnmp_session *,
686                                                  netsnmp_pdu *, u_char *,
687                                                  size_t *),
688                                   int (*frbuild) (netsnmp_session *,
689                                                   netsnmp_pdu *, u_char **,
690                                                   size_t *, size_t *),
691                                   int (*fcheck) (u_char *, size_t));
692
693     /*
694      * provided for backwards compatability.  Don't use these functions.
695      * See snmp_debug.h and snmp_debug.c instead.
696      */
697
698     void            snmp_set_do_debugging(int);
699     int             snmp_get_do_debugging(void);
700
701
702     /*
703      * snmp_error - return error data
704      * Inputs :  address of errno, address of snmp_errno, address of string
705      * Caller must free the string returned after use.
706      */
707     void            snmp_error(netsnmp_session *, int *, int *, char **);
708     /*
709      * single session API.
710      *
711      * These functions perform similar actions as snmp_XX functions,
712      * but operate on a single session only.
713      *
714      * Synopsis:
715      
716      void * sessp;
717      netsnmp_session session, *ss;
718      netsnmp_pdu *pdu, *response;
719      
720      snmp_sess_init(&session);
721      session.retries = ...
722      session.remote_port = ...
723      sessp = snmp_sess_open(&session);
724      ss = snmp_sess_session(sessp);
725      if (ss == NULL)
726      exit(1);
727      ...
728      if (ss->community) free(ss->community);
729      ss->community = strdup(gateway);
730      ss->community_len = strlen(gateway);
731      ...
732      snmp_sess_synch_response(sessp, pdu, &response);
733      ...
734      snmp_sess_close(sessp);
735      
736      * See also:
737      * snmp_sess_synch_response, in snmp_client.h.
738      
739      * Notes:
740      *  1. Invoke snmp_sess_session after snmp_sess_open.
741      *  2. snmp_sess_session return value is an opaque pointer.
742      *  3. Do NOT free memory returned by snmp_sess_session.
743      *  4. Replace snmp_send(ss,pdu) with snmp_sess_send(sessp,pdu)
744      */
745
746     void            snmp_sess_init(netsnmp_session *);
747     void           *snmp_sess_open(netsnmp_session *);
748     void           *snmp_sess_pointer(netsnmp_session *);
749     netsnmp_session *snmp_sess_session(void *);
750
751     /*
752      * Return the netsnmp_transport structure associated with the given opaque
753      * pointer.  
754      */
755
756     struct netsnmp_transport_s *snmp_sess_transport(void *);
757     void            snmp_sess_transport_set(void *,
758                                             struct netsnmp_transport_s *);
759
760     /*
761      * EXPERIMENTAL API EXTENSIONS ------------------------------------------ 
762      * 
763      * snmp_sess_add_ex, snmp_sess_add, snmp_add 
764      * 
765      * Analogous to snmp_open family of functions, but taking an
766      * netsnmp_transport pointer as an extra argument.  Unlike snmp_open et
767      * al. it doesn't attempt to interpret the in_session->peername as a
768      * transport endpoint specifier, but instead uses the supplied transport.
769      * JBPN
770      * 
771      */
772
773     void           *snmp_sess_add_ex(netsnmp_session *,
774                                      struct netsnmp_transport_s *,
775                                      int (*fpre_parse) (netsnmp_session *,
776                                                         struct
777                                                         netsnmp_transport_s
778                                                         *, void *, int),
779                                      int (*fparse) (netsnmp_session *,
780                                                     struct snmp_pdu *,
781                                                     u_char *, size_t),
782                                      int (*fpost_parse) (netsnmp_session *,
783                                                          struct snmp_pdu *,
784                                                          int),
785                                      int (*fbuild) (netsnmp_session *,
786                                                     struct snmp_pdu *,
787                                                     u_char *, size_t *),
788                                      int (*frbuild) (netsnmp_session *,
789                                                      struct snmp_pdu *,
790                                                      u_char **, size_t *,
791                                                      size_t *),
792                                      int (*fcheck) (u_char *, size_t),
793                                      netsnmp_pdu *(*fcreate_pdu) (struct
794                                                                   netsnmp_transport_s
795                                                                   *,
796                                                                   void *,
797                                                                   size_t));
798
799     void           *snmp_sess_add(netsnmp_session *,
800                                   struct netsnmp_transport_s *,
801                                   int (*fpre_parse) (netsnmp_session *,
802                                                      struct
803                                                      netsnmp_transport_s *,
804                                                      void *, int),
805                                   int (*fpost_parse) (netsnmp_session *,
806                                                       netsnmp_pdu *, int));
807
808     netsnmp_session *snmp_add(netsnmp_session *,
809                               struct netsnmp_transport_s *,
810                               int (*fpre_parse) (netsnmp_session *,
811                                                  struct netsnmp_transport_s
812                                                  *, void *, int),
813                               int (*fpost_parse) (netsnmp_session *,
814                                                   netsnmp_pdu *, int));
815     netsnmp_session *snmp_add_full(netsnmp_session * in_session,
816                                    struct netsnmp_transport_s *transport,
817                                    int (*fpre_parse) (netsnmp_session *,
818                                                       struct
819                                                       netsnmp_transport_s
820                                                       *, void *, int),
821                                    int (*fparse) (netsnmp_session *,
822                                                   netsnmp_pdu *, u_char *,
823                                                   size_t),
824                                    int (*fpost_parse) (netsnmp_session *,
825                                                        netsnmp_pdu *, int),
826                                    int (*fbuild) (netsnmp_session *,
827                                                   netsnmp_pdu *, u_char *,
828                                                   size_t *),
829                                    int (*frbuild) (netsnmp_session *,
830                                                    netsnmp_pdu *,
831                                                    u_char **, size_t *,
832                                                    size_t *),
833                                    int (*fcheck) (u_char *, size_t),
834                                    netsnmp_pdu *(*fcreate_pdu) (struct
835                                                                 netsnmp_transport_s
836                                                                 *, void *,
837                                                                 size_t)
838         );
839
840     /*
841      * use return value from snmp_sess_open as void * parameter 
842      */
843
844     int             snmp_sess_send(void *, netsnmp_pdu *);
845     int             snmp_sess_async_send(void *, netsnmp_pdu *,
846                                          netsnmp_callback, void *);
847     int             snmp_sess_select_info(void *, int *, fd_set *,
848                                           struct timeval *, int *);
849     int             snmp_sess_read(void *, fd_set *);
850     void            snmp_sess_timeout(void *);
851     int             snmp_sess_close(void *);
852
853     void            snmp_sess_error(void *, int *, int *, char **);
854     void            netsnmp_sess_log_error(int priority,
855                                            const char *prog_string,
856                                            netsnmp_session * ss);
857     void            snmp_sess_perror(const char *prog_string,
858                                      netsnmp_session * ss);
859
860     /*
861      * end single session API 
862      */
863
864     /*
865      * generic statistic counters 
866      */
867
868     /*
869      * snmpv3 statistics 
870      */
871
872     /*
873      * mpd stats 
874      */
875 #define   STAT_SNMPUNKNOWNSECURITYMODELS     0
876 #define   STAT_SNMPINVALIDMSGS               1
877 #define   STAT_SNMPUNKNOWNPDUHANDLERS        2
878 #define   STAT_MPD_STATS_START               STAT_SNMPUNKNOWNSECURITYMODELS
879 #define   STAT_MPD_STATS_END                 STAT_SNMPUNKNOWNPDUHANDLERS
880
881     /*
882      * usm stats 
883      */
884 #define   STAT_USMSTATSUNSUPPORTEDSECLEVELS  3
885 #define   STAT_USMSTATSNOTINTIMEWINDOWS      4
886 #define   STAT_USMSTATSUNKNOWNUSERNAMES      5
887 #define   STAT_USMSTATSUNKNOWNENGINEIDS      6
888 #define   STAT_USMSTATSWRONGDIGESTS          7
889 #define   STAT_USMSTATSDECRYPTIONERRORS      8
890 #define   STAT_USM_STATS_START               STAT_USMSTATSUNSUPPORTEDSECLEVELS
891 #define   STAT_USM_STATS_END                 STAT_USMSTATSDECRYPTIONERRORS
892
893     /*
894      * snmp counters 
895      */
896 #define  STAT_SNMPINPKTS                     9
897 #define  STAT_SNMPOUTPKTS                    10
898 #define  STAT_SNMPINBADVERSIONS              11
899 #define  STAT_SNMPINBADCOMMUNITYNAMES        12
900 #define  STAT_SNMPINBADCOMMUNITYUSES         13
901 #define  STAT_SNMPINASNPARSEERRS             14
902     /*
903      * #define  STAT_SNMPINBADTYPES              15 
904      */
905 #define  STAT_SNMPINTOOBIGS                  16
906 #define  STAT_SNMPINNOSUCHNAMES              17
907 #define  STAT_SNMPINBADVALUES                18
908 #define  STAT_SNMPINREADONLYS                19
909 #define  STAT_SNMPINGENERRS                  20
910 #define  STAT_SNMPINTOTALREQVARS             21
911 #define  STAT_SNMPINTOTALSETVARS             22
912 #define  STAT_SNMPINGETREQUESTS              23
913 #define  STAT_SNMPINGETNEXTS                 24
914 #define  STAT_SNMPINSETREQUESTS              25
915 #define  STAT_SNMPINGETRESPONSES             26
916 #define  STAT_SNMPINTRAPS                    27
917 #define  STAT_SNMPOUTTOOBIGS                 28
918 #define  STAT_SNMPOUTNOSUCHNAMES             29
919 #define  STAT_SNMPOUTBADVALUES               30
920     /*
921      * #define  STAT_SNMPOUTREADONLYS            31 
922      */
923 #define  STAT_SNMPOUTGENERRS                 32
924 #define  STAT_SNMPOUTGETREQUESTS             33
925 #define  STAT_SNMPOUTGETNEXTS                34
926 #define  STAT_SNMPOUTSETREQUESTS             35
927 #define  STAT_SNMPOUTGETRESPONSES            36
928 #define  STAT_SNMPOUTTRAPS                   37
929     /*
930      * AUTHTRAPENABLE                            38 
931      */
932 #define  STAT_SNMPSILENTDROPS                39
933 #define  STAT_SNMPPROXYDROPS                 40
934 #define  STAT_SNMP_STATS_START               STAT_SNMPINPKTS
935 #define  STAT_SNMP_STATS_END                 STAT_SNMPPROXYDROPS
936
937     /*
938      * target mib counters 
939      */
940 #define  STAT_SNMPUNAVAILABLECONTEXTS        41
941 #define  STAT_SNMPUNKNOWNCONTEXTS            42
942 #define  STAT_TARGET_STATS_START             STAT_SNMPUNAVAILABLECONTEXTS
943 #define  STAT_TARGET_STATS_END               STAT_SNMPUNKNOWNCONTEXTS
944
945 #define  MAX_STATS                           43
946
947 #ifdef __cplusplus
948 }
949 #endif
950 #endif                          /* SNMP_API_H */