1 #ifndef SNMP_H 2 #define SNMP_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 /* 8 * Definitions for the Simple Network Management Protocol (RFC 1067). 9 * 10 * 11 */ 12 /*********************************************************** 13 Copyright 1988, 1989 by Carnegie Mellon University 14 15 All Rights Reserved 16 17 Permission to use, copy, modify, and distribute this software and its 18 documentation for any purpose and without fee is hereby granted, 19 provided that the above copyright notice appear in all copies and that 20 both that copyright notice and this permission notice appear in 21 supporting documentation, and that the name of CMU not be 22 used in advertising or publicity pertaining to distribution of the 23 software without specific, written prior permission. 24 25 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 26 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 27 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 28 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 29 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 30 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 31 SOFTWARE. 32 ******************************************************************/ 33 34 /* 35 * Portions of this file are copyrighted by: 36 * Copyright (c) 2016 VMware, Inc. All rights reserved. 37 * Use is subject to license terms specified in the COPYING file 38 */ 39 40 41 #define SNMP_PORT 161 /* standard UDP port for SNMP agents 42 * to receive requests messages */ 43 #define SNMP_TRAP_PORT 162 /* standard UDP port for SNMP 44 * managers to receive notificaion 45 * (trap and inform) messages */ 46 47 #define SNMP_MAX_LEN 1500 /* typical maximum message size */ 48 #define SNMP_MIN_MAX_LEN 484 /* minimum maximum message size */ 49 #define SNMP_MAX_PACKET_LEN (0x7fffffff) 50 51 /* 52 * SNMP versions 53 */ 54 /* 55 * There currently exists the following SNMP versions. 56 * * (Note that only SNMPv1 is in widespread usage, and this code supports 57 * * only SNMPv1, SNMPv2c, and SNMPv3. 58 * * 59 * * SNMPv1 - (full) the original version, defined by RFC 1157 60 * * SNMPsec - (historic) the first attempt to add strong security 61 * * to SNMPv1, defined by RFCs 1351, 1352, and 1353. 62 * * SNMPv2p - (historic) party-based SNMP, which was another 63 * * attempt to add strong security to SNMP, defined 64 * * by RFCs 1441, 1445, 1446, 1448, and 1449. 65 * * SNMPv2c - (experimental) community string-based SNMPv2, 66 * * which was an attempt to combine the protocol 67 * * operations of SNMPv2 with the security of 68 * * SNMPv1, defined by RFCs 1901, 1905, and 1906. 69 * * SNMPv2u - (experimental) user-based SNMPv2, which provided 70 * * security based on user names and protocol 71 * * operations of SNMPv2, defined by RFCs 1905, 72 * * 1909, and 1910. 73 * * SNMPv2* (or SNMPv2star) - (experimental) an attempt to add the 74 * * best features of SNMPv2p and SNMPv2u, defined 75 * * by unpublished documents found at WEB site 76 * * owned by SNMP Research (a leading SNMP vendor) 77 * * SNMPv3 - the current attempt by the IETF working group to merge 78 * * the SNMPv2u and SNMPv2* proposals into a more widly 79 * * accepted SNMPv3. It is defined by not yet published 80 * * documents of the IETF SNMPv3 WG. 81 * * 82 * * SNMPv1, SNMPv2c, SNMPv2u, and SNMPv3 messages have a common 83 * * form, which is an ASN.1 sequence containing a message version 84 * * field, followed by version dependent fields. 85 * * SNMPsec, SNMPv2p, and SNMPv2* messages have a common form, 86 * * which is a tagged ASN.1 context specific sequence containing 87 * * message dependent fields. 88 * * 89 * * In the #defines for the message versions below, the value 90 * * for SNMPv1, SNMPv2c, SNMPv2u, and SNMPv3 messages is the 91 * * value of the message version field. Since SNMPsec, SNMPv2p, 92 * * and SNMPv2* messages do not have a message version field, 93 * * the value in the defines for them is choosen to be a large 94 * * arbitrary number. 95 * * 96 * * Note that many of the version ID's are defined below purely for 97 * * documentational purposes. At this point the only protocol planned 98 * * for future implementations is SNMP3, as the other v2 protocols will 99 * * not be supported by the IETF (ie, v2u, v2sec, v2star) or used by 100 * * the snmp community at large (at the time of this writing). 101 */ 102 103 /* 104 * versions based on version field 105 */ 106 #ifndef NETSNMP_DISABLE_SNMPV1 107 #define SNMP_VERSION_1 0 108 #endif 109 #ifndef NETSNMP_DISABLE_SNMPV2C 110 #define SNMP_VERSION_2c 1 111 #endif 112 #define SNMP_VERSION_2u 2 /* not (will never be) supported by this code */ 113 #define SNMP_VERSION_3 3 114 115 /* 116 * versions not based on a version field 117 */ 118 #define SNMP_VERSION_sec 128 /* not (will never be) supported by this code */ 119 #define SNMP_VERSION_2p 129 /* no longer supported by this code (> 4.0) */ 120 #define SNMP_VERSION_2star 130 /* not (will never be) supported by this code */ 121 122 /* 123 * PDU types in SNMPv1, SNMPsec, SNMPv2p, SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 124 */ 125 #define SNMP_MSG_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0) /* a0=160 */ 126 #define SNMP_MSG_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1) /* a1=161 */ 127 #define SNMP_MSG_RESPONSE (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2) /* a2=162 */ 128 #ifndef NETSNMP_NO_WRITE_SUPPORT 129 #define SNMP_MSG_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3) /* a3=163 */ 130 #endif /* !NETSNMP_NO_WRITE_SUPPORT */ 131 132 /* 133 * PDU types in SNMPv1 and SNMPsec 134 */ 135 #define SNMP_MSG_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4) /* a4=164 */ 136 137 /* 138 * PDU types in SNMPv2p, SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 139 */ 140 #define SNMP_MSG_GETBULK (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5) /* a5=165 */ 141 #define SNMP_MSG_INFORM (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6) /* a6=166 */ 142 #define SNMP_MSG_TRAP2 (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7) /* a7=167 */ 143 144 /* 145 * PDU types in SNMPv2u, SNMPv2*, and SNMPv3 146 */ 147 #define SNMP_MSG_REPORT (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8) /* a8=168 */ 148 149 #ifndef NETSNMP_NO_WRITE_SUPPORT 150 /* 151 * internal modes that should never be used by the protocol for the 152 * pdu type. 153 * 154 * All modes < 128 are reserved for SET requests. 155 */ 156 #define SNMP_MSG_INTERNAL_SET_BEGIN -1 157 #define SNMP_MSG_INTERNAL_SET_RESERVE1 0 /* these should match snmp.h */ 158 #define SNMP_MSG_INTERNAL_SET_RESERVE2 1 159 #define SNMP_MSG_INTERNAL_SET_ACTION 2 160 #define SNMP_MSG_INTERNAL_SET_COMMIT 3 161 #define SNMP_MSG_INTERNAL_SET_FREE 4 162 #define SNMP_MSG_INTERNAL_SET_UNDO 5 163 #define SNMP_MSG_INTERNAL_SET_MAX 6 164 165 #define SNMP_MSG_INTERNAL_CHECK_VALUE 17 166 #define SNMP_MSG_INTERNAL_ROW_CREATE 18 167 #define SNMP_MSG_INTERNAL_UNDO_SETUP 19 168 #define SNMP_MSG_INTERNAL_SET_VALUE 20 169 #define SNMP_MSG_INTERNAL_CHECK_CONSISTENCY 21 170 #define SNMP_MSG_INTERNAL_UNDO_SET 22 171 #define SNMP_MSG_INTERNAL_COMMIT 23 172 #define SNMP_MSG_INTERNAL_UNDO_COMMIT 24 173 #define SNMP_MSG_INTERNAL_IRREVERSIBLE_COMMIT 25 174 #define SNMP_MSG_INTERNAL_UNDO_CLEANUP 26 175 #endif /* !NETSNMP_NO_WRITE_SUPPORT */ 176 177 /* 178 * modes > 128 for non sets. 179 * Note that 160-168 overlap with SNMP ASN1 pdu types 180 */ 181 #define SNMP_MSG_INTERNAL_PRE_REQUEST 128 182 #define SNMP_MSG_INTERNAL_OBJECT_LOOKUP 129 183 #define SNMP_MSG_INTERNAL_POST_REQUEST 130 184 #define SNMP_MSG_INTERNAL_GET_STASH 131 185 186 /* 187 * test for member of Confirmed Class i.e., reportable 188 */ 189 #ifdef NETSNMP_NO_WRITE_SUPPORT 190 #define SNMP_CMD_CONFIRMED(c) (c == SNMP_MSG_INFORM || c == SNMP_MSG_GETBULK ||\ 191 c == SNMP_MSG_GETNEXT || c == SNMP_MSG_GET ) 192 #else /* !NETSNMP_NO_WRITE_SUPPORT */ 193 #define SNMP_CMD_CONFIRMED(c) (c == SNMP_MSG_INFORM || c == SNMP_MSG_GETBULK ||\ 194 c == SNMP_MSG_GETNEXT || c == SNMP_MSG_GET || \ 195 c == SNMP_MSG_SET ) 196 #endif /* !NETSNMP_NO_WRITE_SUPPORT */ 197 198 /* 199 * Exception values for SNMPv2p, SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 200 */ 201 #define SNMP_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | 0x0) /* 80=128 */ 202 #define SNMP_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | 0x1) /* 81=129 */ 203 #define SNMP_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | 0x2) /* 82=130 */ 204 205 /* 206 * Error codes (the value of the field error-status in PDUs) 207 */ 208 209 /* 210 * in SNMPv1, SNMPsec, SNMPv2p, SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs 211 */ 212 #define SNMP_ERR_NOERROR (0) /* XXX Used only for PDUs? */ 213 #define SNMP_ERR_TOOBIG (1) 214 #define SNMP_ERR_NOSUCHNAME (2) 215 #define SNMP_ERR_BADVALUE (3) 216 #define SNMP_ERR_READONLY (4) 217 #define SNMP_ERR_GENERR (5) 218 219 /* 220 * in SNMPv2p, SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs 221 */ 222 #define SNMP_ERR_NOACCESS (6) 223 #define SNMP_ERR_WRONGTYPE (7) 224 #define SNMP_ERR_WRONGLENGTH (8) 225 #define SNMP_ERR_WRONGENCODING (9) 226 #define SNMP_ERR_WRONGVALUE (10) 227 #define SNMP_ERR_NOCREATION (11) 228 #define SNMP_ERR_INCONSISTENTVALUE (12) 229 #define SNMP_ERR_RESOURCEUNAVAILABLE (13) 230 #define SNMP_ERR_COMMITFAILED (14) 231 #define SNMP_ERR_UNDOFAILED (15) 232 #define SNMP_ERR_AUTHORIZATIONERROR (16) 233 #define SNMP_ERR_NOTWRITABLE (17) 234 235 /* 236 * in SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs 237 */ 238 #define SNMP_ERR_INCONSISTENTNAME (18) 239 240 #define MAX_SNMP_ERR 18 241 242 #define SNMP_VALIDATE_ERR(x) ( (x > MAX_SNMP_ERR) ? \ 243 SNMP_ERR_GENERR : \ 244 (x < SNMP_ERR_NOERROR) ? \ 245 SNMP_ERR_GENERR : \ 246 x ) 247 248 /* 249 * values of the generic-trap field in trap PDUs 250 */ 251 #define SNMP_TRAP_COLDSTART (0) 252 #define SNMP_TRAP_WARMSTART (1) 253 #define SNMP_TRAP_LINKDOWN (2) 254 #define SNMP_TRAP_LINKUP (3) 255 #define SNMP_TRAP_AUTHFAIL (4) 256 #define SNMP_TRAP_EGPNEIGHBORLOSS (5) 257 #define SNMP_TRAP_ENTERPRISESPECIFIC (6) 258 259 /* 260 * row status values 261 */ 262 #define SNMP_ROW_NONEXISTENT 0 263 #define SNMP_ROW_ACTIVE 1 264 #define SNMP_ROW_NOTINSERVICE 2 265 #define SNMP_ROW_NOTREADY 3 266 #define SNMP_ROW_CREATEANDGO 4 267 #define SNMP_ROW_CREATEANDWAIT 5 268 #define SNMP_ROW_DESTROY 6 269 270 /* 271 * row storage values 272 */ 273 #define SNMP_STORAGE_NONE 0 274 #define SNMP_STORAGE_OTHER 1 275 #define SNMP_STORAGE_VOLATILE 2 276 #define SNMP_STORAGE_NONVOLATILE 3 277 #define SNMP_STORAGE_PERMANENT 4 278 #define SNMP_STORAGE_READONLY 5 279 280 /* 281 * message processing models 282 */ 283 #define SNMP_MP_MODEL_SNMPv1 0 284 #define SNMP_MP_MODEL_SNMPv2c 1 285 #define SNMP_MP_MODEL_SNMPv2u 2 286 #define SNMP_MP_MODEL_SNMPv3 3 287 #define SNMP_MP_MODEL_SNMPv2p 256 288 289 /* 290 * security values 291 */ 292 #define SNMP_SEC_MODEL_ANY 0 293 #define SNMP_SEC_MODEL_SNMPv1 1 294 #define SNMP_SEC_MODEL_SNMPv2c 2 295 #define SNMP_SEC_MODEL_USM 3 296 #define SNMP_SEC_MODEL_TSM 4 297 #define SNMP_SEC_MODEL_SNMPv2p 256 298 299 #define SNMP_SEC_LEVEL_NOAUTH 1 300 #define SNMP_SEC_LEVEL_AUTHNOPRIV 2 301 #define SNMP_SEC_LEVEL_AUTHPRIV 3 302 303 #define SNMP_MSG_FLAG_AUTH_BIT 0x01 304 #define SNMP_MSG_FLAG_PRIV_BIT 0x02 305 #define SNMP_MSG_FLAG_RPRT_BIT 0x04 306 307 /* 308 * control PDU handling characteristics 309 */ 310 /** NOTE low byte used for AGENTX_MSG_FLAG_* */ 311 #define UCD_MSG_FLAG_RESPONSE_PDU 0x100 312 #define UCD_MSG_FLAG_EXPECT_RESPONSE 0x200 313 #define UCD_MSG_FLAG_FORCE_PDU_COPY 0x400 314 #define UCD_MSG_FLAG_ALWAYS_IN_VIEW 0x800 315 #define UCD_MSG_FLAG_PDU_TIMEOUT 0x1000 316 #define UCD_MSG_FLAG_ONE_PASS_ONLY 0x2000 317 #define UCD_MSG_FLAG_TUNNELED 0x4000 318 #ifdef NETSNMP_USE_REVERSE_ASNENCODING 319 #define UCD_MSG_FLAG_FORWARD_ENCODE 0x8000 320 #endif 321 #define UCD_MSG_FLAG_BULK_TOOBIG 0x010000 322 323 /* 324 * view status 325 */ 326 #define SNMP_VIEW_INCLUDED 1 327 #define SNMP_VIEW_EXCLUDED 2 328 329 /* 330 * basic oid values 331 */ 332 #define SNMP_OID_INTERNET 1, 3, 6, 1 333 #define SNMP_OID_ENTERPRISES SNMP_OID_INTERNET, 4, 1 334 #define SNMP_OID_MIB2 SNMP_OID_INTERNET, 2, 1 335 #define SNMP_OID_SNMPV2 SNMP_OID_INTERNET, 6 336 #define SNMP_OID_SNMPMODULES SNMP_OID_SNMPV2, 3 337 338 /* 339 * lengths as defined by TCs 340 */ 341 #define SNMPADMINLENGTH 255 342 343 344 NETSNMP_IMPORT 345 char *uptime_string(u_long, char *); 346 char *uptime_string_n(u_long, char *, size_t); 347 NETSNMP_IMPORT 348 void xdump(const void *, size_t, const char *); 349 NETSNMP_IMPORT 350 u_char *snmp_parse_var_op(u_char *, oid *, size_t *, u_char *, 351 size_t *, u_char **, size_t *); 352 NETSNMP_IMPORT 353 u_char *snmp_build_var_op(u_char *, oid *, size_t *, u_char, 354 size_t, u_char *, size_t *); 355 356 357 #ifdef NETSNMP_USE_REVERSE_ASNENCODING 358 int snmp_realloc_rbuild_var_op(u_char ** pkt, 359 size_t * pkt_len, 360 size_t * offset, 361 int allow_realloc, 362 const oid * name, 363 size_t * name_len, 364 u_char value_type, 365 u_char * value, 366 size_t value_length); 367 #endif 368 369 #ifdef __cplusplus 370 } 371 #endif 372 #endif /* SNMP_H */ 373