mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 18:56:40 +00:00
lib: simplify nb_cli_show_dnode_cmds
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
parent
53ab0eacab
commit
634aa8253e
@ -529,25 +529,6 @@ static int nb_cli_candidate_load_transaction(struct vty *vty,
|
|||||||
return CMD_SUCCESS;
|
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. */
|
/* Prepare the configuration for display. */
|
||||||
void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults)
|
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);
|
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,
|
void nb_cli_show_dnode_cmds(struct vty *vty, struct lyd_node *root,
|
||||||
bool with_defaults)
|
bool with_defaults)
|
||||||
{
|
{
|
||||||
struct lyd_node *next, *child, *parent;
|
struct nb_node *nb_node;
|
||||||
|
|
||||||
LY_TREE_DFS_BEGIN (root, next, child) {
|
if (!with_defaults && yang_dnode_is_default_recursive(root))
|
||||||
struct nb_node *nb_node;
|
return;
|
||||||
|
|
||||||
nb_node = child->schema->priv;
|
nb_node = root->schema->priv;
|
||||||
if (!nb_node || !nb_node->cbs.cli_show)
|
|
||||||
goto next;
|
|
||||||
|
|
||||||
/* Skip default values. */
|
if (nb_node && nb_node->cbs.cli_show)
|
||||||
if (!with_defaults && yang_dnode_is_default_recursive(child))
|
(*nb_node->cbs.cli_show)(vty, root, with_defaults);
|
||||||
goto next;
|
|
||||||
|
|
||||||
(*nb_node->cbs.cli_show)(vty, child, with_defaults);
|
if (!(root->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA)))
|
||||||
next:
|
show_dnode_children_cmds(vty, root, with_defaults);
|
||||||
/*
|
|
||||||
* 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 (nb_node && nb_node->cbs.cli_show_end)
|
||||||
* There is a possible path in this macro that ends up
|
(*nb_node->cbs.cli_show_end)(vty, root);
|
||||||
* 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nb_cli_show_config_cmds(struct vty *vty, struct nb_config *config,
|
static void nb_cli_show_config_cmds(struct vty *vty, struct nb_config *config,
|
||||||
|
Loading…
Reference in New Issue
Block a user