]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: fix prefix-list entry update
authorIgor Ryzhov <iryzhov@nfware.com>
Sun, 25 Feb 2024 23:00:17 +0000 (01:00 +0200)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Tue, 27 Feb 2024 11:40:00 +0000 (11:40 +0000)
When a prefix-list entry is updated, current NB code calls the
replacement code multiple times, once per each updated field. It means
that when multiple fields of an entry are changed in a single commit,
the replacement is done with an interim state of a prefix-list instead
of a final one. To fix the issue, we should call the replacement code
once, after all fields of an entry are updated.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
(cherry picked from commit 0bc2ab8598fa1418d3a45499e4f047622d21d6b4)

lib/filter_nb.c

index 91f80dcb5e86cc7a508df924e982e136f3c7a193..39042d39ab9a1bc740c75b40a300949345d0fb3b 100644 (file)
@@ -136,9 +136,6 @@ static int lib_prefix_list_entry_prefix_length_greater_or_equal_modify(
 
        ple->ge = yang_dnode_get_uint8(args->dnode, NULL);
 
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -157,9 +154,6 @@ static int lib_prefix_list_entry_prefix_length_lesser_or_equal_modify(
 
        ple->le = yang_dnode_get_uint8(args->dnode, NULL);
 
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -178,9 +172,6 @@ static int lib_prefix_list_entry_prefix_length_greater_or_equal_destroy(
 
        ple->ge = 0;
 
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -199,9 +190,6 @@ static int lib_prefix_list_entry_prefix_length_lesser_or_equal_destroy(
 
        ple->le = 0;
 
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -1229,6 +1217,22 @@ static int lib_prefix_list_entry_destroy(struct nb_cb_destroy_args *args)
        return NB_OK;
 }
 
+static void
+lib_prefix_list_entry_apply_finish(struct nb_cb_apply_finish_args *args)
+{
+       struct prefix_list_entry *ple;
+
+       ple = nb_running_get_entry(args->dnode, NULL, true);
+
+       /*
+        * Finish prefix entry update procedure. The procedure is started in
+        * children callbacks. `prefix_list_entry_update_start` can be called
+        * multiple times if multiple children are modified, but it is actually
+        * executed only once because of the protection by `ple->installed`.
+        */
+       prefix_list_entry_update_finish(ple);
+}
+
 /*
  * XPath: /frr-filter:lib/prefix-list/entry/action
  */
@@ -1251,9 +1255,6 @@ static int lib_prefix_list_entry_action_modify(struct nb_cb_modify_args *args)
        else
                ple->type = PREFIX_DENY;
 
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -1281,10 +1282,6 @@ static int lib_prefix_list_entry_prefix_modify(struct nb_cb_modify_args *args)
                prefix_copy(&ple->prefix, &p);
        }
 
-
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -1302,9 +1299,6 @@ static int lib_prefix_list_entry_prefix_destroy(struct nb_cb_destroy_args *args)
 
        memset(&ple->prefix, 0, sizeof(ple->prefix));
 
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -1552,9 +1546,6 @@ static int lib_prefix_list_entry_any_create(struct nb_cb_create_args *args)
                break;
        }
 
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -1572,9 +1563,6 @@ static int lib_prefix_list_entry_any_destroy(struct nb_cb_destroy_args *args)
 
        ple->any = false;
 
-       /* Finish prefix entry update procedure. */
-       prefix_list_entry_update_finish(ple);
-
        return NB_OK;
 }
 
@@ -1741,6 +1729,7 @@ const struct frr_yang_module_info frr_filter_info = {
                        .cbs = {
                                .create = lib_prefix_list_entry_create,
                                .destroy = lib_prefix_list_entry_destroy,
+                               .apply_finish = lib_prefix_list_entry_apply_finish,
                                .cli_cmp = prefix_list_cmp,
                                .cli_show = prefix_list_show,
                        }