diff options
author | 2020-12-14 07:44:26 +0000 | |
---|---|---|
committer | 2020-12-14 07:44:26 +0000 | |
commit | dd843e541a326b4672a5eb32ef5ba66c9df5593e (patch) | |
tree | 4dcf281627a9ef606cda815697dd8efa8a77e6c0 | |
parent | use _PATH_SSH_USER_DIR instead of hardcoded .ssh in path (diff) | |
download | wireguard-openbsd-dd843e541a326b4672a5eb32ef5ba66c9df5593e.tar.xz wireguard-openbsd-dd843e541a326b4672a5eb32ef5ba66c9df5593e.zip |
Implement displaying SMI enums as text.
For now limit to TruthValue implemented on ifPromiscuousMode and
ifConnectorPresent.
OK jan@
-rw-r--r-- | usr.bin/snmp/mib.h | 19 | ||||
-rw-r--r-- | usr.bin/snmp/smi.c | 32 | ||||
-rw-r--r-- | usr.bin/snmp/smi.h | 10 |
3 files changed, 51 insertions, 10 deletions
diff --git a/usr.bin/snmp/mib.h b/usr.bin/snmp/mib.h index 38764d7082e..3e8cc5c302e 100644 --- a/usr.bin/snmp/mib.h +++ b/usr.bin/snmp/mib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.h,v 1.8 2020/09/12 18:11:43 martijn Exp $ */ +/* $OpenBSD: mib.h,v 1.9 2020/12/14 07:44:26 martijn Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org> @@ -1034,8 +1034,8 @@ { MIBDECL(ifHCOutBroadcastPkts) }, \ { MIBDECL(ifLinkUpDownTrapEnable) }, \ { MIBDECL(ifHighSpeed) }, \ - { MIBDECL(ifPromiscuousMode) }, \ - { MIBDECL(ifConnectorPresent) }, \ + { MIBDECL(ifPromiscuousMode), "TruthValue" }, \ + { MIBDECL(ifConnectorPresent), "TruthValue" }, \ { MIBDECL(ifAlias) }, \ { MIBDECL(ifCounterDiscontinuityTime) }, \ { MIBDECL(ifStackTable) }, \ @@ -1460,10 +1460,15 @@ { MIBEND } \ } -#define TEXTCONV_TREE { \ - { "SnmpAdminString", "255t", BER_TYPE_OCTETSTRING }, \ - { "DisplayString", "255a", BER_TYPE_OCTETSTRING }, \ - { NULL, NULL } \ +#define TEXTCONV_TREE { \ + { "SnmpAdminString", BER_TYPE_OCTETSTRING, "255t" }, \ + { "DisplayString", BER_TYPE_OCTETSTRING, "255a" }, \ + { "TruthValue", BER_TYPE_INTEGER, NULL, (struct textconv_enum[]){\ + { 1, "true" }, \ + { 2, "false" }, \ + { 0, NULL } \ + }}, \ + { NULL } \ } void mib_init(void); diff --git a/usr.bin/snmp/smi.c b/usr.bin/snmp/smi.c index 804a6830d1e..ae2768370db 100644 --- a/usr.bin/snmp/smi.c +++ b/usr.bin/snmp/smi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smi.c,v 1.12 2020/08/08 13:02:54 martijn Exp $ */ +/* $OpenBSD: smi.c,v 1.13 2020/12/14 07:44:26 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org> @@ -39,6 +39,7 @@ #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) char *smi_displayhint_os(struct textconv *, int, const char *, size_t, int); +char *smi_displayhint_int(struct textconv*, int, long long); int smi_oid_cmp(struct oid *, struct oid *); int smi_key_cmp(struct oid *, struct oid *); @@ -345,6 +346,10 @@ smi_print_element(struct ber_oid *oid, struct ber_element *root, int print_hint, break; } hint = "INTEGER: "; + if (object != NULL && object->o_textconv != NULL && + object->o_textconv->tc_syntax == root->be_encoding) + return smi_displayhint_int(object->o_textconv, + print_hint, v); if (root->be_class == BER_CLASS_APPLICATION) { if (root->be_type == SNMP_T_COUNTER32) hint = "Counter32: "; @@ -630,6 +635,31 @@ smi_foreach(struct oid *oid) return RB_NEXT(oidtree, &smi_oidtree, oid); } +char * +smi_displayhint_int(struct textconv *tc, int print_hint, long long v) +{ + size_t i; + char *rbuf; + + for (i = 0; tc->tc_enum[i].tce_name != NULL; i++) { + if (tc->tc_enum[i].tce_number == v) { + if (print_hint) { + if (asprintf(&rbuf, "INTEGER: %s(%lld)", + tc->tc_enum[i].tce_name, v) == -1) + return NULL; + } else { + if (asprintf(&rbuf, "%s", + tc->tc_enum[i].tce_name) == -1) + return NULL; + } + return rbuf; + } + } + if (asprintf(&rbuf, "%s%lld", print_hint ? "INTEGER: " : "", v) == -1) + return NULL; + return rbuf; +} + #define REPLACEMENT "\357\277\275" char * smi_displayhint_os(struct textconv *tc, int print_hint, const char *src, diff --git a/usr.bin/snmp/smi.h b/usr.bin/snmp/smi.h index eeb8cbc8de9..1c3fbf1ab66 100644 --- a/usr.bin/snmp/smi.h +++ b/usr.bin/snmp/smi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smi.h,v 1.3 2020/08/03 14:45:54 martijn Exp $ */ +/* $OpenBSD: smi.h,v 1.4 2020/12/14 07:44:26 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org> @@ -67,10 +67,16 @@ struct oid { RB_ENTRY(oid) o_keyword; }; +struct textconv_enum { + uint32_t tce_number; + const char *tce_name; +}; + struct textconv { const char *tc_name; - const char *tc_display_hint; unsigned int tc_syntax; + const char *tc_display_hint; + struct textconv_enum *tc_enum; RB_ENTRY(textconv) tc_entry; }; |