Skip to content

Commit

Permalink
Fixed: [Yang leaves without smiv2:oid directive are not shown well in…
Browse files Browse the repository at this point in the history
… snmpwalk] (https://#398)
  • Loading branch information
doronb committed Jan 18, 2023
1 parent 3428f4d commit ac534a4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
8 changes: 5 additions & 3 deletions apps/snmp/snmp_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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]){
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions apps/snmp/snmp_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions apps/snmp/snmp_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions apps/snmp/snmp_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -317,10 +317,14 @@ mibyang_table_register(clicon_handle h,

/* Count columns */
yleaf = NULL;
table_info->max_column = 0;
table_info->max_column = 0;
oid oid3[MAX_OID_LEN] = {0,};
size_t oid3len = MAX_OID_LEN;
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");
Expand Down

0 comments on commit ac534a4

Please sign in to comment.