From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Florian Westphal <fw@strlen.de>, netfilter-devel@vger.kernel.org
Subject: [nf PATCH v2 5/8] netfilter: nf_tables: Introduce nf_tables_getobj_single
Date: Thu, 28 Sep 2023 18:52:41 +0200 [thread overview]
Message-ID: <20230928165244.7168-6-phil@nwl.cc> (raw)
In-Reply-To: <20230928165244.7168-1-phil@nwl.cc>
Outsource the reply skb preparation for non-dump getrule requests into a
distinct function. Prep work for object reset locking.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Changes since v1:
- New patch
---
net/netfilter/nf_tables_api.c | 66 +++++++++++++++++++++++++++--------
1 file changed, 51 insertions(+), 15 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 67ee0d09cb844..eee149ea98b41 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -7775,19 +7775,65 @@ static int nf_tables_dump_obj_done(struct netlink_callback *cb)
}
/* called with rcu_read_lock held */
+static struct sk_buff *
+nf_tables_getobj_single(u32 portid, const struct nfnl_info *info,
+ const struct nlattr * const nla[], bool reset)
+{
+ struct netlink_ext_ack *extack = info->extack;
+ u8 genmask = nft_genmask_cur(info->net);
+ u8 family = info->nfmsg->nfgen_family;
+ const struct nft_table *table;
+ struct net *net = info->net;
+ struct nft_object *obj;
+ struct sk_buff *skb2;
+ u32 objtype;
+ int err;
+
+ if (!nla[NFTA_OBJ_NAME] ||
+ !nla[NFTA_OBJ_TYPE])
+ return ERR_PTR(-EINVAL);
+
+ table = nft_table_lookup(net, nla[NFTA_OBJ_TABLE], family, genmask, 0);
+ if (IS_ERR(table)) {
+ NL_SET_BAD_ATTR(extack, nla[NFTA_OBJ_TABLE]);
+ return ERR_CAST(table);
+ }
+
+ objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE]));
+ obj = nft_obj_lookup(net, table, nla[NFTA_OBJ_NAME], objtype, genmask);
+ if (IS_ERR(obj)) {
+ NL_SET_BAD_ATTR(extack, nla[NFTA_OBJ_NAME]);
+ return ERR_CAST(obj);
+ }
+
+ skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
+ if (!skb2)
+ return ERR_PTR(-ENOMEM);
+
+ err = nf_tables_fill_obj_info(skb2, net, portid,
+ info->nlh->nlmsg_seq, NFT_MSG_NEWOBJ, 0,
+ family, table, obj, reset);
+ if (err < 0) {
+ kfree_skb(skb2);
+ return ERR_PTR(err);
+ }
+
+ return skb2;
+}
+
static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
const struct nlattr * const nla[])
{
struct netlink_ext_ack *extack = info->extack;
u8 genmask = nft_genmask_cur(info->net);
u8 family = info->nfmsg->nfgen_family;
+ u32 portid = NETLINK_CB(skb).portid;
const struct nft_table *table;
struct net *net = info->net;
struct nft_object *obj;
struct sk_buff *skb2;
bool reset = false;
u32 objtype;
- int err;
if (info->nlh->nlmsg_flags & NLM_F_DUMP) {
struct netlink_dump_control c = {
@@ -7818,10 +7864,6 @@ static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
return PTR_ERR(obj);
}
- skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC);
- if (!skb2)
- return -ENOMEM;
-
if (NFNL_MSG_TYPE(info->nlh->nlmsg_type) == NFT_MSG_GETOBJ_RESET)
reset = true;
@@ -7840,17 +7882,11 @@ static int nf_tables_getobj(struct sk_buff *skb, const struct nfnl_info *info,
kfree(buf);
}
- err = nf_tables_fill_obj_info(skb2, net, NETLINK_CB(skb).portid,
- info->nlh->nlmsg_seq, NFT_MSG_NEWOBJ, 0,
- family, table, obj, reset);
- if (err < 0)
- goto err_fill_obj_info;
-
- return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
+ skb2 = nf_tables_getobj_single(portid, info, nla, reset);
+ if (IS_ERR(skb2))
+ return PTR_ERR(skb2);
-err_fill_obj_info:
- kfree_skb(skb2);
- return err;
+ return nfnetlink_unicast(skb2, net, portid);
}
static void nft_obj_destroy(const struct nft_ctx *ctx, struct nft_object *obj)
--
2.41.0
next prev parent reply other threads:[~2023-09-28 16:52 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 16:52 [nf PATCH v2 0/8] Introduce locking for reset requests Phil Sutter
2023-09-28 16:52 ` [nf PATCH v2 1/8] netfilter: nf_tables: Don't allocate nft_rule_dump_ctx Phil Sutter
2023-09-28 18:49 ` Pablo Neira Ayuso
2023-09-29 10:15 ` Phil Sutter
2023-09-28 19:00 ` Florian Westphal
2023-09-29 10:13 ` Phil Sutter
2023-09-28 16:52 ` [nf PATCH v2 2/8] netfilter: nf_tables: Introduce nf_tables_getrule_single() Phil Sutter
2023-09-28 16:52 ` [nf PATCH v2 3/8] netfilter: nf_tables: Add locking for NFT_MSG_GETRULE_RESET requests Phil Sutter
2023-09-28 16:52 ` [nf PATCH v2 4/8] netfilter: nf_tables: Introduce struct nft_obj_dump_ctx Phil Sutter
2023-09-28 16:52 ` Phil Sutter [this message]
2023-09-28 16:52 ` [nf PATCH v2 6/8] netfilter: nf_tables: Add locking for NFT_MSG_GETOBJ_RESET requests Phil Sutter
2023-09-28 16:52 ` [nf PATCH v2 7/8] netfilter: nf_tables: Pass reset bit in nft_set_dump_ctx Phil Sutter
2023-09-28 18:53 ` Pablo Neira Ayuso
2023-09-29 10:08 ` Phil Sutter
2023-09-29 10:15 ` Pablo Neira Ayuso
2023-09-29 10:18 ` Phil Sutter
2023-09-29 10:56 ` Pablo Neira Ayuso
2023-09-29 11:12 ` Phil Sutter
2023-09-28 16:52 ` [nf PATCH v2 8/8] netfilter: nf_tables: Add locking for NFT_MSG_GETSETELEM_RESET requests Phil Sutter
2023-09-28 17:46 ` Florian Westphal
2023-09-28 18:47 ` Pablo Neira Ayuso
2023-09-28 18:57 ` Florian Westphal
2023-09-28 19:04 ` Pablo Neira Ayuso
2023-09-28 19:21 ` Florian Westphal
2023-09-28 20:07 ` Florian Westphal
2023-09-29 11:25 ` Phil Sutter
2023-09-29 11:30 ` Florian Westphal
2023-09-29 11:45 ` Phil Sutter
2023-09-28 19:39 ` Jozsef Kadlecsik
2023-09-28 20:09 ` Florian Westphal
2023-09-28 20:25 ` Jozsef Kadlecsik
2023-09-29 11:03 ` Phil Sutter
2023-09-28 18:51 ` Pablo Neira Ayuso
2023-09-29 10:28 ` 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=20230928165244.7168-6-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=fw@strlen.de \
--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).