summaryrefslogtreecommitdiff
path: root/regress/usr.sbin
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2023-11-13 10:16:52 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2023-11-13 10:16:52 +0000
commit060c0f7bf0a5f4bb7ecd22a0f39d841d6246b186 (patch)
tree0fdd3307dc7e35a438ca0dd91c6ffd5c5ef08a02 /regress/usr.sbin
parentafe9474f23010fb817775f449f7bb0922a09d3dd (diff)
Add 2 tests to make sure getbulkrequests return the correct error index.
Diffstat (limited to 'regress/usr.sbin')
-rw-r--r--regress/usr.sbin/snmpd/Makefile4
-rw-r--r--regress/usr.sbin/snmpd/backend.c80
-rw-r--r--regress/usr.sbin/snmpd/regress.h2
-rw-r--r--regress/usr.sbin/snmpd/snmpd_regress.c2
4 files changed, 87 insertions, 1 deletions
diff --git a/regress/usr.sbin/snmpd/Makefile b/regress/usr.sbin/snmpd/Makefile
index ba0db3bb41d..21b8b4403dd 100644
--- a/regress/usr.sbin/snmpd/Makefile
+++ b/regress/usr.sbin/snmpd/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.9 2023/11/10 12:16:53 martijn Exp $
+# $OpenBSD: Makefile,v 1.10 2023/11/13 10:16:51 martijn Exp $
# Regress tests for snmpd
PROG = snmpd_regress
@@ -235,6 +235,8 @@ BACKEND_TARGETS+= backend_error_getnext_parseerror
BACKEND_TARGETS+= backend_error_getnext_requestdenied
BACKEND_TARGETS+= backend_error_getnext_processingerror
BACKEND_TARGETS+= backend_error_getnext_nonstandard
+BACKEND_TARGETS+= backend_error_getbulk_firstrepetition
+BACKEND_TARGETS+= backend_error_getbulk_secondrepetition
REGRESS_TARGETS+= ${BACKEND_TARGETS}
backend: ${BACKEND_TARGETS}
diff --git a/regress/usr.sbin/snmpd/backend.c b/regress/usr.sbin/snmpd/backend.c
index 5832fe98719..830ad445b23 100644
--- a/regress/usr.sbin/snmpd/backend.c
+++ b/regress/usr.sbin/snmpd/backend.c
@@ -5373,3 +5373,83 @@ backend_error_getnext_nonstandard(void)
snmpv2_response_validate(snmp_s, 1000, community, requestid, GENERR, 1,
&varbind, 1);
}
+
+void
+backend_error_getbulk_firstrepetition(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(MIB_BACKEND_ERROR, 63),
+ };
+ 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_ERROR, 63), __func__);
+ agentx_register(ax_s, sessionid, 0, 0, 127, 0,
+ OID_ARG(MIB_BACKEND_ERROR, 63), 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;
+ n = agentx_read(ax_s, buf, sizeof(buf), 1000);
+ agentx_getnext_handle(__func__, buf, n, 0, sessionid, NULL, &varbind, 1);
+ varbind.name.n_subid--;
+ agentx_response(ax_s, buf, GENERR, 1, &varbind, 1);
+
+ snmpv2_response_validate(snmp_s, 1000, community, requestid, GENERR, 1,
+ &varbind, 1);
+}
+
+void
+backend_error_getbulk_secondrepetition(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(MIB_BACKEND_ERROR, 64),
+ .data.int32 = 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_ERROR, 64), __func__);
+ agentx_register(ax_s, sessionid, 0, 0, 127, 0,
+ OID_ARG(MIB_BACKEND_ERROR, 64), 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;
+ n = agentx_read(ax_s, buf, sizeof(buf), 1000);
+ agentx_getnext_handle(__func__, buf, n, 0, sessionid, NULL, &varbind, 1);
+ varbind.type = TYPE_INTEGER;
+ agentx_response(ax_s, buf, 0, NOERROR, &varbind, 1);
+ varbind.name.subid[varbind.name.n_subid - 1] = 1;
+ n = agentx_read(ax_s, buf, sizeof(buf), 1000);
+ agentx_getnext_handle(__func__, buf, n, 0, sessionid, NULL, &varbind, 1);
+ varbind.name.subid[varbind.name.n_subid - 1] = 0;
+ varbind.type = TYPE_NULL;
+ agentx_response(ax_s, buf, 0, GENERR, &varbind, 1);
+
+ varbind.name.n_subid--;
+ snmpv2_response_validate(snmp_s, 1000, community, requestid, GENERR, 1,
+ &varbind, 1);
+}
diff --git a/regress/usr.sbin/snmpd/regress.h b/regress/usr.sbin/snmpd/regress.h
index 3b7c5ac12e6..3f5fb17ebe2 100644
--- a/regress/usr.sbin/snmpd/regress.h
+++ b/regress/usr.sbin/snmpd/regress.h
@@ -364,4 +364,6 @@ void backend_error_getnext_parseerror(void);
void backend_error_getnext_requestdenied(void);
void backend_error_getnext_processingerror(void);
void backend_error_getnext_nonstandard(void);
+void backend_error_getbulk_firstrepetition(void);
+void backend_error_getbulk_secondrepetition(void);
void snmp_v3_usm_noauthpriv(void);
diff --git a/regress/usr.sbin/snmpd/snmpd_regress.c b/regress/usr.sbin/snmpd/snmpd_regress.c
index 88c78c0b3d0..29e759480af 100644
--- a/regress/usr.sbin/snmpd/snmpd_regress.c
+++ b/regress/usr.sbin/snmpd/snmpd_regress.c
@@ -208,6 +208,8 @@ const struct {
{ "backend_error_getnext_requestdenied", backend_error_getnext_requestdenied },
{ "backend_error_getnext_processingerror", backend_error_getnext_processingerror },
{ "backend_error_getnext_nonstandard", backend_error_getnext_nonstandard },
+ { "backend_error_getbulk_firstrepetition", backend_error_getbulk_firstrepetition },
+ { "backend_error_getbulk_secondrepetition", backend_error_getbulk_secondrepetition },
{ "snmp_v3_usm_noauthpriv", snmp_v3_usm_noauthpriv},
{ NULL, NULL }
};