]> git.puffer.fish Git - matthieu/frr.git/commitdiff
*: Modify agentx to be allowed to be called
authorDonald Sharp <sharpd@nvidia.com>
Thu, 9 May 2024 11:47:29 +0000 (07:47 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Fri, 10 May 2024 14:16:29 +0000 (10:16 -0400)
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: #15896
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
14 files changed:
bgpd/bgp_main.c
eigrpd/eigrp_main.c
isisd/isis_main.c
ldpd/ldpd.c
lib/agentx.c
lib/libagentx.c [new file with mode: 0644]
lib/libagentx.h [new file with mode: 0644]
lib/smux.h
lib/subdir.am
ospf6d/ospf6_main.c
ospfd/ospf_main.c
python/xref2vtysh.py
ripd/rip_main.c
zebra/main.c

index 44d5ee68cce6d26aa2a631e0f5340d654bf5c094..2bbd3a4b1bb8296577fb7330f93cbe0506e63a31 100644 (file)
@@ -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"
@@ -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
index d387b9be1804f635bc8a379bd31ecd660511209d..319ac925337be7dc7fff635f5d0ace0981ec0300 100644 (file)
@@ -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"
@@ -178,9 +179,11 @@ int main(int argc, char **argv, char **envp)
 
        /* EIGRP master init. */
        eigrp_master_init();
+
        eigrp_om->master = frr_init();
        master = eigrp_om->master;
 
+       libagentx_init();
        eigrp_error_init();
        eigrp_vrf_init();
        vrf_init(NULL, NULL, NULL, NULL);
index 60ec8cdad480994fa5ba0ff72f895beaeec0b62d..8dd3a97aa1faf5cb2e0c41b5e61b7cb2e49d2bb3 100644 (file)
@@ -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"
@@ -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();
index 492a36b3d6a19e0e185e44e84e386295c9ed5bae..4d38fdcd02c958b025a80aafd0f87f743cd020b6 100644 (file)
@@ -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);
@@ -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();
index 70ee6753ff4ce347364c0f8cdf1da3a4d77d35af..19f2a6b7fce85cc8cc86abc8e7d81a9233879e98 100644 (file)
 #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 (file)
index 0000000..2382657
--- /dev/null
@@ -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 (file)
index 0000000..c3246d9
--- /dev/null
@@ -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
index cec4d2a1bf1e76ca18cf325641c5c03c3db051b5..8ec847afd01f5ed08c2b9b6c0de0fda6df286435 100644 (file)
@@ -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,
index 221c0b1e1d87f3b9969e9592761b90574e77f876..3264f31af7a433dfaf6dcd381457a77b3976ca3a 100644 (file)
@@ -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 \
index abd43203357c2a3870be9710233b12cf77666cd9..8320f11f6cceed20a325318cc2b72a1a6cf42d37 100644 (file)
@@ -24,6 +24,7 @@
 #include "vrf.h"
 #include "bfd.h"
 #include "libfrr.h"
+#include "libagentx.h"
 
 #include "ospf6d.h"
 #include "ospf6_top.h"
@@ -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();
index 9e97abba1ca10ea22cb932b416c1200c81f4600b..fdb4e5c5875fdc72d809a206031336bda1dc7a6e 100644 (file)
@@ -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"
@@ -256,6 +257,7 @@ int main(int argc, char **argv)
        master = om->master;
 
        /* Library inits. */
+       libagentx_init();
        ospf_debug_init();
        ospf_vrf_init();
 
index 177de757b04def886c9416378e1c6d51709a7233..75d9ccf367df78a0ae5b354a0cb0439968abac1f 100644 (file)
@@ -32,7 +32,7 @@ frr_top_src = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 # 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",
index 734e7ac4d92619ead19015073b817ad78dc458ee..67469f5fe52c2987a256b881243d4d6979f36c0e 100644 (file)
@@ -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"
@@ -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();
index d83f1d0491bf3c0228b27c123963bafedc439b90..ea1e1cbdbbd8c53a6b764de3f52cd191037f76cf 100644 (file)
@@ -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"
@@ -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();