From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.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 v2 07/13] genetlink: support split policies in ctrl_dumppolicy_put_op()
Date: Wed, 2 Nov 2022 14:33:32 -0700 [thread overview]
Message-ID: <20221102213338.194672-8-kuba@kernel.org> (raw)
In-Reply-To: <20221102213338.194672-1-kuba@kernel.org>
Pass do and dump versions of the op to ctrl_dumppolicy_put_op()
so that it can provide a different policy index for the two.
Since we now look at policies, and those are set appropriately
there's no need to look at the GENL_DONT_VALIDATE_DUMP flag.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
---
v2: while at it fix the whitespace to appease checkpatch
---
net/netlink/genetlink.c | 55 ++++++++++++++++++++++++-----------------
1 file changed, 33 insertions(+), 22 deletions(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index d0c35738839b..93e33e20a0e8 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1345,7 +1345,8 @@ static void *ctrl_dumppolicy_prep(struct sk_buff *skb,
static int ctrl_dumppolicy_put_op(struct sk_buff *skb,
struct netlink_callback *cb,
- struct genl_ops *op)
+ struct genl_split_ops *doit,
+ struct genl_split_ops *dumpit)
{
struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
struct nlattr *nest_pol, *nest_op;
@@ -1353,10 +1354,7 @@ static int ctrl_dumppolicy_put_op(struct sk_buff *skb,
int idx;
/* skip if we have nothing to show */
- if (!op->policy)
- return 0;
- if (!op->doit &&
- (!op->dumpit || op->validate & GENL_DONT_VALIDATE_DUMP))
+ if (!doit->policy && !dumpit->policy)
return 0;
hdr = ctrl_dumppolicy_prep(skb, cb);
@@ -1367,21 +1365,26 @@ static int ctrl_dumppolicy_put_op(struct sk_buff *skb,
if (!nest_pol)
goto err;
- nest_op = nla_nest_start(skb, op->cmd);
+ nest_op = nla_nest_start(skb, doit->cmd);
if (!nest_op)
goto err;
- /* for now both do/dump are always the same */
- idx = netlink_policy_dump_get_policy_idx(ctx->state,
- op->policy,
- op->maxattr);
+ if (doit->policy) {
+ idx = netlink_policy_dump_get_policy_idx(ctx->state,
+ doit->policy,
+ doit->maxattr);
- if (op->doit && nla_put_u32(skb, CTRL_ATTR_POLICY_DO, idx))
- goto err;
+ if (nla_put_u32(skb, CTRL_ATTR_POLICY_DO, idx))
+ goto err;
+ }
+ if (dumpit->policy) {
+ idx = netlink_policy_dump_get_policy_idx(ctx->state,
+ dumpit->policy,
+ dumpit->maxattr);
- if (op->dumpit && !(op->validate & GENL_DONT_VALIDATE_DUMP) &&
- nla_put_u32(skb, CTRL_ATTR_POLICY_DUMP, idx))
- goto err;
+ if (nla_put_u32(skb, CTRL_ATTR_POLICY_DUMP, idx))
+ goto err;
+ }
nla_nest_end(skb, nest_op);
nla_nest_end(skb, nest_pol);
@@ -1399,16 +1402,19 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
void *hdr;
if (!ctx->policies) {
+ struct genl_split_ops doit, dumpit;
struct genl_ops op;
if (ctx->single_op) {
- int err;
-
- err = genl_get_cmd(ctx->op, ctx->rt, &op);
- if (WARN_ON(err))
- return err;
+ if (genl_get_cmd_split(ctx->op, GENL_CMD_CAP_DO,
+ ctx->rt, &doit) &&
+ genl_get_cmd_split(ctx->op, GENL_CMD_CAP_DUMP,
+ ctx->rt, &dumpit)) {
+ WARN_ON(1);
+ return -ENOENT;
+ }
- if (ctrl_dumppolicy_put_op(skb, cb, &op))
+ if (ctrl_dumppolicy_put_op(skb, cb, &doit, &dumpit))
return skb->len;
/* don't enter the loop below */
@@ -1418,7 +1424,12 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
while (ctx->opidx < genl_get_cmd_cnt(ctx->rt)) {
genl_get_cmd_by_index(ctx->opidx, ctx->rt, &op);
- if (ctrl_dumppolicy_put_op(skb, cb, &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))
return skb->len;
ctx->opidx++;
--
2.38.1
next prev parent reply other threads:[~2022-11-02 21:34 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-02 21:33 [PATCH net-next v2 00/13] genetlink: support per op type policies Jakub Kicinski
2022-11-02 21:33 ` [PATCH net-next v2 01/13] genetlink: refactor the cmd <> policy mapping dump Jakub Kicinski
2022-11-02 23:52 ` Jacob Keller
2022-11-03 1:52 ` Jakub Kicinski
2022-11-03 3:06 ` Keller, Jacob E
2022-11-02 21:33 ` [PATCH net-next v2 02/13] genetlink: move the private fields in struct genl_family Jakub Kicinski
2022-11-02 21:33 ` [PATCH net-next v2 03/13] genetlink: introduce split op representation Jakub Kicinski
2022-11-02 21:33 ` [PATCH net-next v2 04/13] genetlink: load policy based on validation flags Jakub Kicinski
2022-11-02 21:33 ` [PATCH net-next v2 05/13] genetlink: check for callback type at op load time Jakub Kicinski
2022-11-02 21:33 ` [PATCH net-next v2 06/13] genetlink: add policies for both doit and dumpit in ctrl_dumppolicy_start() Jakub Kicinski
2022-11-03 17:38 ` Jacob Keller
2022-11-02 21:33 ` Jakub Kicinski [this message]
2022-11-02 21:33 ` [PATCH net-next v2 08/13] genetlink: inline genl_get_cmd() Jakub Kicinski
2022-11-03 17:04 ` Jacob Keller
2022-11-02 21:33 ` [PATCH net-next v2 09/13] genetlink: add iterator for walking family ops Jakub Kicinski
2022-11-02 21:33 ` [PATCH net-next v2 10/13] genetlink: use iterator in the op to policy map dumping Jakub Kicinski
2022-11-02 21:33 ` [PATCH net-next v2 11/13] genetlink: inline old iteration helpers Jakub Kicinski
2022-11-02 21:33 ` [PATCH net-next v2 12/13] genetlink: allow families to use split ops directly Jakub Kicinski
2022-11-04 22:10 ` Nicolas Dichtel
2022-11-04 22:19 ` Jakub Kicinski
2022-11-04 22:28 ` Nicolas Dichtel
2022-11-02 21:33 ` [PATCH net-next v2 13/13] genetlink: convert control family to split ops Jakub Kicinski
2022-11-03 17:09 ` [PATCH net-next v2 00/13] genetlink: support per op type policies Jacob Keller
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=20221102213338.194672-8-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=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).