From: Renato Westphal Date: Thu, 28 Feb 2019 22:54:47 +0000 (-0300) Subject: lib: fix removal of yang non-presence containers X-Git-Tag: 7.1_pulled~175^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=1912caa2caf14936379df830e028d1492a061988;p=mirror%2Ffrr.git 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 --- diff --git a/lib/northbound.c b/lib/northbound.c index fd71579ff0..edf7e0eca6 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];