summaryrefslogtreecommitdiff
path: root/lib/yang.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2019-03-02 15:00:46 -0300
committerRenato Westphal <renatowestphal@gmail.com>2019-03-29 11:32:21 -0300
commit8f88441d717c0ded412543cceabf0ddd93ee9f09 (patch)
tree0a460d2da46a5b910535529c92e8db2fa5ff2a74 /lib/yang.c
parent6a534dcafcb623f1b85b5ee2a13c74faab227ced (diff)
parent700e9faa28bbdc3460e1d7aa109b6e4acaf347b3 (diff)
Merge remote-tracking branch 'frr/master' into rip-vrf
Merge commit to solve a bunch of conflicts with other PRs that were merged in the previous weeks. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/yang.c')
-rw-r--r--lib/yang.c50
1 files changed, 47 insertions, 3 deletions
diff --git a/lib/yang.c b/lib/yang.c
index 4077b29746..7982d14fdd 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")
@@ -658,8 +660,41 @@ 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
+
+struct ly_ctx *yang_ctx_new_setup(void)
+{
+ struct ly_ctx *ctx;
+ const char *yang_models_path = YANG_MODELS_PATH;
+
+ if (access(yang_models_path, R_OK | X_OK)) {
+ yang_models_path = NULL;
+ if (errno == ENOENT)
+ zlog_info("yang model directory \"%s\" does not exist",
+ YANG_MODELS_PATH);
+ else
+ flog_err_sys(EC_LIB_LIBYANG,
+ "cannot access yang model directory \"%s\"",
+ YANG_MODELS_PATH);
+ }
+
+ ctx = ly_ctx_new(yang_models_path, LY_CTX_DISABLE_SEARCHDIR_CWD);
+ if (!ctx)
+ return NULL;
+ ly_ctx_set_module_imp_clb(ctx, yang_module_imp_clb, NULL);
+ return ctx;
+}
+
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;
@@ -669,21 +704,29 @@ 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);
+ ly_native_ctx = yang_ctx_new_setup();
if (!ly_native_ctx) {
flog_err(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
exit(1);
}
- 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++) {
@@ -697,6 +740,7 @@ void yang_init(void)
"%s: failed to load frr_user_types.so", __func__);
exit(1);
}
+#endif
yang_translator_init();
}