Skip to main content

netsnmp_sys_nocrypto/
lib.rs

1#![allow(non_camel_case_types,non_snake_case,non_upper_case_globals)]
2extern crate libc;
3
4use std::os::raw;
5use std::sync::{Once, ONCE_INIT};
6
7pub const MAX_OID_LEN:       libc::size_t = 128;
8
9pub const STAT_SUCCESS:      raw::c_int = 0;
10pub const STAT_ERROR:        raw::c_int = 1;
11pub const STAT_TIMEOUT:      raw::c_int = 2;
12
13pub const SNMP_VERSION_1:    raw::c_long = 0;
14pub const SNMP_VERSION_2c:   raw::c_long = 1;
15pub const SNMP_VERSION_3:    raw::c_long = 3;
16
17pub const SNMP_SEC_MODEL_ANY:        raw::c_int = 0;
18pub const SNMP_SEC_MODEL_SNMPv1:     raw::c_int = 1;
19pub const SNMP_SEC_MODEL_SNMPv2c:    raw::c_int = 2;
20pub const SNMP_SEC_MODEL_USM:        raw::c_int = 3;
21pub const SNMP_SEC_MODEL_TSM:        raw::c_int = 4;
22pub const SNMP_SEC_MODEL_SNMPv2p:    raw::c_int = 256;
23
24pub const SNMP_SEC_LEVEL_NOAUTH:     raw::c_int = 1;
25pub const SNMP_SEC_LEVEL_AUTHNOPRIV: raw::c_int = 2;
26pub const SNMP_SEC_LEVEL_AUTHPRIV:   raw::c_int = 3;
27
28pub const SNMP_MSG_GET:      raw::c_int = 160;
29pub const SNMP_MSG_GETNEXT:  raw::c_int = 161;
30pub const SNMP_MSG_RESPONSE: raw::c_int = 162;
31pub const SNMP_MSG_SET:      raw::c_int = 163;
32pub const SNMP_MSG_TRAP:     raw::c_int = 164;
33pub const SNMP_MSG_GETBULK:  raw::c_int = 165;
34pub const SNMP_MSG_INFORM:   raw::c_int = 166;
35pub const SNMP_MSG_TRAP2:    raw::c_int = 167;
36pub const SNMP_MSG_REPORT:   raw::c_int = 168;
37
38pub const SNMP_NOSUCHOBJECT:     raw::c_uchar = (ASN_CONTEXT | ASN_PRIMITIVE | 0x0);
39pub const SNMP_NOSUCHINSTANCE:   raw::c_uchar = (ASN_CONTEXT | ASN_PRIMITIVE | 0x1);
40pub const SNMP_ENDOFMIBVIEW:     raw::c_uchar = (ASN_CONTEXT | ASN_PRIMITIVE | 0x2);
41
42pub const SNMP_ERR_NOERROR:             raw::c_long =  0;
43pub const SNMP_ERR_TOOBIG:	            raw::c_long =  1;
44pub const SNMP_ERR_NOSUCHNAME:          raw::c_long =  2;
45pub const SNMP_ERR_BADVALUE:            raw::c_long =  3;
46pub const SNMP_ERR_READONLY:            raw::c_long =  4;
47pub const SNMP_ERR_GENERR:	            raw::c_long =  5;
48pub const SNMP_ERR_NOACCESS:	          raw::c_long =  6;
49pub const SNMP_ERR_WRONGTYPE:	          raw::c_long =  7;
50pub const SNMP_ERR_WRONGLENGTH:		      raw::c_long =  8;
51pub const SNMP_ERR_WRONGENCODING:	      raw::c_long =  9;
52pub const SNMP_ERR_WRONGVALUE:		      raw::c_long = 10;
53pub const SNMP_ERR_NOCREATION:		      raw::c_long = 11;
54pub const SNMP_ERR_INCONSISTENTVALUE:	  raw::c_long = 12;
55pub const SNMP_ERR_RESOURCEUNAVAILABLE: raw::c_long = 13;
56pub const SNMP_ERR_COMMITFAILED:        raw::c_long = 14;
57pub const SNMP_ERR_UNDOFAILED:	        raw::c_long = 15;
58pub const SNMP_ERR_AUTHORIZATIONERROR:  raw::c_long = 16;
59pub const SNMP_ERR_NOTWRITABLE:         raw::c_long = 17;
60pub const SNMP_ERR_INCONSISTENTNAME:    raw::c_long = 18;
61
62pub const SNMPERR_SUCCESS:                      raw::c_int =   0;     /* XXX  Non-PDU "success" code. */
63pub const SNMPERR_GENERR:                       raw::c_int =  -1;
64pub const SNMPERR_BAD_LOCPORT:                  raw::c_int =  -2;
65pub const SNMPERR_BAD_ADDRESS:                  raw::c_int =  -3;
66pub const SNMPERR_BAD_SESSION:                  raw::c_int =  -4;
67pub const SNMPERR_TOO_LONG:                     raw::c_int =  -5;
68pub const SNMPERR_NO_SOCKET:                    raw::c_int =  -6;
69pub const SNMPERR_V2_IN_V1:                     raw::c_int =  -7;
70pub const SNMPERR_V1_IN_V2:                     raw::c_int =  -8;
71pub const SNMPERR_BAD_REPEATERS:                raw::c_int =  -9;
72pub const SNMPERR_BAD_REPETITIONS:              raw::c_int = -10;
73pub const SNMPERR_BAD_ASN1_BUILD:               raw::c_int = -11;
74pub const SNMPERR_BAD_SENDTO:                   raw::c_int = -12;
75pub const SNMPERR_BAD_PARSE:                    raw::c_int = -13;
76pub const SNMPERR_BAD_VERSION:                  raw::c_int = -14;
77pub const SNMPERR_BAD_SRC_PARTY:                raw::c_int = -15;
78pub const SNMPERR_BAD_DST_PARTY:                raw::c_int = -16;
79pub const SNMPERR_BAD_CONTEXT:                  raw::c_int = -17;
80pub const SNMPERR_BAD_COMMUNITY:                raw::c_int = -18;
81pub const SNMPERR_NOAUTH_DESPRIV:               raw::c_int = -19;
82pub const SNMPERR_BAD_ACL:                      raw::c_int = -20;
83pub const SNMPERR_BAD_PARTY:                    raw::c_int = -21;
84pub const SNMPERR_ABORT:                        raw::c_int = -22;
85pub const SNMPERR_UNKNOWN_PDU:                  raw::c_int = -23;
86pub const SNMPERR_TIMEOUT:                      raw::c_int = -24;
87pub const SNMPERR_BAD_RECVFROM:                 raw::c_int = -25;
88pub const SNMPERR_BAD_ENG_ID:                   raw::c_int = -26;
89pub const SNMPERR_BAD_SEC_NAME:                 raw::c_int = -27;
90pub const SNMPERR_BAD_SEC_LEVEL:                raw::c_int = -28;
91pub const SNMPERR_ASN_PARSE_ERR:                raw::c_int = -29;
92pub const SNMPERR_UNKNOWN_SEC_MODEL:            raw::c_int = -30;
93pub const SNMPERR_INVALID_MSG:                  raw::c_int = -31;
94pub const SNMPERR_UNKNOWN_ENG_ID:               raw::c_int = -32;
95pub const SNMPERR_UNKNOWN_USER_NAME:            raw::c_int = -33;
96pub const SNMPERR_UNSUPPORTED_SEC_LEVEL:        raw::c_int = -34;
97pub const SNMPERR_AUTHENTICATION_FAILURE:       raw::c_int = -35;
98pub const SNMPERR_NOT_IN_TIME_WINDOW:           raw::c_int = -36;
99pub const SNMPERR_DECRYPTION_ERR:               raw::c_int = -37;
100pub const SNMPERR_SC_GENERAL_FAILURE:           raw::c_int = -38;
101pub const SNMPERR_SC_NOT_CONFIGURED:            raw::c_int = -39;
102pub const SNMPERR_KT_NOT_AVAILABLE:             raw::c_int = -40;
103pub const SNMPERR_UNKNOWN_REPORT:               raw::c_int = -41;
104pub const SNMPERR_USM_GENERICERROR:             raw::c_int = -42;
105pub const SNMPERR_USM_UNKNOWNSECURITYNAME:      raw::c_int = -43;
106pub const SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL: raw::c_int = -44;
107pub const SNMPERR_USM_ENCRYPTIONERROR:          raw::c_int = -45;
108pub const SNMPERR_USM_AUTHENTICATIONFAILURE:    raw::c_int = -46;
109pub const SNMPERR_USM_PARSEERROR:               raw::c_int = -47;
110pub const SNMPERR_USM_UNKNOWNENGINEID:          raw::c_int = -48;
111pub const SNMPERR_USM_NOTINTIMEWINDOW:          raw::c_int = -49;
112pub const SNMPERR_USM_DECRYPTIONERROR:          raw::c_int = -50;
113pub const SNMPERR_NOMIB:                        raw::c_int = -51;
114pub const SNMPERR_RANGE:                        raw::c_int = -52;
115pub const SNMPERR_MAX_SUBID:                    raw::c_int = -53;
116pub const SNMPERR_BAD_SUBID:                    raw::c_int = -54;
117pub const SNMPERR_LONG_OID:                     raw::c_int = -55;
118pub const SNMPERR_BAD_NAME:                     raw::c_int = -56;
119pub const SNMPERR_VALUE:                        raw::c_int = -57;
120pub const SNMPERR_UNKNOWN_OBJID:                raw::c_int = -58;
121pub const SNMPERR_NULL_PDU:                     raw::c_int = -59;
122pub const SNMPERR_NO_VARS:                      raw::c_int = -60;
123pub const SNMPERR_VAR_TYPE:                     raw::c_int = -61;
124pub const SNMPERR_MALLOC:                       raw::c_int = -62;
125pub const SNMPERR_KRB5:                         raw::c_int = -63;
126pub const SNMPERR_PROTOCOL:                     raw::c_int = -64;
127pub const SNMPERR_OID_NONINCREASING:            raw::c_int = -65;
128pub const SNMPERR_JUST_A_CONTEXT_PROBE:         raw::c_int = -66;
129pub const SNMPERR_TRANSPORT_NO_CONFIG:          raw::c_int = -67;
130pub const SNMPERR_TRANSPORT_CONFIG_ERROR:       raw::c_int = -68;
131pub const SNMPERR_TLS_NO_CERTIFICATE:           raw::c_int = -69;
132pub const SNMPERR_MAX:                          raw::c_int = -69;
133
134pub const ASN_BOOLEAN:	    raw::c_uchar = 0x01;
135pub const ASN_INTEGER:	    raw::c_uchar = 0x02;
136pub const ASN_BIT_STR:	    raw::c_uchar = 0x03;
137pub const ASN_OCTET_STR:    raw::c_uchar = 0x04;
138pub const ASN_NULL:	        raw::c_uchar = 0x05;
139pub const ASN_OBJECT_ID:	  raw::c_uchar = 0x06;
140pub const ASN_SEQUENCE:	    raw::c_uchar = 0x10;
141pub const ASN_SET:		      raw::c_uchar = 0x11;
142pub const ASN_UNIVERSAL:	  raw::c_uchar = 0x00;
143pub const ASN_APPLICATION:  raw::c_uchar = 0x40;
144pub const ASN_CONTEXT:	    raw::c_uchar = 0x80;
145pub const ASN_PRIVATE:	    raw::c_uchar = 0xC0;
146pub const ASN_PRIMITIVE:	  raw::c_uchar = 0x00;
147pub const ASN_CONSTRUCTOR:	raw::c_uchar = 0x20;
148
149pub const ASN_IPADDRESS:    raw::c_uchar = (ASN_APPLICATION |  0);
150pub const ASN_COUNTER:      raw::c_uchar = (ASN_APPLICATION |  1);
151pub const ASN_GAUGE:        raw::c_uchar = (ASN_APPLICATION |  2);
152pub const ASN_UNSIGNED:     raw::c_uchar = (ASN_APPLICATION |  2); // RFC 1902 - same as GAUGE
153pub const ASN_TIMETICKS:    raw::c_uchar = (ASN_APPLICATION |  3);
154pub const ASN_OPAQUE:       raw::c_uchar = (ASN_APPLICATION |  4); // changed so no conflict with other includes
155pub const ASN_NSAP:         raw::c_uchar = (ASN_APPLICATION |  5); // historic - don't use
156pub const ASN_COUNTER64:    raw::c_uchar = (ASN_APPLICATION |  6);
157pub const ASN_UINTEGER:     raw::c_uchar = (ASN_APPLICATION |  7); // historic - don't use
158pub const ASN_FLOAT:        raw::c_uchar = (ASN_APPLICATION |  8);
159pub const ASN_DOUBLE:       raw::c_uchar = (ASN_APPLICATION |  9);
160pub const ASN_INTEGER64:    raw::c_uchar = (ASN_APPLICATION | 10);
161pub const ASN_UNSIGNED64:   raw::c_uchar = (ASN_APPLICATION | 11);
162
163pub const USM_AUTH_KU_LEN: usize = 32;
164pub const USM_PRIV_KU_LEN: usize = 32;
165
166pub const NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE: raw::c_int = 1;
167pub const NETSNMP_CALLBACK_OP_TIMED_OUT:        raw::c_int = 2;
168pub const NETSNMP_CALLBACK_OP_SEND_FAILED:      raw::c_int = 3;
169pub const NETSNMP_CALLBACK_OP_CONNECT:          raw::c_int = 4;
170pub const NETSNMP_CALLBACK_OP_DISCONNECT:       raw::c_int = 5;
171
172pub const NETSNMP_DS_LIBRARY_ID:	raw::c_int = 0;
173pub const NETSNMP_DS_APPLICATION_ID: raw::c_int = 1;
174pub const NETSNMP_DS_TOKEN_ID:	raw::c_int = 2;
175pub const NETSNMP_DS_LIB_MIB_ERRORS:	raw::c_int = 0;
176pub const NETSNMP_DS_LIB_SAVE_MIB_DESCRS:	raw::c_int = 1;
177pub const NETSNMP_DS_LIB_MIB_COMMENT_TERM:	raw::c_int = 2;
178pub const NETSNMP_DS_LIB_MIB_PARSE_LABEL:	raw::c_int = 3;
179pub const NETSNMP_DS_LIB_DUMP_PACKET:	raw::c_int = 4;
180pub const NETSNMP_DS_LIB_LOG_TIMESTAMP:	raw::c_int = 5;
181pub const NETSNMP_DS_LIB_DONT_READ_CONFIGS:	raw::c_int = 6;
182pub const NETSNMP_DS_LIB_MIB_REPLACE:	raw::c_int = 7;
183pub const NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM:	raw::c_int = 8;
184pub const NETSNMP_DS_LIB_PRINT_NUMERIC_OIDS:	raw::c_int = 9;
185pub const NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS:	raw::c_int = 10;
186pub const NETSNMP_DS_LIB_ALARM_DONT_USE_SIG:	raw::c_int = 11 ;
187pub const NETSNMP_DS_LIB_PRINT_FULL_OID:	raw::c_int = 12;
188pub const NETSNMP_DS_LIB_QUICK_PRINT:	raw::c_int = 13;
189pub const NETSNMP_DS_LIB_RANDOM_ACCESS:	raw::c_int = 14;
190pub const NETSNMP_DS_LIB_REGEX_ACCESS:	raw::c_int = 15;
191pub const NETSNMP_DS_LIB_DONT_CHECK_RANGE:	raw::c_int = 16 ;
192pub const NETSNMP_DS_LIB_NO_TOKEN_WARNINGS:	raw::c_int = 17 ;
193pub const NETSNMP_DS_LIB_NUMERIC_TIMETICKS:	raw::c_int = 18;
194pub const NETSNMP_DS_LIB_ESCAPE_QUOTES:	raw::c_int = 19;
195pub const NETSNMP_DS_LIB_REVERSE_ENCODE:	raw::c_int = 20 ;
196pub const NETSNMP_DS_LIB_PRINT_BARE_VALUE:	raw::c_int = 21;
197pub const NETSNMP_DS_LIB_EXTENDED_INDEX:	raw::c_int = 22;
198pub const NETSNMP_DS_LIB_PRINT_HEX_TEXT:	raw::c_int = 23;
199pub const NETSNMP_DS_LIB_PRINT_UCD_STYLE_OID:	raw::c_int =  24;
200pub const NETSNMP_DS_LIB_READ_UCD_STYLE_OID:	raw::c_int = 25 ;
201pub const NETSNMP_DS_LIB_HAVE_READ_PREMIB_CONFIG:	raw::c_int = 26;
202pub const NETSNMP_DS_LIB_HAVE_READ_CONFIG:	raw::c_int = 27;
203pub const NETSNMP_DS_LIB_QUICKE_PRINT:	raw::c_int = 28;
204pub const NETSNMP_DS_LIB_DONT_PRINT_UNITS:	raw::c_int = 29;
205pub const NETSNMP_DS_LIB_NO_DISPLAY_HINT:	raw::c_int = 30;
206pub const NETSNMP_DS_LIB_16BIT_IDS:	raw::c_int = 31;
207pub const NETSNMP_DS_LIB_DONT_PERSIST_STATE:	raw::c_int = 32;
208pub const NETSNMP_DS_LIB_2DIGIT_HEX_OUTPUT:	raw::c_int = 33;
209
210pub const NETSNMP_DS_LIB_MIB_WARNINGS:	raw::c_uchar = 0;
211pub const NETSNMP_DS_LIB_SECLEVEL:	raw::c_uchar = 1;
212pub const NETSNMP_DS_LIB_SNMPVERSION:	raw::c_uchar = 2;
213pub const NETSNMP_DS_LIB_DEFAULT_PORT:	raw::c_uchar = 3;
214pub const NETSNMP_DS_LIB_OID_OUTPUT_FORMAT:	raw::c_uchar = 4;
215pub const NETSNMP_DS_LIB_STRING_OUTPUT_FORMAT:	raw::c_uchar = 5;
216
217pub const NETSNMP_DS_LIB_SECNAME:	raw::c_uchar = 0;
218pub const NETSNMP_DS_LIB_CONTEXT:	raw::c_uchar = 1;
219pub const NETSNMP_DS_LIB_PASSPHRASE:	raw::c_uchar = 2;
220pub const NETSNMP_DS_LIB_AUTHPASSPHRASE:	raw::c_uchar = 3;
221pub const NETSNMP_DS_LIB_PRIVPASSPHRASE:	raw::c_uchar = 4;
222pub const NETSNMP_DS_LIB_OPTIONALCONFIG:	raw::c_uchar = 5;
223pub const NETSNMP_DS_LIB_APPTYPE:	raw::c_uchar = 6;
224pub const NETSNMP_DS_LIB_COMMUNITY:	raw::c_uchar = 7;
225pub const NETSNMP_DS_LIB_PERSISTENT_DIR:	raw::c_uchar = 8;
226pub const NETSNMP_DS_LIB_CONFIGURATION_DIR:	raw::c_uchar = 9;
227pub const NETSNMP_DS_LIB_SECMODEL:	raw::c_uchar = 10;
228pub const NETSNMP_DS_LIB_MIBDIRS:	raw::c_uchar = 11;
229pub const NETSNMP_DS_LIB_OIDSUFFIX:	raw::c_uchar = 12;
230pub const NETSNMP_DS_LIB_OIDPREFIX:	raw::c_uchar = 13;
231pub const NETSNMP_DS_LIB_CLIENT_ADDR:	raw::c_uchar = 14;
232pub const NETSNMP_DS_LIB_TEMP_FILE_PATTERN:	raw::c_uchar = 15;
233pub const NETSNMP_DS_LIB_AUTHMASTERKEY:	raw::c_uchar = 16;
234pub const NETSNMP_DS_LIB_PRIVMASTERKEY:	raw::c_uchar = 17;
235pub const NETSNMP_DS_LIB_AUTHLOCALIZEDKEY:	raw::c_uchar = 18;
236pub const NETSNMP_DS_LIB_PRIVLOCALIZEDKEY:	raw::c_uchar = 19;
237
238
239
240mod agent_constants;
241pub use agent_constants::*;
242
243mod auto_agent;
244pub use auto_agent::*;
245
246mod auto;
247pub use auto::*;
248
249
250pub fn init_once(typ: &[u8]) {
251	static INIT: Once = ONCE_INIT;
252	INIT.call_once(||{
253	   init(typ);
254	})
255}
256pub fn init(typ: &[u8]) {
257	let mut type_dup = [0u8; 256];
258	type_dup[..typ.len()].copy_from_slice(typ);
259	unsafe {
260		init_snmp(type_dup.as_ptr() as *mut raw::c_char);
261	}
262}
263pub fn shutdown(typ: &[u8], persist: bool) {
264	let mut type_dup = [0u8; 256];
265	type_dup[..typ.len()].copy_from_slice(typ);
266	unsafe{
267		if !persist {
268			netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, 1);
269		}
270		snmp_shutdown(type_dup.as_ptr() as *mut raw::c_char);
271	}
272}
273#[cfg(test)]
274mod tests;