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 00305 void *myvoid; 00306 }; 00307 00308 /* 00309 * A list of all the outstanding requests for a particular session. 00310 */ 00311 #ifdef SNMP_NEED_REQUEST_LIST 00312 typedef struct request_list { 00313 struct request_list *next_request; 00314 long request_id; /* request id */ 00315 long message_id; /* message id */ 00316 netsnmp_callback callback; /* user callback per request (NULL if unused) */ 00317 void *cb_data; /* user callback data per request (NULL if unused) */ 00318 int retries; /* Number of retries */ 00319 u_long timeout; /* length to wait for timeout */ 00320 struct timeval time; /* Time this request was made */ 00321 struct timeval expire; /* time this request is due to expire */ 00322 struct snmp_session *session; 00323 netsnmp_pdu *pdu; /* The pdu for this request 00324 * (saved so it can be retransmitted */ 00325 } netsnmp_request_list; 00326 #endif /* SNMP_NEED_REQUEST_LIST */ 00327 00328 /* 00329 * Set fields in session and pdu to the following to get a default or unconfigured value. 00330 */ 00331 #define SNMP_DEFAULT_COMMUNITY_LEN 0 /* to get a default community name */ 00332 #define SNMP_DEFAULT_RETRIES -1 00333 #define SNMP_DEFAULT_TIMEOUT -1 00334 #define SNMP_DEFAULT_REMPORT 0 00335 #define SNMP_DEFAULT_REQID -1 00336 #define SNMP_DEFAULT_MSGID -1 00337 #define SNMP_DEFAULT_ERRSTAT -1 00338 #define SNMP_DEFAULT_ERRINDEX -1 00339 #define SNMP_DEFAULT_ADDRESS 0 00340 #define SNMP_DEFAULT_PEERNAME NULL 00341 #define SNMP_DEFAULT_ENTERPRISE_LENGTH 0 00342 #define SNMP_DEFAULT_TIME 0 00343 #define SNMP_DEFAULT_VERSION -1 00344 #define SNMP_DEFAULT_SECMODEL -1 00345 #define SNMP_DEFAULT_CONTEXT "" 00346 #ifndef DISABLE_MD5 00347 #define SNMP_DEFAULT_AUTH_PROTO usmHMACMD5AuthProtocol 00348 #else 00349 #define SNMP_DEFAULT_AUTH_PROTO usmHMACSHA1AuthProtocol 00350 #endif 00351 #define SNMP_DEFAULT_AUTH_PROTOLEN USM_LENGTH_OID_TRANSFORM 00352 #ifndef DISABLE_DES 00353 #define SNMP_DEFAULT_PRIV_PROTO usmDESPrivProtocol 00354 #else 00355 #define SNMP_DEFAULT_PRIV_PROTO usmAESPrivProtocol 00356 #endif 00357 #define SNMP_DEFAULT_PRIV_PROTOLEN USM_LENGTH_OID_TRANSFORM 00358 00359 extern const char *snmp_api_errstring(int); 00360 extern void snmp_perror(const char *); 00361 extern void snmp_set_detail(const char *); 00362 00363 #define SNMP_MAX_MSG_SIZE 1472 /* ethernet MTU minus IP/UDP header */ 00364 #define SNMP_MAX_MSG_V3_HDRS (4+3+4+7+7+3+7+16) /* fudge factor=16 */ 00365 #define SNMP_MAX_ENG_SIZE 32 00366 #define SNMP_MAX_SEC_NAME_SIZE 256 00367 #define SNMP_MAX_CONTEXT_SIZE 256 00368 #define SNMP_SEC_PARAM_BUF_SIZE 256 00369 00370 /* 00371 * set to one to ignore unauthenticated Reports 00372 */ 00373 #define SNMPV3_IGNORE_UNAUTH_REPORTS 0 00374 00375 /* 00376 * authoritative engine definitions 00377 */ 00378 #define SNMP_SESS_NONAUTHORITATIVE 0 /* should be 0 to default to this */ 00379 #define SNMP_SESS_AUTHORITATIVE 1 /* don't learn engineIDs */ 00380 #define SNMP_SESS_UNKNOWNAUTH 2 /* sometimes (like NRs) */ 00381 00382 /* 00383 * to determine type of Report from varbind_list 00384 */ 00385 #define REPORT_STATS_LEN 9 00386 #define REPORT_snmpUnknownSecurityModels_NUM 1 00387 #define REPORT_snmpInvalidMsgs_NUM 2 00388 #define REPORT_usmStatsUnsupportedSecLevels_NUM 1 00389 #define REPORT_usmStatsNotInTimeWindows_NUM 2 00390 #define REPORT_usmStatsUnknownUserNames_NUM 3 00391 #define REPORT_usmStatsUnknownEngineIDs_NUM 4 00392 #define REPORT_usmStatsWrongDigests_NUM 5 00393 #define REPORT_usmStatsDecryptionErrors_NUM 6 00394 00395 #define SNMP_DETAIL_SIZE 512 00396 00397 #define SNMP_FLAGS_USER_CREATED 0x200 /* USM user has been created */ 00398 #define SNMP_FLAGS_DONT_PROBE 0x100 /* don't probe for an engineID */ 00399 #define SNMP_FLAGS_STREAM_SOCKET 0x80 00400 #define SNMP_FLAGS_LISTENING 0x40 /* Server stream sockets only */ 00401 #define SNMP_FLAGS_SUBSESSION 0x20 00402 #define SNMP_FLAGS_STRIKE2 0x02 00403 #define SNMP_FLAGS_STRIKE1 0x01 00404 00405 #define CLEAR_SNMP_STRIKE_FLAGS(x) \ 00406 x &= ~(SNMP_FLAGS_STRIKE2|SNMP_FLAGS_STRIKE1) 00407 00408 /* 00409 * returns '1' if the session is to be regarded as dead, 00410 * otherwise set the strike flags appropriately, and return 0 00411 */ 00412 #define SET_SNMP_STRIKE_FLAGS(x) \ 00413 (( x & SNMP_FLAGS_STRIKE2 ) ? 1 : \ 00414 ((( x & SNMP_FLAGS_STRIKE1 ) ? ( x |= SNMP_FLAGS_STRIKE2 ) : \ 00415 ( x |= SNMP_FLAGS_STRIKE1 )), \ 00416 0)) 00417 00418 /* 00419 * Error return values. 00420 * 00421 * SNMPERR_SUCCESS is the non-PDU "success" code. 00422 * 00423 * XXX These should be merged with SNMP_ERR_* defines and confined 00424 * to values < 0. ??? 00425 */ 00426 #define SNMPERR_SUCCESS (0) /* XXX Non-PDU "success" code. */ 00427 #define SNMPERR_GENERR (-1) 00428 #define SNMPERR_BAD_LOCPORT (-2) 00429 #define SNMPERR_BAD_ADDRESS (-3) 00430 #define SNMPERR_BAD_SESSION (-4) 00431 #define SNMPERR_TOO_LONG (-5) 00432 #define SNMPERR_NO_SOCKET (-6) 00433 #define SNMPERR_V2_IN_V1 (-7) 00434 #define SNMPERR_V1_IN_V2 (-8) 00435 #define SNMPERR_BAD_REPEATERS (-9) 00436 #define SNMPERR_BAD_REPETITIONS (-10) 00437 #define SNMPERR_BAD_ASN1_BUILD (-11) 00438 #define SNMPERR_BAD_SENDTO (-12) 00439 #define SNMPERR_BAD_PARSE (-13) 00440 #define SNMPERR_BAD_VERSION (-14) 00441 #define SNMPERR_BAD_SRC_PARTY (-15) 00442 #define SNMPERR_BAD_DST_PARTY (-16) 00443 #define SNMPERR_BAD_CONTEXT (-17) 00444 #define SNMPERR_BAD_COMMUNITY (-18) 00445 #define SNMPERR_NOAUTH_DESPRIV (-19) 00446 #define SNMPERR_BAD_ACL (-20) 00447 #define SNMPERR_BAD_PARTY (-21) 00448 #define SNMPERR_ABORT (-22) 00449 #define SNMPERR_UNKNOWN_PDU (-23) 00450 #define SNMPERR_TIMEOUT (-24) 00451 #define SNMPERR_BAD_RECVFROM (-25) 00452 #define SNMPERR_BAD_ENG_ID (-26) 00453 #define SNMPERR_BAD_SEC_NAME (-27) 00454 #define SNMPERR_BAD_SEC_LEVEL (-28) 00455 #define SNMPERR_ASN_PARSE_ERR (-29) 00456 #define SNMPERR_UNKNOWN_SEC_MODEL (-30) 00457 #define SNMPERR_INVALID_MSG (-31) 00458 #define SNMPERR_UNKNOWN_ENG_ID (-32) 00459 #define SNMPERR_UNKNOWN_USER_NAME (-33) 00460 #define SNMPERR_UNSUPPORTED_SEC_LEVEL (-34) 00461 #define SNMPERR_AUTHENTICATION_FAILURE (-35) 00462 #define SNMPERR_NOT_IN_TIME_WINDOW (-36) 00463 #define SNMPERR_DECRYPTION_ERR (-37) 00464 #define SNMPERR_SC_GENERAL_FAILURE (-38) 00465 #define SNMPERR_SC_NOT_CONFIGURED (-39) 00466 #define SNMPERR_KT_NOT_AVAILABLE (-40) 00467 #define SNMPERR_UNKNOWN_REPORT (-41) 00468 #define SNMPERR_USM_GENERICERROR (-42) 00469 #define SNMPERR_USM_UNKNOWNSECURITYNAME (-43) 00470 #define SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL (-44) 00471 #define SNMPERR_USM_ENCRYPTIONERROR (-45) 00472 #define SNMPERR_USM_AUTHENTICATIONFAILURE (-46) 00473 #define SNMPERR_USM_PARSEERROR (-47) 00474 #define SNMPERR_USM_UNKNOWNENGINEID (-48) 00475 #define SNMPERR_USM_NOTINTIMEWINDOW (-49) 00476 #define SNMPERR_USM_DECRYPTIONERROR (-50) 00477 #define SNMPERR_NOMIB (-51) 00478 #define SNMPERR_RANGE (-52) 00479 #define SNMPERR_MAX_SUBID (-53) 00480 #define SNMPERR_BAD_SUBID (-54) 00481 #define SNMPERR_LONG_OID (-55) 00482 #define SNMPERR_BAD_NAME (-56) 00483 #define SNMPERR_VALUE (-57) 00484 #define SNMPERR_UNKNOWN_OBJID (-58) 00485 #define SNMPERR_NULL_PDU (-59) 00486 #define SNMPERR_NO_VARS (-60) 00487 #define SNMPERR_VAR_TYPE (-61) 00488 #define SNMPERR_MALLOC (-62) 00489 #define SNMPERR_KRB5 (-63) 00490 #define SNMPERR_PROTOCOL (-64) 00491 00492 #define SNMPERR_MAX (-64) 00493 00494 #define non_repeaters errstat 00495 #define max_repetitions errindex 00496 00497 typedef union { 00498 long *integer; 00499 u_char *string; 00500 oid *objid; 00501 u_char *bitstring; 00502 struct counter64 *counter64; 00503 #ifdef OPAQUE_SPECIAL_TYPES 00504 float *floatVal; 00505 double *doubleVal; 00506 /* 00507 * t_union *unionVal; 00508 */ 00509 #endif /* OPAQUE_SPECIAL_TYPES */ 00510 } netsnmp_vardata; 00511 00512 00517 struct variable_list { 00519 struct variable_list *next_variable; 00521 oid *name; 00523 size_t name_length; 00525 u_char type; 00527 netsnmp_vardata val; 00529 size_t val_len; 00531 oid name_loc[MAX_OID_LEN]; 00533 u_char buf[40]; 00535 void *data; 00537 void (*dataFreeHook)(void *); 00538 int index; 00539 }; 00540 00541 00542 00543 /* 00544 * netsnmp_session *snmp_open(session) 00545 * netsnmp_session *session; 00546 * 00547 * Sets up the session with the snmp_session information provided 00548 * by the user. Then opens and binds the necessary UDP port. 00549 * A handle to the created session is returned (this is different than 00550 * the pointer passed to snmp_open()). On any error, NULL is returned 00551 * and snmp_errno is set to the appropriate error code. 00552 */ 00553 netsnmp_session *snmp_open(netsnmp_session *); 00554 00555 /* 00556 * int snmp_close(session) 00557 * netsnmp_session *session; 00558 * 00559 * Close the input session. Frees all data allocated for the session, 00560 * dequeues any pending requests, and closes any sockets allocated for 00561 * the session. Returns 0 on error, 1 otherwise. 00562 * 00563 * snmp_close_sessions() does the same thing for all open sessions 00564 */ 00565 int snmp_close(netsnmp_session *); 00566 int snmp_close_sessions(void); 00567 00568 00569 /* 00570 * int snmp_send(session, pdu) 00571 * netsnmp_session *session; 00572 * netsnmp_pdu *pdu; 00573 * 00574 * Sends the input pdu on the session after calling snmp_build to create 00575 * a serialized packet. If necessary, set some of the pdu data from the 00576 * session defaults. Add a request corresponding to this pdu to the list 00577 * of outstanding requests on this session, then send the pdu. 00578 * Returns the request id of the generated packet if applicable, otherwise 1. 00579 * On any error, 0 is returned. 00580 * The pdu is freed by snmp_send() unless a failure occured. 00581 */ 00582 int snmp_send(netsnmp_session *, netsnmp_pdu *); 00583 00584 /* 00585 * int snmp_async_send(session, pdu, callback, cb_data) 00586 * netsnmp_session *session; 00587 * netsnmp_pdu *pdu; 00588 * netsnmp_callback callback; 00589 * void *cb_data; 00590 * 00591 * Sends the input pdu on the session after calling snmp_build to create 00592 * a serialized packet. If necessary, set some of the pdu data from the 00593 * session defaults. Add a request corresponding to this pdu to the list 00594 * of outstanding requests on this session and store callback and data, 00595 * then send the pdu. 00596 * Returns the request id of the generated packet if applicable, otherwise 1. 00597 * On any error, 0 is returned. 00598 * The pdu is freed by snmp_send() unless a failure occured. 00599 */ 00600 int snmp_async_send(netsnmp_session *, netsnmp_pdu *, 00601 netsnmp_callback, void *); 00602 00603 00604 /* 00605 * void snmp_read(fdset) 00606 * fd_set *fdset; 00607 * 00608 * Checks to see if any of the fd's set in the fdset belong to 00609 * snmp. Each socket with it's fd set has a packet read from it 00610 * and snmp_parse is called on the packet received. The resulting pdu 00611 * is passed to the callback routine for that session. If the callback 00612 * routine returns successfully, the pdu and it's request are deleted. 00613 */ 00614 void snmp_read(fd_set *); 00615 00616 00617 00618 /* 00619 * void 00620 * snmp_free_pdu(pdu) 00621 * netsnmp_pdu *pdu; 00622 * 00623 * Frees the pdu and any malloc'd data associated with it. 00624 */ 00625 void snmp_free_pdu(netsnmp_pdu *); 00626 00627 void snmp_free_var(netsnmp_variable_list *); /* frees just this one */ 00628 00629 void snmp_free_varbind(netsnmp_variable_list * var); /* frees all in list */ 00630 00631 /* 00632 * int snmp_select_info(numfds, fdset, timeout, block) 00633 * int *numfds; 00634 * fd_set *fdset; 00635 * struct timeval *timeout; 00636 * int *block; 00637 * 00638 * Returns info about what snmp requires from a select statement. 00639 * numfds is the number of fds in the list that are significant. 00640 * All file descriptors opened for SNMP are OR'd into the fdset. 00641 * If activity occurs on any of these file descriptors, snmp_read 00642 * should be called with that file descriptor set. 00643 * 00644 * The timeout is the latest time that SNMP can wait for a timeout. The 00645 * select should be done with the minimum time between timeout and any other 00646 * timeouts necessary. This should be checked upon each invocation of select. 00647 * If a timeout is received, snmp_timeout should be called to check if the 00648 * timeout was for SNMP. (snmp_timeout is idempotent) 00649 * 00650 * Block is 1 if the select is requested to block indefinitely, rather than 00651 * time out. If block is input as 1, the timeout value will be treated as 00652 * undefined, but it must be available for setting in snmp_select_info. On 00653 * return, if block is true, the value of timeout will be undefined. 00654 * 00655 * snmp_select_info returns the number of open sockets. (i.e. The number 00656 * of sessions open) 00657 */ 00658 int snmp_select_info(int *, fd_set *, struct timeval *, 00659 int *); 00660 00661 00662 00663 /* 00664 * void snmp_timeout(); 00665 * 00666 * snmp_timeout should be called whenever the timeout from snmp_select_info 00667 * expires, but it is idempotent, so snmp_timeout can be polled (probably a 00668 * cpu expensive proposition). snmp_timeout checks to see if any of the 00669 * sessions have an outstanding request that has timed out. If it finds one 00670 * (or more), and that pdu has more retries available, a new packet is formed 00671 * from the pdu and is resent. If there are no more retries available, the 00672 * callback for the session is used to alert the user of the timeout. 00673 */ 00674 00675 void snmp_timeout(void); 00676 00677 00678 /* 00679 * This routine must be supplied by the application: 00680 * 00681 * u_char *authenticator(pdu, length, community, community_len) 00682 * u_char *pdu; The rest of the PDU to be authenticated 00683 * int *length; The length of the PDU (updated by the authenticator) 00684 * u_char *community; The community name to authenticate under. 00685 * int community_len The length of the community name. 00686 * 00687 * Returns the authenticated pdu, or NULL if authentication failed. 00688 * If null authentication is used, the authenticator in snmp_session can be 00689 * set to NULL(0). 00690 */ 00691 00692 00693 00694 /* 00695 * This routine must be supplied by the application: 00696 * 00697 * int callback(operation, session, reqid, pdu, magic) 00698 * int operation; 00699 * netsnmp_session *session; The session authenticated under. 00700 * int reqid; The request id of this pdu (0 for TRAP) 00701 * netsnmp_pdu *pdu; The pdu information. 00702 * void *magic A link to the data for this routine. 00703 * 00704 * Returns 1 if request was successful, 0 if it should be kept pending. 00705 * Any data in the pdu must be copied because it will be freed elsewhere. 00706 * Operations are defined below: 00707 */ 00708 00709 #define NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE 1 00710 #define NETSNMP_CALLBACK_OP_TIMED_OUT 2 00711 #define NETSNMP_CALLBACK_OP_SEND_FAILED 3 00712 #define NETSNMP_CALLBACK_OP_CONNECT 4 00713 #define NETSNMP_CALLBACK_OP_DISCONNECT 5 00714 00715 long snmp_get_next_msgid(void); 00716 long snmp_get_next_reqid(void); 00717 long snmp_get_next_sessid(void); 00718 long snmp_get_next_transid(void); 00719 00720 int snmp_oid_compare(const oid *, size_t, const oid *, 00721 size_t); 00722 int snmp_oid_ncompare(const oid *, size_t, const oid *, 00723 size_t, size_t); 00724 int snmp_oidtree_compare(const oid *, size_t, const oid *, 00725 size_t); 00726 int netsnmp_oid_compare_ll(const oid * in_name1, 00727 size_t len1, const oid * in_name2, 00728 size_t len2, size_t *offpt); 00729 int netsnmp_oid_equals(const oid *, size_t, const oid *, 00730 size_t); 00731 int netsnmp_oid_tree_equals(const oid *, size_t, const oid *, 00732 size_t); 00733 int netsnmp_oid_is_subtree(const oid *, size_t, const oid *, 00734 size_t); 00735 int netsnmp_oid_find_prefix(const oid * in_name1, size_t len1, 00736 const oid * in_name2, size_t len2); 00737 void init_snmp(const char *); 00738 u_char *snmp_pdu_build(netsnmp_pdu *, u_char *, size_t *); 00739 #ifdef USE_REVERSE_ASNENCODING 00740 u_char *snmp_pdu_rbuild(netsnmp_pdu *, u_char *, size_t *); 00741 #endif 00742 int snmpv3_parse(netsnmp_pdu *, u_char *, size_t *, 00743 u_char **, netsnmp_session *); 00744 int snmpv3_packet_build(netsnmp_session *, 00745 netsnmp_pdu *pdu, u_char * packet, 00746 size_t * out_length, 00747 u_char * pdu_data, 00748 size_t pdu_data_len); 00749 int snmpv3_packet_rbuild(netsnmp_session *, 00750 netsnmp_pdu *pdu, u_char * packet, 00751 size_t * out_length, 00752 u_char * pdu_data, 00753 size_t pdu_data_len); 00754 int snmpv3_make_report(netsnmp_pdu *pdu, int error); 00755 int snmpv3_get_report_type(netsnmp_pdu *pdu); 00756 int snmp_pdu_parse(netsnmp_pdu *pdu, u_char * data, 00757 size_t * length); 00758 u_char *snmpv3_scopedPDU_parse(netsnmp_pdu *pdu, u_char * cp, 00759 size_t * length); 00760 void snmp_store(const char *type); 00761 void snmp_shutdown(const char *type); 00762 netsnmp_variable_list *snmp_pdu_add_variable(netsnmp_pdu *, const oid *, 00763 size_t, u_char, const u_char *, 00764 size_t); 00765 netsnmp_variable_list *snmp_varlist_add_variable(netsnmp_variable_list 00766 ** varlist, 00767 const oid * name, 00768 size_t name_length, 00769 u_char type, 00770 const u_char * value, 00771 size_t len); 00772 int snmp_add_var(netsnmp_pdu *, const oid *, size_t, char, 00773 const char *); 00774 oid *snmp_duplicate_objid(const oid * objToCopy, size_t); 00775 u_int snmp_increment_statistic(int which); 00776 u_int snmp_increment_statistic_by(int which, int count); 00777 u_int snmp_get_statistic(int which); 00778 void snmp_init_statistics(void); 00779 int create_user_from_session(netsnmp_session * session); 00780 int snmp_get_fd_for_session(struct snmp_session *sessp); 00781 00782 /* 00783 * New re-allocating reverse encoding functions. 00784 */ 00785 #ifdef USE_REVERSE_ASNENCODING 00786 00787 int snmpv3_packet_realloc_rbuild(u_char ** pkt, size_t * pkt_len, 00788 size_t * offset, 00789 netsnmp_session * session, 00790 netsnmp_pdu *pdu, u_char * pdu_data, 00791 size_t pdu_data_len); 00792 00793 int snmp_pdu_realloc_rbuild(u_char ** pkt, size_t * pkt_len, 00794 size_t * offset, netsnmp_pdu *pdu); 00795 #endif 00796 00797 00798 00799 /* 00800 * Extended open; fpre_parse has changed. 00801 */ 00802 00803 netsnmp_session *snmp_open_ex(netsnmp_session *, 00804 int (*fpre_parse) (netsnmp_session *, 00805 struct 00806 netsnmp_transport_s *, 00807 void *, int), 00808 int (*fparse) (netsnmp_session *, 00809 netsnmp_pdu *, u_char *, 00810 size_t), 00811 int (*fpost_parse) (netsnmp_session *, 00812 netsnmp_pdu *, int), 00813 int (*fbuild) (netsnmp_session *, 00814 netsnmp_pdu *, u_char *, 00815 size_t *), 00816 int (*frbuild) (netsnmp_session *, 00817 netsnmp_pdu *, u_char **, 00818 size_t *, size_t *), 00819 int (*fcheck) (u_char *, size_t)); 00820 00821 /* 00822 * provided for backwards compatability. Don't use these functions. 00823 * See snmp_debug.h and snmp_debug.c instead. 00824 */ 00825 00826 void snmp_set_do_debugging(int); 00827 int snmp_get_do_debugging(void); 00828 00829 00830 /* 00831 * snmp_error - return error data 00832 * Inputs : address of errno, address of snmp_errno, address of string 00833 * Caller must free the string returned after use. 00834 */ 00835 void snmp_error(netsnmp_session *, int *, int *, char **); 00836 /* 00837 * single session API. 00838 * 00839 * These functions perform similar actions as snmp_XX functions, 00840 * but operate on a single session only. 00841 * 00842 * Synopsis: 00843 00844 void * sessp; 00845 netsnmp_session session, *ss; 00846 netsnmp_pdu *pdu, *response; 00847 00848 snmp_sess_init(&session); 00849 session.retries = ... 00850 session.remote_port = ... 00851 sessp = snmp_sess_open(&session); 00852 ss = snmp_sess_session(sessp); 00853 if (ss == NULL) 00854 exit(1); 00855 ... 00856 if (ss->community) free(ss->community); 00857 ss->community = strdup(gateway); 00858 ss->community_len = strlen(gateway); 00859 ... 00860 snmp_sess_synch_response(sessp, pdu, &response); 00861 ... 00862 snmp_sess_close(sessp); 00863 00864 * See also: 00865 * snmp_sess_synch_response, in snmp_client.h. 00866 00867 * Notes: 00868 * 1. Invoke snmp_sess_session after snmp_sess_open. 00869 * 2. snmp_sess_session return value is an opaque pointer. 00870 * 3. Do NOT free memory returned by snmp_sess_session. 00871 * 4. Replace snmp_send(ss,pdu) with snmp_sess_send(sessp,pdu) 00872 */ 00873 00874 void snmp_sess_init(netsnmp_session *); 00875 void *snmp_sess_open(netsnmp_session *); 00876 void *snmp_sess_pointer(netsnmp_session *); 00877 netsnmp_session *snmp_sess_session(void *); 00878 00879 /* 00880 * Return the netsnmp_transport structure associated with the given opaque 00881 * pointer. 00882 */ 00883 00884 struct netsnmp_transport_s *snmp_sess_transport(void *); 00885 void snmp_sess_transport_set(void *, 00886 struct netsnmp_transport_s *); 00887 00888 /* 00889 * EXPERIMENTAL API EXTENSIONS ------------------------------------------ 00890 * 00891 * snmp_sess_add_ex, snmp_sess_add, snmp_add 00892 * 00893 * Analogous to snmp_open family of functions, but taking an 00894 * netsnmp_transport pointer as an extra argument. Unlike snmp_open et 00895 * al. it doesn't attempt to interpret the in_session->peername as a 00896 * transport endpoint specifier, but instead uses the supplied transport. 00897 * JBPN 00898 * 00899 */ 00900 00901 void *snmp_sess_add_ex(netsnmp_session *, 00902 struct netsnmp_transport_s *, 00903 int (*fpre_parse) (netsnmp_session *, 00904 struct 00905 netsnmp_transport_s 00906 *, void *, int), 00907 int (*fparse) (netsnmp_session *, 00908 struct snmp_pdu *, 00909 u_char *, size_t), 00910 int (*fpost_parse) (netsnmp_session *, 00911 struct snmp_pdu *, 00912 int), 00913 int (*fbuild) (netsnmp_session *, 00914 struct snmp_pdu *, 00915 u_char *, size_t *), 00916 int (*frbuild) (netsnmp_session *, 00917 struct snmp_pdu *, 00918 u_char **, size_t *, 00919 size_t *), 00920 int (*fcheck) (u_char *, size_t), 00921 netsnmp_pdu *(*fcreate_pdu) (struct 00922 netsnmp_transport_s 00923 *, 00924 void *, 00925 size_t)); 00926 00927 void *snmp_sess_add(netsnmp_session *, 00928 struct netsnmp_transport_s *, 00929 int (*fpre_parse) (netsnmp_session *, 00930 struct 00931 netsnmp_transport_s *, 00932 void *, int), 00933 int (*fpost_parse) (netsnmp_session *, 00934 netsnmp_pdu *, int)); 00935 00936 netsnmp_session *snmp_add(netsnmp_session *, 00937 struct netsnmp_transport_s *, 00938 int (*fpre_parse) (netsnmp_session *, 00939 struct netsnmp_transport_s 00940 *, void *, int), 00941 int (*fpost_parse) (netsnmp_session *, 00942 netsnmp_pdu *, int)); 00943 netsnmp_session *snmp_add_full(netsnmp_session * in_session, 00944 struct netsnmp_transport_s *transport, 00945 int (*fpre_parse) (netsnmp_session *, 00946 struct 00947 netsnmp_transport_s 00948 *, void *, int), 00949 int (*fparse) (netsnmp_session *, 00950 netsnmp_pdu *, u_char *, 00951 size_t), 00952 int (*fpost_parse) (netsnmp_session *, 00953 netsnmp_pdu *, int), 00954 int (*fbuild) (netsnmp_session *, 00955 netsnmp_pdu *, u_char *, 00956 size_t *), 00957 int (*frbuild) (netsnmp_session *, 00958 netsnmp_pdu *, 00959 u_char **, size_t *, 00960 size_t *), 00961 int (*fcheck) (u_char *, size_t), 00962 netsnmp_pdu *(*fcreate_pdu) (struct 00963 netsnmp_transport_s 00964 *, void *, 00965 size_t) 00966 ); 00967 00968 /* 00969 * use return value from snmp_sess_open as void * parameter 00970 */ 00971 00972 int snmp_sess_send(void *, netsnmp_pdu *); 00973 int snmp_sess_async_send(void *, netsnmp_pdu *, 00974 netsnmp_callback, void *); 00975 int snmp_sess_select_info(void *, int *, fd_set *, 00976 struct timeval *, int *); 00977 int snmp_sess_read(void *, fd_set *); 00978 void snmp_sess_timeout(void *); 00979 int snmp_sess_close(void *); 00980 00981 void snmp_sess_error(void *, int *, int *, char **); 00982 void netsnmp_sess_log_error(int priority, 00983 const char *prog_string, 00984 netsnmp_session * ss); 00985 void snmp_sess_perror(const char *prog_string, 00986 netsnmp_session * ss); 00987 const char * snmp_pdu_type(int type); 00988 00989 /* 00990 * end single session API 00991 */ 00992 00993 /* 00994 * generic statistic counters 00995 */ 00996 00997 /* 00998 * snmpv3 statistics 00999 */ 01000 01001 /* 01002 * mpd stats 01003 */ 01004 #define STAT_SNMPUNKNOWNSECURITYMODELS 0 01005 #define STAT_SNMPINVALIDMSGS 1 01006 #define STAT_SNMPUNKNOWNPDUHANDLERS 2 01007 #define STAT_MPD_STATS_START STAT_SNMPUNKNOWNSECURITYMODELS 01008 #define STAT_MPD_STATS_END STAT_SNMPUNKNOWNPDUHANDLERS 01009 01010 /* 01011 * usm stats 01012 */ 01013 #define STAT_USMSTATSUNSUPPORTEDSECLEVELS 3 01014 #define STAT_USMSTATSNOTINTIMEWINDOWS 4 01015 #define STAT_USMSTATSUNKNOWNUSERNAMES 5 01016 #define STAT_USMSTATSUNKNOWNENGINEIDS 6 01017 #define STAT_USMSTATSWRONGDIGESTS 7 01018 #define STAT_USMSTATSDECRYPTIONERRORS 8 01019 #define STAT_USM_STATS_START STAT_USMSTATSUNSUPPORTEDSECLEVELS 01020 #define STAT_USM_STATS_END STAT_USMSTATSDECRYPTIONERRORS 01021 01022 /* 01023 * snmp counters 01024 */ 01025 #define STAT_SNMPINPKTS 9 01026 #define STAT_SNMPOUTPKTS 10 01027 #define STAT_SNMPINBADVERSIONS 11 01028 #define STAT_SNMPINBADCOMMUNITYNAMES 12 01029 #define STAT_SNMPINBADCOMMUNITYUSES 13 01030 #define STAT_SNMPINASNPARSEERRS 14 01031 /* 01032 * #define STAT_SNMPINBADTYPES 15 01033 */ 01034 #define STAT_SNMPINTOOBIGS 16 01035 #define STAT_SNMPINNOSUCHNAMES 17 01036 #define STAT_SNMPINBADVALUES 18 01037 #define STAT_SNMPINREADONLYS 19 01038 #define STAT_SNMPINGENERRS 20 01039 #define STAT_SNMPINTOTALREQVARS 21 01040 #define STAT_SNMPINTOTALSETVARS 22 01041 #define STAT_SNMPINGETREQUESTS 23 01042 #define STAT_SNMPINGETNEXTS 24 01043 #define STAT_SNMPINSETREQUESTS 25 01044 #define STAT_SNMPINGETRESPONSES 26 01045 #define STAT_SNMPINTRAPS 27 01046 #define STAT_SNMPOUTTOOBIGS 28 01047 #define STAT_SNMPOUTNOSUCHNAMES 29 01048 #define STAT_SNMPOUTBADVALUES 30 01049 /* 01050 * #define STAT_SNMPOUTREADONLYS 31 01051 */ 01052 #define STAT_SNMPOUTGENERRS 32 01053 #define STAT_SNMPOUTGETREQUESTS 33 01054 #define STAT_SNMPOUTGETNEXTS 34 01055 #define STAT_SNMPOUTSETREQUESTS 35 01056 #define STAT_SNMPOUTGETRESPONSES 36 01057 #define STAT_SNMPOUTTRAPS 37 01058 /* 01059 * AUTHTRAPENABLE 38 01060 */ 01061 #define STAT_SNMPSILENTDROPS 39 01062 #define STAT_SNMPPROXYDROPS 40 01063 #define STAT_SNMP_STATS_START STAT_SNMPINPKTS 01064 #define STAT_SNMP_STATS_END STAT_SNMPPROXYDROPS 01065 01066 /* 01067 * target mib counters 01068 */ 01069 #define STAT_SNMPUNAVAILABLECONTEXTS 41 01070 #define STAT_SNMPUNKNOWNCONTEXTS 42 01071 #define STAT_TARGET_STATS_START STAT_SNMPUNAVAILABLECONTEXTS 01072 #define STAT_TARGET_STATS_END STAT_SNMPUNKNOWNCONTEXTS 01073 01074 #define MAX_STATS 43 01075 01076 #ifdef __cplusplus 01077 } 01078 #endif 01079 #endif /* SNMP_API_H */
1.3.9.1
Last modified: Thursday, 01-Mar-2007 16:20:11 PST
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.