]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: fix removal of yang non-presence containers
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 28 Feb 2019 22:54:47 +0000 (19:54 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 2 Mar 2019 23:01:49 +0000 (20:01 -0300)
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>
lib/northbound.c

index fd71579ff02d4e7cb26ba9d3afbaaa8a185d65cf..edf7e0eca6893add20ad0dbbd5927b23d78500ee 100644 (file)
@@ -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];