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, kernel-team@fb.com,
	johannes@sipsolutions.net, jiri@resnulli.us, andrew@lunn.ch,
	mkubecek@suse.cz, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 6/6] ethtool: specify which header flags are supported per command
Date: Mon,  5 Oct 2020 08:57:53 -0700	[thread overview]
Message-ID: <20201005155753.2333882-7-kuba@kernel.org> (raw)
In-Reply-To: <20201005155753.2333882-1-kuba@kernel.org>

Perform header flags validation through the policy.

Only pause command supports ETHTOOL_FLAG_STATS. Create a separate
policy to be able to express that in policy dumps to user space.

Note that even though the core will validate the header policy,
it cannot record multiple layers of attributes and we have to
re-parse header sub-attrs. When doing so we could skip attribute
validation, or use most permissive policy.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 net/ethtool/netlink.c | 31 +++++++++++++++++++++----------
 net/ethtool/netlink.h |  1 +
 net/ethtool/pause.c   |  2 +-
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index e78ff7ce2a7d..b972789d6b8d 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -9,12 +9,26 @@ static struct genl_family ethtool_genl_family;
 static bool ethnl_ok __read_mostly;
 static u32 ethnl_bcast_seq;
 
+#define ETHTOOL_FLAGS_BASIC (ETHTOOL_FLAG_COMPACT_BITSETS |	\
+			     ETHTOOL_FLAG_OMIT_REPLY)
+#define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS)
+
 const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_MAX + 1] = {
 	[ETHTOOL_A_HEADER_UNSPEC]	= { .type = NLA_REJECT },
 	[ETHTOOL_A_HEADER_DEV_INDEX]	= { .type = NLA_U32 },
 	[ETHTOOL_A_HEADER_DEV_NAME]	= { .type = NLA_NUL_STRING,
 					    .len = ALTIFNAMSIZ - 1 },
-	[ETHTOOL_A_HEADER_FLAGS]	= { .type = NLA_U32 },
+	[ETHTOOL_A_HEADER_FLAGS]	= NLA_POLICY_MASK(NLA_U32,
+							  ETHTOOL_FLAGS_BASIC),
+};
+
+const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_MAX + 1] = {
+	[ETHTOOL_A_HEADER_UNSPEC]	= { .type = NLA_REJECT },
+	[ETHTOOL_A_HEADER_DEV_INDEX]	= { .type = NLA_U32 },
+	[ETHTOOL_A_HEADER_DEV_NAME]	= { .type = NLA_NUL_STRING,
+					    .len = ALTIFNAMSIZ - 1 },
+	[ETHTOOL_A_HEADER_FLAGS]	= NLA_POLICY_MASK(NLA_U32,
+							  ETHTOOL_FLAGS_STATS),
 };
 
 /**
@@ -47,19 +61,16 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
 		NL_SET_ERR_MSG(extack, "request header missing");
 		return -EINVAL;
 	}
+	/* Use most permissive header policy here, ops should specify their
+	 * actual header policy via NLA_POLICY_NESTED(), and the real
+	 * validation will happen in genetlink code.
+	 */
 	ret = nla_parse_nested(tb, ETHTOOL_A_HEADER_MAX, header,
-			       ethnl_header_policy, extack);
+			       ethnl_header_policy_stats, extack);
 	if (ret < 0)
 		return ret;
-	if (tb[ETHTOOL_A_HEADER_FLAGS]) {
+	if (tb[ETHTOOL_A_HEADER_FLAGS])
 		flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
-		if (flags & ~ETHTOOL_FLAG_ALL) {
-			NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_HEADER_FLAGS],
-					    "unrecognized request flags");
-			nl_set_extack_cookie_u32(extack, ETHTOOL_FLAG_ALL);
-			return -EOPNOTSUPP;
-		}
-	}
 
 	devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
 	if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) {
diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h
index 4fcd2e8b259b..f04d94e5fa77 100644
--- a/net/ethtool/netlink.h
+++ b/net/ethtool/netlink.h
@@ -348,6 +348,7 @@ extern const struct ethnl_request_ops ethnl_eee_request_ops;
 extern const struct ethnl_request_ops ethnl_tsinfo_request_ops;
 
 extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_MAX + 1];
+extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_MAX + 1];
 extern const struct nla_policy ethnl_strset_get_policy[ETHTOOL_A_STRSET_MAX + 1];
 extern const struct nla_policy ethnl_linkinfo_get_policy[ETHTOOL_A_LINKINFO_MAX + 1];
 extern const struct nla_policy ethnl_linkinfo_set_policy[ETHTOOL_A_LINKINFO_MAX + 1];
diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c
index a7fbe0e4dca6..a5c2abddc992 100644
--- a/net/ethtool/pause.c
+++ b/net/ethtool/pause.c
@@ -19,7 +19,7 @@ struct pause_reply_data {
 const struct nla_policy ethnl_pause_get_policy[ETHTOOL_A_PAUSE_MAX + 1] = {
 	[ETHTOOL_A_PAUSE_UNSPEC]		= { .type = NLA_REJECT },
 	[ETHTOOL_A_PAUSE_HEADER]		=
-		NLA_POLICY_NESTED(ethnl_header_policy),
+		NLA_POLICY_NESTED(ethnl_header_policy_stats),
 	[ETHTOOL_A_PAUSE_AUTONEG]		= { .type = NLA_REJECT },
 	[ETHTOOL_A_PAUSE_RX]			= { .type = NLA_REJECT },
 	[ETHTOOL_A_PAUSE_TX]			= { .type = NLA_REJECT },
-- 
2.26.2


  parent reply	other threads:[~2020-10-05 15:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05 15:57 [PATCH net-next 0/6] ethtool: allow dumping policies to user space Jakub Kicinski
2020-10-05 15:57 ` [PATCH net-next 1/6] ethtool: wire up get policies to ops Jakub Kicinski
2020-10-05 18:56   ` Johannes Berg
2020-10-05 19:16     ` Jakub Kicinski
2020-10-05 19:21       ` Johannes Berg
2020-10-05 19:31         ` Jakub Kicinski
2020-10-05 19:33           ` Johannes Berg
2020-10-05 19:41             ` Jakub Kicinski
2020-10-05 19:46               ` Johannes Berg
2020-10-05 19:51                 ` Jakub Kicinski
2020-10-05 21:52             ` Jacob Keller
2020-10-05 21:33           ` Jacob Keller
2020-10-05 15:57 ` [PATCH net-next 2/6] ethtool: use the attributes parsed by the core in get commands Jakub Kicinski
2020-10-05 15:57 ` [PATCH net-next 3/6] ethtool: wire up set policies to ops Jakub Kicinski
2020-10-05 15:57 ` [PATCH net-next 4/6] ethtool: link up ethnl_header_policy as a nested policy Jakub Kicinski
2020-10-05 15:57 ` [PATCH net-next 5/6] netlink: add mask validation Jakub Kicinski
2020-10-05 19:05   ` Johannes Berg
2020-10-05 19:22     ` Jakub Kicinski
2020-10-05 19:25       ` Johannes Berg
2020-10-05 19:34         ` Jakub Kicinski
2020-10-05 19:37           ` Johannes Berg
2020-10-05 19:47           ` Michal Kubecek
2020-10-05 19:28     ` Michal Kubecek
2020-10-05 19:31       ` Johannes Berg
2020-10-05 19:40         ` Jakub Kicinski
2020-10-05 19:53           ` Johannes Berg
2020-10-05 20:12             ` Johannes Berg
2020-10-05 22:21               ` Jakub Kicinski
2020-10-06  6:37                 ` Johannes Berg
2020-10-06 11:52                   ` Johannes Berg
2020-10-05 15:57 ` Jakub Kicinski [this message]
2020-10-05 18:58   ` [PATCH net-next 6/6] ethtool: specify which header flags are supported per command Johannes Berg
2020-10-05 19:25     ` Jakub Kicinski
2020-10-05 19:28       ` Johannes Berg

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=20201005155753.2333882-7-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=jiri@resnulli.us \
    --cc=johannes@sipsolutions.net \
    --cc=kernel-team@fb.com \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.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.