From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nf-next PATCH 2/2] netfilter: nf_tables: Annotate reduced expressions
Date: Wed, 11 May 2022 18:54:53 +0200 [thread overview]
Message-ID: <20220511165453.22425-3-phil@nwl.cc> (raw)
In-Reply-To: <20220511165453.22425-1-phil@nwl.cc>
Introduce NFTA_EXPR_FLAG_REDUCED and set it for expressions which were
omitted from the rule blob due to being redundant. This allows user
space to verify the rule optimizer's results.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/net/netfilter/nf_tables.h | 2 +-
include/uapi/linux/netfilter/nf_tables.h | 7 +++++++
net/netfilter/nf_tables_api.c | 3 ++-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 78db54737de00..031477edaa885 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -129,7 +129,7 @@ struct nft_regs_track {
u8 num_reg;
} regs[NFT_REG32_NUM];
- const struct nft_expr *cur;
+ struct nft_expr *cur;
const struct nft_expr *last;
};
diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h
index 36bf019322a44..1da84ebc3f27a 100644
--- a/include/uapi/linux/netfilter/nf_tables.h
+++ b/include/uapi/linux/netfilter/nf_tables.h
@@ -523,6 +523,13 @@ enum nft_expr_attributes {
};
#define NFTA_EXPR_MAX (__NFTA_EXPR_MAX - 1)
+/**
+ * NFTA_EXPR_FLAGS values
+ *
+ * @NFTA_EXPR_FLAG_REDUCED: redundant expression omitted from blob
+ */
+#define NFTA_EXPR_FLAG_REDUCED (1 << 0)
+
/**
* enum nft_immediate_attributes - nf_tables immediate expression netlink attributes
*
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index fddc557983119..eb4fceae80385 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -8360,8 +8360,8 @@ static bool nft_expr_reduce(struct nft_regs_track *track,
static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *chain)
{
- const struct nft_expr *expr, *last;
struct nft_regs_track track = {};
+ struct nft_expr *expr, *last;
unsigned int size, data_size;
void *data, *data_boundary;
struct nft_rule_dp *prule;
@@ -8404,6 +8404,7 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha
track.cur = expr;
if (nft_expr_reduce(&track, expr)) {
+ expr->flags |= NFTA_EXPR_FLAG_REDUCED;
expr = track.cur;
continue;
}
--
2.34.1
next prev parent reply other threads:[~2022-05-11 16:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-11 16:54 [nf-next PATCH 0/2] nf_tables: Export rule optimizer results to user space Phil Sutter
2022-05-11 16:54 ` [nf-next PATCH 1/2] netfilter: nf_tables: Introduce expression flags Phil Sutter
2022-05-11 16:54 ` Phil Sutter [this message]
2022-05-11 23:37 ` [nf-next PATCH 2/2] netfilter: nf_tables: Annotate reduced expressions kernel test robot
2022-05-12 1:39 ` kernel test robot
2022-05-12 3:01 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220511165453.22425-3-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).