From f112580546e72c6f792ffe83c30a023b4f557d6f Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 2 May 2022 17:20:22 +0200 Subject: [PATCH] SNMP MIB->YANG translation file handling. Added configure option --with-mib-generated-yang-dir=DIR with default value /usr/share/mibyang where generated YANGs from MIBs should be placed so that SNMP tests know where to find the YANGs. --- CHANGELOG.md | 3 +++ configure | 24 ++++++++++++++++++++++++ configure.ac | 14 ++++++++++++++ lib/src/clixon_yang_parse_lib.c | 5 ++++- test/config.sh.in | 1 + test/test_snmp.sh | 6 ++++++ test/test_snmp_table.sh | 6 ++++++ 7 files changed, 58 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 597cecf2..3c8e9a5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,9 @@ * YANG `clixon-config@2022-03-21.yang` changes: * Added option: * `CLICON_SNMP_AGENT_SOCK` + * New configure options: + * `--enable-netsnmp` + * `--with-mib-generated-yang-dir=DIR` * Thanks Siklu for sponshoring ## 5.8.0 diff --git a/configure b/configure index c49dafae..e2768846 100755 --- a/configure +++ b/configure @@ -632,6 +632,7 @@ ac_ct_CXX CXXFLAGS CXX CPP +MIB_GENERATED_YANG_DIR YANG_STANDARD_DIR YANG_INSTALLDIR CLIXON_YANG_PATCH @@ -724,6 +725,7 @@ with_restconf enable_http1 enable_nghttp2 enable_netsnmp +with_mib_generated_yang_dir with_configfile with_libxml2 with_sigaction @@ -1387,6 +1389,9 @@ Optional Packages: --with-restconf=fcgi FCGI interface for stand-alone web rev-proxy eg nginx --without-restconf Disable restconf altogether + --with-mib-generated-yang-dir=DIR + Directory of generated YANG specs (default: + $prefix/share/mibyang) --with-configfile=FILE Set default path to config file --with-libxml2 Use gnome/libxml2 regex engine --without-sigaction Don't use sigaction @@ -3400,6 +3405,8 @@ HAVE_HTTP1=false # Examples require standard IETF YANGs. You need to provide these for example and tests +# SNMP tests require generated YANGs from MIBs + # ac_ext=c @@ -5429,6 +5436,23 @@ fi done + + + # MIB_GENERATED_YANG_DIR is where clixon assumes generated YANGs from MIBs are stored + # This is NOT installed by Clixon and is not needed for core system + # However, it is required by SNMP tests. + # To generate: for i in /usr/share/snmp/mibs/*; do smidump -f yang $i > `basename -s .txt $i`.yang; done + +# Check whether --with-mib-generated-yang-dir was given. +if test "${with_mib_generated_yang_dir+set}" = set; then : + withval=$with_mib_generated_yang_dir; MIB_GENERATED_YANG_DIR="$withval" +else + MIB_GENERATED_YANG_DIR="${prefix}/share/mibyang" + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: Generated YANGs from MIB files are expected to be in ${MIB_GENERATED_YANG_DIR}" >&5 +$as_echo "Generated YANGs from MIB files are expected to be in ${MIB_GENERATED_YANG_DIR}" >&6; } fi # Set default config file location diff --git a/configure.ac b/configure.ac index 07abc414..eebe76ae 100644 --- a/configure.ac +++ b/configure.ac @@ -124,6 +124,8 @@ AC_SUBST(CLIXON_YANG_PATCH) AC_SUBST(YANG_INSTALLDIR) # Examples require standard IETF YANGs. You need to provide these for example and tests AC_SUBST(YANG_STANDARD_DIR) +# SNMP tests require generated YANGs from MIBs +AC_SUBST(MIB_GENERATED_YANG_DIR) # AC_PROG_CC() @@ -293,6 +295,18 @@ if test "$enable_netsnmp" = "yes"; then AC_CHECK_LIB(netsnmp, init_snmp) AC_CHECK_LIB(netsnmpagent, init_agent) AC_CHECK_HEADERS(net-snmp/net-snmp-config.h,[], AC_MSG_ERROR([snmp is missing])) + + + # MIB_GENERATED_YANG_DIR is where clixon assumes generated YANGs from MIBs are stored + # This is NOT installed by Clixon and is not needed for core system + # However, it is required by SNMP tests. + # To generate: for i in /usr/share/snmp/mibs/*; do smidump -f yang $i > `basename -s .txt $i`.yang; done + AC_ARG_WITH(mib-generated-yang-dir, + [AS_HELP_STRING([--with-mib-generated-yang-dir=DIR],[Directory of generated YANG specs (default: $prefix/share/mibyang)])], + [MIB_GENERATED_YANG_DIR="$withval"], + [MIB_GENERATED_YANG_DIR="${prefix}/share/mibyang"] + ) + AC_MSG_RESULT(Generated YANGs from MIB files are expected to be in ${MIB_GENERATED_YANG_DIR}) fi # Set default config file location diff --git a/lib/src/clixon_yang_parse_lib.c b/lib/src/clixon_yang_parse_lib.c index 1eb9b3ae..7c60d7f8 100644 --- a/lib/src/clixon_yang_parse_lib.c +++ b/lib/src/clixon_yang_parse_lib.c @@ -790,7 +790,10 @@ yang_parse_str(char *str, if (yang_scan_exit(&yy) < 0) goto done; } - ymod = yy.yy_module; + if ((ymod = yy.yy_module) == NULL){ + clicon_err(OE_YANG, 0, "No module in YANG %s", name); + goto done; + } /* Add filename for debugging and errors, see also ys_linenum on (each symbol?) */ if (yang_filename_set(ymod, name) < 0) goto done; diff --git a/test/config.sh.in b/test/config.sh.in index 391e08c2..242e924c 100755 --- a/test/config.sh.in +++ b/test/config.sh.in @@ -95,3 +95,4 @@ YANG_STANDARD_DIR=@YANG_STANDARD_DIR@ YANG_INSTALLDIR=@YANG_INSTALLDIR@ +MIB_GENERATED_YANG_DIR=@MIB_GENERATED_YANG_DIR@ diff --git a/test/test_snmp.sh b/test/test_snmp.sh index 6407b539..8d8b99d6 100755 --- a/test/test_snmp.sh +++ b/test/test_snmp.sh @@ -24,6 +24,8 @@ cat < $cfg $cfg ${YANG_INSTALLDIR} + ${YANG_STANDARD_DIR} + ${MIB_GENERATED_YANG_DIR} $fyang $dir/$APPNAME.sock /var/tmp/$APPNAME.pidfile @@ -37,6 +39,9 @@ module clixon-example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; + import NET-SNMP-EXAMPLES-MIB { + prefix "net-snmp-examples"; + } } EOF @@ -59,6 +64,7 @@ function testinit(){ err "Failed to start snmpd" fi + new "test params: -f $cfg" # Kill old backend and start a new one new "kill old backend" sudo clixon_backend -zf $cfg diff --git a/test/test_snmp_table.sh b/test/test_snmp_table.sh index 76c0267e..4ba41dd0 100755 --- a/test/test_snmp_table.sh +++ b/test/test_snmp_table.sh @@ -34,6 +34,8 @@ cat < $cfg $cfg ${YANG_INSTALLDIR} + ${YANG_STANDARD_DIR} + ${MIB_GENERATED_YANG_DIR} $fyang $dir/$APPNAME.sock /var/tmp/$APPNAME.pidfile @@ -47,6 +49,9 @@ module clixon-example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; + import NET-SNMP-EXAMPLES-MIB { + prefix "net-snmp-examples"; + } } EOF @@ -69,6 +74,7 @@ function testinit(){ err "Failed to start snmpd" fi + new "test params: -f $cfg" # Kill old backend and start a new one new "kill old backend" sudo clixon_backend -zf $cfg