snmpd.h revision 124861
1/*
2 * Copyright (c) 2001-2003
3 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4 *	All rights reserved.
5 *
6 * Author: Harti Brandt <harti@freebsd.org>
7 *
8 * Redistribution of this software and documentation and use in source and
9 * binary forms, with or without modification, are permitted provided that
10 * the following conditions are met:
11 *
12 * 1. Redistributions of source code or documentation must retain the above
13 *    copyright notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS
22 * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
25 * FRAUNHOFER FOKUS OR ITS CONTRIBUTORS  BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * $Begemot: bsnmp/snmpd/snmpd.h,v 1.23 2003/12/09 12:28:53 hbb Exp $
34 *
35 * Private SNMPd data and functions.
36 */
37#include <sys/queue.h>
38#ifdef USE_LIBBEGEMOT
39#include <rpoll.h>
40#else
41#include <isc/eventlib.h>
42#endif
43
44#define PATH_SYSCONFIG "/etc:/usr/etc:/usr/local/etc"
45
46#ifdef USE_LIBBEGEMOT
47#define	evTimerID	int
48#define	evFileID	int
49#endif
50
51/*************************************************************
52 *
53 * Communities
54 */
55struct community {
56	struct lmodule *owner;	/* who created the community */
57	u_int		private;/* private name for the module */
58	u_int		value;	/* value of this community */
59	u_char *	string;	/* the community string */
60	const u_char *	descr;	/* description */
61	TAILQ_ENTRY(community) link;
62
63	struct asn_oid	index;
64};
65/* list of all known communities */
66extern TAILQ_HEAD(community_list, community) community_list;
67
68/*************************************************************
69 *
70 * Request IDs.
71 */
72struct idrange {
73	u_int		type;	/* type id */
74	int32_t		base;	/* base of this range */
75	int32_t		size;	/* size of this range */
76	int32_t		next;	/* generator */
77	struct lmodule *owner;	/* owner module */
78	TAILQ_ENTRY(idrange) link;
79};
80
81/* list of all known ranges */
82extern TAILQ_HEAD(idrange_list, idrange) idrange_list;
83
84/* identifier generator */
85extern u_int next_idrange;
86
87/* request id generator for traps */
88extern u_int trap_reqid;
89
90/*************************************************************
91 *
92 * Timers
93 */
94struct timer {
95	void	(*func)(void *);/* user function */
96	void	*udata;		/* user data */
97	evTimerID id;		/* timer id */
98	struct lmodule *owner;	/* owner of the timer */
99	LIST_ENTRY(timer) link;
100};
101
102/* list of all current timers */
103extern LIST_HEAD(timer_list, timer) timer_list;
104
105
106/*************************************************************
107 *
108 * File descriptors
109 */
110struct fdesc {
111	int	fd;		/* the file descriptor */
112	void	(*func)(int, void *);/* user function */
113	void	*udata;		/* user data */
114	evFileID id;		/* file id */
115	struct lmodule *owner;	/* owner module of the file */
116	LIST_ENTRY(fdesc) link;
117};
118
119/* list of all current selected files */
120extern LIST_HEAD(fdesc_list, fdesc) fdesc_list;
121
122/*************************************************************
123 *
124 * Loadable modules
125 */
126# define LM_SECTION_MAX	14
127struct lmodule {
128	char		section[LM_SECTION_MAX + 1]; /* and index */
129	char		*path;
130	u_int		flags;
131	void		*handle;
132	const struct snmp_module *config;
133
134	TAILQ_ENTRY(lmodule) link;
135	TAILQ_ENTRY(lmodule) start;
136
137	struct asn_oid	index;
138};
139#define LM_STARTED	0x0001
140#define LM_ONSTARTLIST	0x0002
141
142extern TAILQ_HEAD(lmodules, lmodule) lmodules;
143
144struct lmodule *lm_load(const char *, const char *);
145void lm_unload(struct lmodule *);
146void lm_start(struct lmodule *);
147
148/*************************************************************
149 *
150 * SNMP ports
151 */
152/*
153 * Common input stuff
154 */
155struct port_input {
156	int		fd;		/* socket */
157	void		*id;		/* evSelect handle */
158
159	int		stream : 1;	/* stream socket */
160	int		cred : 1;	/* want credentials */
161
162	struct sockaddr	*peer;		/* last received packet */
163	socklen_t	peerlen;
164	int		priv : 1;	/* peer is privileged */
165
166	u_char		*buf;		/* receive buffer */
167	size_t		buflen;		/* buffer length */
168	size_t		length;		/* received length */
169	size_t		consumed;	/* how many bytes used */
170};
171
172struct tport {
173	struct asn_oid	index;		/* table index of this tp point */
174	TAILQ_ENTRY(tport) link;	/* table link */
175	struct transport *transport;	/* who handles this */
176};
177TAILQ_HEAD(tport_list, tport);
178
179int snmpd_input(struct port_input *, struct tport *);
180void snmpd_input_close(struct port_input *);
181
182
183/*
184 * Transport domain
185 */
186#define TRANS_NAMELEN	64
187
188struct transport_def {
189	const char	*name;		/* name of this transport */
190	struct asn_oid	id;		/* OBJID of this transport */
191
192	int		(*start)(void);
193	int		(*stop)(int);
194
195	void		(*close_port)(struct tport *);
196	int		(*init_port)(struct tport *);
197
198	ssize_t		(*send)(struct tport *, const u_char *, size_t,
199			    const struct sockaddr *, size_t);
200};
201struct transport {
202	struct asn_oid	index;		/* transport table index */
203	TAILQ_ENTRY(transport) link;	/* ... and link */
204	u_int		or_index;	/* registration index */
205
206	struct tport_list table;	/* list of open ports */
207
208	const struct transport_def *vtab;
209};
210
211TAILQ_HEAD(transport_list, transport);
212extern struct transport_list transport_list;
213
214void trans_insert_port(struct transport *, struct tport *);
215void trans_remove_port(struct tport *);
216struct tport *trans_find_port(struct transport *,
217    const struct asn_oid *, u_int);
218struct tport *trans_next_port(struct transport *,
219    const struct asn_oid *, u_int);
220struct tport *trans_first_port(struct transport *);
221struct tport *trans_iter_port(struct transport *,
222    int (*)(struct tport *, intptr_t), intptr_t);
223
224int trans_register(const struct transport_def *, struct transport **);
225int trans_unregister(struct transport *);
226
227/*************************************************************
228 *
229 * SNMPd scalar configuration.
230 */
231struct snmpd {
232	/* transmit buffer size */
233	u_int32_t	txbuf;
234
235	/* receive buffer size */
236	u_int32_t	rxbuf;
237
238	/* disable community table */
239	int		comm_dis;
240
241	/* authentication traps */
242	int		auth_traps;
243
244	/* source address for V1 traps */
245	u_char		trap1addr[4];
246
247	/* version enable flags */
248	uint32_t	version_enable;
249};
250extern struct snmpd snmpd;
251
252#define	VERS_ENABLE_V1	0x00000001
253#define	VERS_ENABLE_V2C	0x00000002
254#define	VERS_ENABLE_ALL	0x00000003
255
256/*
257 * The debug group
258 */
259struct debug {
260	u_int		dump_pdus;
261	u_int		logpri;
262	u_int		evdebug;
263};
264extern struct debug debug;
265
266
267/*
268 * SNMPd statistics table
269 */
270struct snmpd_stats {
271	u_int32_t	inPkts;		/* total packets received */
272	u_int32_t	inBadVersions;	/* unknown version number */
273	u_int32_t	inASNParseErrs;	/* fatal parse errors */
274	u_int32_t	inBadCommunityNames;
275	u_int32_t	inBadCommunityUses;
276	u_int32_t	proxyDrops;	/* dropped by proxy function */
277	u_int32_t	silentDrops;
278
279	u_int32_t	inBadPduTypes;
280	u_int32_t	inTooLong;
281	u_int32_t	noTxbuf;
282	u_int32_t	noRxbuf;
283};
284extern struct snmpd_stats snmpd_stats;
285
286/*
287 * OR Table
288 */
289struct objres {
290	TAILQ_ENTRY(objres) link;
291	u_int		index;
292	struct asn_oid	oid;	/* the resource OID */
293	char		descr[256];
294	u_int32_t	uptime;
295	struct lmodule	*module;
296};
297TAILQ_HEAD(objres_list, objres);
298extern struct objres_list objres_list;
299
300/*
301 * Trap Sink Table
302 */
303struct trapsink {
304	TAILQ_ENTRY(trapsink) link;
305	struct asn_oid	index;
306	u_int		status;
307	int		socket;
308	u_char		comm[SNMP_COMMUNITY_MAXLEN];
309	int		version;
310};
311enum {
312	TRAPSINK_ACTIVE		= 1,
313	TRAPSINK_NOT_IN_SERVICE	= 2,
314	TRAPSINK_NOT_READY	= 3,
315	TRAPSINK_DESTROY	= 6,
316
317	TRAPSINK_V1		= 1,
318	TRAPSINK_V2		= 2,
319};
320TAILQ_HEAD(trapsink_list, trapsink);
321extern struct trapsink_list trapsink_list;
322
323extern const char *syspath;
324
325/* snmpSerialNo */
326extern int32_t snmp_serial_no;
327
328int init_actvals(void);
329int read_config(const char *, struct lmodule *);
330int define_macro(const char *name, const char *value);
331
332#define	LOG_ASN1_ERRORS	0x10000000
333#define	LOG_SNMP_ERRORS	0x20000000
334