summaryrefslogtreecommitdiff
path: root/lib/yang.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2018-11-30 21:42:25 +0100
committerDavid Lamparter <equinox@diac24.net>2019-01-24 17:44:41 +0100
commit02a0df1f22c5cef8e4d3392d56e7db82da0d49cf (patch)
treea59f287e4ea30e471c3083700d606f0b2bf42e41 /lib/yang.c
parentc8d3e7955417ac882dd9b078011c52ee97c3577a (diff)
build, lib/yang: bake in extensions if possible
Starting with libyang 0.16.74, we can load internally embedded yang extensions instead of going through the file system/dlopen. Detect support for this at build time and use if available. NB: the fallback mechanism will go away in a short while. Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/yang.c')
-rw-r--r--lib/yang.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c
index 71b41c35d8..f62a8163f9 100644
--- a/lib/yang.c
+++ b/lib/yang.c
@@ -26,6 +26,8 @@
#include "yang_translator.h"
#include "northbound.h"
+#include <libyang/user_types.h>
+
DEFINE_MTYPE(LIB, YANG_MODULE, "YANG module")
DEFINE_MTYPE(LIB, YANG_DATA, "YANG data structure")
@@ -639,8 +641,18 @@ static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path)
zlog(priority, "libyang: %s", msg);
}
+#if CONFDATE > 20190401
+CPP_NOTICE("lib/yang: time to remove non-LIBYANG_EXT_BUILTIN support")
+#endif
+
+#ifdef LIBYANG_EXT_BUILTIN
+extern struct lytype_plugin_list frr_user_types[];
+#endif
+
void yang_init(void)
{
+#ifndef LIBYANG_EXT_BUILTIN
+CPP_NOTICE("lib/yang: deprecated libyang <0.16.74 extension loading in use!")
static char ly_plugin_dir[PATH_MAX];
const char *const *ly_loaded_plugins;
const char *ly_plugin;
@@ -650,11 +662,20 @@ void yang_init(void)
snprintf(ly_plugin_dir, sizeof(ly_plugin_dir), "%s=%s",
"LIBYANG_USER_TYPES_PLUGINS_DIR", LIBYANG_PLUGINS_PATH);
putenv(ly_plugin_dir);
+#endif
/* Initialize libyang global parameters that affect all containers. */
ly_set_log_clb(ly_log_cb, 1);
ly_log_options(LY_LOLOG | LY_LOSTORE);
+#ifdef LIBYANG_EXT_BUILTIN
+ if (ly_register_types(frr_user_types, "frr_user_types")) {
+ flog_err(EC_LIB_LIBYANG_PLUGIN_LOAD,
+ "ly_register_types() failed");
+ exit(1);
+ }
+#endif
+
/* Initialize libyang container for native models. */
ly_native_ctx =
ly_ctx_new(YANG_MODELS_PATH, LY_CTX_DISABLE_SEARCHDIR_CWD);
@@ -665,6 +686,7 @@ void yang_init(void)
ly_ctx_set_module_imp_clb(ly_native_ctx, yang_module_imp_clb, NULL);
ly_ctx_set_priv_dup_clb(ly_native_ctx, ly_dup_cb);
+#ifndef LIBYANG_EXT_BUILTIN
/* Detect if the required libyang plugin(s) were loaded successfully. */
ly_loaded_plugins = ly_get_loaded_plugins();
for (size_t i = 0; (ly_plugin = ly_loaded_plugins[i]); i++) {
@@ -678,6 +700,7 @@ void yang_init(void)
"%s: failed to load frr_user_types.so", __func__);
exit(1);
}
+#endif
yang_translator_init();
}