From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nf-next PATCH v3 2/4] netfilter: nf_tables: Introduce struct nft_expr_dp
Date: Thu, 12 May 2022 18:47:39 +0200 [thread overview]
Message-ID: <20220512164741.31440-3-phil@nwl.cc> (raw)
In-Reply-To: <20220512164741.31440-1-phil@nwl.cc>
This is a minimal variant of struct nft_expr for use in ruleset blob.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/net/netfilter/nf_tables.h | 9 ++++++++-
net/netfilter/nf_tables_api.c | 11 ++++++++---
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 4308e38df8e7a..708593dd4142e 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -338,6 +338,8 @@ struct nft_set_estimate {
#define NFT_EXPR_SIZE(size) size
#define NFT_EXPR_FULL_SIZE(size) (sizeof(struct nft_expr) + \
ALIGN(size, __alignof__(struct nft_expr)))
+#define NFT_EXPR_DP_SIZE(size) (sizeof(struct nft_expr_dp) + \
+ ALIGN(size, __alignof__(struct nft_expr_dp)))
/**
* struct nft_expr - nf_tables expression
@@ -992,12 +994,17 @@ static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext,
#define NFT_CHAIN_POLICY_UNSET U8_MAX
+struct nft_expr_dp {
+ const struct nft_expr_ops *ops;
+ unsigned char data[] __aligned(__alignof__(u64));
+};
+
struct nft_rule_dp {
u64 is_last:1,
dlen:12,
handle:42; /* for tracing */
unsigned char data[]
- __attribute__((aligned(__alignof__(struct nft_expr))));
+ __aligned(__alignof__(struct nft_expr_dp));
};
struct nft_rule_blob {
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 609fc9137ac01..ba2f712823776 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -8363,6 +8363,7 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha
struct nft_regs_track track = {};
void *data, *data_boundary;
struct nft_rule_dp *prule;
+ struct nft_expr_dp *pexpr;
struct nft_rule *rule;
/* already handled or inactive chain? */
@@ -8372,7 +8373,9 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha
data_size = 0;
list_for_each_entry(rule, &chain->rules, list) {
if (nft_is_active_next(net, rule)) {
- data_size += sizeof(*prule) + rule->dlen;
+ data_size += sizeof(*prule);
+ nft_rule_for_each_expr(expr, last, rule)
+ data_size += NFT_EXPR_DP_SIZE(expr->ops->size);
if (data_size > INT_MAX)
return -ENOMEM;
}
@@ -8406,11 +8409,13 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha
continue;
}
- expr_size = NFT_EXPR_FULL_SIZE(expr->ops->size);
+ expr_size = NFT_EXPR_DP_SIZE(expr->ops->size);
if (WARN_ON_ONCE(data + expr_size > data_boundary))
return -ENOMEM;
- memcpy(data + size, expr, expr_size);
+ pexpr = (struct nft_expr_dp *)(data + size);
+ pexpr->ops = expr->ops;
+ memcpy(pexpr->data, expr->data, expr->ops->size);
size += expr_size;
}
if (WARN_ON_ONCE(size >= 1 << 12))
--
2.34.1
next prev parent reply other threads:[~2022-05-12 16:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 16:47 [nf-next PATCH v3 0/4] nf_tables: Export rule optimizer results to user space Phil Sutter
2022-05-12 16:47 ` [nf-next PATCH v3 1/4] netfilter: nf_tables: Store net size in nft_expr_ops::size Phil Sutter
2022-05-12 16:47 ` Phil Sutter [this message]
2022-05-12 16:47 ` [nf-next PATCH v3 3/4] netfilter: nf_tables: Introduce expression flags Phil Sutter
2022-05-12 16:47 ` [nf-next PATCH v3 4/4] netfilter: nf_tables: Annotate reduced expressions Phil Sutter
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=20220512164741.31440-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).