From c0526fad9ca2aeec5e9397ead2967a98ae0a9c2b Mon Sep 17 00:00:00 2001 From: doronb Date: Wed, 18 Jan 2023 14:53:25 +0200 Subject: [PATCH] Fixed: [Yang leaves without smiv2:oid directive are not shown well in snmpwalk] (https://https://github.com/clicon/clixon/issues/398) --- apps/snmp/snmp_handler.c | 8 +++++--- apps/snmp/snmp_lib.c | 24 ++++++++++++++++++++++++ apps/snmp/snmp_lib.h | 1 + apps/snmp/snmp_register.c | 10 ++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index 4eca4ff2..cd06b4c7 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -875,7 +875,7 @@ snmp_table_get(clicon_handle h, if ((ret = yangext_oid_get(ys, oidleaf, &oidleaflen, NULL)) < 0) goto done; if (ret == 0) - goto done; + continue; if (oidtlen + 1 != oidleaflen) /* Indexes may be from other OID scope, skip those */ continue; if (oids[oidleaflen-1] == oidleaf[oidleaflen-1]) @@ -1003,7 +1003,7 @@ snmp_table_set(clicon_handle h, if ((ret = yangext_oid_get(yi, oidleaf, &oidleaflen, NULL)) < 0) goto done; if (ret == 0) - goto done; + continue; if (oidtlen + 1 != oidleaflen) /* Indexes may be from other OID scope, skip those */ continue; if (oids[oidleaflen-1] == oidleaf[oidleaflen-1]){ @@ -1090,7 +1090,7 @@ snmp_table_set(clicon_handle h, cvk_val, &rowstatus)) < 0) goto done; - } + } else{ /* If no rowstatus object, default to active */ rowstatus = 1; @@ -1231,6 +1231,8 @@ snmp_table_getnext(clicon_handle h, continue; if ((ret = yangext_oid_get(ycol, oidc, &oidclen, NULL)) < 0) goto done; + if (ret == 0) + continue; /* Append key oid */ if (oid_append(oidc, &oidclen, oidk, oidklen) < 0) goto done; diff --git a/apps/snmp/snmp_lib.c b/apps/snmp/snmp_lib.c index f3d8e9e8..3ba50f4c 100644 --- a/apps/snmp/snmp_lib.c +++ b/apps/snmp/snmp_lib.c @@ -365,6 +365,30 @@ yangext_oid_get(yang_stmt *yn, goto done; } + + +/*! Given a YANG node, return 1 if leaf has oid directive in it, otherwise 0 + * @param[in] yn Yang node + * @retval 1 found + * @retval 0 not found + */ +int yangext_is_oid_exist(yang_stmt *yn) { + + int exist = 0; + char *oidstr = NULL; + + if ((yang_keyword_get(yn) != Y_LEAF) || + (yang_extension_value(yn, "oid", IETF_YANG_SMIV2_NS, &exist, &oidstr) < 0) || + (exist == 0) || + (oidstr == NULL)) { + return 0; + } + else { + return 1; + } +} + + /*! Duplicate clixon snmp handler struct * Use signature of libnetsnmp data_clone field of netsnmp_mib_handler in agent_handler.h * @param[in] arg diff --git a/apps/snmp/snmp_lib.h b/apps/snmp/snmp_lib.h index dae6ed1e..c86a58a6 100644 --- a/apps/snmp/snmp_lib.h +++ b/apps/snmp/snmp_lib.h @@ -87,6 +87,7 @@ int oid_cbuf(cbuf *cb, const oid *objid, size_t objidlen); int oid_print(FILE *f, const oid *objid, size_t objidlen); int snmp_yang_type_get(yang_stmt *ys, yang_stmt **yrefp, char **origtypep, yang_stmt **yrestypep, char **restypep); int yangext_oid_get(yang_stmt *yn, oid *objid, size_t *objidlen, char **objidstr); +int yangext_is_oid_exist(yang_stmt *yn); int snmp_access_str2int(char *modes_str); const char *snmp_msg_int2str(int msg); void *snmp_handle_clone(void *arg); diff --git a/apps/snmp/snmp_register.c b/apps/snmp/snmp_register.c index 0868eb25..52883a6e 100644 --- a/apps/snmp/snmp_register.c +++ b/apps/snmp/snmp_register.c @@ -192,7 +192,7 @@ mibyang_leaf_register(clicon_handle h, } oid_cbuf(cboid, oid1, oid1len); clicon_debug(1, "%s register: %s %s", __FUNCTION__, name, cbuf_get(cboid)); - ok: + ok: retval = 0; done: if (cboid) @@ -317,10 +317,12 @@ mibyang_table_register(clicon_handle h, /* Count columns */ yleaf = NULL; - table_info->max_column = 0; + table_info->max_column = 0; while ((yleaf = yn_each(ylist, yleaf)) != NULL) { - if (yang_keyword_get(yleaf) == Y_LEAF) - table_info->max_column++; + if ((yang_keyword_get(yleaf) != Y_LEAF) || (ret = yangext_is_oid_exist(yleaf)) != 1) + continue; + + table_info->max_column++; } if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){ clicon_err(OE_SNMP, ret, "netsnmp_register_table");