|
|
ac684a |
From 61c295c9dec447239ed2c84b0073594ffecf7554 Mon Sep 17 00:00:00 2001
|
|
|
ac684a |
From: Phil Sutter <psutter@redhat.com>
|
|
|
ac684a |
Date: Wed, 27 Apr 2022 14:46:47 +0200
|
|
|
ac684a |
Subject: [PATCH] src: add CMD_OBJ_SETELEMS
|
|
|
ac684a |
|
|
|
ac684a |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2073287
|
|
|
ac684a |
Upstream Status: nftables commit c9eae091983ae
|
|
|
ac684a |
Conflicts: Context change due to missing commit 086ec6f30c96e
|
|
|
ac684a |
("mnl: extended error support for create command").
|
|
|
ac684a |
|
|
|
ac684a |
commit c9eae091983ae9ffcf2ca5b666bc03d5a1916c2f
|
|
|
ac684a |
Author: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
ac684a |
Date: Fri May 8 14:44:03 2020 +0200
|
|
|
ac684a |
|
|
|
ac684a |
src: add CMD_OBJ_SETELEMS
|
|
|
ac684a |
|
|
|
ac684a |
This new command type results from expanding the set definition in two
|
|
|
ac684a |
commands: One to add the set and another to add the elements. This
|
|
|
ac684a |
results in 1:1 mapping between the command object to the netlink API.
|
|
|
ac684a |
The command is then translated into a netlink message which gets a
|
|
|
ac684a |
unique sequence number. This sequence number allows to correlate the
|
|
|
ac684a |
netlink extended error reporting with the corresponding command.
|
|
|
ac684a |
|
|
|
ac684a |
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
|
|
ac684a |
---
|
|
|
ac684a |
include/rule.h | 2 ++
|
|
|
ac684a |
src/rule.c | 23 +++++++++++++++++++----
|
|
|
ac684a |
2 files changed, 21 insertions(+), 4 deletions(-)
|
|
|
ac684a |
|
|
|
ac684a |
diff --git a/include/rule.h b/include/rule.h
|
|
|
ac684a |
index 7fe607f..1efd4fb 100644
|
|
|
ac684a |
--- a/include/rule.h
|
|
|
ac684a |
+++ b/include/rule.h
|
|
|
ac684a |
@@ -545,6 +545,7 @@ enum cmd_ops {
|
|
|
ac684a |
* @CMD_OBJ_ELEMENTS: set element(s)
|
|
|
ac684a |
* @CMD_OBJ_SET: set
|
|
|
ac684a |
* @CMD_OBJ_SETS: multiple sets
|
|
|
ac684a |
+ * @CMD_OBJ_SETELEMS: set elements
|
|
|
ac684a |
* @CMD_OBJ_RULE: rule
|
|
|
ac684a |
* @CMD_OBJ_CHAIN: chain
|
|
|
ac684a |
* @CMD_OBJ_CHAINS: multiple chains
|
|
|
ac684a |
@@ -572,6 +573,7 @@ enum cmd_obj {
|
|
|
ac684a |
CMD_OBJ_INVALID,
|
|
|
ac684a |
CMD_OBJ_ELEMENTS,
|
|
|
ac684a |
CMD_OBJ_SET,
|
|
|
ac684a |
+ CMD_OBJ_SETELEMS,
|
|
|
ac684a |
CMD_OBJ_SETS,
|
|
|
ac684a |
CMD_OBJ_RULE,
|
|
|
ac684a |
CMD_OBJ_CHAIN,
|
|
|
ac684a |
diff --git a/src/rule.c b/src/rule.c
|
|
|
ac684a |
index afb6dc9..c43e0cd 100644
|
|
|
ac684a |
--- a/src/rule.c
|
|
|
ac684a |
+++ b/src/rule.c
|
|
|
ac684a |
@@ -1352,11 +1352,11 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,
|
|
|
ac684a |
void nft_cmd_expand(struct cmd *cmd)
|
|
|
ac684a |
{
|
|
|
ac684a |
struct list_head new_cmds;
|
|
|
ac684a |
+ struct set *set, *newset;
|
|
|
ac684a |
struct flowtable *ft;
|
|
|
ac684a |
struct table *table;
|
|
|
ac684a |
struct chain *chain;
|
|
|
ac684a |
struct rule *rule;
|
|
|
ac684a |
- struct set *set;
|
|
|
ac684a |
struct obj *obj;
|
|
|
ac684a |
struct cmd *new;
|
|
|
ac684a |
struct handle h;
|
|
|
ac684a |
@@ -1412,6 +1412,18 @@ void nft_cmd_expand(struct cmd *cmd)
|
|
|
ac684a |
}
|
|
|
ac684a |
list_splice(&new_cmds, &cmd->list);
|
|
|
ac684a |
break;
|
|
|
ac684a |
+ case CMD_OBJ_SET:
|
|
|
ac684a |
+ set = cmd->set;
|
|
|
ac684a |
+ memset(&h, 0, sizeof(h));
|
|
|
ac684a |
+ handle_merge(&h, &set->handle);
|
|
|
ac684a |
+ newset = set_clone(set);
|
|
|
ac684a |
+ newset->handle.set_id = set->handle.set_id;
|
|
|
ac684a |
+ newset->init = set->init;
|
|
|
ac684a |
+ set->init = NULL;
|
|
|
ac684a |
+ new = cmd_alloc(CMD_ADD, CMD_OBJ_SETELEMS, &h,
|
|
|
ac684a |
+ &set->location, newset);
|
|
|
ac684a |
+ list_add(&new->list, &cmd->list);
|
|
|
ac684a |
+ break;
|
|
|
ac684a |
default:
|
|
|
ac684a |
break;
|
|
|
ac684a |
}
|
|
|
ac684a |
@@ -1460,6 +1472,7 @@ void cmd_free(struct cmd *cmd)
|
|
|
ac684a |
expr_free(cmd->expr);
|
|
|
ac684a |
break;
|
|
|
ac684a |
case CMD_OBJ_SET:
|
|
|
ac684a |
+ case CMD_OBJ_SETELEMS:
|
|
|
ac684a |
set_free(cmd->set);
|
|
|
ac684a |
break;
|
|
|
ac684a |
case CMD_OBJ_RULE:
|
|
|
ac684a |
@@ -1545,7 +1558,7 @@ static int do_add_setelems(struct netlink_ctx *ctx, struct cmd *cmd,
|
|
|
ac684a |
}
|
|
|
ac684a |
|
|
|
ac684a |
static int do_add_set(struct netlink_ctx *ctx, const struct cmd *cmd,
|
|
|
ac684a |
- uint32_t flags)
|
|
|
ac684a |
+ uint32_t flags, bool add)
|
|
|
ac684a |
{
|
|
|
ac684a |
struct set *set = cmd->set;
|
|
|
ac684a |
|
|
|
ac684a |
@@ -1556,7 +1569,7 @@ static int do_add_set(struct netlink_ctx *ctx, const struct cmd *cmd,
|
|
|
ac684a |
&ctx->nft->output) < 0)
|
|
|
ac684a |
return -1;
|
|
|
ac684a |
}
|
|
|
ac684a |
- if (mnl_nft_set_add(ctx, cmd, flags) < 0)
|
|
|
ac684a |
+ if (add && mnl_nft_set_add(ctx, cmd, flags) < 0)
|
|
|
ac684a |
return -1;
|
|
|
ac684a |
if (set->init != NULL) {
|
|
|
ac684a |
return __do_add_setelems(ctx, set, set->init, flags);
|
|
|
ac684a |
@@ -1579,7 +1592,9 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl)
|
|
|
ac684a |
case CMD_OBJ_RULE:
|
|
|
ac684a |
return mnl_nft_rule_add(ctx, cmd, flags | NLM_F_APPEND);
|
|
|
ac684a |
case CMD_OBJ_SET:
|
|
|
ac684a |
- return do_add_set(ctx, cmd, flags);
|
|
|
ac684a |
+ return do_add_set(ctx, cmd, flags, true);
|
|
|
ac684a |
+ case CMD_OBJ_SETELEMS:
|
|
|
ac684a |
+ return do_add_set(ctx, cmd, flags, false);
|
|
|
ac684a |
case CMD_OBJ_ELEMENTS:
|
|
|
ac684a |
return do_add_setelems(ctx, cmd, flags);
|
|
|
ac684a |
case CMD_OBJ_COUNTER:
|
|
|
ac684a |
--
|
|
|
ac684a |
2.34.1
|
|
|
ac684a |
|