Blame SOURCES/0007-cache-Fix-for-doubled-output-after-reset-command.patch

911625
From a44bd9f4b6cf77cb75c5f596908100270893e8d5 Mon Sep 17 00:00:00 2001
911625
From: Phil Sutter <psutter@redhat.com>
911625
Date: Fri, 17 Jan 2020 12:50:23 +0100
911625
Subject: [PATCH] cache: Fix for doubled output after reset command
911625
911625
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1790793
911625
Upstream Status: nftables commit 7def18395d118
911625
911625
commit 7def18395d118e22a009de7e2e8de7f77906580b
911625
Author: Phil Sutter <phil@nwl.cc>
911625
Date:   Tue Jan 14 17:25:35 2020 +0100
911625
911625
    cache: Fix for doubled output after reset command
911625
911625
    Reset command causes a dump of the objects to reset and adds those to
911625
    cache. Yet it ignored if the object in question was already there and up
911625
    to now CMD_RESET was flagged as NFT_CACHE_FULL.
911625
911625
    Tackle this from two angles: First, reduce cache requirements of reset
911625
    command to the necessary bits which is table cache. This alone would
911625
    suffice if there wasn't interactive mode (and other libnftables users):
911625
    A cache containing the objects to reset might be in place already, so
911625
    add dumped objects to cache only if they don't exist already.
911625
911625
    Signed-off-by: Phil Sutter <phil@nwl.cc>
911625
    Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
911625
---
911625
 src/cache.c                                    |  4 +++-
911625
 src/rule.c                                     |  3 ++-
911625
 tests/shell/testcases/sets/0024named_objects_0 | 12 +++++++++++-
911625
 3 files changed, 16 insertions(+), 3 deletions(-)
911625
911625
diff --git a/src/cache.c b/src/cache.c
911625
index 0c28a28..05f0d68 100644
911625
--- a/src/cache.c
911625
+++ b/src/cache.c
911625
@@ -138,8 +138,10 @@ unsigned int cache_evaluate(struct nft_ctx *nft, struct list_head *cmds)
911625
 		case CMD_GET:
911625
 			flags = evaluate_cache_get(cmd, flags);
911625
 			break;
911625
-		case CMD_LIST:
911625
 		case CMD_RESET:
911625
+			flags |= NFT_CACHE_TABLE;
911625
+			break;
911625
+		case CMD_LIST:
911625
 		case CMD_EXPORT:
911625
 		case CMD_MONITOR:
911625
 			flags |= NFT_CACHE_FULL;
911625
diff --git a/src/rule.c b/src/rule.c
911625
index d985d3a..3ca1805 100644
911625
--- a/src/rule.c
911625
+++ b/src/rule.c
911625
@@ -2554,7 +2554,8 @@ static int do_command_reset(struct netlink_ctx *ctx, struct cmd *cmd)
911625
 	ret = netlink_reset_objs(ctx, cmd, type, dump);
911625
 	list_for_each_entry_safe(obj, next, &ctx->list, list) {
911625
 		table = table_lookup(&obj->handle, &ctx->nft->cache);
911625
-		list_move(&obj->list, &table->objs);
911625
+		if (!obj_lookup(table, obj->handle.obj.name, obj->type))
911625
+			list_move(&obj->list, &table->objs);
911625
 	}
911625
 	if (ret < 0)
911625
 		return ret;
911625
diff --git a/tests/shell/testcases/sets/0024named_objects_0 b/tests/shell/testcases/sets/0024named_objects_0
911625
index 3bd16f2..21200c3 100755
911625
--- a/tests/shell/testcases/sets/0024named_objects_0
911625
+++ b/tests/shell/testcases/sets/0024named_objects_0
911625
@@ -35,4 +35,14 @@ table inet x {
911625
 set -e
911625
 $NFT -f - <<< "$RULESET"
911625
 
911625
-$NFT reset counter inet x user321
911625
+EXPECTED="table inet x {
911625
+	counter user321 {
911625
+		packets 12 bytes 1433
911625
+	}
911625
+}"
911625
+
911625
+GET="$($NFT reset counter inet x user321)"
911625
+if [ "$EXPECTED" != "$GET" ] ; then
911625
+	$DIFF -u <(echo "$EXPECTED") <(echo "$GET")
911625
+	exit 1
911625
+fi
911625
-- 
911625
1.8.3.1
911625