xref: /openbsd/usr.sbin/snmpd/snmp.h (revision c3e23a03)
1 /*	$OpenBSD: snmp.h,v 1.21 2024/02/08 17:34:09 martijn Exp $	*/
2 
3 /*
4  * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef SNMPD_SNMP_H
20 #define SNMPD_SNMP_H
21 
22 #include <sys/types.h>
23 
24 /*
25  * SNMP IMSG interface
26  */
27 
28 #define SNMP_MAX_OID_STRLEN	128	/* max size of the OID _string_ */
29 
30 enum snmp_type {
31 	SNMP_IPADDR		= 0,
32 	SNMP_COUNTER32		= 1,
33 	SNMP_GAUGE32		= 2,
34 	SNMP_UNSIGNED32		= 2,
35 	SNMP_TIMETICKS		= 3,
36 	SNMP_OPAQUE		= 4,
37 	SNMP_NSAPADDR		= 5,
38 	SNMP_COUNTER64		= 6,
39 	SNMP_UINTEGER32		= 7,
40 
41 	SNMP_INTEGER32		= 100,
42 	SNMP_BITSTRING		= 101,
43 	SNMP_OCTETSTRING	= 102,
44 	SNMP_NULL		= 103,
45 	SNMP_OBJECT		= 104
46 };
47 
48 enum snmp_imsg_ctl {
49 	IMSG_SNMP_DUMMY		= 1000,	/* something that works everywhere */
50 	IMSG_SNMP_ELEMENT,
51 	IMSG_SNMP_END,
52 	IMSG_SNMP_LOCK,			/* enable restricted mode */
53 };
54 
55 struct snmp_imsg_hdr {
56 	u_int32_t	 imsg_type;
57 	u_int16_t	 imsg_len;
58 	u_int16_t	 imsg_flags;
59 	u_int32_t	 imsg_peerid;
60 	u_int32_t	 imsg_pid;
61 };
62 
63 struct snmp_imsg {
64 	char		 snmp_oid[SNMP_MAX_OID_STRLEN];
65 	u_int8_t	 snmp_type;
66 	u_int16_t	 snmp_len;
67 };
68 
69 /*
70  * SNMP BER types
71  */
72 
73 enum snmp_version {
74 	SNMP_V1			= 0,
75 	SNMP_V2			= 1,	/* SNMPv2c */
76 	SNMP_V3			= 3
77 };
78 
79 enum snmp_pdutype {
80 	SNMP_C_GETREQ		= 0,
81 	SNMP_C_GETNEXTREQ	= 1,
82 	SNMP_C_RESPONSE		= 2,
83 	SNMP_C_SETREQ		= 3,
84 	SNMP_C_TRAP		= 4,
85 
86 	/* SNMPv2 */
87 	SNMP_C_GETBULKREQ	= 5,
88 	SNMP_C_INFORMREQ	= 6,
89 	SNMP_C_TRAPV2		= 7,
90 	SNMP_C_REPORT		= 8
91 };
92 
93 enum snmp_varbindtype {
94 	SNMP_V_NOSUCHOBJECT	= 0,
95 	SNMP_V_NOSUCHINSTANCE	= 1,
96 	SNMP_V_ENDOFMIBVIEW	= 2
97 };
98 
99 enum snmp_application {
100 	SNMP_T_IPADDR		= 0,
101 	SNMP_T_COUNTER32	= 1,
102 	SNMP_T_GAUGE32		= 2,
103 	SNMP_T_UNSIGNED32	= 2,
104 	SNMP_T_TIMETICKS	= 3,
105 	SNMP_T_OPAQUE		= 4,
106 	SNMP_T_NSAPADDR		= 5,
107 	SNMP_T_COUNTER64	= 6,
108 	SNMP_T_UINTEGER32	= 7
109 };
110 
111 enum snmp_generic_trap {
112 	SNMP_TRAP_COLDSTART	= 0,
113 	SNMP_TRAP_WARMSTART	= 1,
114 	SNMP_TRAP_LINKDOWN	= 2,
115 	SNMP_TRAP_LINKUP	= 3,
116 	SNMP_TRAP_AUTHFAILURE	= 4,
117 	SNMP_TRAP_EGPNEIGHLOSS	= 5,
118 	SNMP_TRAP_ENTERPRISE	= 6
119 };
120 
121 enum snmp_error {
122 	SNMP_ERROR_NONE		= 0,
123 	SNMP_ERROR_TOOBIG	= 1,
124 	SNMP_ERROR_NOSUCHNAME	= 2,
125 	SNMP_ERROR_BADVALUE	= 3,
126 	SNMP_ERROR_READONLY	= 4,
127 	SNMP_ERROR_GENERR	= 5,
128 
129 	/* SNMPv2 */
130 	SNMP_ERROR_NOACCESS	= 6,
131 	SNMP_ERROR_WRONGTYPE	= 7,
132 	SNMP_ERROR_WRONGLENGTH	= 8,
133 	SNMP_ERROR_WRONGENC	= 9,
134 	SNMP_ERROR_WRONGVALUE	= 10,
135 	SNMP_ERROR_NOCREATION	= 11,
136 	SNMP_ERROR_INCONVALUE	= 12,
137 	SNMP_ERROR_RESUNAVAIL	= 13, /* EGAIN */
138 	SNMP_ERROR_COMMITFAILED	= 14,
139 	SNMP_ERROR_UNDOFAILED	= 15,
140 	SNMP_ERROR_AUTHERROR	= 16,
141 	SNMP_ERROR_NOTWRITABLE	= 17,
142 	SNMP_ERROR_INCONNAME	= 18
143 };
144 
145 enum snmp_security_model {
146 	SNMP_SEC_ANY = 0,
147 	SNMP_SEC_SNMPv1 = 1,
148 	SNMP_SEC_SNMPv2c = 2,
149 	SNMP_SEC_USM = 3,
150 	SNMP_SEC_TSM = 4
151 };
152 
153 #define SNMP_MSGFLAG_AUTH	0x01
154 #define SNMP_MSGFLAG_PRIV	0x02
155 #define SNMP_MSGFLAG_SECMASK	(SNMP_MSGFLAG_AUTH | SNMP_MSGFLAG_PRIV)
156 #define SNMP_MSGFLAG_REPORT	0x04
157 
158 #define SNMP_MAX_TIMEWINDOW	150	/* RFC3414 */
159 
160 /* RFC2578 */
161 #define SMI_INTEGER_MIN		INT32_MIN
162 #define SMI_INTEGER_MAX		INT32_MAX
163 #define SMI_OCTETSTRING_MAX	65535
164 #define SMI_IPADDRESS_MAX	4
165 #define SMI_COUNTER32_MIN	0
166 #define SMI_COUNTER32_MAX	UINT32_MAX
167 #define SMI_GAUGE32_MIN		0
168 #define SMI_GAUGE32_MAX		UINT32_MAX
169 #define SMI_TIMETICKS_MIN	0
170 #define SMI_TIMETICKS_MAX	UINT32_MAX
171 
172 
173 #endif /* SNMPD_SNMP_H */
174