From 9e7a548ce421660b0d22bfeb90c2b2b53742aac7 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 22 May 2012 14:32:22 +0200 Subject: build: allow configure and build in a separate directory Some .h files in lib/ are autogenerated. The search path should include the build directory and the source directory. They usually match but sometimes, they may be different. For example: $ mkdir build $ cd build $ ../configure $ make --- babeld/Makefile.am | 2 +- bgpd/Makefile.am | 2 +- guile/Makefile.am | 2 +- isisd/Makefile.am | 2 +- isisd/topology/Makefile.am | 2 +- lib/Makefile.am | 2 +- ospf6d/Makefile.am | 2 +- ospfclient/Makefile.am | 2 +- ospfd/Makefile.am | 2 +- ripd/Makefile.am | 2 +- ripngd/Makefile.am | 2 +- tests/Makefile.am | 2 +- vtysh/Makefile.am | 2 +- vtysh/extract.pl.in | 2 +- watchquagga/Makefile.am | 2 +- zebra/Makefile.am | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/babeld/Makefile.am b/babeld/Makefile.am index 8703de06..81f66126 100644 --- a/babeld/Makefile.am +++ b/babeld/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/bgpd/Makefile.am b/bgpd/Makefile.am index 3051555b..e5ee893a 100644 --- a/bgpd/Makefile.am +++ b/bgpd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/guile/Makefile.am b/guile/Makefile.am index 5beb71c4..8d7008e9 100644 --- a/guile/Makefile.am +++ b/guile/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with Automake to create Makefile.in -INCLUDES = @GUILE_CFLAGS@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib +INCLUDES = @GUILE_CFLAGS@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -I. -I$(srcdir) AM_CFLAGS = $(PICFLAGS) diff --git a/isisd/Makefile.am b/isisd/Makefile.am index 26b8ee7c..4e9b2441 100644 --- a/isisd/Makefile.am +++ b/isisd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib \ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib \ @ISIS_TOPOLOGY_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/isisd/topology/Makefile.am b/isisd/topology/Makefile.am index b25497cb..ccd2e717 100644 --- a/isisd/topology/Makefile.am +++ b/isisd/topology/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" AM_CFLAGS = $(PICFLAGS) diff --git a/lib/Makefile.am b/lib/Makefile.am index 890cc5ca..4c67858c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" lib_LTLIBRARIES = libzebra.la diff --git a/ospf6d/Makefile.am b/ospf6d/Makefile.am index 01bc6fe0..d05b0207 100644 --- a/ospf6d/Makefile.am +++ b/ospf6d/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/ospfclient/Makefile.am b/ospfclient/Makefile.am index b8aae84b..607bbed6 100644 --- a/ospfclient/Makefile.am +++ b/ospfclient/Makefile.am @@ -1,6 +1,6 @@ ## Automake.am for OSPF API client -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib lib_LTLIBRARIES = libospfapiclient.la libospfapiclient_la_LDFLAGS = -version 0:0:0 diff --git a/ospfd/Makefile.am b/ospfd/Makefile.am index 2e4d5c8e..d0b4ae84 100644 --- a/ospfd/Makefile.am +++ b/ospfd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/ripd/Makefile.am b/ripd/Makefile.am index 2fa26659..3196090c 100644 --- a/ripd/Makefile.am +++ b/ripd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/ripngd/Makefile.am b/ripngd/Makefile.am index c6bd4868..83ddca0a 100644 --- a/ripngd/Makefile.am +++ b/ripngd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/tests/Makefile.am b/tests/Makefile.am index 2e98ff79..0c262a4a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\" AM_CFLAGS = $(PICFLAGS) diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am index 0fd2f148..7550173c 100644 --- a/vtysh/Makefile.am +++ b/vtysh/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with Automake to create Makefile.in -INCLUDES = @INCLUDES@ -I$(top_srcdir) -I$(top_srcdir)/lib +INCLUDES = @INCLUDES@ -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" LIBS = @LIBS@ @CURSES@ @LIBPAM@ diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 61b2d2a2..99224f80 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -63,7 +63,7 @@ $ignore{'"show history"'} = "ignore"; foreach (@ARGV) { $file = $_; - open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib -I@top_srcdir@/isisd/topology @SNMP_INCLUDES@ @CPPFLAGS@ $file |"); + open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib -I@top_builddir@/lib -I@top_srcdir@/isisd/topology @SNMP_INCLUDES@ @CPPFLAGS@ $file |"); local $/; undef $/; $line = ; close (FH); diff --git a/watchquagga/Makefile.am b/watchquagga/Makefile.am index a49f62e8..badaa5b5 100644 --- a/watchquagga/Makefile.am +++ b/watchquagga/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with Automake to create Makefile.in -INCLUDES = @INCLUDES@ -I$(top_srcdir) -I$(top_srcdir)/lib +INCLUDES = @INCLUDES@ -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSTATEDIR=\"$(localstatedir)/\" AM_CFLAGS = $(PICFLAGS) diff --git a/zebra/Makefile.am b/zebra/Makefile.am index 542f36f4..e5b749a6 100644 --- a/zebra/Makefile.am +++ b/zebra/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DMULTIPATH_NUM=@MULTIPATH_NUM@ INSTALL_SDATA=@INSTALL@ -m 600 -- cgit v1.2.1 From 6b1e37f8537fa2a4560de32e83ca5089763e2d39 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 22 May 2012 22:15:20 +0200 Subject: build: only define HAVE_SNMP NetSNMP is the only SNMP implementation for Quagga. We don't need two different symbols. --- bgpd/bgp_snmp.c | 6 ------ configure.ac | 3 +-- lib/smux.c | 6 ------ ospf6d/ospf6_snmp.c | 6 ------ ospfd/ospf_snmp.c | 6 ------ ripd/rip_snmp.c | 6 ------ zebra/zebra_snmp.c | 6 ------ 7 files changed, 1 insertion(+), 38 deletions(-) diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index 86cc0879..f6b10563 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -21,14 +21,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include #ifdef HAVE_SNMP -#ifdef HAVE_NETSNMP #include #include -#else -#include -#include -#include -#endif #include "if.h" #include "log.h" diff --git a/configure.ac b/configure.ac index 80f65b98..c3c651f1 100755 --- a/configure.ac +++ b/configure.ac @@ -1370,8 +1370,7 @@ if test "${enable_snmp}" = "yes"; then LIBS="${LIBS} -lcrypto"; fi AC_CHECK_LIB(netsnmp, asn_parse_int, - [AC_DEFINE(HAVE_NETSNMP,,Net SNMP) - AC_DEFINE(HAVE_SNMP,,SNMP) + [AC_DEFINE(HAVE_SNMP,,SNMP) LIBS="${LIBS} -lnetsnmp"], [AC_MSG_ERROR([--enable-snmp given, but cannot find support for SNMP])]) diff --git a/lib/smux.c b/lib/smux.c index b7cd18d1..145ec90b 100644 --- a/lib/smux.c +++ b/lib/smux.c @@ -22,14 +22,8 @@ #include #ifdef HAVE_SNMP -#ifdef HAVE_NETSNMP #include #include -#else -#include -#include -#include -#endif #include "log.h" #include "thread.h" diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 5ac7846d..11b733b8 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -23,14 +23,8 @@ #ifdef HAVE_SNMP -#ifdef HAVE_NETSNMP #include #include -#else -#include -#include -#include -#endif #include "log.h" #include "vty.h" diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index 9c9dd47a..739dcae1 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -25,14 +25,8 @@ #include #ifdef HAVE_SNMP -#ifdef HAVE_NETSNMP #include #include -#else -#include -#include -#include -#endif #include "if.h" #include "log.h" diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c index 61c47c71..803ac856 100644 --- a/ripd/rip_snmp.c +++ b/ripd/rip_snmp.c @@ -22,14 +22,8 @@ #include #ifdef HAVE_SNMP -#ifdef HAVE_NETSNMP #include #include -#else -#include -#include -#include -#endif #include "if.h" #include "log.h" diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c index 0fde4bb8..3dbfb587 100644 --- a/zebra/zebra_snmp.c +++ b/zebra/zebra_snmp.c @@ -22,14 +22,8 @@ #include #ifdef HAVE_SNMP -#ifdef HAVE_NETSNMP #include #include -#else -#include -#include -#include -#endif #include "if.h" #include "log.h" -- cgit v1.2.1 From 08d7f6533ecc0f935a76918c462982004534864d Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 22 May 2012 22:29:17 +0200 Subject: build: use net-snmp-config to configure NetSNMP The correct method to link to NetSNMP is to use net-snmp-config (which is like pkg-config). Explicit link to libcrypto is also dropped (NetSNMP libs are linked to libcrypto, no need to link Quagga to it). Moreover, @SNMP_INCLUDES@ is dropped because useless. Due to a bug in configure.ac, it was properly populated. --- babeld/Makefile.am | 2 +- bgpd/Makefile.am | 2 +- configure.ac | 35 +++++++++++++++++++---------------- lib/Makefile.am | 2 +- ospf6d/Makefile.am | 2 +- ospfd/Makefile.am | 2 +- ripd/Makefile.am | 2 +- ripngd/Makefile.am | 2 +- vtysh/extract.pl.in | 2 +- zebra/Makefile.am | 2 +- 10 files changed, 28 insertions(+), 25 deletions(-) diff --git a/babeld/Makefile.am b/babeld/Makefile.am index 81f66126..af1201a7 100644 --- a/babeld/Makefile.am +++ b/babeld/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/bgpd/Makefile.am b/bgpd/Makefile.am index e5ee893a..9928734e 100644 --- a/bgpd/Makefile.am +++ b/bgpd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/configure.ac b/configure.ac index c3c651f1..a2738a95 100755 --- a/configure.ac +++ b/configure.ac @@ -221,8 +221,6 @@ AC_ARG_ENABLE(netlink, [ --enable-netlink force to use Linux netlink interface]) AC_ARG_ENABLE(broken-aliases, [ --enable-broken-aliases enable aliases as distinct interfaces for Linux 2.2.X]) -AC_ARG_WITH(crypto, -[ --without-crypto do not use libcrypto in SNMP]) AC_ARG_ENABLE(snmp, [ --enable-snmp enable SNMP support]) AC_ARG_WITH(libpam, @@ -1366,19 +1364,24 @@ dnl ------------------ dnl check Net-SNMP library dnl ------------------ if test "${enable_snmp}" = "yes"; then - if test "$with_crypto" != "no"; then - LIBS="${LIBS} -lcrypto"; - fi - AC_CHECK_LIB(netsnmp, asn_parse_int, - [AC_DEFINE(HAVE_SNMP,,SNMP) - LIBS="${LIBS} -lnetsnmp"], - [AC_MSG_ERROR([--enable-snmp given, but cannot find support for SNMP])]) - - AC_CHECK_HEADER([net-snmp/net-snmp-config.h], - [], - [AC_MSG_ERROR([--enable-snmp given, but cannot find net-snmp-config.h])], - QUAGGA_INCLUDES) - AC_SUBST(SNMP_INCLUDES) + AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], [no]) + if test x"$NETSNMP_CONFIG" = x"no"; then + AC_MSG_ERROR([--enable-snmp given but unable to find net-snmp-config]) + fi + LIBS="$LIBS `${NETSNMP_CONFIG} --agent-libs`" + CFLAGS="`${NETSNMP_CONFIG} --base-cflags` $CFLAGS" + AC_MSG_CHECKING([whether we can link to Net-SNMP]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([ +int main(void); +], +[ +{ + return 0; +} +])],[AC_MSG_RESULT(yes)],[ + AC_MSG_RESULT(no) + AC_MSG_ERROR([--enable-snmp given but not usable])]) + AC_DEFINE(HAVE_SNMP,,SNMP) fi dnl --------------------------- @@ -1624,7 +1627,7 @@ source code location : ${srcdir} compiler : ${CC} compiler flags : ${CFLAGS} make : ${MAKE-make} -includes : ${INCLUDES} ${SNMP_INCLUDES} +includes : ${INCLUDES} linker flags : ${LDFLAGS} ${LIBS} ${LIBCAP} ${LIBREADLINE} ${LIBM} state file directory : ${quagga_statedir} config file directory : `eval echo \`echo ${sysconfdir}\`` diff --git a/lib/Makefile.am b/lib/Makefile.am index 4c67858c..d01cf724 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" lib_LTLIBRARIES = libzebra.la diff --git a/ospf6d/Makefile.am b/ospf6d/Makefile.am index d05b0207..726ce543 100644 --- a/ospf6d/Makefile.am +++ b/ospf6d/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/ospfd/Makefile.am b/ospfd/Makefile.am index d0b4ae84..f968d7d6 100644 --- a/ospfd/Makefile.am +++ b/ospfd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/ripd/Makefile.am b/ripd/Makefile.am index 3196090c..b0bc7a87 100644 --- a/ripd/Makefile.am +++ b/ripd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/ripngd/Makefile.am b/ripngd/Makefile.am index 83ddca0a..de5bebae 100644 --- a/ripngd/Makefile.am +++ b/ripngd/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 99224f80..2dbaf0a1 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -63,7 +63,7 @@ $ignore{'"show history"'} = "ignore"; foreach (@ARGV) { $file = $_; - open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib -I@top_builddir@/lib -I@top_srcdir@/isisd/topology @SNMP_INCLUDES@ @CPPFLAGS@ $file |"); + open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib -I@top_builddir@/lib -I@top_srcdir@/isisd/topology @CPPFLAGS@ $file |"); local $/; undef $/; $line = ; close (FH); diff --git a/zebra/Makefile.am b/zebra/Makefile.am index e5b749a6..9ac90f8e 100644 --- a/zebra/Makefile.am +++ b/zebra/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in. -INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib @SNMP_INCLUDES@ +INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DMULTIPATH_NUM=@MULTIPATH_NUM@ INSTALL_SDATA=@INSTALL@ -m 600 -- cgit v1.2.1 From 3a4c96885ec878ae4631b0fb7bb7839578725976 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 23 May 2012 00:52:46 +0200 Subject: smux: isolate SMUX implementation from SNMP implementation lib/snmp.c gets OID related helper functions that can be used with another SNMP interface. smux.h is cleaned of SMUX specific bits to only expose functions that may be used by an alternative implementation. We also do not redefine functions already present in NetSNMP. Just use the appropriate headers. --- lib/Makefile.am | 2 +- lib/smux.c | 123 ++++++++++++++++++-------------------------------------- lib/smux.h | 81 ++----------------------------------- lib/snmp.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 161 deletions(-) create mode 100644 lib/snmp.c diff --git a/lib/Makefile.am b/lib/Makefile.am index d01cf724..73417ad8 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -11,7 +11,7 @@ libzebra_la_SOURCES = \ checksum.c vector.c linklist.c vty.c command.c \ sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.c \ filter.c routemap.c distribute.c stream.c str.c log.c plist.c \ - zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c privs.c \ + zclient.c sockopt.c smux.c snmp.c md5.c if_rmap.c keychain.c privs.c \ sigevent.c pqueue.c jhash.c memtypes.c workqueue.c BUILT_SOURCES = memtypes.h route_types.h diff --git a/lib/smux.c b/lib/smux.c index 145ec90b..a5d84a8f 100644 --- a/lib/smux.c +++ b/lib/smux.c @@ -34,6 +34,45 @@ #include "sockunion.h" #include "smux.h" +#define SMUX_PORT_DEFAULT 199 + +#define SMUXMAXPKTSIZE 1500 +#define SMUXMAXSTRLEN 256 + +#define SMUX_OPEN (ASN_APPLICATION | ASN_CONSTRUCTOR | 0) +#define SMUX_CLOSE (ASN_APPLICATION | ASN_PRIMITIVE | 1) +#define SMUX_RREQ (ASN_APPLICATION | ASN_CONSTRUCTOR | 2) +#define SMUX_RRSP (ASN_APPLICATION | ASN_PRIMITIVE | 3) +#define SMUX_SOUT (ASN_APPLICATION | ASN_PRIMITIVE | 4) + +#define SMUX_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0) +#define SMUX_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1) +#define SMUX_GETRSP (ASN_CONTEXT | ASN_CONSTRUCTOR | 2) +#define SMUX_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3) +#define SMUX_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4) + +#define SMUX_MAX_FAILURE 3 + +/* SNMP tree. */ +struct subtree +{ + /* Tree's oid. */ + oid name[MAX_OID_LEN]; + u_char name_len; + + /* List of the variables. */ + struct variable *variables; + + /* Length of the variables list. */ + int variables_num; + + /* Width of the variables list. */ + int variables_width; + + /* Registered flag. */ + int registered; +}; + #define min(A,B) ((A) < (B) ? (A) : (B)) enum smux_event {SMUX_SCHEDULE, SMUX_CONNECT, SMUX_READ}; @@ -76,62 +115,6 @@ static struct cmd_node smux_node = /* thread master */ static struct thread_master *master; -void * -oid_copy (void *dest, const void *src, size_t size) -{ - return memcpy (dest, src, size * sizeof (oid)); -} - -void -oid2in_addr (oid oid[], int len, struct in_addr *addr) -{ - int i; - u_char *pnt; - - if (len == 0) - return; - - pnt = (u_char *) addr; - - for (i = 0; i < len; i++) - *pnt++ = oid[i]; -} - -void -oid_copy_addr (oid oid[], struct in_addr *addr, int len) -{ - int i; - u_char *pnt; - - if (len == 0) - return; - - pnt = (u_char *) addr; - - for (i = 0; i < len; i++) - oid[i] = *pnt++; -} - -int -oid_compare (oid *o1, int o1_len, oid *o2, int o2_len) -{ - int i; - - for (i = 0; i < min (o1_len, o2_len); i++) - { - if (o1[i] < o2[i]) - return -1; - else if (o1[i] > o2[i]) - return 1; - } - if (o1_len < o2_len) - return -1; - if (o1_len > o2_len) - return 1; - - return 0; -} - static int oid_compare_part (oid *o1, int o1_len, oid *o2, int o2_len) { @@ -473,7 +456,7 @@ smux_set (oid *reqid, size_t *reqid_len, if (write_method) { return (*write_method)(action, val, val_type, val_len, - statP, suffix, suffix_len, v); + statP, suffix, suffix_len); } else { @@ -1354,32 +1337,6 @@ smux_peer_oid (struct vty *vty, const char *oid_str, const char *passwd_str) return 0; } -int -smux_header_generic (struct variable *v, oid *name, size_t *length, int exact, - size_t *var_len, WriteMethod **write_method) -{ - oid fulloid[MAX_OID_LEN]; - int ret; - - oid_copy (fulloid, v->name, v->namelen); - fulloid[v->namelen] = 0; - /* Check against full instance. */ - ret = oid_compare (name, *length, fulloid, v->namelen + 1); - - /* Check single instance. */ - if ((exact && (ret != 0)) || (!exact && (ret >= 0))) - return MATCH_FAILED; - - /* In case of getnext, fill in full instance. */ - memcpy (name, fulloid, (v->namelen + 1) * sizeof (oid)); - *length = v->namelen + 1; - - *write_method = 0; - *var_len = sizeof(long); /* default to 'long' results */ - - return MATCH_SUCCEEDED; -} - static int smux_peer_default (void) { diff --git a/lib/smux.h b/lib/smux.h index f5754ed9..83ae56ce 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -22,24 +22,8 @@ #ifndef _ZEBRA_SNMP_H #define _ZEBRA_SNMP_H -#define SMUX_PORT_DEFAULT 199 - -#define SMUXMAXPKTSIZE 1500 -#define SMUXMAXSTRLEN 256 - -#define SMUX_OPEN (ASN_APPLICATION | ASN_CONSTRUCTOR | 0) -#define SMUX_CLOSE (ASN_APPLICATION | ASN_PRIMITIVE | 1) -#define SMUX_RREQ (ASN_APPLICATION | ASN_CONSTRUCTOR | 2) -#define SMUX_RRSP (ASN_APPLICATION | ASN_PRIMITIVE | 3) -#define SMUX_SOUT (ASN_APPLICATION | ASN_PRIMITIVE | 4) - -#define SMUX_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0) -#define SMUX_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1) -#define SMUX_GETRSP (ASN_CONTEXT | ASN_CONSTRUCTOR | 2) -#define SMUX_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3) -#define SMUX_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4) - -#define SMUX_MAX_FAILURE 3 +#include +#include /* Structures here are mostly compatible with UCD SNMP 4.1.1 */ #define MATCH_FAILED (-1) @@ -55,69 +39,12 @@ #define IN_ADDR_SIZE sizeof(struct in_addr) -struct variable; - +#undef REGISTER_MIB #define REGISTER_MIB(descr, var, vartype, theoid) \ smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \ sizeof(var)/sizeof(struct vartype), \ theoid, sizeof(theoid)/sizeof(oid)) -typedef int (WriteMethod)(int action, - u_char *var_val, - u_char var_val_type, - size_t var_val_len, - u_char *statP, - oid *name, - size_t length, - struct variable *v); - -typedef u_char *(FindVarMethod)(struct variable *v, - oid *name, - size_t *length, - int exact, - size_t *var_len, - WriteMethod **write_method); - -/* SNMP variable */ -struct variable -{ - /* Index of the MIB.*/ - u_char magic; - - /* Type of variable. */ - char type; - - /* Access control list. */ - u_short acl; - - /* Callback function. */ - FindVarMethod *findVar; - - /* Suffix of the MIB. */ - int namelen; - oid name[MAX_OID_LEN]; -}; - -/* SNMP tree. */ -struct subtree -{ - /* Tree's oid. */ - oid name[MAX_OID_LEN]; - u_char name_len; - - /* List of the variables. */ - struct variable *variables; - - /* Length of the variables list. */ - int variables_num; - - /* Width of the variables list. */ - int variables_width; - - /* Registered flag. */ - int registered; -}; - struct trap_object { FindVarMethod *findVar; @@ -145,7 +72,6 @@ struct trap_object ) extern void smux_init (struct thread_master *tm); -extern void smux_start (void); extern void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t); extern int smux_header_generic (struct variable *, oid [], size_t *, @@ -153,6 +79,7 @@ extern int smux_header_generic (struct variable *, oid [], size_t *, extern int smux_trap (const oid *, size_t, const oid *, size_t, const struct trap_object *, size_t, unsigned int, u_char); + extern int oid_compare (oid *, int, oid *, int); extern void oid2in_addr (oid [], int, struct in_addr *); extern void *oid_copy (void *, const void *, size_t); diff --git a/lib/snmp.c b/lib/snmp.c new file mode 100644 index 00000000..d7b1d953 --- /dev/null +++ b/lib/snmp.c @@ -0,0 +1,113 @@ +/* SNMP support + * Copyright (C) 1999 Kunihiro Ishiguro + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Zebra; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include + +#ifdef HAVE_SNMP +#include +#include + +#include "smux.h" + +#define min(A,B) ((A) < (B) ? (A) : (B)) + +int +oid_compare (oid *o1, int o1_len, oid *o2, int o2_len) +{ + int i; + + for (i = 0; i < min (o1_len, o2_len); i++) + { + if (o1[i] < o2[i]) + return -1; + else if (o1[i] > o2[i]) + return 1; + } + if (o1_len < o2_len) + return -1; + if (o1_len > o2_len) + return 1; + + return 0; +} + +void * +oid_copy (void *dest, const void *src, size_t size) +{ + return memcpy (dest, src, size * sizeof (oid)); +} + +void +oid2in_addr (oid oid[], int len, struct in_addr *addr) +{ + int i; + u_char *pnt; + + if (len == 0) + return; + + pnt = (u_char *) addr; + + for (i = 0; i < len; i++) + *pnt++ = oid[i]; +} + +void +oid_copy_addr (oid oid[], struct in_addr *addr, int len) +{ + int i; + u_char *pnt; + + if (len == 0) + return; + + pnt = (u_char *) addr; + + for (i = 0; i < len; i++) + oid[i] = *pnt++; +} + +int +smux_header_generic (struct variable *v, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) +{ + oid fulloid[MAX_OID_LEN]; + int ret; + + oid_copy (fulloid, v->name, v->namelen); + fulloid[v->namelen] = 0; + /* Check against full instance. */ + ret = oid_compare (name, *length, fulloid, v->namelen + 1); + + /* Check single instance. */ + if ((exact && (ret != 0)) || (!exact && (ret >= 0))) + return MATCH_FAILED; + + /* In case of getnext, fill in full instance. */ + memcpy (name, fulloid, (v->namelen + 1) * sizeof (oid)); + *length = v->namelen + 1; + + *write_method = 0; + *var_len = sizeof(long); /* default to 'long' results */ + + return MATCH_SUCCEEDED; +} +#endif /* HAVE_SNMP */ -- cgit v1.2.1 From d6be5fb9bc41ea77547204eeedd12132b26ad662 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 24 May 2012 09:44:43 +0200 Subject: agentx: add AgentX support to Quagga. --enable-snmp will enable AgentX support in Quagga. SMUX is still here and can be enabled with --enable-snmp=smux. AgentX support can be enabled with "agentx" in configuration file. As for SMUX, this command is not understood by vtysh. It can be disabled with "no agentx", though there is no real use of this since this command cannot be used with vtysh. If "agentx" and "no agentx" command were added to vtysh, it would not be possible to disable agentx support after enabling it because NetSNMP does not expose the appropriate methods for this. The internals of AgentX are hidden by NetSNMP. Therefore, we don't have a file descriptor to add to the threading system. We do not have the timers to set either. Therefore, the event loop is modified to make use of snmp_select_info() from NetSNMP. Traps are not supported yet. --- configure.ac | 18 +++++++- lib/Makefile.am | 2 +- lib/agentx.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/smux.c | 2 +- lib/thread.c | 49 +++++++++++++++++++++ 5 files changed, 200 insertions(+), 4 deletions(-) create mode 100644 lib/agentx.c diff --git a/configure.ac b/configure.ac index a2738a95..277bad55 100755 --- a/configure.ac +++ b/configure.ac @@ -222,7 +222,7 @@ AC_ARG_ENABLE(netlink, AC_ARG_ENABLE(broken-aliases, [ --enable-broken-aliases enable aliases as distinct interfaces for Linux 2.2.X]) AC_ARG_ENABLE(snmp, -[ --enable-snmp enable SNMP support]) +[ --enable-snmp=ARG enable SNMP support (smux or agentx)]) AC_ARG_WITH(libpam, [ --with-libpam use libpam for PAM support in vtysh]) AC_ARG_ENABLE(tcp-zebra, @@ -1363,7 +1363,7 @@ AC_SUBST(LIB_REGEX) dnl ------------------ dnl check Net-SNMP library dnl ------------------ -if test "${enable_snmp}" = "yes"; then +if test "${enable_snmp}" != ""; then AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], [no]) if test x"$NETSNMP_CONFIG" = x"no"; then AC_MSG_ERROR([--enable-snmp given but unable to find net-snmp-config]) @@ -1382,6 +1382,20 @@ int main(void); AC_MSG_RESULT(no) AC_MSG_ERROR([--enable-snmp given but not usable])]) AC_DEFINE(HAVE_SNMP,,SNMP) + case "${enable_snmp}" in + yes) + SNMP_METHOD=agentx + ;; + smux|agentx) + SNMP_METHOD="${enable_snmp}" + ;; + *) + AC_MSG_ERROR([--enable-snmp given with an unknown method (${enable_snmp}). Use smux or agentx]) + ;; + esac + AH_TEMPLATE([SNMP_SMUX], [Use SNMP SMUX to interface with snmpd]) + AH_TEMPLATE([SNMP_AGENTX], [Use SNMP AgentX to interface with snmpd]) + AC_DEFINE_UNQUOTED(AS_TR_CPP(SNMP_${SNMP_METHOD}),,SNMP method to interface with snmpd) fi dnl --------------------------- diff --git a/lib/Makefile.am b/lib/Makefile.am index 73417ad8..e00ad54d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -11,7 +11,7 @@ libzebra_la_SOURCES = \ checksum.c vector.c linklist.c vty.c command.c \ sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.c \ filter.c routemap.c distribute.c stream.c str.c log.c plist.c \ - zclient.c sockopt.c smux.c snmp.c md5.c if_rmap.c keychain.c privs.c \ + zclient.c sockopt.c smux.c agentx.c snmp.c md5.c if_rmap.c keychain.c privs.c \ sigevent.c pqueue.c jhash.c memtypes.c workqueue.c BUILT_SOURCES = memtypes.h route_types.h diff --git a/lib/agentx.c b/lib/agentx.c new file mode 100644 index 00000000..9cf6de5e --- /dev/null +++ b/lib/agentx.c @@ -0,0 +1,133 @@ +/* SNMP support + * Copyright (C) 2012 Vincent Bernat + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Zebra; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include + +#if defined HAVE_SNMP && defined SNMP_AGENTX +#include +#include + +#include "command.h" +#include "smux.h" + +int agentx_enabled = 0; + +/* AgentX node. */ +static struct cmd_node agentx_node = +{ + SMUX_NODE, + "" /* AgentX has no interface. */ +}; + +/* Logging NetSNMP messages */ +static int +agentx_log_callback(int major, int minor, + void *serverarg, void *clientarg) +{ + struct snmp_log_message *slm = (struct snmp_log_message *)serverarg; + char *msg = strdup (slm->msg); + if (msg) msg[strlen(msg)-1] = '\0'; + switch (slm->priority) + { + case LOG_EMERG: zlog_err ("snmp[emerg]: %s", msg?msg:slm->msg); break; + case LOG_ALERT: zlog_err ("snmp[alert]: %s", msg?msg:slm->msg); break; + case LOG_CRIT: zlog_err ("snmp[crit]: %s", msg?msg:slm->msg); break; + case LOG_ERR: zlog_err ("snmp[err]: %s", msg?msg:slm->msg); break; + case LOG_WARNING: zlog_warn ("snmp[warning]: %s", msg?msg:slm->msg); break; + case LOG_NOTICE: zlog_notice("snmp[notice]: %s", msg?msg:slm->msg); break; + case LOG_INFO: zlog_info ("snmp[info]: %s", msg?msg:slm->msg); break; + case LOG_DEBUG: zlog_debug ("snmp[debug]: %s", msg?msg:slm->msg); break; + } + free(msg); + return SNMP_ERR_NOERROR; +} + +static int +config_write_agentx (struct vty *vty) +{ + if (agentx_enabled) + vty_out (vty, "agentx%s", VTY_NEWLINE); + return 0; +} + +DEFUN (agentx_enable, + agentx_enable_cmd, + "agentx", + "SNMP AgentX protocol settings\n" + "SNMP AgentX settings\n") +{ + if (!agentx_enabled) + { + init_snmp("quagga"); + agentx_enabled = 1; + return CMD_SUCCESS; + } + vty_out (vty, "SNMP AgentX already enabled%s", VTY_NEWLINE); + return CMD_WARNING; +} + +DEFUN (no_agentx, + no_agentx_cmd, + "no agentx", + NO_STR + "SNMP AgentX protocol settings\n" + "SNMP AgentX settings\n") +{ + if (!agentx_enabled) return CMD_SUCCESS; + vty_out (vty, "SNMP AgentX support cannot be disabled once enabled%s", VTY_NEWLINE); + return CMD_WARNING; +} + +void +smux_init (struct thread_master *tm) +{ + netsnmp_enable_subagent (); + snmp_disable_log (); + snmp_enable_calllog (); + snmp_register_callback (SNMP_CALLBACK_LIBRARY, + SNMP_CALLBACK_LOGGING, + agentx_log_callback, + NULL); + init_agent ("quagga"); + + install_node (&agentx_node, config_write_agentx); + install_element (CONFIG_NODE, &agentx_enable_cmd); + install_element (CONFIG_NODE, &no_agentx_cmd); +} + +void +smux_register_mib (const char *descr, struct variable *var, + size_t width, int num, + oid name[], size_t namelen) +{ + register_mib (descr, var, width, num, name, namelen); +} + +int +smux_trap (const oid *name, size_t namelen, + const oid *iname, size_t inamelen, + const struct trap_object *trapobj, size_t trapobjlen, + unsigned int tick, u_char sptrap) +{ + return 1; +} + +#endif /* HAVE_SNMP */ diff --git a/lib/smux.c b/lib/smux.c index a5d84a8f..29370050 100644 --- a/lib/smux.c +++ b/lib/smux.c @@ -21,7 +21,7 @@ #include -#ifdef HAVE_SNMP +#if defined HAVE_SNMP && defined SNMP_SMUX #include #include diff --git a/lib/thread.c b/lib/thread.c index 86d0ff8c..6341dfd7 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -29,6 +29,16 @@ #include "hash.h" #include "command.h" #include "sigevent.h" + +#if defined HAVE_SNMP && defined SNMP_AGENTX +#include +#include +#include +#include + +extern int agentx_enabled; +#endif + /* Recent absolute time of day */ struct timeval recent_time; @@ -1030,6 +1040,11 @@ thread_fetch (struct thread_master *m, struct thread *fetch) while (1) { int num = 0; +#if defined HAVE_SNMP && defined SNMP_AGENTX + struct timeval snmp_timer_wait; + int snmpblock = 0; + int fdsetsize; +#endif /* Signals pre-empt everything */ quagga_sigevent_process (); @@ -1065,6 +1080,26 @@ thread_fetch (struct thread_master *m, struct thread *fetch) timer_wait = timer_wait_bg; } +#if defined HAVE_SNMP && defined SNMP_AGENTX + /* When SNMP is enabled, we may have to select() on additional + FD. snmp_select_info() will add them to `readfd'. The trick + with this function is its last argument. We need to set it to + 0 if timer_wait is not NULL and we need to use the provided + new timer only if it is still set to 0. */ + if (agentx_enabled) + { + fdsetsize = FD_SETSIZE; + snmpblock = 1; + if (timer_wait) + { + snmpblock = 0; + memcpy(&snmp_timer_wait, timer_wait, sizeof(struct timeval)); + } + snmp_select_info(&fdsetsize, &readfd, &snmp_timer_wait, &snmpblock); + if (snmpblock == 0) + timer_wait = &snmp_timer_wait; + } +#endif num = select (FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait); /* Signals should get quick treatment */ @@ -1076,6 +1111,20 @@ thread_fetch (struct thread_master *m, struct thread *fetch) return NULL; } +#if defined HAVE_SNMP && defined SNMP_AGENTX + if (agentx_enabled) + { + if (num > 0) + snmp_read(&readfd); + else if (num == 0) + { + snmp_timeout(); + run_alarms(); + } + netsnmp_check_outstanding_agent_requests(); + } +#endif + /* Check foreground timers. Historically, they have had higher priority than I/O threads, so let's push them onto the ready list in front of the I/O threads. */ -- cgit v1.2.1 From 4b89e45d928d41bb5d32a00ba7b402d6a3bbdf44 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 24 May 2012 21:22:01 +0200 Subject: smux: remove `tick` argument from smux_trap() smux_trap() contains an argument whose use appears to be to set sysUpTime.0/timestamp field in SNMP trap. However, this value is not used in smux_trap(). Moreover, it is expected that this field is the value of sysUpTime.0 when the trap was sent and not any other time related to the trap. To avoid any confusion, we remove this field from the signature of the function. --- bgpd/bgp_snmp.c | 4 ++-- lib/agentx.c | 2 +- lib/smux.c | 2 +- lib/smux.h | 2 +- ospfd/ospf_snmp.c | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index f6b10563..a995ff6c 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -853,7 +853,7 @@ bgpTrapEstablished (struct peer *peer) smux_trap (bgp_oid, sizeof bgp_oid / sizeof (oid), index, IN_ADDR_SIZE, bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), - bm->start_time - bgp_clock (), BGPESTABLISHED); + BGPESTABLISHED); } void @@ -872,7 +872,7 @@ bgpTrapBackwardTransition (struct peer *peer) smux_trap (bgp_oid, sizeof bgp_oid / sizeof (oid), index, IN_ADDR_SIZE, bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), - bm->start_time - bgp_clock (), BGPBACKWARDTRANSITION); + BGPBACKWARDTRANSITION); } void diff --git a/lib/agentx.c b/lib/agentx.c index 9cf6de5e..2358581f 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -125,7 +125,7 @@ int smux_trap (const oid *name, size_t namelen, const oid *iname, size_t inamelen, const struct trap_object *trapobj, size_t trapobjlen, - unsigned int tick, u_char sptrap) + u_char sptrap) { return 1; } diff --git a/lib/smux.c b/lib/smux.c index 29370050..38c7018e 100644 --- a/lib/smux.c +++ b/lib/smux.c @@ -972,7 +972,7 @@ int smux_trap (const oid *name, size_t namelen, const oid *iname, size_t inamelen, const struct trap_object *trapobj, size_t trapobjlen, - unsigned int tick, u_char sptrap) + u_char sptrap) { unsigned int i; u_char buf[BUFSIZ]; diff --git a/lib/smux.h b/lib/smux.h index 83ae56ce..78460e68 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -78,7 +78,7 @@ extern int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, WriteMethod **); extern int smux_trap (const oid *, size_t, const oid *, size_t, const struct trap_object *, - size_t, unsigned int, u_char); + size_t, u_char); extern int oid_compare (oid *, int, oid *, int); extern void oid2in_addr (oid [], int, struct in_addr *); diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index 739dcae1..409153b8 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -2616,7 +2616,7 @@ ospfTrapNbrStateChange (struct ospf_neighbor *on) index, IN_ADDR_SIZE + 1, ospfNbrTrapList, sizeof ospfNbrTrapList / sizeof (struct trap_object), - time (NULL), NBRSTATECHANGE); + NBRSTATECHANGE); } void @@ -2633,7 +2633,7 @@ ospfTrapVirtNbrStateChange (struct ospf_neighbor *on) index, IN_ADDR_SIZE + 1, ospfVirtNbrTrapList, sizeof ospfVirtNbrTrapList / sizeof (struct trap_object), - time (NULL), VIRTNBRSTATECHANGE); + VIRTNBRSTATECHANGE); } void @@ -2652,7 +2652,7 @@ ospfTrapIfStateChange (struct ospf_interface *oi) index, IN_ADDR_SIZE + 1, ospfIfTrapList, sizeof ospfIfTrapList / sizeof (struct trap_object), - time (NULL), IFSTATECHANGE); + IFSTATECHANGE); } void @@ -2669,7 +2669,7 @@ ospfTrapVirtIfStateChange (struct ospf_interface *oi) index, IN_ADDR_SIZE + 1, ospfVirtIfTrapList, sizeof ospfVirtIfTrapList / sizeof (struct trap_object), - time (NULL), VIRTIFSTATECHANGE); + VIRTIFSTATECHANGE); } /* Register OSPF2-MIB. */ void -- cgit v1.2.1 From b8cf46b715b2c21db5dce8118c70b4dd9b5255a3 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 25 May 2012 08:56:44 +0200 Subject: smux: drop findVar element from trap object struct This element was not unused. --- bgpd/bgp_snmp.c | 4 ++-- lib/smux.h | 3 +-- ospfd/ospf_snmp.c | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index a995ff6c..73406d59 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -833,8 +833,8 @@ bgp4PathAttrTable (struct variable *v, oid name[], size_t *length, /* BGP Traps. */ struct trap_object bgpTrapList[] = { - {bgpPeerTable, 3, {3, 1, BGPPEERLASTERROR}}, - {bgpPeerTable, 3, {3, 1, BGPPEERSTATE}} + {3, {3, 1, BGPPEERLASTERROR}}, + {3, {3, 1, BGPPEERSTATE}} }; void diff --git a/lib/smux.h b/lib/smux.h index 78460e68..b7d5096e 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -47,8 +47,7 @@ struct trap_object { - FindVarMethod *findVar; - int namelen; + int namelen; /* Negative if the object is not indexed */ oid name[MAX_OID_LEN]; }; diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index 409153b8..b2d56860 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -2568,35 +2568,35 @@ ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length, struct trap_object ospfNbrTrapList[] = { - {ospfGeneralGroup, -2, {1, OSPFROUTERID}}, - {ospfNbrEntry, 3, {10, 1, OSPFNBRIPADDR}}, - {ospfNbrEntry, 3, {10, 1, OSPFNBRRTRID}}, - {ospfNbrEntry, 3, {10, 1, OSPFNBRSTATE}} + {-2, {1, OSPFROUTERID}}, + {3, {10, 1, OSPFNBRIPADDR}}, + {3, {10, 1, OSPFNBRRTRID}}, + {3, {10, 1, OSPFNBRSTATE}} }; struct trap_object ospfVirtNbrTrapList[] = { - {ospfGeneralGroup, -2, {1, 1}}, - {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRAREA}}, - {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRRTRID}}, - {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRSTATE}} + {-2, {1, 1}}, + {3, {11, 1, OSPFVIRTNBRAREA}}, + {3, {11, 1, OSPFVIRTNBRRTRID}}, + {3, {11, 1, OSPFVIRTNBRSTATE}} }; struct trap_object ospfIfTrapList[] = { - {ospfGeneralGroup, -2, {1, OSPFROUTERID}}, - {ospfIfEntry, 3, {7, 1, OSPFIFIPADDRESS}}, - {ospfIfEntry, 3, {7, 1, OSPFADDRESSLESSIF}}, - {ospfIfEntry, 3, {7, 1, OSPFIFSTATE}} + {-2, {1, OSPFROUTERID}}, + {3, {7, 1, OSPFIFIPADDRESS}}, + {3, {7, 1, OSPFADDRESSLESSIF}}, + {3, {7, 1, OSPFIFSTATE}} }; struct trap_object ospfVirtIfTrapList[] = { - {ospfGeneralGroup, -2, {1, OSPFROUTERID}}, - {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFAREAID}}, - {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFNEIGHBOR}}, - {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFSTATE}} + {-2, {1, OSPFROUTERID}}, + {3, {9, 1, OSPFVIRTIFAREAID}}, + {3, {9, 1, OSPFVIRTIFNEIGHBOR}}, + {3, {9, 1, OSPFVIRTIFSTATE}} }; void -- cgit v1.2.1 From b7c0d0651cd64f644d02ef5e4d1b82febe7e57d8 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 25 May 2012 11:17:01 +0200 Subject: agentx: handle SNMP traps smux_trap() signature has been changed to provide appropriate level information to send SNMPv2 notifications. This includes the addition of the enterprise OID to use (from which is derived the SNMP trap OID) and the MIB registry to locate the appropriate function for variable bindings provided by the trap. The SMUX implementation has been updated but ignore the provided enterprise OID. Instead, it still uses the SMUX peer OID to keep compatibility with previous versions of Quagga. The SMUX implementation also ignores the provided MIB registry since it uses smux_get() function to grab the appropriate values. This is not possible with the AgentX implementation since there is no such function provided by NetSNMP. --- bgpd/bgp_snmp.c | 9 ++++-- lib/agentx.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- lib/smux.c | 9 +++++- lib/smux.h | 31 +++++++++++++++++++-- ospfd/ospf_snmp.c | 17 +++++++++--- 5 files changed, 137 insertions(+), 11 deletions(-) diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index 73406d59..36fd4ef4 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -118,6 +118,7 @@ SNMP_LOCAL_VARIABLES /* BGP-MIB instances. */ oid bgp_oid [] = { BGP4MIB }; +oid bgp_trap_oid [] = { BGP4MIB, 0 }; /* IP address 0.0.0.0. */ static struct in_addr bgp_empty_addr = {0}; @@ -850,7 +851,9 @@ bgpTrapEstablished (struct peer *peer) oid_copy_addr (index, &addr, IN_ADDR_SIZE); - smux_trap (bgp_oid, sizeof bgp_oid / sizeof (oid), + smux_trap (bgp_variables, sizeof bgp_variables / sizeof (struct variable), + bgp_trap_oid, sizeof bgp_trap_oid / sizeof (oid), + bgp_oid, sizeof bgp_oid / sizeof (oid), index, IN_ADDR_SIZE, bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), BGPESTABLISHED); @@ -869,7 +872,9 @@ bgpTrapBackwardTransition (struct peer *peer) oid_copy_addr (index, &addr, IN_ADDR_SIZE); - smux_trap (bgp_oid, sizeof bgp_oid / sizeof (oid), + smux_trap (bgp_variables, sizeof bgp_variables / sizeof (struct variable), + bgp_trap_oid, sizeof bgp_trap_oid / sizeof (oid), + bgp_oid, sizeof bgp_oid / sizeof (oid), index, IN_ADDR_SIZE, bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), BGPBACKWARDTRANSITION); diff --git a/lib/agentx.c b/lib/agentx.c index 2358581f..be6b4320 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -122,11 +122,91 @@ smux_register_mib (const char *descr, struct variable *var, } int -smux_trap (const oid *name, size_t namelen, +smux_trap (struct variable *vp, size_t vp_len, + const oid *ename, size_t enamelen, + const oid *name, size_t namelen, const oid *iname, size_t inamelen, const struct trap_object *trapobj, size_t trapobjlen, u_char sptrap) { + oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; + size_t objid_snmptrap_len = sizeof objid_snmptrap / sizeof (oid); + oid notification_oid[MAX_OID_LEN]; + size_t notification_oid_len; + unsigned int i; + + netsnmp_variable_list *notification_vars = NULL; + if (!agentx_enabled) return 0; + + /* snmpTrapOID */ + oid_copy (notification_oid, ename, enamelen); + notification_oid[enamelen] = sptrap; + notification_oid_len = enamelen + 1; + snmp_varlist_add_variable (¬ification_vars, + objid_snmptrap, objid_snmptrap_len, + ASN_OBJECT_ID, + (u_char *) notification_oid, + notification_oid_len * sizeof(oid)); + + /* Provided bindings */ + for (i = 0; i < trapobjlen; i++) + { + unsigned int j; + oid oid[MAX_OID_LEN]; + size_t oid_len, onamelen; + u_char *val; + size_t val_len; + WriteMethod *wm = NULL; + struct variable cvp; + + /* Make OID. */ + if (trapobj[i].namelen > 0) + { + /* Columnar object */ + onamelen = trapobj[i].namelen; + oid_copy (oid, name, namelen); + oid_copy (oid + namelen, trapobj[i].name, onamelen); + oid_copy (oid + namelen + onamelen, iname, inamelen); + oid_len = namelen + onamelen + inamelen; + } + else + { + /* Scalar object */ + onamelen = trapobj[i].namelen * (-1); + oid_copy (oid, name, namelen); + oid_copy (oid + namelen, trapobj[i].name, onamelen); + oid[onamelen + namelen] = 0; + oid_len = namelen + onamelen + 1; + } + + /* Locate the appropriate function and type in the MIB registry. */ + for (j = 0; j < vp_len; j++) + { + if (oid_compare (trapobj[i].name, onamelen, vp[j].name, vp[j].namelen) != 0) + continue; + /* We found the appropriate variable in the MIB registry. */ + oid_copy(cvp.name, name, namelen); + oid_copy(cvp.name + namelen, vp[j].name, vp[j].namelen); + cvp.namelen = namelen + vp[j].namelen; + cvp.type = vp[j].type; + cvp.magic = vp[j].magic; + cvp.acl = vp[j].acl; + cvp.findVar = vp[j].findVar; + /* Grab the result. */ + val = cvp.findVar (&cvp, oid, &oid_len, 1, &val_len, &wm); + if (!val) break; + snmp_varlist_add_variable (¬ification_vars, + oid, oid_len, + vp[j].type, + val, + val_len); + break; + } + } + + + send_v2trap (notification_vars); + snmp_free_varbind (notification_vars); return 1; } diff --git a/lib/smux.c b/lib/smux.c index 38c7018e..07466400 100644 --- a/lib/smux.c +++ b/lib/smux.c @@ -968,8 +968,15 @@ smux_open (int sock) return send (sock, buf, (ptr - buf), 0); } +/* `ename` is ignored. Instead of using the provided enterprise OID, + the SMUX peer is used. This keep compatibility with the previous + versions of Quagga. + + All other fields are used as they are intended. */ int -smux_trap (const oid *name, size_t namelen, +smux_trap (struct variable *vp, size_t vp_len, + const oid *ename, size_t enamelen, + const oid *name, size_t namelen, const oid *iname, size_t inamelen, const struct trap_object *trapobj, size_t trapobjlen, u_char sptrap) diff --git a/lib/smux.h b/lib/smux.h index b7d5096e..b29fdc72 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -75,9 +75,34 @@ extern void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t); extern int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, WriteMethod **); -extern int smux_trap (const oid *, size_t, const oid *, size_t, - const struct trap_object *, - size_t, u_char); + +/* For traps, three OID are provided: + + 1. The enterprise OID to use (the last argument will be appended to + it to form the SNMP trap OID) + + 2. The base OID for objects to be sent in traps. + + 3. The index OID for objects to be sent in traps. This index is used + to designate a particular instance of a column. + + The provided trap object contains the bindings to be sent with the + trap. The base OID will be prefixed to the provided OID and, if the + length is positive, the requested OID is assumed to be a columnar + object and the index OID will be appended. + + The two first arguments are the MIB registry used to locate the trap + objects. + + The use of the arguments may differ depending on the implementation + used. +*/ +extern int smux_trap (struct variable *, size_t, + const oid *, size_t, + const oid *, size_t, + const oid *, size_t, + const struct trap_object *, size_t, + u_char); extern int oid_compare (oid *, int, oid *, int); extern void oid2in_addr (oid [], int, struct in_addr *); diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index b2d56860..c8416de6 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -210,6 +210,7 @@ SNMP_LOCAL_VARIABLES /* OSPF-MIB instances. */ oid ospf_oid [] = { OSPF2MIB }; +oid ospf_trap_oid [] = { OSPF2MIB, 16, 2 }; /* Not reverse mappable! */ /* IP address 0.0.0.0. */ static struct in_addr ospf_empty_addr = {0}; @@ -2612,7 +2613,9 @@ ospfTrapNbrStateChange (struct ospf_neighbor *on) oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE); index[IN_ADDR_SIZE] = 0; - smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid), + smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable), + ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid), + ospf_oid, sizeof ospf_oid / sizeof (oid), index, IN_ADDR_SIZE + 1, ospfNbrTrapList, sizeof ospfNbrTrapList / sizeof (struct trap_object), @@ -2629,7 +2632,9 @@ ospfTrapVirtNbrStateChange (struct ospf_neighbor *on) oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE); index[IN_ADDR_SIZE] = 0; - smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid), + smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable), + ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid), + ospf_oid, sizeof ospf_oid / sizeof (oid), index, IN_ADDR_SIZE + 1, ospfVirtNbrTrapList, sizeof ospfVirtNbrTrapList / sizeof (struct trap_object), @@ -2648,7 +2653,9 @@ ospfTrapIfStateChange (struct ospf_interface *oi) oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE); index[IN_ADDR_SIZE] = 0; - smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid), + smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable), + ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid), + ospf_oid, sizeof ospf_oid / sizeof (oid), index, IN_ADDR_SIZE + 1, ospfIfTrapList, sizeof ospfIfTrapList / sizeof (struct trap_object), @@ -2665,7 +2672,9 @@ ospfTrapVirtIfStateChange (struct ospf_interface *oi) oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE); index[IN_ADDR_SIZE] = 0; - smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid), + smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable), + ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid), + ospf_oid, sizeof ospf_oid / sizeof (oid), index, IN_ADDR_SIZE + 1, ospfVirtIfTrapList, sizeof ospfVirtIfTrapList / sizeof (struct trap_object), -- cgit v1.2.1 From 0ff4b9c96793898429052de576d8da368e48997e Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 25 May 2012 12:04:51 +0200 Subject: agentx: add appropriate documentation --- doc/overview.texi | 5 +++- doc/snmp.texi | 89 ++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 83 insertions(+), 11 deletions(-) diff --git a/doc/overview.texi b/doc/overview.texi index 435834b7..7acfc0e9 100644 --- a/doc/overview.texi +++ b/doc/overview.texi @@ -7,7 +7,7 @@ provides TCP/IP based routing services with routing protocols support such as RIPv1, RIPv2, RIPng, OSPFv2, OSPFv3, BGP-4, and BGP-4+ (@pxref{Supported RFCs}). Quagga also supports special BGP Route Reflector and Route Server behavior. In addition to traditional IPv4 routing protocols, Quagga also -supports IPv6 routing protocols. With SNMP daemon which supports SMUX +supports IPv6 routing protocols. With SNMP daemon which supports SMUX and AgentX protocol, Quagga provides routing protocol MIBs (@pxref{SNMP Support}). Quagga uses an advanced software architecture to provide you with a high @@ -238,6 +238,9 @@ J. Chu, Editor. July 1994.} @cite{OSPF Version 2 Management Information Base. F. Baker, R. Coltun. November 1995.} +@item @asis{RFC2741} +@cite{Agent Extensibility (AgentX) Protocol. M. Daniele, B. Wijnen. January 2000.} + @end table @node How to get Quagga diff --git a/doc/snmp.texi b/doc/snmp.texi index 3f80cc58..0918a462 100644 --- a/doc/snmp.texi +++ b/doc/snmp.texi @@ -5,11 +5,12 @@ feature for collecting network information from router and/or host. Quagga itself does not support SNMP agent (server daemon) functionality but is able to connect to a SNMP agent using the SMUX protocol -(@cite{RFC1227}) and make the routing protocol MIBs available through -it. +(@cite{RFC1227}) or the AgentX protocol (@cite{RFC2741}) and make the +routing protocol MIBs available through it. @menu * Getting and installing an SNMP agent:: +* AgentX configuration:: * SMUX configuration:: * MIB and command reference:: * Handling SNMP Traps:: @@ -18,20 +19,82 @@ it. @node Getting and installing an SNMP agent @section Getting and installing an SNMP agent -There are several SNMP agent which support SMUX. We recommend to use the latest +There are several SNMP agent which support SMUX or AgentX. We recommend to use the latest version of @code{net-snmp} which was formerly known as @code{ucd-snmp}. It is free and open software and available at @uref{http://www.net-snmp.org/} and as binary package for most Linux distributions. -@code{net-snmp} has to be compiled with @code{--with-mib-modules=smux} to -be able to accept connections from Quagga. +@code{net-snmp} has to be compiled with @code{--with-mib-modules=agentx} to +be able to accept connections from Quagga using AgentX protocol or with +@code{--with-mib-modules=smux} to use SMUX protocol. + +Nowadays, SMUX is a legacy protocol. The AgentX protocol should be +preferred for any new deployment. Both protocols have the same coverage. + +@node AgentX configuration +@section AgentX configuration + +To enable AgentX protocol support, Quagga must have been build with the +@code{--enable-snmp} or @code{--enable-snmp=agentx} option. Both the +master SNMP agent (snmpd) and each of the Quagga daemons must be +configured. In @code{/etc/snmp/snmpd.conf}, @code{master agentx} +directive should be added. In each of the Quagga daemons, @code{agentx} +command will enable AgentX support. + +@example +/etc/snmp/snmpd.conf: + # + # example access restrictions setup + # + com2sec readonly default public + group MyROGroup v1 readonly + view all included .1 80 + access MyROGroup "" any noauth exact all none none + # + # enable master agent for AgentX subagents + # + master agentx + +/etc/quagga/ospfd.conf: + ! ... the rest of ospfd.conf has been omitted for clarity ... + ! + agentx + ! +@end example + +Upon successful connection, you should get something like this in the +log of each Quagga daemons: + +@example +2012/05/25 11:39:08 ZEBRA: snmp[info]: NET-SNMP version 5.4.3 AgentX subagent connected +@end example + +Then, you can use the following command to check everything works as expected: + +@example +# snmpwalk -c public -v1 localhost .1.3.6.1.2.1.14.1.1 +OSPF-MIB::ospfRouterId.0 = IpAddress: 192.168.42.109 +[...] +@end example + +The AgentX protocol can be transported over a Unix socket or using TCP +or UDP. It usually defaults to a Unix socket and depends on how NetSNMP +was built. If need to configure Quagga to use another transport, you can +configure it through @code{/etc/snmp/quagga.conf}: + +@example +/etc/snmp/quagga.conf: + [snmpd] + # Use a remote master agent + agentXSocket tcp:192.168.15.12:705 +@end example @node SMUX configuration @section SMUX configuration To enable SMUX protocol support, Quagga must have been build with the -@code{--enable-snmp} option. +@code{--enable-snmp=smux} option. -A separate connection has then to be established between between the +A separate connection has then to be established between the SNMP agent (snmpd) and each of the Quagga daemons. This connections each use different OID numbers and passwords. Be aware that this OID number is not the one that is used in queries by clients, it is solely @@ -85,7 +148,7 @@ troublesome @code{snmp_log()} line in the function @section MIB and command reference The following OID numbers are used for the interprocess communication of snmpd and -the Quagga daemons. Sadly, SNMP has not been implemented in all daemons yet. +the Quagga daemons with SMUX only. @example (OIDs below .iso.org.dod.internet.private.enterprises) zebra .1.3.6.1.4.1.3317.1.2.1 .gnome.gnomeProducts.zebra.zserv @@ -95,7 +158,8 @@ ospfd .1.3.6.1.4.1.3317.1.2.5 .gnome.gnomeProducts.zebra.ospfd ospf6d .1.3.6.1.4.1.3317.1.2.6 .gnome.gnomeProducts.zebra.ospf6d @end example -The following OID numbers are used for querying the SNMP daemon by a client: +Sadly, SNMP has not been implemented in all daemons yet. The following +OID numbers are used for querying the SNMP daemon by a client: @example zebra .1.3.6.1.2.1.4.24 .iso.org.dot.internet.mgmt.mib-2.ip.ipForward ospfd .1.3.6.1.2.1.14 .iso.org.dot.internet.mgmt.mib-2.ospf @@ -104,7 +168,7 @@ ripd .1.3.6.1.2.1.23 .iso.org.dot.internet.mgmt.mib-2.rip2 ospf6d .1.3.6.1.3.102 .iso.org.dod.internet.experimental.ospfv3 @end example -The following syntax is understood by the Quagga daemons for configuring SNMP: +The following syntax is understood by the Quagga daemons for configuring SNMP using SMUX: @deffn {Command} {smux peer @var{oid}} {} @deffnx {Command} {no smux peer @var{oid}} {} @end deffn @@ -113,4 +177,9 @@ The following syntax is understood by the Quagga daemons for configuring SNMP: @deffnx {Command} {no smux peer @var{oid} @var{password}} {} @end deffn +Here is the syntax for using AgentX: +@deffn {Command} {agentx} {} +@deffnx {Command} {no agentx} {} +@end deffn + @include snmptrap.texi -- cgit v1.2.1 From 8046ba6ec4d6e87bf8da6563c0f3e5e66c4652b3 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 31 May 2012 13:30:28 +0200 Subject: snmp: let handlers accept OID from a lesser prefix Most table handlers do not expect to be given an OID whose prefix is outside what they can handle. This is not a problem with the SMUX implementation since it always correct the OID such that the prefix matches. However, this is not the case for the AgentX implementation. A new function, smux_header_table() is used to do this normalization. --- bgpd/bgp_snmp.c | 7 ++++++- lib/smux.h | 2 ++ lib/snmp.c | 20 ++++++++++++++++++++ ospf6d/ospf6_snmp.c | 8 ++++++++ ospfd/ospf_snmp.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ ripd/rip_snmp.c | 12 ++++++++++++ zebra/zebra_snmp.c | 8 ++++++++ 7 files changed, 104 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index 36fd4ef4..c8f2aa54 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -455,7 +455,9 @@ bgpPeerTable (struct variable *v, oid name[], size_t *length, static struct in_addr addr; struct peer *peer; - *write_method = NULL; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; memset (&addr, 0, sizeof (struct in_addr)); peer = bgpPeerTable_lookup (v, name, length, &addr, exact); @@ -765,6 +767,9 @@ bgp4PathAttrTable (struct variable *v, oid name[], size_t *length, if (! bgp) return NULL; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; memset (&addr, 0, sizeof (struct prefix_ipv4)); binfo = bgp4PathAttrLookup (v, name, length, bgp, &addr, exact); diff --git a/lib/smux.h b/lib/smux.h index b29fdc72..72b4eaf0 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -75,6 +75,8 @@ extern void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t); extern int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, WriteMethod **); +extern int smux_header_table (struct variable *, oid *, size_t *, + int, size_t *, WriteMethod **); /* For traps, three OID are provided: diff --git a/lib/snmp.c b/lib/snmp.c index d7b1d953..79595a1e 100644 --- a/lib/snmp.c +++ b/lib/snmp.c @@ -110,4 +110,24 @@ smux_header_generic (struct variable *v, oid *name, size_t *length, int exact, return MATCH_SUCCEEDED; } + +int +smux_header_table (struct variable *v, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) +{ + /* If the requested OID name is less than OID prefix we + handle, adjust it to our prefix. */ + if ((oid_compare (name, *length, v->name, v->namelen)) < 0) + { + if (exact) + return MATCH_FAILED; + oid_copy(name, v->name, v->namelen); + *length = v->namelen; + } + + *write_method = 0; + *var_len = sizeof(long); + + return MATCH_SUCCEEDED; +} #endif /* HAVE_SNMP */ diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 11b733b8..d252f549 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -306,6 +306,10 @@ ospfv3AreaEntry (struct variable *v, oid *name, size_t *length, if (ospf6 == NULL) return NULL; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + len = *length - v->namelen; len = (len >= sizeof (u_int32_t) ? sizeof (u_int32_t) : 0); if (exact && len != sizeof (u_int32_t)) @@ -372,6 +376,10 @@ ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length, struct ospf6_area *oa; struct listnode *node; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&area_id, 0, sizeof (struct in_addr)); type = 0; memset (&id, 0, sizeof (struct in_addr)); diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index c8416de6..1daf0d6a 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -704,6 +704,10 @@ ospfAreaEntry (struct variable *v, oid *name, size_t *length, int exact, struct ospf_area *area; struct in_addr addr; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&addr, 0, sizeof (struct in_addr)); area = ospfAreaLookup (v, name, length, &addr, exact); @@ -847,6 +851,10 @@ ospfStubAreaEntry (struct variable *v, oid *name, size_t *length, struct ospf_area *area; struct in_addr addr; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&addr, 0, sizeof (struct in_addr)); area = ospfStubAreaLookup (v, name, length, &addr, exact); @@ -1078,6 +1086,10 @@ ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact, struct in_addr router_id; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + /* INDEX { ospfLsdbAreaId, ospfLsdbType, ospfLsdbLsid, ospfLsdbRouterId } */ @@ -1240,6 +1252,10 @@ ospfAreaRangeEntry (struct variable *v, oid *name, size_t *length, int exact, struct in_addr mask; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + /* Check OSPF instance. */ ospf = ospf_lookup (); if (ospf == NULL) @@ -1344,6 +1360,10 @@ ospfHostEntry (struct variable *v, oid *name, size_t *length, int exact, struct in_addr addr; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + /* Check OSPF instance. */ ospf = ospf_lookup (); if (ospf == NULL) @@ -1679,6 +1699,10 @@ ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact, struct ospf_interface *oi; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + ifindex = 0; memset (&ifaddr, 0, sizeof (struct in_addr)); @@ -1847,6 +1871,10 @@ ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact, struct ospf_interface *oi; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + ifindex = 0; memset (&ifaddr, 0, sizeof (struct in_addr)); @@ -2039,6 +2067,10 @@ ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact, struct in_addr area_id; struct in_addr neighbor; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&area_id, 0, sizeof (struct in_addr)); memset (&neighbor, 0, sizeof (struct in_addr)); @@ -2272,6 +2304,10 @@ ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact, struct ospf_neighbor *nbr; struct ospf_interface *oi; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&nbr_addr, 0, sizeof (struct in_addr)); ifindex = 0; @@ -2334,6 +2370,10 @@ ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact, struct in_addr neighbor; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&area_id, 0, sizeof (struct in_addr)); memset (&neighbor, 0, sizeof (struct in_addr)); @@ -2482,6 +2522,10 @@ ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact, struct in_addr router_id; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + type = OSPF_AS_EXTERNAL_LSA; memset (&ls_id, 0, sizeof (struct in_addr)); memset (&router_id, 0, sizeof (struct in_addr)); @@ -2533,6 +2577,10 @@ static u_char * ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + /* Return the current value of the variable */ switch (v->magic) { diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c index 803ac856..090ebfae 100644 --- a/ripd/rip_snmp.c +++ b/ripd/rip_snmp.c @@ -345,6 +345,10 @@ rip2IfStatEntry (struct variable *v, oid name[], size_t *length, static struct in_addr addr; static long valid = SNMP_VALID; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&addr, 0, sizeof (struct in_addr)); /* Lookup interface. */ @@ -448,6 +452,10 @@ rip2IfConfAddress (struct variable *v, oid name[], size_t *length, struct interface *ifp; struct rip_interface *ri; + if (smux_header_table(v, name, length, exact, val_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&addr, 0, sizeof (struct in_addr)); /* Lookup interface. */ @@ -518,6 +526,10 @@ rip2PeerTable (struct variable *v, oid name[], size_t *length, struct rip_peer *peer; + if (smux_header_table(v, name, length, exact, val_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&addr, 0, sizeof (struct in_addr)); /* Lookup interface. */ diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c index 3dbfb587..f52bbcb8 100644 --- a/zebra/zebra_snmp.c +++ b/zebra/zebra_snmp.c @@ -451,6 +451,10 @@ ipFwTable (struct variable *v, oid objid[], size_t *objid_len, static struct in_addr netmask; struct nexthop *nexthop; + if (smux_header_table(v, objid, objid_len, exact, val_len, write_method) + == MATCH_FAILED) + return NULL; + get_fwtable_route_node(v, objid, objid_len, exact, &np, &rib); if (!np) return NULL; @@ -549,6 +553,10 @@ static u_char * ipCidrTable (struct variable *v, oid objid[], size_t *objid_len, int exact, size_t *val_len, WriteMethod **write_method) { + if (smux_header_table(v, objid, objid_len, exact, val_len, write_method) + == MATCH_FAILED) + return NULL; + switch (v->magic) { case IPCIDRROUTEDEST: -- cgit v1.2.1