diff options
Diffstat (limited to 'lib/northbound.c')
| -rw-r--r-- | lib/northbound.c | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/lib/northbound.c b/lib/northbound.c index c99f993ea5..ecfa2c9d11 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -152,20 +152,22 @@ static int nb_node_del_cb(const struct lys_node *snode, void *arg) struct nb_node *nb_node; nb_node = snode->priv; - lys_set_private(snode, NULL); - XFREE(MTYPE_NB_NODE, nb_node); + if (nb_node) { + lys_set_private(snode, NULL); + XFREE(MTYPE_NB_NODE, nb_node); + } return YANG_ITER_CONTINUE; } void nb_nodes_create(void) { - yang_snodes_iterate_all(nb_node_new_cb, 0, NULL); + yang_snodes_iterate(NULL, nb_node_new_cb, 0, NULL); } void nb_nodes_delete(void) { - yang_snodes_iterate_all(nb_node_del_cb, 0, NULL); + yang_snodes_iterate(NULL, nb_node_del_cb, 0, NULL); } struct nb_node *nb_node_find(const char *xpath) @@ -273,8 +275,10 @@ static int nb_node_validate(const struct lys_node *snode, void *arg) unsigned int *errors = arg; /* Validate callbacks and priority. */ - *errors += nb_node_validate_cbs(nb_node); - *errors += nb_node_validate_priority(nb_node); + if (nb_node) { + *errors += nb_node_validate_cbs(nb_node); + *errors += nb_node_validate_priority(nb_node); + } return YANG_ITER_CONTINUE; } @@ -2232,25 +2236,11 @@ static void nb_load_callbacks(const struct frr_yang_module_info *module) } } -void nb_init(struct thread_master *tm, - const struct frr_yang_module_info *const modules[], - size_t nmodules, bool db_enabled) +void nb_validate_callbacks(void) { unsigned int errors = 0; - /* Load YANG modules. */ - for (size_t i = 0; i < nmodules; i++) - yang_module_load(modules[i]->name); - - /* Create a nb_node for all YANG schema nodes. */ - nb_nodes_create(); - - /* Load northbound callbacks. */ - for (size_t i = 0; i < nmodules; i++) - nb_load_callbacks(modules[i]); - - /* Validate northbound callbacks. */ - yang_snodes_iterate_all(nb_node_validate, 0, &errors); + yang_snodes_iterate(NULL, nb_node_validate, 0, &errors); if (errors > 0) { flog_err( EC_LIB_NB_CBS_VALIDATION, @@ -2258,9 +2248,33 @@ void nb_init(struct thread_master *tm, __func__, errors); exit(1); } +} +void nb_load_module(const struct frr_yang_module_info *module_info) +{ + struct yang_module *module; + + DEBUGD(&nb_dbg_events, "northbound: loading %s.yang", + module_info->name); + + module = yang_module_load(module_info->name); + yang_snodes_iterate(module->info, nb_node_new_cb, 0, NULL); + nb_load_callbacks(module_info); +} + +void nb_init(struct thread_master *tm, + const struct frr_yang_module_info *const modules[], + size_t nmodules, bool db_enabled) +{ nb_db_enabled = db_enabled; + /* Load YANG modules and their corresponding northbound callbacks. */ + for (size_t i = 0; i < nmodules; i++) + nb_load_module(modules[i]); + + /* Validate northbound callbacks. */ + nb_validate_callbacks(); + /* Create an empty running configuration. */ running_config = nb_config_new(NULL); running_config_entries = hash_create(running_config_entry_key_make, |
