summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2019-02-28 23:54:47 +0100
committerRenato Westphal <renato@opensourcerouting.org>2019-03-03 00:01:49 +0100
commit1912caa2caf14936379df830e028d1492a061988 (patch)
tree9e940599a8f9406bb8d339d7cb887f34fccb5611 /lib
parentlib: simplify code that calculates configuration diffs (diff)
downloadfrr-1912caa2caf14936379df830e028d1492a061988.tar.xz
frr-1912caa2caf14936379df830e028d1492a061988.zip
lib: fix removal of yang non-presence containers
Non-presence containers don't have "destroy" callbacks. So, once a np-container is deleted, we need to call the "destroy" callbacks of its child nodes instead. This commit doesn't fix any real problem as of now since all np-containers from the FRR YANG modules contain or one more mandatory child nodes, so they can't be deleted (libyang will add missing np-containers when validating data). Nevertheless, upcoming YANG modules should benefit from this change. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/northbound.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/northbound.c b/lib/northbound.c
index fd71579ff..edf7e0eca 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -384,6 +384,26 @@ static void nb_config_diff_created(const struct lyd_node *dnode,
}
}
+static void nb_config_diff_deleted(const struct lyd_node *dnode,
+ struct nb_config_cbs *changes)
+{
+ if (nb_operation_is_valid(NB_OP_DESTROY, dnode->schema))
+ nb_config_diff_add_change(changes, NB_OP_DESTROY, dnode);
+ else if (CHECK_FLAG(dnode->schema->nodetype, LYS_CONTAINER)) {
+ struct lyd_node *child;
+
+ /*
+ * Non-presence containers need special handling since they
+ * don't have "destroy" callbacks. In this case, what we need to
+ * do is to call the "destroy" callbacks of their child nodes
+ * when applicable (i.e. optional nodes).
+ */
+ LY_TREE_FOR (dnode->child, child) {
+ nb_config_diff_deleted(child, changes);
+ }
+ }
+}
+
/* Calculate the delta between two different configurations. */
static void nb_config_diff(const struct nb_config *config1,
const struct nb_config *config2,
@@ -408,8 +428,7 @@ static void nb_config_diff(const struct nb_config *config1,
break;
case LYD_DIFF_DELETED:
dnode = diff->first[i];
- nb_config_diff_add_change(changes, NB_OP_DESTROY,
- dnode);
+ nb_config_diff_deleted(dnode, changes);
break;
case LYD_DIFF_CHANGED:
dnode = diff->second[i];