2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 * Author: Harti Brandt <harti@freebsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $Begemot: bsnmp/snmpd/snmpd.h,v 1.24 2004/08/06 08:47:13 brandt Exp $
31 * Private SNMPd data and functions.
33 #include <sys/queue.h>
37 #include <isc/eventlib.h>
40 #define PATH_SYSCONFIG "/etc:/usr/etc:/usr/local/etc"
47 /*************************************************************
52 struct lmodule *owner; /* who created the community */
53 u_int private;/* private name for the module */
54 u_int value; /* value of this community */
55 u_char * string; /* the community string */
56 const u_char * descr; /* description */
57 TAILQ_ENTRY(community) link;
61 /* list of all known communities */
62 extern TAILQ_HEAD(community_list, community) community_list;
64 /*************************************************************
69 u_int type; /* type id */
70 int32_t base; /* base of this range */
71 int32_t size; /* size of this range */
72 int32_t next; /* generator */
73 struct lmodule *owner; /* owner module */
74 TAILQ_ENTRY(idrange) link;
77 /* list of all known ranges */
78 extern TAILQ_HEAD(idrange_list, idrange) idrange_list;
80 /* identifier generator */
81 extern u_int next_idrange;
83 /* request id generator for traps */
84 extern u_int trap_reqid;
86 /*************************************************************
91 void (*func)(void *);/* user function */
92 void *udata; /* user data */
93 evTimerID id; /* timer id */
94 struct lmodule *owner; /* owner of the timer */
95 LIST_ENTRY(timer) link;
98 /* list of all current timers */
99 extern LIST_HEAD(timer_list, timer) timer_list;
102 /*************************************************************
107 int fd; /* the file descriptor */
108 void (*func)(int, void *);/* user function */
109 void *udata; /* user data */
110 evFileID id; /* file id */
111 struct lmodule *owner; /* owner module of the file */
112 LIST_ENTRY(fdesc) link;
115 /* list of all current selected files */
116 extern LIST_HEAD(fdesc_list, fdesc) fdesc_list;
118 /*************************************************************
122 # define LM_SECTION_MAX 14
124 char section[LM_SECTION_MAX + 1]; /* and index */
128 const struct snmp_module *config;
130 TAILQ_ENTRY(lmodule) link;
131 TAILQ_ENTRY(lmodule) start;
133 struct asn_oid index;
135 #define LM_STARTED 0x0001
136 #define LM_ONSTARTLIST 0x0002
138 extern TAILQ_HEAD(lmodules, lmodule) lmodules;
140 struct lmodule *lm_load(const char *, const char *);
141 void lm_unload(struct lmodule *);
142 void lm_start(struct lmodule *);
144 /*************************************************************
153 void *id; /* evSelect handle */
155 int stream : 1; /* stream socket */
156 int cred : 1; /* want credentials */
158 struct sockaddr *peer; /* last received packet */
160 int priv : 1; /* peer is privileged */
162 u_char *buf; /* receive buffer */
163 size_t buflen; /* buffer length */
164 size_t length; /* received length */
165 size_t consumed; /* how many bytes used */
169 struct asn_oid index; /* table index of this tp point */
170 TAILQ_ENTRY(tport) link; /* table link */
171 struct transport *transport; /* who handles this */
173 TAILQ_HEAD(tport_list, tport);
175 int snmpd_input(struct port_input *, struct tport *);
176 void snmpd_input_close(struct port_input *);
182 #define TRANS_NAMELEN 64
184 struct transport_def {
185 const char *name; /* name of this transport */
186 struct asn_oid id; /* OBJID of this transport */
191 void (*close_port)(struct tport *);
192 int (*init_port)(struct tport *);
194 ssize_t (*send)(struct tport *, const u_char *, size_t,
195 const struct sockaddr *, size_t);
198 struct asn_oid index; /* transport table index */
199 TAILQ_ENTRY(transport) link; /* ... and link */
200 u_int or_index; /* registration index */
202 struct tport_list table; /* list of open ports */
204 const struct transport_def *vtab;
207 TAILQ_HEAD(transport_list, transport);
208 extern struct transport_list transport_list;
210 void trans_insert_port(struct transport *, struct tport *);
211 void trans_remove_port(struct tport *);
212 struct tport *trans_find_port(struct transport *,
213 const struct asn_oid *, u_int);
214 struct tport *trans_next_port(struct transport *,
215 const struct asn_oid *, u_int);
216 struct tport *trans_first_port(struct transport *);
217 struct tport *trans_iter_port(struct transport *,
218 int (*)(struct tport *, intptr_t), intptr_t);
220 int trans_register(const struct transport_def *, struct transport **);
221 int trans_unregister(struct transport *);
223 /*************************************************************
225 * SNMPd scalar configuration.
228 /* transmit buffer size */
231 /* receive buffer size */
234 /* disable community table */
237 /* authentication traps */
240 /* source address for V1 traps */
243 /* version enable flags */
244 uint32_t version_enable;
246 extern struct snmpd snmpd;
248 #define VERS_ENABLE_V1 0x00000001
249 #define VERS_ENABLE_V2C 0x00000002
250 #define VERS_ENABLE_ALL 0x00000003
260 extern struct debug debug;
264 * SNMPd statistics table
267 u_int32_t inPkts; /* total packets received */
268 u_int32_t inBadVersions; /* unknown version number */
269 u_int32_t inASNParseErrs; /* fatal parse errors */
270 u_int32_t inBadCommunityNames;
271 u_int32_t inBadCommunityUses;
272 u_int32_t proxyDrops; /* dropped by proxy function */
273 u_int32_t silentDrops;
275 u_int32_t inBadPduTypes;
280 extern struct snmpd_stats snmpd_stats;
286 TAILQ_ENTRY(objres) link;
288 struct asn_oid oid; /* the resource OID */
291 struct lmodule *module;
293 TAILQ_HEAD(objres_list, objres);
294 extern struct objres_list objres_list;
300 TAILQ_ENTRY(trapsink) link;
301 struct asn_oid index;
304 u_char comm[SNMP_COMMUNITY_MAXLEN];
309 TRAPSINK_NOT_IN_SERVICE = 2,
310 TRAPSINK_NOT_READY = 3,
311 TRAPSINK_DESTROY = 6,
316 TAILQ_HEAD(trapsink_list, trapsink);
317 extern struct trapsink_list trapsink_list;
319 extern const char *syspath;
322 extern int32_t snmp_serial_no;
324 int init_actvals(void);
325 int read_config(const char *, struct lmodule *);
326 int define_macro(const char *name, const char *value);
328 #define LOG_ASN1_ERRORS 0x10000000
329 #define LOG_SNMP_ERRORS 0x20000000