From: martijn Date: Tue, 24 Oct 2023 13:37:02 +0000 (+0000) Subject: appl_agentx_free() closes any open sessions before freeing everything up. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=273d3fb05d0b81ab8db0042292c2795934b14f3f;p=openbsd appl_agentx_free() closes any open sessions before freeing everything up. Up until now all sessions were closed with reasonShutdown, which is not accurate for every situation. Give it an additional reason argument that propagates to appl_agentx_forceclose(). OK tb@ --- diff --git a/usr.sbin/snmpd/application_agentx.c b/usr.sbin/snmpd/application_agentx.c index 81b37bd9280..43c300e9422 100644 --- a/usr.sbin/snmpd/application_agentx.c +++ b/usr.sbin/snmpd/application_agentx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: application_agentx.c,v 1.8 2023/10/24 13:28:11 martijn Exp $ */ +/* $OpenBSD: application_agentx.c,v 1.9 2023/10/24 13:37:02 martijn Exp $ */ /* * Copyright (c) 2022 Martijn van Duren * @@ -77,7 +77,7 @@ struct appl_agentx_session { void appl_agentx_listen(struct agentx_master *); void appl_agentx_accept(int, short, void *); -void appl_agentx_free(struct appl_agentx_connection *); +void appl_agentx_free(struct appl_agentx_connection *, enum appl_close_reason); void appl_agentx_recv(int, short, void *); void appl_agentx_open(struct appl_agentx_connection *, struct ax_pdu *); void appl_agentx_close(struct appl_agentx_session *, struct ax_pdu *); @@ -178,7 +178,7 @@ appl_agentx_shutdown(void) struct appl_agentx_connection *conn, *tconn; RB_FOREACH_SAFE(conn, appl_agentx_conns, &appl_agentx_conns, tconn) - appl_agentx_free(conn); + appl_agentx_free(conn, APPL_CLOSE_REASONSHUTDOWN); } void @@ -249,7 +249,8 @@ appl_agentx_backend(int fd) } void -appl_agentx_free(struct appl_agentx_connection *conn) +appl_agentx_free(struct appl_agentx_connection *conn, + enum appl_close_reason reason) { struct appl_agentx_session *session; @@ -261,7 +262,7 @@ appl_agentx_free(struct appl_agentx_connection *conn) appl_agentx_session_free(session); else appl_agentx_forceclose(&(session->sess_backend), - APPL_CLOSE_REASONSHUTDOWN); + reason); } RB_REMOVE(appl_agentx_conns, &appl_agentx_conns, conn); @@ -294,7 +295,8 @@ appl_agentx_recv(int fd, short event, void *cookie) ax_free(conn->conn_ax); conn->conn_ax = NULL; } - appl_agentx_free(conn); + appl_agentx_free(conn, errno == EPROTO ? + APPL_CLOSE_REASONPROTOCOLERROR : APPL_CLOSE_REASONOTHER); return; } @@ -458,7 +460,7 @@ appl_agentx_recv(int fd, short event, void *cookie) appl_agentx_forceclose(&(session->sess_backend), APPL_CLOSE_REASONPARSEERROR); if (TAILQ_EMPTY(&(conn->conn_sessions))) - appl_agentx_free(conn); + appl_agentx_free(conn, APPL_CLOSE_REASONOTHER); } void @@ -847,7 +849,7 @@ appl_agentx_send(int fd, short event, void *cookie) log_warn("AgentX(%"PRIu32")", conn->conn_id); ax_free(conn->conn_ax); conn->conn_ax = NULL; - appl_agentx_free(conn); + appl_agentx_free(conn, APPL_CLOSE_REASONOTHER); return; case 0: return;