]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add flag to have libyang load internal ietf-yang-library module 17015/head
authorChristian Hopps <chopps@labn.net>
Mon, 7 Oct 2024 03:23:31 +0000 (03:23 +0000)
committerChristian Hopps <chopps@labn.net>
Mon, 7 Oct 2024 03:32:44 +0000 (03:32 +0000)
Mgmtd makes use of libyang's internal ietf-yang-library module to add
support for said module to FRR management. Previously, mgmtd was loading
this module explicitly; however, that required that libyang's
`ietf-yang-library.yang` module definition file be co-located with FRR's
yang files so that it (and ietf-datastore.yang) would be found when
searched for by libyang using FRRs search path. This isn't always the
case depending on how the user compiles and installs libyang so mgmtd
was failing to run in some cases.

Instead of doing it the above way we simply tell libyang to load it's
internal version of ietf-yang-library when we initialize the libyang
context.

This required adding a boolean to a couple of the init functions which
is why so many files are touched (although all the changes are minimal).

Signed-off-by: Christian Hopps <chopps@labn.net>
19 files changed:
lib/grammar_sandbox_main.c
lib/libfrr.c
lib/libfrr.h
lib/northbound.c
lib/northbound.h
lib/yang.c
lib/yang.h
lib/yang_translator.c
mgmtd/mgmt.c
mgmtd/mgmt_main.c
tests/bgpd/test_peer_attr.c
tests/helpers/c/main.c
tests/isisd/test_isis_spf.c
tests/lib/cli/common_cli.c
tests/lib/cli/test_commands.c
tests/lib/northbound/test_oper_data.c
tests/lib/test_grpc.cpp
tools/gen_northbound_callbacks.c
tools/gen_yang_deviations.c

index abd42f359f059adb4b6a3581aa8b9c29a3d3e4ef..05088d52d11392112669f7cdb0ad279b3bd30fcd 100644 (file)
@@ -40,7 +40,7 @@ int main(int argc, char **argv)
 
        vty_init(master, true);
        lib_cmd_init();
-       nb_init(master, NULL, 0, false);
+       nb_init(master, NULL, 0, false, false);
 
        vty_stdio(vty_do_exit);
 
index a1982841d3a7a19fa222a4128711005e1d52de7e..f2247a48e555141be4aaded617e486c7af1e90e4 100644 (file)
@@ -820,7 +820,8 @@ struct event_loop *frr_init(void)
        log_ref_vty_init();
        lib_error_init();
 
