diff options
author | Igor Ryzhov <iryzhov@nfware.com> | 2024-01-24 02:02:15 +0100 |
---|---|---|
committer | Igor Ryzhov <iryzhov@nfware.com> | 2024-01-28 22:28:40 +0100 |
commit | 3625360d889b71dfe5f8d849955bc7a275946741 (patch) | |
tree | ec7709ee6d2a247590e1ee6b7b906bb8eb8d1ec9 | |
parent | zebra: convert interface ipv6 nd dnssl command to NB (diff) | |
download | frr-3625360d889b71dfe5f8d849955bc7a275946741.tar.xz frr-3625360d889b71dfe5f8d849955bc7a275946741.zip |
lib: add support for "features" when loading YANG modules
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
-rw-r--r-- | lib/northbound.c | 3 | ||||
-rw-r--r-- | lib/northbound.h | 7 | ||||
-rw-r--r-- | lib/yang.c | 11 | ||||
-rw-r--r-- | lib/yang.h | 8 | ||||
-rw-r--r-- | tests/isisd/test_isis_spf.c | 2 | ||||
-rw-r--r-- | tools/gen_northbound_callbacks.c | 2 | ||||
-rw-r--r-- | tools/gen_yang_deviations.c | 2 |
7 files changed, 26 insertions, 9 deletions
diff --git a/lib/northbound.c b/lib/northbound.c index 949218332..b1da3315d 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -2384,7 +2384,8 @@ void nb_init(struct event_loop *tm, for (size_t i = 0; i < nmodules; i++) { DEBUGD(&nb_dbg_events, "northbound: loading %s.yang", modules[i]->name); - *loadedp++ = yang_module_load(modules[i]->name); + *loadedp++ = yang_module_load(modules[i]->name, + modules[i]->features); } if (explicit_compile) diff --git a/lib/northbound.h b/lib/northbound.h index 493e5ce70..b7194ea40 100644 --- a/lib/northbound.h +++ b/lib/northbound.h @@ -628,6 +628,13 @@ struct frr_yang_module_info { */ bool ignore_cfg_cbs; + /* + * The NULL-terminated list of supported features. + * Use ["*", NULL] to enable all features. + * Use NULL to disable all features. + */ + const char **features; + /* Northbound callbacks. */ const struct { /* Data path of this YANG node. */ diff --git a/lib/yang.c b/lib/yang.c index b6884619d..7a3d6df49 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -100,13 +100,14 @@ RB_GENERATE(yang_modules, yang_module, entry, yang_module_compare) struct yang_modules yang_modules = RB_INITIALIZER(&yang_modules); -struct yang_module *yang_module_load(const char *module_name) +struct yang_module *yang_module_load(const char *module_name, + const char **features) { struct yang_module *module; const struct lys_module *module_info; - module_info = - ly_ctx_load_module(ly_native_ctx, module_name, NULL, NULL); + module_info = ly_ctx_load_module(ly_native_ctx, module_name, NULL, + features); if (!module_info) { flog_err(EC_LIB_YANG_MODULE_LOAD, "%s: failed to load data model: %s", __func__, @@ -130,8 +131,10 @@ struct yang_module *yang_module_load(const char *module_name) void yang_module_load_all(void) { + static const char * const all_features[] = { "*", NULL }; + for (size_t i = 0; i < array_size(frr_native_modules); i++) - yang_module_load(frr_native_modules[i]); + yang_module_load(frr_native_modules[i], (const char **)all_features); } struct yang_module *yang_module_find(const char *module_name) diff --git a/lib/yang.h b/lib/yang.h index 1235125f2..431b2eee4 100644 --- a/lib/yang.h +++ b/lib/yang.h @@ -112,10 +112,16 @@ extern struct yang_modules yang_modules; * module_name * Name of the YANG module. * + * features + * NULL-terminated array of feature names to enable. + * If NULL, all features are disabled. + * To enable all features, use ["*", NULL]. + * * Returns: * Pointer to newly created YANG module. */ -extern struct yang_module *yang_module_load(const char *module_name); +extern struct yang_module *yang_module_load(const char *module_name, + const char **features); /* * Load all FRR native YANG models. diff --git a/tests/isisd/test_isis_spf.c b/tests/isisd/test_isis_spf.c index 95f045c90..4ea28cda2 100644 --- a/tests/isisd/test_isis_spf.c +++ b/tests/isisd/test_isis_spf.c @@ -540,7 +540,7 @@ int main(int argc, char **argv) zlog_aux_init("NONE: ", ZLOG_DISABLED); /* IS-IS inits. */ - yang_module_load("frr-isisd"); + yang_module_load("frr-isisd", NULL); SET_FLAG(im->options, F_ISIS_UNIT_TEST); debug_spf_events |= DEBUG_SPF_EVENTS; debug_lfa |= DEBUG_LFA; diff --git a/tools/gen_northbound_callbacks.c b/tools/gen_northbound_callbacks.c index 550058bfe..618855901 100644 --- a/tools/gen_northbound_callbacks.c +++ b/tools/gen_northbound_callbacks.c @@ -350,7 +350,7 @@ int main(int argc, char *argv[]) module = yang_module_find(argv[0]); if (!module) /* Non-native FRR module (e.g. modules from unit tests). */ - module = yang_module_load(argv[0]); + module = yang_module_load(argv[0], NULL); yang_init_loading_complete(); diff --git a/tools/gen_yang_deviations.c b/tools/gen_yang_deviations.c index fc9f55bcb..251643c69 100644 --- a/tools/gen_yang_deviations.c +++ b/tools/gen_yang_deviations.c @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) yang_init(false, false); /* Load YANG module. */ - module = yang_module_load(argv[0]); + module = yang_module_load(argv[0], NULL); /* Generate deviations. */ yang_snodes_iterate(module->info, generate_yang_deviation, 0, NULL); |