2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 * Author: Harti Brandt <harti@freebsd.org>
8 * Copyright (c) 2010 The FreeBSD Foundation
11 * Portions of this software were developed by Shteryana Sotirova Shopova
12 * under sponsorship from the FreeBSD Foundation.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * $Begemot: bsnmp/lib/snmp.h,v 1.30 2004/08/06 08:46:54 brandt Exp $
38 * Header file for SNMP functions.
43 #include <sys/types.h>
46 #define BSNMP_MINOR 13
48 #define SNMP_COMMUNITY_MAXLEN 128
49 #define SNMP_MAX_BINDINGS 100
50 #define SNMP_CONTEXT_NAME_SIZ (32 + 1)
51 #define SNMP_ENGINE_ID_SIZ 32
52 #define SNMP_TIME_WINDOW 150
56 SNMP_SYNTAX_INTEGER, /* == INTEGER32 */
57 SNMP_SYNTAX_OCTETSTRING,
59 SNMP_SYNTAX_IPADDRESS,
61 SNMP_SYNTAX_GAUGE, /* == UNSIGNED32 */
62 SNMP_SYNTAX_TIMETICKS,
65 SNMP_SYNTAX_COUNTER64,
66 SNMP_SYNTAX_NOSUCHOBJECT, /* exception */
67 SNMP_SYNTAX_NOSUCHINSTANCE, /* exception */
68 SNMP_SYNTAX_ENDOFMIBVIEW, /* exception */
73 enum snmp_syntax syntax;
75 int32_t integer; /* also integer32 */
82 uint32_t uint32; /* also gauge32, counter32,
83 unsigned32, timeticks */
95 #define SNMP_MPM_SNMP_V1 0
96 #define SNMP_MPM_SNMP_V2c 1
97 #define SNMP_MPM_SNMP_V3 3
99 #define SNMP_ADM_STR32_SIZ (32 + 1)
100 #define SNMP_AUTH_KEY_SIZ 40
101 #define SNMP_PRIV_KEY_SIZ 32
102 #define SNMP_USM_AUTH_SIZE 12
103 #define SNMP_USM_PRIV_SIZE 8
104 #define SNMP_AUTH_HMACMD5_KEY_SIZ 16
105 #define SNMP_AUTH_HMACSHA_KEY_SIZ 20
106 #define SNMP_PRIV_AES_KEY_SIZ 16
107 #define SNMP_PRIV_DES_KEY_SIZ 8
111 SNMP_SECMODEL_ANY = 0,
112 SNMP_SECMODEL_SNMPv1 = 1,
113 SNMP_SECMODEL_SNMPv2c = 2,
114 SNMP_SECMODEL_USM = 3,
115 SNMP_SECMODEL_UNKNOWN
118 enum snmp_usm_level {
119 SNMP_noAuthNoPriv = 1,
124 enum snmp_authentication {
125 SNMP_AUTH_NOAUTH = 0,
131 SNMP_PRIV_NOPRIV = 0,
137 uint8_t engine_id[SNMP_ENGINE_ID_SIZ];
139 int32_t engine_boots;
141 int32_t max_msg_size;
145 char sec_name[SNMP_ADM_STR32_SIZ];
146 enum snmp_authentication auth_proto;
147 enum snmp_privacy priv_proto;
148 uint8_t auth_key[SNMP_AUTH_KEY_SIZ];
149 uint8_t priv_key[SNMP_PRIV_KEY_SIZ];
153 char community[SNMP_COMMUNITY_MAXLEN + 1];
154 enum snmp_version version;
157 /* SNMPv3 PDU header fields */
160 int32_t security_model;
161 struct snmp_engine engine;
163 /* Associated USM user parameters */
164 struct snmp_user user;
165 uint8_t msg_digest[SNMP_USM_AUTH_SIZE];
166 uint8_t msg_salt[SNMP_USM_PRIV_SIZE];
168 /* View-based Access Model */
169 /* XXX: put in separate structure - conflicts with struct snmp_context */
170 uint32_t context_engine_len;
171 uint8_t context_engine[SNMP_ENGINE_ID_SIZ];
172 char context_name[SNMP_CONTEXT_NAME_SIZ];
175 struct asn_oid enterprise;
176 u_char agent_addr[4];
177 int32_t generic_trap;
178 int32_t specific_trap;
183 int32_t error_status;
186 /* fixes for encoding */
188 asn_len_t scoped_len;
191 u_char *encrypted_ptr;
197 struct snmp_value bindings[SNMP_MAX_BINDINGS];
200 #define snmp_v1_pdu snmp_pdu
202 #define SNMP_PDU_GET 0
203 #define SNMP_PDU_GETNEXT 1
204 #define SNMP_PDU_RESPONSE 2
205 #define SNMP_PDU_SET 3
206 #define SNMP_PDU_TRAP 4 /* v1 */
207 #define SNMP_PDU_GETBULK 5 /* v2 */
208 #define SNMP_PDU_INFORM 6 /* v2 */
209 #define SNMP_PDU_TRAP2 7 /* v2 */
210 #define SNMP_PDU_REPORT 8 /* v2 */
212 #define SNMP_ERR_NOERROR 0
213 #define SNMP_ERR_TOOBIG 1
214 #define SNMP_ERR_NOSUCHNAME 2 /* v1 */
215 #define SNMP_ERR_BADVALUE 3 /* v1 */
216 #define SNMP_ERR_READONLY 4 /* v1 */
217 #define SNMP_ERR_GENERR 5
218 #define SNMP_ERR_NO_ACCESS 6 /* v2 */
219 #define SNMP_ERR_WRONG_TYPE 7 /* v2 */
220 #define SNMP_ERR_WRONG_LENGTH 8 /* v2 */
221 #define SNMP_ERR_WRONG_ENCODING 9 /* v2 */
222 #define SNMP_ERR_WRONG_VALUE 10 /* v2 */
223 #define SNMP_ERR_NO_CREATION 11 /* v2 */
224 #define SNMP_ERR_INCONS_VALUE 12 /* v2 */
225 #define SNMP_ERR_RES_UNAVAIL 13 /* v2 */
226 #define SNMP_ERR_COMMIT_FAILED 14 /* v2 */
227 #define SNMP_ERR_UNDO_FAILED 15 /* v2 */
228 #define SNMP_ERR_AUTH_ERR 16 /* v2 */
229 #define SNMP_ERR_NOT_WRITEABLE 17 /* v2 */
230 #define SNMP_ERR_INCONS_NAME 18 /* v2 */
232 #define SNMP_TRAP_COLDSTART 0
233 #define SNMP_TRAP_WARMSTART 1
234 #define SNMP_TRAP_LINKDOWN 2
235 #define SNMP_TRAP_LINKUP 3
236 #define SNMP_TRAP_AUTHENTICATION_FAILURE 4
237 #define SNMP_TRAP_EGP_NEIGHBOR_LOSS 5
238 #define SNMP_TRAP_ENTERPRISE 6
247 SNMP_CODE_BADSECLEVEL,
255 #define SNMP_MSG_AUTH_FLAG 0x1
256 #define SNMP_MSG_PRIV_FLAG 0x2
257 #define SNMP_MSG_REPORT_FLAG 0x4
258 #define SNMP_MSG_AUTODISCOVER 0x80
260 void snmp_value_free(struct snmp_value *);
261 int snmp_value_parse(const char *, enum snmp_syntax, union snmp_values *);
262 int snmp_value_copy(struct snmp_value *, const struct snmp_value *);
264 void snmp_pdu_free(struct snmp_pdu *);
265 void snmp_pdu_init_secparams(struct snmp_pdu *);
266 enum snmp_code snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *);
267 enum snmp_code snmp_pdu_decode_header(struct asn_buf *, struct snmp_pdu *);
268 enum snmp_code snmp_pdu_decode_scoped(struct asn_buf *, struct snmp_pdu *, int32_t *);
269 enum snmp_code snmp_pdu_encode(struct snmp_pdu *, struct asn_buf *);
270 enum snmp_code snmp_pdu_decode_secmode(struct asn_buf *, struct snmp_pdu *);
272 int snmp_pdu_snoop(const struct asn_buf *);
274 void snmp_pdu_dump(const struct snmp_pdu *pdu);
276 enum snmp_code snmp_passwd_to_keys(struct snmp_user *, char *);
277 enum snmp_code snmp_get_local_keys(struct snmp_user *, uint8_t *, uint32_t);
278 enum snmp_code snmp_calc_keychange(struct snmp_user *, uint8_t *);
280 extern void (*snmp_error)(const char *, ...);
281 extern void (*snmp_printf)(const char *, ...);
283 #define TRUTH_MK(F) ((F) ? 1 : 2)
284 #define TRUTH_GET(T) (((T) == 1) ? 1 : 0)
285 #define TRUTH_OK(T) ((T) == 1 || (T) == 2)