summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/agentx.c44
-rw-r--r--lib/libagentx.c63
-rw-r--r--lib/libagentx.h14
-rw-r--r--lib/smux.h1
-rw-r--r--lib/subdir.am2
5 files changed, 90 insertions, 34 deletions
diff --git a/lib/agentx.c b/lib/agentx.c
index 70ee6753f..19f2a6b7f 100644
--- a/lib/agentx.c
+++ b/lib/agentx.c
@@ -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;
@@ -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)
@@ -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);
@@ -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)
@@ -252,6 +229,9 @@ 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();
@@ -259,10 +239,6 @@ void smux_init(struct event_loop *tm)
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);
}
diff --git a/lib/libagentx.c b/lib/libagentx.c
new file mode 100644
index 000000000..23826572e
--- /dev/null
+++ b/lib/libagentx.c
@@ -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);
+}
diff --git a/lib/libagentx.h b/lib/libagentx.h
new file mode 100644
index 000000000..c3246d975
--- /dev/null
+++ b/lib/libagentx.h
@@ -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
diff --git a/lib/smux.h b/lib/smux.h
index cec4d2a1b..8ec847afd 100644
--- a/lib/smux.h
+++ b/lib/smux.h
@@ -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,
diff --git a/lib/subdir.am b/lib/subdir.am
index 221c0b1e1..3264f31af 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -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 \
@@ -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 \