mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 15:33:56 +00:00
lib: simplify code that calculates configuration diffs
This is just a small refactoring to reduce code duplication. No behavior changes intended. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
700e9faa28
commit
cacbffafc9
@ -348,41 +348,40 @@ static void nb_config_diff_del_changes(struct nb_config_cbs *changes)
|
|||||||
* configurations. Given a new subtree, calculate all new YANG data nodes,
|
* configurations. Given a new subtree, calculate all new YANG data nodes,
|
||||||
* excluding default leafs and leaf-lists. This is a recursive function.
|
* excluding default leafs and leaf-lists. This is a recursive function.
|
||||||
*/
|
*/
|
||||||
static void nb_config_diff_new_subtree(const struct lyd_node *dnode,
|
static void nb_config_diff_created(const struct lyd_node *dnode,
|
||||||
struct nb_config_cbs *changes)
|
struct nb_config_cbs *changes)
|
||||||
{
|
{
|
||||||
|
enum nb_operation operation;
|
||||||
struct lyd_node *child;
|
struct lyd_node *child;
|
||||||
|
|
||||||
LY_TREE_FOR (dnode->child, child) {
|
switch (dnode->schema->nodetype) {
|
||||||
enum nb_operation operation;
|
|
||||||
|
|
||||||
switch (child->schema->nodetype) {
|
|
||||||
case LYS_LEAF:
|
case LYS_LEAF:
|
||||||
case LYS_LEAFLIST:
|
case LYS_LEAFLIST:
|
||||||
if (lyd_wd_default((struct lyd_node_leaf_list *)child))
|
if (lyd_wd_default((struct lyd_node_leaf_list *)dnode))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (nb_operation_is_valid(NB_OP_CREATE, child->schema))
|
if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema))
|
||||||
operation = NB_OP_CREATE;
|
operation = NB_OP_CREATE;
|
||||||
else if (nb_operation_is_valid(NB_OP_MODIFY,
|
else if (nb_operation_is_valid(NB_OP_MODIFY, dnode->schema))
|
||||||
child->schema))
|
|
||||||
operation = NB_OP_MODIFY;
|
operation = NB_OP_MODIFY;
|
||||||
else
|
else
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
nb_config_diff_add_change(changes, operation, child);
|
nb_config_diff_add_change(changes, operation, dnode);
|
||||||
break;
|
break;
|
||||||
case LYS_CONTAINER:
|
case LYS_CONTAINER:
|
||||||
case LYS_LIST:
|
case LYS_LIST:
|
||||||
if (nb_operation_is_valid(NB_OP_CREATE, child->schema))
|
if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema))
|
||||||
nb_config_diff_add_change(changes, NB_OP_CREATE,
|
nb_config_diff_add_change(changes, NB_OP_CREATE, dnode);
|
||||||
child);
|
|
||||||
nb_config_diff_new_subtree(child, changes);
|
/* Process child nodes recursively. */
|
||||||
|
LY_TREE_FOR (dnode->child, child) {
|
||||||
|
nb_config_diff_created(child, changes);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate the delta between two different configurations. */
|
/* Calculate the delta between two different configurations. */
|
||||||
@ -399,42 +398,28 @@ static void nb_config_diff(const struct nb_config *config1,
|
|||||||
for (int i = 0; diff->type[i] != LYD_DIFF_END; i++) {
|
for (int i = 0; diff->type[i] != LYD_DIFF_END; i++) {
|
||||||
LYD_DIFFTYPE type;
|
LYD_DIFFTYPE type;
|
||||||
struct lyd_node *dnode;
|
struct lyd_node *dnode;
|
||||||
enum nb_operation operation;
|
|
||||||
|
|
||||||
type = diff->type[i];
|
type = diff->type[i];
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LYD_DIFF_CREATED:
|
case LYD_DIFF_CREATED:
|
||||||
dnode = diff->second[i];
|
dnode = diff->second[i];
|
||||||
|
nb_config_diff_created(dnode, changes);
|
||||||
if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema))
|
|
||||||
operation = NB_OP_CREATE;
|
|
||||||
else if (nb_operation_is_valid(NB_OP_MODIFY,
|
|
||||||
dnode->schema))
|
|
||||||
operation = NB_OP_MODIFY;
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
break;
|
break;
|
||||||
case LYD_DIFF_DELETED:
|
case LYD_DIFF_DELETED:
|
||||||
dnode = diff->first[i];
|
dnode = diff->first[i];
|
||||||
operation = NB_OP_DESTROY;
|
nb_config_diff_add_change(changes, NB_OP_DESTROY,
|
||||||
|
dnode);
|
||||||
break;
|
break;
|
||||||
case LYD_DIFF_CHANGED:
|
case LYD_DIFF_CHANGED:
|
||||||
dnode = diff->second[i];
|
dnode = diff->second[i];
|
||||||
operation = NB_OP_MODIFY;
|
nb_config_diff_add_change(changes, NB_OP_MODIFY, dnode);
|
||||||
break;
|
break;
|
||||||
case LYD_DIFF_MOVEDAFTER1:
|
case LYD_DIFF_MOVEDAFTER1:
|
||||||
case LYD_DIFF_MOVEDAFTER2:
|
case LYD_DIFF_MOVEDAFTER2:
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
nb_config_diff_add_change(changes, operation, dnode);
|
|
||||||
|
|
||||||
if (type == LYD_DIFF_CREATED
|
|
||||||
&& CHECK_FLAG(dnode->schema->nodetype,
|
|
||||||
LYS_CONTAINER | LYS_LIST))
|
|
||||||
nb_config_diff_new_subtree(dnode, changes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lyd_free_diff(diff);
|
lyd_free_diff(diff);
|
||||||
|
Loading…
Reference in New Issue
Block a user