From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net, johannes@sipsolutions.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
jiri@resnulli.us, razor@blackwall.org, nicolas.dichtel@6wind.com,
gnault@redhat.com, jacob.e.keller@intel.com, fw@strlen.de,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 10/13] genetlink: use iterator in the op to policy map dumping
Date: Tue, 18 Oct 2022 16:07:25 -0700 [thread overview]
Message-ID: <20221018230728.1039524-11-kuba@kernel.org> (raw)
In-Reply-To: <20221018230728.1039524-1-kuba@kernel.org>
We can't put the full iterator in the struct ctrl_dump_policy_ctx
because dump context is statically sized by netlink core.
Allocate it dynamically.
Rename policy to dump_map to make the logic a little easier to follow.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
net/netlink/genetlink.c | 48 ++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index c5fcb7b9c383..63807204805a 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1225,10 +1225,10 @@ static int genl_ctrl_event(int event, const struct genl_family *family,
struct ctrl_dump_policy_ctx {
struct netlink_policy_dump_state *state;
const struct genl_family *rt;
- unsigned int opidx;
+ struct genl_op_iter *op_iter;
u32 op;
u16 fam_id;
- u8 policies:1,
+ u8 dump_map:1,
single_op:1;
};
@@ -1298,9 +1298,16 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
if (!ctx->state)
return -ENODATA;
+
+ ctx->dump_map = 1;
return 0;
}
+ ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL);
+ if (!ctx->op_iter)
+ return -ENOMEM;
+ ctx->dump_map = genl_op_iter_init(rt, ctx->op_iter);
+
for (genl_op_iter_init(rt, &i); genl_op_iter_next(&i); ) {
if (i.doit.policy) {
err = netlink_policy_dump_add_policy(&ctx->state,
@@ -1318,12 +1325,16 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
}
}
- if (!ctx->state)
- return -ENODATA;
+ if (!ctx->state) {
+ err = -ENODATA;
+ goto err_free_op_iter;
+ }
return 0;
err_free_state:
netlink_policy_dump_free(ctx->state);
+err_free_op_iter:
+ kfree(ctx->op_iter);
return err;
}
@@ -1403,11 +1414,10 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
void *hdr;
- if (!ctx->policies) {
- struct genl_split_ops doit, dumpit;
- struct genl_ops op;
-
+ if (ctx->dump_map) {
if (ctx->single_op) {
+ struct genl_split_ops doit, dumpit;
+
if (genl_get_cmd(ctx->op, GENL_CMD_CAP_DO,
ctx->rt, &doit) &&
genl_get_cmd(ctx->op, GENL_CMD_CAP_DUMP,
@@ -1419,25 +1429,18 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
if (ctrl_dumppolicy_put_op(skb, cb, &doit, &dumpit))
return skb->len;
- ctx->opidx = genl_get_cmd_cnt(ctx->rt);
+ /* done with the per-op policy index list */
+ ctx->dump_map = 0;
}
- while (ctx->opidx < genl_get_cmd_cnt(ctx->rt)) {
- genl_get_cmd_by_index(ctx->opidx, ctx->rt, &op);
-
- genl_cmd_full_to_split(&doit, ctx->rt,
- &op, GENL_CMD_CAP_DO);
- genl_cmd_full_to_split(&dumpit, ctx->rt,
- &op, GENL_CMD_CAP_DUMP);
-
- if (ctrl_dumppolicy_put_op(skb, cb, &doit, &dumpit))
+ while (ctx->dump_map) {
+ if (ctrl_dumppolicy_put_op(skb, cb,
+ &ctx->op_iter->doit,
+ &ctx->op_iter->dumpit))
return skb->len;
- ctx->opidx++;
+ ctx->dump_map = genl_op_iter_next(ctx->op_iter);
}
-
- /* completed with the per-op policy index list */
- ctx->policies = true;
}
while (netlink_policy_dump_loop(ctx->state)) {
@@ -1470,6 +1473,7 @@ static int ctrl_dumppolicy_done(struct netlink_callback *cb)
{
struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
+ kfree(ctx->op_iter);
netlink_policy_dump_free(ctx->state);
return 0;
}
--
2.37.3
next prev parent reply other threads:[~2022-10-18 23:07 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 23:07 [PATCH net-next 00/13] genetlink: support per op type policies Jakub Kicinski
2022-10-18 23:07 ` [PATCH net-next 01/13] genetlink: refactor the cmd <> policy mapping dump Jakub Kicinski
2022-10-19 7:50 ` Johannes Berg
2022-10-19 15:59 ` Jakub Kicinski
2022-10-19 21:20 ` Jacob Keller
2022-10-18 23:07 ` [PATCH net-next 02/13] genetlink: move the private fields in struct genl_family Jakub Kicinski
2022-10-19 7:51 ` Johannes Berg
2022-10-19 21:21 ` Jacob Keller
2022-10-18 23:07 ` [PATCH net-next 03/13] genetlink: introduce split op representation Jakub Kicinski
2022-10-19 7:59 ` Johannes Berg
2022-10-19 19:14 ` Jakub Kicinski
2022-10-19 19:36 ` Johannes Berg
2022-10-19 19:50 ` Jakub Kicinski
2022-10-19 21:28 ` Jacob Keller
2022-10-18 23:07 ` [PATCH net-next 04/13] genetlink: load policy based on validation flags Jakub Kicinski
2022-10-19 8:01 ` Johannes Berg
2022-10-19 19:20 ` Jakub Kicinski
2022-10-19 19:33 ` Johannes Berg
2022-10-19 19:49 ` Jakub Kicinski
2022-10-18 23:07 ` [PATCH net-next 05/13] genetlink: check for callback type at op load time Jakub Kicinski
2022-10-19 21:33 ` Jacob Keller
2022-10-19 21:45 ` Jakub Kicinski
2022-10-18 23:07 ` [PATCH net-next 06/13] genetlink: add policies for both doit and dumpit in ctrl_dumppolicy_start() Jakub Kicinski
2022-10-19 8:08 ` Johannes Berg
2022-10-19 19:22 ` Jakub Kicinski
2022-10-18 23:07 ` [PATCH net-next 07/13] genetlink: support split policies in ctrl_dumppolicy_put_op() Jakub Kicinski
2022-10-19 21:38 ` Jacob Keller
2022-10-19 21:46 ` Jakub Kicinski
2022-10-18 23:07 ` [PATCH net-next 08/13] genetlink: inline genl_get_cmd() Jakub Kicinski
2022-10-19 21:46 ` Jacob Keller
2022-10-18 23:07 ` [PATCH net-next 09/13] genetlink: add iterator for walking family ops Jakub Kicinski
2022-10-19 21:49 ` Jacob Keller
2022-10-18 23:07 ` Jakub Kicinski [this message]
2022-10-19 21:53 ` [PATCH net-next 10/13] genetlink: use iterator in the op to policy map dumping Jacob Keller
2022-10-18 23:07 ` [PATCH net-next 11/13] genetlink: inline old iteration helpers Jakub Kicinski
2022-10-19 22:15 ` Jacob Keller
2022-10-18 23:07 ` [PATCH net-next 12/13] genetlink: allow families to use split ops directly Jakub Kicinski
2022-10-19 8:15 ` Johannes Berg
2022-10-19 19:25 ` Jakub Kicinski
2022-10-19 19:37 ` Johannes Berg
2022-10-19 19:57 ` Jakub Kicinski
2022-10-20 7:32 ` Johannes Berg
2022-10-20 18:09 ` Jakub Kicinski
2022-10-21 11:02 ` Johannes Berg
2022-10-21 15:01 ` Jakub Kicinski
2022-10-18 23:07 ` [PATCH net-next 13/13] genetlink: convert control family to split ops Jakub Kicinski
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=20221018230728.1039524-11-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=gnault@redhat.com \
--cc=jacob.e.keller@intel.com \
--cc=jiri@resnulli.us \
--cc=johannes@sipsolutions.net \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.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).