snmp_api.h 30 KB

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