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