snmpagent.h revision 128237
1122394Sharti/*
2122394Sharti * Copyright (c) 2001-2003
3122394Sharti *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4122394Sharti *	All rights reserved.
5122394Sharti *
6122394Sharti * Author: Harti Brandt <harti@freebsd.org>
7122394Sharti *
8122394Sharti * Redistribution of this software and documentation and use in source and
9122394Sharti * binary forms, with or without modification, are permitted provided that
10122394Sharti * the following conditions are met:
11122394Sharti *
12122394Sharti * 1. Redistributions of source code or documentation must retain the above
13122394Sharti *    copyright notice, this list of conditions and the following disclaimer.
14122394Sharti * 2. Redistributions in binary form must reproduce the above copyright
15122394Sharti *    notice, this list of conditions and the following disclaimer in the
16122394Sharti *    documentation and/or other materials provided with the distribution.
17122394Sharti * 3. Neither the name of the Institute nor the names of its contributors
18122394Sharti *    may be used to endorse or promote products derived from this software
19122394Sharti *    without specific prior written permission.
20122394Sharti *
21122394Sharti * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS
22122394Sharti * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23122394Sharti * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
24122394Sharti * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
25122394Sharti * FRAUNHOFER FOKUS OR ITS CONTRIBUTORS  BE LIABLE FOR ANY DIRECT, INDIRECT,
26122394Sharti * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27122394Sharti * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28122394Sharti * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29122394Sharti * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30122394Sharti * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31122394Sharti * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32122394Sharti *
33128237Sharti * $Begemot: bsnmp/lib/snmpagent.h,v 1.12 2004/04/13 15:18:15 novo Exp $
34122394Sharti *
35122394Sharti * Header file for SNMP functions. This requires snmp.h to be included.
36122394Sharti */
37122394Sharti#ifndef snmp_agent_h_
38122394Sharti#define snmp_agent_h_
39122394Sharti
40122394Shartistruct snmp_dependency;
41122394Sharti
42128237Shartienum snmp_ret {
43128237Sharti	/* OK, generate a response */
44128237Sharti	SNMP_RET_OK	= 0,
45128237Sharti	/* Error, ignore packet (no response) */
46128237Sharti	SNMP_RET_IGN	= 1,
47128237Sharti	/* Error, generate response from original packet */
48128237Sharti	SNMP_RET_ERR	= 2
49128237Sharti};
50128237Sharti
51122394Sharti/* Semi-Opaque object for SET operations */
52122394Shartistruct snmp_context {
53122394Sharti	u_int	var_index;
54122394Sharti	struct snmp_scratch *scratch;
55122394Sharti	struct snmp_dependency *dep;
56122394Sharti	void	*data;		/* user data */
57128237Sharti	enum snmp_ret code;	/* return code */
58122394Sharti};
59122394Sharti
60122394Shartistruct snmp_scratch {
61122394Sharti	void		*ptr1;
62122394Sharti	void		*ptr2;
63122394Sharti	u_int32_t	int1;
64122394Sharti	u_int32_t	int2;
65122394Sharti};
66122394Sharti
67122394Shartienum snmp_depop {
68122394Sharti	SNMP_DEPOP_COMMIT,
69128237Sharti	SNMP_DEPOP_ROLLBACK,
70128237Sharti	SNMP_DEPOP_FINISH
71122394Sharti};
72122394Sharti
73122394Shartitypedef int (*snmp_depop_t)(struct snmp_context *, struct snmp_dependency *,
74122394Sharti    enum snmp_depop);
75122394Sharti
76122394Shartistruct snmp_dependency {
77122394Sharti	struct asn_oid	obj;
78122394Sharti	struct asn_oid	idx;
79122394Sharti};
80122394Sharti
81122394Sharti/*
82122394Sharti * The TREE
83122394Sharti */
84122394Shartienum snmp_node_type {
85122394Sharti	SNMP_NODE_LEAF = 1,
86122394Sharti	SNMP_NODE_COLUMN
87122394Sharti};
88122394Sharti
89122394Shartienum snmp_op {
90122394Sharti	SNMP_OP_GET 	= 1,
91122394Sharti	SNMP_OP_GETNEXT,
92122394Sharti	SNMP_OP_SET,
93122394Sharti	SNMP_OP_COMMIT,
94122394Sharti	SNMP_OP_ROLLBACK,
95122394Sharti};
96122394Sharti
97122394Shartitypedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *,
98122394Sharti    u_int, u_int, enum snmp_op);
99122394Sharti
100122394Shartistruct snmp_node {
101122394Sharti	struct asn_oid oid;
102122394Sharti	const char	*name;		/* name of the leaf */
103122394Sharti	enum snmp_node_type type;	/* type of this node */
104122394Sharti	enum snmp_syntax syntax;
105122394Sharti	snmp_op_t	op;
106122394Sharti	u_int		flags;
107122394Sharti	u_int32_t	index;		/* index data */
108122394Sharti	void		*data;		/* application data */
109128237Sharti	void		*tree_data;	/* application data */
110122394Sharti};
111122394Shartiextern struct snmp_node *tree;
112122394Shartiextern u_int  tree_size;
113122394Sharti
114122394Sharti#define SNMP_NODE_CANSET	0x0001	/* SET allowed */
115122394Sharti
116122394Sharti#define SNMP_INDEXES_MAX	7
117122394Sharti#define SNMP_INDEX_SHIFT	4
118122394Sharti#define SNMP_INDEX_MASK	0xf
119122394Sharti#define SNMP_INDEX_COUNT(V)	((V) & SNMP_INDEX_MASK)
120122394Sharti#define SNMP_INDEX(V,I) \
121122394Sharti	(((V) >> (((I) + 1) * SNMP_INDEX_SHIFT)) & SNMP_INDEX_MASK)
122122394Sharti
123122394Shartienum {
124122394Sharti	SNMP_TRACE_GET		= 0x00000001,
125122394Sharti	SNMP_TRACE_GETNEXT	= 0x00000002,
126122394Sharti	SNMP_TRACE_SET		= 0x00000004,
127122394Sharti	SNMP_TRACE_DEPEND	= 0x00000008,
128122394Sharti	SNMP_TRACE_FIND		= 0x00000010,
129122394Sharti};
130122394Sharti/* trace flag for the following functions */
131122394Shartiextern u_int snmp_trace;
132122394Sharti
133122394Sharti/* called to write the trace */
134122394Shartiextern void (*snmp_debug)(const char *fmt, ...);
135122394Sharti
136122394Shartienum snmp_ret snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b,
137122394Sharti    struct snmp_pdu *resp, void *);
138122394Shartienum snmp_ret snmp_getnext(struct snmp_pdu *pdu, struct asn_buf *resp_b,
139122394Sharti    struct snmp_pdu *resp, void *);
140122394Shartienum snmp_ret snmp_getbulk(struct snmp_pdu *pdu, struct asn_buf *resp_b,
141122394Sharti    struct snmp_pdu *resp, void *);
142122394Shartienum snmp_ret snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b,
143122394Sharti    struct snmp_pdu *resp, void *);
144122394Sharti
145122394Shartienum snmp_ret snmp_make_errresp(const struct snmp_pdu *, struct asn_buf *,
146122394Sharti    struct asn_buf *);
147122394Sharti
148122394Shartistruct snmp_dependency *snmp_dep_lookup(struct snmp_context *,
149122394Sharti    const struct asn_oid *, const struct asn_oid *, size_t, snmp_depop_t);
150122394Sharti
151122394Shartistruct snmp_context *snmp_init_context(void);
152122394Shartiint snmp_dep_commit(struct snmp_context *);
153122394Shartiint snmp_dep_rollback(struct snmp_context *);
154128237Shartivoid snmp_dep_finish(struct snmp_context *);
155122394Sharti
156122394Sharti#endif
157