|
net-snmp
5.4.1
|
00001 /* Portions of this file are subject to the following copyright(s). See 00002 * the Net-SNMP's COPYING file for more details and other copyrights 00003 * that may apply: 00004 */ 00005 /* 00006 * Portions of this file are copyrighted by: 00007 * Copyright © 2003 Sun Microsystems, Inc. All rights reserved. 00008 * Use is subject to license terms specified in the COPYING file 00009 * distributed with the Net-SNMP package. 00010 */ 00011 #ifndef SNMP_API_H 00012 #define SNMP_API_H 00013 00014 /* 00015 * @file snmp_api.h - API for access to snmp. 00016 * 00017 * @addtogroup library 00018 * 00019 * Caution: when using this library in a multi-threaded application, 00020 * the values of global variables "snmp_errno" and "snmp_detail" 00021 * cannot be reliably determined. Suggest using snmp_error() 00022 * to obtain the library error codes. 00023 * 00024 * @{ 00025 */ 00026 00027 #ifndef DONT_SHARE_ERROR_WITH_OTHER_THREADS 00028 #define SET_SNMP_ERROR(x) snmp_errno=(x) 00029 #else 00030 #define SET_SNMP_ERROR(x) 00031 #endif 00032 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 /*********************************************************** 00039 Copyright 1989 by Carnegie Mellon University 00040 00041 All Rights Reserved 00042 00043 Permission to use, copy, modify, and distribute this software and its 00044 documentation for any purpose and without fee is hereby granted, 00045 provided that the above copyright notice appear in all copies and that 00046 both that copyright notice and this permission notice appear in 00047 supporting documentation, and that the name of CMU not be 00048 used in advertising or publicity pertaining to distribution of the 00049 software without specific, written prior permission. 00050 00051 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 00052 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 00053 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 00054 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 00055 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 00056 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 00057 SOFTWARE. 00058 ******************************************************************/ 00059 00062 struct variable_list; 00063 typedef struct variable_list netsnmp_variable_list; 00064 struct timeval; 00065 struct netsnmp_transport_s; 00066 00067 #define USM_AUTH_KU_LEN 32 00068 #define USM_PRIV_KU_LEN 32 00069 00075 typedef struct snmp_pdu { 00076 00077 /* 00078 * Protocol-version independent fields 00079 */ 00081 long version; 00083 int command; 00085 long reqid; 00087 long msgid; 00089 long transid; 00091 long sessid; 00093 long errstat; 00095 long errindex; 00097 u_long time; 00098 u_long flags; 00099 00100 int securityModel; 00102 int securityLevel; 00103 int msgParseModel; 00104 00110 void *transport_data; 00111 int transport_data_length; 00112 00117 const oid *tDomain; 00118 size_t tDomainLen; 00119 00120 netsnmp_variable_list *variables; 00121 00122 00123 /* 00124 * SNMPv1 & SNMPv2c fields 00125 */ 00127 u_char *community; 00129 size_t community_len; 00130 00131 /* 00132 * Trap information 00133 */ 00135 oid *enterprise; 00136 size_t enterprise_length; 00138 long trap_type; 00140 long specific_type; 00142 unsigned char agent_addr[4]; 00143 00144 /* 00145 * SNMPv3 fields 00146 */ 00148 u_char *contextEngineID; 00150 size_t contextEngineIDLen; 00152 char *contextName; 00154 size_t contextNameLen; 00156 u_char *securityEngineID; 00158 size_t securityEngineIDLen; 00160 char *securityName; 00162 size_t securityNameLen; 00163 00164 /* 00165 * AgentX fields 00166 * (also uses SNMPv1 community field) 00167 */ 00168 int priority; 00169 int range_subid; 00170 00171 void *securityStateRef; 00172 } netsnmp_pdu; 00173 00174 struct snmp_session; 00175 00178 typedef struct snmp_session netsnmp_session; 00179 00180 typedef int (*snmp_callback) (int, netsnmp_session *, int, 00181 netsnmp_pdu *, void *); 00182 typedef int (*netsnmp_callback) (int, netsnmp_session *, int, 00183 netsnmp_pdu *, void *); 00187 struct snmp_session { 00188 /* 00189 * Protocol-version independent fields 00190 */ 00192 long version; 00194 int retries; 00196 long timeout; 00197 u_long flags; 00198 struct snmp_session *subsession; 00199 struct snmp_session *next; 00200 00202 char *peername; 00204 u_short remote_port; 00206 char *localname; 00208 u_short local_port; 00212 u_char *(*authenticator) (u_char *, size_t *, u_char *, size_t); 00214 netsnmp_callback callback; 00218 void *callback_magic; 00220 int s_errno; 00222 int s_snmp_errno; 00224 long sessid; 00225 00226 /* 00227 * SNMPv1 & SNMPv2c fields 00228 */ 00230 u_char *community; 00232 size_t community_len; 00234 size_t rcvMsgMaxSize; 00236 size_t sndMsgMaxSize; 00237 00238 /* 00239 * SNMPv3 fields 00240 */ 00242 u_char isAuthoritative; 00244 u_char *contextEngineID; 00246 size_t contextEngineIDLen; 00248 u_int engineBoots; 00250 u_int engineTime; 00252 char *contextName; 00254 size_t contextNameLen; 00256 u_char *securityEngineID; 00258 size_t securityEngineIDLen; 00260 char *securityName; 00262 size_t securityNameLen; 00263 00265 oid *securityAuthProto; 00267 size_t securityAuthProtoLen; 00269 u_char securityAuthKey[USM_AUTH_KU_LEN]; 00271 size_t securityAuthKeyLen; 00273 u_char *securityAuthLocalKey; 00275 size_t securityAuthLocalKeyLen; 00276 00278 oid *securityPrivProto; 00280 size_t securityPrivProtoLen; 00282 u_char securityPrivKey[USM_PRIV_KU_LEN]; 00284 size_t securityPrivKeyLen; 00286 u_char *securityPrivLocalKey; 00288 size_t securityPrivLocalKeyLen; 00289 00291 int securityModel; 00293 int securityLevel; 00295 char *paramName; 00296 00300 void *securityInfo; 00301 00308 void *myvoid; 00309 }; 00310 00311 /* 00312 * A list of all the outstanding requests for a particular session. 00313 */ 00314 #ifdef SNMP_NEED_REQUEST_LIST 00315 typedef struct request_list { 00316 struct request_list *next_request; 00317 long request_id; /* request id */ 00318 long message_id; /* message id */ 00319 netsnmp_callback callback; /* user callback per request (NULL if unused) */ 00320 void *cb_data; /* user callback data per request (NULL if unused) */ 00321 int retries; /* Number of retries */ 00322 u_long timeout; /* length to wait for timeout */ 00323 struct timeval time; /* Time this request was made */ 00324 struct timeval expire; /* time this request is due to expire */ 00325 struct snmp_session *session; 00326 netsnmp_pdu *pdu; /* The pdu for this request 00327 * (saved so it can be retransmitted */ 00328 } netsnmp_request_list; 00329 #endif /* SNMP_NEED_REQUEST_LIST */ 00330 00331 /* 00332 * Set fields in session and pdu to the following to get a default or unconfigured value. 00333 */ 00334 #define SNMP_DEFAULT_COMMUNITY_LEN 0 /* to get a default community name */ 00335 #define SNMP_DEFAULT_RETRIES -1 00336 #define SNMP_DEFAULT_TIMEOUT -1 00337 #define SNMP_DEFAULT_REMPORT 0 00338 #define SNMP_DEFAULT_REQID -1 00339 #define SNMP_DEFAULT_MSGID -1 00340 #define SNMP_DEFAULT_ERRSTAT -1 00341 #define SNMP_DEFAULT_ERRINDEX -1 00342 #define SNMP_DEFAULT_ADDRESS 0 00343 #define SNMP_DEFAULT_PEERNAME NULL 00344 #define SNMP_DEFAULT_ENTERPRISE_LENGTH 0 00345 #define SNMP_DEFAULT_TIME 0 00346 #define SNMP_DEFAULT_VERSION -1 00347 #define SNMP_DEFAULT_SECMODEL -1 00348 #define SNMP_DEFAULT_CONTEXT "" 00349 #ifndef NETSNMP_DISABLE_MD5 00350 #define SNMP_DEFAULT_AUTH_PROTO usmHMACMD5AuthProtocol 00351 #else 00352 #define SNMP_DEFAULT_AUTH_PROTO usmHMACSHA1AuthProtocol 00353 #endif 00354 #define SNMP_DEFAULT_AUTH_PROTOLEN USM_LENGTH_OID_TRANSFORM 00355 #ifndef NETSNMP_DISABLE_DES 00356 #define SNMP_DEFAULT_PRIV_PROTO usmDESPrivProtocol 00357 #else 00358 #define SNMP_DEFAULT_PRIV_PROTO usmAESPrivProtocol 00359 #endif 00360 #define SNMP_DEFAULT_PRIV_PROTOLEN USM_LENGTH_OID_TRANSFORM 00361 00362 NETSNMP_IMPORT const char *snmp_api_errstring(int); 00363 NETSNMP_IMPORT void snmp_perror(const char *); 00364 NETSNMP_IMPORT void snmp_set_detail(const char *); 00365 00366 #define SNMP_MAX_MSG_SIZE 1472 /* ethernet MTU minus IP/UDP header */ 00367 #define SNMP_MAX_MSG_V3_HDRS (4+3+4+7+7+3+7+16) /* fudge factor=16 */ 00368 #define SNMP_MAX_ENG_SIZE 32 00369 #define SNMP_MAX_SEC_NAME_SIZE 256 00370 #define SNMP_MAX_CONTEXT_SIZE 256 00371 #define SNMP_SEC_PARAM_BUF_SIZE 256 00372 00373 /* 00374 * set to one to ignore unauthenticated Reports 00375 */ 00376 #define SNMPV3_IGNORE_UNAUTH_REPORTS 0 00377 00378 /* 00379 * authoritative engine definitions 00380 */ 00381 #define SNMP_SESS_NONAUTHORITATIVE 0 /* should be 0 to default to this */ 00382 #define SNMP_SESS_AUTHORITATIVE 1 /* don't learn engineIDs */ 00383 #define SNMP_SESS_UNKNOWNAUTH 2 /* sometimes (like NRs) */ 00384 00385 /* 00386 * to determine type of Report from varbind_list 00387 */ 00388 #define REPORT_STATS_LEN 9 00389 #define REPORT_snmpUnknownSecurityModels_NUM 1 00390 #define REPORT_snmpInvalidMsgs_NUM 2 00391 #define REPORT_usmStatsUnsupportedSecLevels_NUM 1 00392 #define REPORT_usmStatsNotInTimeWindows_NUM 2 00393 #define REPORT_usmStatsUnknownUserNames_NUM 3 00394 #define REPORT_usmStatsUnknownEngineIDs_NUM 4 00395 #define REPORT_usmStatsWrongDigests_NUM 5 00396 #define REPORT_usmStatsDecryptionErrors_NUM 6 00397 00398 #define SNMP_DETAIL_SIZE 512 00399 00400 #define SNMP_FLAGS_RESP_CALLBACK 0x400 /* Additional callback on response */ 00401 #define SNMP_FLAGS_USER_CREATED 0x200 /* USM user has been created */ 00402 #define SNMP_FLAGS_DONT_PROBE 0x100 /* don't probe for an engineID */ 00403 #define SNMP_FLAGS_STREAM_SOCKET 0x80 00404 #define SNMP_FLAGS_LISTENING 0x40 /* Server stream sockets only */ 00405 #define SNMP_FLAGS_SUBSESSION 0x20 00406 #define SNMP_FLAGS_STRIKE2 0x02 00407 #define SNMP_FLAGS_STRIKE1 0x01 00408 00409 #define CLEAR_SNMP_STRIKE_FLAGS(x) \ 00410 x &= ~(SNMP_FLAGS_STRIKE2|SNMP_FLAGS_STRIKE1) 00411 00412 /* 00413 * returns '1' if the session is to be regarded as dead, 00414 * otherwise set the strike flags appropriately, and return 0 00415 */ 00416 #define SET_SNMP_STRIKE_FLAGS(x) \ 00417 (( x & SNMP_FLAGS_STRIKE2 ) ? 1 : \ 00418 ((( x & SNMP_FLAGS_STRIKE1 ) ? ( x |= SNMP_FLAGS_STRIKE2 ) : \ 00419 ( x |= SNMP_FLAGS_STRIKE1 )), \ 00420 0)) 00421 00422 /* 00423 * Error return values. 00424 * 00425 * SNMPERR_SUCCESS is the non-PDU "success" code. 00426 * 00427 * XXX These should be merged with SNMP_ERR_* defines and confined 00428 * to values < 0. ??? 00429 */ 00430 #define SNMPERR_SUCCESS (0) /* XXX Non-PDU "success" code. */ 00431 #define SNMPERR_GENERR (-1) 00432 #define SNMPERR_BAD_LOCPORT (-2) 00433 #define SNMPERR_BAD_ADDRESS (-3) 00434 #define SNMPERR_BAD_SESSION (-4) 00435 #define SNMPERR_TOO_LONG (-5) 00436 #define SNMPERR_NO_SOCKET (-6) 00437 #define SNMPERR_V2_IN_V1 (-7) 00438 #define SNMPERR_V1_IN_V2 (-8) 00439 #define SNMPERR_BAD_REPEATERS (-9) 00440 #define SNMPERR_BAD_REPETITIONS (-10) 00441 #define SNMPERR_BAD_ASN1_BUILD (-11) 00442 #define SNMPERR_BAD_SENDTO (-12) 00443 #define SNMPERR_BAD_PARSE (-13) 00444 #define SNMPERR_BAD_VERSION (-14) 00445 #define SNMPERR_BAD_SRC_PARTY (-15) 00446 #define SNMPERR_BAD_DST_PARTY (-16) 00447 #define SNMPERR_BAD_CONTEXT (-17) 00448 #define SNMPERR_BAD_COMMUNITY (-18) 00449 #define SNMPERR_NOAUTH_DESPRIV (-19) 00450 #define SNMPERR_BAD_ACL (-20) 00451 #define SNMPERR_BAD_PARTY (-21) 00452 #define SNMPERR_ABORT (-22) 00453 #define SNMPERR_UNKNOWN_PDU (-23) 00454 #define SNMPERR_TIMEOUT (-24) 00455 #define SNMPERR_BAD_RECVFROM (-25) 00456 #define SNMPERR_BAD_ENG_ID (-26) 00457 #define SNMPERR_BAD_SEC_NAME (-27) 00458 #define SNMPERR_BAD_SEC_LEVEL (-28) 00459 #define SNMPERR_ASN_PARSE_ERR (-29) 00460 #define SNMPERR_UNKNOWN_SEC_MODEL (-30) 00461 #define SNMPERR_INVALID_MSG (-31) 00462 #define SNMPERR_UNKNOWN_ENG_ID (-32) 00463 #define SNMPERR_UNKNOWN_USER_NAME (-33) 00464 #define SNMPERR_UNSUPPORTED_SEC_LEVEL (-34) 00465 #define SNMPERR_AUTHENTICATION_FAILURE (-35) 00466 #define SNMPERR_NOT_IN_TIME_WINDOW (-36) 00467 #define SNMPERR_DECRYPTION_ERR (-37) 00468 #define SNMPERR_SC_GENERAL_FAILURE (-38) 00469 #define SNMPERR_SC_NOT_CONFIGURED (-39) 00470 #define SNMPERR_KT_NOT_AVAILABLE (-40) 00471 #define SNMPERR_UNKNOWN_REPORT (-41) 00472 #define SNMPERR_USM_GENERICERROR (-42) 00473 #define SNMPERR_USM_UNKNOWNSECURITYNAME (-43) 00474 #define SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL (-44) 00475 #define SNMPERR_USM_ENCRYPTIONERROR (-45) 00476 #define SNMPERR_USM_AUTHENTICATIONFAILURE (-46) 00477 #define SNMPERR_USM_PARSEERROR (-47) 00478 #define SNMPERR_USM_UNKNOWNENGINEID (-48) 00479 #define SNMPERR_USM_NOTINTIMEWINDOW (-49) 00480 #define SNMPERR_USM_DECRYPTIONERROR (-50) 00481 #define SNMPERR_NOMIB (-51) 00482 #define SNMPERR_RANGE (-52) 00483 #define SNMPERR_MAX_SUBID (-53) 00484 #define SNMPERR_BAD_SUBID (-54) 00485 #define SNMPERR_LONG_OID (-55) 00486 #define SNMPERR_BAD_NAME (-56) 00487 #define SNMPERR_VALUE (-57) 00488 #define SNMPERR_UNKNOWN_OBJID (-58) 00489 #define SNMPERR_NULL_PDU (-59) 00490 #define SNMPERR_NO_VARS (-60) 00491 #define SNMPERR_VAR_TYPE (-61) 00492 #define SNMPERR_MALLOC (-62) 00493 #define SNMPERR_KRB5 (-63) 00494 #define SNMPERR_PROTOCOL (-64) 00495 #define SNMPERR_OID_NONINCREASING (-65) 00496 00497 #define SNMPERR_MAX (-65) 00498 00499 #define non_repeaters errstat 00500 #define max_repetitions errindex 00501 00502 typedef union { 00503 long *integer; 00504 u_char *string; 00505 oid *objid; 00506 u_char *bitstring; 00507 struct counter64 *counter64; 00508 #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES 00509 float *floatVal; 00510 double *doubleVal; 00511 /* 00512 * t_union *unionVal; 00513 */ 00514 #endif /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */ 00515 } netsnmp_vardata; 00516 00517 00522 struct variable_list { 00524 struct variable_list *next_variable; 00526 oid *name; 00528 size_t name_length; 00530 u_char type; 00532 netsnmp_vardata val; 00534 size_t val_len; 00536 oid name_loc[MAX_OID_LEN]; 00538 u_char buf[40]; 00540 void *data; 00542 void (*dataFreeHook)(void *); 00543 int index; 00544 }; 00545 00546 00547 00548 /* 00549 * netsnmp_session *snmp_open(session) 00550 * netsnmp_session *session; 00551 * 00552 * Sets up the session with the snmp_session information provided 00553 * by the user. Then opens and binds the necessary UDP port. 00554 * A handle to the created session is returned (this is different than 00555 * the pointer passed to snmp_open()). On any error, NULL is returned 00556 * and snmp_errno is set to the appropriate error code. 00557 */ 00558 netsnmp_session *snmp_open(netsnmp_session *); 00559 00560 /* 00561 * int snmp_close(session) 00562 * netsnmp_session *session; 00563 * 00564 * Close the input session. Frees all data allocated for the session, 00565 * dequeues any pending requests, and closes any sockets allocated for 00566 * the session. Returns 0 on error, 1 otherwise. 00567 * 00568 * snmp_close_sessions() does the same thing for all open sessions 00569 */ 00570 int snmp_close(netsnmp_session *); 00571 int snmp_close_sessions(void); 00572 00573 00574 /* 00575 * int snmp_send(session, pdu) 00576 * netsnmp_session *session; 00577 * netsnmp_pdu *pdu; 00578 * 00579 * Sends the input pdu on the session after calling snmp_build to create 00580 * a serialized packet. If necessary, set some of the pdu data from the 00581 * session defaults. Add a request corresponding to this pdu to the list 00582 * of outstanding requests on this session, then send the pdu. 00583 * Returns the request id of the generated packet if applicable, otherwise 1. 00584 * On any error, 0 is returned. 00585 * The pdu is freed by snmp_send() unless a failure occured. 00586 */ 00587 int snmp_send(netsnmp_session *, netsnmp_pdu *); 00588 00589 /* 00590 * int snmp_async_send(session, pdu, callback, cb_data) 00591 * netsnmp_session *session; 00592 * netsnmp_pdu *pdu; 00593 * netsnmp_callback callback; 00594 * void *cb_data; 00595 * 00596 * Sends the input pdu on the session after calling snmp_build to create 00597 * a serialized packet. If necessary, set some of the pdu data from the 00598 * session defaults. Add a request corresponding to this pdu to the list 00599 * of outstanding requests on this session and store callback and data, 00600 * then send the pdu. 00601 * Returns the request id of the generated packet if applicable, otherwise 1. 00602 * On any error, 0 is returned. 00603 * The pdu is freed by snmp_send() unless a failure occured. 00604 */ 00605 int snmp_async_send(netsnmp_session *, netsnmp_pdu *, 00606 netsnmp_callback, void *); 00607 00608 00609 /* 00610 * void snmp_read(fdset) 00611 * fd_set *fdset; 00612 * 00613 * Checks to see if any of the fd's set in the fdset belong to 00614 * snmp. Each socket with it's fd set has a packet read from it 00615 * and snmp_parse is called on the packet received. The resulting pdu 00616 * is passed to the callback routine for that session. If the callback 00617 * routine returns successfully, the pdu and it's request are deleted. 00618 */ 00619 void snmp_read(fd_set *); 00620 00621 00622 00623 /* 00624 * void 00625 * snmp_free_pdu(pdu) 00626 * netsnmp_pdu *pdu; 00627 * 00628 * Frees the pdu and any malloc'd data associated with it. 00629 */ 00630 void snmp_free_pdu(netsnmp_pdu *); 00631 00632 void snmp_free_var(netsnmp_variable_list *); /* frees just this one */ 00633 00634 void snmp_free_varbind(netsnmp_variable_list * var); /* frees all in list */ 00635 00636 /* 00637 * int snmp_select_info(numfds, fdset, timeout, block) 00638 * int *numfds; 00639 * fd_set *fdset; 00640 * struct timeval *timeout; 00641 * int *block; 00642 * 00643 * Returns info about what snmp requires from a select statement. 00644 * numfds is the number of fds in the list that are significant. 00645 * All file descriptors opened for SNMP are OR'd into the fdset. 00646 * If activity occurs on any of these file descriptors, snmp_read 00647 * should be called with that file descriptor set. 00648 * 00649 * The timeout is the latest time that SNMP can wait for a timeout. The 00650 * select should be done with the minimum time between timeout and any other 00651 * timeouts necessary. This should be checked upon each invocation of select. 00652 * If a timeout is received, snmp_timeout should be called to check if the 00653 * timeout was for SNMP. (snmp_timeout is idempotent) 00654 * 00655 * Block is 1 if the select is requested to block indefinitely, rather than 00656 * time out. If block is input as 1, the timeout value will be treated as 00657 * undefined, but it must be available for setting in snmp_select_info. On 00658 * return, if block is true, the value of timeout will be undefined. 00659 * 00660 * snmp_select_info returns the number of open sockets. (i.e. The number 00661 * of sessions open) 00662 */ 00663 int snmp_select_info(int *, fd_set *, struct timeval *, 00664 int *); 00665 00666 00667 00668 /* 00669 * void snmp_timeout(); 00670 * 00671 * snmp_timeout should be called whenever the timeout from snmp_select_info 00672 * expires, but it is idempotent, so snmp_timeout can be polled (probably a 00673 * cpu expensive proposition). snmp_timeout checks to see if any of the 00674 * sessions have an outstanding request that has timed out. If it finds one 00675 * (or more), and that pdu has more retries available, a new packet is formed 00676 * from the pdu and is resent. If there are no more retries available, the 00677 * callback for the session is used to alert the user of the timeout. 00678 */ 00679 00680 void snmp_timeout(void); 00681 00682 00683 /* 00684 * This routine must be supplied by the application: 00685 * 00686 * u_char *authenticator(pdu, length, community, community_len) 00687 * u_char *pdu; The rest of the PDU to be authenticated 00688 * int *length; The length of the PDU (updated by the authenticator) 00689 * u_char *community; The community name to authenticate under. 00690 * int community_len The length of the community name. 00691 * 00692 * Returns the authenticated pdu, or NULL if authentication failed. 00693 * If null authentication is used, the authenticator in snmp_session can be 00694 * set to NULL(0). 00695 */ 00696 00697 00698 00699 /* 00700 * This routine must be supplied by the application: 00701 * 00702 * int callback(operation, session, reqid, pdu, magic) 00703 * int operation; 00704 * netsnmp_session *session; The session authenticated under. 00705 * int reqid; The request id of this pdu (0 for TRAP) 00706 * netsnmp_pdu *pdu; The pdu information. 00707 * void *magic A link to the data for this routine. 00708 * 00709 * Returns 1 if request was successful, 0 if it should be kept pending. 00710 * Any data in the pdu must be copied because it will be freed elsewhere. 00711 * Operations are defined below: 00712 */ 00713 00714 #define NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE 1 00715 #define NETSNMP_CALLBACK_OP_TIMED_OUT 2 00716 #define NETSNMP_CALLBACK_OP_SEND_FAILED 3 00717 #define NETSNMP_CALLBACK_OP_CONNECT 4 00718 #define NETSNMP_CALLBACK_OP_DISCONNECT 5 00719 00720 long snmp_get_next_msgid(void); 00721 long snmp_get_next_reqid(void); 00722 long snmp_get_next_sessid(void); 00723 long snmp_get_next_transid(void); 00724 00725 int snmp_oid_compare(const oid *, size_t, const oid *, 00726 size_t); 00727 int snmp_oid_ncompare(const oid *, size_t, const oid *, 00728 size_t, size_t); 00729 int snmp_oidtree_compare(const oid *, size_t, const oid *, 00730 size_t); 00731 int snmp_oidsubtree_compare(const oid *, size_t, const oid *, 00732 size_t); 00733 int netsnmp_oid_compare_ll(const oid * in_name1, 00734 size_t len1, const oid * in_name2, 00735 size_t len2, size_t *offpt); 00736 int netsnmp_oid_equals(const oid *, size_t, const oid *, 00737 size_t); 00738 int netsnmp_oid_tree_equals(const oid *, size_t, const oid *, 00739 size_t); 00740 int netsnmp_oid_is_subtree(const oid *, size_t, const oid *, 00741 size_t); 00742 int netsnmp_oid_find_prefix(const oid * in_name1, size_t len1, 00743 const oid * in_name2, size_t len2); 00744 void init_snmp(const char *); 00745 u_char *snmp_pdu_build(netsnmp_pdu *, u_char *, size_t *); 00746 #ifdef NETSNMP_USE_REVERSE_ASNENCODING 00747 u_char *snmp_pdu_rbuild(netsnmp_pdu *, u_char *, size_t *); 00748 #endif 00749 int snmpv3_parse(netsnmp_pdu *, u_char *, size_t *, 00750 u_char **, netsnmp_session *); 00751 int snmpv3_packet_build(netsnmp_session *, 00752 netsnmp_pdu *pdu, u_char * packet, 00753 size_t * out_length, 00754 u_char * pdu_data, 00755 size_t pdu_data_len); 00756 int snmpv3_packet_rbuild(netsnmp_session *, 00757 netsnmp_pdu *pdu, u_char * packet, 00758 size_t * out_length, 00759 u_char * pdu_data, 00760 size_t pdu_data_len); 00761 int snmpv3_make_report(netsnmp_pdu *pdu, int error); 00762 int snmpv3_get_report_type(netsnmp_pdu *pdu); 00763 int snmp_pdu_parse(netsnmp_pdu *pdu, u_char * data, 00764 size_t * length); 00765 u_char *snmpv3_scopedPDU_parse(netsnmp_pdu *pdu, u_char * cp, 00766 size_t * length); 00767 void snmp_store(const char *type); 00768 void snmp_shutdown(const char *type); 00769 netsnmp_variable_list *snmp_pdu_add_variable(netsnmp_pdu *, const oid *, 00770 size_t, u_char, const u_char *, 00771 size_t); 00772 netsnmp_variable_list *snmp_varlist_add_variable(netsnmp_variable_list 00773 ** varlist, 00774 const oid * name, 00775 size_t name_length, 00776 u_char type, 00777 const u_char * value, 00778 size_t len); 00779 int snmp_add_var(netsnmp_pdu *, const oid *, size_t, char, 00780 const char *); 00781 oid *snmp_duplicate_objid(const oid * objToCopy, size_t); 00782 u_int snmp_increment_statistic(int which); 00783 u_int snmp_increment_statistic_by(int which, int count); 00784 u_int snmp_get_statistic(int which); 00785 void snmp_init_statistics(void); 00786 int create_user_from_session(netsnmp_session * session); 00787 int snmp_get_fd_for_session(struct snmp_session *sessp); 00788 00789 /* 00790 * New re-allocating reverse encoding functions. 00791 */ 00792 #ifdef NETSNMP_USE_REVERSE_ASNENCODING 00793 00794 int snmpv3_packet_realloc_rbuild(u_char ** pkt, size_t * pkt_len, 00795 size_t * offset, 00796 netsnmp_session * session, 00797 netsnmp_pdu *pdu, u_char * pdu_data, 00798 size_t pdu_data_len); 00799 00800 int snmp_pdu_realloc_rbuild(u_char ** pkt, size_t * pkt_len, 00801 size_t * offset, netsnmp_pdu *pdu); 00802 #endif 00803 00804 00805 00806 /* 00807 * Extended open; fpre_parse has changed. 00808 */ 00809 00810 netsnmp_session *snmp_open_ex(netsnmp_session *, 00811 int (*fpre_parse) (netsnmp_session *, 00812 struct 00813 netsnmp_transport_s *, 00814 void *, int), 00815 int (*fparse) (netsnmp_session *, 00816 netsnmp_pdu *, u_char *, 00817 size_t), 00818 int (*fpost_parse) (netsnmp_session *, 00819 netsnmp_pdu *, int), 00820 int (*fbuild) (netsnmp_session *, 00821 netsnmp_pdu *, u_char *, 00822 size_t *), 00823 int (*frbuild) (netsnmp_session *, 00824 netsnmp_pdu *, u_char **, 00825 size_t *, size_t *), 00826 int (*fcheck) (u_char *, size_t)); 00827 00828 /* 00829 * provided for backwards compatability. Don't use these functions. 00830 * See snmp_debug.h and snmp_debug.c instead. 00831 */ 00832 00833 void snmp_set_do_debugging(int); 00834 int snmp_get_do_debugging(void); 00835 00836 00837 /* 00838 * snmp_error - return error data 00839 * Inputs : address of errno, address of snmp_errno, address of string 00840 * Caller must free the string returned after use. 00841 */ 00842 void snmp_error(netsnmp_session *, int *, int *, char **); 00843 /* 00844 * single session API. 00845 * 00846 * These functions perform similar actions as snmp_XX functions, 00847 * but operate on a single session only. 00848 * 00849 * Synopsis: 00850 00851 void * sessp; 00852 netsnmp_session session, *ss; 00853 netsnmp_pdu *pdu, *response; 00854 00855 snmp_sess_init(&session); 00856 session.retries = ... 00857 session.remote_port = ... 00858 sessp = snmp_sess_open(&session); 00859 ss = snmp_sess_session(sessp); 00860 if (ss == NULL) 00861 exit(1); 00862 ... 00863 if (ss->community) free(ss->community); 00864 ss->community = strdup(gateway); 00865 ss->community_len = strlen(gateway); 00866 ... 00867 snmp_sess_synch_response(sessp, pdu, &response); 00868 ... 00869 snmp_sess_close(sessp); 00870 00871 * See also: 00872 * snmp_sess_synch_response, in snmp_client.h. 00873 00874 * Notes: 00875 * 1. Invoke snmp_sess_session after snmp_sess_open. 00876 * 2. snmp_sess_session return value is an opaque pointer. 00877 * 3. Do NOT free memory returned by snmp_sess_session. 00878 * 4. Replace snmp_send(ss,pdu) with snmp_sess_send(sessp,pdu) 00879 */ 00880 00881 void snmp_sess_init(netsnmp_session *); 00882 void *snmp_sess_open(netsnmp_session *); 00883 void *snmp_sess_pointer(netsnmp_session *); 00884 netsnmp_session *snmp_sess_session(void *); 00885 00886 /* 00887 * Return the netsnmp_transport structure associated with the given opaque 00888 * pointer. 00889 */ 00890 00891 struct netsnmp_transport_s *snmp_sess_transport(void *); 00892 void snmp_sess_transport_set(void *, 00893 struct netsnmp_transport_s *); 00894 00895 /* 00896 * EXPERIMENTAL API EXTENSIONS ------------------------------------------ 00897 * 00898 * snmp_sess_add_ex, snmp_sess_add, snmp_add 00899 * 00900 * Analogous to snmp_open family of functions, but taking an 00901 * netsnmp_transport pointer as an extra argument. Unlike snmp_open et 00902 * al. it doesn't attempt to interpret the in_session->peername as a 00903 * transport endpoint specifier, but instead uses the supplied transport. 00904 * JBPN 00905 * 00906 */ 00907 00908 void *snmp_sess_add_ex(netsnmp_session *, 00909 struct netsnmp_transport_s *, 00910 int (*fpre_parse) (netsnmp_session *, 00911 struct 00912 netsnmp_transport_s 00913 *, void *, int), 00914 int (*fparse) (netsnmp_session *, 00915 struct snmp_pdu *, 00916 u_char *, size_t), 00917 int (*fpost_parse) (netsnmp_session *, 00918 struct snmp_pdu *, 00919 int), 00920 int (*fbuild) (netsnmp_session *, 00921 struct snmp_pdu *, 00922 u_char *, size_t *), 00923 int (*frbuild) (netsnmp_session *, 00924 struct snmp_pdu *, 00925 u_char **, size_t *, 00926 size_t *), 00927 int (*fcheck) (u_char *, size_t), 00928 netsnmp_pdu *(*fcreate_pdu) (struct 00929 netsnmp_transport_s 00930 *, 00931 void *, 00932 size_t)); 00933 00934 void *snmp_sess_add(netsnmp_session *, 00935 struct netsnmp_transport_s *, 00936 int (*fpre_parse) (netsnmp_session *, 00937 struct 00938 netsnmp_transport_s *, 00939 void *, int), 00940 int (*fpost_parse) (netsnmp_session *, 00941 netsnmp_pdu *, int)); 00942 00943 netsnmp_session *snmp_add(netsnmp_session *, 00944 struct netsnmp_transport_s *, 00945 int (*fpre_parse) (netsnmp_session *, 00946 struct netsnmp_transport_s 00947 *, void *, int), 00948 int (*fpost_parse) (netsnmp_session *, 00949 netsnmp_pdu *, int)); 00950 netsnmp_session *snmp_add_full(netsnmp_session * in_session, 00951 struct netsnmp_transport_s *transport, 00952 int (*fpre_parse) (netsnmp_session *, 00953 struct 00954 netsnmp_transport_s 00955 *, void *, int), 00956 int (*fparse) (netsnmp_session *, 00957 netsnmp_pdu *, u_char *, 00958 size_t), 00959 int (*fpost_parse) (netsnmp_session *, 00960 netsnmp_pdu *, int), 00961 int (*fbuild) (netsnmp_session *, 00962 netsnmp_pdu *, u_char *, 00963 size_t *), 00964 int (*frbuild) (netsnmp_session *, 00965 netsnmp_pdu *, 00966 u_char **, size_t *, 00967 size_t *), 00968 int (*fcheck) (u_char *, size_t), 00969 netsnmp_pdu *(*fcreate_pdu) (struct 00970 netsnmp_transport_s 00971 *, void *, 00972 size_t) 00973 ); 00974 00975 /* 00976 * use return value from snmp_sess_open as void * parameter 00977 */ 00978 00979 int snmp_sess_send(void *, netsnmp_pdu *); 00980 int snmp_sess_async_send(void *, netsnmp_pdu *, 00981 netsnmp_callback, void *); 00982 int snmp_sess_select_info(void *, int *, fd_set *, 00983 struct timeval *, int *); 00984 int snmp_sess_read(void *, fd_set *); 00985 void snmp_sess_timeout(void *); 00986 int snmp_sess_close(void *); 00987 00988 void snmp_sess_error(void *, int *, int *, char **); 00989 void netsnmp_sess_log_error(int priority, 00990 const char *prog_string, 00991 netsnmp_session * ss); 00992 void snmp_sess_perror(const char *prog_string, 00993 netsnmp_session * ss); 00994 const char * snmp_pdu_type(int type); 00995 00996 /* 00997 * end single session API 00998 */ 00999 01000 /* 01001 * generic statistic counters 01002 */ 01003 01004 /* 01005 * snmpv3 statistics 01006 */ 01007 01008 /* 01009 * mpd stats 01010 */ 01011 #define STAT_SNMPUNKNOWNSECURITYMODELS 0 01012 #define STAT_SNMPINVALIDMSGS 1 01013 #define STAT_SNMPUNKNOWNPDUHANDLERS 2 01014 #define STAT_MPD_STATS_START STAT_SNMPUNKNOWNSECURITYMODELS 01015 #define STAT_MPD_STATS_END STAT_SNMPUNKNOWNPDUHANDLERS 01016 01017 /* 01018 * usm stats 01019 */ 01020 #define STAT_USMSTATSUNSUPPORTEDSECLEVELS 3 01021 #define STAT_USMSTATSNOTINTIMEWINDOWS 4 01022 #define STAT_USMSTATSUNKNOWNUSERNAMES 5 01023 #define STAT_USMSTATSUNKNOWNENGINEIDS 6 01024 #define STAT_USMSTATSWRONGDIGESTS 7 01025 #define STAT_USMSTATSDECRYPTIONERRORS 8 01026 #define STAT_USM_STATS_START STAT_USMSTATSUNSUPPORTEDSECLEVELS 01027 #define STAT_USM_STATS_END STAT_USMSTATSDECRYPTIONERRORS 01028 01029 /* 01030 * snmp counters 01031 */ 01032 #define STAT_SNMPINPKTS 9 01033 #define STAT_SNMPOUTPKTS 10 01034 #define STAT_SNMPINBADVERSIONS 11 01035 #define STAT_SNMPINBADCOMMUNITYNAMES 12 01036 #define STAT_SNMPINBADCOMMUNITYUSES 13 01037 #define STAT_SNMPINASNPARSEERRS 14 01038 /* 01039 * #define STAT_SNMPINBADTYPES 15 01040 */ 01041 #define STAT_SNMPINTOOBIGS 16 01042 #define STAT_SNMPINNOSUCHNAMES 17 01043 #define STAT_SNMPINBADVALUES 18 01044 #define STAT_SNMPINREADONLYS 19 01045 #define STAT_SNMPINGENERRS 20 01046 #define STAT_SNMPINTOTALREQVARS 21 01047 #define STAT_SNMPINTOTALSETVARS 22 01048 #define STAT_SNMPINGETREQUESTS 23 01049 #define STAT_SNMPINGETNEXTS 24 01050 #define STAT_SNMPINSETREQUESTS 25 01051 #define STAT_SNMPINGETRESPONSES 26 01052 #define STAT_SNMPINTRAPS 27 01053 #define STAT_SNMPOUTTOOBIGS 28 01054 #define STAT_SNMPOUTNOSUCHNAMES 29 01055 #define STAT_SNMPOUTBADVALUES 30 01056 /* 01057 * #define STAT_SNMPOUTREADONLYS 31 01058 */ 01059 #define STAT_SNMPOUTGENERRS 32 01060 #define STAT_SNMPOUTGETREQUESTS 33 01061 #define STAT_SNMPOUTGETNEXTS 34 01062 #define STAT_SNMPOUTSETREQUESTS 35 01063 #define STAT_SNMPOUTGETRESPONSES 36 01064 #define STAT_SNMPOUTTRAPS 37 01065 /* 01066 * AUTHTRAPENABLE 38 01067 */ 01068 #define STAT_SNMPSILENTDROPS 39 01069 #define STAT_SNMPPROXYDROPS 40 01070 #define STAT_SNMP_STATS_START STAT_SNMPINPKTS 01071 #define STAT_SNMP_STATS_END STAT_SNMPPROXYDROPS 01072 01073 /* 01074 * target mib counters 01075 */ 01076 #define STAT_SNMPUNAVAILABLECONTEXTS 41 01077 #define STAT_SNMPUNKNOWNCONTEXTS 42 01078 #define STAT_TARGET_STATS_START STAT_SNMPUNAVAILABLECONTEXTS 01079 #define STAT_TARGET_STATS_END STAT_SNMPUNKNOWNCONTEXTS 01080 01081 #define MAX_STATS 43 01082 01083 #ifdef __cplusplus 01084 } 01085 #endif 01086 #endif /* SNMP_API_H */
1.7.6.1