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>
7133211Sharti *
8216594Ssyrinx * Copyright (c) 2010 The FreeBSD Foundation
9216594Ssyrinx * All rights reserved.
10216594Ssyrinx *
11216594Ssyrinx * Portions of this software were developed by Shteryana Sotirova Shopova
12216594Ssyrinx * under sponsorship from the FreeBSD Foundation.
13216594Ssyrinx *
14133211Sharti * Redistribution and use in source and binary forms, with or without
15133211Sharti * modification, are permitted provided that the following conditions
16133211Sharti * are met:
17133211Sharti * 1. Redistributions of source code must retain the above copyright
18133211Sharti *    notice, this list of conditions and the following disclaimer.
19122394Sharti * 2. Redistributions in binary form must reproduce the above copyright
20122394Sharti *    notice, this list of conditions and the following disclaimer in the
21122394Sharti *    documentation and/or other materials provided with the distribution.
22133211Sharti *
23133211Sharti * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24133211Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25133211Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26133211Sharti * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
27133211Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28133211Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29133211Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30133211Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31133211Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32133211Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33133211Sharti * SUCH DAMAGE.
34122394Sharti *
35156066Sharti * $Begemot: bsnmp/snmpd/snmpmod.h,v 1.32 2006/02/14 09:04:20 brandt_h Exp $
36122394Sharti *
37122394Sharti * SNMP daemon data and functions exported to modules.
38122394Sharti */
39122394Sharti#ifndef snmpmod_h_
40122394Sharti#define snmpmod_h_
41122394Sharti
42122394Sharti#include <sys/types.h>
43228411Strociny#include <sys/queue.h>
44122394Sharti#include <sys/socket.h>
45122394Sharti#include <net/if.h>
46122394Sharti#include <netinet/in.h>
47122394Sharti#include "asn1.h"
48122394Sharti#include "snmp.h"
49122394Sharti#include "snmpagent.h"
50122394Sharti
51122394Sharti#define MAX_MOD_ARGS	16
52122394Sharti
53122394Sharti/*
54122394Sharti * These macros help to handle object lists for SNMP tables. They use
55122394Sharti * tail queues to hold the objects in ascending order in the list.
56150920Sharti * ordering can be done either on an integer/unsigned field, an asn_oid
57150920Sharti * or an ordering function.
58122394Sharti */
59122394Sharti#define INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, LINK, INDEX) do {	\
60122394Sharti	__typeof (PTR) _lelem;						\
61122394Sharti									\
62122394Sharti	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
63122394Sharti		if (asn_compare_oid(&_lelem->INDEX, &(PTR)->INDEX) > 0)	\
64122394Sharti			break;						\
65122394Sharti	if (_lelem == NULL)						\
66122394Sharti		TAILQ_INSERT_TAIL((LIST), (PTR), LINK);			\
67122394Sharti	else								\
68122394Sharti		TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK);		\
69150920Sharti    } while (0)
70122394Sharti
71122394Sharti#define INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, INDEX) do {	\
72122394Sharti	__typeof (PTR) _lelem;						\
73122394Sharti									\
74122394Sharti	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
75122394Sharti		if ((asn_subid_t)_lelem->INDEX > (asn_subid_t)(PTR)->INDEX)\
76122394Sharti			break;						\
77122394Sharti	if (_lelem == NULL)						\
78122394Sharti		TAILQ_INSERT_TAIL((LIST), (PTR), LINK);			\
79122394Sharti	else								\
80122394Sharti		TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK);		\
81150920Sharti    } while (0)
82122394Sharti
83150920Sharti#define	INSERT_OBJECT_FUNC_LINK(PTR, LIST, LINK, FUNC) do {		\
84150920Sharti	__typeof (PTR) _lelem;						\
85150920Sharti									\
86150920Sharti	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
87150920Sharti		if ((FUNC)(_lelem, (PTR)) > 0)				\
88150920Sharti			break;						\
89150920Sharti	if (_lelem == NULL)						\
90150920Sharti		TAILQ_INSERT_TAIL((LIST), (PTR), LINK);			\
91150920Sharti	else								\
92150920Sharti		TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK);		\
93150920Sharti    } while (0)
94150920Sharti
95150920Sharti#define	INSERT_OBJECT_FUNC_LINK_REV(PTR, LIST, HEAD, LINK, FUNC) do {	\
96150920Sharti	__typeof (PTR) _lelem;						\
97150920Sharti									\
98150920Sharti	TAILQ_FOREACH_REVERSE(_lelem, (LIST), HEAD, LINK)		\
99150920Sharti		if ((FUNC)(_lelem, (PTR)) < 0)				\
100150920Sharti			break;						\
101150920Sharti	if (_lelem == NULL)						\
102150920Sharti		TAILQ_INSERT_HEAD((LIST), (PTR), LINK);			\
103150920Sharti	else								\
104150920Sharti		TAILQ_INSERT_AFTER((LIST), _lelem, (PTR), LINK);	\
105150920Sharti    } while (0)
106150920Sharti
107122394Sharti#define FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({	\
108122394Sharti	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
109122394Sharti									\
110122394Sharti	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
111122394Sharti		if (index_compare(OID, SUB, &_lelem->INDEX) == 0)	\
112122394Sharti			break;						\
113122394Sharti	(_lelem);							\
114122394Sharti    })
115122394Sharti
116122394Sharti#define NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({	\
117122394Sharti	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
118122394Sharti									\
119122394Sharti	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
120122394Sharti		if (index_compare(OID, SUB, &_lelem->INDEX) < 0)	\
121122394Sharti			break;						\
122122394Sharti	(_lelem);							\
123122394Sharti    })
124122394Sharti
125122394Sharti#define FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({	\
126122394Sharti	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
127122394Sharti									\
128122394Sharti	if ((OID)->len - SUB != 1)					\
129122394Sharti		_lelem = NULL;						\
130122394Sharti	else								\
131122394Sharti		TAILQ_FOREACH(_lelem, (LIST), LINK)			\
132122394Sharti			if ((OID)->subs[SUB] == (asn_subid_t)_lelem->INDEX)\
133122394Sharti				break;					\
134122394Sharti	(_lelem);							\
135122394Sharti    })
136122394Sharti
137122394Sharti#define NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({	\
138122394Sharti	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
139122394Sharti									\
140122394Sharti	if ((OID)->len - SUB == 0)					\
141122394Sharti		_lelem = TAILQ_FIRST(LIST);				\
142122394Sharti	else								\
143122394Sharti		TAILQ_FOREACH(_lelem, (LIST), LINK)			\
144122394Sharti			if ((OID)->subs[SUB] < (asn_subid_t)_lelem->INDEX)\
145122394Sharti				break;					\
146122394Sharti	(_lelem);							\
147122394Sharti    })
148122394Sharti
149150920Sharti#define FIND_OBJECT_FUNC_LINK(LIST, OID, SUB, LINK, FUNC) ({		\
150150920Sharti	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
151150920Sharti									\
152150920Sharti	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
153150920Sharti		if ((FUNC)(OID, SUB, _lelem) == 0)			\
154150920Sharti			break;						\
155150920Sharti	(_lelem);							\
156150920Sharti    })
157150920Sharti
158150920Sharti#define NEXT_OBJECT_FUNC_LINK(LIST, OID, SUB, LINK, FUNC) ({		\
159150920Sharti	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
160150920Sharti									\
161150920Sharti	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
162150920Sharti		if ((FUNC)(OID, SUB, _lelem) < 0)			\
163150920Sharti			break;						\
164150920Sharti	(_lelem);							\
165150920Sharti    })
166150920Sharti
167122394Sharti/*
168122394Sharti * Macros for the case where the index field is called 'index'
169122394Sharti */
170122394Sharti#define INSERT_OBJECT_OID_LINK(PTR, LIST, LINK)				\
171122394Sharti    INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, LINK, index)
172122394Sharti
173122394Sharti#define INSERT_OBJECT_INT_LINK(PTR, LIST, LINK) do {			\
174122394Sharti    INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, index)
175122394Sharti
176122394Sharti#define FIND_OBJECT_OID_LINK(LIST, OID, SUB, LINK)			\
177122394Sharti    FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, index)
178122394Sharti
179122394Sharti#define NEXT_OBJECT_OID_LINK(LIST, OID, SUB, LINK)			\
180122394Sharti    NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, index)
181122394Sharti
182122394Sharti#define FIND_OBJECT_INT_LINK(LIST, OID, SUB, LINK)			\
183122394Sharti    FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, index)
184122394Sharti
185122394Sharti#define NEXT_OBJECT_INT_LINK(LIST, OID, SUB, LINK)			\
186122394Sharti    NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, index)
187122394Sharti
188122394Sharti/*
189122394Sharti * Macros for the case where the index field is called 'index' and the
190122394Sharti * link field 'link'.
191122394Sharti */
192122394Sharti#define INSERT_OBJECT_OID(PTR, LIST)					\
193122394Sharti    INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, link, index)
194122394Sharti
195122394Sharti#define INSERT_OBJECT_INT(PTR, LIST)					\
196122394Sharti    INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, link, index)
197122394Sharti
198150920Sharti#define	INSERT_OBJECT_FUNC_REV(PTR, LIST, HEAD, FUNC)			\
199150920Sharti    INSERT_OBJECT_FUNC_LINK_REV(PTR, LIST, HEAD, link, FUNC)
200150920Sharti
201122394Sharti#define FIND_OBJECT_OID(LIST, OID, SUB)					\
202122394Sharti    FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index)
203122394Sharti
204122394Sharti#define FIND_OBJECT_INT(LIST, OID, SUB)					\
205122394Sharti    FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index)
206122394Sharti
207150920Sharti#define	FIND_OBJECT_FUNC(LIST, OID, SUB, FUNC)				\
208150920Sharti    FIND_OBJECT_FUNC_LINK(LIST, OID, SUB, link, FUNC)
209150920Sharti
210122394Sharti#define NEXT_OBJECT_OID(LIST, OID, SUB)					\
211122394Sharti    NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index)
212122394Sharti
213122394Sharti#define NEXT_OBJECT_INT(LIST, OID, SUB)					\
214122394Sharti    NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index)
215122394Sharti
216150920Sharti#define	NEXT_OBJECT_FUNC(LIST, OID, SUB, FUNC)				\
217150920Sharti    NEXT_OBJECT_FUNC_LINK(LIST, OID, SUB, link, FUNC)
218150920Sharti
219122394Shartistruct lmodule;
220122394Sharti
221146525Sharti/* The tick when the program was started. This is the absolute time of
222146525Sharti * the start in 100th of a second. */
223146525Shartiextern uint64_t start_tick;
224122394Sharti
225146525Sharti/* The tick when the current packet was received. This is the absolute
226146525Sharti * time in 100th of second. */
227146525Shartiextern uint64_t this_tick;
228122394Sharti
229146525Sharti/* Get the current absolute time in 100th of a second. */
230146525Shartiuint64_t get_ticks(void);
231146525Sharti
232122394Sharti/*
233122394Sharti * Return code for proxy function
234122394Sharti */
235122394Shartienum snmpd_proxy_err {
236122394Sharti	/* proxy code will process the PDU */
237122394Sharti	SNMPD_PROXY_OK,
238122394Sharti	/* proxy code does not process PDU */
239122394Sharti	SNMPD_PROXY_REJ,
240122394Sharti	/* drop this PDU */
241122394Sharti	SNMPD_PROXY_DROP,
242122394Sharti	/* drop because of bad community */
243122394Sharti	SNMPD_PROXY_BADCOMM,
244122394Sharti	/* drop because of bad community use */
245122394Sharti	SNMPD_PROXY_BADCOMMUSE
246122394Sharti};
247122394Sharti
248122394Sharti/*
249122394Sharti * Input handling
250122394Sharti */
251122394Shartienum snmpd_input_err {
252122394Sharti	/* proceed with packet */
253122394Sharti	SNMPD_INPUT_OK,
254122394Sharti	/* fatal error in packet, ignore it */
255122394Sharti	SNMPD_INPUT_FAILED,
256122394Sharti	/* value encoding has wrong length in a SET operation */
257122394Sharti	SNMPD_INPUT_VALBADLEN,
258122394Sharti	/* value encoding is out of range */
259122394Sharti	SNMPD_INPUT_VALRANGE,
260122394Sharti	/* value has bad encoding */
261122394Sharti	SNMPD_INPUT_VALBADENC,
262124861Sharti	/* need more data (truncated packet) */
263124861Sharti	SNMPD_INPUT_TRUNC,
264133211Sharti	/* unknown community */
265133211Sharti	SNMPD_INPUT_BAD_COMM,
266122394Sharti};
267122394Sharti
268122394Sharti/*
269122394Sharti * Every loadable module must have one of this structures with
270122394Sharti * the external name 'config'.
271122394Sharti */
272122394Shartistruct snmp_module {
273122394Sharti	/* a comment describing what this module implements */
274122394Sharti	const char *comment;
275122394Sharti
276150920Sharti	/* the initialization function */
277122394Sharti	int (*init)(struct lmodule *, int argc, char *argv[]);
278122394Sharti
279122394Sharti	/* the finalisation function */
280122394Sharti	int (*fini)(void);
281122394Sharti
282122394Sharti	/* the idle function */
283122394Sharti	void (*idle)(void);
284122394Sharti
285122394Sharti	/* the dump function */
286122394Sharti	void (*dump)(void);
287122394Sharti
288122394Sharti	/* re-configuration function */
289122394Sharti	void (*config)(void);
290122394Sharti
291122394Sharti	/* start operation */
292122394Sharti	void (*start)(void);
293122394Sharti
294122394Sharti	/* proxy a PDU */
295124861Sharti	enum snmpd_proxy_err (*proxy)(struct snmp_pdu *, void *,
296122394Sharti	    const struct asn_oid *, const struct sockaddr *, socklen_t,
297124861Sharti	    enum snmpd_input_err, int32_t, int);
298122394Sharti
299122394Sharti	/* the tree this module is going to server */
300122394Sharti	const struct snmp_node *tree;
301122394Sharti	u_int tree_size;
302122394Sharti
303122394Sharti	/* function called, when another module was unloaded/loaded */
304122394Sharti	void (*loading)(const struct lmodule *, int);
305122394Sharti};
306122394Sharti
307122394Sharti/*
308122394Sharti * Stuff exported to modules
309122394Sharti */
310122394Sharti
311122394Sharti/*
312122394Sharti * The system group.
313122394Sharti */
314122394Shartistruct systemg {
315122394Sharti	u_char		*descr;
316122394Sharti	struct asn_oid	object_id;
317122394Sharti	u_char		*contact;
318122394Sharti	u_char		*name;
319122394Sharti	u_char		*location;
320122394Sharti	u_int32_t	services;
321122394Sharti	u_int32_t	or_last_change;
322122394Sharti};
323122394Shartiextern struct systemg systemg;
324122394Sharti
325122394Sharti/*
326122394Sharti * Community support.
327122394Sharti *
328122394Sharti * We have 2 fixed communities for SNMP read and write access. Modules
329122394Sharti * can create their communities dynamically. They are deleted automatically
330122394Sharti * if the module is unloaded.
331122394Sharti */
332122394Sharti#define COMM_INITIALIZE	0
333122394Sharti#define COMM_READ	1
334122394Sharti#define COMM_WRITE	2
335122394Sharti
336122394Shartiu_int comm_define(u_int, const char *descr, struct lmodule *, const char *str);
337122394Sharticonst char * comm_string(u_int);
338122394Sharti
339122394Sharti/* community for current packet */
340122394Shartiextern u_int community;
341122394Sharti
342216294Ssyrinx/*
343216294Ssyrinx * SNMP User-based Security Model data. Modified via the snmp_usm(3) module.
344216294Ssyrinx */
345216294Ssyrinxstruct snmpd_usmstat {
346216294Ssyrinx	uint32_t	unsupported_seclevels;
347216294Ssyrinx	uint32_t	not_in_time_windows;
348216294Ssyrinx	uint32_t	unknown_users;
349216294Ssyrinx	uint32_t	unknown_engine_ids;
350216294Ssyrinx	uint32_t	wrong_digests;
351216294Ssyrinx	uint32_t	decrypt_errors;
352216294Ssyrinx};
353216294Ssyrinx
354216294Ssyrinxextern struct snmpd_usmstat snmpd_usmstats;
355216294Ssyrinxstruct snmpd_usmstat *bsnmpd_get_usm_stats(void);
356216294Ssyrinxvoid bsnmpd_reset_usm_stats(void);
357216294Ssyrinx
358216294Ssyrinxstruct usm_user {
359216294Ssyrinx	struct snmp_user		suser;
360216294Ssyrinx	uint8_t				user_engine_id[SNMP_ENGINE_ID_SIZ];
361216294Ssyrinx	uint32_t			user_engine_len;
362216294Ssyrinx	char				user_public[SNMP_ADM_STR32_SIZ];
363216294Ssyrinx	uint32_t			user_public_len;
364216294Ssyrinx	int32_t				status;
365216294Ssyrinx	int32_t				type;
366216294Ssyrinx	SLIST_ENTRY(usm_user)		up;
367216294Ssyrinx};
368216294Ssyrinx
369216294SsyrinxSLIST_HEAD(usm_userlist, usm_user);
370216294Ssyrinxstruct usm_user *usm_first_user(void);
371216294Ssyrinxstruct usm_user *usm_next_user(struct usm_user *);
372216294Ssyrinxstruct usm_user *usm_find_user(uint8_t *, uint32_t, char *);
373216294Ssyrinxstruct usm_user *usm_new_user(uint8_t *, uint32_t, char *);
374216294Ssyrinxvoid usm_delete_user(struct usm_user *);
375216294Ssyrinxvoid usm_flush_users(void);
376216294Ssyrinx
377216294Ssyrinx/* USM user for current packet */
378216294Ssyrinxextern struct usm_user *usm_user;
379216294Ssyrinx
380216294Ssyrinx/*
381216294Ssyrinx * SNMP View-based Access Control Model data. Modified via the snmp_vacm(3) module.
382216294Ssyrinx */
383216294Ssyrinxstruct vacm_group;
384216294Ssyrinx
385216294Ssyrinxstruct vacm_user {
386216294Ssyrinx	/* Security user name from USM */
387216294Ssyrinx	char				secname[SNMP_ADM_STR32_SIZ];
388216294Ssyrinx	int32_t				sec_model;
389216294Ssyrinx	/* Back pointer to user assigned group name */
390216294Ssyrinx	struct vacm_group		*group;
391216294Ssyrinx	int32_t				type;
392216294Ssyrinx	int32_t				status;
393216294Ssyrinx	SLIST_ENTRY(vacm_user)		vvu;
394216294Ssyrinx	SLIST_ENTRY(vacm_user)		vvg;
395216294Ssyrinx};
396216294Ssyrinx
397216294SsyrinxSLIST_HEAD(vacm_userlist, vacm_user);
398216294Ssyrinx
399216294Ssyrinxstruct vacm_group {
400216294Ssyrinx	char				groupname[SNMP_ADM_STR32_SIZ];
401216294Ssyrinx	struct vacm_userlist		group_users;
402216294Ssyrinx	SLIST_ENTRY(vacm_group)		vge;
403216294Ssyrinx};
404216294Ssyrinx
405216294SsyrinxSLIST_HEAD(vacm_grouplist, vacm_group);
406216294Ssyrinx
407216294Ssyrinxstruct vacm_access {
408216294Ssyrinx	/* The group name is index, not a column in the table */
409216294Ssyrinx	struct vacm_group		*group;
410216294Ssyrinx	char				ctx_prefix[SNMP_ADM_STR32_SIZ];
411216294Ssyrinx	int32_t				sec_model;
412216294Ssyrinx	int32_t				sec_level;
413216294Ssyrinx	int32_t				ctx_match;
414216294Ssyrinx	struct vacm_view		*read_view;
415216294Ssyrinx	struct vacm_view		*write_view;
416216294Ssyrinx	struct vacm_view		*notify_view;
417216294Ssyrinx	int32_t				type;
418216294Ssyrinx	int32_t				status;
419216294Ssyrinx	TAILQ_ENTRY(vacm_access)	vva;
420216294Ssyrinx};
421216294Ssyrinx
422216294SsyrinxTAILQ_HEAD(vacm_accesslist, vacm_access);
423216294Ssyrinx
424216294Ssyrinxstruct vacm_view {
425216294Ssyrinx	char				viewname[SNMP_ADM_STR32_SIZ]; /* key */
426216294Ssyrinx	struct asn_oid			subtree; /* key */
427216294Ssyrinx	uint8_t				mask[16];
428216294Ssyrinx	uint8_t				exclude;
429216294Ssyrinx	int32_t				type;
430216294Ssyrinx	int32_t				status;
431216294Ssyrinx	SLIST_ENTRY(vacm_view)		vvl;
432216294Ssyrinx};
433216294Ssyrinx
434216294SsyrinxSLIST_HEAD(vacm_viewlist, vacm_view);
435216294Ssyrinx
436216294Ssyrinxstruct vacm_context {
437216294Ssyrinx	/* The ID of the module that registered this context */
438216294Ssyrinx	int32_t				regid;
439216294Ssyrinx	char				ctxname[SNMP_ADM_STR32_SIZ];
440216294Ssyrinx	SLIST_ENTRY(vacm_context)	vcl;
441216294Ssyrinx};
442216294Ssyrinx
443216294SsyrinxSLIST_HEAD(vacm_contextlist, vacm_context);
444216294Ssyrinx
445216294Ssyrinxvoid vacm_groups_init(void);
446216294Ssyrinxstruct vacm_user *vacm_first_user(void);
447216294Ssyrinxstruct vacm_user *vacm_next_user(struct vacm_user *);
448216294Ssyrinxstruct vacm_user *vacm_new_user(int32_t, char *);
449216294Ssyrinxint vacm_delete_user(struct vacm_user *);
450216294Ssyrinxint vacm_user_set_group(struct vacm_user *, u_char *, u_int);
451216294Ssyrinxstruct vacm_access *vacm_first_access_rule(void);
452216294Ssyrinxstruct vacm_access *vacm_next_access_rule(struct vacm_access *);
453216294Ssyrinxstruct vacm_access *vacm_new_access_rule(char *, char *, int32_t, int32_t);
454216294Ssyrinxint vacm_delete_access_rule(struct vacm_access *);
455216294Ssyrinxstruct vacm_view *vacm_first_view(void);
456216294Ssyrinxstruct vacm_view *vacm_next_view(struct vacm_view *);
457216294Ssyrinxstruct vacm_view *vacm_new_view(char *, struct asn_oid *);
458216294Ssyrinxint vacm_delete_view(struct vacm_view *);
459216294Ssyrinxstruct vacm_context *vacm_first_context(void);
460216294Ssyrinxstruct vacm_context *vacm_next_context(struct vacm_context *);
461216294Ssyrinxstruct vacm_context *vacm_add_context(char *, int32_t);
462216294Ssyrinxvoid vacm_flush_contexts(int32_t);
463216294Ssyrinx
464216294Ssyrinx/*
465216594Ssyrinx * RFC 3413 SNMP Management Target & Notification MIB
466216594Ssyrinx */
467216594Ssyrinx
468216594Ssyrinxstruct snmpd_target_stats {
469216594Ssyrinx	uint32_t			unavail_contexts;
470216594Ssyrinx	uint32_t			unknown_contexts;
471216594Ssyrinx};
472216594Ssyrinx
473216594Ssyrinx#define	SNMP_UDP_ADDR_SIZ		6
474216594Ssyrinx#define	SNMP_TAG_SIZ			(255 + 1)
475216594Ssyrinx
476216594Ssyrinxstruct target_address {
477216594Ssyrinx	char				name[SNMP_ADM_STR32_SIZ];
478216594Ssyrinx	uint8_t				address[SNMP_UDP_ADDR_SIZ];
479216594Ssyrinx	int32_t				timeout;
480216594Ssyrinx	int32_t				retry;
481216594Ssyrinx	char				taglist[SNMP_TAG_SIZ];
482216594Ssyrinx	char				paramname[SNMP_ADM_STR32_SIZ];
483216594Ssyrinx	int32_t				type;
484216594Ssyrinx	int32_t				socket;
485216594Ssyrinx	int32_t				status;
486216594Ssyrinx	SLIST_ENTRY(target_address)	ta;
487216594Ssyrinx};
488216594Ssyrinx
489216594SsyrinxSLIST_HEAD(target_addresslist, target_address);
490216594Ssyrinx
491216594Ssyrinxstruct target_param {
492216594Ssyrinx	char				name[SNMP_ADM_STR32_SIZ];
493216594Ssyrinx	int32_t				mpmodel;
494216594Ssyrinx	int32_t				sec_model;
495216594Ssyrinx	char				secname[SNMP_ADM_STR32_SIZ];
496216594Ssyrinx	enum snmp_usm_level		sec_level;
497216594Ssyrinx	int32_t				type;
498216594Ssyrinx	int32_t				status;
499216594Ssyrinx	SLIST_ENTRY(target_param)	tp;
500216594Ssyrinx};
501216594Ssyrinx
502216594SsyrinxSLIST_HEAD(target_paramlist, target_param);
503216594Ssyrinx
504216594Ssyrinxstruct target_notify {
505216594Ssyrinx	char				name[SNMP_ADM_STR32_SIZ];
506216594Ssyrinx	char				taglist[SNMP_TAG_SIZ];
507216594Ssyrinx	int32_t				notify_type;
508216594Ssyrinx	int32_t				type;
509216594Ssyrinx	int32_t				status;
510216594Ssyrinx	SLIST_ENTRY(target_notify)	tn;
511216594Ssyrinx};
512216594Ssyrinx
513216594SsyrinxSLIST_HEAD(target_notifylist, target_notify);
514216594Ssyrinx
515216594Ssyrinxextern struct snmpd_target_stats snmpd_target_stats;
516216594Ssyrinxstruct snmpd_target_stats *bsnmpd_get_target_stats(void);
517216594Ssyrinxstruct target_address *target_first_address(void);
518216594Ssyrinxstruct target_address *target_next_address(struct target_address *);
519216594Ssyrinxstruct target_address *target_new_address(char *);
520216594Ssyrinxint target_activate_address(struct target_address *);
521216594Ssyrinxint target_delete_address(struct target_address *);
522216594Ssyrinxstruct target_param *target_first_param(void);
523216594Ssyrinxstruct target_param *target_next_param(struct target_param *);
524216594Ssyrinxstruct target_param *target_new_param(char *);
525216594Ssyrinxint target_delete_param(struct target_param *);
526216594Ssyrinxstruct target_notify *target_first_notify(void);
527216594Ssyrinxstruct target_notify *target_next_notify(struct target_notify *);
528216594Ssyrinxstruct target_notify *target_new_notify(char *);
529216594Ssyrinxint target_delete_notify (struct target_notify *);
530216594Ssyrinxvoid target_flush_all(void);
531216594Ssyrinx
532216594Ssyrinx/*
533122394Sharti * Well known OIDs
534122394Sharti */
535122394Shartiextern const struct asn_oid oid_zeroDotZero;
536122394Sharti
537216294Ssyrinx/* SNMPv3 Engine Discovery */
538216294Ssyrinxextern const struct asn_oid oid_usmUnknownEngineIDs;
539216294Ssyrinxextern const struct asn_oid oid_usmNotInTimeWindows;
540216294Ssyrinx
541122394Sharti/*
542122394Sharti * Request ID ranges.
543122394Sharti *
544122394Sharti * A module can request a range of request ids and associate them with a
545122394Sharti * type field. All ranges are deleted if a module is unloaded.
546122394Sharti */
547122394Shartiu_int reqid_allocate(int size, struct lmodule *);
548122394Shartiint32_t reqid_next(u_int type);
549122394Shartiint32_t reqid_base(u_int type);
550122394Shartiint reqid_istype(int32_t reqid, u_int type);
551122394Shartiu_int reqid_type(int32_t reqid);
552122394Sharti
553122394Sharti/*
554122394Sharti * Timers.
555122394Sharti */
556122394Shartivoid *timer_start(u_int, void (*)(void *), void *, struct lmodule *);
557150920Shartivoid *timer_start_repeat(u_int, u_int, void (*)(void *), void *,
558150920Sharti    struct lmodule *);
559122394Shartivoid timer_stop(void *);
560122394Sharti
561122394Sharti/*
562122394Sharti * File descriptors
563122394Sharti */
564122394Shartivoid *fd_select(int, void (*)(int, void *), void *, struct lmodule *);
565122394Shartivoid fd_deselect(void *);
566122394Shartivoid fd_suspend(void *);
567122394Shartiint fd_resume(void *);
568122394Sharti
569122394Sharti/*
570122394Sharti * Object resources
571122394Sharti */
572122394Shartiu_int or_register(const struct asn_oid *, const char *, struct lmodule *);
573122394Shartivoid or_unregister(u_int);
574122394Sharti
575122394Sharti/*
576122394Sharti * Buffers
577122394Sharti */
578122394Shartivoid *buf_alloc(int tx);
579122394Shartisize_t buf_size(int tx);
580122394Sharti
581122394Sharti/* decode PDU and find community */
582122394Shartienum snmpd_input_err snmp_input_start(const u_char *, size_t, const char *,
583124861Sharti    struct snmp_pdu *, int32_t *, size_t *);
584122394Sharti
585122394Sharti/* process the pdu. returns either _OK or _FAILED */
586122394Shartienum snmpd_input_err snmp_input_finish(struct snmp_pdu *, const u_char *,
587122394Sharti    size_t, u_char *, size_t *, const char *, enum snmpd_input_err, int32_t,
588122394Sharti    void *);
589122394Sharti
590124861Shartivoid snmp_output(struct snmp_pdu *, u_char *, size_t *, const char *);
591124861Shartivoid snmp_send_port(void *, const struct asn_oid *, struct snmp_pdu *,
592122394Sharti	const struct sockaddr *, socklen_t);
593216594Ssyrinxenum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int32_t *);
594122394Sharti
595122394Sharti/* sending traps */
596122394Shartivoid snmp_send_trap(const struct asn_oid *, ...);
597122394Sharti
598122394Sharti/*
599122394Sharti * Action support
600122394Sharti */
601122394Shartiint string_save(struct snmp_value *, struct snmp_context *, ssize_t, u_char **);
602122394Shartivoid string_commit(struct snmp_context *);
603122394Shartivoid string_rollback(struct snmp_context *, u_char **);
604122394Shartiint string_get(struct snmp_value *, const u_char *, ssize_t);
605155429Shartiint string_get_max(struct snmp_value *, const u_char *, ssize_t, size_t);
606122394Shartivoid string_free(struct snmp_context *);
607122394Sharti
608122394Shartiint ip_save(struct snmp_value *, struct snmp_context *, u_char *);
609122394Shartivoid ip_rollback(struct snmp_context *, u_char *);
610122394Shartivoid ip_commit(struct snmp_context *);
611122394Shartiint ip_get(struct snmp_value *, u_char *);
612122394Sharti
613122394Shartiint oid_save(struct snmp_value *, struct snmp_context *, struct asn_oid *);
614122394Shartivoid oid_rollback(struct snmp_context *, struct asn_oid *);
615122394Shartivoid oid_commit(struct snmp_context *);
616122394Shartiint oid_get(struct snmp_value *, const struct asn_oid *);
617122394Sharti
618122394Shartiint index_decode(const struct asn_oid *oid, u_int sub, u_int code, ...);
619122394Shartiint index_compare(const struct asn_oid *, u_int, const struct asn_oid *);
620122394Shartiint index_compare_off(const struct asn_oid *, u_int, const struct asn_oid *,
621122394Sharti    u_int);
622122394Shartivoid index_append(struct asn_oid *, u_int, const struct asn_oid *);
623122394Shartivoid index_append_off(struct asn_oid *, u_int, const struct asn_oid *, u_int);
624122394Sharti
625122394Sharti#endif
626