diff --git a/lib/northbound.c b/lib/northbound.c index e79ccc7dd0..a978c7fe78 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -162,12 +162,12 @@ static int nb_node_del_cb(const struct lys_node *snode, void *arg) 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) @@ -2254,7 +2254,7 @@ void nb_init(struct thread_master *tm, 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, diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c index a53e90d558..8acba9fd2b 100644 --- a/lib/northbound_confd.c +++ b/lib/northbound_confd.c @@ -1279,7 +1279,7 @@ static int frr_confd_init_dp(const char *program_name) * Iterate over all loaded YANG modules and subscribe to the paths * referent to state data. */ - yang_snodes_iterate_all(frr_confd_subscribe_state, 0, &data_cbs); + yang_snodes_iterate(NULL, frr_confd_subscribe_state, 0, &data_cbs); /* Register notification stream. */ memset(&ncbs, 0, sizeof(ncbs)); @@ -1430,7 +1430,7 @@ static int frr_confd_init(const char *program_name) goto error; } - yang_snodes_iterate_all(frr_confd_calculate_snode_hash, 0, NULL); + yang_snodes_iterate(NULL, frr_confd_calculate_snode_hash, 0, NULL); hook_register(nb_notification_send, frr_confd_notification_send); diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c index e9aac3ef14..c027f4de72 100644 --- a/lib/northbound_sysrepo.c +++ b/lib/northbound_sysrepo.c @@ -690,10 +690,10 @@ static int frr_sr_init(void) int event_pipe; frr_sr_subscribe_config(module); - yang_snodes_iterate_module(module->info, frr_sr_subscribe_state, - 0, module); - yang_snodes_iterate_module(module->info, frr_sr_subscribe_rpc, - 0, module); + yang_snodes_iterate(module->info, frr_sr_subscribe_state, 0, + module); + yang_snodes_iterate(module->info, frr_sr_subscribe_rpc, 0, + module); /* Watch subscriptions. */ ret = sr_get_event_pipe(module->sr_subscription, &event_pipe); diff --git a/lib/yang.c b/lib/yang.c index 46012acf51..c59cb642f0 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -227,8 +227,8 @@ next: return ret; } -int yang_snodes_iterate_module(const struct lys_module *module, - yang_iterate_cb cb, uint16_t flags, void *arg) +int yang_snodes_iterate(const struct lys_module *module, yang_iterate_cb cb, + uint16_t flags, void *arg) { const struct lys_module *module_iter; uint32_t idx = 0; @@ -252,25 +252,6 @@ int yang_snodes_iterate_module(const struct lys_module *module, return ret; } -int yang_snodes_iterate_all(yang_iterate_cb cb, uint16_t flags, void *arg) -{ - struct yang_module *module; - int ret = YANG_ITER_CONTINUE; - - RB_FOREACH (module, yang_modules, &yang_modules) { - struct lys_node *snode; - - LY_TREE_FOR (module->info->data, snode) { - ret = yang_snodes_iterate_subtree(snode, NULL, cb, - flags, arg); - if (ret == YANG_ITER_STOP) - return ret; - } - } - - return ret; -} - void yang_snode_get_path(const struct lys_node *snode, enum yang_path_type type, char *xpath, size_t xpath_len) { diff --git a/lib/yang.h b/lib/yang.h index 867ade9676..0cd6a4a6f2 100644 --- a/lib/yang.h +++ b/lib/yang.h @@ -186,10 +186,11 @@ extern int yang_snodes_iterate_subtree(const struct lys_node *snode, void *arg); /* - * Iterate over all libyang schema nodes from the given YANG module. + * Iterate over all libyang schema nodes from all loeaded modules of from the + * given YANG module. * * module - * YANG module to operate on. + * When set, iterate over all nodes of the specified module only. * * cb * Function to call with each schema node. @@ -203,27 +204,8 @@ extern int yang_snodes_iterate_subtree(const struct lys_node *snode, * Returns: * The return value of the last called callback. */ -extern int yang_snodes_iterate_module(const struct lys_module *module, - yang_iterate_cb cb, uint16_t flags, - void *arg); - -/* - * Iterate over all libyang schema nodes from all loaded YANG modules. - * - * cb - * Function to call with each schema node. - * - * flags - * YANG_ITER_* flags to control how the iteration is performed. - * - * arg - * Arbitrary argument passed as the second parameter in each call to 'cb'. - * - * Returns: - * The return value of the last called callback. - */ -extern int yang_snodes_iterate_all(yang_iterate_cb cb, uint16_t flags, - void *arg); +extern int yang_snodes_iterate(const struct lys_module *module, + yang_iterate_cb cb, uint16_t flags, void *arg); /* * Build schema path or data path of the schema node. diff --git a/lib/yang_translator.c b/lib/yang_translator.c index 7dbb1f3f1a..1f64675d6a 100644 --- a/lib/yang_translator.c +++ b/lib/yang_translator.c @@ -469,12 +469,12 @@ static unsigned int yang_translator_validate(struct yang_translator *translator) args.errors = 0; for (ALL_LIST_ELEMENTS_RO(translator->modules, ln, tmodule)) { - yang_snodes_iterate_module( - tmodule->module, yang_translator_validate_cb, - YANG_ITER_FILTER_NPCONTAINERS - | YANG_ITER_FILTER_LIST_KEYS - | YANG_ITER_FILTER_INPUT_OUTPUT, - &args); + yang_snodes_iterate(tmodule->module, + yang_translator_validate_cb, + YANG_ITER_FILTER_NPCONTAINERS + | YANG_ITER_FILTER_LIST_KEYS + | YANG_ITER_FILTER_INPUT_OUTPUT, + &args); } if (args.errors) @@ -500,11 +500,11 @@ static unsigned int yang_module_nodes_count(const struct lys_module *module) { unsigned int total = 0; - yang_snodes_iterate_module(module, yang_module_nodes_count_cb, - YANG_ITER_FILTER_NPCONTAINERS - | YANG_ITER_FILTER_LIST_KEYS - | YANG_ITER_FILTER_INPUT_OUTPUT, - &total); + yang_snodes_iterate(module, yang_module_nodes_count_cb, + YANG_ITER_FILTER_NPCONTAINERS + | YANG_ITER_FILTER_LIST_KEYS + | YANG_ITER_FILTER_INPUT_OUTPUT, + &total); return total; } diff --git a/tools/gen_northbound_callbacks.c b/tools/gen_northbound_callbacks.c index eaab932228..a785f43cdf 100644 --- a/tools/gen_northbound_callbacks.c +++ b/tools/gen_northbound_callbacks.c @@ -368,13 +368,12 @@ int main(int argc, char *argv[]) /* Generate callback prototypes. */ if (!static_cbs) { printf("/* prototypes */\n"); - yang_snodes_iterate_module(module->info, generate_prototypes, 0, - NULL); + yang_snodes_iterate(module->info, generate_prototypes, 0, NULL); printf("\n"); } /* Generate callback functions. */ - yang_snodes_iterate_module(module->info, generate_callbacks, 0, NULL); + yang_snodes_iterate(module->info, generate_callbacks, 0, NULL); strlcpy(module_name_underscores, module->name, sizeof(module_name_underscores)); @@ -386,7 +385,7 @@ int main(int argc, char *argv[]) "\t.name = \"%s\",\n" "\t.nodes = {\n", module_name_underscores, module->name); - yang_snodes_iterate_module(module->info, generate_nb_nodes, 0, NULL); + yang_snodes_iterate(module->info, generate_nb_nodes, 0, NULL); printf("\t\t{\n" "\t\t\t.xpath = NULL,\n" "\t\t},\n"); diff --git a/tools/gen_yang_deviations.c b/tools/gen_yang_deviations.c index f908e1fc69..53a53c943c 100644 --- a/tools/gen_yang_deviations.c +++ b/tools/gen_yang_deviations.c @@ -71,8 +71,8 @@ int main(int argc, char *argv[]) module = yang_module_load(argv[0]); /* Generate deviations. */ - yang_snodes_iterate_module(module->info, generate_yang_deviation, - YANG_ITER_FILTER_IMPLICIT, NULL); + yang_snodes_iterate(module->info, generate_yang_deviation, + YANG_ITER_FILTER_IMPLICIT, NULL); /* Cleanup and exit. */ yang_terminate();