diff options
author | Igor Ryzhov <iryzhov@nfware.com> | 2021-03-22 17:29:50 +0100 |
---|---|---|
committer | Igor Ryzhov <iryzhov@nfware.com> | 2021-03-23 12:57:33 +0100 |
commit | 634aa8253ea224d094f4a0aab01126cbd79c811e (patch) | |
tree | faa4312c9a48fc063b6cfd5f3b8d9fe859c3c573 /lib/northbound_cli.c | |
parent | Merge pull request #8115 from mjstapp/fix_ax_pthread (diff) | |
download | frr-634aa8253ea224d094f4a0aab01126cbd79c811e.tar.xz frr-634aa8253ea224d094f4a0aab01126cbd79c811e.zip |
lib: simplify nb_cli_show_dnode_cmds
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib/northbound_cli.c')
-rw-r--r-- | lib/northbound_cli.c | 75 |
1 files changed, 19 insertions, 56 deletions
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index a2c8bc863..efb887748 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -529,25 +529,6 @@ static int nb_cli_candidate_load_transaction(struct vty *vty, return CMD_SUCCESS; } -/* - * ly_iter_next_is_up: detects when iterating up on the yang model. - * - * This function detects whether next node in the iteration is upwards, - * then return the node otherwise return NULL. - */ -static struct lyd_node *ly_iter_next_up(const struct lyd_node *elem) -{ - /* Are we going downwards? Is this still not a leaf? */ - if (!(elem->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA))) - return NULL; - - /* Are there still leaves in this branch? */ - if (elem->next != NULL) - return NULL; - - return elem->parent; -} - /* Prepare the configuration for display. */ void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults) { @@ -569,51 +550,33 @@ void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults) ly_native_ctx); } +static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root, + bool with_defaults) +{ + struct lyd_node *child; + + LY_TREE_FOR (root->child, child) + nb_cli_show_dnode_cmds(vty, child, with_defaults); +} + void nb_cli_show_dnode_cmds(struct vty *vty, struct lyd_node *root, bool with_defaults) { - struct lyd_node *next, *child, *parent; + struct nb_node *nb_node; - LY_TREE_DFS_BEGIN (root, next, child) { - struct nb_node *nb_node; + if (!with_defaults && yang_dnode_is_default_recursive(root)) + return; - nb_node = child->schema->priv; - if (!nb_node || !nb_node->cbs.cli_show) - goto next; + nb_node = root->schema->priv; - /* Skip default values. */ - if (!with_defaults && yang_dnode_is_default_recursive(child)) - goto next; + if (nb_node && nb_node->cbs.cli_show) + (*nb_node->cbs.cli_show)(vty, root, with_defaults); - (*nb_node->cbs.cli_show)(vty, child, with_defaults); - next: - /* - * When transiting upwards in the yang model we should - * give the previous container/list node a chance to - * print its close vty output (e.g. "!" or "end-family" - * etc...). - */ - parent = ly_iter_next_up(child); - if (parent != NULL) { - nb_node = parent->schema->priv; - if (nb_node && nb_node->cbs.cli_show_end) - (*nb_node->cbs.cli_show_end)(vty, parent); - } + if (!(root->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA))) + show_dnode_children_cmds(vty, root, with_defaults); - /* - * There is a possible path in this macro that ends up - * dereferencing child->parent->parent. We just null checked - * child->parent by checking (ly_iter_next_up(child) != NULL) - * above. - * - * I am not sure whether it is possible for the other - * conditions within this macro guarding the problem - * dereference to be satisfied when child->parent == NULL. - */ -#ifndef __clang_analyzer__ - LY_TREE_DFS_END(root, next, child); -#endif - } + if (nb_node && nb_node->cbs.cli_show_end) + (*nb_node->cbs.cli_show_end)(vty, root); } static void nb_cli_show_config_cmds(struct vty *vty, struct nb_config *config, |