diff --git a/apps/snmp/snmp_lib.c b/apps/snmp/snmp_lib.c index 26151088..b08dcf2f 100644 --- a/apps/snmp/snmp_lib.c +++ b/apps/snmp/snmp_lib.c @@ -156,15 +156,17 @@ static const map_str2str yang_snmp_types[] = { { NULL, NULL} /* if not found */ }; - /* A function that checks that all subtypes of the union are the same + +/*! A function that checks that all subtypes of the union are the same + * * @param[in] ytype Yang resolved type (a union in this case) * @param[out] cb Buffer where type of subtypes is written - * @retval 1 - true(All subtypes are the same) - * @retval 0 - false + * @retval 1 true(All subtypes are the same) + * @retval 0 false */ -int +static int is_same_subtypes_union(yang_stmt *ytype, - cbuf *cb) + char **restype) { int retval = 0; yang_stmt *y_sub_type = NULL; @@ -188,34 +190,20 @@ is_same_subtypes_union(yang_stmt *ytype, &y_resolved_type, &options, &cvv, patterns, NULL, &fraction_digits) < 0 || ( NULL == y_resolved_type) ) break; - if( (NULL == (resolved_type_str = yang_argument_get(y_resolved_type))) ) + if ((resolved_type_str = yang_argument_get(y_resolved_type)) == NULL) break; - if( NULL == type_str || strcmp(type_str, resolved_type_str) == 0) + if (type_str == NULL || strcmp(type_str, resolved_type_str) == 0) type_str = resolved_type_str; else break; } - if (NULL == y_sub_type && NULL != type_str){ - cbuf_append_str(cb, resolved_type_str); + if (y_sub_type == NULL && type_str != NULL){ + *restype = resolved_type_str; retval = 1; } return retval; } -char* -yang_type_to_snmp(yang_stmt *ytype, - char* yang_type_str) -{ - char* type_str = yang_type_str; - if (yang_type_str && strcmp(yang_type_str, "union") == 0){ - cbuf *cb = cbuf_new(); - if (is_same_subtypes_union(ytype, cb) > 0) - type_str = cbuf_get(cb); - } - char* ret = clicon_str2str(yang_snmp_types, type_str); - return (NULL == ret) ? type_str : ret; -} - /*! Translate from snmp string to int representation * * @note Internal snmpd, maybe find something in netsnmpd? @@ -346,6 +334,7 @@ snmp_yang_type_get(yang_stmt *ys, int retval = -1; yang_stmt *yrestype; /* resolved type */ char *restype; /* resolved type */ + char *restype2; char *origtype = NULL; /* original type */ yang_stmt *ypath; yang_stmt *yref = NULL; @@ -354,8 +343,13 @@ snmp_yang_type_get(yang_stmt *ys, if (yang_type_get(ys, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0) goto done; restype = yrestype?yang_argument_get(yrestype):NULL; - restype = yang_type_to_snmp(yrestype, restype); - if (strcmp(restype, "leafref")==0){ + if (restype && strcmp(restype, "union") == 0){ + is_same_subtypes_union(yrestype, &restype); + + } + if ((restype2 = clicon_str2str(yang_snmp_types, restype)) == NULL) + restype2 = restype; + if (strcmp(restype2, "leafref")==0){ if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){ clicon_err(OE_YANG, 0, "No path in leafref"); goto done; @@ -372,7 +366,7 @@ snmp_yang_type_get(yang_stmt *ys, } if (yang_type_get(yref, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0) goto done; - restype = yrestype?yang_argument_get(yrestype):NULL; + restype2 = yrestype?yang_argument_get(yrestype):NULL; } if (yrefp){ if (yref) @@ -387,7 +381,7 @@ snmp_yang_type_get(yang_stmt *ys, if (yrestypep) *yrestypep = yrestype; if (restypep) - *restypep = restype; + *restypep = restype2; retval = 0; done: if (origtype) @@ -406,7 +400,7 @@ snmp_yang_type_get(yang_stmt *ys, * @retval 0 OK: Look in exist and value for return value * @retval -1 Error * - * @note This optimizatoin may not work if the unknown statements are augmented in ys. + * @note This optimization may not work if the unknown statements are augmented in ys. * @see yang_extension_value for the generic function */ int @@ -1395,4 +1389,3 @@ clixon_snmp_api_oid_find(oid *oid0, // done: return retval; } - diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile index 1eaa5e1c..789b00d5 100644 --- a/docker/test/Dockerfile +++ b/docker/test/Dockerfile @@ -96,6 +96,7 @@ RUN install -d /clixon/build/usr/local/bin/test RUN install *.sh /clixon/build/usr/local/bin/test RUN install *.exp /clixon/build/usr/local/bin/test RUN install clixon.png /clixon/build/usr/local/bin/test +RUN install *.supp /clixon/build/usr/local/bin/test RUN install -d /clixon/build/mibs RUN install mibs/* /clixon/build/mibs diff --git a/docker/test/Dockerfile.fcgi b/docker/test/Dockerfile.fcgi index 56b25a58..fe0d6952 100644 --- a/docker/test/Dockerfile.fcgi +++ b/docker/test/Dockerfile.fcgi @@ -104,6 +104,7 @@ RUN install -d /clixon/build/usr/local/bin/test RUN install *.sh /clixon/build/usr/local/bin/test RUN install *.exp /clixon/build/usr/local/bin/test RUN install clixon.png /clixon/build/usr/local/bin/test +RUN install *.supp /clixon/build/usr/local/bin/test RUN install -d /clixon/build/mibs RUN install mibs/* /clixon/build/mibs diff --git a/docker/test/Dockerfile.native b/docker/test/Dockerfile.native index 3e92c205..01350ee2 100644 --- a/docker/test/Dockerfile.native +++ b/docker/test/Dockerfile.native @@ -102,6 +102,7 @@ RUN install -d /clixon/build/usr/local/bin/test RUN install *.sh /clixon/build/usr/local/bin/test RUN install *.exp /clixon/build/usr/local/bin/test RUN install clixon.png /clixon/build/usr/local/bin/test +RUN install *.supp /clixon/build/usr/local/bin/test RUN install -d /clixon/build/mibs RUN install mibs/* /clixon/build/mibs diff --git a/docker/test/Makefile.in b/docker/test/Makefile.in index c151c2c0..7e186982 100644 --- a/docker/test/Makefile.in +++ b/docker/test/Makefile.in @@ -91,6 +91,13 @@ test: docker ./cleanup.sh ; ./start.sh # kill (ignore error) and the start it sudo docker exec -t clixon-test bash -c 'cd /usr/local/bin/test && detail=true ./sum.sh' +# Special-purpose memory test for snmp +memsnmp: docker + ./cleanup.sh ; ./start.sh # kill (ignore error) and the start it + sudo docker exec -t clixon-test bash -c 'sudo apk add --update valgrind; cd /usr/local/bin/test && pattern=test_snmp_union.sh ./mem.sh snmp' + +# sudo docker exec -t clixon-test bash -c 'sudo apk add --update valgrind; cd /usr/local/bin/test && pattern=test_snmp*.sh ./mem.sh snmp' + depend: install-include: diff --git a/test/test_snmp_entity.sh b/test/test_snmp_entity.sh index 080df494..bfb76567 100755 --- a/test/test_snmp_entity.sh +++ b/test/test_snmp_entity.sh @@ -127,7 +127,7 @@ function testinit(){ sudo killall -q clixon_snmp new "Starting clixon_snmp" - start_snmp $cfg & + start_snmp $cfg fi new "wait snmp" diff --git a/test/test_snmp_get.sh b/test/test_snmp_get.sh index 6330a468..6436b570 100755 --- a/test/test_snmp_get.sh +++ b/test/test_snmp_get.sh @@ -123,7 +123,7 @@ function testinit(){ sudo killall -q clixon_snmp new "Starting clixon_snmp" - start_snmp $cfg & + start_snmp $cfg fi new "wait snmp" diff --git a/test/test_snmp_ifmib.sh b/test/test_snmp_ifmib.sh index 685551e3..5d35a1b3 100755 --- a/test/test_snmp_ifmib.sh +++ b/test/test_snmp_ifmib.sh @@ -180,7 +180,7 @@ function testinit(){ sudo killall -q clixon_snmp new "Starting clixon_snmp" - start_snmp $cfg & + start_snmp $cfg fi new "wait snmp" diff --git a/test/test_snmp_rowstatus.sh b/test/test_snmp_rowstatus.sh index 6c58f14f..97fa67ee 100755 --- a/test/test_snmp_rowstatus.sh +++ b/test/test_snmp_rowstatus.sh @@ -90,7 +90,7 @@ function testinit(){ sudo killall -q clixon_snmp new "Starting clixon_snmp" - start_snmp $cfg & + start_snmp $cfg fi new "wait snmp" diff --git a/test/test_snmp_set.sh b/test/test_snmp_set.sh index 661afffb..97739d23 100755 --- a/test/test_snmp_set.sh +++ b/test/test_snmp_set.sh @@ -140,7 +140,7 @@ function testinit(){ sudo killall -q clixon_snmp new "Starting clixon_snmp" - start_snmp $cfg & + start_snmp $cfg fi new "wait snmp" diff --git a/test/test_snmp_system.sh b/test/test_snmp_system.sh index b3fd5cf8..450ac6e8 100755 --- a/test/test_snmp_system.sh +++ b/test/test_snmp_system.sh @@ -106,7 +106,7 @@ function testinit(){ new "Starting clixon_snmp" # XXX augmented objects seem to be registered twice: error: duplicate registration: MIB modules snmpSetSerialNo and AgentX subagent 52, session 0x562087a70e20, subsession 0x562087a820c0 (oid .1.3.6.1.6.3.1.1.6.1). - start_snmp $cfg & + start_snmp $cfg fi new "wait snmp" diff --git a/test/test_snmp_union.sh b/test/test_snmp_union.sh index 4fdf5ec5..42fcc8ab 100755 --- a/test/test_snmp_union.sh +++ b/test/test_snmp_union.sh @@ -116,7 +116,7 @@ function testinit(){ sudo killall -q clixon_snmp new "Starting clixon_snmp" - start_snmp $cfg & + start_snmp $cfg fi new "wait snmp"