Fixed: [Yang leaves without smiv2:oid directive are not shown well in snmpwalk] (https://https://github.com/clicon/clixon/issues/398)

This commit is contained in:
doronb 2023-01-18 14:53:25 +02:00
parent 3428f4d5ff
commit c0526fad9c
4 changed files with 36 additions and 7 deletions

View file

@ -875,7 +875,7 @@ snmp_table_get(clicon_handle h,
if ((ret = yangext_oid_get(ys, oidleaf, &oidleaflen, NULL)) < 0) if ((ret = yangext_oid_get(ys, oidleaf, &oidleaflen, NULL)) < 0)
goto done; goto done;
if (ret == 0) if (ret == 0)
goto done; continue;
if (oidtlen + 1 != oidleaflen) /* Indexes may be from other OID scope, skip those */ if (oidtlen + 1 != oidleaflen) /* Indexes may be from other OID scope, skip those */
continue; continue;
if (oids[oidleaflen-1] == oidleaf[oidleaflen-1]) 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) if ((ret = yangext_oid_get(yi, oidleaf, &oidleaflen, NULL)) < 0)
goto done; goto done;
if (ret == 0) if (ret == 0)
goto done; continue;
if (oidtlen + 1 != oidleaflen) /* Indexes may be from other OID scope, skip those */ if (oidtlen + 1 != oidleaflen) /* Indexes may be from other OID scope, skip those */
continue; continue;
if (oids[oidleaflen-1] == oidleaf[oidleaflen-1]){ if (oids[oidleaflen-1] == oidleaf[oidleaflen-1]){
@ -1231,6 +1231,8 @@ snmp_table_getnext(clicon_handle h,
continue; continue;
if ((ret = yangext_oid_get(ycol, oidc, &oidclen, NULL)) < 0) if ((ret = yangext_oid_get(ycol, oidc, &oidclen, NULL)) < 0)
goto done; goto done;
if (ret == 0)
continue;
/* Append key oid */ /* Append key oid */
if (oid_append(oidc, &oidclen, oidk, oidklen) < 0) if (oid_append(oidc, &oidclen, oidk, oidklen) < 0)
goto done; goto done;

View file

@ -365,6 +365,30 @@ yangext_oid_get(yang_stmt *yn,
goto done; 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 /*! Duplicate clixon snmp handler struct
* Use signature of libnetsnmp data_clone field of netsnmp_mib_handler in agent_handler.h * Use signature of libnetsnmp data_clone field of netsnmp_mib_handler in agent_handler.h
* @param[in] arg * @param[in] arg

View file

@ -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 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 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_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); int snmp_access_str2int(char *modes_str);
const char *snmp_msg_int2str(int msg); const char *snmp_msg_int2str(int msg);
void *snmp_handle_clone(void *arg); void *snmp_handle_clone(void *arg);

View file

@ -319,7 +319,9 @@ mibyang_table_register(clicon_handle h,
yleaf = NULL; yleaf = NULL;
table_info->max_column = 0; table_info->max_column = 0;
while ((yleaf = yn_each(ylist, yleaf)) != NULL) { while ((yleaf = yn_each(ylist, yleaf)) != NULL) {
if (yang_keyword_get(yleaf) == Y_LEAF) if ((yang_keyword_get(yleaf) != Y_LEAF) || (ret = yangext_is_oid_exist(yleaf)) != 1)
continue;
table_info->max_column++; table_info->max_column++;
} }
if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){