Virgin import of bsnmpd 1.11

This commit is contained in:
Hartmut Brandt 2005-10-04 14:41:06 +00:00
parent 9ed6112d51
commit 165c5d31cb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/bsnmp/dist/; revision=150920
svn path=/vendor/bsnmp/1.11/; revision=150922; tag=vendor/bsnmp/1.11
46 changed files with 37254 additions and 541 deletions

38
contrib/bsnmp/Makefile.in Normal file
View File

@ -0,0 +1,38 @@
# Copyright (c) 2001-2003
# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/Makefile.in,v 1.4 2005/10/04 11:21:22 brandt_h Exp $
#
SUBDIR= lib gensnmptree snmpd snmp_mibII snmp_ntp
ifeq "$(HAVE_LIBSMI)" "yes"
SUBDIR += gensnmpdef
endif
all:
+@for f in $(SUBDIR) ; do \
echo "==> $$f" ; \
if ! $(SUBMAKE) -C $$f all ; then \
break ; \
fi ; \
done
install:
+@for f in $(SUBDIR) ; do \
echo "==> $$f" ; \
if ! $(SUBMAKE) -C $$f install ; then \
break ; \
fi ; \
done
clean:
+@for f in $(SUBDIR) ; do \
echo "==> $$f" ; \
if ! $(SUBMAKE) -C $$f clean ; then \
break ; \
fi ; \
done

View File

@ -1,3 +1,25 @@
1.11 Make the Mib2 routing table use red-black tree. This vastly
reduces loading and access time. Load the table only every 10
minutes. In the meantime process message from the routing socket
to update the table.
Lot of man-page fixes from ru@freebsd.org.
Fixes to command line macros and macro redefinition.
Trap variables for ntp (still need trap definition and code).
Periodic timers from Victor Cruceru.
Man-page fixes from Christian Brueffer.
Lots of spelling fixes from Giorgios Keramidas.
A number of changes to facilitate building on FreeBSD-4 from
Andrey Elsukov.
Add repeatable timers.
1.10 1.10
Change all the tick handling in the daemon from 32-bit to 64-bit. Change all the tick handling in the daemon from 32-bit to 64-bit.
Bump the modules' major version number to 3. Bump the modules' major version number to 3.
@ -34,7 +56,7 @@
Maxim Konovalov) Maxim Konovalov)
1.7 1.7
snmpd: Move event library initialisation before reading of snmpd: Move event library initialization before reading of
config file (thanks to phk). config file (thanks to phk).
gensnmptree: can now read more than one tree and merge them. gensnmptree: can now read more than one tree and merge them.

View File

@ -1 +1 @@
1.10 1.11

5867
contrib/bsnmp/acinclude.m4 Normal file

File diff suppressed because it is too large Load Diff

14
contrib/bsnmp/aclocal.m4 vendored Normal file
View File

@ -0,0 +1,14 @@
# generated automatically by aclocal 1.9.2 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
# Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
m4_include([acinclude.m4])

View File

@ -0,0 +1,11 @@
# Copyright (c) 2004
# Hartmut Brandt
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/config/Makefile.build,v 1.1 2004/04/13 17:01:31 novo Exp $
#
all: build-prog build-lib build-man1 build-man3

View File

@ -0,0 +1,126 @@
# Copyright (c) 2001-2003
# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/config/Makefile.post,v 1.4 2005/10/04 11:21:28 brandt_h Exp $
#
.SUFFIXES: .lo
.c.lo:
@test -d .deps || mkdir .deps >/dev/null 2>&1
$(LIBTOOL) --mode=compile $(CC) -c $(CFLAGS) -o $@ $<
LIBTOOL_DEPS= @LIBTOOL_DEPS@
$(LIBTOOL): $(LIBTOOL_DEPS)
$(SHELL) ../config.status --recheck
clean:
rm -rf *.o .libs .deps *.a *.la *.lo $(PROG) $(LIB) core $(PROG).core $(CLEANFILES)
DEPENDS=$(patsubst %.c,.deps/%.d, $(patsubst %.h,, $(SRCS)))
ifndef MANFILTER
MANFILTER=cat
endif
ifneq "$(MAN1)" ""
build-man1: $(MAN1:%.1=%.1out)
install-man1:
@$(srcdir)/../config/mkinstalldirs $(mandir)/man1
for f in $(MAN1) ; do \
$(BSD_INSTALL_MAN) $${f}out $(mandir)/man1/$${f} ; \
done
%.1out: %.1
cat $< | $(MANFILTER) >$@
else
build-man1:
install-man1:
endif
ifneq "$(MAN3)" ""
build-man3: $(MAN3:%.3=%.3out)
install-man3:
@$(srcdir)/../config/mkinstalldirs $(mandir)/man3
for f in $(MAN3) ; do \
$(BSD_INSTALL_MAN) $${f}out $(mandir)/man3/$${f} ; \
done
%.3out: %.3
cat $< | $(MANFILTER) >$@
else
build-man3:
install-man3:
endif
ifneq "$(DEFS)" ""
install-defs:
@$(srcdir)/../config/mkinstalldirs $(DEFSDIR)
$(BSD_INSTALL_DATA) $(DEFS:%=$(srcdir)/%) $(DEFSDIR)
DEFSDIR= ${datadir}/snmp/defs
else
install-defs:
endif
ifneq "$(INCS)" ""
INCDIR= $(includedir)/bsnmp
install-incs:
@$(srcdir)/../config/mkinstalldirs $(INCDIR)
for f in $(INCS) ; do \
$(BSD_INSTALL_DATA) $(srcdir)/$$f $(INCDIR) ; \
done
else
install-incs:
endif
ifneq "$(BMIBS)" ""
BMIBSDIR= ${datadir}/snmp/mibs
install-mibs:
@$(srcdir)/../config/mkinstalldirs $(BMIBSDIR)
for f in $(BMIBS) ; do \
$(BSD_INSTALL_DATA) $(srcdir)/$$f $(BMIBSDIR) ; \
done
else
install-mibs:
endif
ifneq "$(PROG)" ""
build-prog: $(PROG)
install-prog:
@$(srcdir)/../config/mkinstalldirs $(bindir)
$(LIBTOOL) --mode=install $(BSD_INSTALL_PROGRAM) $(builddir)/$(PROG) $(bindir)/$(PROG)
else
build-prog:
install-prog:
endif
ifneq "$(LIB)" ""
build-lib: $(LIB)
install-lib:
@$(srcdir)/../config/mkinstalldirs $(libdir)
$(LIBTOOL) --mode=install $(BSD_INSTALL_DATA) $(LIB) $(libdir)
else
build-lib:
install-lib:
endif
install: install-prog install-lib install-incs install-man1 install-man3 install-defs install-mibs
-include /dev/null $(DEPENDS)

View File

@ -0,0 +1,66 @@
# Copyright (c) 2004-2005
# Hartmut Brandt.
# All rights reserved.
# Copyright (c) 2001-2003
# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/config/Makefile.pre,v 1.5 2005/10/04 11:21:28 brandt_h Exp $
#
@SET_MAKE@
VPATH+= @srcdir@
srcdir= @srcdir@
top_builddir= @top_builddir@
builddir= @builddir@
prefix= @prefix@
exec_prefix= @exec_prefix@
bindir= @bindir@
sbindir= @sbindir@
libdir= @libdir@
includedir= @includedir@
mandir= @mandir@
datadir= @datadir@
INSTALL= @INSTALL@
INSTALL_PROGRAM= @INSTALL_PROGRAM@
INSTALL_DATA= @INSTALL_DATA@
INSTALL_SCRIPT= @INSTALL_SCRIPT@
ifndef BSD_INSTALL_MAN
BSD_INSTALL_MAN = ${INSTALL_DATA}
endif
ifndef BSD_INSTALL_DATA
BSD_INSTALL_DATA = ${INSTALL_DATA}
endif
ifndef BSD_INSTALL_PROGRAM
BSD_INSTALL_PROGRAM = ${INSTALL_PROGRAM}
endif
LIBTOOL= @LIBTOOL@
CC= @CC@
DEFINES=@DEFS@
CFLAGS= @CFLAGS@
LDFLAGS= @LDFLAGS@
LIBEV= @LIBEV@
LIBWRAP= @LIBWRAP@
# Assume a Posix-ish make that passes MAKEFLAGS in the environment.
SUBMAKE= $(MAKE) --no-print-directory
WARNS= -Wsystem-headers -Werror -Wall -Wno-format-y2k -W \
-Wstrict-prototypes -Wmissing-prototypes \
-Wpointer-arith -Wreturn-type -Wcast-qual \
-Wwrite-strings -Wswitch -Wshadow -Wcast-align \
-Wbad-function-cast -Wchar-subscripts -Winline \
-Wnested-externs -Wredundant-decls -std=c99
CFLAGS+= $(WARNS) -Wp,-MD,.deps/$(*F).d
CFLAGS+= $(DEFINES)
HAVE_LIBSMI=@HAVE_LIBSMI@

1388
contrib/bsnmp/config/config.guess vendored Executable file

File diff suppressed because it is too large Load Diff

1489
contrib/bsnmp/config/config.sub vendored Executable file

File diff suppressed because it is too large Load Diff

236
contrib/bsnmp/config/install.sh Executable file
View File

@ -0,0 +1,236 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5.
#
# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
tranformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain
# $Id: mkinstalldirs,v 1.1 1999/06/17 13:26:38 maw Exp $
errstatus=0
for file
do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d
do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp" 1>&2
mkdir "$pathcomp" || lasterr=$?
if test ! -d "$pathcomp"; then
errstatus=$lasterr
fi
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# mkinstalldirs ends here

20188
contrib/bsnmp/configure vendored Executable file

File diff suppressed because it is too large Load Diff

134
contrib/bsnmp/configure.ac Normal file
View File

@ -0,0 +1,134 @@
#
# Copyright (c) 2004-2005
# Hartmut Brandt.
# All rights reserved.
# Copyright (c) 2003-2003
# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/configure.ac,v 1.8 2005/10/04 11:21:26 brandt_h Exp $
#
AC_INIT([BSNMP], [1.0], [harti@freebsd.org], bsnmp)
AC_PREREQ(2.53)
AC_COPYRIGHT([Copyright (c)1996-2003 Fraunhofer Fokus. All rights reserved.])
AC_REVISION($Revision$)
AC_CONFIG_SRCDIR(config/install.sh)
AC_CONFIG_AUX_DIR(config)
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AC_PROG_CC
AC_PROG_CPP
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_ARG_WITH(libbegemot,
AC_HELP_STRING([--with-libbegemot],
[use libbegemot instead of libisc and set path to where the
includes and lib are found(default is NO, if no path specified default=/usr/local)]),
ac_cv_use_libbegemot=$withval, ac_cv_use_libbegemot=no)
AC_CACHE_CHECK(whether to use libbegemot,
ac_cv_use_libbegemot, ac_cv_use_libbegemot=no)
if test $ac_cv_use_libbegemot == "yes" ; then
ac_cv_use_libbegemot="/usr/local"
fi
if test $ac_cv_use_libbegemot != "no" ; then
AC_DEFINE(USE_LIBBEGEMOT)
AC_SUBST(LIBEV, -lbegemot)
CFLAGS="${CFLAGS} -I$ac_cv_use_libbegemot/include"
LDFLAGS="${LDFLAGS} -L$ac_cv_use_libbegemot/lib"
AC_CHECK_LIB(begemot, poll_register, ,
[AC_ERROR([libbegemot not found])])
else
AC_SUBST(LIBEV, -lisc)
fi
AC_ARG_WITH(tcpwrappers,
AC_HELP_STRING([--with-tcpwrappers],
[use libwrap to control access]),
ac_cv_use_tcpwrappers=$withval, ac_cv_use_tcpwrappers=no)
if test $ac_cv_use_tcpwrappers != "no" ; then
AC_DEFINE(USE_TCPWRAPPERS)
AC_SUBST(LIBWRAP, -lwrap)
fi
LDFLAGS="${LDFLAGS} -L/usr/local/lib"
AC_CHECK_LIB(smi, smiGetNode, HAVE_LIBSMI=yes, HAVE_LIBSMI=no)
AC_SUBST(HAVE_LIBSMI)
# check for BSD's err.h
AC_CHECK_HEADERS([err.h])
# check for strlcpy
AC_CHECK_FUNCS(strlcpy)
# check for getaddrinfo
AC_CHECK_FUNCS(getaddrinfo)
AC_CHECK_HEADER(stdint.h,
AC_DEFINE(HAVE_STDINT_H))
AC_CHECK_HEADER(inttypes.h,
[AC_DEFINE(HAVE_INTTYPES_H)
ac_have_inttypes_h=yes])
AC_CACHE_CHECK([how to print quads],
ac_cv_quad_fmt,
[if test "$ac_have_inttypes_h" = "yes" ; then
AC_EGREP_CPP(yes,
[
# include <inttypes.h>
# ifdef PRIu64
yes
# endif
],
ac_cv_quad_fmt=PRIu64,
AC_TRY_RUN(
[[
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
int
main()
{
char buf[100];
sprintf(buf, "%llx", 0x1234567887654321LLU);
exit((strcmp(buf, "1234567887654321") == 0) ? 0 : 1);
}
]],
ac_cv_quad_fmt='"ll"',
ac_cv_quad_fmt='"q"',
ac_cv_quad_fmt='"q"')
fi ]))
if test "$ac_cv_quad_fmt" = "PRIu64" ; then
AC_DEFINE(QUADFMT, PRIu64)
AC_DEFINE(QUADXFMT, PRIx64)
else
AC_DEFINE_UNQUOTED(QUADFMT, ${ac_cv_quad_fmt}"u")
AC_DEFINE_UNQUOTED(QUADXFMT, ${ac_cv_quad_fmt}"x")
fi
AC_CONFIG_FILES([
Makefile:config/Makefile.pre:Makefile.in
lib/Makefile:config/Makefile.pre:config/Makefile.build:lib/Makefile.in:config/Makefile.post
gensnmptree/Makefile:config/Makefile.pre:config/Makefile.build:gensnmptree/Makefile.in:config/Makefile.post
gensnmpdef/Makefile:config/Makefile.pre:config/Makefile.build:gensnmpdef/Makefile.in:config/Makefile.post
snmpd/Makefile:config/Makefile.pre:config/Makefile.build:snmpd/Makefile.in:config/Makefile.post
snmp_mibII/Makefile:config/Makefile.pre:config/Makefile.build:snmp_mibII/Makefile.in:config/Makefile.post
snmp_ntp/Makefile:config/Makefile.pre:config/Makefile.build:snmp_ntp/Makefile.in:config/Makefile.post
])
AC_OUTPUT

View File

