From 3428f4d5ffdeaf0dee48d783f470ebc9fdc5e0f3 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 16 Jan 2023 12:00:08 +0100 Subject: [PATCH] Fixed: [snmpwalk doesn't show properly SNMP boolean values which equal false](https://github.com/clicon/clixon/issues/400) --- CHANGELOG.md | 1 + apps/snmp/snmp_lib.c | 6 +++--- apps/snmp/snmp_main.c | 1 + test/test_snmp_entity.sh | 10 +++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e04bb037..c9cb01e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ Developers may need to change their code ### Corrected Bugs +* Fixed: [snmpwalk doesn't show properly SNMP boolean values which equal false](https://github.com/clicon/clixon/issues/400) * Fixed: yang-library: Remove revision if empty instead of sending empty revision * This was a change from RFC 7895 to RFC 8525 * Fixed: [locally scoped YANG typedef in grouping does not work #394](https://github.com/clicon/clixon/issues/394) diff --git a/apps/snmp/snmp_lib.c b/apps/snmp/snmp_lib.c index 7567db25..f3d8e9e8 100644 --- a/apps/snmp/snmp_lib.c +++ b/apps/snmp/snmp_lib.c @@ -651,11 +651,11 @@ type_xml2snmp_pre(char *xmlstr0, /* special case for bool: although smidump translates TruthValue to boolean * and there is an ASN_BOOLEAN constant: * 1) there is no code for ASN_BOOLEAN and - * 2) Truthvalue actually translates to enum true(1)/false(0) + * 2) Truthvalue actually translates to enum true(1)/false(2) */ else if (strcmp(restype, "boolean") == 0){ if (strcmp(xmlstr0, "false")==0) - str = "0"; + str = "2"; else str = "1"; } @@ -675,7 +675,7 @@ type_xml2snmp_pre(char *xmlstr0, goto done; } -/*! Given snmp string value (as translated frm XML) parse into snmp value +/*! Given snmp string value (as translated from XML) parse into snmp value * * @param[in] snmpstr SNMP type string * @param[in,out] asn1type ASN.1 type id diff --git a/apps/snmp/snmp_main.c b/apps/snmp/snmp_main.c index 0d3a0e99..5a4ccd43 100644 --- a/apps/snmp/snmp_main.c +++ b/apps/snmp/snmp_main.c @@ -525,6 +525,7 @@ main(int argc, * used by the client, even though new TCP sessions are created for * each message sent to the backend. */ + clicon_data_set(h, "session-transport", "cl:snmp"); if (clicon_hello_req(h, "cl:snmp", NULL, &id) < 0) goto done; clicon_session_id_set(h, id); diff --git a/test/test_snmp_entity.sh b/test/test_snmp_entity.sh index ad9639c4..cf806d91 100755 --- a/test/test_snmp_entity.sh +++ b/test/test_snmp_entity.sh @@ -468,12 +468,12 @@ validate_oid $OID29 $OID29 "INTEGER" "1" validate_oid $NAME29 $NAME29 "INTEGER" "true(1)" new "Get next fru, $OID29" -validate_oid $OID29 $OID30 "INTEGER" "0" -validate_oid $NAME29 $NAME30 "INTEGER" "0" +validate_oid $OID29 $OID30 "INTEGER" "2" +validate_oid $NAME29 $NAME30 "INTEGER" "false(2)" new "Get fru 2, $OID30" -validate_oid $OID30 $OID30 "INTEGER" "0" -validate_oid $NAME30 $NAME30 "INTEGER" "0" +validate_oid $OID30 $OID30 "INTEGER" "2" +validate_oid $NAME30 $NAME30 "INTEGER" "false(2)" new "Get next fru 2, $OID30" validate_oid $NAME30 $NAME31 "STRING" "12593-49-49,49:49:49.49" @@ -519,7 +519,7 @@ expectpart "$($snmpwalk $ENTITY_OID)" 0 "SNMPv2-SMI::mib-2.47.1.1.1.1.1.1 = INTE "SNMPv2-SMI::mib-2.47.1.1.1.1.15.1 = STRING: \"Asset 123\"" \ "SNMPv2-SMI::mib-2.47.1.1.1.1.15.2 = STRING: \"Asset 456\"" \ "SNMPv2-SMI::mib-2.47.1.1.1.1.16.1 = INTEGER: 1" \ - "SNMPv2-SMI::mib-2.47.1.1.1.1.16.2 = INTEGER: 0" \ + "SNMPv2-SMI::mib-2.47.1.1.1.1.16.2 = INTEGER: 2" \ new "Cleaning up" testexit