1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _PDU_H 28 #define _PDU_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 typedef uint_t oid; 37 38 /* 39 * SNMP PDU variable list 40 */ 41 typedef struct pdu_varlist { 42 struct pdu_varlist *nextvar; 43 oid *name; 44 size_t name_len; /* number of subids in the name */ 45 union { 46 uint_t *uiptr; /* unused except while parsing */ 47 int *iptr; 48 uchar_t *str; 49 oid *objid; 50 } val; 51 size_t val_len; /* in bytes even if val is objid */ 52 uchar_t type; 53 } pdu_varlist_t; 54 55 /* 56 * Essential snmp message/PDU fields 57 */ 58 typedef struct snmp_pdu { 59 int version; 60 uchar_t *community; 61 size_t community_len; 62 int command; 63 int reqid; 64 int errstat; /* shared with non-repeaters for GETBULK */ 65 int errindex; /* shared with max-repetitions for GETBULK */ 66 pdu_varlist_t *vars; 67 68 uchar_t *req_pkt; /* not really part of PDU */ 69 size_t req_pktsz; /* not really part of PDU */ 70 uchar_t *reply_pkt; /* not really part of PDU */ 71 size_t reply_pktsz; /* not really part of PDU */ 72 } snmp_pdu_t; 73 #define non_repeaters errstat 74 #define max_repetitions errindex 75 76 /* 77 * Supported SNMP versions 78 */ 79 #define SNMP_VERSION_1 0 80 #define SNMP_VERSION_2c 1 81 82 /* 83 * Community strings for supported PDUs 84 */ 85 #define SNMP_DEF_COMMUNITY "public" 86 #define SNMP_DEF_COMMUNITY_LEN 6 87 88 /* 89 * PDU types (not all are supported) 90 */ 91 #define SNMP_MSG_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x0) 92 #define SNMP_MSG_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x1) 93 #define SNMP_MSG_RESPONSE (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x2) 94 #define SNMP_MSG_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x3) 95 #define SNMP_MSG_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x4) 96 #define SNMP_MSG_GETBULK (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x5) 97 #define SNMP_MSG_INFORM (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x6) 98 #define SNMP_MSG_TRAP2 (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x7) 99 #define SNMP_MSG_REPORT (ASN_CONTEXT | ASN_CONSTRUCTOR | (uchar_t)0x8) 100 101 /* 102 * Exception values (not all are supported) 103 */ 104 #define SNMP_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | (uchar_t)0x0) 105 #define SNMP_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | (uchar_t)0x1) 106 #define SNMP_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | (uchar_t)0x2) 107 108 /* 109 * Error codes (not all are supported) 110 */ 111 #define SNMP_ERR_NOERROR (0) 112 #define SNMP_ERR_TOOBIG (1) 113 #define SNMP_ERR_NOSUCHNAME (2) 114 #define SNMP_ERR_BADVALUE (3) 115 #define SNMP_ERR_READONLY (4) 116 #define SNMP_ERR_GENERR (5) 117 #define SNMP_ERR_NOACCESS (6) 118 #define SNMP_ERR_WRONGTYPE (7) 119 #define SNMP_ERR_WRONGLENGTH (8) 120 #define SNMP_ERR_WRONGENCODING (9) 121 #define SNMP_ERR_WRONGVALUE (10) 122 #define SNMP_ERR_NOCREATION (11) 123 #define SNMP_ERR_INCONSISTENTVALUE (12) 124 #define SNMP_ERR_RESOURCEUNAVAILABLE (13) 125 #define SNMP_ERR_COMMITFAILED (14) 126 #define SNMP_ERR_UNDOFAILED (15) 127 #define SNMP_ERR_AUTHORIZATIONERROR (16) 128 #define SNMP_ERR_NOTWRITABLE (17) 129 #define SNMP_ERR_INCONSISTENTNAME (18) 130 131 /* 132 * Default values 133 */ 134 #define SNMP_DEF_NON_REPEATERS 0 135 #define SNMP_DEF_MAX_REPETITIONS 25 136 #define SNMP_DEF_PKTBUF_SZ 2048 137 #define SNMP_PKTBUF_BLKSZ 1024 138 #define SNMP_MAX_ERR 18 139 #define MIN_SUBIDS_IN_OID 2 140 #define MAX_SUBIDS_IN_OID 128 141 142 /* 143 * Exported interfaces used by other parts of snmplib 144 */ 145 snmp_pdu_t *snmp_create_pdu(int, int, char *, int, int); 146 int snmp_make_packet(snmp_pdu_t *); 147 snmp_pdu_t *snmp_parse_reply(int, uchar_t *, size_t); 148 void snmp_free_pdu(snmp_pdu_t *); 149 150 /* 151 * Imported from elsewhere 152 */ 153 int snmp_get_reqid(void); 154 155 #ifdef __cplusplus 156 } 157 #endif 158 159 #endif /* _PDU_H */ 160