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 6/9] genetlink: use .start callback for dumppolicy
Date: Wed, 30 Sep 2020 17:05:15 -0700 [thread overview]
Message-ID: <20201001000518.685243-7-kuba@kernel.org> (raw)
In-Reply-To: <20201001000518.685243-1-kuba@kernel.org>
The structure of ctrl_dumppolicy() is clearly split into
init and dumping. Move the init to a .start callback
for clarity, it's a more idiomatic netlink dump code structure.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
net/netlink/genetlink.c | 48 ++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index a8001044d8cd..dfa8a00640c0 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1107,33 +1107,29 @@ struct ctrl_dump_policy_ctx {
unsigned int fam_id;
};
-static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
+static int ctrl_dumppolicy_start(struct netlink_callback *cb)
{
struct ctrl_dump_policy_ctx *ctx = (void *)cb->args;
+ struct nlattr *tb[CTRL_ATTR_MAX + 1];
const struct genl_family *rt;
int err;
- if (!ctx->fam_id) {
- struct nlattr *tb[CTRL_ATTR_MAX + 1];
-
- err = genlmsg_parse(cb->nlh, &genl_ctrl, tb,
- genl_ctrl.maxattr,
- genl_ctrl.policy, cb->extack);
- if (err)
- return err;
+ err = genlmsg_parse(cb->nlh, &genl_ctrl, tb, genl_ctrl.maxattr,
+ genl_ctrl.policy, cb->extack);
+ if (err)
+ return err;
- if (!tb[CTRL_ATTR_FAMILY_ID] && !tb[CTRL_ATTR_FAMILY_NAME])
- return -EINVAL;
+ if (!tb[CTRL_ATTR_FAMILY_ID] && !tb[CTRL_ATTR_FAMILY_NAME])
+ return -EINVAL;
- if (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;
- ctx->fam_id = rt->id;
- }
+ if (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;
+ ctx->fam_id = rt->id;
}
rt = genl_family_find_byid(ctx->fam_id);
@@ -1143,9 +1139,12 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
if (!rt->policy)
return -ENODATA;
- err = netlink_policy_dump_start(rt->policy, rt->maxattr, &ctx->state);
- if (err)
- return err;
+ return netlink_policy_dump_start(rt->policy, rt->maxattr, &ctx->state);
+}
+
+static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
+{
+ struct ctrl_dump_policy_ctx *ctx = (void *)cb->args;
while (netlink_policy_dump_loop(&ctx->state)) {
void *hdr;
@@ -1157,7 +1156,7 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
if (!hdr)
goto nla_put_failure;
- if (nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, rt->id))
+ if (nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, ctx->fam_id))
goto nla_put_failure;
nest = nla_nest_start(skb, CTRL_ATTR_POLICY);
@@ -1189,6 +1188,7 @@ static const struct genl_ops genl_ctrl_ops[] = {
},
{
.cmd = CTRL_CMD_GETPOLICY,
+ .start = ctrl_dumppolicy_start,
.dumpit = ctrl_dumppolicy,
},
};
--
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 ` [RFC net-next 5/9] genetlink: add a structure for dump state Jakub Kicinski
2020-10-01 7:48 ` Johannes Berg
2020-10-01 8:04 ` Michal Kubecek
2020-10-01 0:05 ` Jakub Kicinski [this message]
2020-10-01 7:49 ` [RFC net-next 6/9] genetlink: use .start callback for dumppolicy 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-7-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).