From 6f5d93645a6e9b04bccbd48ae2196a66638a49ca Mon Sep 17 00:00:00 2001 From: martijn Date: Tue, 24 Oct 2023 08:54:52 +0000 Subject: [PATCH] According to RFC2741 section 6.1.1 an agentx-response-pdu shouldn't have the NON_DEFAULT_CONTEXT set. Remove the argument from ax_response(). OK tb@ --- lib/libagentx/agentx.c | 6 ++---- lib/libagentx/ax.c | 8 ++++---- lib/libagentx/ax.h | 5 ++--- usr.sbin/snmpd/application_agentx.c | 32 ++++++++++++++--------------- usr.sbin/snmpd/ax.c | 8 ++++---- usr.sbin/snmpd/ax.h | 5 ++--- 6 files changed, 29 insertions(+), 35 deletions(-) diff --git a/lib/libagentx/agentx.c b/lib/libagentx/agentx.c index 07993b7c847..cc43ad45740 100644 --- a/lib/libagentx/agentx.c +++ b/lib/libagentx/agentx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agentx.c,v 1.22 2022/12/27 17:10:05 jmc Exp $ */ +/* $OpenBSD: agentx.c,v 1.23 2023/10/24 08:54:52 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren * @@ -2733,8 +2733,7 @@ agentx_get_finalize(struct agentx_get *axg) free(logmsg); if (ax_response(ax->ax_ax, axs->axs_id, axg->axg_transactionid, - axg->axg_packetid, AGENTX_CONTEXT_CTX(axc), 0, error, index, - vbl, nvarbind) == -1) { + axg->axg_packetid, 0, error, index, vbl, nvarbind) == -1) { agentx_log_axg_warn(axg, "Couldn't parse request"); agentx_reset(ax); } else @@ -4041,7 +4040,6 @@ agentx_read(struct agentx *ax) if (ax_response(ax->ax_ax, axs->axs_id, pdu->ap_header.aph_transactionid, pdu->ap_header.aph_packetid, - axc == NULL ? NULL : AGENTX_CONTEXT_CTX(axc), 0, error, 1, NULL, 0) == -1) agentx_log_axc_warn(axc, "transaction: %u packetid: %u: failed to send " diff --git a/lib/libagentx/ax.c b/lib/libagentx/ax.c index 5e1b0e0c195..4377a82d680 100644 --- a/lib/libagentx/ax.c +++ b/lib/libagentx/ax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ax.c,v 1.9 2023/10/24 08:48:41 martijn Exp $ */ +/* $OpenBSD: ax.c,v 1.10 2023/10/24 08:54:52 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren * @@ -553,11 +553,11 @@ ax_unregister(struct ax *ax, uint32_t sessionid, int ax_response(struct ax *ax, uint32_t sessionid, uint32_t transactionid, - uint32_t packetid, struct ax_ostring *context, uint32_t sysuptime, - uint16_t error, uint16_t index, struct ax_varbind *vblist, size_t nvb) + uint32_t packetid, uint32_t sysuptime, uint16_t error, uint16_t index, + struct ax_varbind *vblist, size_t nvb) { if (ax_pdu_header(ax, AX_PDU_TYPE_RESPONSE, 0, sessionid, - transactionid, packetid, context) == -1) + transactionid, packetid, NULL) == -1) return -1; if (ax_pdu_add_uint32(ax, sysuptime) == -1 || diff --git a/lib/libagentx/ax.h b/lib/libagentx/ax.h index 17fe584c877..f4de378f238 100644 --- a/lib/libagentx/ax.h +++ b/lib/libagentx/ax.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ax.h,v 1.4 2021/01/02 01:06:31 rob Exp $ */ +/* $OpenBSD: ax.h,v 1.5 2023/10/24 08:54:52 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren * @@ -220,8 +220,7 @@ uint32_t ax_register(struct ax *, uint8_t, uint32_t, uint32_t ax_unregister(struct ax *, uint32_t, struct ax_ostring *, uint8_t, uint8_t, struct ax_oid *, uint32_t); int ax_response(struct ax *, uint32_t, uint32_t, uint32_t, - struct ax_ostring *, uint32_t, uint16_t, uint16_t, - struct ax_varbind *, size_t); + uint32_t, uint16_t, uint16_t, struct ax_varbind *, size_t); void ax_pdu_free(struct ax_pdu *); void ax_varbind_free(struct ax_varbind *); const char *ax_error2string(enum ax_pdu_error); diff --git a/usr.sbin/snmpd/application_agentx.c b/usr.sbin/snmpd/application_agentx.c index c7a2a2691a3..1d1c0e36c7c 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.4 2022/09/01 14:34:17 martijn Exp $ */ +/* $OpenBSD: application_agentx.c,v 1.5 2023/10/24 08:54:52 martijn Exp $ */ /* * Copyright (c) 2022 Martijn van Duren * @@ -311,8 +311,7 @@ appl_agentx_recv(int fd, short event, void *cookie) pdu->ap_header.aph_sessionid); ax_response(conn->conn_ax, pdu->ap_header.aph_sessionid, pdu->ap_header.aph_transactionid, - pdu->ap_header.aph_packetid, - &(pdu->ap_context), smi_getticks(), + pdu->ap_header.aph_packetid, smi_getticks(), APPL_ERROR_NOTOPEN, 0, NULL, 0); appl_agentx_send(-1, EV_WRITE, conn); goto fail; @@ -370,8 +369,8 @@ appl_agentx_recv(int fd, short event, void *cookie) case AX_PDU_TYPE_PING: ax_response(conn->conn_ax, pdu->ap_header.aph_sessionid, pdu->ap_header.aph_transactionid, - pdu->ap_header.aph_packetid, &(pdu->ap_context), - smi_getticks(), APPL_ERROR_NOERROR, 0, NULL, 0); + pdu->ap_header.aph_packetid, smi_getticks(), + APPL_ERROR_NOERROR, 0, NULL, 0); appl_agentx_send(-1, EV_WRITE, conn); break; case AX_PDU_TYPE_INDEXALLOCATE: @@ -380,8 +379,8 @@ appl_agentx_recv(int fd, short event, void *cookie) ax_pdutype2string(pdu->ap_header.aph_type)); ax_response(conn->conn_ax, pdu->ap_header.aph_sessionid, pdu->ap_header.aph_transactionid, - pdu->ap_header.aph_packetid, &(pdu->ap_context), - smi_getticks(), APPL_ERROR_PROCESSINGERROR, 1, + pdu->ap_header.aph_packetid, smi_getticks(), + APPL_ERROR_PROCESSINGERROR, 1, pdu->ap_payload.ap_vbl.ap_varbind, pdu->ap_payload.ap_vbl.ap_nvarbind); appl_agentx_send(-1, EV_WRITE, conn); @@ -392,8 +391,8 @@ appl_agentx_recv(int fd, short event, void *cookie) ax_pdutype2string(pdu->ap_header.aph_type)); ax_response(conn->conn_ax, pdu->ap_header.aph_sessionid, pdu->ap_header.aph_transactionid, - pdu->ap_header.aph_packetid, &(pdu->ap_context), - smi_getticks(), APPL_ERROR_PROCESSINGERROR, 1, + pdu->ap_header.aph_packetid, smi_getticks(), + APPL_ERROR_PROCESSINGERROR, 1, NULL, 0); appl_agentx_send(-1, EV_WRITE, conn); break; @@ -492,16 +491,15 @@ appl_agentx_open(struct appl_agentx_connection *conn, struct ax_pdu *pdu) log_info("%s: %s %s: Open", session->sess_backend.ab_name, oidbuf, session->sess_descr.aos_string); - ax_response(conn->conn_ax, session->sess_id, pdu->ap_header.aph_transactionid, - pdu->ap_header.aph_packetid, NULL, smi_getticks(), APPL_ERROR_NOERROR, 0, - NULL, 0); + ax_response(conn->conn_ax, session->sess_id, + pdu->ap_header.aph_transactionid, pdu->ap_header.aph_packetid, + smi_getticks(), APPL_ERROR_NOERROR, 0, NULL, 0); appl_agentx_send(-1, EV_WRITE, conn); return; fail: ax_response(conn->conn_ax, 0, pdu->ap_header.aph_transactionid, - pdu->ap_header.aph_packetid, NULL, 0, APPL_ERROR_OPENFAILED, 0, - NULL, 0); + pdu->ap_header.aph_packetid, 0, APPL_ERROR_OPENFAILED, 0, NULL, 0); appl_agentx_send(-1, EV_WRITE, conn); if (session != NULL) free(session->sess_descr.aos_string); @@ -521,7 +519,7 @@ appl_agentx_close(struct appl_agentx_session *session, struct ax_pdu *pdu) ax_response(conn->conn_ax, pdu->ap_header.aph_sessionid, pdu->ap_header.aph_transactionid, pdu->ap_header.aph_packetid, - &(pdu->ap_context), smi_getticks(), APPL_ERROR_NOERROR, 0, NULL, 0); + smi_getticks(), APPL_ERROR_NOERROR, 0, NULL, 0); appl_agentx_send(-1, EV_WRITE, conn); } @@ -593,7 +591,7 @@ appl_agentx_register(struct appl_agentx_session *session, struct ax_pdu *pdu) fail: ax_response(session->sess_conn->conn_ax, session->sess_id, pdu->ap_header.aph_transactionid, pdu->ap_header.aph_packetid, - &(pdu->ap_context), smi_getticks(), error, 0, NULL, 0); + smi_getticks(), error, 0, NULL, 0); appl_agentx_send(-1, EV_WRITE, session->sess_conn); } @@ -620,7 +618,7 @@ appl_agentx_unregister(struct appl_agentx_session *session, struct ax_pdu *pdu) fail: ax_response(session->sess_conn->conn_ax, session->sess_id, pdu->ap_header.aph_transactionid, pdu->ap_header.aph_packetid, - &(pdu->ap_context), smi_getticks(), error, 0, NULL, 0); + smi_getticks(), error, 0, NULL, 0); appl_agentx_send(-1, EV_WRITE, session->sess_conn); } diff --git a/usr.sbin/snmpd/ax.c b/usr.sbin/snmpd/ax.c index 418e931d94f..a5c4c19306a 100644 --- a/usr.sbin/snmpd/ax.c +++ b/usr.sbin/snmpd/ax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ax.c,v 1.2 2023/10/24 08:48:41 martijn Exp $ */ +/* $OpenBSD: ax.c,v 1.3 2023/10/24 08:54:52 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren * @@ -715,11 +715,11 @@ ax_unregister(struct ax *ax, uint32_t sessionid, int ax_response(struct ax *ax, uint32_t sessionid, uint32_t transactionid, - uint32_t packetid, struct ax_ostring *context, uint32_t sysuptime, - uint16_t error, uint16_t index, struct ax_varbind *vblist, size_t nvb) + uint32_t packetid, uint32_t sysuptime, uint16_t error, uint16_t index, + struct ax_varbind *vblist, size_t nvb) { if (ax_pdu_header(ax, AX_PDU_TYPE_RESPONSE, 0, sessionid, - transactionid, packetid, context) == -1) + transactionid, packetid, NULL) == -1) return -1; if (ax_pdu_add_uint32(ax, sysuptime) == -1 || diff --git a/usr.sbin/snmpd/ax.h b/usr.sbin/snmpd/ax.h index 3b2ea93ba99..550197838d7 100644 --- a/usr.sbin/snmpd/ax.h +++ b/usr.sbin/snmpd/ax.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ax.h,v 1.1 2022/08/23 08:56:20 martijn Exp $ */ +/* $OpenBSD: ax.h,v 1.2 2023/10/24 08:54:52 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren * @@ -251,8 +251,7 @@ uint32_t ax_register(struct ax *, uint8_t, uint32_t, uint32_t ax_unregister(struct ax *, uint32_t, struct ax_ostring *, uint8_t, uint8_t, struct ax_oid *, uint32_t); int ax_response(struct ax *, uint32_t, uint32_t, uint32_t, - struct ax_ostring *, uint32_t, uint16_t, uint16_t, - struct ax_varbind *, size_t); + uint32_t, uint16_t, uint16_t, struct ax_varbind *, size_t); void ax_pdu_free(struct ax_pdu *); void ax_varbind_free(struct ax_varbind *); const char *ax_error2string(enum ax_pdu_error); -- 2.20.1