-/* $OpenBSD: application_internal.c,v 1.1 2023/11/04 09:22:52 martijn Exp $ */
+/* $OpenBSD: application_internal.c,v 1.2 2023/11/04 09:28:04 martijn Exp $ */
/*
* Copyright (c) 2023 Martijn van Duren <martijn@openbsd.org>
struct appl_varbind *);
void appl_internal_getnext(struct appl_backend *, int32_t, int32_t,
const char *, struct appl_varbind *);
+struct ber_element *appl_internal_snmp(struct ber_oid *);
struct appl_internal_object *appl_internal_object_parent(struct ber_oid *);
int appl_internal_object_cmp(struct appl_internal_object *,
struct appl_internal_object *);
void
appl_internal_init(void)
{
+ appl_internal_region(&OID(MIB_snmp));
+ appl_internal_object(&OID(MIB_snmpInPkts), appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpOutPkts), appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpInBadVersions), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInBadCommunityNames),
+ appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpInBadCommunityUses),
+ appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpInASNParseErrs), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInTooBigs), appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpInNoSuchNames), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInBadValues), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInReadOnlys), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInReadOnlys), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInGenErrs), appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpInTotalReqVars), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInTotalSetVars), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInGetRequests), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInGetNexts), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInSetRequests), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInGetResponses), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpInTraps), appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpOutTooBigs), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpOutNoSuchNames), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpOutBadValues), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpOutGenErrs), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpOutGetRequests), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpOutGetNexts), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpOutSetRequests), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpOutGetResponses), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpOutTraps), appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpEnableAuthenTraps),
+ appl_internal_snmp, NULL);
+ appl_internal_object(&OID(MIB_snmpSilentDrops), appl_internal_snmp,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpProxyDrops), appl_internal_snmp,
+ NULL);
}
void
appl_response(backend, requestid, APPL_ERROR_GENERR, i + 1, vblist);
}
+struct ber_element *
+appl_internal_snmp(struct ber_oid *oid)
+{
+ struct snmp_stats *stats = &snmpd_env->sc_stats;
+ struct ber_element *value = NULL;
+
+ if (ober_oid_cmp(oid, &OID(MIB_snmpEnableAuthenTraps, 0)) == 0)
+ return ober_add_integer(NULL,
+ stats->snmp_enableauthentraps ? 1 : 2);
+ if (ober_oid_cmp(&OID(MIB_snmpInPkts, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_inpkts);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutPkts, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outpkts);
+ else if (ober_oid_cmp(&OID(MIB_snmpInBadVersions, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_inbadversions);
+ else if (ober_oid_cmp(&OID(MIB_snmpInBadCommunityNames, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_inbadcommunitynames);
+ else if (ober_oid_cmp(&OID(MIB_snmpInBadCommunityUses, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_inbadcommunityuses);
+ else if (ober_oid_cmp(&OID(MIB_snmpInASNParseErrs, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_inasnparseerrs);
+ else if (ober_oid_cmp(&OID(MIB_snmpInTooBigs, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_intoobigs);
+ else if (ober_oid_cmp(&OID(MIB_snmpInNoSuchNames, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_innosuchnames);
+ else if (ober_oid_cmp(&OID(MIB_snmpInBadValues, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_inbadvalues);
+ else if (ober_oid_cmp(&OID(MIB_snmpInReadOnlys, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_inreadonlys);
+ else if (ober_oid_cmp(&OID(MIB_snmpInGenErrs, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_ingenerrs);
+ else if (ober_oid_cmp(&OID(MIB_snmpInTotalReqVars, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_intotalreqvars);
+ else if (ober_oid_cmp(&OID(MIB_snmpInTotalSetVars, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_intotalsetvars);
+ else if (ober_oid_cmp(&OID(MIB_snmpInGetRequests, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_ingetrequests);
+ else if (ober_oid_cmp(&OID(MIB_snmpInGetNexts, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_ingetnexts);
+ else if (ober_oid_cmp(&OID(MIB_snmpInSetRequests, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_insetrequests);
+ else if (ober_oid_cmp(&OID(MIB_snmpInGetResponses, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_ingetresponses);
+ else if (ober_oid_cmp(&OID(MIB_snmpInTraps, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_intraps);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutTooBigs, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outtoobigs);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutNoSuchNames, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outnosuchnames);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutBadValues, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outbadvalues);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutGenErrs, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outgenerrs);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutGetRequests, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outgetrequests);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutGetNexts, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outgetnexts);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutSetRequests, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outsetrequests);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutGetResponses, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outgetresponses);
+ else if (ober_oid_cmp(&OID(MIB_snmpOutTraps, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_outtraps);
+ else if (ober_oid_cmp(&OID(MIB_snmpSilentDrops, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_silentdrops);
+ else if (ober_oid_cmp(&OID(MIB_snmpProxyDrops, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_proxydrops);
+
+ if (value != NULL)
+ ober_set_header(value, BER_CLASS_APPLICATION, SNMP_T_COUNTER32);
+ return value;
+}
+
struct appl_internal_object *
appl_internal_object_parent(struct ber_oid *oid)
{
-/* $OpenBSD: mib.c,v 1.105 2022/10/06 14:41:08 martijn Exp $ */
+/* $OpenBSD: mib.c,v 1.106 2023/11/04 09:28:04 martijn Exp $ */
/*
* Copyright (c) 2012 Joel Knight <joel@openbsd.org>
*/
int mib_getsys(struct oid *, struct ber_oid *, struct ber_element **);
-int mib_getsnmp(struct oid *, struct ber_oid *, struct ber_element **);
int mib_sysor(struct oid *, struct ber_oid *, struct ber_element **);
-int mib_setsnmp(struct oid *, struct ber_oid *, struct ber_element **);
static struct oid mib_tree[] = MIB_TREE;
{ MIB(sysORID), OID_TRD, mib_sysor },
{ MIB(sysORDescr), OID_TRD, mib_sysor },
{ MIB(sysORUpTime), OID_TRD, mib_sysor },
- { MIB(snmp), OID_MIB },
- { MIB(snmpInPkts), OID_RD, mib_getsnmp },
- { MIB(snmpOutPkts), OID_RD, mib_getsnmp },
- { MIB(snmpInBadVersions), OID_RD, mib_getsnmp },
- { MIB(snmpInBadCommunityNames), OID_RD, mib_getsnmp },
- { MIB(snmpInBadCommunityUses), OID_RD, mib_getsnmp },
- { MIB(snmpInASNParseErrs), OID_RD, mib_getsnmp },
- { MIB(snmpInTooBigs), OID_RD, mib_getsnmp },
- { MIB(snmpInNoSuchNames), OID_RD, mib_getsnmp },
- { MIB(snmpInBadValues), OID_RD, mib_getsnmp },
- { MIB(snmpInReadOnlys), OID_RD, mib_getsnmp },
- { MIB(snmpInGenErrs), OID_RD, mib_getsnmp },
- { MIB(snmpInTotalReqVars), OID_RD, mib_getsnmp },
- { MIB(snmpInTotalSetVars), OID_RD, mib_getsnmp },
- { MIB(snmpInGetRequests), OID_RD, mib_getsnmp },
- { MIB(snmpInGetNexts), OID_RD, mib_getsnmp },
- { MIB(snmpInSetRequests), OID_RD, mib_getsnmp },
- { MIB(snmpInGetResponses), OID_RD, mib_getsnmp },
- { MIB(snmpInTraps), OID_RD, mib_getsnmp },
- { MIB(snmpOutTooBigs), OID_RD, mib_getsnmp },
- { MIB(snmpOutNoSuchNames), OID_RD, mib_getsnmp },
- { MIB(snmpOutBadValues), OID_RD, mib_getsnmp },
- { MIB(snmpOutGenErrs), OID_RD, mib_getsnmp },
- { MIB(snmpOutGetRequests), OID_RD, mib_getsnmp },
- { MIB(snmpOutGetNexts), OID_RD, mib_getsnmp },
- { MIB(snmpOutSetRequests), OID_RD, mib_getsnmp },
- { MIB(snmpOutGetResponses), OID_RD, mib_getsnmp },
- { MIB(snmpOutTraps), OID_RD, mib_getsnmp },
- { MIB(snmpEnableAuthenTraps), OID_RD, mib_getsnmp },
- { MIB(snmpSilentDrops), OID_RD, mib_getsnmp },
- { MIB(snmpProxyDrops), OID_RD, mib_getsnmp },
{ MIBEND }
};
return (0);
}
-int
-mib_getsnmp(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
-{
- struct snmp_stats *stats = &snmpd_env->sc_stats;
- long long i;
- struct statsmap {
- u_int8_t m_id;
- u_int32_t *m_ptr;
- } mapping[] = {
- { 1, &stats->snmp_inpkts },
- { 2, &stats->snmp_outpkts },
- { 3, &stats->snmp_inbadversions },
- { 4, &stats->snmp_inbadcommunitynames },
- { 5, &stats->snmp_inbadcommunityuses },
- { 6, &stats->snmp_inasnparseerrs },
- { 8, &stats->snmp_intoobigs },
- { 9, &stats->snmp_innosuchnames },
- { 10, &stats->snmp_inbadvalues },
- { 11, &stats->snmp_inreadonlys },
- { 12, &stats->snmp_ingenerrs },
- { 13, &stats->snmp_intotalreqvars },
- { 14, &stats->snmp_intotalsetvars },
- { 15, &stats->snmp_ingetrequests },
- { 16, &stats->snmp_ingetnexts },
- { 17, &stats->snmp_insetrequests },
- { 18, &stats->snmp_ingetresponses },
- { 19, &stats->snmp_intraps },
- { 20, &stats->snmp_outtoobigs },
- { 21, &stats->snmp_outnosuchnames },
- { 22, &stats->snmp_outbadvalues },
- { 24, &stats->snmp_outgenerrs },
- { 25, &stats->snmp_outgetrequests },
- { 26, &stats->snmp_outgetnexts },
- { 27, &stats->snmp_outsetrequests },
- { 28, &stats->snmp_outgetresponses },
- { 29, &stats->snmp_outtraps },
- { 31, &stats->snmp_silentdrops },
- { 32, &stats->snmp_proxydrops }
- };
-
- switch (oid->o_oid[OIDIDX_snmp]) {
- case 30:
- i = stats->snmp_enableauthentraps == 1 ? 1 : 2;
- *elm = ober_add_integer(*elm, i);
- break;
- default:
- for (i = 0;
- (u_int)i < (sizeof(mapping) / sizeof(mapping[0])); i++) {
- if (oid->o_oid[OIDIDX_snmp] == mapping[i].m_id) {
- *elm = ober_add_integer(*elm, *mapping[i].m_ptr);
- ober_set_header(*elm,
- BER_CLASS_APPLICATION, SNMP_T_COUNTER32);
- return (0);
- }
- }
- return (-1);
- }
-
- return (0);
-}
-
-int
-mib_setsnmp(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
-{
- struct snmp_stats *stats = &snmpd_env->sc_stats;
- long long i;
-
- if (ober_get_integer(*elm, &i) == -1)
- return (-1);
-
- stats->snmp_enableauthentraps = i == 1 ? 1 : 0;
-
- return (0);
-}
-
/*
* Defined in SNMP-USER-BASED-SM-MIB.txt (RFC 3414)
*/