netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 9/9] genetlink: allow dumping command-specific policy
Date: Wed, 30 Sep 2020 17:05:18 -0700	[thread overview]
Message-ID: <20201001000518.685243-10-kuba@kernel.org> (raw)
In-Reply-To: <20201001000518.685243-1-kuba@kernel.org>

Right now CTRL_CMD_GETPOLICY can only dump the family-wide
policy. Support dumping policy of a specific op.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 include/uapi/linux/genetlink.h |  1 +
 net/netlink/genetlink.c        | 23 +++++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/genetlink.h b/include/uapi/linux/genetlink.h
index 9c0636ec2286..7dbe2d5d7d46 100644
--- a/include/uapi/linux/genetlink.h
+++ b/include/uapi/linux/genetlink.h
@@ -64,6 +64,7 @@ enum {
 	CTRL_ATTR_OPS,
 	CTRL_ATTR_MCAST_GROUPS,
 	CTRL_ATTR_POLICY,
+	CTRL_ATTR_OP,
 	__CTRL_ATTR_MAX,
 };
 
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index f2833e9165c7..12e9f323af35 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1113,12 +1113,14 @@ static int genl_ctrl_event(int event, const struct genl_family *family,
 struct ctrl_dump_policy_ctx {
 	unsigned long state;
 	unsigned int fam_id;
+	u8 cmd;
 };
 
 static const struct nla_policy ctrl_policy_policy[] = {
 	[CTRL_ATTR_FAMILY_ID]	= { .type = NLA_U16 },
 	[CTRL_ATTR_FAMILY_NAME]	= { .type = NLA_NUL_STRING,
 				    .len = GENL_NAMSIZ - 1 },
+	[CTRL_ATTR_OP]		= { .type = NLA_U8 },
 };
 
 static int ctrl_dumppolicy_start(struct netlink_callback *cb)
@@ -1127,6 +1129,8 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
 	struct ctrl_dump_policy_ctx *ctx = (void *)cb->args;
 	struct nlattr **tb = info->attrs;
 	const struct genl_family *rt;
+	struct genl_ops op;
+	int err;
 
 	if (!tb[CTRL_ATTR_FAMILY_ID] && !tb[CTRL_ATTR_FAMILY_NAME])
 		return -EINVAL;
@@ -1145,10 +1149,23 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
 	if (!rt)
 		return -ENOENT;
 
-	if (!rt->policy)
+	if (tb[CTRL_ATTR_OP]) {
+		ctx->cmd = nla_get_u8(tb[CTRL_ATTR_OP]);
+
+		err = genl_get_cmd(ctx->cmd, rt, &op);
+		if (err) {
+			NL_SET_BAD_ATTR(cb->extack, tb[CTRL_ATTR_OP]);
+			return err;
+		}
+	} else {
+		op.policy = rt->policy;
+		op.maxattr = rt->maxattr;
+	}
+
+	if (!op.policy)
 		return -ENODATA;
 
-	return netlink_policy_dump_start(rt->policy, rt->maxattr, &ctx->state);
+	return netlink_policy_dump_start(op.policy, op.maxattr, &ctx->state);
 }
 
 static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
@@ -1167,6 +1184,8 @@ static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
 
 		if (nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, ctx->fam_id))
 			goto nla_put_failure;
+		if (ctx->cmd && nla_put_u8(skb, CTRL_ATTR_OP, ctx->cmd))
+			goto nla_put_failure;
 
 		nest = nla_nest_start(skb, CTRL_ATTR_POLICY);
 		if (!nest)
-- 
2.26.2


  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 ` [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 ` Jakub Kicinski [this message]
2020-10-01  7:59   ` [RFC net-next 9/9] genetlink: allow dumping command-specific policy 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-10-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).