Annotation of src/usr.bin/snmp/snmp.h, Revision 1.2
1.2 ! martijn 1: /* $OpenBSD: snmp.h,v 1.1 2019/08/09 06:17:59 martijn Exp $ */
1.1 martijn 2:
3: /*
4: * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org>
5: * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
6: *
7: * Permission to use, copy, modify, and distribute this software for any
8: * purpose with or without fee is hereby granted, provided that the above
9: * copyright notice and this permission notice appear in all copies.
10: *
11: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18: */
19:
20: #ifndef SNMPD_SNMP_H
21: #define SNMPD_SNMP_H
22:
23: #include <sys/types.h>
24: #include <sys/queue.h>
25: #include <endian.h>
26:
27: #include <time.h>
28:
29: #define READ_BUF_SIZE 65535
30:
31: #define SNMP_MAX_OID_STRLEN 128 /* max size of the OID _string_ */
32:
33: /*
34: * SNMP BER types
35: */
36:
37: enum snmp_version {
38: SNMP_V1 = 0,
39: SNMP_V2C = 1, /* SNMPv2c */
40: SNMP_V3 = 3
41: };
42:
43: enum snmp_context {
44: SNMP_C_GETREQ = 0,
45: SNMP_C_GETNEXTREQ = 1,
46: SNMP_C_GETRESP = 2,
47: SNMP_C_SETREQ = 3,
48: SNMP_C_TRAP = 4,
49:
50: /* SNMPv2 */
51: SNMP_C_GETBULKREQ = 5,
52: SNMP_C_INFORMREQ = 6,
53: SNMP_C_TRAPV2 = 7,
54: SNMP_C_REPORT = 8
55: };
56:
57: enum snmp_application {
58: SNMP_T_IPADDR = 0,
59: SNMP_T_COUNTER32 = 1,
60: SNMP_T_GAUGE32 = 2,
61: SNMP_T_UNSIGNED32 = 2,
62: SNMP_T_TIMETICKS = 3,
63: SNMP_T_OPAQUE = 4,
64: SNMP_T_NSAPADDR = 5,
65: SNMP_T_COUNTER64 = 6,
66: SNMP_T_UINTEGER32 = 7
67: };
68:
69: enum snmp_generic_trap {
70: SNMP_TRAP_COLDSTART = 0,
71: SNMP_TRAP_WARMSTART = 1,
72: SNMP_TRAP_LINKDOWN = 2,
73: SNMP_TRAP_LINKUP = 3,
74: SNMP_TRAP_AUTHFAILURE = 4,
75: SNMP_TRAP_EGPNEIGHLOSS = 5,
76: SNMP_TRAP_ENTERPRISE = 6
77: };
78:
79: enum snmp_error {
80: SNMP_ERROR_NONE = 0,
81: SNMP_ERROR_TOOBIG = 1,
82: SNMP_ERROR_NOSUCHNAME = 2,
83: SNMP_ERROR_BADVALUE = 3,
84: SNMP_ERROR_READONLY = 4,
85: SNMP_ERROR_GENERR = 5,
86:
87: /* SNMPv2 */
88: SNMP_ERROR_NOACCESS = 6,
89: SNMP_ERROR_WRONGTYPE = 7,
90: SNMP_ERROR_WRONGLENGTH = 8,
91: SNMP_ERROR_WRONGENC = 9,
92: SNMP_ERROR_WRONGVALUE = 10,
93: SNMP_ERROR_NOCREATION = 11,
94: SNMP_ERROR_INCONVALUE = 12,
95: SNMP_ERROR_RESUNAVAIL = 13, /* EGAIN */
96: SNMP_ERROR_COMMITFAILED = 14,
97: SNMP_ERROR_UNDOFAILED = 15,
98: SNMP_ERROR_AUTHERROR = 16,
99: SNMP_ERROR_NOTWRITABLE = 17,
100: SNMP_ERROR_INCONNAME = 18
101: };
102:
103: enum snmp_security_model {
104: SNMP_SEC_ANY = 0,
105: SNMP_SEC_SNMPv1 = 1,
106: SNMP_SEC_SNMPv2c = 2,
107: SNMP_SEC_USM = 3,
108: SNMP_SEC_TSM = 4
109: };
110:
111: struct snmp_agent {
112: int fd;
113: enum snmp_version version;
114: char *community;
115: int timeout;
116: int retries;
117: };
118:
119: #define SNMP_MSGFLAG_AUTH 0x01
120: #define SNMP_MSGFLAG_PRIV 0x02
121: #define SNMP_MSGFLAG_SECMASK (SNMP_MSGFLAG_AUTH | SNMP_MSGFLAG_PRIV)
122: #define SNMP_MSGFLAG_REPORT 0x04
123:
124: #define SNMP_MAX_TIMEWINDOW 150 /* RFC3414 */
125:
126: struct snmp_agent *snmp_connect_v12(int, enum snmp_version, const char *);
127: void snmp_free_agent(struct snmp_agent *);
128: struct ber_element *
129: snmp_get(struct snmp_agent *agent, struct ber_oid *oid, size_t len);
130: struct ber_element *snmp_getnext(struct snmp_agent *, struct ber_oid *, size_t);
131: struct ber_element *
132: snmp_getbulk(struct snmp_agent *, struct ber_oid *, size_t, int, int);
133: int snmp_trap(struct snmp_agent *, struct timespec *, struct ber_oid *,
134: struct ber_element *);
1.2 ! martijn 135:
! 136: ssize_t ber_copy_writebuf(struct ber *, void **);
1.1 martijn 137:
138: #endif /* SNMPD_SNMP_H */