xref: /openbsd/usr.bin/snmp/smi.h (revision dd843e54)
1 /*	$OpenBSD: smi.h,v 1.4 2020/12/14 07:44:26 martijn Exp $	*/
2 
3 /*
4  * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org>
5  * Copyright (c) 2007, 2008 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 #include <sys/tree.h>
21 #include <sys/queue.h>
22 
23 #define OID_ROOT		0x00
24 #define OID_RD			0x01
25 #define OID_WR			0x02
26 #define OID_IFSET		0x04	/* only if user-specified value */
27 #define OID_DYNAMIC		0x08	/* free allocated data */
28 #define OID_TABLE		0x10	/* dynamic sub-elements */
29 #define OID_MIB			0x20	/* root-OID of a supported MIB */
30 #define OID_KEY			0x40	/* lookup tables */
31 #define	OID_REGISTERED		0x80	/* OID registered by subagent */
32 
33 #define OID_RS			(OID_RD|OID_IFSET)
34 #define OID_WS			(OID_WR|OID_IFSET)
35 #define OID_RW			(OID_RD|OID_WR)
36 #define OID_RWS			(OID_RW|OID_IFSET)
37 
38 #define OID_TRD			(OID_RD|OID_TABLE)
39 #define OID_TWR			(OID_WR|OID_TABLE)
40 #define OID_TRS			(OID_RD|OID_IFSET|OID_TABLE)
41 #define OID_TWS			(OID_WR|OID_IFSET|OID_TABLE)
42 #define OID_TRW			(OID_RD|OID_WR|OID_TABLE)
43 #define OID_TRWS		(OID_RW|OID_IFSET|OID_TABLE)
44 
45 enum smi_output_string {
46 	smi_os_default,
47 	smi_os_hex,
48 	smi_os_ascii
49 };
50 
51 enum smi_oid_lookup {
52 	smi_oidl_numeric,
53 	smi_oidl_short,
54 	smi_oidl_full
55 };
56 
57 struct oid {
58 	struct ber_oid		 o_id;
59 #define o_oid			 o_id.bo_id
60 #define o_oidlen		 o_id.bo_n
61 
62 	const char		*o_name;
63 	const char		*o_tcname;
64 	struct textconv		*o_textconv;
65 
66 	RB_ENTRY(oid)		 o_element;
67 	RB_ENTRY(oid)		 o_keyword;
68 };
69 
70 struct textconv_enum {
71 	uint32_t		 tce_number;
72 	const char		*tce_name;
73 };
74 
75 struct textconv {
76 	const char		*tc_name;
77 	unsigned int		 tc_syntax;
78 	const char		*tc_display_hint;
79 	struct textconv_enum	*tc_enum;
80 	RB_ENTRY(textconv)	 tc_entry;
81 };
82 
83 int smi_init(void);
84 unsigned int smi_application(struct ber_element *);
85 int smi_string2oid(const char *, struct ber_oid *);
86 char *smi_oid2string(struct ber_oid *, char *, size_t, enum smi_oid_lookup);
87 void smi_mibtree(struct oid *);
88 void smi_textconvtree(struct textconv *);
89 struct oid *smi_foreach(struct oid *);
90 void smi_debug_elements(struct ber_element *, int);
91 char *smi_print_element(struct ber_oid *, struct ber_element *, int,
92     enum smi_output_string, enum smi_oid_lookup, int);
93