Skip to content

Commit

Permalink
*: Modify agentx to be allowed to be called
Browse files Browse the repository at this point in the history
If you had a situation where an operator turned on
ospfd with snmp but not ospf6d and agentx was configured
then you get into a situation where ospf6d would complain
that the config for agentx did not exist.  Let's modify
the code to allow this situation to happen.

Fixes: FRRouting#15896
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed May 9, 2024
1 parent 8ac0a1d commit 300ca69
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 35 deletions.
3 changes: 3 additions & 0 deletions bgpd/bgp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "bfd.h"
#include "libfrr.h"
#include "ns.h"
#include "libagentx.h"

#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h"
Expand Down Expand Up @@ -516,8 +517,10 @@ int main(int argc, char **argv)
bgp_option_set(BGP_OPT_NO_ZEBRA);
bgp_error_init();
/* Initializations. */
libagentx_init();
bgp_vrf_init();


#ifdef HAVE_SCRIPTING
bgp_script_init();
#endif
Expand Down
3 changes: 3 additions & 0 deletions eigrpd/eigrp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "distribute.h"
#include "libfrr.h"
#include "routemap.h"
#include "libagentx.h"
//#include "if_rmap.h"

#include "eigrpd/eigrp_structs.h"
Expand Down Expand Up @@ -178,6 +179,8 @@ int main(int argc, char **argv, char **envp)

/* EIGRP master init. */
eigrp_master_init();
libagentx_init();

eigrp_om->master = frr_init();
master = eigrp_om->master;

Expand Down
2 changes: 2 additions & 0 deletions isisd/isis_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "libfrr.h"
#include "routemap.h"
#include "affinitymap.h"
#include "libagentx.h"

#include "isisd/isis_affinitymap.h"
#include "isisd/isis_constants.h"
Expand Down Expand Up @@ -307,6 +308,7 @@ int main(int argc, char **argv, char **envp)
/*
* initializations
*/
libagentx_init();
cmd_init_config_callbacks(isis_config_start, isis_config_end);
isis_error_init();
access_list_init();
Expand Down
2 changes: 2 additions & 0 deletions ldpd/ldpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "libfrr.h"
#include "lib_errors.h"
#include "zlog_recirculate.h"
#include "libagentx.h"

static void ldpd_shutdown(void);
static pid_t start_child(enum ldpd_process, char *, int, int, int);
Expand Down Expand Up @@ -370,6 +371,7 @@ main(int argc, char *argv[])
zlog_recirculate_subscribe(master, pipe_lde_log[0]);
zlog_recirculate_subscribe(master, pipe_ldpe_log[0]);

libagentx_init();
vrf_init(NULL, NULL, NULL, NULL);
access_list_init();
ldp_vty_init();
Expand Down
44 changes: 10 additions & 34 deletions lib/agentx.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#include "hook.h"
#include "libfrr.h"
#include "xref.h"
#include "lib/libagentx.h"

XREF_SETUP();

DEFINE_HOOK(agentx_enabled, (), ());

static bool agentx_enabled = false;
//bool agentx_enabled = false;

static struct event_loop *agentx_tm;
static struct event *timeout_thr = NULL;
Expand Down Expand Up @@ -153,15 +154,6 @@ static void agentx_events_update(void)
netsnmp_large_fd_set_cleanup(&lfds);
}

/* AgentX node. */
static int config_write_agentx(struct vty *vty);
static struct cmd_node agentx_node = {
.name = "smux",
.node = SMUX_NODE,
.prompt = "",
.config_write = config_write_agentx,
};

/* Logging NetSNMP messages */
static int agentx_log_callback(int major, int minor, void *serverarg,
void *clientarg)
Expand Down Expand Up @@ -201,17 +193,7 @@ static int agentx_log_callback(int major, int minor, void *serverarg,
return SNMP_ERR_NOERROR;
}

static int config_write_agentx(struct vty *vty)
{
if (agentx_enabled)
vty_out(vty, "agentx\n");
return 1;
}

DEFUN (agentx_enable,
agentx_enable_cmd,
"agentx",
"SNMP AgentX protocol settings\n")
static int agentx_cli_on(void)
{
if (!agentx_enabled) {
init_snmp(FRR_SMUX_NAME);
Expand All @@ -221,19 +203,14 @@ DEFUN (agentx_enable,
hook_call(agentx_enabled);
}

return CMD_SUCCESS;
return 1;
}

DEFUN (no_agentx,
no_agentx_cmd,
"no agentx",
NO_STR
"SNMP AgentX protocol settings\n")
static int agentx_cli_off(void)
{
if (!agentx_enabled)
return CMD_SUCCESS;
vty_out(vty, "SNMP AgentX support cannot be disabled once enabled\n");
return CMD_WARNING_CONFIG_FAILED;
return 1;
return 0;
}

static int smux_disable(void)
Expand All @@ -252,17 +229,16 @@ void smux_init(struct event_loop *tm)
{
agentx_tm = tm;

hook_register(agentx_cli_enabled, agentx_cli_on);
hook_register(agentx_cli_disabled, agentx_cli_off);

netsnmp_enable_subagent();
snmp_disable_log();
snmp_enable_calllog();
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_LOGGING,
agentx_log_callback, NULL);
init_agent(FRR_SMUX_NAME);

install_node(&agentx_node);
install_element(CONFIG_NODE, &agentx_enable_cmd);
install_element(CONFIG_NODE, &no_agentx_cmd);

hook_register(frr_early_fini, smux_disable);
}

