-/* $OpenBSD: application.c,v 1.33 2023/11/08 19:59:46 martijn Exp $ */
+/* $OpenBSD: application.c,v 1.34 2023/11/08 20:02:52 martijn Exp $ */
/*
* Copyright (c) 2021 Martijn van Duren <martijn@openbsd.org>
struct appl_context *aru_ctx;
struct snmp_message *aru_statereference;
enum snmp_pdutype aru_requesttype;
+ enum snmp_pdutype aru_responsetype;
int32_t aru_requestid; /* upstream requestid */
int32_t aru_transactionid; /* RFC 2741 section 6.1 */
uint16_t aru_nonrepeaters;
int appl_error_valid(enum appl_error, enum snmp_pdutype);
int appl_varbind_backend(struct appl_varbind_internal *);
void appl_varbind_error(struct appl_varbind_internal *, enum appl_error);
-void appl_report(struct snmp_message *, int32_t, struct ber_oid *,
- struct ber_element *);
+void appl_report(struct snmp_message *, int32_t, struct ber_oid *);
void appl_pdu_log(struct appl_backend *, enum snmp_pdutype, int32_t, uint16_t,
uint16_t, struct appl_varbind *);
void ober_oid_nextsibling(struct ber_oid *);
{
struct appl_context *ctx;
struct appl_request_upstream *ureq;
- struct ber_oid oid;
- struct ber_element *value, *varbind, *varbindlist;
+ struct ber_element *varbind, *varbindlist;
long long nonrepeaters, maxrepetitions;
static uint32_t transactionid;
int32_t requestid;
/* RFC 3413, section 3.2, processPDU, item 5, final bullet */
if ((ctx = appl_context(ctxname, 0)) == NULL) {
- oid = BER_OID(MIB_snmpUnknownContexts, 0);
snmp_target_mib.snmp_unknowncontexts++;
- if ((value = ober_add_integer(NULL,
- snmp_target_mib.snmp_unknowncontexts)) == NULL)
- fatal("ober_add_integer");
- appl_report(statereference, requestid, &oid, value);
+ appl_report(statereference, requestid,
+ &OID(MIB_snmpUnknownContexts, 0));
return;
}
ureq->aru_statereference = statereference;
ureq->aru_transactionid = transactionid++;
ureq->aru_requesttype = pdu->be_type;
+ ureq->aru_responsetype = SNMP_C_RESPONSE;
ureq->aru_requestid = requestid;
ureq->aru_error = APPL_ERROR_NOERROR;
ureq->aru_index = 0;
}
ureq->aru_vblist[i - 1].avi_varbind.av_next = NULL;
- appl_pdu_log(NULL, SNMP_C_RESPONSE, ureq->aru_requestid,
+ appl_pdu_log(NULL, ureq->aru_responsetype, ureq->aru_requestid,
ureq->aru_error, ureq->aru_index,
&(ureq->aru_vblist[0].avi_varbind));
varbindlist = varbind;
}
- snmpe_send(ureq->aru_statereference, SNMP_C_RESPONSE,
+ snmpe_send(ureq->aru_statereference, ureq->aru_responsetype,
ureq->aru_requestid, ureq->aru_error, ureq->aru_index, varbindlist);
ureq->aru_statereference = NULL;
appl_request_upstream_free(ureq);
}
void
-appl_report(struct snmp_message *msg, int32_t requestid, struct ber_oid *oid,
- struct ber_element *value)
+appl_report(struct snmp_message *statereference, int32_t requestid,
+ struct ber_oid *oid)
{
- struct ber_element *varbind;
-
- varbind = ober_printf_elements(NULL, "{Oe}", oid, value);
- if (varbind == NULL) {
- log_warn("%"PRId32": ober_printf_elements", requestid);
- ober_free_elements(value);
- snmp_msgfree(msg);
- return;
- }
+ struct appl_request_upstream *ureq;
- snmpe_send(msg, SNMP_C_REPORT, requestid, 0, 0, varbind);
+ if ((ureq = calloc(1, sizeof(*ureq))) == NULL)
+ fatal("malloc");
+ ureq->aru_ctx = appl_context(NULL, 0);
+ ureq->aru_statereference = statereference;
+ ureq->aru_requesttype = SNMP_C_GETREQ;
+ ureq->aru_responsetype = SNMP_C_REPORT;
+ ureq->aru_requestid = requestid;
+ ureq->aru_transactionid = 0;
+ ureq->aru_nonrepeaters = 0;
+ ureq->aru_maxrepetitions = 0;
+ if ((ureq->aru_vblist = calloc(1, sizeof(*ureq->aru_vblist))) == NULL)
+ fatal("malloc");
+ ureq->aru_varbindlen = 1;
+ ureq->aru_error = APPL_ERROR_NOERROR;
+ ureq->aru_index = 0;
+ ureq->aru_locked = 0;
+ ureq->aru_pduversion = SNMP_V3;
+
+ ureq->aru_vblist[0].avi_state = APPL_VBSTATE_NEW;
+ ureq->aru_vblist[0].avi_varbind.av_oid = *oid;
+ ureq->aru_vblist[0].avi_varbind.av_value = NULL;
+ ureq->aru_vblist[0].avi_varbind.av_next = NULL;
+ ureq->aru_vblist[0].avi_origid = *oid;
+ ureq->aru_vblist[0].avi_index = 1;
+ ureq->aru_vblist[0].avi_request_upstream = ureq;
+ ureq->aru_vblist[0].avi_request_downstream = NULL;
+ ureq->aru_vblist[0].avi_next = NULL;
+ ureq->aru_vblist[0].avi_sub = NULL;
+
+ appl_request_upstream_resolve(ureq);
}
struct ber_element *