Commit 8572790517 for frr
commit 8572790517f6d37d660d9ed574bd2af34e8773b8
Author: Chirag Shah <chirag@nvidia.com>
Date: Fri Oct 23 15:59:17 2026 -0700
lib: record whether the AgentX master session is up
Net-snmp tells the subagent when its session to snmpd opens or the
transport drops, using SNMPD_CALLBACK_INDEX_START and
SNMPD_CALLBACK_INDEX_STOP. In this net-snmp those are session events,
not MIB index walks. Register them before init_snmp() so both the
open and the close are seen.
agentx_connected is set from those callbacks and cleared on shutdown.
The session pointer passed into the callback is not stored.
Without the registration, net-snmp still opens and reconnects the
session on its own, and FRR has no record of it. Trap sending is
unchanged: smux_trap_multi_index() calls send_v2trap() when agentx is
enabled and does not read this flag.
Ticket: #5219067
Assisted-by: Cursor (Auto)
Signed-off-by: Chirag Shah <chirag@nvidia.com>
diff --git a/lib/agentx.c b/lib/agentx.c
index fa8c34fe07..c4fca5a068 100644
--- a/lib/agentx.c
+++ b/lib/agentx.c
@@ -11,6 +11,7 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/snmp_vars.h>
+#include <net-snmp/agent/agent_callbacks.h>
#include <net-snmp/library/large_fd_set.h>
#include "command.h"
@@ -30,6 +31,12 @@ DEFINE_HOOK(agentx_enabled, (), ());
//bool agentx_enabled = false;
+/* True between AgentX master-session open and transport disconnect.
+ * In this net-snmp, SNMPD_CALLBACK_INDEX_START / INDEX_STOP are fired
+ * only from agentx/subagent.c for that session, not for MIB index walks.
+ */
+static bool agentx_connected;
+
static struct event_loop *agentx_tm;
static struct event *timeout_thr = NULL;
static struct list *events = NULL;
@@ -218,9 +225,29 @@ static int agentx_cli_off(void)
return 0;
}
+static int agentx_master_up_cb(int majorID, int minorID, void *serverarg, void *clientarg)
+{
+ /* A repeated START for the session that is already up changes nothing. */
+ if (agentx_connected)
+ return SNMP_ERR_NOERROR;
+
+ agentx_connected = true;
+ return SNMP_ERR_NOERROR;
+}
+
+static int agentx_master_down_cb(int majorID, int minorID, void *serverarg, void *clientarg)
+{
+ if (!agentx_connected)
+ return SNMP_ERR_NOERROR;
+
+ agentx_connected = false;
+ return SNMP_ERR_NOERROR;
+}
+
static int smux_disable(void)
{
agentx_enabled = false;
+ agentx_connected = false;
return 0;
}
@@ -242,6 +269,11 @@ void smux_init(struct event_loop *tm)
snmp_enable_calllog();
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_LOGGING,
agentx_log_callback, NULL);
+ /* Master-session up/down. Registered before init_snmp() opens it. */
+ snmp_register_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_INDEX_START,
+ agentx_master_up_cb, NULL);
+ snmp_register_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_INDEX_STOP,
+ agentx_master_down_cb, NULL);
init_agent(FRR_SMUX_NAME);
hook_register(frr_early_fini, smux_disable);