Index | Thread | Search

From:
Martijn van Duren <openbsd+tech@list.imperialat.at>
Subject:
snmpd: remove sm_transactionid
To:
tech@openbsd.org
Date:
Fri, 30 Oct 2026 19:20:23 +0100

Download raw body.

Thread
  • Martijn van Duren:

    snmpd: remove sm_transactionid

Hello tech@,

Originally I've added sm_transactionid as a starting point of keeping
track of where an snmp_message lives in accordance with AgentX/RFC2741.
In the end I ended up storing the transactionid and a reference to the
snmp_message inside application.c's struct appl_request_upstream, and
ended up never using sm_tranactionid and forgetting about it.

I think it's time to remove it.

OK?

martijn@

diff /usr/src
path + /usr/src
commit - 8c9ea0ff3fd3788b066415bd61a787c53e6c77b7
blob - 81dfcb880c0abdf35802eb67ed227cb5dd4a8de5
file + usr.sbin/snmpd/snmpd.h
--- usr.sbin/snmpd/snmpd.h
+++ usr.sbin/snmpd/snmpd.h
@@ -230,8 +230,6 @@ struct snmp_message {
 	u_int8_t		 sm_data[READ_BUF_SIZE];
 	size_t			 sm_datalen;
 
-	uint32_t		 sm_transactionid;
-
 	u_int			 sm_version;
 
 	/* V1, V2c */
@@ -267,11 +265,7 @@ struct snmp_message {
 
 	struct ber_element	*sm_varbind;
 	struct ber_element	*sm_varbindresp;
-
-	RB_ENTRY(snmp_message)	 sm_entry;
 };
-RB_HEAD(snmp_messages, snmp_message);
-extern struct snmp_messages snmp_messages;
 
 /* Defined in SNMPv2-MIB.txt (RFC 3418) */
 struct snmp_stats {
@@ -479,8 +473,6 @@ void		 snmpe(struct privsep *, struct privsep_proc *);
 void		 snmpe_shutdown(void);
 void		 snmpe_dispatchmsg(struct snmp_message *);
 void		 snmpe_response(struct snmp_message *);
-int		 snmp_messagecmp(struct snmp_message *, struct snmp_message *);
-RB_PROTOTYPE(snmp_messages, snmp_message, sm_entry, snmp_messagecmp)
 
 /* trap.c */
 void		 trap_init(void);
commit - 8c9ea0ff3fd3788b066415bd61a787c53e6c77b7
blob - 2dbe327fde17a372c5cf208ac9697c3afaeb7db2
file + usr.sbin/snmpd/snmpe.c
--- usr.sbin/snmpd/snmpe.c
+++ usr.sbin/snmpd/snmpe.c
@@ -61,8 +61,6 @@ int	 snmpe_encode(struct snmp_message *);
 struct imsgev	*iev_parent;
 static const struct timeval	snmpe_tcp_timeout = { 10, 0 }; /* 10s */
 
-struct snmp_messages snmp_messages = RB_INITIALIZER(&snmp_messages);
-
 static struct privsep_proc procs[] = {
 	{ "parent",	PROC_PARENT, snmpe_dispatch_parent },
 	{ "storage",	PROC_STORAGE, snmpe_dispatch_storage }
@@ -305,11 +303,6 @@ snmpe_parse(struct snmp_message *msg)
 
 	msg->sm_errstr = "invalid message";
 
-	do {
-		msg->sm_transactionid = arc4random();
-	} while (msg->sm_transactionid == 0 ||
-	    RB_INSERT(snmp_messages, &snmp_messages, msg) != NULL);
-
 	if (ober_scanf_elements(root, "{ie", &ver, &a) != 0)
 		goto parsefail;
 
@@ -868,8 +861,6 @@ snmpe_response(struct snmp_message *msg)
 void
 snmp_msgfree(struct snmp_message *msg)
 {
-	if (msg->sm_transactionid != 0)
-		RB_REMOVE(snmp_messages, &snmp_messages, msg);
 	event_del(&msg->sm_sockev);
 	ober_free(&msg->sm_ber);
 	if (msg->sm_req != NULL)
@@ -933,12 +924,3 @@ snmpe_encode(struct snmp_message *msg)
 #endif
 	return 0;
 }
-
-int
-snmp_messagecmp(struct snmp_message *m1, struct snmp_message *m2)
-{
-	return (m1->sm_transactionid < m2->sm_transactionid ? -1 :
-	    m1->sm_transactionid > m2->sm_transactionid);
-}
-
-RB_GENERATE(snmp_messages, snmp_message, sm_entry, snmp_messagecmp)