Expand Down
63 changes: 63 additions & 0 deletions lib/libagentx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/* SNMP cli support
* Copyright (C) 2024 Donald Sharp <sharpd@nvidia.com> NVIDIA Corporation
*/
#include <zebra.h>

#include "lib/hook.h"
#include "lib/libagentx.h"
#include "command.h"

DEFINE_HOOK(agentx_cli_enabled, (), ());
DEFINE_HOOK(agentx_cli_disabled, (), ());

bool agentx_enabled;

/* AgentX node. */
static int config_write_agentx(struct vty *vty)
{
if (agentx_enabled)
vty_out(vty, "agentx\n");
return 1;
}

static struct cmd_node agentx_node = {
.name = "smux",
.node = SMUX_NODE,
.prompt = "",
.config_write = config_write_agentx,
};

DEFUN(agentx_enable, agentx_enable_cmd, "agentx",
"SNMP AgentX protocol settings\n")
{
if (!hook_have_hooks(agentx_cli_enabled)) {
zlog_info(
"agentx specified but the agentx Module is not loaded, is this intentional?");

return CMD_SUCCESS;
}

hook_call(agentx_cli_enabled);

return CMD_SUCCESS;
}

DEFUN(no_agentx, no_agentx_cmd, "no agentx",
NO_STR "SNMP AgentX protocol settings\n")
{
vty_out(vty, "SNMP AgentX support cannot be disabled once enabled\n");
if (!hook_call(agentx_cli_disabled))
return CMD_WARNING_CONFIG_FAILED;

return CMD_SUCCESS;
}

void libagentx_init(void)
{
agentx_enabled = false;

install_node(&agentx_node);
install_element(CONFIG_NODE, &agentx_enable_cmd);
install_element(CONFIG_NODE, &no_agentx_cmd);
}
14 changes: 14 additions & 0 deletions lib/libagentx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/* SNMP cli support
* Copyright (C) 2024 Donald Sharp <sharpd@nvidia.com> NVIDIA Corporation
*/
#ifndef __LIBAGENTX_H__
#define __LIBAGENTX_H__

extern void libagentx_init(void);
extern bool agentx_enabled;

DECLARE_HOOK(agentx_cli_enabled, (), ());
DECLARE_HOOK(agentx_cli_disabled, (), ());

#endif
1 change: 1 addition & 0 deletions lib/smux.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct index_oid {
*/
extern bool smux_enabled(void);

extern void libagentx_init(void);
extern void smux_init(struct event_loop *tm);
extern void smux_agentx_enable(void);
extern void smux_register_mib(const char *, struct variable *, size_t, int,
Expand Down
2 changes: 2 additions & 0 deletions lib/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ lib_libfrr_la_SOURCES = \
lib/ldp_sync.c \
lib/lib_errors.c \
lib/lib_vty.c \
lib/libagentx.c \
lib/libfrr.c \
lib/libfrr_trace.c \
lib/linklist.c \
Expand Down Expand Up @@ -252,6 +253,7 @@ pkginclude_HEADERS += \
lib/ldp_sync.h \
lib/lib_errors.h \
lib/lib_vty.h \
lib/libagentx.h \
lib/libfrr.h \
lib/libfrr_trace.h \
lib/libospf.h \
Expand Down
2 changes: 2 additions & 0 deletions ospf6d/ospf6_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "vrf.h"
#include "bfd.h"
#include "libfrr.h"
#include "libagentx.h"

#include "ospf6d.h"
#include "ospf6_top.h"
Expand Down Expand Up @@ -266,6 +267,7 @@ int main(int argc, char *argv[], char *envp[])
/* thread master */
master = om6->master;

libagentx_init();
keychain_init();
ospf6_vrf_init();
access_list_init();
Expand Down
2 changes: 2 additions & 0 deletions ospfd/ospf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "libfrr.h"
#include "routemap.h"
#include "keychain.h"
#include "libagentx.h"

#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
Expand Down Expand Up @@ -256,6 +257,7 @@ int main(int argc, char **argv)
master = om->master;

/* Library inits. */
libagentx_init();
ospf_debug_init();
ospf_vrf_init();

Expand Down
2 changes: 1 addition & 1 deletion python/xref2vtysh.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# not quite obvious...

daemon_flags = {
"lib/agentx.c": "VTYSH_ISISD|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA",
"lib/libagentx.c": "VTYSH_ISISD|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA",
"lib/filter.c": "VTYSH_ACL_SHOW",
"lib/filter_cli.c": "VTYSH_ACL_CONFIG",
"lib/if.c": "VTYSH_INTERFACE",
Expand Down
2 changes: 2 additions & 0 deletions ripd/rip_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "routemap.h"
#include "bfd.h"
#include "mgmt_be_client.h"
#include "libagentx.h"

#include "ripd/ripd.h"
#include "ripd/rip_bfd.h"
Expand Down Expand Up @@ -190,6 +191,7 @@ int main(int argc, char **argv)
master = frr_init();

/* Library initialization. */
libagentx_init();
rip_error_init();
keychain_init_new(true);
rip_vrf_init();
Expand Down
2 changes: 2 additions & 0 deletions zebra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "routemap.h"
#include "routing_nb.h"
#include "mgmt_be_client.h"
#include "libagentx.h"

#include "zebra/zebra_router.h"
#include "zebra/zebra_errors.h"
Expand Down Expand Up @@ -435,6 +436,7 @@ int main(int argc, char **argv)
zrouter.master = frr_init();

/* Zebra related initialize. */
libagentx_init();
zebra_router_init(asic_offload, notify_on_ack, v6_with_v4_nexthop);
zserv_init();
zebra_rib_init();
Expand Down

0 comments on commit 300ca69

Please sign in to comment.