All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, andrew@lunn.ch,
	johannes@sipsolutions.net, jiri@resnulli.us, mkubecek@suse.cz,
	dsahern@kernel.org, pablo@netfilter.org,
	Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 10/10] genetlink: allow dumping command-specific policy
Date: Thu,  1 Oct 2020 15:59:33 -0700	[thread overview]
Message-ID: <20201001225933.1373426-11-kuba@kernel.org> (raw)
In-Reply-To: <20201001225933.1373426-1-kuba@kernel.org>

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

v2:
 - make cmd U32, just in case.
v1:
 - don't echo op in the output in a naive way, this should
   make it cleaner to extend the output format for dumping
   policies for all the commands at once in the future.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 include/uapi/linux/genetlink.h |  1 +
 net/netlink/genetlink.c        | 24 +++++++++++++++++++-----
 2 files changed, 20 insertions(+), 5 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 fc5d25bd5698..dd4b7a2979ac 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -123,7 +123,7 @@ static void genl_op_from_full(const struct genl_family *family,
 		op->policy = family->policy;
 }
 
-static int genl_get_cmd_full(u8 cmd, const struct genl_family *family,
+static int genl_get_cmd_full(u32 cmd, const struct genl_family *family,
 			     struct genl_ops *op)
 {
 	int i;
@@ -152,7 +152,7 @@ static void genl_op_from_small(const struct genl_family *family,
 	op->policy = family->policy;
 }
 
-static int genl_get_cmd_small(u8 cmd, const struct genl_family *family,
+static int genl_get_cmd_small(u32 cmd, const struct genl_family *family,
 			      struct genl_ops *op)
 {
 	int i;
@@ -166,7 +166,7 @@ static int genl_get_cmd_small(u8 cmd, const struct genl_family *family,
 	return -ENOENT;
 }
 
-static int genl_get_cmd(u8 cmd, const struct genl_family *family,
+static int genl_get_cmd(u32 cmd, const struct genl_family *family,
 			struct genl_ops *op)
 {
 	if (!genl_get_cmd_full(cmd, family, op))
@@ -1119,6 +1119,7 @@ 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_U32 },
 };
 
 static int ctrl_dumppolicy_start(struct netlink_callback *cb)
@@ -1127,6 +1128,8 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
 	struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
 	struct nlattr **tb = info->attrs;
 	const struct genl_family *rt;
+	struct genl_ops op;
+	int err;
 
 	BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
 
@@ -1147,10 +1150,21 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
 	if (!rt)
 		return -ENOENT;
 
-	if (!rt->policy)
+	if (tb[CTRL_ATTR_OP]) {
+		err = genl_get_cmd(nla_get_u32(tb[CTRL_ATTR_OP]), 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)
-- 
2.26.2


  parent reply	other threads:[~2020-10-01 23:00 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01 22:59 [PATCH net-next v2 00/10] genetlink: support per-command policy dump Jakub Kicinski
2020-10-01 22:59 ` [PATCH net-next v2 01/10] genetlink: reorg struct genl_family Jakub Kicinski
2020-10-01 22:59 ` [PATCH net-next v2 02/10] genetlink: add small version of ops Jakub Kicinski
2020-10-01 22:59 ` [PATCH net-next v2 03/10] genetlink: move to smaller ops wherever possible Jakub Kicinski
2020-10-01 22:59 ` [PATCH net-next v2 04/10] genetlink: add a structure for dump state Jakub Kicinski
2020-10-01 22:59 ` [PATCH net-next v2 05/10] genetlink: use .start callback for dumppolicy Jakub Kicinski
2020-10-01 22:59 ` [PATCH net-next v2 06/10] genetlink: bring back per op policy Jakub Kicinski
2020-10-01 22:59 ` [PATCH net-next v2 07/10] taskstats: move specifying netlink policy back to ops Jakub Kicinski
2020-10-01 22:59 ` [PATCH net-next v2 08/10] genetlink: use parsed attrs in dumppolicy Jakub Kicinski
2020-10-02  6:30   ` Johannes Berg
2020-10-01 22:59 ` [PATCH net-next v2 09/10] genetlink: switch control commands to per-op policies Jakub Kicinski
2020-10-02  6:33   ` Johannes Berg
2020-10-01 22:59 ` Jakub Kicinski [this message]
2020-10-02  6:34   ` [PATCH net-next v2 10/10] genetlink: allow dumping command-specific policy Johannes Berg
2020-10-02  0:36 ` [PATCH net-next v2 00/10] genetlink: support per-command policy dump Jakub Kicinski
2020-10-02  6:29   ` Johannes Berg
2020-10-02 14:40     ` Jakub Kicinski
2020-10-02 14:42       ` Johannes Berg
2020-10-02 14:55         ` Jakub Kicinski
2020-10-02 14:58           ` Johannes Berg
2020-10-02 15:03             ` Jakub Kicinski
2020-10-02 15:04               ` Johannes Berg
2020-10-02 15:09                 ` Jakub Kicinski
2020-10-02 15:13                   ` Johannes Berg
2020-10-02 15:25                     ` Jakub Kicinski
2020-10-02 15:28                       ` Johannes Berg
2020-10-02 16:55                       ` Michal Kubecek
2020-10-02 20:07                       ` David Miller
2020-10-02 20:27                   ` Johannes Berg
2020-10-02 20:50                     ` Jakub Kicinski
2020-10-02 20:59                       ` Johannes Berg
2020-10-02 21:00                         ` Johannes Berg
2020-10-02 21:17                           ` Jakub Kicinski
2020-10-02 21:22                             ` Jakub Kicinski
2020-10-02 21:52                               ` 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=20201001225933.1373426-11-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.