-/* $OpenBSD: application_internal.c,v 1.2 2023/11/04 09:28:04 martijn Exp $ */
+/* $OpenBSD: application_internal.c,v 1.3 2023/11/04 09:30:28 martijn Exp $ */
/*
* Copyright (c) 2023 Martijn van Duren <martijn@openbsd.org>
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 ber_element *appl_internal_engine(struct ber_oid *);
+struct ber_element *appl_internal_usmstats(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 *);
NULL);
appl_internal_object(&OID(MIB_snmpProxyDrops), appl_internal_snmp,
NULL);
+
+ appl_internal_region(&OID(MIB_snmpV2));
+ appl_internal_object(&OID(MIB_snmpEngineID), appl_internal_engine,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpEngineBoots), appl_internal_engine,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpEngineTime), appl_internal_engine,
+ NULL);
+ appl_internal_object(&OID(MIB_snmpEngineMaxMsgSize),
+ appl_internal_engine, NULL);
+
+ appl_internal_object(&OID(MIB_usmStatsUnsupportedSecLevels),
+ appl_internal_usmstats, NULL);
+ appl_internal_object(&OID(MIB_usmStatsNotInTimeWindow),
+ appl_internal_usmstats, NULL);
+ appl_internal_object(&OID(MIB_usmStatsUnknownUserNames),
+ appl_internal_usmstats, NULL);
+ appl_internal_object(&OID(MIB_usmStatsUnknownEngineId),
+ appl_internal_usmstats, NULL);
+ appl_internal_object(&OID(MIB_usmStatsWrongDigests),
+ appl_internal_usmstats, NULL);
+ appl_internal_object(&OID(MIB_usmStatsDecryptionErrors),
+ appl_internal_usmstats, NULL);
}
void
return value;
}
+struct ber_element *
+appl_internal_engine(struct ber_oid *oid)
+{
+ if (ober_oid_cmp(&OID(MIB_snmpEngineID, 0), oid) == 0)
+ return ober_add_nstring(NULL, snmpd_env->sc_engineid,
+ snmpd_env->sc_engineid_len);
+ else if (ober_oid_cmp(&OID(MIB_snmpEngineBoots, 0), oid) == 0)
+ return ober_add_integer(NULL, snmpd_env->sc_engine_boots);
+ else if (ober_oid_cmp(&OID(MIB_snmpEngineTime, 0), oid) == 0)
+ return ober_add_integer(NULL, snmpd_engine_time());
+ else if (ober_oid_cmp(&OID(MIB_snmpEngineMaxMsgSize, 0), oid) == 0)
+ return ober_add_integer(NULL, READ_BUF_SIZE);
+ return NULL;
+}
+
+struct ber_element *
+appl_internal_usmstats(struct ber_oid *oid)
+{
+ struct snmp_stats *stats = &snmpd_env->sc_stats;
+ struct ber_element *value = NULL;
+
+ if (ober_oid_cmp(&OID(MIB_usmStatsUnsupportedSecLevels, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_usmbadseclevel);
+ else if (ober_oid_cmp(&OID(MIB_usmStatsNotInTimeWindow, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_usmtimewindow);
+ else if (ober_oid_cmp(&OID(MIB_usmStatsUnknownUserNames, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_usmnosuchuser);
+ else if (ober_oid_cmp(&OID(MIB_usmStatsUnknownEngineId, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_usmnosuchengine);
+ else if (ober_oid_cmp(&OID(MIB_usmStatsWrongDigests, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_usmwrongdigest);
+ else if (ober_oid_cmp(&OID(MIB_usmStatsDecryptionErrors, 0), oid) == 0)
+ value = ober_add_integer(NULL, stats->snmp_usmdecrypterr);
+
+ 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.106 2023/11/04 09:28:04 martijn Exp $ */
+/* $OpenBSD: mib.c,v 1.107 2023/11/04 09:30:28 martijn Exp $ */
/*
* Copyright (c) 2012 Joel Knight <joel@openbsd.org>
return (0);
}
-/*
- * Defined in SNMP-USER-BASED-SM-MIB.txt (RFC 3414)
- */
-int mib_engine(struct oid *, struct ber_oid *, struct ber_element **);
-int mib_usmstats(struct oid *, struct ber_oid *, struct ber_element **);
-
-static struct oid usm_mib[] = {
- { MIB(snmpEngine), OID_MIB },
- { MIB(snmpEngineID), OID_RD, mib_engine },
- { MIB(snmpEngineBoots), OID_RD, mib_engine },
- { MIB(snmpEngineTime), OID_RD, mib_engine },
- { MIB(snmpEngineMaxMsgSize), OID_RD, mib_engine },
- { MIB(usmStats), OID_MIB },
- { MIB(usmStatsUnsupportedSecLevels), OID_RD, mib_usmstats },
- { MIB(usmStatsNotInTimeWindow), OID_RD, mib_usmstats },
- { MIB(usmStatsUnknownUserNames), OID_RD, mib_usmstats },
- { MIB(usmStatsUnknownEngineId), OID_RD, mib_usmstats },
- { MIB(usmStatsWrongDigests), OID_RD, mib_usmstats },
- { MIB(usmStatsDecryptionErrors), OID_RD, mib_usmstats },
- { MIBEND }
-};
-
-int
-mib_engine(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
-{
- switch (oid->o_oid[OIDIDX_snmpEngine]) {
- case 1:
- *elm = ober_add_nstring(*elm, snmpd_env->sc_engineid,
- snmpd_env->sc_engineid_len);
- break;
- case 2:
- *elm = ober_add_integer(*elm, snmpd_env->sc_engine_boots);
- break;
- case 3:
- *elm = ober_add_integer(*elm, snmpd_engine_time());
- break;
- case 4:
- *elm = ober_add_integer(*elm, READ_BUF_SIZE);
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-int
-mib_usmstats(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[] = {
- { OIDVAL_usmErrSecLevel, &stats->snmp_usmbadseclevel },
- { OIDVAL_usmErrTimeWindow, &stats->snmp_usmtimewindow },
- { OIDVAL_usmErrUserName, &stats->snmp_usmnosuchuser },
- { OIDVAL_usmErrEngineId, &stats->snmp_usmnosuchengine },
- { OIDVAL_usmErrDigest, &stats->snmp_usmwrongdigest },
- { OIDVAL_usmErrDecrypt, &stats->snmp_usmdecrypterr },
- };
-
- for (i = 0; (u_int)i < (sizeof(mapping) / sizeof(mapping[0])); i++) {
- if (oid->o_oid[OIDIDX_usmStats] == 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);
-}
-
/*
* Import all MIBs
*/
/* SNMPv2-MIB */
smi_mibtree(base_mib);
-
- /* SNMP-USER-BASED-SM-MIB */
- smi_mibtree(usm_mib);
}