]> git.puffer.fish Git - matthieu/frr.git/commitdiff
build, lib/yang: bake in extensions if possible
authorDavid Lamparter <equinox@diac24.net>
Fri, 30 Nov 2018 20:42:25 +0000 (21:42 +0100)
committerDavid Lamparter <equinox@diac24.net>
Thu, 24 Jan 2019 16:44:41 +0000 (17:44 +0100)
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>
configure.ac
doc/developer/building-libyang.rst
doc/user/installation.rst
lib/yang.c
yang/libyang_plugins/subdir.am

index 4a17b3686f7a80e894130a2d9e0f039fc321d23e..afdc6336b0251c668badaeb3916d24350958aebc 100755 (executable)
@@ -1610,6 +1610,24 @@ AC_CHECK_MEMBER([struct lyd_node.priv], [], [
   ])
 ], [[#include <libyang/libyang.h>]])
 
+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 ---------------
index 005b6ba78680a49ac39d13e226934c8d2e69bded..c45c294b75295db8640da9422235c04e2a093fc7 100644 (file)
@@ -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:
 
index ebca53ea32ea48134c434e4bd1778da8046f64ff..4e1582ccd8f8a2a57b924b6e89d1f61fd24c05b8 100644 (file)
@@ -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:
index 71b41c35d8225a660650a573549b1c93617c12a2..f62a8163f9760e0cd70d558529491ce154dbbdd7 100644 (file)
@@ -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();
 }
index 956d22587c0bd150baeda3c4ce5c2e5ff9e87f9e..716478908342d2ede059e0b376c65f0bc44b3825 100644 (file)
@@ -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