summaryrefslogtreecommitdiff
path: root/lib/northbound.c
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2025-02-11 07:12:06 +0000
committerChristian Hopps <chopps@labn.net>2025-02-14 18:14:30 +0000
commitd03ecf4562ef3ade6b7b83bf6c683c4741f395ba (patch)
treec98c21a9d07c6168c6702c8d0787a51d9ee77bf7 /lib/northbound.c
parentbaf4c1a78fe4cafdbb2cdbed030a31ea04a18c4a (diff)
lib: nb: call child destroy CBs when YANG container is deleted
Previously the code was only calling the child destroy callbacks if the target deleted node was a non-presence container. We now add a flag to the callback structure to instruct northbound to perform the rescursive delete for code that wishes for this to happen. - Fix wrong relative path lookup in keychain destroy callback Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib/northbound.c')
-rw-r--r--lib/northbound.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/northbound.c b/lib/northbound.c
index 60794b8728..ad9e517d52 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -516,20 +516,33 @@ void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq,
static void nb_config_diff_deleted(const struct lyd_node *dnode, uint32_t *seq,
struct nb_config_cbs *changes)
{
+ struct nb_node *nb_node = dnode->schema->priv;
+ struct lyd_node *child;
+ bool recursed = false;
+
/* Ignore unimplemented nodes. */
- if (!dnode->schema->priv)
+ if (!nb_node)
return;
+ /*
+ * If the CB structure indicates it (recurse flag set), call the destroy
+ * callbacks for the children of a containment node.
+ */
+ if (CHECK_FLAG(dnode->schema->nodetype, LYS_CONTAINER | LYS_LIST) &&
+ CHECK_FLAG(nb_node->cbs.flags, F_NB_CB_DESTROY_RECURSE)) {
+ recursed = true;
+ LY_LIST_FOR (lyd_child(dnode), child) {
+ nb_config_diff_deleted(child, seq, changes);
+ }
+ }
+
if (nb_cb_operation_is_valid(NB_CB_DESTROY, dnode->schema))
nb_config_diff_add_change(changes, NB_CB_DESTROY, seq, dnode);
- else if (CHECK_FLAG(dnode->schema->nodetype, LYS_CONTAINER)) {
- struct lyd_node *child;
-
+ else if (CHECK_FLAG(dnode->schema->nodetype, LYS_CONTAINER) && !recursed) {
/*
- * 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).
+ * If we didn't already above, call destroy on the children of
+ * this container (it's an NP container) as NP containers have
+ * no destroy CB themselves.
*/
LY_LIST_FOR (lyd_child(dnode), child) {
nb_config_diff_deleted(child, seq, changes);