From 323caf1d7013c4787b30ee34b3c53dd4bf0a92aa Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Tue, 20 Feb 2024 22:27:29 +0200 Subject: [PATCH 1/2] lib: add missing priority for affinity map callbacks Other objects depend on affinity-maps being created before them by using leafref with require-instance true. Set the priority to ensure that. Signed-off-by: Igor Ryzhov --- lib/affinitymap_northbound.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/affinitymap_northbound.c b/lib/affinitymap_northbound.c index 8e84d36f2f..003e0c11b9 100644 --- a/lib/affinitymap_northbound.c +++ b/lib/affinitymap_northbound.c @@ -94,7 +94,8 @@ const struct frr_yang_module_info frr_affinity_map_info = { .cbs = { .create = lib_affinity_map_create, .destroy = lib_affinity_map_destroy, - } + }, + .priority = NB_DFLT_PRIORITY - 1, }, { .xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map/value", From 01f371a677dc52ff888b14360f6ffd63b91f3845 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Tue, 20 Feb 2024 22:32:52 +0200 Subject: [PATCH 2/2] lib: fix order of northbound callbacks When ordering the NB callbacks according to their priorities, if the operation is "destroy" we should reverse the order, to destroy the dependants before the dependencies. This fixes the crash, that can be reproduced with the following steps: ``` frr# conf term file-lock frr(config)# affinity-map map bit-position 10 frr(config)# interface test frr(config-if)# link-params frr(config-link-params)# affinity map frr(config-link-params)# exit frr(config-if)# exit frr(config)# mgmt commit apply frr(config)# no affinity-map map frr(config)# interface test frr(config-if)# link-params frr(config-link-params)# no affinity map frr(config-link-params)# exit frr(config-if)# exit frr(config)# mgmt commit apply ``` Signed-off-by: Igor Ryzhov --- lib/northbound.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/northbound.c b/lib/northbound.c index a3d91e56af..6b31b818c5 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -391,11 +391,14 @@ void nb_config_replace(struct nb_config *config_dst, static inline int nb_config_cb_compare(const struct nb_config_cb *a, const struct nb_config_cb *b) { - /* Sort by priority first. */ + /* + * Sort by priority first. If the operation is "destroy", reverse the + * order, so that the dependencies are destroyed before the dependants. + */ if (a->nb_node->priority < b->nb_node->priority) - return -1; + return a->operation != NB_CB_DESTROY ? -1 : 1; if (a->nb_node->priority > b->nb_node->priority) - return 1; + return a->operation != NB_CB_DESTROY ? 1 : -1; /* * Preserve the order of the configuration changes as told by libyang.