Add 3 tests for when getbulk reaches EOMV.
authormartijn <martijn@openbsd.org>
Thu, 16 Nov 2023 13:26:45 +0000 (13:26 +0000)
committermartijn <martijn@openbsd.org>
Thu, 16 Nov 2023 13:26:45 +0000 (13:26 +0000)
regress/usr.sbin/snmpd/Makefile
regress/usr.sbin/snmpd/backend.c
regress/usr.sbin/snmpd/regress.h
regress/usr.sbin/snmpd/snmpd_regress.c

index 21b8b44..9f34037 100644 (file)
@@ -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
index 830ad44..86af8de 100644 (file)
@@ -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)
 {
index 3f5fb17..cd05eb5 100644 (file)
@@ -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);
index 29e7594..36714ce 100644 (file)
@@ -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 },