diff options
| author | Jafar Al-Gharaibeh <jafar@atcorp.com> | 2025-02-17 23:14:16 -0600 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-17 23:14:16 -0600 | 
| commit | 9a729a2fa3262e7d9718c40e43da56e75afea29e (patch) | |
| tree | 02122a352a3d0d7a3bb57d7c7a102d612cd4d6af | |
| parent | 33ed0a3315682382cfbac4a6b3ff4f18b67f69d1 (diff) | |
| parent | 3c08c6fe28e2345999cdeb3c8cba2ac8903faa8b (diff) | |
Merge pull request #18191 from FRRouting/mergify/bp/dev/10.3/pr-18082
lib: nb: call child destroy CBs when YANG container is deleted (backport #18082)
| -rw-r--r-- | lib/keychain_nb.c | 4 | ||||
| -rw-r--r-- | lib/northbound.c | 29 | ||||
| -rw-r--r-- | lib/northbound.h | 11 | 
3 files changed, 34 insertions, 10 deletions
diff --git a/lib/keychain_nb.c b/lib/keychain_nb.c index 57967b30a5..7c3df1c857 100644 --- a/lib/keychain_nb.c +++ b/lib/keychain_nb.c @@ -587,9 +587,9 @@ static int key_chains_key_chain_key_crypto_algorithm_destroy(  	if (args->event != NB_EV_APPLY)  		return NB_OK; -	name = yang_dnode_get_string(args->dnode, "../../../name"); +	name = yang_dnode_get_string(args->dnode, "../../name");  	keychain = keychain_lookup(name); -	index = (uint32_t)yang_dnode_get_uint64(args->dnode, "../../key-id"); +	index = (uint32_t)yang_dnode_get_uint64(args->dnode, "../key-id");  	key = key_lookup(keychain, index);  	key->hash_algo = KEYCHAIN_ALGO_NULL;  	keychain_touch(keychain); 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); diff --git a/lib/northbound.h b/lib/northbound.h index c31f007e70..7d38c63a86 100644 --- a/lib/northbound.h +++ b/lib/northbound.h @@ -386,6 +386,11 @@ struct nb_callbacks {  	int (*destroy)(struct nb_cb_destroy_args *args);  	/* +	 * Flags to control the how northbound callbacks are invoked. +	 */ +	uint flags; + +	/*  	 * Configuration callback.  	 *  	 * A list entry or leaf-list entry has been moved. Only applicable when @@ -622,6 +627,12 @@ struct nb_callbacks {  	void (*cli_show_end)(struct vty *vty, const struct lyd_node *dnode);  }; +/* + * Flag indicating the northbound should recurse destroy the children of this + * node when it is destroyed. + */ +#define F_NB_CB_DESTROY_RECURSE 0x01 +  struct nb_dependency_callbacks {  	void (*get_dependant_xpath)(const struct lyd_node *dnode, char *xpath);  	void (*get_dependency_xpath)(const struct lyd_node *dnode, char *xpath);  | 