@ -0,0 +1,17 @@
# Copyright (c) 2004
# Hartmut Brandt
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/gensnmpdef/Makefile.in,v 1.2 2004/04/14 09:54:51 novo Exp $
#
PROG= gensnmpdef
SRCS= gensnmpdef.c
MAN1= gensnmpdef.1
CFLAGS+= -I/usr/local/include
$(PROG): $(SRCS:.c=.lo)
$(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(SRCS:.c=.lo) -lsmi

View File

@ -1,5 +1,5 @@
.\" .\"
.\" Copyright (C) 2004 .\" Copyright (C) 2004-2005
.\" Hartmut Brandt. .\" Hartmut Brandt.
.\" All rights reserved. .\" All rights reserved.
.\" .\"
@ -26,9 +26,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $Begemot: bsnmp/gensnmpdef/gensnmpdef.1,v 1.3 2005/02/25 11:55:54 brandt_h Exp $ .\" $Begemot: bsnmp/gensnmpdef/gensnmpdef.1,v 1.5 2005/10/04 08:46:46 brandt_h Exp $
.\" .\"
.Dd April 14, 2004 .Dd June 14, 2005
.Dt GENSNMPDEF 1 .Dt GENSNMPDEF 1
.Os .Os
.Sh NAME .Sh NAME
@ -43,7 +43,8 @@
The The
.Nm .Nm
utility is used to create an initial MIB description file from utility is used to create an initial MIB description file from
one or more MIBs. The description file must be edited to be actually useful one or more MIBs.
The description file must be edited to be actually useful
for feeding it into for feeding it into
.Xr gensnmptree 1 . .Xr gensnmptree 1 .
.Pp .Pp
@ -57,13 +58,13 @@ of 3 is just correct in most cases.
.Pp .Pp
.Nm .Nm
does no attempt on sorting the OID tree so in case of complex and does no attempt on sorting the OID tree so in case of complex and
non-standard MIBs it is necessay to sort the tree in the resulting definition non-standard MIBs it is necessary to sort the tree in the resulting definition
file by hand. file by hand.
.Sh SEE ALSO .Sh SEE ALSO
.Xr snmpd 1 .Xr snmpd 1
.Sh AUTHORS
.An Hartmut Brandt Aq harti@freebsd.org
.Sh BUGS .Sh BUGS
The utility is by no means bullet-proof and may fail for complex The utility is by no means bullet-proof and may fail for complex
or non-standard MIBs. or non-standard MIBs.
Its output is expected to be edited by hand. Its output is expected to be edited by hand.
.Sh AUTHORS
.An Hartmut Brandt Aq harti@freebsd.org

View File

@ -0,0 +1,17 @@
# Copyright (c) 2001-2003
# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/gensnmptree/Makefile.in,v 1.3 2004/04/13 17:01:31 novo Exp $
#
PROG= gensnmptree
SRCS= gensnmptree.c
MAN1= gensnmptree.1
CFLAGS+= -I$(srcdir)/../lib
$(PROG): $(SRCS:.c=.lo)
$(LIBTOOL) --mode=link $(CC) $(LDLAGS) -o $@ $(SRCS:.c=.lo)

View File

@ -1,5 +1,5 @@
.\" .\"
.\" Copyright (c) 2001-2003 .\" Copyright (c) 2001-2005
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). .\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved. .\" All rights reserved.
.\" .\"
@ -26,9 +26,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $Begemot: bsnmp/gensnmptree/gensnmptree.1,v 1.4 2005/02/25 11:55:56 brandt_h Exp $ .\" $Begemot: bsnmp/gensnmptree/gensnmptree.1,v 1.5 2005/06/15 11:31:25 brandt_h Exp $
.\" .\"
.Dd October 7, 2003 .Dd June 14, 2005
.Dt GENSNMPTREE 1 .Dt GENSNMPTREE 1
.Os .Os
.Sh NAME .Sh NAME
@ -43,8 +43,8 @@
The The
.Nm .Nm
utility is used to either generate C language tables and header files from utility is used to either generate C language tables and header files from
a MIB description or to numeric OIDs from MIB descriptions. The first form a MIB description or to numeric OIDs from MIB descriptions.
is used only for maintaining the The first form is used only for maintaining the
.Xr snmpd 1 .Xr snmpd 1
daemon or for module writers. daemon or for module writers.
The second form may be used by SNMP client program writers. The second form may be used by SNMP client program writers.
@ -70,7 +70,8 @@ option is specified
.Nm .Nm
expects MIB variable names (only the last component) on its command line. expects MIB variable names (only the last component) on its command line.
It reads a MIB specification from standard input and for each MIB variable It reads a MIB specification from standard input and for each MIB variable
name emits two C preprocessor defines on its standard output. One define name emits two C preprocessor defines on its standard output.
One define
.Va OID_ Ns Ar name .Va OID_ Ns Ar name
can be used as an array initialized to initialize a can be used as an array initialized to initialize a
.Va struct asn_oid . .Va struct asn_oid .
@ -85,7 +86,8 @@ Print a short help page.
.It Fl e .It Fl e
Enter extract mode. Enter extract mode.
.It Fl l .It Fl l
Generate local preprocessor includes. This is used for bootstrapping Generate local preprocessor includes.
This is used for bootstrapping
.Xr snmpd 1 . .Xr snmpd 1 .
.It Fl t .It Fl t
Instead of normal output print the resulting tree. Instead of normal output print the resulting tree.

View File

