From 78c070b65be53f10a2e932f5f0f95c780e393d54 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 6 Jun 2022 18:14:21 +0200 Subject: [PATCH] SNMP frontend: String table index --- apps/snmp/snmp_handler.c | 2 +- apps/snmp/snmp_lib.c | 23 +++++++++---- apps/snmp/snmp_lib.h | 3 +- apps/snmp/snmp_register.c | 69 ++++++++++++++++++++++++++------------- 4 files changed, 66 insertions(+), 31 deletions(-) diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index e591d620..dfa90cde 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -377,7 +377,7 @@ clixon_snmp_scalar_handler(netsnmp_mib_handler *handler, /* see net-snmp/agent/snmp_agent.h / net-snmp/library/snmp.h */ switch (reqinfo->mode) { case MODE_GET: /* 160 */ - if (snmp_scalar_get(sh->sh_h, ys, sh->sh_cvk, + if (snmp_scalar_get(sh->sh_h, ys, sh->sh_cvk_orig, requestvb, sh->sh_default, reqinfo, requests) < 0) goto done; break; diff --git a/apps/snmp/snmp_lib.c b/apps/snmp/snmp_lib.c index 9bb9cfc6..1ccdec99 100644 --- a/apps/snmp/snmp_lib.c +++ b/apps/snmp/snmp_lib.c @@ -157,8 +157,13 @@ snmp_handle_clone(void *arg) return NULL; } memset(sh1, 0, sizeof(*sh1)); - if (sh0->sh_cvk && - (sh1->sh_cvk = cvec_dup(sh0->sh_cvk)) == NULL){ + if (sh0->sh_cvk_orig && + (sh1->sh_cvk_orig = cvec_dup(sh0->sh_cvk_orig)) == NULL){ + clicon_err(OE_UNIX, errno, "cvec_dup"); + return NULL; + } + if (sh0->sh_cvk_oid && + (sh1->sh_cvk_oid = cvec_dup(sh0->sh_cvk_oid)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_dup"); return NULL; } @@ -175,8 +180,10 @@ snmp_handle_free(void *arg) clixon_snmp_handle *sh = (clixon_snmp_handle *)arg; if (sh != NULL){ - if (sh->sh_cvk) - cvec_free(sh->sh_cvk); + if (sh->sh_cvk_orig) + cvec_free(sh->sh_cvk_orig); + if (sh->sh_cvk_oid) + cvec_free(sh->sh_cvk_oid); if (sh->sh_table_info){ if (sh->sh_table_info->indexes){ snmp_free_varbind(sh->sh_table_info->indexes); @@ -685,7 +692,9 @@ yang2xpath(yang_stmt *ys, return retval; } -/*! +/*! Translate from xml body to OID + * For ints this is one to one, eg 42 -> 42 + * But for eg strings this is more comples, eg foo -> 3.6.22.22 (or something,...) */ int snmp_body2oid(cxobj *xi, @@ -712,7 +721,7 @@ snmp_body2oid(cxobj *xi, case ASN_COUNTER: case ASN_IPADDRESS: if (cv_string_set(cv, body) < 0){ - clicon_err(OE_UNIX,errno, "cv_string_set"); + clicon_err(OE_UNIX, errno, "cv_string_set"); goto done; } break; @@ -726,7 +735,7 @@ snmp_body2oid(cxobj *xi, for (i=0; ish_oid, oid1, sizeof(oid1)); sh->sh_oidlen = sz1; sh->sh_default = default_str; - if (cvk && - (sh->sh_cvk = cvec_dup(cvk)) == NULL){ + if (cvk_orig && + (sh->sh_cvk_orig = cvec_dup(cvk_orig)) == NULL){ + clicon_err(OE_UNIX, errno, "cvec_dup"); + goto done; + } + if (cvk_oid && + (sh->sh_cvk_oid = cvec_dup(cvk_oid)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_dup"); goto done; } @@ -363,9 +371,10 @@ mibyang_table_traverse_static(clicon_handle h, cxobj *xrow; cxobj *xcol; yang_stmt *y; - cvec *cvk0; + cvec *cvk_name; cg_var *cv0; - cvec *cvk = NULL; /* vector of index keys */ + cvec *cvk_orig = NULL; /* vector of index keys: original index */ + cvec *cvk_oid = NULL; /* vector of index keys: translated to OID */ cg_var *cv; int i; cxobj *xi; @@ -383,35 +392,48 @@ mibyang_table_traverse_static(clicon_handle h, } if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) { /* Make a clone of key-list, but replace names with values */ - if ((cvk0 = yang_cvec_get(ylist)) == NULL){ + if ((cvk_name = yang_cvec_get(ylist)) == NULL){ clicon_err(OE_YANG, 0, "No keys"); goto done; } xrow = NULL; while ((xrow = xml_child_each(xtable, xrow, CX_ELMNT)) != NULL) { - if (cvk){ - cvec_free(cvk); - cvk = NULL; + if (cvk_orig){ + cvec_free(cvk_orig); + cvk_orig = NULL; } - if ((cvk = cvec_dup(cvk0)) == NULL){ + if ((cvk_orig = cvec_dup(cvk_name)) == NULL){ clicon_err(OE_UNIX, errno, "cvec_dup"); goto done; } - for (i=0; i