-       nb_init(master, di->yang_modules, di->n_yang_modules, true);
+       nb_init(master, di->yang_modules, di->n_yang_modules, true,
+               (di->flags & FRR_LOAD_YANG_LIBRARY) != 0);
        if (nb_db_init() != NB_OK)
                flog_warn(EC_LIB_NB_DATABASE,
                          "%s: failed to initialize northbound database",
index 7ed7be4d984d7338b42a0f492f0df6e9d3fc7edb..df537e2e3b43593c2d68634bb31033813beb8245 100644 (file)
@@ -46,6 +46,11 @@ extern "C" {
  * is responsible for calling frr_vty_serv() itself.
  */
 #define FRR_MANUAL_VTY_START (1 << 7)
+/* If FRR_LOAD_YANG_LIBRARY is set then libyang will be told to load and
+ * implement it's internal ietf-yang-library implementation. This should
+ * normally only be done from mgmtd.
+ */
+#define FRR_LOAD_YANG_LIBRARY (1 << 8)
 
 PREDECL_DLIST(log_args);
 struct log_arg {
index 2dae21341e59780a3a7b0b8ae556475e37c24a87..a385cc9ece9453094b7c52668bd3100bb3045ba7 100644 (file)
@@ -2701,7 +2701,7 @@ void nb_validate_callbacks(void)
 
 void nb_init(struct event_loop *tm,
             const struct frr_yang_module_info *const modules[],
-            size_t nmodules, bool db_enabled)
+            size_t nmodules, bool db_enabled, bool load_library)
 {
        struct yang_module *loaded[nmodules], **loadedp = loaded;
 
@@ -2717,7 +2717,7 @@ void nb_init(struct event_loop *tm,
 
        nb_db_enabled = db_enabled;
 
-       yang_init(true, explicit_compile);
+       yang_init(true, explicit_compile, load_library);
 
        /* Load YANG modules and their corresponding northbound callbacks. */
        for (size_t i = 0; i < nmodules; i++) {
index dd3fbf8f73415d58db6058f531f744e80f8ed4dc..97a1d31e5792ba656335a5ca91fc59383581df69 100644 (file)
@@ -1703,10 +1703,12 @@ void nb_validate_callbacks(void);
  *
  * db_enabled
  *    Set this to record the transactions in the transaction log.
+ *
+ * load_library
+ *    Set this to have libyang to load/implement the ietf-yang-library.
  */
-extern void nb_init(struct event_loop *tm,
-                   const struct frr_yang_module_info *const modules[],
-                   size_t nmodules, bool db_enabled);
+extern void nb_init(struct event_loop *tm, const struct frr_yang_module_info *const modules[],
+                   size_t nmodules, bool db_enabled, bool load_library);
 
 /*
  * Finish the northbound layer gracefully. Should be called only when the daemon
index 14d5b118c652a2044c23bf17ed3cd66bd5d0094e..b847b8b77b6895268280224623cfaddf81185e5e 100644 (file)
@@ -976,7 +976,7 @@ void yang_debugging_set(bool enable)
        }
 }
 
-struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile)
+struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile, bool load_library)
 {
        struct ly_ctx *ctx = NULL;
        const char *yang_models_path = YANG_MODELS_PATH;
@@ -994,7 +994,9 @@ struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile)
                                     YANG_MODELS_PATH);
        }
 
-       options = LY_CTX_NO_YANGLIBRARY | LY_CTX_DISABLE_SEARCHDIR_CWD;
+       options = LY_CTX_DISABLE_SEARCHDIR_CWD;
+       if (!load_library)
+               options |= LY_CTX_NO_YANGLIBRARY;
        if (explicit_compile)
                options |= LY_CTX_EXPLICIT_COMPILE;
        err = ly_ctx_new(yang_models_path, options, &ctx);
@@ -1007,7 +1009,7 @@ struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile)
        return ctx;
 }
 
-void yang_init(bool embedded_modules, bool defer_compile)
+void yang_init(bool embedded_modules, bool defer_compile, bool load_library)
 {
        /* Initialize libyang global parameters that affect all containers. */
        ly_set_log_clb(ly_zlog_cb
@@ -1019,7 +1021,7 @@ void yang_init(bool embedded_modules, bool defer_compile)
        ly_log_options(LY_LOLOG | LY_LOSTORE);
 
        /* Initialize libyang container for native models. */
-       ly_native_ctx = yang_ctx_new_setup(embedded_modules, defer_compile);
+       ly_native_ctx = yang_ctx_new_setup(embedded_modules, defer_compile, load_library);
        if (!ly_native_ctx) {
                flog_err(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
                exit(1);
index c4fc78b8aed7f0153954fd99cac8212521896eb7..52857ecf003f6e38dd3cc1dc0b84f4b7a89dc5c9 100644 (file)
@@ -607,9 +607,11 @@ extern struct yang_data *yang_data_list_find(const struct list *list,
  * explicit_compile
  *    True if the caller will later call ly_ctx_compile to compile all loaded
  *    modules at once.
+ * load_library
+ *    Set this to have libyang to load/implement the ietf-yang-library.
  */
-extern struct ly_ctx *yang_ctx_new_setup(bool embedded_modules,
-                                        bool explicit_compile);
+extern struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile,
+                                        bool load_library);
 
 /*
  * Enable or disable libyang verbose debugging.
@@ -727,8 +729,10 @@ extern const char *yang_print_errors(struct ly_ctx *ly_ctx, char *buf,
  *    Specify whether libyang should attempt to look for embedded YANG modules.
  * defer_compile
  *    Hold off on compiling modules until yang_init_loading_complete is called.
+ * load_library
+ *    Set this to have libyang to load/implement the ietf-yang-library.
  */
-extern void yang_init(bool embedded_modules, bool defer_compile);
+extern void yang_init(bool embedded_modules, bool defer_compile, bool load_library);
 
 /*
  * Should be called after yang_init and all yang_module_load()s have been done,
index 005f6422f3b323c4b39a5f5cdc28752ee0042fb6..b7599e0a7120ec9aa87757a96a2fd8ad6f09b22c 100644 (file)
@@ -166,7 +166,7 @@ struct yang_translator *yang_translator_load(const char *path)
        RB_INSERT(yang_translators, &yang_translators, translator);
 
        /* Initialize the translator libyang context. */
-       translator->ly_ctx = yang_ctx_new_setup(false, false);
+       translator->ly_ctx = yang_ctx_new_setup(false, false, false);
        if (!translator->ly_ctx) {
                flog_warn(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
                goto error;
@@ -512,7 +512,7 @@ static unsigned int yang_module_nodes_count(const struct lys_module *module)
 
 void yang_translator_init(void)
 {
-       ly_translator_ctx = yang_ctx_new_setup(true, false);
+       ly_translator_ctx = yang_ctx_new_setup(true, false, false);
        if (!ly_translator_ctx) {
                flog_err(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
                exit(1);
index 02c54b921542b43e5ff006d795f3c63c9ac1a7f1..cfadad4829e255ad57b2155b5aeaa6a8c8f0d30e 100644 (file)
@@ -57,9 +57,6 @@ void mgmt_init(void)
        /* Initialize MGMTD Transaction module */
        mgmt_txn_init(mm, mm->master);
 
-       /* Add yang-library module */
-       yang_module_load("ietf-yang-library", NULL);
-
        /* Initialize the MGMTD Frontend Adapter Module */
        mgmt_fe_adapter_init(mm->master);
 
index e181d0da5ef026a7c5b952f198a2894afa0ae820..1880d94415fa36906ab854aced10759701519fe5 100644 (file)
@@ -214,7 +214,7 @@ FRR_DAEMON_INFO(mgmtd, MGMTD,
                .n_yang_modules = array_size(mgmt_yang_modules),
 
                /* avoid libfrr trying to read our config file for us */
-               .flags = FRR_MANUAL_VTY_START | FRR_NO_SPLIT_CONFIG,
+               .flags = FRR_MANUAL_VTY_START | FRR_NO_SPLIT_CONFIG | FRR_LOAD_YANG_LIBRARY,
        );
 /* clang-format on */
 
index d5faa33ca875e4d08e2ec2a9b4503dfe398aea21..17002464e14ece81c6b832e4c40a06f475dc45df 100644 (file)
@@ -1355,7 +1355,7 @@ static void bgp_startup(void)
        zprivs_init(&bgpd_privs);
 
        master = event_master_create(NULL);
-       nb_init(master, NULL, 0, false);
+       nb_init(master, NULL, 0, false, false);
        bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
        bgp_option_set(BGP_OPT_NO_LISTEN);
        vrf_init(NULL, NULL, NULL, NULL);
index 9cb395bb1f7384a630de60fb55e8a6e3da01d80d..344af82fca5a0dd4022a569d4f754a6785c1ffa8 100644 (file)
@@ -143,7 +143,7 @@ int main(int argc, char **argv)
        vty_init(master, false);
        lib_cmd_init();
        debug_init();
-       nb_init(master, NULL, 0, false);
+       nb_init(master, NULL, 0, false, false);
 
        /* OSPF vty inits. */
        test_vty_init();
index 93009a1b84e198c7776a6547e417fa926203e142..e5a8f7a5139220cc8960a2dea610b9662f9c067d 100644 (file)
@@ -546,7 +546,7 @@ int main(int argc, char **argv)
        cmd_init(1);
        cmd_hostname_set("test");
        vty_init(master, false);
-       yang_init(true, false);
+       yang_init(true, false, false);
        if (debug)
                zlog_aux_init("NONE: ", LOG_DEBUG);
        else
index 640197143590b39b61328a94fd0cc857477d6099..342a91cc79a70e1651ae20648629b7796caf4951 100644 (file)
@@ -77,7 +77,7 @@ int main(int argc, char **argv)
        for (yangcount = 0; test_yang_modules && test_yang_modules[yangcount];
             yangcount++)
                ;
-       nb_init(master, test_yang_modules, yangcount, false);
+       nb_init(master, test_yang_modules, yangcount, false, false);
 
        test_init(argc, argv);
 
index 0034c2af8960d98baed0da29f16986cb10f01be2..9873383fdcf7984be57f0977be1329ee1da7b6c6 100644 (file)
@@ -197,7 +197,7 @@ static void test_init(void)
 
        cmd_init(1);
        debug_init();
-       nb_init(master, NULL, 0, false);
+       nb_init(master, NULL, 0, false, false);
 
        install_node(&bgp_node);
        install_node(&rip_node);
index 74a0dfe6cc251588dcfe97e9faeca6a51dbc3833..fdc9e53ca3eaf38fba16fdcf81a4103005fc6098 100644 (file)
@@ -461,7 +461,7 @@ int main(int argc, char **argv)
        vty_init(master, false);
        lib_cmd_init();
        debug_init();
-       nb_init(master, modules, array_size(modules), false);
+       nb_init(master, modules, array_size(modules), false, false);
 
        install_element(ENABLE_NODE, &test_rpc_cmd);
 
index 2f0282704e15728f11b72461cc5aa02443ec6ec0..379a8688a7b83482a38b327b84929b5c8ea42574 100644 (file)
@@ -111,8 +111,7 @@ static void static_startup(void)
        static_debug_init();
 
        master = event_master_create(NULL);
-       nb_init(master, staticd_yang_modules, array_size(staticd_yang_modules),
-               false);
+       nb_init(master, staticd_yang_modules, array_size(staticd_yang_modules), false, false);
 
        static_zebra_init();
        vty_init(master, true);
index a8798113635768af170c9e954b8bbdf627fc8faa..046dc9e99ef14376b0629e6eef01649e3399e359 100644 (file)
@@ -448,7 +448,7 @@ int main(int argc, char *argv[])
        if (argc != 1)
                usage(EXIT_FAILURE);
 
-       yang_init(false, true);
+       yang_init(false, true, false);
 
        if (search_path)
                ly_ctx_set_searchdir(ly_native_ctx, search_path);
index 251643c69ebb4b1f7cf4119064a1be591f51ee07..c2e7fd91c61750ba95225cd30d6feca2834ea2ce 100644 (file)
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
        if (argc != 1)
                usage(EXIT_FAILURE);
 
-       yang_init(false, false);
+       yang_init(false, false, false);
 
        /* Load YANG module. */
        module = yang_module_load(argv[0], NULL);