Merge pull request #402 from doron2020/Yang_leaves_without_smiv2_oid_directive_are_not_shown+well_in_snmpwalk

Fixed: [Yang leaves without smiv2:oid directive are not shown well in…
This commit is contained in:
Olof Hagsand 2023-01-19 09:02:23 +01:00 committed by GitHub
commit fe291fe73d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)
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]){
@ -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;

View file

@ -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

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 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);

View file

@ -319,7 +319,9 @@ mibyang_table_register(clicon_handle h,
yleaf = NULL;
table_info->max_column = 0;
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++;
}
if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){