From: Jakub Kicinski <kuba@kernel.org>
To: netdev@vger.kernel.org
Cc: andrew@lunn.ch, johannes@sipsolutions.net, jiri@resnulli.us,
mkubecek@suse.cz, dsahern@kernel.org, pablo@netfilter.org,
Jakub Kicinski <kuba@kernel.org>
Subject: [RFC net-next 5/9] genetlink: add a structure for dump state
Date: Wed, 30 Sep 2020 17:05:14 -0700 [thread overview]
Message-ID: <20201001000518.685243-6-kuba@kernel.org> (raw)
In-Reply-To: <20201001000518.685243-1-kuba@kernel.org>
Whenever netlink dump uses more than 2 cb->args[] entries
code gets hard to read. We're about to add more state to
ctrl_dumppolicy() so create a structure.
Since the structure is typed and clearly named we can remove
the local fam_id variable and use ctx->fam_id directly.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
net/netlink/genetlink.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 38d8f353dba1..a8001044d8cd 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1102,13 +1102,18 @@ static int genl_ctrl_event(int event, const struct genl_family *family,
return 0;
}
+struct ctrl_dump_policy_ctx {
+ unsigned long state;
+ unsigned int fam_id;
+};
+
static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
{
+ struct ctrl_dump_policy_ctx *ctx = (void *)cb->args;
const struct genl_family *rt;
- unsigned int fam_id = cb->args[0];
int err;
- if (!fam_id) {
+ if (!ctx->fam_id) {
struct nlattr *tb[CTRL_ATTR_MAX + 1];
err = genlmsg_parse(cb->nlh, &genl_ctrl, tb,
@@ -1121,28 +1126,28 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
return -EINVAL;
if (tb[CTRL_ATTR_FAMILY_ID]) {
- fam_id = nla_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
+ ctx->fam_id = nla_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
} else {
rt = genl_family_find_byname(
nla_data(tb[CTRL_ATTR_FAMILY_NAME]));
if (!rt)
return -ENOENT;
- fam_id = rt->id;
+ ctx->fam_id = rt->id;
}
}
- rt = genl_family_find_byid(fam_id);
+ rt = genl_family_find_byid(ctx->fam_id);
if (!rt)
return -ENOENT;
if (!rt->policy)
return -ENODATA;
- err = netlink_policy_dump_start(rt->policy, rt->maxattr, &cb->args[1]);
+ err = netlink_policy_dump_start(rt->policy, rt->maxattr, &ctx->state);
if (err)
return err;
- while (netlink_policy_dump_loop(&cb->args[1])) {
+ while (netlink_policy_dump_loop(&ctx->state)) {
void *hdr;
struct nlattr *nest;
@@ -1159,7 +1164,7 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
if (!nest)
goto nla_put_failure;
- if (netlink_policy_dump_write(skb, cb->args[1]))
+ if (netlink_policy_dump_write(skb, ctx->state))
goto nla_put_failure;
nla_nest_end(skb, nest);
@@ -1172,7 +1177,6 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
break;
}
- cb->args[0] = fam_id;
return skb->len;
}
--
2.26.2
next prev parent reply other threads:[~2020-10-01 0:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 0:05 [RFC net-next 0/9] genetlink: support per-command policy dump Jakub Kicinski
2020-10-01 0:05 ` [RFC net-next 1/9] genetlink: add missing kdoc for validation flags Jakub Kicinski
2020-10-01 0:05 ` [RFC net-next 2/9] genetlink: reorg struct genl_family Jakub Kicinski
2020-10-01 7:34 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 3/9] genetlink: add small version of ops Jakub Kicinski
2020-10-01 7:40 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 4/9] genetlink: move to smaller ops wherever possible Jakub Kicinski
2020-10-01 7:42 ` Johannes Berg
2020-10-01 0:05 ` Jakub Kicinski [this message]
2020-10-01 7:48 ` [RFC net-next 5/9] genetlink: add a structure for dump state Johannes Berg
2020-10-01 8:04 ` Michal Kubecek
2020-10-01 0:05 ` [RFC net-next 6/9] genetlink: use .start callback for dumppolicy Jakub Kicinski
2020-10-01 7:49 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 7/9] genetlink: bring back per op policy Jakub Kicinski
2020-10-01 7:53 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 8/9] genetlink: use per-op policy for CTRL_CMD_GETPOLICY Jakub Kicinski
2020-10-01 7:56 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 9/9] genetlink: allow dumping command-specific policy Jakub Kicinski
2020-10-01 7:59 ` Johannes Berg
2020-10-01 15:41 ` Jakub Kicinski
2020-10-01 16:00 ` Johannes Berg
2020-10-01 16:24 ` Jakub Kicinski
2020-10-01 16:57 ` Johannes Berg
2020-10-01 17:09 ` 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=20201001000518.685243-6-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew@lunn.ch \
--cc=dsahern@kernel.org \
--cc=jiri@resnulli.us \
--cc=johannes@sipsolutions.net \
--cc=mkubecek@suse.cz \
--cc=netdev@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).