MFC: BEGEMOT_1_11 and vendor patches:

config.c: 1.1.1.7
	main.c: 1.1.1.10, 1.1.1.11
	snmpd.config: 1.1.1.6
This commit is contained in:
harti 2006-01-20 16:34:37 +00:00
parent 03e2bbe4b2
commit 2c80e8f4d2
9 changed files with 354 additions and 139 deletions

View File

@ -1,4 +1,7 @@
.\"
.\" Copyright (c) 2004-2005
.\" Hartmut Brandt.
.\" All rights reserved.
.\" Copyright (c) 2001-2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved.
@ -26,14 +29,14 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Begemot: bsnmp/snmpd/bsnmpd.1,v 1.6 2005/02/25 11:56:01 brandt_h Exp $
.\" $Begemot: bsnmp/snmpd/bsnmpd.1,v 1.9 2005/10/04 08:46:54 brandt_h Exp $
.\"
.Dd August 15, 2002
.Dd October 4, 2005
.Dt SNMPD 1
.Os
.Sh NAME
.Nm snmpd
.Nd "simple and extendable SNMP daemon"
.Nm bsnmpd
.Nd "simple and extensible SNMP daemon"
.Sh SYNOPSIS
.Nm
.Op Fl dh
@ -46,9 +49,10 @@
.Sh DESCRIPTION
The
.Nm
daemon servers the internet SNMP (Simple Network Managment Protocol).
daemon servers the internet SNMP (Simple Network Management Protocol).
It is intended to serve only the absolute basic MIBs and implement all other
MIBs through loadable modules. In this way the
MIBs through loadable modules.
In this way the
.Nm
can be used in unexpected ways.
.Pp
@ -78,11 +82,13 @@ This causes the debugging level of the event library (see
to be set to 10.
.It Cm trace Ns Cm = Ns Cm level
This option causes the snmp library trace flag to be set to the specified
value. The value can be specified in the usual C-syntax for numbers.
value.
The value can be specified in the usual C-syntax for numbers.
.El
.It Fl I Ar paths
This option specifies a colon separated list of directories to search for
configuration include files. The default is
configuration include files.
The default is
.Pa /etc:/usr/etc/:/usr/local/etc .
These paths are only searched for include specified within <> parentheses.
.It Fl l Ar prefix
@ -98,8 +104,8 @@ Specify an alternate pid file instead of the default one.
The
.Nm
reads its configuration from either the default or the user specified
configuration file. The configuration file consists of the following types of
lines:
configuration file.
The configuration file consists of the following types of lines:
.Bl -bullet -offset indent
.It
variable assignments
@ -112,18 +118,21 @@ MIB variable assignments
.El
.Pp
If a line is too long it can be continued on the next line by ending it with
a backslash. Empty lines and lines in which the first non-blank character is a
a backslash.
Empty lines and lines in which the first non-blank character is a
.Dq #
sign are ignored.
.Pp
All MIB variable assignments of the entire configuration (including nested
configuration files) are handled as one transaction, i.e. as if they arrived
in a single SET PDU. Any failure during the initial configuration read causes
configuration files) are handled as one transaction, i.e., as if they arrived
in a single SET PDU.
Any failure during the initial configuration read causes
.Nm
to exit. A failure during the configuration read caused by a module load
to exit.
A failure during the configuration read caused by a module load
causes the loading of the module to fail.
.Pp
The configuration is read during initialisation of
The configuration is read during initialization of
.Nm ,
when a module is loaded and when
.Nm
@ -138,23 +147,25 @@ variable ?= string
The string reaches from the first non-blank character after the
equal sign until the first new line or
.Dq #
character. In the first case
character.
In the first case
the string is assigned to the variable unconditionally, in the second case the
variable is only assigned if it does not exist yet.
.Pp
Variable names must begin with a letter or underscore and contain only letters,
digits or underscores.
.Ss SECTION SEPARATORS
The configuration consists of named sections. The MIB variable assignments in
the section named
The configuration consists of named sections.
The MIB variable assignments in the section named
.Dq snmpd
are executed only during initial setup or when
.Nm
receives a SIGHUP. All other sections are executed when either a module
receives a SIGHUP.
All other sections are executed when either a module
with the same name as the section is loaded or
.Nm
receives a SIGHUP and that module is already loaded. The default section
at the start of the configuration is
receives a SIGHUP and that module is already loaded.
The default section at the start of the configuration is
.Dq snmpd .
One can switch to another section with the syntax
.Bd -unfilled -offset indent
@ -163,10 +174,11 @@ One can switch to another section with the syntax
.Pp
Where
.Ar secname
is the name of the section. The same
is the name of the section.
The same
.Ar secname
can be used in more than one place in the configuration. All of these parts are
collected into one section.
can be used in more than one place in the configuration.
All of these parts are collected into one section.
.Ss INCLUDE DIRECTIVES
Another configuration file can be included into the current one with the
include directive that takes one of two forms:
@ -177,8 +189,8 @@ include directive that takes one of two forms:
.Pp
The first form causes the file to be searched in the current directory, the
second form causes the file to be searched in the directories specified in
the system include path. Nesting depth is only restricted by available
memory.
the system include path.
Nesting depth is only restricted by available memory.
.Ss MIB VARIABLE ASSIGNMENTS
A MIB variable is assigned with the syntax
.Bd -unfilled -offset indent
@ -186,17 +198,23 @@ oid [ suboids ] = value
.Ed
.Pp
.Va oid
is the name of the variable to be set. Only the last component of the entire
name is used here. If the variable is a scalar, the index (.0) is automatically
appended and need not to be specified. If the variable is a table column,
the index
is the name of the variable to be set.
Only the last component of the entire name is used here.
If the variable is a scalar, the index (.0) is automatically
appended and need not to be specified.
If the variable is a table column, the index
.Pq Va suboids
must be specified. The index consist of elements each seperated from the
previous one by a dot. Elements may be either numbers, strings or hostnames
enclosed in [] brackets. If the element is a number it is appended
to the current oid. If the element is a string, its length and the
must be specified.
The index consist of elements each separated from the
previous one by a dot.
Elements may be either numbers, strings or hostnames
enclosed in [] brackets.
If the element is a number it is appended
to the current oid.
If the element is a string, its length and the
.Tn ASCII
code of each of its characters are appended to the current oid. If the
code of each of its characters are appended to the current oid.
If the
element is a hostname, the IP address of the host is looked up and the four
elements of the IP address are appended to the oid.
.Pp
@ -213,7 +231,8 @@ myvariable.27.6.102.111.111.111.108.108.127.0.0.1.38.94.33
The value of the assignment may be either empty, a string or a number.
If a string starts with a letter or an underscore and consists only of
letters, digits, underscores and minus signs, it can be written without
quotes. In all other cases the string must be enclosed in double quotes.
quotes.
In all other cases the string must be enclosed in double quotes.
.Sh SUBSTITUTIONS
A variable substitution is written as
.Bd -unfilled -offset indent
@ -222,8 +241,8 @@ $(variable)
.Pp
where
.Ar variable
is the name of the variable to substitute. Using an undefined variable is
considered an error.
is the name of the variable to substitute.
Using an undefined variable is considered an error.
.Sh FILES
.Bl -tag -width ".It Pa /var/run/ Ns Ao Ar prefix Ac Ns \&.pid" -compact
.It Pa /etc/ Ns Ao Ar prefix Ac Ns \&.config

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Begemot: bsnmp/snmpd/config.c,v 1.22 2004/08/12 17:09:49 brandt Exp $
* $Begemot: bsnmp/snmpd/config.c,v 1.24 2005/10/04 11:21:37 brandt_h Exp $
*
* Parse configuration file.
*/
@ -206,17 +206,18 @@ input_open_file(const char *fname, int sysdir)
struct input *input;
FILE *fp;
char path[PATH_MAX + 1];
char *col;
const char *col;
const char *ptr;
if (sysdir) {
ptr = syspath;
fp = NULL;
while (*ptr != '\0') {
if ((col = strchr(ptr, ':')) == NULL)
if ((col = strchr(ptr, ':')) == NULL) {
snprintf(path, sizeof(path), "%s/%s",
ptr, fname);
else if (col == ptr)
col = ptr + strlen(ptr) - 1;
} else if (col == ptr)
snprintf(path, sizeof(path), "./%s", fname);
else
snprintf(path, sizeof(path), "%.*s/%s",
@ -820,7 +821,7 @@ parse_oid(const char *varname, struct asn_oid *oid)
while (token == '.') {
if (gettoken() == TOK_NUM) {
if (numval > ASN_MAXID)
report("subid too large %#"PRIx64, numval);
report("subid too large %#"QUADXFMT, numval);
if (oid->len == ASN_MAXOIDLEN)
report("index too long");
oid->subs[oid->len++] = numval;
@ -863,7 +864,7 @@ parse_syntax_integer(struct snmp_value *value)
if (token != TOK_NUM)
report("bad INTEGER syntax");
if (numval > 0x7fffffff)
report("INTEGER too large %"PRIu64, numval);
report("INTEGER too large %"QUADFMT, numval);
value->v.integer = numval;
gettoken();
@ -1131,7 +1132,7 @@ parse_define(const char *varname)
m->value = string;
m->length = length;
} else {
if (t != TOK_ASSIGN) {
if (t == TOK_ASSIGN) {
free(m->value);
m->value = string;
m->length = length;
@ -1360,5 +1361,7 @@ define_macro(const char *name, const char *value)
}
strcpy(m->value, value);
m->length = strlen(value);
m->perm = 1;
LIST_INSERT_HEAD(&macros, m, link);
return (0);
}

View File

@ -26,13 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Begemot: bsnmp/snmpd/main.c,v 1.93 2005/05/23 11:10:16 brandt_h Exp $
* $Begemot: bsnmp/snmpd/main.c,v 1.97 2005/10/04 14:32:45 brandt_h Exp $
*
* SNMPd main stuff.
*/
#include <sys/param.h>
#include <sys/un.h>
#include <sys/ucred.h>
#include <sys/uio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
@ -56,6 +57,10 @@
#include "tree.h"
#include "oid.h"
#if !defined(INT32_MAX)
#define INT32_MAX (0x7fffffff)
#endif
#define PATH_PID "/var/run/%s.pid"
#define PATH_CONFIG "/etc/%s.config"
@ -734,7 +739,7 @@ check_priv(struct port_input *pi, struct msghdr *msg)
pi->priv = 0;
if (msg->msg_controllen == sizeof(*cmsg)) {
/* process explicitely sends credentials */
/* process explicitly sends credentials */
cmsg = (struct credmsg *)msg->msg_control;
pi->priv = (cmsg->cred.cmcred_euid == 0);
@ -1457,8 +1462,8 @@ main(int argc, char *argv[])
/*
* Get standard communities
*/
(void)comm_define(1, "SNMP read", NULL, "public");
(void)comm_define(2, "SNMP write", NULL, "public");
(void)comm_define(1, "SNMP read", NULL, NULL);
(void)comm_define(2, "SNMP write", NULL, NULL);
community = COMM_INITIALIZE;
trap_reqid = reqid_allocate(512, NULL);
@ -1611,6 +1616,10 @@ get_ticks()
/*
* Timer support
*/
/*
* Trampoline for the non-repeatable timers.
*/
#ifdef USE_LIBBEGEMOT
static void
tfunc(int tid __unused, void *uap)
@ -1628,7 +1637,24 @@ tfunc(evContext ctx __unused, void *uap, struct timespec due __unused,
}
/*
* Start a timer
* Trampoline for the repeatable timers.
*/
#ifdef USE_LIBBEGEMOT
static void
trfunc(int tid __unused, void *uap)
#else
static void
trfunc(evContext ctx __unused, void *uap, struct timespec due __unused,
struct timespec inter __unused)
#endif
{
struct timer *tp = uap;
tp->func(tp->udata);
}
/*
* Start a one-shot timer
*/
void *
timer_start(u_int ticks, void (*func)(void *), void *udata, struct lmodule *mod)
@ -1669,6 +1695,55 @@ timer_start(u_int ticks, void (*func)(void *), void *udata, struct lmodule *mod)
return (tp);
}
/*
* Start a repeatable timer. When used with USE_LIBBEGEMOT the first argument
* is currently ignored and the initial number of ticks is set to the
* repeat number of ticks.
*/
void *
timer_start_repeat(u_int ticks __unused, u_int repeat_ticks,
void (*func)(void *), void *udata, struct lmodule *mod)
{
struct timer *tp;
#ifndef USE_LIBBEGEMOT
struct timespec due;
struct timespec inter;
#endif
if ((tp = malloc(sizeof(struct timer))) == NULL) {
syslog(LOG_CRIT, "out of memory for timer");
exit(1);
}
#ifndef USE_LIBBEGEMOT
due = evAddTime(evNowTime(),
evConsTime(ticks / 100, (ticks % 100) * 10000));
inter = evConsTime(repeat_ticks / 100, (repeat_ticks % 100) * 10000);
#endif
tp->udata = udata;
tp->owner = mod;
tp->func = func;
LIST_INSERT_HEAD(&timer_list, tp, link);
#ifdef USE_LIBBEGEMOT
if ((tp->id = poll_start_timer(repeat_ticks * 10, 1, trfunc, tp)) < 0) {
syslog(LOG_ERR, "cannot set timer: %m");
exit(1);
}
#else
if (evSetTimer(evctx, trfunc, tp, due, inter, &tp->id) == -1) {
syslog(LOG_ERR, "cannot set timer: %m");
exit(1);
}
#endif
return (tp);
}
/*
* Stop a timer.
*/
void
timer_stop(void *p)
{
@ -2157,7 +2232,7 @@ lm_load(const char *path, const char *section)
av[ac] = NULL;
/*
* Run the initialisation function
* Run the initialization function
*/
if ((err = (*m->config->init)(m, ac, av)) != 0) {
syslog(LOG_ERR, "lm_load: init failed: %d", err);

View File

@ -42,6 +42,8 @@ traphost := noc.bar.com
trapport := 162
read := "public"
# Uncomment the line below that sets the community string
# to enable write access.
write := "geheim"
trap := "mytrap"
@ -52,8 +54,20 @@ trap := "mytrap"
begemotSnmpdDebugDumpPdus = 2
begemotSnmpdDebugSyslogPri = 7
#
# Set the read and write communities.
#
# The default value of the community strings is NULL (note, that this is
# different from the empty string). This disables both read and write access.
# To enable read access only the read community string must be set. Setting
# the write community string enables both read and write access with that
# string.
#
# Be sure to understand the security implications of SNMPv2 - the community
# strings are readable on the wire!
#
begemotSnmpdCommunityString.0.1 = $(read)
begemotSnmpdCommunityString.0.2 = $(write)
# begemotSnmpdCommunityString.0.2 = $(write)
begemotSnmpdCommunityDisable = 1
# open standard SNMP ports

View File

@ -1,4 +1,7 @@
.\"
.\" Copyright (c) 2004-2005
.\" Hartmut Brandt.
.\" All rights reserved.
.\" Copyright (c) 2001-2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved.
@ -26,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Begemot: bsnmp/snmpd/snmpmod.3,v 1.10 2005/05/23 09:10:11 brandt_h Exp $
.\" $Begemot: bsnmp/snmpd/snmpmod.3,v 1.14 2005/10/04 13:30:35 brandt_h Exp $
.\"
.Dd May 23, 2005
.Dd October 4, 2005
.Dt SNMPMOD 3
.Os
.Sh NAME
@ -63,6 +66,7 @@
.Nm reqid_istype ,
.Nm reqid_type ,
.Nm timer_start ,
.Nm timer_start_repeat ,
.Nm timer_stop ,
.Nm fd_select ,
.Nm fd_deselect ,
@ -142,6 +146,8 @@ Begemot SNMP library
.Fn reqid_type "int32_t reqid"
.Ft void *
.Fn timer_start "u_int ticks" "void (*func)(void *)" "void *uarg" "struct lmodule *mod"
.Ft void *
.Fn timer_start_repeat "u_int ticks" "u_int repeat_ticks" "void (*func)(void *)" "void *uarg" "struct lmodule *mod"
.Ft void
.Fn timer_stop "void *timer_id"
.Ft void *
@ -221,22 +227,26 @@ Begemot SNMP library
.Fn index_append_off "struct asn_oid *dst" "u_int sub" "const struct asn_oid *src" "u_int off"
.Sh DESCRIPTION
The
.Xr snmpd 1
.Xr bsnmpd 1
SNMP daemon implements a minimal MIB which consists of the system group, part
of the SNMP MIB, a private configuration MIB, a trap destination table, a
UDP port table, a community table, a module table, a statistics group and
a debugging group. All other MIBs are support through loadable modules.
a debugging group.
All other MIBs are support through loadable modules.
This allows
.Xr snmpd 1
.Xr bsnmpd 1
to use for task, that are not the classical SNMP task.
.Ss MODULE LOADING AND UNLOADING
Modules are loaded by writing to the module table. This table is indexed by
a string, that identfies the module to the daemon. This identifier is used
Modules are loaded by writing to the module table.
This table is indexed by a string, that identifies the module to the daemon.
This identifier is used
to select the correct configuration section from the configuration files and
to identify resources allocated to this module. A row in the module table is
to identify resources allocated to this module.
A row in the module table is
created by writing a string of non-zero length to the
.Va begemotSnmpdModulePath
column. This string must be the complete path to the file containing the module.
column.
This string must be the complete path to the file containing the module.
A module can be unloaded by writing a zero length string to the path column
of an existing row.
.Pp
@ -273,29 +283,33 @@ This structure must be statically initialized and its fields have the
following functions:
.Bl -tag -width ".It Va tree_size"
.It Va comment
This is a string that will be visible in the module table. It should give
some hint about the function of this module.
This is a string that will be visible in the module table.
It should give some hint about the function of this module.
.It Va init
This function is called upon loading the module. The module pointer should
This function is called upon loading the module.
The module pointer should
be stored by the module because it is needed in other calls and the
argument vector will contain the arguments to this module from the daemons
command line. This function should return 0 if everything is ok or an
UNIX error code (see
.Xr errno 3 ).
command line.
This function should return 0 if everything is ok or an UNIX error code (see
.Xr errno 3 ) .
Once the function returns 0, the
.Va fini
function is called when the module is unloaded.
.It Va fini
The module is unloaded. This gives the module a chance to free resources that
are not automatically freed. Be sure to free all memory, because daemons tend
to run very long. This function pointer may be
The module is unloaded.
This gives the module a chance to free resources that
are not automatically freed.
Be sure to free all memory, because daemons tend to run very long.
This function pointer may be
.Li NULL
if it is not needed.
.It Va idle
If this function pointer is not
.Li NULL ,
the function pointed to by it is called whenever the daemon is going
to wait for an event. Try to avoid using this feature.
to wait for an event.
Try to avoid using this feature.
.It Va dump
Whenever the daemon receives a
.Li SIGUSR1
@ -322,7 +336,7 @@ If not
this function is called after successful loading and initializing the module
to start its actual operation.
.It Va proxy
If the daemon receives a PDU and that PDU has a community string who's
If the daemon receives a PDU and that PDU has a community string whose
community was registered by this module and
.Va proxy
is not
@ -336,16 +350,18 @@ This is the number of nodes in
.It Va loading
If this pointer is not
.Li NULL
it is called whenever another module was loaded or unloaded. It gets a
it is called whenever another module was loaded or unloaded.
It gets a
pointer to that module and a flag that is 0 for unloading and 1 for loading.
.El
.Pp
When everything is ok, the daemon merges the module's MIB tree into its current
global tree, calls the modules
.Fn init
function. If this function returns an error, the modules MIB tree is removed from
the global one and the module is unloaded. If initialisation is successful,
the modules
function.
If this function returns an error, the modules MIB tree is removed from
the global one and the module is unloaded.
If initialization is successful, the modules
.Fn start
function is called.
After it returns the
@ -363,10 +379,11 @@ functions of all other modules are called.
There are a number of macros designed to help implementing SNMP tables.
A problem while implementing a table is the support for the GETNEXT operator.
The GETNEXT operation has to find out whether, given an arbitrary OID, the
lessest table row, that has an OID higher than the given OID. The easiest way
lessest table row, that has an OID higher than the given OID.
The easiest way
to do this is to keep the table as an ordered list of structures each one
of which contains an OID that is the index of the table row. This allows easy
removal, insertion and search.
of which contains an OID that is the index of the table row.
This allows easy removal, insertion and search.
.Pp
The helper macros assume, that the table is organized as a TAILQ (see
.Xr queue 3
@ -400,7 +417,7 @@ assume the existence of a
.Vt struct asn_oid
that is used as index, the macros
.Fn *_OBJECT_INT_*
assume the existance of an unsigned integer field that is used as index.
assume the existence of an unsigned integer field that is used as index.
.Pp
The macros
.Fn *_INDEX
@ -413,7 +430,7 @@ The macros
allow the explicit naming of the link field of the tail queues, the others
assume that the link field is named
.Va link .
Explicitely naming the link field may be necessary if the same structures
Explicitly naming the link field may be necessary if the same structures
are held in two or more different tables.
.Pp
The arguments to the macros are as follows:
@ -431,7 +448,8 @@ Must point to the
.Va var
field of the
.Fa value
argument to the node operation callback. This is the OID to search for.
argument to the node operation callback.
This is the OID to search for.
.It Fa SUB
This is the index of the start of the table index in the OID pointed to
by
@ -466,18 +484,19 @@ struct systemg {
u_char *contact;
u_char *name;
u_char *location;
u_int32_t services;
u_int32_t or_last_change;
uint32_t services;
uint32_t or_last_change;
};
.Ed
.Ss COMMUNITIES
The SNMP daemon implements a community table. On recipte of a request message
The SNMP daemon implements a community table.
On recipte of a request message
the community string in that message is compared to each of the community
strings in that table, if a match is found, the global variable
.Va community
is set to the community identifier for that community. Community identifiers
are unsigned integers. For the three standard communities there are three
constants defined:
is set to the community identifier for that community.
Community identifiers are unsigned integers.
For the three standard communities there are three constants defined:
.Bd -literal -offset indent
#define COMM_INITIALIZE 0
#define COMM_READ 1
@ -487,24 +506,26 @@ constants defined:
.Va community
is set to
.Li COMM_INITIALIZE
while the assignments in the configuration file are processed. To
while the assignments in the configuration file are processed.
To
.Li COMM_READ
or
.Li COMM_WRITE
when the community strings for the read-write or read-only community are found
in the incoming PDU.
.Pp
Modules can define additional communities. This may be necessary to provide
Modules can define additional communities.
This may be necessary to provide
transport proxying (a PDU received on one communication link is proxied to
another link) or to implement non-UDP access points to SNMP. A new
community is defined with the function
another link) or to implement non-UDP access points to SNMP.
A new community is defined with the function
.Fn comm_define .
It takes the following parameters:
.Bl -tag -width ".It Fa descr"
.It Fa priv
This is an integer identifying the community to the module. Each module has
its own namespace with regard to this parameter. The community table is
indexed with the module name and this identifier.
This is an integer identifying the community to the module.
Each module has its own namespace with regard to this parameter.
The community table is indexed with the module name and this identifier.
.It Fa descr
This is a string providing a human readable description of the community.
It is visible in the community table.
@ -514,7 +535,8 @@ This is the module defining the community.
This is the initial community string.
.El
.Pp
The function returns a globally unique community identifier. If a PDU is
The function returns a globally unique community identifier.
If a PDU is
received who's community string matches, this identifier is set into the global
.Va community .
.Pp
@ -531,7 +553,8 @@ contains the OID 0.0.
.Ss REQUEST ID RANGES
For modules that implement SNMP client functions besides SNMP agent functions
it may be necessary to identify SNMP requests by their identifier to allow
easier routing of responses to the correct sub-system. Request id ranges
easier routing of responses to the correct sub-system.
Request id ranges
provide a way to aquire globally non-overlapping sub-ranges of the entire
31-bit id range.
.Pp
@ -543,7 +566,8 @@ For example, the call
id = reqid_allocate(1000, module);
.Ed
.Pp
allocates a range of 1000 request ids. The function returns the request
allocates a range of 1000 request ids.
The function returns the request
id range identifier or 0 if there is not enough identifier space.
The function
.Fn reqid_base
@ -578,9 +602,20 @@ after
.Fa ticks
SNMP ticks have expired.
.Fa mod
is the module that starts the timer. Timers are one-shot, they are not
restarted. The function returns a timer identifier that can be used to
stop the timer via
is the module that starts the timer.
These timers are one-shot, they are not restarted.
Repeatable timers are started with
.Fn timer_start_repeat
which takes an additional argument
.Fa repeat_ticks .
The argument
.Fa ticks
gives the number of ticks until the first execution of the callback, while
.Fa repeat_ticks
is the number of ticks between invocations of the callback.
Note, that currently the number of initial ticks silently may be set identical
to the number of ticks between callback invocations.
The function returns a timer identifier that can be used to stop the timer via
.Fn timer_stop .
If a module is unloaded all timers started by the module that have not expired
yet are stopped.
@ -598,9 +633,10 @@ and the user argument
.Fa uarg
whenever the file descriptor
.Fa fd
can be red or has a close condition. If the file descriptor is not in
non-blocking mode, it is set to non-blocking mode. If the callback is not
needed anymore,
can be read or has a close condition.
If the file descriptor is not in
non-blocking mode, it is set to non-blocking mode.
If the callback is not needed anymore,
.Fn fd_deselect
may be called with the value returned from
.Fn fd_select .
@ -609,17 +645,18 @@ the module is unloaded.
.Pp
To temporarily suspend the file descriptor registration
.Fn fd_suspend
can be called. This also causes the file descriptor to be switched back to
can be called.
This also causes the file descriptor to be switched back to
blocking mode if it was blocking prior the call to
.Fn fd_select .
This is necessary to do synchronuous input on a selected socket.
This is necessary to do synchronous input on a selected socket.
The effect of
.Fn fd_suspend
can be undone with
.Fn fd_resume .
.Ss OBJECT RESOURCES
The system group contains an object resource table. A module may create
an entry in this table by calling
The system group contains an object resource table.
A module may create an entry in this table by calling
.Fn or_register
with the
.Fa oid
@ -634,10 +671,11 @@ unloaded.
.Ss TRANSMIT AND RECEIVE BUFFERS
A buffer is allocated via
.Fn buf_alloc .
The argument must be 1 for transmit and 0 for receive buffers. The function
may return
The argument must be 1 for transmit and 0 for receive buffers.
The function may return
.Li NULL
if there is no memory available. The current buffersize can be obtained with
if there is no memory available.
The current buffersize can be obtained with
.Fn buf_size .
.Sh PROCESSING PDUS
For modules that need to do their own PDU processing (for example for proxying)
@ -666,7 +704,8 @@ A SET PDU had a value field in a binding with wrong ASN.1 encoding.
The buffer appears to contain a valid begin of a PDU, but is too short.
For streaming transports this means that the caller must save what he
already has and trying to obtain more input and reissue this input to
the function. For datagram transports this means that part of the
the function.
For datagram transports this means that part of the
datagram was lost and the input should be ignored.
.El
.Pp
@ -674,11 +713,12 @@ The function
.Fn snmp_input_finish
does the other half of processing: if
.Fn snmp_input_start
did not return OK, tries to construct an error response. If the start was OK,
it calls the correct function from
.Xr bsnmpagent
did not return OK, tries to construct an error response.
If the start was OK, it calls the correct function from
.Xr bsnmpagent 3
to execute the request and depending on the outcome constructs a response or
error response PDU or ignores the request PDU. It returns either
error response PDU or ignores the request PDU.
It returns either
.Er SNMPD_INPUT_OK
or
.Er SNMPD_INPUT_FAILED .
@ -695,7 +735,8 @@ the transport and the index in the port table) to the given address.
.Pp
The function
.Fn snmp_send_trap
sends a trap to all trap destinations. The arguments are the
sends a trap to all trap destinations.
The arguments are the
.Fa oid
identifying the trap and a NULL-terminated list of
.Vt struct snmp_value
@ -712,15 +753,16 @@ should be called for SNMP_OP_SET.
.Fa value
and
.Fa ctx
are the resp\&. arguments to the node callback.
are the resp\&.\& arguments to the node callback.
.Fa valp
is a pointer to the pointer that holds the current value and
.Fa req_size
should be -1 if any size of the string is acceptable or a number larger or
equal zero if the string must have a specific size. The function saves
equal zero if the string must have a specific size.
The function saves
the old value in the scratch area (note, that any initial value must have
been allocated by
.Xr malloc 3 ),
.Xr malloc 3 ) ,
allocates a new string, copies over the new value, NUL-terminates it and
sets the new current value.
.It Fn string_commit
@ -728,11 +770,13 @@ simply frees the saved old value in the scratch area.
.It Fn string_rollback
frees the new value, and puts back the old one.
.It Fn string_get
is used for GET or GETNEXT. If
is used for GET or GETNEXT.
If
.Fa len
is -1, the length is computed via
.Xr strlen 3
from the current string value. If the current value is NULL,
from the current string value.
If the current value is NULL,
a OCTET STRING of zero length is returned.
.It Fn string_free
must be called if either rollback or commit fails to free the saved old value.
@ -771,13 +815,15 @@ Retrieves the OID
The following functions help in handling table indexes:
.Bl -tag -width "XXXXXXXXX"
.It Fn index_decode
Decodes the index part of the OID. The parameter
Decodes the index part of the OID.
The parameter
.Fa oid
must be a pointer to the
.Va var
field of the
.Fa value
argument of the node callback. The
argument of the node callback.
The
.Fa sub
argument must be the index of the start of the index in the OID (this is
the
@ -794,14 +840,16 @@ elements as follows:
.Vt int32_t *
expected as argument.
.It Li COUNTER64
.Vt u_int64_t *
expected as argument. Note, that this syntax is illegal for indexes.
.Vt uint64_t *
expected as argument.
Note, that this syntax is illegal for indexes.
.It Li OCTET STRING
A
.Vt u_char **
and a
.Vt size_t *
expected as arguments. A buffer is allocated to hold the decoded string.
expected as arguments.
A buffer is allocated to hold the decoded string.
.It Li OID
A
.Vt struct asn_oid *
@ -828,7 +876,8 @@ and
.Fa sub
resp.
.Fa oid2
is the OID to compare to. The function returns -1, 0, +1 when the
is the OID to compare to.
The function returns -1, 0, +1 when the
variable is lesser, equal, higher to the given OID.
.Fa oid2
must contain only the index part of the table column.
@ -861,7 +910,7 @@ beginning at position
.El
.Sh SEE ALSO
.Xr gensnmptree 1 ,
.Xr snmpd 1 ,
.Xr bsnmpd 1 ,
.Xr bsnmpagent 3 ,
.Xr bsnmpclient 3 ,
.Xr bsnmplib 3

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Begemot: bsnmp/snmpd/snmpmod.h,v 1.28 2005/05/23 09:03:59 brandt_h Exp $
* $Begemot: bsnmp/snmpd/snmpmod.h,v 1.31 2005/10/04 13:30:36 brandt_h Exp $
*
* SNMP daemon data and functions exported to modules.
*/
@ -46,7 +46,8 @@
/*
* These macros help to handle object lists for SNMP tables. They use
* tail queues to hold the objects in ascending order in the list.
* ordering can be done either on an integer/unsigned field or and asn_oid.
* ordering can be done either on an integer/unsigned field, an asn_oid
* or an ordering function.
*/
#define INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, LINK, INDEX) do { \
__typeof (PTR) _lelem; \
@ -58,7 +59,7 @@
TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \
else \
TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \
} while(0)
} while (0)
#define INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, INDEX) do { \
__typeof (PTR) _lelem; \
@ -70,7 +71,31 @@
TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \
else \
TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \
} while(0)
} while (0)
#define INSERT_OBJECT_FUNC_LINK(PTR, LIST, LINK, FUNC) do { \
__typeof (PTR) _lelem; \
\
TAILQ_FOREACH(_lelem, (LIST), LINK) \
if ((FUNC)(_lelem, (PTR)) > 0) \
break; \
if (_lelem == NULL) \
TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \
else \
TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \
} while (0)
#define INSERT_OBJECT_FUNC_LINK_REV(PTR, LIST, HEAD, LINK, FUNC) do { \
__typeof (PTR) _lelem; \
\
TAILQ_FOREACH_REVERSE(_lelem, (LIST), HEAD, LINK) \
if ((FUNC)(_lelem, (PTR)) < 0) \
break; \
if (_lelem == NULL) \
TAILQ_INSERT_HEAD((LIST), (PTR), LINK); \
else \
TAILQ_INSERT_AFTER((LIST), _lelem, (PTR), LINK); \
} while (0)
#define FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({ \
__typeof (TAILQ_FIRST(LIST)) _lelem; \
@ -114,6 +139,24 @@
(_lelem); \
})
#define FIND_OBJECT_FUNC_LINK(LIST, OID, SUB, LINK, FUNC) ({ \
__typeof (TAILQ_FIRST(LIST)) _lelem; \
\
TAILQ_FOREACH(_lelem, (LIST), LINK) \
if ((FUNC)(OID, SUB, _lelem) == 0) \
break; \
(_lelem); \
})
#define NEXT_OBJECT_FUNC_LINK(LIST, OID, SUB, LINK, FUNC) ({ \
__typeof (TAILQ_FIRST(LIST)) _lelem; \
\
TAILQ_FOREACH(_lelem, (LIST), LINK) \
if ((FUNC)(OID, SUB, _lelem) < 0) \
break; \
(_lelem); \
})
/*
* Macros for the case where the index field is called 'index'
*/
@ -145,18 +188,27 @@
#define INSERT_OBJECT_INT(PTR, LIST) \
INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, link, index)
#define INSERT_OBJECT_FUNC_REV(PTR, LIST, HEAD, FUNC) \
INSERT_OBJECT_FUNC_LINK_REV(PTR, LIST, HEAD, link, FUNC)
#define FIND_OBJECT_OID(LIST, OID, SUB) \
FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index)
#define FIND_OBJECT_INT(LIST, OID, SUB) \
FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index)
#define FIND_OBJECT_FUNC(LIST, OID, SUB, FUNC) \
FIND_OBJECT_FUNC_LINK(LIST, OID, SUB, link, FUNC)
#define NEXT_OBJECT_OID(LIST, OID, SUB) \
NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index)
#define NEXT_OBJECT_INT(LIST, OID, SUB) \
NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index)
#define NEXT_OBJECT_FUNC(LIST, OID, SUB, FUNC) \
NEXT_OBJECT_FUNC_LINK(LIST, OID, SUB, link, FUNC)
struct lmodule;
/* The tick when the program was started. This is the absolute time of
@ -214,7 +266,7 @@ struct snmp_module {
/* a comment describing what this module implements */
const char *comment;
/* the initialisation function */
/* the initialization function */
int (*init)(struct lmodule *, int argc, char *argv[]);
/* the finalisation function */
@ -301,6 +353,8 @@ u_int reqid_type(int32_t reqid);
* Timers.
*/
void *timer_start(u_int, void (*)(void *), void *, struct lmodule *);
void *timer_start_repeat(u_int, u_int, void (*)(void *), void *,
struct lmodule *);
void timer_stop(void *);
/*

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Begemot: bsnmp/snmpd/trans_udp.c,v 1.4 2004/08/06 08:47:16 brandt Exp $
* $Begemot: bsnmp/snmpd/trans_udp.c,v 1.5 2005/10/04 08:46:56 brandt_h Exp $
*
* UDP transport
*/
@ -137,7 +137,7 @@ udp_init_port(struct tport *tp)
/*
* Create a new SNMP Port object and start it, if we are not
* in initialisation mode. The arguments are in host byte order.
* in initialization mode. The arguments are in host byte order.
*/
static int
udp_open_port(u_int8_t *addr, u_int32_t udp_port, struct udp_port **pp)

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Begemot: bsnmp/snmpd/trap.c,v 1.8 2004/08/06 08:47:17 brandt Exp $
* $Begemot: bsnmp/snmpd/trap.c,v 1.9 2005/10/04 11:21:39 brandt_h Exp $
*
* TrapSinkTable
*/
@ -107,7 +107,7 @@ trapsink_create(struct trapsink_dep *tdep)
if (connect(t->socket, (struct sockaddr *)&sa, sa.sin_len) == -1) {
syslog(LOG_ERR, "connect(%s,%u): %m",
inet_ntoa(sa.sin_addr), ntohl(sa.sin_port));
inet_ntoa(sa.sin_addr), ntohs(sa.sin_port));
(void)close(t->socket);
free(t);
return (SNMP_ERR_GENERR);

View File

@ -24,7 +24,8 @@ DEFS= tree.def
DEFSDIR= ${SHAREDIR}/snmp/defs
CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd -I. -DUSE_LIBBEGEMOT
CFLAGS+= -DUSE_TCPWRAPPERS
CFLAGS+= -DUSE_TCPWRAPPERS -DQUADFMT='"llu"' -DQUADXFMT='"llx"'
CFLAGS+= -DHAVE_STDINT_H -DHAVE_INTTYPES_H
DPADD= ${LIBBEGEMOT} ${LIBBSNMP}
LDADD= -lbegemot -lbsnmp -lwrap