@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/gensnmptree/gensnmptree.c,v 1.42 2005/04/26 16:26:19 brandt_h Exp $ * $Begemot: bsnmp/gensnmptree/gensnmptree.c,v 1.43 2005/10/04 11:21:29 brandt_h Exp $
* *
* Generate OID table from table description. * Generate OID table from table description.
* *
@ -595,7 +595,9 @@ gen_table(struct node *node)
fprintf(fp, "#include <sys/types.h>\n"); fprintf(fp, "#include <sys/types.h>\n");
fprintf(fp, "#include <stdio.h>\n"); fprintf(fp, "#include <stdio.h>\n");
#ifdef HAVE_STDINT_H
fprintf(fp, "#include <stdint.h>\n"); fprintf(fp, "#include <stdint.h>\n");
#endif
if (localincs) { if (localincs) {
fprintf(fp, "#include \"asn1.h\"\n"); fprintf(fp, "#include \"asn1.h\"\n");
fprintf(fp, "#include \"snmp.h\"\n"); fprintf(fp, "#include \"snmp.h\"\n");

View File

@ -0,0 +1,20 @@
# Copyright (c) 2003-2003
# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/lib/Makefile.in,v 1.4 2004/08/06 08:46:47 brandt Exp $
#
SRCS= asn1.c snmp.c snmpagent.c snmpclient.c support.c
INCS= asn1.h snmp.h snmpagent.h snmpclient.h
MAN3= asn1.3 bsnmplib.3 bsnmpclient.3 bsnmpagent.3
LIB= libbsnmp.la
SHLIB_MAJOR= 2
SHLIB_MINOR= 0
CFLAGS+= -I$(srcdir)
$(LIB): $(SRCS:.c=.lo)
$(LIBTOOL) --mode=link $(CC) $(LDLAGS) -o $@ $(SRCS:.c=.lo) -rpath $(libdir) -version-info $(SHLIB_MAJOR):$(SHLIB_MINOR)

View File

@ -1,4 +1,7 @@
.\" .\"
.\" Copyright (c) 2004-2005
.\" Hartmut Brandt.
.\" All rights reserved.
.\" Copyright (c) 2001-2003 .\" Copyright (c) 2001-2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). .\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved. .\" All rights reserved.
@ -26,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $Begemot: bsnmp/lib/asn1.3,v 1.6 2005/02/25 11:55:57 brandt_h Exp $ .\" $Begemot: bsnmp/lib/asn1.3,v 1.9 2005/10/04 08:46:49 brandt_h Exp $
.\" .\"
.Dd August 15, 2002 .Dd October 4, 2005
.Dt ASN1 3 .Dt ASN1 3
.Os .Os
.Sh NAME .Sh NAME
@ -142,8 +145,8 @@ Begemot SNMP library
.Fn asn_oid2str "const struct asn_oid *oid" .Fn asn_oid2str "const struct asn_oid *oid"
.Sh DESCRIPTION .Sh DESCRIPTION
The ASN.1 library contains routines to handle ASN.1 encoding for SNMP. The ASN.1 library contains routines to handle ASN.1 encoding for SNMP.
It supports only the restricted form of ASN.1 as required by SNMP. There It supports only the restricted form of ASN.1 as required by SNMP.
are two basic structures used throughout the library: There are two basic structures used throughout the library:
.Bd -literal -offset indent .Bd -literal -offset indent
/* these restrictions are in the SMI */ /* these restrictions are in the SMI */
#define ASN_MAXID 0xffffffff #define ASN_MAXID 0xffffffff
@ -176,17 +179,18 @@ struct asn_buf {
#define asn_ptr asn_u.ptr #define asn_ptr asn_u.ptr
.Ed .Ed
.Pp .Pp
This structure is used to encode and decode ASN.1. It describes the output This structure is used to encode and decode ASN.1.
It describes the output
buffer for encoding routines and the input buffer for decoding routines. buffer for encoding routines and the input buffer for decoding routines.
For encoding For encoding
.Fa asn_len .Fa asn_len
holds the number of remaining free octets in the buffer. The first free byte holds the number of remaining free octets in the buffer.
is pointed to by The first free byte is pointed to by
.Fa asn_ptr . .Fa asn_ptr .
For decoding For decoding
.Fa asn_len .Fa asn_len
holds the number of remaining bytes to decode. The next byte to decode is pointed holds the number of remaining bytes to decode.
to by The next byte to decode is pointed to by
.Fa asn_cptr . .Fa asn_cptr .
.Pp .Pp
Most of the functions return an error code Most of the functions return an error code
@ -216,20 +220,20 @@ of error.
.Pp .Pp
The function The function
.Fn asn_get_header .Fn asn_get_header
reads the next header from the input octet stream. It returns the tag reads the next header from the input octet stream.
in the variable pointed to by It returns the tag in the variable pointed to by
.Fa type .Fa type
(note that only single byte tags are supported) and the decoded length field (note that only single byte tags are supported) and the decoded length field
in the value pointed to by in the value pointed to by
.Fa lenp .Fa lenp
(this is restricted to a unsigned 32-bit value). All errors in this function (this is restricted to a unsigned 32-bit value).
are fatal and stop processing. All errors in this function are fatal and stop processing.
.Pp .Pp
The function The function
.Fn asn_put_header .Fn asn_put_header
writes an ASN.1 header. writes an ASN.1 header.
.Fa type .Fa type
is the tag to write and is restricted to one byte tags (i.e. tags is the tag to write and is restricted to one byte tags (i.e., tags
lesser or equal than 0x30). lesser or equal than 0x30).
.Fa len .Fa len
is the length of the value and is restricted to 16-bit. is the length of the value and is restricted to 16-bit.
@ -246,15 +250,18 @@ writes a header with the given tag
and space for the maximum supported length field and sets the pointer pointed and space for the maximum supported length field and sets the pointer pointed
to by to by
.Fa ptr .Fa ptr
to the begin of this length field. This pointer must then be fed into to the begin of this length field.
This pointer must then be fed into
.Fn asn_commit_header .Fn asn_commit_header
directly after writing the value to the buffer. The function will compute the directly after writing the value to the buffer.
The function will compute the
length, insert it into the right place and shift the value if the resulting length, insert it into the right place and shift the value if the resulting
length field is shorter than the estimated one. length field is shorter than the estimated one.
.Pp .Pp
The function The function
.Fn asn_get_integer_raw .Fn asn_get_integer_raw
is used to decode a signed integer value (32-bit). It assumes, that the is used to decode a signed integer value (32-bit).
It assumes, that the
header of the integer has been decoded already. header of the integer has been decoded already.
.Fa len .Fa len
is the length obtained from the ASN.1 header and the integer will be returned is the length obtained from the ASN.1 header and the integer will be returned
@ -263,8 +270,8 @@ in the value pointed to by
.Pp .Pp
The function The function
.Fn asn_get_integer .Fn asn_get_integer
decodes a complete 32-bit signed integer including the header. If the decodes a complete 32-bit signed integer including the header.
tag is wrong If the tag is wrong
.Li ASN_ERR_TAG .Li ASN_ERR_TAG
is returned. is returned.
The function The function
@ -273,14 +280,16 @@ encodes a 32-bit signed integer.
.Pp .Pp
The function The function
.Fn asn_get_octetstring_raw .Fn asn_get_octetstring_raw
decodes the value field of an ASN.1 octet string. The length obtained from the decodes the value field of an ASN.1 octet string.
header must be fed into the The length obtained from the header must be fed into the
.Fa len .Fa len
argument and argument and
.Fa out .Fa out
must point to a buffer to receive the octet string. On entry to the function must point to a buffer to receive the octet string.
On entry to the function
.Fa outsize .Fa outsize
must point to the size of the buffer. On exit must point to the size of the buffer.
On exit
.Fa outsize .Fa outsize
will point to the number of octets decoded (if no error occurs this will be will point to the number of octets decoded (if no error occurs this will be
equal to equal to
@ -291,7 +300,8 @@ decodes an octetstring including the header.
.Fa out .Fa out
must point to a buffer to receive the string, must point to a buffer to receive the string,
.Fa outsize .Fa outsize
must point to the size of the buffer. On exit of the function must point to the size of the buffer.
On exit of the function
.Fa outsize .Fa outsize
will point to the number of octets decoded. will point to the number of octets decoded.
The function The function
@ -316,7 +326,8 @@ encodes a null.
.Pp .Pp
The function The function
.Fn asn_put_exception .Fn asn_put_exception
is used to encode an SNMPv2 exception. The exception type is is used to encode an SNMPv2 exception.
The exception type is
.Fa type . .Fa type .
.Pp .Pp
The function The function
@ -369,8 +380,8 @@ The function
.Fn asn_get_counter64_raw .Fn asn_get_counter64_raw
decodes an unsigned 64-bit integer value. decodes an unsigned 64-bit integer value.
.Fa len .Fa len
must be the value length from the header. The resulting value is must be the value length from the header.
stored into the variable pointed to by The resulting value is stored into the variable pointed to by
.Fa res . .Fa res .
The function The function
.Fn asn_put_counter64 .Fn asn_put_counter64
@ -392,12 +403,12 @@ bytes in the input buffer.
.Pp .Pp
The function The function
.Fn asn_slice_oid .Fn asn_slice_oid
splits a part out from an OID. It takes all the subids from the OID splits a part out from an OID.
pointed to by It takes all the subids from the OID pointed to by
.Fa src .Fa src
starting with the subid at position starting with the subid at position
.Fa from .Fa from
(the first subid beeing subid 0) up to, but not including, subid (the first subid being subid 0) up to, but not including, subid
.Fa to .Fa to
and generates a new OID in and generates a new OID in
.Fa dest . .Fa dest .
@ -413,8 +424,8 @@ appends the OID
.Fa from .Fa from
to the OID to the OID
.Fa to .Fa to
given that the resulting OID is not too long. If the maximum length is exceeded given that the resulting OID is not too long.
the result is undefined. If the maximum length is exceeded the result is undefined.
.Pp .Pp
The function The function
.Fn asn_compare_oid .Fn asn_compare_oid
@ -442,7 +453,8 @@ makes a printable string from
.Fa oid . .Fa oid .
The buffer pointed to by The buffer pointed to by
.Fa str .Fa str
must be large enough to hold the result. The constant must be large enough to hold the result.
The constant
.Li ASN_OIDSTRLEN .Li ASN_OIDSTRLEN
is defined to be the length of the maximum string generated by this function is defined to be the length of the maximum string generated by this function
(including the trailing NUL). (including the trailing NUL).
@ -452,7 +464,7 @@ makes a printable string from
.Fa oid .Fa oid
into a private buffer that is overwritten by each call. into a private buffer that is overwritten by each call.
.Sh DIAGNOSTICS .Sh DIAGNOSTICS
When an error occures in any of the function the function pointed to When an error occurs in any of the function the function pointed to
by the global pointer by the global pointer
.Bd -literal -offset indent .Bd -literal -offset indent
extern void (*asn_error)(const struct asn_buf *, const char *, ...); extern void (*asn_error)(const struct asn_buf *, const char *, ...);
@ -469,7 +481,7 @@ starting with
followed by the error message and an optional dump of the buffer. followed by the error message and an optional dump of the buffer.
.Sh SEE ALSO .Sh SEE ALSO
.Xr gensnmptree 1 , .Xr gensnmptree 1 ,
.Xr snmpd 1 , .Xr bsnmpd 1 ,
.Xr bsnmpagent 3 , .Xr bsnmpagent 3 ,
.Xr bsnmpclient 3 , .Xr bsnmpclient 3 ,
.Xr bsnmplib 3 .Xr bsnmplib 3

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/lib/asn1.c,v 1.28 2004/08/06 08:46:49 brandt Exp $ * $Begemot: bsnmp/lib/asn1.c,v 1.29 2005/10/04 11:21:31 brandt_h Exp $
* *
* ASN.1 for SNMP. * ASN.1 for SNMP.
*/ */
@ -35,7 +35,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#elif defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#endif
#include <assert.h> #include <assert.h>
#include "asn1.h" #include "asn1.h"

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/lib/asn1.h,v 1.18 2004/08/06 08:46:50 brandt Exp $ * $Begemot: bsnmp/lib/asn1.h,v 1.19 2005/10/04 11:21:31 brandt_h Exp $
* *
* ASN.1 for SNMP * ASN.1 for SNMP
*/ */
@ -179,4 +179,14 @@ enum {
ASN_EXCEPT_ENDOFMIBVIEW = 0x02, ASN_EXCEPT_ENDOFMIBVIEW = 0x02,
}; };
#if !defined(INT32_MIN)
#define INT32_MIN (-0x7fffffff-1)
#endif
#if !defined(INT32_MAX)
#define INT32_MAX (0x7fffffff)
#endif
#if !defined(UINT32_MAX)
#define UINT32_MAX (0xffffffff)
#endif
#endif #endif

View File

@ -1,4 +1,7 @@
.\" .\"
.\" Copyright (c) 2004-2005
.\" Hartmut Brandt.
.\" All rights reserved.
.\" Copyright (c) 2001-2003 .\" Copyright (c) 2001-2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). .\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved. .\" All rights reserved.
@ -26,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $Begemot: bsnmp/lib/bsnmpagent.3,v 1.7 2005/02/25 11:55:58 brandt_h Exp $ .\" $Begemot: bsnmp/lib/bsnmpagent.3,v 1.10 2005/10/04 08:46:49 brandt_h Exp $
.\" .\"
.Dd August 16, 2002 .Dd October 4, 2005
.Dt BSNMPAGENT 3 .Dt BSNMPAGENT 3
.Os .Os
.Sh NAME .Sh NAME
@ -87,14 +90,15 @@ Begemot SNMP library
.Fn snmp_dep_finish "struct snmp_context *ctx" .Fn snmp_dep_finish "struct snmp_context *ctx"
.Sh DESCRIPTION .Sh DESCRIPTION
The SNMP library contains routines to easily build SNMP agent applications The SNMP library contains routines to easily build SNMP agent applications
that use SNMP versions 1 or 2. Note, however, that it may be even easier to that use SNMP versions 1 or 2.
build an Note, however, that it may be even easier to build an
.Xr snmpd 1 .Xr bsnmpd 1
loadable module, that handles the new MIB (see loadable module, that handles the new MIB (see
.Xr snmpmod 3 ). .Xr snmpmod 3 ) .
.Pp .Pp
Most of the agent routines operate on a global array that the describes the Most of the agent routines operate on a global array that the describes the
complete MIB served by the agent. This array is held in the two variables: complete MIB served by the agent.
This array is held in the two variables:
.Bd -literal -offset indent .Bd -literal -offset indent
extern struct snmp_node *tree; extern struct snmp_node *tree;
extern u_int tree_size; extern u_int tree_size;
@ -126,7 +130,8 @@ Base OID of the scalar or table column.
.It Va name .It Va name
Name of this variable. Name of this variable.
.It Va type .It Va type
Type of this variable. One of: Type of this variable.
One of:
.Bd -literal -offset indent .Bd -literal -offset indent
enum snmp_node_type { enum snmp_node_type {
SNMP_NODE_LEAF = 1, SNMP_NODE_LEAF = 1,
@ -136,17 +141,20 @@ enum snmp_node_type {
.It Va syntax .It Va syntax
The SNMP syntax of this variable. The SNMP syntax of this variable.
.It Va op .It Va op
The user supplied handler for this variable. The handler is called with The user supplied handler for this variable.
the following arguments: The handler is called with the following arguments:
.Bl -tag -width "ctx" .Bl -tag -width "ctx"
.It Fa ctx .It Fa ctx
A pointer to the context (see below). A pointer to the context (see below).
.Li NULL . .Li NULL .
.It Fa val .It Fa val
The value to be set or retrieved. For GETNEXT and GETBULK operations the oid in The value to be set or retrieved.
this value is the current OID. The function (called in this case only for For GETNEXT and GETBULK operations the oid in
this value is the current OID.
The function (called in this case only for
table rows) must find the lexically next existing OID within the same column and table rows) must find the lexically next existing OID within the same column and
set the oid and value subfields accordingly. If the table column is exhausted the set the oid and value subfields accordingly.
If the table column is exhausted the
function must return function must return
.Li SNMP_ERR_NOSUCHNAME . .Li SNMP_ERR_NOSUCHNAME .
For all other operations the oid in For all other operations the oid in
@ -169,18 +177,20 @@ enum snmp_op {
.Ed .Ed
.El .El
.Pp .Pp
The user handler must return an appropiate SNMP v2 error code. If the original The user handler must return an appropriate SNMP v2 error code.
If the original
PDU was a version 1 PDU, the error code is mapped automatically. PDU was a version 1 PDU, the error code is mapped automatically.
.It Va flags .It Va flags
Currently only the flag Currently only the flag
.Li SNMP_NODE_CANSET is defined and set for nodes, that can be written or .Li SNMP_NODE_CANSET is defined and set for nodes, that can be written or
created. created.
.It Va index .It Va index
This word describes the index for table columns. Each part of the index This word describes the index for table columns.
takes 4 bits starting at bit 4. Bits 0 to 3 hold the number of index parts. Each part of the index takes 4 bits starting at bit 4.
This arrangment allows for tables with up to seven indexes. Each bit group Bits 0 to 3 hold the number of index parts.
contains the syntax for the index part. There are a number of macros to This arrangement allows for tables with up to seven indexes.
help in parsing this field: Each bit group contains the syntax for the index part.
There are a number of macros to help in parsing this field:
.Bd -literal -offset indent .Bd -literal -offset indent
#define SNMP_INDEXES_MAX 7 #define SNMP_INDEXES_MAX 7
#define SNMP_INDEX_SHIFT 4 #define SNMP_INDEX_SHIFT 4
@ -197,8 +207,9 @@ This field may contain arbitrary data and is not used by the library.
The easiest way to construct the node table is The easiest way to construct the node table is
.Xr gensnmptree 1 . .Xr gensnmptree 1 .
Note, that one must be careful when changing the tree while executing a SET Note, that one must be careful when changing the tree while executing a SET
operation. Consult the sources for operation.
.Xr snmpd 1 . Consult the sources for
.Xr bsnmpd 1 .
.Pp .Pp
The global variable The global variable
.Va snmp_trace .Va snmp_trace
@ -218,7 +229,8 @@ enum {
.Pp .Pp
Setting a bit to true causes the library to call Setting a bit to true causes the library to call
.Fn snmp_debug .Fn snmp_debug
in strategic places with a debug string. The library contains a default in strategic places with a debug string.
The library contains a default
implementation for the debug function that prints a message to standard error. implementation for the debug function that prints a message to standard error.
.Pp .Pp
Many of the functions use a so called context: Many of the functions use a so called context:
@ -234,8 +246,8 @@ struct snmp_context {
struct snmp_scratch { struct snmp_scratch {
void *ptr1; void *ptr1;
void *ptr2; void *ptr2;
u_int32_t int1; uint32_t int1;
u_int32_t int2; uint32_t int2;
}; };
.Ed .Ed
.Pp .Pp
@ -243,15 +255,17 @@ The fields are used as follows:
.Bl -tag -width ".It Va var_index" .Bl -tag -width ".It Va var_index"
.It Va va_index .It Va va_index
For the node operation callback this is the For the node operation callback this is the
index of the variable binding that should be returned if an error occures. index of the variable binding that should be returned if an error occurs.
Set by the library. In all other functions this is undefined. Set by the library.
In all other functions this is undefined.
.It Va scratch .It Va scratch
For the node operation callback this is a pointer to a per variable binding For the node operation callback this is a pointer to a per variable binding
scratch area that can be used to implement the commit and rollback. Set scratch area that can be used to implement the commit and rollback.
by the library. Set by the library.
.It Va dep .It Va dep
In the dependency callback function (see below) this is a pointer to the In the dependency callback function (see below) this is a pointer to the
current dependency. Set by the library. current dependency.
Set by the library.
.It Va data .It Va data
This is the This is the
.Fa data .Fa data
@ -267,21 +281,24 @@ executes an SNMP GETNEXT operation and the function
.Fn snmp_getbulk .Fn snmp_getbulk
executes an SNMP GETBULK operation. executes an SNMP GETBULK operation.
For all three functions the response PDU is constructed and encoded For all three functions the response PDU is constructed and encoded
on the fly. If everything is ok, the response PDU is returned in on the fly.
If everything is ok, the response PDU is returned in
.Fa resp .Fa resp
and and
.Fa resp_b . .Fa resp_b .
The caller must call The caller must call
.Fn snmp_pdu_free .Fn snmp_pdu_free
to free the response PDU in this case. One of the following values may be to free the response PDU in this case.
returned: One of the following values may be returned:
.Bl -tag -width ".It Li SNMP_RET_ERR" .Bl -tag -width ".It Li SNMP_RET_ERR"
.It Li SNMP_RET_OK .It Li SNMP_RET_OK
Operation successful, response PDU may be sent. Operation successful, response PDU may be sent.
.It Li SNMP_RET_IGN .It Li SNMP_RET_IGN
Operation failed, no response PDU constructed. Request is ignored. Operation failed, no response PDU constructed.
Request is ignored.
.It Li SNMP_RET_ERR .It Li SNMP_RET_ERR
Error in operation. The error code and index have been set in Error in operation.
The error code and index have been set in
.Fa pdu . .Fa pdu .
No response PDU has been constructed. No response PDU has been constructed.
The caller may construct an error response PDU via The caller may construct an error response PDU via
@ -290,47 +307,56 @@ The caller may construct an error response PDU via
.Pp .Pp
The function The function
.Fn snmp_set .Fn snmp_set
executes an SNMP SET operation. The arguments are the same as for the previous executes an SNMP SET operation.
three functions. The operation of this functions is, however, much more complex. The arguments are the same as for the previous
three functions.
The operation of this functions is, however, much more complex.
.Pp .Pp
The SET operation occures in several stages: The SET operation occurs in several stages:
.Bl -enum -offset indent .Bl -enum -offset indent
.It .It
For each binding search the corresponding nodes, check that the For each binding search the corresponding nodes, check that the
variable is writeable and the syntax is ok. The writeable check can be done variable is writeable and the syntax is ok.
only for scalars. For columns it must be done in the node's operation callback The writeable check can be done only for scalars.
function. For columns it must be done in the node's operation callback function.
.It .It
For each binding call the node's operation callback with function SNMP_OP_SET. For each binding call the node's operation callback with function SNMP_OP_SET.
The callback may create dependencies or finalizers (see below). For simple The callback may create dependencies or finalizers (see below).
For simple
scalars the scratch area may be enough to handle commit and rollback, for scalars the scratch area may be enough to handle commit and rollback, for
interdependend table columns dependencies may be necessary. interdependent table columns dependencies may be necessary.
.It .It
If the previous step fails at any point, the node's operation callback If the previous step fails at any point, the node's operation callback
functions are called for all bindings for which SNMP_OP_SET was executed functions are called for all bindings for which SNMP_OP_SET was executed
with SNMP_OP_ROLLBACK, in the opposite order. This allows all variables to with SNMP_OP_ROLLBACK, in the opposite order.
undo the effect of the SET operation. After this all the dependencies This allows all variables to undo the effect of the SET operation.
are freed After this all the dependencies are freed
and the finalizers are executed with a fail flag of 1. Then the function and the finalizers are executed with a fail flag of 1.
Then the function
returns to the caller with an appropriate error indication. returns to the caller with an appropriate error indication.
.It .It
If the SET step was successful for all bindings, the dependency callbacks If the SET step was successful for all bindings, the dependency callbacks
are executed in the order in which the dependencies were created with an are executed in the order in which the dependencies were created with an
operation of SNMP_DEPOP_COMMIT. If any of the dependencies fails, all the operation of SNMP_DEPOP_COMMIT.
If any of the dependencies fails, all the
committed dependencies are called again in the opposite order committed dependencies are called again in the opposite order
with SNMP_DEPOP_ROLLBACK. Than for all bindings from the last to the first with SNMP_DEPOP_ROLLBACK.
Than for all bindings from the last to the first
the node's operation callback is called with SNMP_OP_ROLLBACK to undo the node's operation callback is called with SNMP_OP_ROLLBACK to undo
the effect of SNMP_OP_SET. At the end the dependencies are freed the effect of SNMP_OP_SET.
and the finalizers are called with a fail flag At the end the dependencies are freed and the finalizers are called with
of 1 and the function returns to the caller with an appropriate error indication. a fail flag of 1 and the function returns to the caller with an appropriate
error indication.
.It .It
If the dependency commits were successful, for each binding the node's If the dependency commits were successful, for each binding the node's
operation callback is called with SNMP_OP_COMMIT. Any error returned from operation callback is called with SNMP_OP_COMMIT.
Any error returned from
the callbacks is ignored (an error message is generated via the callbacks is ignored (an error message is generated via
.Fn snmp_error ). .Fn snmp_error ).
.It .It
Now the dependencies are freed and the finalizers are called Now the dependencies are freed and the finalizers are called
with a fail flag of 0. For each dependency just before freeing it with a fail flag of 0.
For each dependency just before freeing it
its callback is called with its callback is called with
.Li SNMP_DEPOP_FINISH. .Li SNMP_DEPOP_FINISH.
Then the function returns Then the function returns
@ -338,20 +364,26 @@ Then the function returns
.El .El
.Pp .Pp
There are to mechanisms to help in complex SET operations: dependencies and There are to mechanisms to help in complex SET operations: dependencies and
finalizers. A dependency is used if several bindings depend on each other. finalizers.
A dependency is used if several bindings depend on each other.
A typical example is the creation of a conceptual row, which requires A typical example is the creation of a conceptual row, which requires
the setting of several columns to succeed. A dependency is identified by the setting of several columns to succeed.
two OIDs. In the table case, the first oid is typically the table's base OID A dependency is identified by
and the second one the index. Both of these can easily be generated from the two OIDs.
In the table case, the first oid is typically the table's base OID
and the second one the index.
Both of these can easily be generated from the
variables OID with variables OID with
.Fn asn_slice_oid . .Fn asn_slice_oid .
The function The function
.Fn snmp_dep_lookup .Fn snmp_dep_lookup
tries to find a dependency based on these two OIDs and, if it cannot find one tries to find a dependency based on these two OIDs and, if it cannot find one
creates a new one. This means for the table example, that the function creates a new one.
This means for the table example, that the function
returns the same dependency for each of the columns of the same table row. returns the same dependency for each of the columns of the same table row.
This allows during the SNMP_OP_SET processing to collect all information This allows during the SNMP_OP_SET processing to collect all information
about the row into the dependency. The arguments to about the row into the dependency.
The arguments to
.Fn snmp_dep_lookup .Fn snmp_dep_lookup
are: the two OIDs to identify the dependency (they are copied into newly are: the two OIDs to identify the dependency (they are copied into newly
created dependencies), the size of the structure to allocate and created dependencies), the size of the structure to allocate and
@ -369,16 +401,17 @@ freed correctly.
.Pp .Pp
The function The function
.Fn snmp_make_errresp .Fn snmp_make_errresp
makes an error response if an operation has failed. It takes the original makes an error response if an operation has failed.
request PDU (it will look only on the error code and index fields), the It takes the original request PDU (it will look only on the error code and
buffer containing the original PDU and a buffer for the error PDU. It copies index fields), the buffer containing the original PDU and a buffer for the
the bindings field from the original PDUs buffer directly to the response error PDU.
PDU and thus does not depend on the decodability of this field. It may return It copies the bindings field from the original PDUs buffer directly to
the same values as the operation functions. the response PDU and thus does not depend on the decodability of this field.
It may return the same values as the operation functions.
.Pp .Pp
The next four functions allow some parts of the SET operation to be executed. The next four functions allow some parts of the SET operation to be executed.
This is only used in This is only used in
.Xr snmpd 1 .Xr bsnmpd 1
to implement the configuration as a single transaction. to implement the configuration as a single transaction.
The function The function
.Fn snmp_init_context .Fn snmp_init_context
@ -395,12 +428,12 @@ The function
.Fn snmp_dep_finish .Fn snmp_dep_finish
executes SNMP_DEPOP_FINISH for all dependencies. executes SNMP_DEPOP_FINISH for all dependencies.
.Sh DIAGNOSTICS .Sh DIAGNOSTICS
If an error occures in any of the function an error indication as described If an error occurs in any of the function an error indication as described
above is returned. Additionally the functions may call snmp_error on unexected above is returned.
errors. Additionally the functions may call snmp_error on unexpected errors.
.Sh SEE ALSO .Sh SEE ALSO
.Xr gensnmptree 1 , .Xr gensnmptree 1 ,
.Xr snmpd 1 , .Xr bsnmpd 1 ,
.Xr bsnmpclient 3 , .Xr bsnmpclient 3 ,
.Xr bsnmplib 3 , .Xr bsnmplib 3 ,
.Xr snmpmod 3 .Xr snmpmod 3

View File

@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $Begemot: bsnmp/lib/bsnmpclient.3,v 1.9 2005/05/23 11:10:12 brandt_h Exp $ .\" $Begemot: bsnmp/lib/bsnmpclient.3,v 1.12 2005/10/04 08:46:50 brandt_h Exp $
.\" .\"
.Dd May 23, 2005 .Dd October 4, 2005
.Dt BSNMPCLIENT 3 .Dt BSNMPCLIENT 3
.Os .Os
.Sh NAME .Sh NAME
@ -104,7 +104,8 @@ Begemot SNMP library
.Fn snmp_dialog "struct snmp_pdu *req" "struct snmp_pdu *resp" .Fn snmp_dialog "struct snmp_pdu *req" "struct snmp_pdu *resp"
.Sh DESCRIPTION .Sh DESCRIPTION
The SNMP library contains routines to easily build SNMP client applications The SNMP library contains routines to easily build SNMP client applications
that use SNMP versions 1 or 2. Most of the routines use a that use SNMP versions 1 or 2.
Most of the routines use a
.Vt struct snmp_client : .Vt struct snmp_client :
.Bd -literal -offset indent .Bd -literal -offset indent
struct snmp_client { struct snmp_client {
@ -145,9 +146,11 @@ struct snmp_client {
The fields of this structure are described below. The fields of this structure are described below.
.Bl -tag -width "timeout_start" .Bl -tag -width "timeout_start"
.It Va version .It Va version
This is the version of SNMP to use. See This is the version of SNMP to use.
See
.Xr bsnmplib 3 .Xr bsnmplib 3
for applicable values. The default version is for applicable values.
The default version is
.Li SNMP_V2c . .Li SNMP_V2c .
.It Va trans .It Va trans
If this is If this is
@ -163,12 +166,14 @@ It uses the
.Va chost .Va chost
field as the path to the server's socket for local sockets. field as the path to the server's socket for local sockets.
.It Va cport .It Va cport
The SNMP agent's UDP port number. This may be a symbolic port number (from The SNMP agent's UDP port number.
.Pa /etc/services This may be a symbolic port number (from
or a numeric port number. If this field is .Pa /etc/services )
or a numeric port number.
If this field is
.Li NULL .Li NULL
(the default) the standard SNMP port is used. This field should not be changed (the default) the standard SNMP port is used.
directly but rather by calling This field should not be changed directly but rather by calling
.Fn snmp_client_set_port . .Fn snmp_client_set_port .
.It Va chost .It Va chost
The SNMP agent's host name, IP address or The SNMP agent's host name, IP address or
@ -178,46 +183,52 @@ If this is
.Li NULL .Li NULL
(the default) (the default)
.Li localhost .Li localhost
is assumed. This field should not be changed directly but rather through is assumed.
calling This field should not be changed directly but rather through calling
.Fn snmp_client_set_host . .Fn snmp_client_set_host .
.It Va read_community .It Va read_community
This is the community name to be used for all requests except SET requests. This is the community name to be used for all requests except SET requests.
The default is The default is
.Sq public . .Sq public .
.It Va write_community .It Va write_community
The community name to be used for SET requests. The default is The community name to be used for SET requests.
The default is
.Sq private . .Sq private .
.It Va timeout .It Va timeout
The maximum time to wait for responses to requests. If the time elapses, the The maximum time to wait for responses to requests.
request is resent up to If the time elapses, the request is resent up to
.Va retries .Va retries
times. The default is 3 seconds. times.
The default is 3 seconds.
.It Va retries .It Va retries
Number of times a request PDU is to be resent. If set to 0, the request is Number of times a request PDU is to be resent.
sent only once. The default is 3 retransmissions. If set to 0, the request is sent only once.
The default is 3 retransmissions.
.It Va dump_pdus .It Va dump_pdus
If set to a non-zero value all received and sent PDUs are dumped via If set to a non-zero value all received and sent PDUs are dumped via
.Xr snmp_pdu_dump 3 . .Xr snmp_pdu_dump 3 .
The default is not to dump PDUs. The default is not to dump PDUs.
.It Va txbuflen .It Va txbuflen
The encoding buffer size to be allocated for transmitted PDUs. The default is The encoding buffer size to be allocated for transmitted PDUs.
10000 octets. The default is 10000 octets.
.It Va rxbuflen .It Va rxbuflen
The decoding buffer size to be allocated for received PDUs. This is the size The decoding buffer size to be allocated for received PDUs.
of the maximum PDU that can be received. The default is 10000 octets. This is the size of the maximum PDU that can be received.
The default is 10000 octets.
.It Va fd .It Va fd
After calling After calling
.Fn snmp_open .Fn snmp_open
this is the file socket file descriptor used for sending and receiving PDUs. this is the file socket file descriptor used for sending and receiving PDUs.
.It Va next_reqid .It Va next_reqid
The request id of the next PDU to send. Used internal by the library. The request id of the next PDU to send.
Used internal by the library.
.It Va max_reqid .It Va max_reqid
The maximum request id to use for outging PDUs. The default is The maximum request id to use for outgoing PDUs.
The default is
.Li INT32_MAX . .Li INT32_MAX .
.It Va min_reqid .It Va min_reqid
The minimum request id to use for outgoing PDUs. Request ids are allocated The minimum request id to use for outgoing PDUs.
linerily starting at Request ids are allocated linearily starting at
.Va min_reqid .Va min_reqid
up to up to
.Va max_reqid . .Va max_reqid .
@ -225,29 +236,30 @@ up to
If an error happens, this field is set to a printable string describing the If an error happens, this field is set to a printable string describing the
error. error.
.It Va timeout_start .It Va timeout_start
This field must point to a function setting up a one shot timeout. After the This field must point to a function setting up a one shot timeout.
timeout has elapsed, the given callback function must be called with the After the timeout has elapsed, the given callback function must be called
user argument. The with the user argument.
The
.Fn timeout_start .Fn timeout_start
function must return a function must return a
.Vt void * .Vt void *
identifying the timeout. identifying the timeout.
.It Va timeout_stop .It Va timeout_stop
This field must be set to a function that stops a running timeout. The function This field must be set to a function that stops a running timeout.
will be called with the return value of the corresponding The function will be called with the return value of the corresponding
.Fn timeout_start .Fn timeout_start
function. function.
.It Va local_path .It Va local_path
If in local socket mode, the name of the clients socket. Not needed by the If in local socket mode, the name of the clients socket.
application. Not needed by the application.
.El .El
.Pp .Pp
In the current implementation there is a global variable In the current implementation there is a global variable
.Pp .Pp
.D1 Vt extern struct snmp_client snmp_client ; .D1 Vt extern struct snmp_client snmp_client ;
.Pp .Pp
that is used by all the library functions. The first call into the library must that is used by all the library functions.
be a call to The first call into the library must be a call to
.Fn snmp_client_init .Fn snmp_client_init
to initialize this global variable to the default values. to initialize this global variable to the default values.
After this call and before calling After this call and before calling
@ -271,23 +283,26 @@ If any of the arguments of the call is not
.Li NULL .Li NULL
the corresponding field in the global the corresponding field in the global
.Va snmp_client .Va snmp_client
is set from the argument. Otherwise the values that are already in that variable is set from the argument.
are used. Otherwise the values that are already in that variable are used.
The function The function
.Fn snmp_close .Fn snmp_close
closes the socket, stops all timeouts and frees all dynamically allocated closes the socket, stops all timeouts and frees all dynamically allocated
resources. resources.
.Pp .Pp
The next three functions are used to create request PDUs. The function The next three functions are used to create request PDUs.
The function
.Fn snmp_pdu_create .Fn snmp_pdu_create
initializes a PDU of type initializes a PDU of type
.Va op . .Va op .
It does not allocate space for the PDU itself. This is the responsibility of It does not allocate space for the PDU itself.
the caller. This is the responsibility of the caller.
.Fn snmp_add_binding .Fn snmp_add_binding
adds bindings to the PDU and returns the (zero based) index of the first new adds bindings to the PDU and returns the (zero based) index of the first new
binding. The arguments are pairs of pointer to the OIDs and syntax constants, binding.
terminated by a NULL. The call The arguments are pairs of pointer to the OIDs and syntax constants,
terminated by a NULL.
The call
.Bd -literal -offset indent .Bd -literal -offset indent
snmp_add_binding(&pdu, snmp_add_binding(&pdu,
&oid1, SNMP_SYNTAX_INTEGER, &oid1, SNMP_SYNTAX_INTEGER,
@ -297,15 +312,16 @@ snmp_add_binding(&pdu,
.Pp .Pp
adds two new bindings to the PDU and returns the index of the first one. adds two new bindings to the PDU and returns the index of the first one.
It is the responsibility of the caller to set the value part of the binding It is the responsibility of the caller to set the value part of the binding
if neccesary. The functions returns -1 if the maximum number of bindings if necessary.
is exhausted. The functions returns -1 if the maximum number of bindings is exhausted.
The function The function
.Fn snmp_oid_append .Fn snmp_oid_append
can be used to construct variable OIDs for requests. It takes a pointer can be used to construct variable OIDs for requests.
to an It takes a pointer to an
.Vt struct asn_oid .Vt struct asn_oid
that is to be constructed, a format string, and a number of arguments that is to be constructed, a format string, and a number of arguments
the type of which depends on the format string. The format string is interpreted the type of which depends on the format string.
The format string is interpreted
character by character in the following way: character by character in the following way:
.Bl -tag -width ".It Li ( Va N Ns Li )" .Bl -tag -width ".It Li ( Va N Ns Li )"
.It Li i .It Li i
@ -332,7 +348,8 @@ This format expects an argument of type
.Vt const char * .Vt const char *
and appends and appends
.Va size .Va size
characters from the string to the OID. The string may contain characters from the string to the OID.
The string may contain
.Li NUL .Li NUL
characters. characters.
.It Li c .It Li c
@ -346,7 +363,8 @@ pointed to by the second argument.
.Pp .Pp
The function The function
.Fn snmp_pdu_check .Fn snmp_pdu_check
may be used to check a response PDU. A number of checks are performed may be used to check a response PDU.
A number of checks are performed
(error code, equal number of bindings, syntaxes and values for SET PDUs). (error code, equal number of bindings, syntaxes and values for SET PDUs).
The function returns +1 if everything is ok, 0 if a NOSUCHNAME or similar The function returns +1 if everything is ok, 0 if a NOSUCHNAME or similar
error was detected, -1 if the response PDU had fatal errors error was detected, -1 if the response PDU had fatal errors
@ -354,38 +372,43 @@ and -2 if
.Fa resp .Fa resp
is is
.Li NULL .Li NULL
(a timeout occured). (a timeout occurred).
.Pp .Pp
The function The function
.Fn snmp_pdu_send .Fn snmp_pdu_send
encodes and sends the given PDU. It records the PDU together with the callback encodes and sends the given PDU.
It records the PDU together with the callback
and user pointers in an internal list and arranges for retransmission if no and user pointers in an internal list and arranges for retransmission if no
response is received. When a response is received or the retransmission count response is received.
When a response is received or the retransmission count
is exceeded the callback is exceeded the callback
.Fa func .Fa func
is called with the orignal request PDU, the response PDU and the user argument is called with the orignal request PDU, the response PDU and the user argument
.Fa uarg . .Fa uarg .
If the retransmit count is exceeded, If the retransmit count is exceeded,
.Fa func .Fa func
is called with the original request PDU, the reponse pointer set to is called with the original request PDU, the response pointer set to
.Li NULL .Li NULL
and the user argument and the user argument
.Fa uarg . .Fa uarg .
The caller should not free the request PDU until the callback function is The caller should not free the request PDU until the callback function is
called. The callback function must free the request PDU and the response called.
PDU (if not The callback function must free the request PDU and the response PDU (if not
.Li NULL ). .Li NULL ).
.Pp .Pp
The function The function
.Fn snmp_receive .Fn snmp_receive
tries to receive a PDU. If the argument is zero, the function polls to see tries to receive a PDU.
If the argument is zero, the function polls to see
whether a packet is available, if the argument is non-zero, the function blocks whether a packet is available, if the argument is non-zero, the function blocks
until the next packet is received. The packet is delivered via the usual callback until the next packet is received.
The packet is delivered via the usual callback
mechanism (non-response packets are silently dropped). mechanism (non-response packets are silently dropped).
The function returns 0, if a packet was received and successfully dispatched, The function returns 0, if a packet was received and successfully dispatched,
-1 if an error occured or no packet was available (in polling mode). -1 if an error occurred or no packet was available (in polling mode).
.Pp .Pp
The next two functions are used to retrieve tables from SNMP agents. The use The next two functions are used to retrieve tables from SNMP agents.
They use
the following input structure, that describes the table: the following input structure, that describes the table:
.Bd -literal -offset indent .Bd -literal -offset indent
struct snmp_table { struct snmp_table {
@ -394,7 +417,7 @@ struct snmp_table {
u_int max_iter; u_int max_iter;
size_t entry_size; size_t entry_size;
u_int index_size; u_int index_size;
u_int64_t req_mask; uint64_t req_mask;
struct snmp_table_entry { struct snmp_table_entry {
asn_subid_t subid; asn_subid_t subid;
@ -410,15 +433,17 @@ The fields of this structure have the following meaning:
This is the base OID of the table. This is the base OID of the table.
.It Va last_change .It Va last_change
Some tables have a scalar variable of type TIMETICKS attached to them, Some tables have a scalar variable of type TIMETICKS attached to them,
that holds the time when the table was last changed. This OID should be that holds the time when the table was last changed.
the OID of this variable (without the \&.0 index). When the table is retrieved This OID should be the OID of this variable (without the \&.0 index).
When the table is retrieved
with multiple GET requests, and the variable changes between two request, with multiple GET requests, and the variable changes between two request,
the table fetch is restarted. the table fetch is restarted.
.It Va max_iter .It Va max_iter
Maximum number of tries to fetch the table. Maximum number of tries to fetch the table.
.It Va entry_size .It Va entry_size
The table fetching routines return a list of structure one for each table The table fetching routines return a list of structures one for each table
row. This variable is the size of one structure and used to row.
This variable is the size of one structure and used to
.Xr malloc 3 .Xr malloc 3
the structure. the structure.
.It Va index_size .It Va index_size
@ -427,19 +452,22 @@ This is the number of index columns in the table.
This is a bit mask with a 1 for each table column that is required. This is a bit mask with a 1 for each table column that is required.
Bit 0 corresponds to the first element (index 0) in the array Bit 0 corresponds to the first element (index 0) in the array
.Va entries , .Va entries ,
bit 1 to the second (index 1) and so on. SNMP tables may be sparse. For sparse bit 1 to the second (index 1) and so on.
columns the bit should not be set. If the bit for a given column is set and SNMP tables may be sparse.
For sparse columns the bit should not be set.
If the bit for a given column is set and
the column value cannot be retrieved for a given row, the table fetch is the column value cannot be retrieved for a given row, the table fetch is
restarted assuming that the table is currently beeing modified by the agent. restarted assuming that the table is currently being modified by the agent.
The bits for the index columns are ignored. The bits for the index columns are ignored.
.It Va entries .It Va entries
This is a variable sized array of column descriptors. This array is terminated This is a variable sized array of column descriptors.
by an element with syntax This array is terminated by an element with syntax
.Li SNMP_SYNTAX_NULL . .Li SNMP_SYNTAX_NULL .
The first The first
.Va index_size .Va index_size
elements describe all the index columns of the table, the rest are normal elements describe all the index columns of the table, the rest are normal
columns. If for a the column at columns.
If for the column at
.Ql entries[N] .Ql entries[N]
the expression the expression
.Ql req_mask & (1 << N) .Ql req_mask & (1 << N)
@ -447,12 +475,14 @@ yields true, the column is considered a required column.
The fields of this the array elements have the following meaning: The fields of this the array elements have the following meaning:
.Bl -tag -width "syntax" .Bl -tag -width "syntax"
.It Va subid .It Va subid
This is the OID subid of the column. This is ignored for index entries. Index This is the OID subid of the column.
entries are decoded according to the This is ignored for index entries.
Index entries are decoded according to the
.Va syntax .Va syntax
field. field.
.It Va syntax .It Va syntax
This is the syntax of the column or index. A syntax of This is the syntax of the column or index.
A syntax of
.Li SNMP_SYNTAX_NULL .Li SNMP_SYNTAX_NULL
terminates the array. terminates the array.
.It Va offset .It Va offset
@ -465,10 +495,11 @@ macro.
.Pp .Pp
Both table fetching functions return TAILQ (see Both table fetching functions return TAILQ (see
.Xr queue 3 ) .Xr queue 3 )
of structures--one for each table row. These structures must start with a of structures--one for each table row.
These structures must start with a
.Fn TAILQ_ENTRY .Fn TAILQ_ENTRY
and a and a
.Vt u_int64_t .Vt uint64_t
and are allocated via and are allocated via
.Xr malloc 3 . .Xr malloc 3 .
The The
@ -476,29 +507,33 @@ The
argument of the table functions must point to a argument of the table functions must point to a
.Fn TAILQ_HEAD . .Fn TAILQ_HEAD .
The The
.Vt u_int64_t .Vt uint64_t
fields, usually called fields, usually called
.Va found .Va found
is used to indicate which of the columns have been found for the given is used to indicate which of the columns have been found for the given
row. It is encoded like the row.
It is encoded like the
.Fa req_mask .Fa req_mask
field. field.
.Pp .Pp
The function The function
.Fn snmp_table_fetch .Fn snmp_table_fetch
synchronuosly fetches the given table. If everything is ok 0 is returned. synchronously fetches the given table.
If everything is ok 0 is returned.
Otherwise the function returns -1 and sets an appropriate error string. Otherwise the function returns -1 and sets an appropriate error string.
The function The function
.Fn snmp_table_fetch_async .Fn snmp_table_fetch_async
fetches the tables asynchronuosly. If either the entire table is fetch, or fetches the tables asynchronously.
an error occures the callback function If either the entire table is fetch, or
an error occurs the callback function
.Fa callback .Fa callback
is called with the callers arguments is called with the callers arguments
.Fa list .Fa list
and and
.Fa uarg .Fa uarg
and a parameter that is either 0 if the table was fetched, or and a parameter that is either 0 if the table was fetched, or
-1 if there was an error. The function itself returns -1 if it could not -1 if there was an error.
The function itself returns -1 if it could not
initialize fetching of the table. initialize fetching of the table.
.Pp .Pp
The following table description is used to fetch the ATM interface table: The following table description is used to fetch the ATM interface table:
@ -508,17 +543,17 @@ The following table description is used to fetch the ATM interface table:
*/ */
struct atmif { struct atmif {
TAILQ_ENTRY(atmif) link; TAILQ_ENTRY(atmif) link;
u_int64_t found; uint64_t found;
int32_t index; int32_t index;
u_char *ifname; u_char *ifname;
size_t ifnamelen; size_t ifnamelen;
u_int32_t node_id; uint32_t node_id;
u_int32_t pcr; uint32_t pcr;
int32_t media; int32_t media;
u_int32_t vpi_bits; uint32_t vpi_bits;
u_int32_t vci_bits; uint32_t vci_bits;
u_int32_t max_vpcs; uint32_t max_vpcs;
u_int32_t max_vccs; uint32_t max_vccs;
u_char *esi; u_char *esi;
size_t esilen; size_t esilen;
int32_t carrier; int32_t carrier;
@ -568,15 +603,18 @@ static const struct snmp_table atmif_table = {
.Pp .Pp
The function The function
.Fn snmp_dialog .Fn snmp_dialog
is used to execute a synchonuous dialog with the agent. The request PDU is used to execute a synchonuous dialog with the agent.
The request PDU
.Fa req .Fa req
is sent and the function blocks until the response PDU is received. Note, is sent and the function blocks until the response PDU is received.
Note,
that asynchonuous receives are handled (i.e. callback functions of other send that asynchonuous receives are handled (i.e. callback functions of other send
calls or table fetches may be called while in the function). The response calls or table fetches may be called while in the function).
PDU is returned in The response PDU is returned in
.Fa resp . .Fa resp .
If no reponse could be received after all timeouts and retries, the function If no response could be received after all timeouts and retries, the function
returns -1. If a response was received 0 is returned. returns -1.
If a response was received 0 is returned.
.Pp .Pp
The function The function
.Fn snmp_parse_server .Fn snmp_parse_server
@ -600,15 +638,16 @@ is the port in case of UDP transport.
The function returns 0 in the case of success and return -1 and sets The function returns 0 in the case of success and return -1 and sets
the error string in case of an error. the error string in case of an error.
.Sh DIAGNOSTICS .Sh DIAGNOSTICS
If an error occures in any of the function an error indication as described If an error occurs in any of the function an error indication as described
above is returned. Additionally the function sets a printable error string above is returned.
Additionally the function sets a printable error string
in the in the
.Va error .Va error
filed of filed of
.Va snmp_client . .Va snmp_client .
.Sh SEE ALSO .Sh SEE ALSO
.Xr gensnmptree 1 , .Xr gensnmptree 1 ,
.Xr snmpd 1 , .Xr bsnmpd 1 ,
.Xr bsnmpagent 3 , .Xr bsnmpagent 3 ,
.Xr bsnmplib 3 .Xr bsnmplib 3
.Sh STANDARDS .Sh STANDARDS

View File

@ -1,4 +1,7 @@
.\" .\"
.\" Copyright (c) 2004-2005
.\" Hartmut Brandt.
.\" All rights reserved.
.\" Copyright (c) 2001-2003 .\" Copyright (c) 2001-2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). .\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved. .\" All rights reserved.
@ -26,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $Begemot: bsnmp/lib/bsnmplib.3,v 1.6 2005/02/25 11:55:59 brandt_h Exp $ .\" $Begemot: bsnmp/lib/bsnmplib.3,v 1.9 2005/10/04 08:46:51 brandt_h Exp $
.\" .\"
.Dd August 15, 2002 .Dd October 4, 2005
.Dt BSNMPLIB 3 .Dt BSNMPLIB 3
.Os .Os
.Sh NAME .Sh NAME
@ -84,15 +87,15 @@ struct snmp_value {
} octetstring; } octetstring;
struct asn_oid oid; struct asn_oid oid;
u_char ipaddress[4]; u_char ipaddress[4];
u_int32_t uint32; /* also gauge32, counter32, uint32_t uint32; /* also gauge32, counter32,
unsigned32, timeticks */ unsigned32, timeticks */
u_int64_t counter64; uint64_t counter64;
} v; } v;
}; };
.Ed .Ed
.Pp .Pp
This structure represents one variable binding from an SNMP PDU. The This structure represents one variable binding from an SNMP PDU.
field The field
.Fa var .Fa var
is the ASN.1 of the variable that is bound. is the ASN.1 of the variable that is bound.
.Fa syntax .Fa syntax
@ -178,8 +181,8 @@ is the type of the PDU.
.Pp .Pp
The function The function
.Fn snmp_value_free .Fn snmp_value_free
is used to free all the dynamic allocated contents of an SNMP value. It does is used to free all the dynamic allocated contents of an SNMP value.
not free the structure pointed to by It does not free the structure pointed to by
.Fa value .Fa value
itself. itself.
.Pp .Pp
@ -187,7 +190,7 @@ The function
.Fn snmp_value_parse .Fn snmp_value_parse
parses the ASCII representation of an SNMP value into its binary form. parses the ASCII representation of an SNMP value into its binary form.
This function is mainly used by the configuration file reader of This function is mainly used by the configuration file reader of
.Xr snmpd 1 . .Xr bsnmpd 1 .
.Pp .Pp
The function The function
.Fn snmp_value_copy .Fn snmp_value_copy
@ -197,14 +200,14 @@ to the structure pointed to by
.Fa to . .Fa to .
It assumes that It assumes that
.Fa to .Fa to
is uninitialized and will overwrite its previous contents. It does not itself is uninitialized and will overwrite its previous contents.
allocate the structure pointed to by It does not itself allocate the structure pointed to by
.Fa to . .Fa to .
.Pp .Pp
The function The function
.Fn snmp_pdu_free .Fn snmp_pdu_free
frees all the dynamically allocated components of the PDU. It does not itself frees all the dynamically allocated components of the PDU.
free the structure pointed to by It does not itself free the structure pointed to by
.Fa pdu . .Fa pdu .
.Pp .Pp
The function The function
@ -239,7 +242,7 @@ The function
.Fn TRUTH_OK .Fn TRUTH_OK
checks, whether its argument is a legal SNMP truth value. checks, whether its argument is a legal SNMP truth value.
.Sh DIAGNOSTICS .Sh DIAGNOSTICS
When an error occures in any of the function the function pointed to When an error occurs in any of the function the function pointed to
by the global pointer by the global pointer
.Bd -literal -offset indent .Bd -literal -offset indent
extern void (*snmp_error)(const char *, ...); extern void (*snmp_error)(const char *, ...);
@ -291,7 +294,7 @@ Encoding failed.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr gensnmptree 1 , .Xr gensnmptree 1 ,
.Xr snmpd 1 , .Xr bsnmpd 1 ,
.Xr bsnmpagent 3 , .Xr bsnmpagent 3 ,
.Xr bsnmpclient 3 , .Xr bsnmpclient 3 ,
.Xr bsnmplib 3 .Xr bsnmplib 3

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/lib/snmp.c,v 1.38 2004/08/06 08:46:53 brandt Exp $ * $Begemot: bsnmp/lib/snmp.c,v 1.40 2005/10/04 14:32:42 brandt_h Exp $
* *
* SNMP * SNMP
*/ */
@ -36,7 +36,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#elif defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#endif
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <netdb.h> #include <netdb.h>

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/lib/snmpagent.c,v 1.19 2004/08/19 17:09:09 brandt Exp $ * $Begemot: bsnmp/lib/snmpagent.c,v 1.20 2005/10/04 11:21:33 brandt_h Exp $
* *
* SNMP Agent functions * SNMP Agent functions
*/ */
@ -36,7 +36,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#elif defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#endif
#include <string.h> #include <string.h>
#include "asn1.h" #include "asn1.h"

View File

@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/lib/snmpclient.c,v 1.31 2005/05/23 11:10:13 brandt_h Exp $ * $Begemot: bsnmp/lib/snmpclient.c,v 1.34 2005/10/04 14:32:42 brandt_h Exp $
* *
* Support functions for SNMP clients. * Support functions for SNMP clients.
*/ */
@ -48,7 +48,11 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <netdb.h> #include <netdb.h>
#ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#elif defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#endif
#include <limits.h> #include <limits.h>
#ifdef HAVE_ERR_H #ifdef HAVE_ERR_H
#include <err.h> #include <err.h>
@ -549,7 +553,7 @@ table_check_cons(struct tabwork *work)
/* /*
* Fetch a table. Returns 0 if ok, -1 on errors. * Fetch a table. Returns 0 if ok, -1 on errors.
* This is the synchronuous variant. * This is the synchronous variant.
*/ */
int int
snmp_table_fetch(const struct snmp_table *descr, void *list) snmp_table_fetch(const struct snmp_table *descr, void *list)
@ -1561,7 +1565,7 @@ ok_get(const struct snmp_pdu * req, const struct snmp_pdu * resp)
} }
/* /*
* Check the reponse to a SET PDU. We check: - the error status must be 0 - * Check the response to a SET PDU. We check: - the error status must be 0 -
* the number of bindings must be equal in response and request - the * the number of bindings must be equal in response and request - the
* syntaxes must be the same in response and request - the OIDs must be the * syntaxes must be the same in response and request - the OIDs must be the
* same in response and request * same in response and request

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/snmp_mibII/mibII.c,v 1.22 2005/05/23 09:03:37 brandt_h Exp $ * $Begemot: bsnmp/snmp_mibII/mibII.c,v 1.23 2005/06/09 12:36:52 brandt_h Exp $
* *
* Implementation of the standard interfaces and ip MIB. * Implementation of the standard interfaces and ip MIB.
*/ */
@ -941,6 +941,10 @@ handle_rtmsg(struct rt_msghdr *rtm)
process_arp(rtm, process_arp(rtm,
(struct sockaddr_dl *)(void *)addrs[RTAX_GATEWAY], (struct sockaddr_dl *)(void *)addrs[RTAX_GATEWAY],
(struct sockaddr_in *)(void *)addrs[RTAX_DST]); (struct sockaddr_in *)(void *)addrs[RTAX_DST]);
} else {
if (rtm->rtm_errno == 0 && (rtm->rtm_flags & RTF_UP))
mib_sroute_process(rtm, addrs[RTAX_GATEWAY],
addrs[RTAX_DST], addrs[RTAX_NETMASK]);
} }
break; break;
@ -955,11 +959,70 @@ handle_rtmsg(struct rt_msghdr *rtm)
process_arp(rtm, process_arp(rtm,
(struct sockaddr_dl *)(void *)addrs[RTAX_GATEWAY], (struct sockaddr_dl *)(void *)addrs[RTAX_GATEWAY],
(struct sockaddr_in *)(void *)addrs[RTAX_DST]); (struct sockaddr_in *)(void *)addrs[RTAX_DST]);
} else {
if (rtm->rtm_errno == 0 && (rtm->rtm_flags & RTF_UP))
mib_sroute_process(rtm, addrs[RTAX_GATEWAY],
addrs[RTAX_DST], addrs[RTAX_NETMASK]);
} }
break; break;
case RTM_DELETE:
mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs);
if (rtm->rtm_errno == 0 && !(rtm->rtm_flags & RTF_LLINFO))
mib_sroute_process(rtm, addrs[RTAX_GATEWAY],
addrs[RTAX_DST], addrs[RTAX_NETMASK]);
break;
} }
} }
/*
* send a routing message
*/
void
mib_send_rtmsg(struct rt_msghdr *rtm, struct sockaddr *gw,
struct sockaddr *dst, struct sockaddr *mask)
{
size_t len;
struct rt_msghdr *msg;
char *cp;
ssize_t sent;
len = sizeof(*rtm) + SA_SIZE(gw) + SA_SIZE(dst) + SA_SIZE(mask);
if ((msg = malloc(len)) == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
return;
}
cp = (char *)(msg + 1);
memset(msg, 0, sizeof(*msg));
msg->rtm_flags = 0;
msg->rtm_version = RTM_VERSION;
msg->rtm_addrs = RTA_DST | RTA_GATEWAY;
memcpy(cp, dst, SA_SIZE(dst));
cp += SA_SIZE(dst);
memcpy(cp, gw, SA_SIZE(gw));
cp += SA_SIZE(gw);
if (mask != NULL) {
memcpy(cp, mask, SA_SIZE(mask));
cp += SA_SIZE(mask);
msg->rtm_addrs |= RTA_NETMASK;
}
msg->rtm_msglen = cp - (char *)msg;
msg->rtm_type = RTM_GET;
if ((sent = write(route, msg, msg->rtm_msglen)) == -1) {
syslog(LOG_ERR, "%s: write: %m", __func__);
free(msg);
return;
}
if (sent != msg->rtm_msglen) {
syslog(LOG_ERR, "%s: short write", __func__);
free(msg);
return;
}
free(msg);
}
/* /*
* Fetch the routing table via sysctl * Fetch the routing table via sysctl
*/ */
@ -1428,6 +1491,7 @@ mibII_start(void)
mib_refresh_iflist(); mib_refresh_iflist();
update_ifa_info(); update_ifa_info();
mib_arp_update(); mib_arp_update();
(void)mib_fetch_route();
mib_iftable_last_change = 0; mib_iftable_last_change = 0;
mib_ifstack_last_change = 0; mib_ifstack_last_change = 0;
@ -1474,7 +1538,6 @@ mibII_init(struct lmodule *mod, int argc __unused, char *argv[] __unused)
syslog(LOG_ERR, "PF_ROUTE: %m"); syslog(LOG_ERR, "PF_ROUTE: %m");
return (-1); return (-1);
} }
(void)shutdown(route, SHUT_WR);
if ((mib_netsock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { if ((mib_netsock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
syslog(LOG_ERR, "PF_INET: %m"); syslog(LOG_ERR, "PF_INET: %m");

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.14 2005/05/23 09:03:38 brandt_h Exp $ * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.15 2005/06/09 12:36:53 brandt_h Exp $
* *
* Implementation of the interfaces and IP groups of MIB-II. * Implementation of the interfaces and IP groups of MIB-II.
*/ */
@ -230,5 +230,16 @@ void mib_arp_update(void);
/* fetch routing table */ /* fetch routing table */
u_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp); u_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp);
/* process routing message */
void mib_sroute_process(struct rt_msghdr *, struct sockaddr *,
struct sockaddr *, struct sockaddr *);
/* send a routing message */
void mib_send_rtmsg(struct rt_msghdr *, struct sockaddr *,
struct sockaddr *, struct sockaddr *);
/* extract addresses from routing message */ /* extract addresses from routing message */
void mib_extract_addrs(int, u_char *, struct sockaddr **); void mib_extract_addrs(int, u_char *, struct sockaddr **);
/* fetch routing table */
int mib_fetch_route(void);

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/snmp_mibII/mibII_ipaddr.c,v 1.9 2004/08/06 08:47:02 brandt Exp $ * $Begemot: bsnmp/snmp_mibII/mibII_ipaddr.c,v 1.10 2005/10/04 11:21:35 brandt_h Exp $
* *
* IP address table. This table is writeable! * IP address table. This table is writeable!
* *
@ -84,10 +84,13 @@ create(struct update *upd)
} }
bcast.s_addr = upd->addr.s_addr & upd->mask.s_addr; bcast.s_addr = upd->addr.s_addr & upd->mask.s_addr;
if (!(upd->set & UPD_BCAST) || upd->bcast) if (!(upd->set & UPD_BCAST) || upd->bcast) {
bcast.s_addr |= htonl(0xffffffff & ~ntohl(upd->mask.s_addr)); uint32_t tmp = ~ntohl(upd->mask.s_addr);
bcast.s_addr |= htonl(0xffffffff & ~tmp);
}
if ((ifa = mib_create_ifa(upd->ifindex, upd->addr, upd->mask, bcast)) == NULL) if ((ifa = mib_create_ifa(upd->ifindex, upd->addr, upd->mask, bcast))
== NULL)
return (SNMP_ERR_GENERR); return (SNMP_ERR_GENERR);
upd->rb |= RB_CREATE; upd->rb |= RB_CREATE;

View File

@ -26,41 +26,218 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Begemot: bsnmp/snmp_mibII/mibII_route.c,v 1.6 2005/05/23 09:03:41 brandt_h Exp $ * $Begemot: bsnmp/snmp_mibII/mibII_route.c,v 1.7 2005/06/09 12:36:53 brandt_h Exp $
* *
* Routing table * Routing table
*/ */
#include <sys/tree.h>
#include "mibII.h" #include "mibII.h"
#include "mibII_oid.h" #include "mibII_oid.h"
struct sroute { struct sroute {
TAILQ_ENTRY(sroute) link; RB_ENTRY(sroute) link;
struct asn_oid index; uint32_t ifindex;
u_int ifindex; uint8_t index[13];
u_int type; uint8_t type;
u_int proto; uint8_t proto;
}; };
static TAILQ_HEAD(, sroute) sroute_list = TAILQ_HEAD_INITIALIZER(sroute_list); RB_HEAD(sroutes, sroute) sroutes = RB_INITIALIZER(&sroutes);
RB_PROTOTYPE(sroutes, sroute, link, sroute_compare);
#define ROUTE_UPDATE_INTERVAL (100 * 60 * 10) /* 10 min */
static uint64_t route_tick; static uint64_t route_tick;
static u_int route_total; static u_int route_total;
/*
* Compare two routes
*/
static int static int
fetch_route(void) sroute_compare(struct sroute *s1, struct sroute *s2)
{
return (memcmp(s1->index, s2->index, 13));
}
static void
sroute_index_append(struct asn_oid *oid, u_int sub, const struct sroute *s)
{
int i;
oid->len = sub + 13;
for (i = 0; i < 13; i++)
oid->subs[sub + i] = s->index[i];
}
#if 0
static void
sroute_print(const struct sroute *r)
{
u_int i;
for (i = 0; i < 13 - 1; i++)
printf("%u.", r->index[i]);
printf("%u proto=%u type=%u", r->index[i], r->proto, r->type);
}
#endif
/*
* process routing message
*/
void
mib_sroute_process(struct rt_msghdr *rtm, struct sockaddr *gw,
struct sockaddr *dst, struct sockaddr *mask)
{
struct sockaddr_in *in_dst, *in_gw;
struct in_addr in_mask;
struct mibif *ifp;
struct sroute key;
struct sroute *r, *r1;
in_addr_t ha;
if (dst == NULL || gw == NULL || dst->sa_family != AF_INET ||
gw->sa_family != AF_INET)
return;
in_dst = (struct sockaddr_in *)(void *)dst;
in_gw = (struct sockaddr_in *)(void *)gw;
if (rtm->rtm_flags & RTF_HOST)
in_mask.s_addr = 0xffffffff;
else if (mask == NULL || mask->sa_len == 0)
in_mask.s_addr = 0;
else
in_mask = ((struct sockaddr_in *)(void *)mask)->sin_addr;
/* build the index */
ha = ntohl(in_dst->sin_addr.s_addr);
key.index[0] = (ha >> 24) & 0xff;
key.index[1] = (ha >> 16) & 0xff;
key.index[2] = (ha >> 8) & 0xff;
key.index[3] = (ha >> 0) & 0xff;
ha = ntohl(in_mask.s_addr);
key.index[4] = (ha >> 24) & 0xff;
key.index[5] = (ha >> 16) & 0xff;
key.index[6] = (ha >> 8) & 0xff;
key.index[7] = (ha >> 0) & 0xff;
/* ToS */
key.index[8] = 0;
ha = ntohl(in_gw->sin_addr.s_addr);
key.index[9] = (ha >> 24) & 0xff;
key.index[10] = (ha >> 16) & 0xff;
key.index[11] = (ha >> 8) & 0xff;
key.index[12] = (ha >> 0) & 0xff;
if (rtm->rtm_type == RTM_DELETE) {
r = RB_FIND(sroutes, &sroutes, &key);
if (r == 0) {
#ifdef DEBUG_ROUTE
syslog(LOG_WARNING, "%s: DELETE: %u.%u.%u.%u "
"%u.%u.%u.%u %u %u.%u.%u.%u not found", __func__,
key.index[0], key.index[1], key.index[2],
key.index[3], key.index[4], key.index[5],
key.index[6], key.index[7], key.index[8],
key.index[9], key.index[10], key.index[11],
key.index[12]);
#endif
return;
}
RB_REMOVE(sroutes, &sroutes, r);
free(r);
route_total--;
#ifdef DEBUG_ROUTE
printf("%s: DELETE: %u.%u.%u.%u "
"%u.%u.%u.%u %u %u.%u.%u.%u\n", __func__,
key.index[0], key.index[1], key.index[2],
key.index[3], key.index[4], key.index[5],
key.index[6], key.index[7], key.index[8],
key.index[9], key.index[10], key.index[11],
key.index[12]);
#endif
return;
}
/* GET or ADD */
ifp = NULL;
if ((ifp = mib_find_if_sys(rtm->rtm_index)) == NULL) {
if (rtm->rtm_type == RTM_ADD) {
/* make it a get so the kernel fills the index */
mib_send_rtmsg(rtm, gw, dst, mask);
return;
}
mib_iflist_bad = 1;
}
if ((r = malloc(sizeof(*r))) == NULL) {
syslog(LOG_ERR, "%m");
return;
}
memcpy(r->index, key.index, sizeof(r->index));
r->ifindex = (ifp == NULL) ? 0 : ifp->index;
r->type = (rtm->rtm_flags & RTF_LLINFO) ? 3 :
(rtm->rtm_flags & RTF_REJECT) ? 2 : 4;
/* cannot really know, what protocol it runs */
r->proto = (rtm->rtm_flags & RTF_LOCAL) ? 2 :
(rtm->rtm_flags & RTF_STATIC) ? 3 :
(rtm->rtm_flags & RTF_DYNAMIC) ? 4 : 10;
r1 = RB_INSERT(sroutes, &sroutes, r);
if (r1 != NULL) {
#ifdef DEBUG_ROUTE
syslog(LOG_WARNING, "%s: %u.%u.%u.%u "
"%u.%u.%u.%u %u %u.%u.%u.%u duplicate route", __func__,
key.index[0], key.index[1], key.index[2],
key.index[3], key.index[4], key.index[5],
key.index[6], key.index[7], key.index[8],
key.index[9], key.index[10], key.index[11],
key.index[12]);
#endif
r1->ifindex = r->ifindex;
r1->type = r->type;
r1->proto = r->proto;
free(r);
return;
}
route_total++;
#ifdef DEBUG_ROUTE
printf("%s: ADD/GET: %u.%u.%u.%u "
"%u.%u.%u.%u %u %u.%u.%u.%u\n", __func__,
key.index[0], key.index[1], key.index[2],
key.index[3], key.index[4], key.index[5],
key.index[6], key.index[7], key.index[8],
key.index[9], key.index[10], key.index[11],
key.index[12]);
#endif
}
int
mib_fetch_route(void)
{ {
u_char *rtab, *next; u_char *rtab, *next;
size_t len; size_t len;
struct sroute *r; struct sroute *r, *r1;
struct rt_msghdr *rtm; struct rt_msghdr *rtm;
struct sockaddr *addrs[RTAX_MAX]; struct sockaddr *addrs[RTAX_MAX];
struct sockaddr_in *sa, *gw;
struct in_addr mask, nhop;
in_addr_t ha;
struct mibif *ifp;
while ((r = TAILQ_FIRST(&sroute_list)) != NULL) { if (route_tick != 0 && route_tick + ROUTE_UPDATE_INTERVAL > this_tick)
TAILQ_REMOVE(&sroute_list, r, link); return (0);
/*
* Remove all routes
*/
r = RB_MIN(sroutes, &sroutes);
while (r != NULL) {
r1 = RB_NEXT(sroutes, &sroutes, r);
RB_REMOVE(sroutes, &sroutes, r);
free(r); free(r);
r = r1;
} }
route_total = 0; route_total = 0;
@ -75,83 +252,120 @@ fetch_route(void)
continue; continue;
mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs); mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs);
if (addrs[RTAX_DST] == NULL || addrs[RTAX_GATEWAY] == NULL ||
addrs[RTAX_DST]->sa_family != AF_INET) mib_sroute_process(rtm, addrs[RTAX_GATEWAY], addrs[RTAX_DST],
continue; addrs[RTAX_NETMASK]);
sa = (struct sockaddr_in *)(void *)addrs[RTAX_DST];
if (rtm->rtm_flags & RTF_HOST) {
mask.s_addr = 0xffffffff;
} else {
if (addrs[RTAX_NETMASK] == NULL ||
addrs[RTAX_NETMASK]->sa_len == 0)
mask.s_addr = 0;
else
mask = ((struct sockaddr_in *)(void *)
addrs[RTAX_NETMASK])->sin_addr;
}
if (addrs[RTAX_GATEWAY] == NULL) {
nhop.s_addr = 0;
} else if (rtm->rtm_flags & RTF_LLINFO) {
nhop = sa->sin_addr;
} else {
gw = (struct sockaddr_in *)(void *)addrs[RTAX_GATEWAY];
if (gw->sin_family != AF_INET)
continue;
nhop = gw->sin_addr;
}
if ((ifp = mib_find_if_sys(rtm->rtm_index)) == NULL) {
mib_iflist_bad = 1;
continue;
}
if ((r = malloc(sizeof(*r))) == NULL) {
syslog(LOG_ERR, "%m");
continue;
}
route_total++;
r->index.len = 13;
ha = ntohl(sa->sin_addr.s_addr);
r->index.subs[0] = (ha >> 24) & 0xff;
r->index.subs[1] = (ha >> 16) & 0xff;
r->index.subs[2] = (ha >> 8) & 0xff;
r->index.subs[3] = (ha >> 0) & 0xff;
ha = ntohl(mask.s_addr);
r->index.subs[4] = (ha >> 24) & 0xff;
r->index.subs[5] = (ha >> 16) & 0xff;
r->index.subs[6] = (ha >> 8) & 0xff;
r->index.subs[7] = (ha >> 0) & 0xff;
r->index.subs[8] = 0;
ha = ntohl(nhop.s_addr);
r->index.subs[9] = (ha >> 24) & 0xff;
r->index.subs[10] = (ha >> 16) & 0xff;
r->index.subs[11] = (ha >> 8) & 0xff;
r->index.subs[12] = (ha >> 0) & 0xff;
r->ifindex = ifp->index;
r->type = (rtm->rtm_flags & RTF_LLINFO) ? 3 :
(rtm->rtm_flags & RTF_REJECT) ? 2 : 4;
/* cannot really know, what protocol it runs */
r->proto = (rtm->rtm_flags & RTF_LOCAL) ? 2 :
(rtm->rtm_flags & RTF_STATIC) ? 3 :
(rtm->rtm_flags & RTF_DYNAMIC) ? 4 : 10;
INSERT_OBJECT_OID(r, &sroute_list);
} }
#if 0
u_int n = 0;
r = RB_MIN(sroutes, &sroutes);
while (r != NULL) {
printf("%u: ", n++);
sroute_print(r);
printf("\n");
r = RB_NEXT(sroutes, &sroutes, r);
}
#endif
free(rtab); free(rtab);
route_tick = get_ticks(); route_tick = get_ticks();
return (0); return (0);
} }
/**
* Find a route in the table.
*/
static struct sroute *
sroute_get(const struct asn_oid *oid, u_int sub)
{
struct sroute key;
int i;
if (oid->len - sub != 13)
return (NULL);
for (i = 0; i < 13; i++)
key.index[i] = oid->subs[sub + i];
return (RB_FIND(sroutes, &sroutes, &key));
}
/**
* Find next route in the table. There is no such RB_ macro, so must
* dig into the innards of the RB stuff.
*/
static struct sroute *
sroute_getnext(struct asn_oid *oid, u_int sub)
{
u_int i;
int comp;
struct sroute key;
struct sroute *best;
struct sroute *s;
/*
* We now, that the OID is at least the tableEntry OID. If it is,
* the user wants the first route.
*/
if (oid->len == sub)
return (RB_MIN(sroutes, &sroutes));
/*
* This is also true for any index that consists of zeros and is
* shorter than the full index.
*/
if (oid->len < sub + 13) {
for (i = sub; i < oid->len; i++)
if (oid->subs[i] != 0)
break;
if (i == oid->len)
return (RB_MIN(sroutes, &sroutes));
/*
* Now if the index is too short, we fill it with zeros and then
* subtract one from the index. We can do this, because we now,
* that there is at least one index element that is not zero.
*/
for (i = oid->len; i < sub + 13; i++)
oid->subs[i] = 0;
for (i = sub + 13 - 1; i >= sub; i--) {
if (oid->subs[i] != 0) {
oid->subs[i]--;
break;
}
oid->subs[i] = ASN_MAXID;
}
oid->len = sub + 13;
}
/* build the index */
for (i = sub; i < sub + 13; i++)
key.index[i - sub] = oid->subs[i];
/* now find the element */
best = NULL;
s = RB_ROOT(&sroutes);
while (s != NULL) {
comp = sroute_compare(&key, s);
if (comp >= 0) {
/* The current element is smaller than what we search.
* Forget about it and move to the right subtree. */
s = RB_RIGHT(s, link);
continue;
}
/* the current element is larger than what we search.
* forget about the right subtree (its even larger), but
* the current element may be what we need. */
if (best == NULL || sroute_compare(s, best) < 0)
/* this one's better */
best = s;
s = RB_LEFT(s, link);
}
return (best);
}
/* /*
* Table * Table
*/ */
@ -159,28 +373,27 @@ int
op_route_table(struct snmp_context *ctx __unused, struct snmp_value *value, op_route_table(struct snmp_context *ctx __unused, struct snmp_value *value,
u_int sub, u_int iidx __unused, enum snmp_op op) u_int sub, u_int iidx __unused, enum snmp_op op)
{ {
static struct sroute *r; struct sroute *r;
if (route_tick < this_tick) if (mib_fetch_route() == -1)
if (fetch_route() == -1) return (SNMP_ERR_GENERR);
return (SNMP_ERR_GENERR);
switch (op) { switch (op) {
case SNMP_OP_GETNEXT: case SNMP_OP_GETNEXT:
if ((r = NEXT_OBJECT_OID(&sroute_list, &value->var, sub)) == NULL) if ((r = sroute_getnext(&value->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME); return (SNMP_ERR_NOSUCHNAME);
index_append(&value->var, sub, &r->index); sroute_index_append(&value->var, sub, r);
break; break;
case SNMP_OP_GET: case SNMP_OP_GET:
if ((r = FIND_OBJECT_OID(&sroute_list, &value->var, sub)) == NULL) if ((r = sroute_get(&value->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME); return (SNMP_ERR_NOSUCHNAME);
break; break;
case SNMP_OP_SET: case SNMP_OP_SET:
if ((r = FIND_OBJECT_OID(&sroute_list, &value->var, sub)) == NULL) if ((r = sroute_get(&value->var, sub)) == NULL)
return (SNMP_ERR_NO_CREATION); return (SNMP_ERR_NOSUCHNAME);
return (SNMP_ERR_NOT_WRITEABLE); return (SNMP_ERR_NOT_WRITEABLE);
case SNMP_OP_ROLLBACK: case SNMP_OP_ROLLBACK:
@ -194,28 +407,28 @@ op_route_table(struct snmp_context *ctx __unused, struct snmp_value *value,
switch (value->var.subs[sub - 1]) { switch (value->var.subs[sub - 1]) {
case LEAF_ipCidrRouteDest: case LEAF_ipCidrRouteDest:
value->v.ipaddress[0] = r->index.subs[0]; value->v.ipaddress[0] = r->index[0];
value->v.ipaddress[1] = r->index.subs[1]; value->v.ipaddress[1] = r->index[1];
value->v.ipaddress[2] = r->index.subs[2]; value->v.ipaddress[2] = r->index[2];
value->v.ipaddress[3] = r->index.subs[3]; value->v.ipaddress[3] = r->index[3];
break; break;
case LEAF_ipCidrRouteMask: case LEAF_ipCidrRouteMask:
value->v.ipaddress[0] = r->index.subs[4]; value->v.ipaddress[0] = r->index[4];
value->v.ipaddress[1] = r->index.subs[5]; value->v.ipaddress[1] = r->index[5];
value->v.ipaddress[2] = r->index.subs[6]; value->v.ipaddress[2] = r->index[6];
value->v.ipaddress[3] = r->index.subs[7]; value->v.ipaddress[3] = r->index[7];
break; break;
case LEAF_ipCidrRouteTos: case LEAF_ipCidrRouteTos:
value->v.integer = r->index.subs[8]; value->v.integer = r->index[8];
break; break;
case LEAF_ipCidrRouteNextHop: case LEAF_ipCidrRouteNextHop:
value->v.ipaddress[0] = r->index.subs[9]; value->v.ipaddress[0] = r->index[9];
value->v.ipaddress[1] = r->index.subs[10]; value->v.ipaddress[1] = r->index[10];
value->v.ipaddress[2] = r->index.subs[11]; value->v.ipaddress[2] = r->index[11];
value->v.ipaddress[3] = r->index.subs[12]; value->v.ipaddress[3] = r->index[12];
break; break;
case LEAF_ipCidrRouteIfIndex: case LEAF_ipCidrRouteIfIndex:
@ -280,9 +493,8 @@ op_route(struct snmp_context *ctx __unused, struct snmp_value *value,
abort(); abort();
} }
if (route_tick < this_tick) if (mib_fetch_route() == -1)
if (fetch_route() == -1) return (SNMP_ERR_GENERR);
return (SNMP_ERR_GENERR);
switch (value->var.subs[sub - 1]) { switch (value->var.subs[sub - 1]) {
@ -293,3 +505,5 @@ op_route(struct snmp_context *ctx __unused, struct snmp_value *value,
} }
return (SNMP_ERR_NOERROR); return (SNMP_ERR_NOERROR);
} }
RB_GENERATE(sroutes, sroute, link, sroute_compare);

View File

@ -1,4 +1,7 @@
.\" .\"
.\" Copyright (c) 2004-2005
.\" Hartmut Brandt
.\" All rights reserved.
.\" Copyright (c) 2001-2003 .\" Copyright (c) 2001-2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). .\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved. .\" All rights reserved.
@ -26,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $Begemot: bsnmp/snmp_mibII/snmp_mibII.3,v 1.7 2005/05/23 09:11:21 brandt_h Exp $ .\" $Begemot: bsnmp/snmp_mibII/snmp_mibII.3,v 1.10 2005/10/04 08:46:52 brandt_h Exp $
.\" .\"
.Dd May 23, 2005 .Dd October 4, 2005
.Dt SNMP_MIBII 3 .Dt SNMP_MIBII 3
.Os .Os
.Sh NAME .Sh NAME
@ -56,7 +59,7 @@
.Nm mib_rcvaddr_delete , .Nm mib_rcvaddr_delete ,
.Nm mibif_notify , .Nm mibif_notify ,
.Nm mibif_unnotify .Nm mibif_unnotify
.Nd "mib-2 module for snmpd. .Nd "mib-2 module for bsnmpd."
.Sh LIBRARY .Sh LIBRARY
.Pq begemotSnmpdModulePath."mibII" = "@MODPATH@snmp_mibII.so" .Pq begemotSnmpdModulePath."mibII" = "@MODPATH@snmp_mibII.so"
.Sh SYNOPSIS .Sh SYNOPSIS
@ -110,27 +113,31 @@
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm snmp_mibII .Nm snmp_mibII
module implements parts of the internet standard MIB-2. Most of the relevant module implements parts of the internet standard MIB-2.
MIBs are implemented. Some of the tables are restricted to be read-only Most of the relevant MIBs are implemented.
instead of read-write. The exact current implementation can be found in Some of the tables are restricted to be read-only instead of read-write.
The exact current implementation can be found in
.Pa @DEFPATH@mibII_tree.def . .Pa @DEFPATH@mibII_tree.def .
The module also exports a number of functions and global variables for use The module also exports a number of functions and global variables for use
by other modules, that need to handle network interfaces. This man page describes by other modules, that need to handle network interfaces.
these functions. This man page describes these functions.
.Ss DIRECT NETWORK ACCESS .Ss DIRECT NETWORK ACCESS
The The
.Nm .Nm
module opens a socket that is used to execute all network related module opens a socket that is used to execute all network related
.Xr ioctl 2 .Xr ioctl 2
functions. This socket is globally available under the name functions.
This socket is globally available under the name
.Va mib_netsock . .Va mib_netsock .
.Ss NETWORK INTERFACES .Ss NETWORK INTERFACES
The The
.Nm .Nm
module handles a list of all currently existing network interfaces. It allows module handles a list of all currently existing network interfaces.
It allows
other modules to handle their own interface lists with special information other modules to handle their own interface lists with special information
by providing a mechanism to register to events that change the interface list by providing a mechanism to register to events that change the interface list
(see below). The basic data structure is the interface structure: (see below).
The basic data structure is the interface structure:
.Bd -literal -offset indent .Bd -literal -offset indent
struct mibif { struct mibif {
TAILQ_ENTRY(mibif) link; TAILQ_ENTRY(mibif) link;
@ -159,35 +166,39 @@ The
.Nm .Nm
module tries to implement the semantic if module tries to implement the semantic if
.Va ifIndex .Va ifIndex
as described in RFC-2863. This RFC states, that an interface indexes may not as described in RFC-2863.
be reused. That means, for example, if This RFC states, that an interface indexes may not be reused.
That means, for example, if
.Pa tun .Pa tun
is a synthetic interface type and the system creates the interface is a synthetic interface type and the system creates the interface
.Pa tun0 , .Pa tun0 ,
destroys this interfaces and again creates a destroys this interfaces and again creates a
.Pa tun 0 , .Pa tun 0 ,
then these interfaces must have different interface indexes, because in fact then these interfaces must have different interface indexes, because in fact
they are different interfaces. If, on the other hand, there is a hardware they are different interfaces.
interface If, on the other hand, there is a hardware interface
.Pa xl0 .Pa xl0
and this interface disappears, because its driver is unloaded and appears and this interface disappears, because its driver is unloaded and appears
again, because the driver is loaded again, the interface index must stay again, because the driver is loaded again, the interface index must stay
the same. the same.
.Nm .Nm
implements this by differentiating between real and synthetic (dynamic) implements this by differentiating between real and synthetic (dynamic)
interfaces. An interface type can be declared dynamic by calling the function interfaces.
An interface type can be declared dynamic by calling the function
.Fn mib_if_set_dyn .Fn mib_if_set_dyn
with the name if the interface type (for example with the name if the interface type (for example
.Qq tun ). .Qq tun ).
For real interfaces, the module keeps the mapping between the interface name For real interfaces, the module keeps the mapping between the interface name
and its and its
.Va ifIndex .Va ifIndex
in a special list, if the interface is unloaded. For dynamic interfaces in a special list, if the interface is unloaded.
For dynamic interfaces
a new a new
.Va ifIndex .Va ifIndex
is generated each time the interface comes into existance. This is generated each time the interface comes into existence.
means, that the interface index as seen by SNMP is not the same index This means, that the interface index as seen by SNMP is not the same index
as used by the system. The SNMP as used by the system.
The SNMP
.Va ifIndex .Va ifIndex
is held in field is held in field
.Va index , .Va index ,
@ -212,8 +223,8 @@ finds an interface by searching for an SNMP
.Fn mib_find_if_sys .Fn mib_find_if_sys
finds an interface by searching for a system interface index and finds an interface by searching for a system interface index and
.Fn mib_find_if_name .Fn mib_find_if_name
finds an interface by looking for an interface name. Each of the finds an interface by looking for an interface name.
function returns Each of the function returns
.Li NULL .Li NULL
if the interface cannot be found. if the interface cannot be found.
.Pp .Pp
@ -227,17 +238,18 @@ can be used to change the interface administrative state to up
(argument is 1) or down (argument is 0). (argument is 1) or down (argument is 0).
.Ss INTERFACE EVENTS .Ss INTERFACE EVENTS
A module can register itself to receive a notification when a new entry is A module can register itself to receive a notification when a new entry is
created in the interface list. This is done by calling created in the interface list.
This is done by calling
.Fn mib_register_newif . .Fn mib_register_newif .
A module can register only one function, a second call to A module can register only one function, a second call to
.Fn mib_register_newif .Fn mib_register_newif
causes the registration to be overwritten. The registration can be removed causes the registration to be overwritten.
with a call to The registration can be removed with a call to
.Fn mib_unregister_newif . .Fn mib_unregister_newif .
If is unregistered automatically, when the registering module is unloaded. It is unregistered automatically, when the registering module is unloaded.
.Pp .Pp
A module can also register to events on a specific interface. This is done A module can also register to events on a specific interface.
by calling This is done by calling
.Fn mibif_notify . .Fn mibif_notify .
This causes the given callback This causes the given callback
.Fa func .Fa func
@ -251,7 +263,8 @@ The interface is destroyed.
.El .El
.Pp .Pp
This mechanism can be used to implement interface type specific MIB parts This mechanism can be used to implement interface type specific MIB parts
in other modules. The registration can be removed with in other modules.
The registration can be removed with
.Fn mib_unnotify .Fn mib_unnotify
which the return value from which the return value from
.Fa mib_notify . .Fa mib_notify .
@ -261,8 +274,8 @@ is destroyed or the registering module is unloaded.
.Ss INTERFACE ADDRESSES .Ss INTERFACE ADDRESSES
The The
.Nm .Nm
module handles a table of interface IP-addresses. These addresses are held module handles a table of interface IP-addresses.
in a These addresses are held in a
.Bd -literal -offset indent .Bd -literal -offset indent
struct mibifa { struct mibifa {
TAILQ_ENTRY(mibifa) link; TAILQ_ENTRY(mibifa) link;
@ -282,8 +295,8 @@ and
.Fn mib_next_ififa . .Fn mib_next_ififa .
The list should not be considered read-only. The list should not be considered read-only.
.Ss INTERFACE RECEIVE ADDRESSES .Ss INTERFACE RECEIVE ADDRESSES
The internet MIB-2 contains a table of interface receive addresses. These The internet MIB-2 contains a table of interface receive addresses.
addresses are handled in: These addresses are handled in:
.Bd -literal -offset indent .Bd -literal -offset indent
struct mibrcvaddr { struct mibrcvaddr {
TAILQ_ENTRY(mibrcvaddr) link; TAILQ_ENTRY(mibrcvaddr) link;
@ -302,8 +315,9 @@ enum {
.Pp .Pp
Note, that the assignment of Note, that the assignment of
.Li MIBRCVADDR_BCAST .Li MIBRCVADDR_BCAST
is based on a list of known interface types. The flags should be handled is based on a list of known interface types.
by modules inplementing interface type specific MIBs. The flags should be handled
by modules implementing interface type specific MIBs.
.Pp .Pp
A receive address can be created with A receive address can be created with
.Fn mib_rcvaddr_create .Fn mib_rcvaddr_create
@ -317,9 +331,11 @@ A receive address can be found with
.Ss INTERFACE STACK TABLE .Ss INTERFACE STACK TABLE
The The
.Nm .Nm
module maintains also the interface stack table. Because for complex stacks, module maintains also the interface stack table.
Because for complex stacks,
there is no system supported generic way of getting this information, interface there is no system supported generic way of getting this information, interface
type specific modules need to help setting up stack entries. The type specific modules need to help setting up stack entries.
The
.Nm .Nm
module handles only the top and bottom entries. module handles only the top and bottom entries.
.Pp .Pp
@ -327,8 +343,10 @@ A table entry is created with
.Fn mib_ifstack_create .Fn mib_ifstack_create
and deleted with and deleted with
.Fn mib_ifstack_delete . .Fn mib_ifstack_delete .
Both functions need the pointers to the interfaces. Entries are automatically Both functions need the pointers to the interfaces.
deleted if any of the interfaces of the entry is destroyed. The functions handle Entries are automatically
deleted if any of the interfaces of the entry is destroyed.
The functions handle
both the stack table and the reverse stack table. both the stack table and the reverse stack table.
.Sh FILES .Sh FILES
.Bl -tag -width ".It Pa @DEFPATH@mibII_tree.def" -compact .Bl -tag -width ".It Pa @DEFPATH@mibII_tree.def" -compact

View File

@ -26,7 +26,7 @@
-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-- SUCH DAMAGE. -- SUCH DAMAGE.
-- --
-- $Begemot: bsnmp/snmp_ntp/BEGEMOT-NTP-MIB.txt,v 1.2 2005/04/26 13:38:01 brandt_h Exp $ -- $Begemot: bsnmp/snmp_ntp/BEGEMOT-NTP-MIB.txt,v 1.3 2005/10/04 08:13:41 brandt_h Exp $
-- --
-- Private MIB for NTP module. -- Private MIB for NTP module.
-- --
@ -35,11 +35,13 @@ BEGEMOT-NTP-MIB DEFINITIONS ::= BEGIN
IMPORTS IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, TimeTicks, Unsigned32, Counter64 MODULE-IDENTITY, OBJECT-TYPE, TimeTicks, Unsigned32, Counter64
FROM SNMPv2-SMI FROM SNMPv2-SMI
TruthValue
FROM SNMPv2-TC
begemot begemot
FROM BEGEMOT-MIB; FROM BEGEMOT-MIB;
begemotNtp MODULE-IDENTITY begemotNtp MODULE-IDENTITY
LAST-UPDATED "200503210000Z" LAST-UPDATED "200509300000Z"
ORGANIZATION "German Aerospace Center" ORGANIZATION "German Aerospace Center"
CONTACT-INFO CONTACT-INFO
" Hartmut Brandt " Hartmut Brandt
@ -114,4 +116,29 @@ begemotNtpStability OBJECT-TYPE
"Current stability in ppm multiplied by 2^32." "Current stability in ppm multiplied by 2^32."
::= { begemotNtpObjects 6 } ::= { begemotNtpObjects 6 }
begemotNtpJitterThresh OBJECT-TYPE
SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Jitter trap threshold in seconds multiplied by 2^32."
::= { begemotNtpObjects 7 }
begemotNtpStabilityThresh OBJECT-TYPE
SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Stability trap threshold in ppm multiplied by 2^32."
::= { begemotNtpObjects 8 }
begemotNtpTrapEnable OBJECT-TYPE
SYNTAX TruthValue
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Enables the sending of traps when either the peer is lost/
found or one of the above thresholds is crossed."
::= { begemotNtpObjects 9 }
END END

View File

@ -0,0 +1,38 @@
# Copyright (c) 2005
# Hartmut Brandt.
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/snmp_ntp/Makefile.in,v 1.2 2005/05/23 09:03:47 brandt_h Exp $
#
MOD= ntp
SRCS= ${MOD}_tree.c snmp_ntp.c
DEFS= ntp_tree.def
BMIBS= BEGEMOT-NTP-MIB.txt NTP-MIB.txt NTP-PROXY-MIB.txt
# MAN3= snmp_ntp.3
MANFILTER= sed -e 's%@MODPATH@%${LIBDIR}/%g' \
-e 's%@DEFPATH@%${DEFSDIR}/%g' \
-e 's%@MIBSPATH@%${MIBSDIR}/%g'
XSYM= ntpMIB
LIB= snmp_${MOD}.la
SHLIB_MAJOR= 3
SHLIB_MINOR= 0
CFLAGS+= -I$(srcdir) -I$(srcdir)/../lib -I$(builddir) -I$(srcdir)/../snmpd
CLEANFILES += ${MOD}_oid.h ${MOD}_tree.c ${MOD}_tree.h
# for bootstrapping
GENSNMPTREE= ${builddir}/../gensnmptree/gensnmptree
$(LIB): ${MOD}_oid.h ${MOD}_tree.h $(SRCS:.c=.lo)
$(LIBTOOL) --mode=link $(CC) $(LDLAGS) -module -o $@ $(SRCS:.c=.lo) -rpath $(libdir) -version-info $(SHLIB_MAJOR):$(SHLIB_MINOR)
${MOD}_oid.h: ${MOD}_tree.def
${GENSNMPTREE} <${srcdir}/${MOD}_tree.def -e ${XSYM} >$@
${MOD}_tree.h ${MOD}_tree.c : ${MOD}_tree.def
${GENSNMPTREE} <${srcdir}/${MOD}_tree.def -l -p ${MOD}_

View File

@ -27,7 +27,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Begemot: bsnmp/snmp_ntp/snmp_ntp.c,v 1.4 2005/05/23 09:03:48 brandt_h Exp $ * $Begemot: bsnmp/snmp_ntp/snmp_ntp.c,v 1.7 2005/10/04 11:21:36 brandt_h Exp $
* *
* NTP interface for SNMPd. * NTP interface for SNMPd.
*/ */
@ -40,7 +40,11 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <netdb.h> #include <netdb.h>
#ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#elif defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -173,7 +177,7 @@ static uint32_t ntp_timeout;
static void ntpd_input(int, void *); static void ntpd_input(int, void *);
static int open_socket(void); static int open_socket(void);
/* the initialisation function */ /* the initialization function */
static int static int
ntp_init(struct lmodule *mod, int argc, char *argv[] __unused) ntp_init(struct lmodule *mod, int argc, char *argv[] __unused)
{ {
@ -360,6 +364,7 @@ ntpd_request(u_int op, u_int associd, const char *vars)
free(rpkt); free(rpkt);
return (-1); return (-1);
} }
return (0);
} }
/* /*
@ -431,7 +436,7 @@ ntpd_read(uint16_t *op, uint16_t *associd, u_char **data, size_t *datalen)
} }
ptr = pkt; ptr = pkt;
if (*ptr != ((NTPC_VERSION << 3) | NTPC_MODE)) { if ((*ptr & 0x3f) != ((NTPC_VERSION << 3) | NTPC_MODE)) {
syslog(LOG_ERR, "unexpected packet version 0x%x", *ptr); syslog(LOG_ERR, "unexpected packet version 0x%x", *ptr);
free(*data); free(*data);
return (-1); return (-1);
@ -720,7 +725,7 @@ val_parse_ip(const char *val, u_char ip[4])
{ {
int r, n, error; int r, n, error;
struct addrinfo hints, *res0; struct addrinfo hints, *res0;
struct sockaddr_in *sin; struct sockaddr_in *sin_local;
r = sscanf(val, "%hhd.%hhd.%hhd.%hhd%n", r = sscanf(val, "%hhd.%hhd.%hhd.%hhd%n",
&ip[0], &ip[1], &ip[2], &ip[3], &n); &ip[0], &ip[1], &ip[2], &ip[3], &n);
@ -743,11 +748,11 @@ val_parse_ip(const char *val, u_char ip[4])
return (-1); return (-1);
} }
sin = (struct sockaddr_in *)(void *)res0->ai_addr; sin_local = (struct sockaddr_in *)(void *)res0->ai_addr;
ip[3] = sin->sin_addr.s_addr >> 24; ip[3] = sin_local->sin_addr.s_addr >> 24;
ip[2] = sin->sin_addr.s_addr >> 16; ip[2] = sin_local->sin_addr.s_addr >> 16;
ip[1] = sin->sin_addr.s_addr >> 8; ip[1] = sin_local->sin_addr.s_addr >> 8;
ip[0] = sin->sin_addr.s_addr >> 0; ip[0] = sin_local->sin_addr.s_addr >> 0;
freeaddrinfo(res0); freeaddrinfo(res0);
return (0); return (0);
@ -1517,7 +1522,7 @@ op_begemot_ntp(struct snmp_context *ctx __unused, struct snmp_value *value,
switch (which) { switch (which) {
case LEAF_begemotNtpHost: case LEAF_begemotNtpHost:
/* only at initialisation */ /* only at initialization */
if (community != COMM_INITIALIZE) if (community != COMM_INITIALIZE)
return (SNMP_ERR_NOT_WRITEABLE); return (SNMP_ERR_NOT_WRITEABLE);
@ -1527,7 +1532,7 @@ op_begemot_ntp(struct snmp_context *ctx __unused, struct snmp_value *value,
return (SNMP_ERR_NOERROR); return (SNMP_ERR_NOERROR);
case LEAF_begemotNtpPort: case LEAF_begemotNtpPort:
/* only at initialisation */ /* only at initialization */
if (community != COMM_INITIALIZE) if (community != COMM_INITIALIZE)
return (SNMP_ERR_NOT_WRITEABLE); return (SNMP_ERR_NOT_WRITEABLE);

View File

@ -0,0 +1,42 @@
# Copyright (c) 2001-2003
# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
# All rights reserved.
#
# Author: Harti Brandt <harti@freebsd.org>
#
# $Begemot: bsnmp/snmpd/Makefile.in,v 1.8 2005/04/22 12:18:14 brandt_h Exp $
#
PROG= bsnmpd
SRCS= tree.c main.c action.c config.c export.c trap.c
SRCS+= trans_udp.c trans_lsock.c
MAN1= bsnmpd.1
MAN3= snmpmod.3
MANFILTER= sed -e 's%@MODPATH@%${LIBDIR}/%g' \
-e 's%@DEFPATH@%${DEFSDIR}/%g' \
-e 's%@MIBSPATH@%${MIBSDIR}/%g'
XSYM= snmpMIB begemotSnmpdModuleTable begemotSnmpd begemotTrapSinkTable \
sysUpTime snmpTrapOID coldStart authenticationFailure \
begemotSnmpdLocalPortTable begemotSnmpdTransUdp begemotSnmpdTransLsock
BMIBS= FOKUS-MIB.txt BEGEMOT-MIB.txt BEGEMOT-SNMPD.txt
DEFS= tree.def
INCS= snmpmod.h
CFLAGS+= -I$(builddir)/. -I${srcdir} -I${srcdir}/../lib
LDFLAGS+= -export-dynamic
$(PROG): $(SRCS:.c=.lo) oid.h tree.h
$(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o $@ $(SRCS:.c=.lo) \
$(builddir)/../lib/libbsnmp.la $(LIBEV) $(LIBWRAP)
CLEANFILES += tree.c tree.h oid.h
tree.c tree.h: tree.def ../gensnmptree/gensnmptree
$(builddir)/../gensnmptree/gensnmptree -l <${srcdir}/tree.def
oid.h: tree.def ../gensnmptree/gensnmptree
$(builddir)/../gensnmptree/gensnmptree <${srcdir}/tree.def -e ${XSYM} >$@
$(SRCS:.c=.lo): oid.h

View File

@ -1,4 +1,7 @@
.\" .\"
.\" Copyright (c) 2004-2005
.\" Hartmut Brandt.
.\" All rights reserved.
.\" Copyright (c) 2001-2003 .\" Copyright (c) 2001-2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). .\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved. .\" All rights reserved.
@ -26,14 +29,14 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" 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 .Dt SNMPD 1
.Os .Os
.Sh NAME .Sh NAME
.Nm snmpd .Nm bsnmpd
.Nd "simple and extendable SNMP daemon" .Nd "simple and extensible SNMP daemon"
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl dh .Op Fl dh
@ -46,9 +49,10 @@
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .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 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 .Nm
can be used in unexpected ways. can be used in unexpected ways.
.Pp .Pp
@ -78,11 +82,13 @@ This causes the debugging level of the event library (see
to be set to 10. to be set to 10.
.It Cm trace Ns Cm = Ns Cm level .It Cm trace Ns Cm = Ns Cm level
This option causes the snmp library trace flag to be set to the specified 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 .El
.It Fl I Ar paths .It Fl I Ar paths
This option specifies a colon separated list of directories to search for 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 . .Pa /etc:/usr/etc/:/usr/local/etc .
These paths are only searched for include specified within <> parentheses. These paths are only searched for include specified within <> parentheses.
.It Fl l Ar prefix .It Fl l Ar prefix
@ -98,8 +104,8 @@ Specify an alternate pid file instead of the default one.
The The
.Nm .Nm
reads its configuration from either the default or the user specified reads its configuration from either the default or the user specified
configuration file. The configuration file consists of the following types of configuration file.
lines: The configuration file consists of the following types of lines:
.Bl -bullet -offset indent .Bl -bullet -offset indent
.It .It
variable assignments variable assignments
@ -112,18 +118,21 @@ MIB variable assignments
.El .El
.Pp .Pp
If a line is too long it can be continued on the next line by ending it with 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 # .Dq #
sign are ignored. sign are ignored.
.Pp .Pp
All MIB variable assignments of the entire configuration (including nested All MIB variable assignments of the entire configuration (including nested
configuration files) are handled as one transaction, i.e. as if they arrived 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 in a single SET PDU.
Any failure during the initial configuration read causes
.Nm .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. causes the loading of the module to fail.
.Pp .Pp
The configuration is read during initialisation of The configuration is read during initialization of
.Nm , .Nm ,
when a module is loaded and when when a module is loaded and when
.Nm .Nm
@ -138,23 +147,25 @@ variable ?= string
The string reaches from the first non-blank character after the The string reaches from the first non-blank character after the
equal sign until the first new line or equal sign until the first new line or
.Dq # .Dq #
character. In the first case character.
In the first case
the string is assigned to the variable unconditionally, in the second case the the string is assigned to the variable unconditionally, in the second case the
variable is only assigned if it does not exist yet. variable is only assigned if it does not exist yet.
.Pp .Pp
Variable names must begin with a letter or underscore and contain only letters, Variable names must begin with a letter or underscore and contain only letters,
digits or underscores. digits or underscores.
.Ss SECTION SEPARATORS .Ss SECTION SEPARATORS
The configuration consists of named sections. The MIB variable assignments in The configuration consists of named sections.
the section named The MIB variable assignments in the section named
.Dq snmpd .Dq snmpd
are executed only during initial setup or when are executed only during initial setup or when
.Nm .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 with the same name as the section is loaded or
.Nm .Nm
receives a SIGHUP and that module is already loaded. The default section receives a SIGHUP and that module is already loaded.
at the start of the configuration is The default section at the start of the configuration is
.Dq snmpd . .Dq snmpd .
One can switch to another section with the syntax One can switch to another section with the syntax
.Bd -unfilled -offset indent .Bd -unfilled -offset indent
@ -163,10 +174,11 @@ One can switch to another section with the syntax
.Pp .Pp
Where Where
.Ar secname .Ar secname
is the name of the section. The same is the name of the section.
The same
.Ar secname .Ar secname
can be used in more than one place in the configuration. All of these parts are can be used in more than one place in the configuration.
collected into one section. All of these parts are collected into one section.
.Ss INCLUDE DIRECTIVES .Ss INCLUDE DIRECTIVES
Another configuration file can be included into the current one with the Another configuration file can be included into the current one with the
include directive that takes one of two forms: include directive that takes one of two forms:
@ -177,8 +189,8 @@ include directive that takes one of two forms:
.Pp .Pp
The first form causes the file to be searched in the current directory, the 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 second form causes the file to be searched in the directories specified in
the system include path. Nesting depth is only restricted by available the system include path.
memory. Nesting depth is only restricted by available memory.
.Ss MIB VARIABLE ASSIGNMENTS .Ss MIB VARIABLE ASSIGNMENTS
A MIB variable is assigned with the syntax A MIB variable is assigned with the syntax
.Bd -unfilled -offset indent .Bd -unfilled -offset indent
@ -186,17 +198,23 @@ oid [ suboids ] = value
.Ed .Ed
.Pp .Pp
.Va oid .Va oid
is the name of the variable to be set. Only the last component of the entire is the name of the variable to be set.
name is used here. If the variable is a scalar, the index (.0) is automatically Only the last component of the entire name is used here.
appended and need not to be specified. If the variable is a table column, If the variable is a scalar, the index (.0) is automatically
the index appended and need not to be specified.
If the variable is a table column, the index
.Pq Va suboids .Pq Va suboids
must be specified. The index consist of elements each seperated from the must be specified.
previous one by a dot. Elements may be either numbers, strings or hostnames The index consist of elements each separated from the
enclosed in [] brackets. If the element is a number it is appended previous one by a dot.
to the current oid. If the element is a string, its length and the 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 .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 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. elements of the IP address are appended to the oid.
.Pp .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. 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 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 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 .Sh SUBSTITUTIONS
A variable substitution is written as A variable substitution is written as
.Bd -unfilled -offset indent .Bd -unfilled -offset indent
@ -222,8 +241,8 @@ $(variable)
.Pp .Pp
where where
.Ar variable .Ar variable
is the name of the variable to substitute. Using an undefined variable is is the name of the variable to substitute.
considered an error. Using an undefined variable is considered an error.
.Sh FILES .Sh FILES
.Bl -tag -width ".It Pa /var/run/ Ns Ao Ar prefix Ac Ns \&.pid" -compact .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 .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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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. * Parse configuration file.
*/ */
@ -820,7 +820,7 @@ parse_oid(const char *varname, struct asn_oid *oid)
while (token == '.') { while (token == '.') {
if (gettoken() == TOK_NUM) { if (gettoken() == TOK_NUM) {
if (numval > ASN_MAXID) if (numval > ASN_MAXID)
report("subid too large %#"PRIx64, numval); report("subid too large %#"QUADXFMT, numval);
if (oid->len == ASN_MAXOIDLEN) if (oid->len == ASN_MAXOIDLEN)
report("index too long"); report("index too long");
oid->subs[oid->len++] = numval; oid->subs[oid->len++] = numval;
@ -863,7 +863,7 @@ parse_syntax_integer(struct snmp_value *value)
if (token != TOK_NUM) if (token != TOK_NUM)
report("bad INTEGER syntax"); report("bad INTEGER syntax");
if (numval > 0x7fffffff) if (numval > 0x7fffffff)
report("INTEGER too large %"PRIu64, numval); report("INTEGER too large %"QUADFMT, numval);
value->v.integer = numval; value->v.integer = numval;
gettoken(); gettoken();
@ -1131,7 +1131,7 @@ parse_define(const char *varname)
m->value = string; m->value = string;
m->length = length; m->length = length;
} else { } else {
if (t != TOK_ASSIGN) { if (t == TOK_ASSIGN) {
free(m->value); free(m->value);
m->value = string; m->value = string;
m->length = length; m->length = length;
@ -1360,5 +1360,7 @@ define_macro(const char *name, const char *value)
} }
strcpy(m->value, value); strcpy(m->value, value);
m->length = strlen(value); m->length = strlen(value);
m->perm = 1;
LIST_INSERT_HEAD(&macros, m, link);
return (0); return (0);
} }

View File

@ -26,13 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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. * SNMPd main stuff.
*/ */
#include <sys/param.h> #include <sys/param.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/ucred.h> #include <sys/ucred.h>
#include <sys/uio.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
@ -734,7 +735,7 @@ check_priv(struct port_input *pi, struct msghdr *msg)
pi->priv = 0; pi->priv = 0;
if (msg->msg_controllen == sizeof(*cmsg)) { if (msg->msg_controllen == sizeof(*cmsg)) {
/* process explicitely sends credentials */ /* process explicitly sends credentials */
cmsg = (struct credmsg *)msg->msg_control; cmsg = (struct credmsg *)msg->msg_control;
pi->priv = (cmsg->cred.cmcred_euid == 0); pi->priv = (cmsg->cred.cmcred_euid == 0);
@ -1611,6 +1612,10 @@ get_ticks()
/* /*
* Timer support * Timer support
*/ */
/*
* Trampoline for the non-repeatable timers.
*/
#ifdef USE_LIBBEGEMOT #ifdef USE_LIBBEGEMOT
static void static void
tfunc(int tid __unused, void *uap) tfunc(int tid __unused, void *uap)
@ -1628,7 +1633,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 * void *
timer_start(u_int ticks, void (*func)(void *), void *udata, struct lmodule *mod) timer_start(u_int ticks, void (*func)(void *), void *udata, struct lmodule *mod)
@ -1669,6 +1691,55 @@ timer_start(u_int ticks, void (*func)(void *), void *udata, struct lmodule *mod)
return (tp); 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 void
timer_stop(void *p) timer_stop(void *p)
{ {
@ -2157,7 +2228,7 @@ lm_load(const char *path, const char *section)
av[ac] = NULL; av[ac] = NULL;
/* /*
* Run the initialisation function * Run the initialization function
*/ */
if ((err = (*m->config->init)(m, ac, av)) != 0) { if ((err = (*m->config->init)(m, ac, av)) != 0) {
syslog(LOG_ERR, "lm_load: init failed: %d", err); syslog(LOG_ERR, "lm_load: init failed: %d", err);

View File

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

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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. * SNMP daemon data and functions exported to modules.
*/ */
@ -46,7 +46,8 @@
/* /*
* These macros help to handle object lists for SNMP tables. They use * These macros help to handle object lists for SNMP tables. They use
* tail queues to hold the objects in ascending order in the list. * 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 { \ #define INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, LINK, INDEX) do { \
__typeof (PTR) _lelem; \ __typeof (PTR) _lelem; \
@ -58,7 +59,7 @@
TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \ TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \
else \ else \
TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \ TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \
} while(0) } while (0)
#define INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, INDEX) do { \ #define INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, INDEX) do { \
__typeof (PTR) _lelem; \ __typeof (PTR) _lelem; \
@ -70,7 +71,31 @@
TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \ TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \
else \ else \
TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \ 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) ({ \ #define FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({ \
__typeof (TAILQ_FIRST(LIST)) _lelem; \ __typeof (TAILQ_FIRST(LIST)) _lelem; \
@ -114,6 +139,24 @@
(_lelem); \ (_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' * Macros for the case where the index field is called 'index'
*/ */
@ -145,18 +188,27 @@
#define INSERT_OBJECT_INT(PTR, LIST) \ #define INSERT_OBJECT_INT(PTR, LIST) \
INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, link, index) 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) \ #define FIND_OBJECT_OID(LIST, OID, SUB) \
FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index) FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index)
#define FIND_OBJECT_INT(LIST, OID, SUB) \ #define FIND_OBJECT_INT(LIST, OID, SUB) \
FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index) 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) \ #define NEXT_OBJECT_OID(LIST, OID, SUB) \
NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index) NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index)
#define NEXT_OBJECT_INT(LIST, OID, SUB) \ #define NEXT_OBJECT_INT(LIST, OID, SUB) \
NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index) 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; struct lmodule;
/* The tick when the program was started. This is the absolute time of /* 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 */ /* a comment describing what this module implements */
const char *comment; const char *comment;
/* the initialisation function */ /* the initialization function */
int (*init)(struct lmodule *, int argc, char *argv[]); int (*init)(struct lmodule *, int argc, char *argv[]);
/* the finalisation function */ /* the finalisation function */
@ -301,6 +353,8 @@ u_int reqid_type(int32_t reqid);
* Timers. * Timers.
*/ */
void *timer_start(u_int, void (*)(void *), void *, struct lmodule *); 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 *); void timer_stop(void *);
/* /*

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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 * 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 * 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 static int
udp_open_port(u_int8_t *addr, u_int32_t udp_port, struct udp_port **pp) 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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 * TrapSinkTable
*/ */
@ -107,7 +107,7 @@ trapsink_create(struct trapsink_dep *tdep)
if (connect(t->socket, (struct sockaddr *)&sa, sa.sin_len) == -1) { if (connect(t->socket, (struct sockaddr *)&sa, sa.sin_len) == -1) {
syslog(LOG_ERR, "connect(%s,%u): %m", 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); (void)close(t->socket);
free(t); free(t);
return (SNMP_ERR_GENERR); return (SNMP_ERR_GENERR);