mirror of
https://github.com/FRRouting/frr.git
synced 2025-04-30 13:37:17 +02:00
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.
This commit is contained in:
parent
3a4c96885e
commit
d6be5fb9bc
18
configure.ac
18
configure.ac
|
@ -222,7 +222,7 @@ AC_ARG_ENABLE(netlink,
|
||||||
AC_ARG_ENABLE(broken-aliases,
|
AC_ARG_ENABLE(broken-aliases,
|
||||||
[ --enable-broken-aliases enable aliases as distinct interfaces for Linux 2.2.X])
|
[ --enable-broken-aliases enable aliases as distinct interfaces for Linux 2.2.X])
|
||||||
AC_ARG_ENABLE(snmp,
|
AC_ARG_ENABLE(snmp,
|
||||||
[ --enable-snmp enable SNMP support])
|
[ --enable-snmp=ARG enable SNMP support (smux or agentx)])
|
||||||
AC_ARG_WITH(libpam,
|
AC_ARG_WITH(libpam,
|
||||||
[ --with-libpam use libpam for PAM support in vtysh])
|
[ --with-libpam use libpam for PAM support in vtysh])
|
||||||
AC_ARG_ENABLE(tcp-zebra,
|
AC_ARG_ENABLE(tcp-zebra,
|
||||||
|
@ -1363,7 +1363,7 @@ AC_SUBST(LIB_REGEX)
|
||||||
dnl ------------------
|
dnl ------------------
|
||||||
dnl check Net-SNMP library
|
dnl check Net-SNMP library
|
||||||
dnl ------------------
|
dnl ------------------
|
||||||
if test "${enable_snmp}" = "yes"; then
|
if test "${enable_snmp}" != ""; then
|
||||||
AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], [no])
|
AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], [no])
|
||||||
if test x"$NETSNMP_CONFIG" = x"no"; then
|
if test x"$NETSNMP_CONFIG" = x"no"; then
|
||||||
AC_MSG_ERROR([--enable-snmp given but unable to find net-snmp-config])
|
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_RESULT(no)
|
||||||
AC_MSG_ERROR([--enable-snmp given but not usable])])
|
AC_MSG_ERROR([--enable-snmp given but not usable])])
|
||||||
AC_DEFINE(HAVE_SNMP,,SNMP)
|
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
|
fi
|
||||||
|
|
||||||
dnl ---------------------------
|
dnl ---------------------------
|
||||||
|
|
|
@ -11,7 +11,7 @@ libzebra_la_SOURCES = \
|
||||||
checksum.c vector.c linklist.c vty.c command.c \
|
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 \
|
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 \
|
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
|
sigevent.c pqueue.c jhash.c memtypes.c workqueue.c
|
||||||
|
|
||||||
BUILT_SOURCES = memtypes.h route_types.h
|
BUILT_SOURCES = memtypes.h route_types.h
|
||||||
|
|
133
lib/agentx.c
Normal file
133
lib/agentx.c
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
/* SNMP support
|
||||||
|
* Copyright (C) 2012 Vincent Bernat <bernat@luffy.cx>
|
||||||
|
*
|
||||||
|
* 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 <zebra.h>
|
||||||
|
|
||||||
|
#if defined HAVE_SNMP && defined SNMP_AGENTX
|
||||||
|
#include <net-snmp/net-snmp-config.h>
|
||||||
|
#include <net-snmp/net-snmp-includes.h>
|
||||||
|
|
||||||
|
#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 */
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include <zebra.h>
|
#include <zebra.h>
|
||||||
|
|
||||||
#ifdef HAVE_SNMP
|
#if defined HAVE_SNMP && defined SNMP_SMUX
|
||||||
#include <net-snmp/net-snmp-config.h>
|
#include <net-snmp/net-snmp-config.h>
|
||||||
#include <net-snmp/net-snmp-includes.h>
|
#include <net-snmp/net-snmp-includes.h>
|
||||||
|
|
||||||
|
|
49
lib/thread.c
49
lib/thread.c
|
@ -29,6 +29,16 @@
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "sigevent.h"
|
#include "sigevent.h"
|
||||||
|
|
||||||
|
#if defined HAVE_SNMP && defined SNMP_AGENTX
|
||||||
|
#include <net-snmp/net-snmp-config.h>
|
||||||
|
#include <net-snmp/net-snmp-includes.h>
|
||||||
|
#include <net-snmp/agent/net-snmp-agent-includes.h>
|
||||||
|
#include <net-snmp/agent/snmp_vars.h>
|
||||||
|
|
||||||
|
extern int agentx_enabled;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Recent absolute time of day */
|
/* Recent absolute time of day */
|
||||||
struct timeval recent_time;
|
struct timeval recent_time;
|
||||||
|
@ -1030,6 +1040,11 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int num = 0;
|
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 */
|
/* Signals pre-empt everything */
|
||||||
quagga_sigevent_process ();
|
quagga_sigevent_process ();
|
||||||
|
@ -1065,6 +1080,26 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
|
||||||
timer_wait = timer_wait_bg;
|
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);
|
num = select (FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait);
|
||||||
|
|
||||||
/* Signals should get quick treatment */
|
/* Signals should get quick treatment */
|
||||||
|
@ -1076,6 +1111,20 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
|
||||||
return NULL;
|
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
|
/* Check foreground timers. Historically, they have had higher
|
||||||
priority than I/O threads, so let's push them onto the ready
|
priority than I/O threads, so let's push them onto the ready
|
||||||
list in front of the I/O threads. */
|
list in front of the I/O threads. */
|
||||||
|
|
Loading…
Reference in a new issue