From 2ccef0395ffcefbe31de02f437166c29a90a40be Mon Sep 17 00:00:00 2001 From: martijn Date: Thu, 16 Nov 2023 13:26:45 +0000 Subject: [PATCH] Add 3 tests for when getbulk reaches EOMV. --- regress/usr.sbin/snmpd/Makefile | 5 +- regress/usr.sbin/snmpd/backend.c | 166 +++++++++++++++++++++++++ regress/usr.sbin/snmpd/regress.h | 3 + regress/usr.sbin/snmpd/snmpd_regress.c | 3 + 4 files changed, 176 insertions(+), 1 deletion(-) diff --git a/regress/usr.sbin/snmpd/Makefile b/regress/usr.sbin/snmpd/Makefile index 21b8b4403dd..9f3403736b8 100644 --- a/regress/usr.sbin/snmpd/Makefile +++ b/regress/usr.sbin/snmpd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.10 2023/11/13 10:16:51 martijn Exp $ +# $OpenBSD: Makefile,v 1.11 2023/11/16 13:26:45 martijn Exp $ # Regress tests for snmpd PROG = snmpd_regress @@ -180,6 +180,9 @@ BACKEND_TARGETS+= backend_getbulk_nonrep_one_maxrep_one BACKEND_TARGETS+= backend_getbulk_nonrep_one_maxrep_two BACKEND_TARGETS+= backend_getbulk_nonrep_two_maxrep_two BACKEND_TARGETS+= backend_getbulk_nonrep_negative +BACKEND_TARGETS+= backend_getbulk_endofmibview +BACKEND_TARGETS+= backend_getbulk_endofmibview_second_rep +BACKEND_TARGETS+= backend_getbulk_endofmibview_two_varbinds BACKEND_TARGETS+= backend_error_get_toobig BACKEND_TARGETS+= backend_error_get_nosuchname BACKEND_TARGETS+= backend_error_get_badvalue diff --git a/regress/usr.sbin/snmpd/backend.c b/regress/usr.sbin/snmpd/backend.c index 830ad445b23..86af8de4b63 100644 --- a/regress/usr.sbin/snmpd/backend.c +++ b/regress/usr.sbin/snmpd/backend.c @@ -3173,6 +3173,172 @@ backend_getbulk_nonrep_negative(void) snmp_timeout(snmp_s, 1); } +/* Assume that everything is registered under 1.3.* */ +void +backend_getbulk_endofmibview(void) +{ + struct sockaddr_storage ss; + struct sockaddr *sa = (struct sockaddr *)&ss; + socklen_t salen; + int snmp_s, ax_s; + uint32_t sessionid; + struct varbind varbind = { + .type = TYPE_NULL, + .name = OID_STRUCT(2, 0), + }; + struct searchrange searchrange = { + .start = OID_STRUCT(2, 0), + .end = OID_STRUCT(2, 1) + }; + int32_t requestid; + char buf[1024]; + size_t n; + + ax_s = agentx_connect(axsocket); + sessionid = agentx_open(ax_s, 0, 0, + OID_ARG(MIB_SUBAGENT_BACKEND_GETBULK, 7), __func__); + agentx_register(ax_s, sessionid, 0, 0, 127, 0, + OID_ARG(2, 0), 0); + + salen = snmp_resolve(SOCK_DGRAM, hostname, servname, sa); + snmp_s = snmp_connect(SOCK_DGRAM, sa, salen); + requestid = snmpv2_getbulk(snmp_s, community, 0, 0, 2, &varbind, 1); + + varbind.name.subid[varbind.name.n_subid++] = 0; + varbind.type = TYPE_ENDOFMIBVIEW; + n = agentx_read(ax_s, buf, sizeof(buf), 1000); + agentx_getnext_handle(__func__, buf, n, 0, sessionid, &searchrange, + &varbind, 1); + varbind.name.n_subid--; + + agentx_response(ax_s, buf, NOERROR, 0, &varbind, 1); + + snmpv2_response_validate(snmp_s, 1000, community, requestid, NOERROR, 0, + &varbind, 1); +} + +void +backend_getbulk_endofmibview_second_rep(void) +{ + struct sockaddr_storage ss; + struct sockaddr *sa = (struct sockaddr *)&ss; + socklen_t salen; + int snmp_s, ax_s; + uint32_t sessionid; + struct varbind request[] = { + { + .type = TYPE_NULL, + .name = OID_STRUCT(2 ,0), + .data.int32 = 1 + }, + { + .type = TYPE_ENDOFMIBVIEW, + .name = OID_STRUCT(2, 0, 0), + } + }; + struct searchrange searchrange = { + .start = OID_STRUCT(2, 0), + .end = OID_STRUCT(2, 1) + }; + int32_t requestid; + char buf[1024]; + size_t n; + + ax_s = agentx_connect(axsocket); + sessionid = agentx_open(ax_s, 0, 0, + OID_ARG(MIB_SUBAGENT_BACKEND_GETBULK, 8), __func__); + agentx_register(ax_s, sessionid, 0, 0, 127, 0, + OID_ARG(2, 0), 0); + + salen = snmp_resolve(SOCK_DGRAM, hostname, servname, sa); + snmp_s = snmp_connect(SOCK_DGRAM, sa, salen); + requestid = snmpv2_getbulk(snmp_s, community, 0, 0, 2, request, 1); + + request[0].name.subid[request[0].name.n_subid++] = 0; + request[0].type = TYPE_INTEGER; + n = agentx_read(ax_s, buf, sizeof(buf), 1000); + agentx_getnext_handle(__func__, buf, n, 0, sessionid, &searchrange, + request, 1); + agentx_response(ax_s, buf, NOERROR, 0, request, 1); + + searchrange.start = request[0].name; + n = agentx_read(ax_s, buf, sizeof(buf), 1000); + agentx_getnext_handle(__func__, buf, n, 0, sessionid, &searchrange, + &request[1], 1); + agentx_response(ax_s, buf, NOERROR, 0, &request[1], 1); + + snmpv2_response_validate(snmp_s, 1000, community, requestid, NOERROR, 0, + request, 2); +} + +void +backend_getbulk_endofmibview_two_varbinds(void) +{ + struct sockaddr_storage ss; + struct sockaddr *sa = (struct sockaddr *)&ss; + socklen_t salen; + int snmp_s, ax_s; + uint32_t sessionid; + struct varbind request[] = { + { + .type = TYPE_NULL, + .name = OID_STRUCT(2 ,0), + .data.int32 = 1 + }, + { + .type = TYPE_NULL, + .name = OID_STRUCT(2, 0, 0), + }, + { + .type = TYPE_ENDOFMIBVIEW, + .name = OID_STRUCT(2, 0, 0), + }, + { + .type = TYPE_ENDOFMIBVIEW, + .name = OID_STRUCT(2, 0, 0), + } + }; + struct searchrange searchrange[] = { + { + .start = OID_STRUCT(2, 0), + .end = OID_STRUCT(2, 1) + }, + { + .start = OID_STRUCT(2, 0, 0), + .end = OID_STRUCT(2, 1) + }, + }; + int32_t requestid; + char buf[1024]; + size_t n; + + ax_s = agentx_connect(axsocket); + sessionid = agentx_open(ax_s, 0, 0, + OID_ARG(MIB_SUBAGENT_BACKEND_GETBULK, 9), __func__); + agentx_register(ax_s, sessionid, 0, 0, 127, 0, + OID_ARG(2, 0), 0); + + salen = snmp_resolve(SOCK_DGRAM, hostname, servname, sa); + snmp_s = snmp_connect(SOCK_DGRAM, sa, salen); + requestid = snmpv2_getbulk(snmp_s, community, 0, 0, 2, request, 2); + + request[0].name.subid[request[0].name.n_subid++] = 0; + request[0].type = TYPE_INTEGER; + request[1].type = TYPE_ENDOFMIBVIEW; + n = agentx_read(ax_s, buf, sizeof(buf), 1000); + agentx_getnext_handle(__func__, buf, n, 0, sessionid, searchrange, + request, 2); + agentx_response(ax_s, buf, NOERROR, 0, request, 2); + + n = agentx_read(ax_s, buf, sizeof(buf), 1000); + agentx_getnext_handle(__func__, buf, n, 0, sessionid, &searchrange[1], + &request[1], 1); + agentx_response(ax_s, buf, NOERROR, 0, &request[1], 1); + + snmpv2_response_validate(snmp_s, 1000, community, requestid, NOERROR, 0, + request, 4); +} + void backend_error_get_toobig(void) { diff --git a/regress/usr.sbin/snmpd/regress.h b/regress/usr.sbin/snmpd/regress.h index 3f5fb17ebe2..cd05eb51bf2 100644 --- a/regress/usr.sbin/snmpd/regress.h +++ b/regress/usr.sbin/snmpd/regress.h @@ -308,6 +308,9 @@ void backend_getbulk_nonrep_one_maxrep_one(void); void backend_getbulk_nonrep_one_maxrep_two(void); void backend_getbulk_nonrep_two_maxrep_two(void); void backend_getbulk_nonrep_negative(void); +void backend_getbulk_endofmibview(void); +void backend_getbulk_endofmibview_second_rep(void); +void backend_getbulk_endofmibview_two_varbinds(void); void backend_error_get_toobig(void); void backend_error_get_nosuchname(void); void backend_error_get_badvalue(void); diff --git a/regress/usr.sbin/snmpd/snmpd_regress.c b/regress/usr.sbin/snmpd/snmpd_regress.c index 29e759480af..36714ce3708 100644 --- a/regress/usr.sbin/snmpd/snmpd_regress.c +++ b/regress/usr.sbin/snmpd/snmpd_regress.c @@ -153,6 +153,9 @@ const struct { { "backend_getbulk_nonrep_one_maxrep_two", backend_getbulk_nonrep_one_maxrep_two }, { "backend_getbulk_nonrep_two_maxrep_two", backend_getbulk_nonrep_two_maxrep_two }, { "backend_getbulk_nonrep_negative", backend_getbulk_nonrep_negative }, + { "backend_getbulk_endofmibview", backend_getbulk_endofmibview }, + { "backend_getbulk_endofmibview_second_rep", backend_getbulk_endofmibview_second_rep }, + { "backend_getbulk_endofmibview_two_varbinds", backend_getbulk_endofmibview_two_varbinds }, { "backend_error_get_toobig", backend_error_get_toobig }, { "backend_error_get_nosuchname", backend_error_get_nosuchname }, { "backend_error_get_badvalue", backend_error_get_badvalue }, -- 2.20.1