]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: fix order of northbound callbacks 15403/head
authorIgor Ryzhov <iryzhov@nfware.com>
Tue, 20 Feb 2024 20:32:52 +0000 (22:32 +0200)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Wed, 21 Feb 2024 08:02:18 +0000 (08:02 +0000)
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 <iryzhov@nfware.com>
(cherry picked from commit 01f371a677dc52ff888b14360f6ffd63b91f3845)

lib/northbound.c

index a3d91e56afb348cdb86c7d178686db85d96d3d6f..6b31b818c515412e737c1db4271fcbe1fb0a67b8 100644 (file)
@@ -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.