From 02a0df1f22c5cef8e4d3392d56e7db82da0d49cf Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 30 Nov 2018 21:42:25 +0100 Subject: [PATCH] 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 --- configure.ac | 18 ++++++++++++++++++ doc/developer/building-libyang.rst | 15 +++++++++++++++ doc/user/installation.rst | 3 +++ lib/yang.c | 23 +++++++++++++++++++++++ yang/libyang_plugins/subdir.am | 5 +++++ 5 files changed, 64 insertions(+) diff --git a/configure.ac b/configure.ac index 4a17b3686f..afdc6336b0 100755 --- a/configure.ac +++ b/configure.ac @@ -1610,6 +1610,24 @@ AC_CHECK_MEMBER([struct lyd_node.priv], [], [ ]) ], [[#include ]]) +ac_ld_flag_save="$LDFLAGS" +LDFLAGS="$LDFLAGS $libyang_LIBS" +AC_CHECK_FUNC([ly_register_types], [ + libyang_ext_builtin=true + AC_DEFINE([LIBYANG_EXT_BUILTIN], [1], [have ly_register_types()]) +], [ + libyang_ext_builtin=false + AC_MSG_WARN([===== old libyang (before 0.16.74) detected =====]) + AC_MSG_WARN([The available version of libyang does not seem to support]) + AC_MSG_WARN([built-in YANG extension modules. This will cause "make check"]) + AC_MSG_WARN([to fail and may create installation and version mismatch issues.]) + AC_MSG_WARN([Support for the old mechanism will be removed at some point.]) + AC_MSG_WARN([Please update libyang to version 0.16.74 or newer.]) + AC_MSG_WARN([===== old libyang (before 0.16.74) detected =====]) +]) +AM_CONDITIONAL([LIBYANG_EXT_BUILTIN], [$libyang_ext_builtin]) +LDFLAGS="$ac_ld_flag_save" + dnl --------------- dnl configuration rollbacks dnl --------------- diff --git a/doc/developer/building-libyang.rst b/doc/developer/building-libyang.rst index 005b6ba786..c45c294b75 100644 --- a/doc/developer/building-libyang.rst +++ b/doc/developer/building-libyang.rst @@ -4,6 +4,13 @@ The libyang library can be installed from third-party packages available `here Note: the libyang dev/devel packages need to be installed in addition to the libyang core package in order to build FRR successfully. +.. warning:: + libyang ABI version 0.16.74 or newer will be required to build FRR in the + near future since it significantly eases build and installation + considerations. "0.16-r3" is equal to 0.16.105 and will work, "0.16-r2" + is equal to 0.16.52 and will stop working. The CI artifacts will be + updated shortly. + For example, for CentOS 7.x: .. code-block:: shell @@ -21,6 +28,14 @@ or Ubuntu 18.04: sudo apt install libpcre3-dev sudo dpkg -i libyang-dev_0.16.46_amd64.deb libyang_0.16.46_amd64.deb +.. note:: + For Debian-based systems, the official libyang package requires recent + versions of swig (3.0.12) and debhelper (11) which are only available in + Debian buster (10). However, libyang packages built on Debian buster can + be installed on both Debian jessie (8) and Debian stretch (9), as well as + various Ubuntu systems. The python3-yang package will not work, but the + other packages (libyang-dev is the one needed for FRR) will. + Alternatively, libyang can be built and installed manually by following the steps below: diff --git a/doc/user/installation.rst b/doc/user/installation.rst index ebca53ea32..4e1582ccd8 100644 --- a/doc/user/installation.rst +++ b/doc/user/installation.rst @@ -335,6 +335,9 @@ options to the configuration script. Look for libyang plugins in `dir` [`prefix`/lib/frr/libyang_plugins]. Note that the FRR libyang plugins will be installed here. + This option is meaningless with libyang 0.16.74 or newer and will be + removed once support for older libyang versions is dropped. + When it's desired to run FRR without installing it in the system, it's possible to configure it as follows to look for YANG modules and libyang plugins in the compile directory: 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 + 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(); } diff --git a/yang/libyang_plugins/subdir.am b/yang/libyang_plugins/subdir.am index 956d22587c..7164789083 100644 --- a/yang/libyang_plugins/subdir.am +++ b/yang/libyang_plugins/subdir.am @@ -1,7 +1,12 @@ # # libyang user types # + +if LIBYANG_EXT_BUILTIN +lib_libfrr_la_SOURCES += yang/libyang_plugins/frr_user_types.c +else libyang_plugins_LTLIBRARIES += yang/libyang_plugins/frr_user_types.la +endif yang_libyang_plugins_frr_user_types_la_CFLAGS = $(WERROR) yang_libyang_plugins_frr_user_types_la_LDFLAGS = -avoid-version -module -shared -export-dynamic -- 2.39.5