mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-06-14 19:05:37 +00:00
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>
This commit is contained in:
parent
c8d3e79554
commit
02a0df1f22
18
configure.ac
18
configure.ac
@ -1610,6 +1610,24 @@ AC_CHECK_MEMBER([struct lyd_node.priv], [], [
|
|||||||
])
|
])
|
||||||
], [[#include <libyang/libyang.h>]])
|
], [[#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 ---------------
|
||||||
dnl configuration rollbacks
|
dnl configuration rollbacks
|
||||||
dnl ---------------
|
dnl ---------------
|
||||||
|
@ -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
|
Note: the libyang dev/devel packages need to be installed in addition
|
||||||
to the libyang core package in order to build FRR successfully.
|
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:
|
For example, for CentOS 7.x:
|
||||||
|
|
||||||
.. code-block:: shell
|
.. code-block:: shell
|
||||||
@ -21,6 +28,14 @@ or Ubuntu 18.04:
|
|||||||
sudo apt install libpcre3-dev
|
sudo apt install libpcre3-dev
|
||||||
sudo dpkg -i libyang-dev_0.16.46_amd64.deb libyang_0.16.46_amd64.deb
|
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
|
Alternatively, libyang can be built and installed manually by following
|
||||||
the steps below:
|
the steps below:
|
||||||
|
|
||||||
|
@ -335,6 +335,9 @@ options to the configuration script.
|
|||||||
Look for libyang plugins in `dir` [`prefix`/lib/frr/libyang_plugins].
|
Look for libyang plugins in `dir` [`prefix`/lib/frr/libyang_plugins].
|
||||||
Note that the FRR libyang plugins will be installed here.
|
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
|
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
|
to configure it as follows to look for YANG modules and libyang plugins in the
|
||||||
compile directory:
|
compile directory:
|
||||||
|
23
lib/yang.c
23
lib/yang.c
@ -26,6 +26,8 @@
|
|||||||
#include "yang_translator.h"
|
#include "yang_translator.h"
|
||||||
#include "northbound.h"
|
#include "northbound.h"
|
||||||
|
|
||||||
|
#include <libyang/user_types.h>
|
||||||
|
|
||||||
DEFINE_MTYPE(LIB, YANG_MODULE, "YANG module")
|
DEFINE_MTYPE(LIB, YANG_MODULE, "YANG module")
|
||||||
DEFINE_MTYPE(LIB, YANG_DATA, "YANG data structure")
|
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);
|
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)
|
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];
|
static char ly_plugin_dir[PATH_MAX];
|
||||||
const char *const *ly_loaded_plugins;
|
const char *const *ly_loaded_plugins;
|
||||||
const char *ly_plugin;
|
const char *ly_plugin;
|
||||||
@ -650,11 +662,20 @@ void yang_init(void)
|
|||||||
snprintf(ly_plugin_dir, sizeof(ly_plugin_dir), "%s=%s",
|
snprintf(ly_plugin_dir, sizeof(ly_plugin_dir), "%s=%s",
|
||||||
"LIBYANG_USER_TYPES_PLUGINS_DIR", LIBYANG_PLUGINS_PATH);
|
"LIBYANG_USER_TYPES_PLUGINS_DIR", LIBYANG_PLUGINS_PATH);
|
||||||
putenv(ly_plugin_dir);
|
putenv(ly_plugin_dir);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize libyang global parameters that affect all containers. */
|
/* Initialize libyang global parameters that affect all containers. */
|
||||||
ly_set_log_clb(ly_log_cb, 1);
|
ly_set_log_clb(ly_log_cb, 1);
|
||||||
ly_log_options(LY_LOLOG | LY_LOSTORE);
|
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. */
|
/* Initialize libyang container for native models. */
|
||||||
ly_native_ctx =
|
ly_native_ctx =
|
||||||
ly_ctx_new(YANG_MODELS_PATH, LY_CTX_DISABLE_SEARCHDIR_CWD);
|
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_module_imp_clb(ly_native_ctx, yang_module_imp_clb, NULL);
|
||||||
ly_ctx_set_priv_dup_clb(ly_native_ctx, ly_dup_cb);
|
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. */
|
/* Detect if the required libyang plugin(s) were loaded successfully. */
|
||||||
ly_loaded_plugins = ly_get_loaded_plugins();
|
ly_loaded_plugins = ly_get_loaded_plugins();
|
||||||
for (size_t i = 0; (ly_plugin = ly_loaded_plugins[i]); i++) {
|
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__);
|
"%s: failed to load frr_user_types.so", __func__);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
yang_translator_init();
|
yang_translator_init();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
#
|
#
|
||||||
# libyang user types
|
# 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
|
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_CFLAGS = $(WERROR)
|
||||||
yang_libyang_plugins_frr_user_types_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
|
yang_libyang_plugins_frr_user_types_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
|
||||||
|
Loading…
Reference in New Issue
Block a user