From patchwork Mon Oct 5 15:57:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 288983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84B1CC4363A for ; Mon, 5 Oct 2020 15:58:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B324206DD for ; Mon, 5 Oct 2020 15:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913494; bh=Q0A8twdlh95KkcTbSxtli0EUmfvK8GPMx/2wdnbRyqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=BGSk0oosOCgyHt4EOq29bNeq3ezbOA/HsgDohbs1WrYDfZdu2auY0X79O7bCXX6CN 7DoqgAFi0VaNPnb1ufgH64SXcX9wn8ciWPOaCFrXoZqu/2kpzqBg7qgXEjozG2dMOn WXXyqf/fmMSrpuylkYPD+WiDkfw/JGdZOT8YhjSc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728910AbgJEP6N (ORCPT ); Mon, 5 Oct 2020 11:58:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:56764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726057AbgJEP6H (ORCPT ); Mon, 5 Oct 2020 11:58:07 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E3B99206DD; Mon, 5 Oct 2020 15:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913486; bh=Q0A8twdlh95KkcTbSxtli0EUmfvK8GPMx/2wdnbRyqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t8zbMmrqDM4D3RHBgmiJuWn4Z/ZhANwQHDfuN4zJ8Pa+8GY6a1rm4kewznoV4x/Lm rC5TC56f/u8q4Z7TcWhue4nY3HnGX5SXLQUluWm5XOvoalGOzSLfPG1euWg/W+H+iS qMpH3gh2gZaOFl8W+pzAHhNuu6Q/Ww3MCkrITG4k= From: Jakub Kicinski 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 Subject: [PATCH net-next 1/6] ethtool: wire up get policies to ops Date: Mon, 5 Oct 2020 08:57:48 -0700 Message-Id: <20201005155753.2333882-2-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201005155753.2333882-1-kuba@kernel.org> References: <20201005155753.2333882-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To make use of genetlink code validating and parsing attributes for us, as well as dumping policies to user space wrie up policies for get commands in struct nla_policy of the ethtool family. For ease of review this commit just does the repetitive wiring up. Next changes will use the core-parsed attrs and migrate set commands. For every ETHTOOL_MSG_*_GET: - add 'ethnl_' prefix to policy name - add extern declaration in net/ethtool/netlink.h - wire up the policy in ethtool_genl_ops[]. Signed-off-by: Jakub Kicinski --- net/ethtool/channels.c | 6 +++--- net/ethtool/coalesce.c | 6 +++--- net/ethtool/debug.c | 5 ++--- net/ethtool/eee.c | 5 ++--- net/ethtool/features.c | 6 +++--- net/ethtool/linkinfo.c | 6 +++--- net/ethtool/linkmodes.c | 6 +++--- net/ethtool/linkstate.c | 6 +++--- net/ethtool/netlink.c | 32 ++++++++++++++++++++++++++++++++ net/ethtool/netlink.h | 16 ++++++++++++++++ net/ethtool/pause.c | 5 ++--- net/ethtool/privflags.c | 6 +++--- net/ethtool/rings.c | 5 ++--- net/ethtool/strset.c | 4 ++-- net/ethtool/tsinfo.c | 5 ++--- net/ethtool/tunnels.c | 6 +++--- net/ethtool/wol.c | 5 ++--- 17 files changed, 86 insertions(+), 44 deletions(-) diff --git a/net/ethtool/channels.c b/net/ethtool/channels.c index 9ecda09ecb11..d3ef94c5ee59 100644 --- a/net/ethtool/channels.c +++ b/net/ethtool/channels.c @@ -17,8 +17,8 @@ struct channels_reply_data { #define CHANNELS_REPDATA(__reply_base) \ container_of(__reply_base, struct channels_reply_data, base) -static const struct nla_policy -channels_get_policy[ETHTOOL_A_CHANNELS_MAX + 1] = { +const struct nla_policy +ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_MAX + 1] = { [ETHTOOL_A_CHANNELS_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_CHANNELS_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_CHANNELS_RX_MAX] = { .type = NLA_REJECT }, @@ -102,7 +102,7 @@ const struct ethnl_request_ops ethnl_channels_request_ops = { .max_attr = ETHTOOL_A_CHANNELS_MAX, .req_info_size = sizeof(struct channels_req_info), .reply_data_size = sizeof(struct channels_reply_data), - .request_policy = channels_get_policy, + .request_policy = ethnl_channels_get_policy, .prepare_data = channels_prepare_data, .reply_size = channels_reply_size, diff --git a/net/ethtool/coalesce.c b/net/ethtool/coalesce.c index 6afd99042d67..e0d8a269a46d 100644 --- a/net/ethtool/coalesce.c +++ b/net/ethtool/coalesce.c @@ -51,8 +51,8 @@ __CHECK_SUPPORTED_OFFSET(COALESCE_TX_USECS_HIGH); __CHECK_SUPPORTED_OFFSET(COALESCE_TX_MAX_FRAMES_HIGH); __CHECK_SUPPORTED_OFFSET(COALESCE_RATE_SAMPLE_INTERVAL); -static const struct nla_policy -coalesce_get_policy[ETHTOOL_A_COALESCE_MAX + 1] = { +const struct nla_policy +ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_MAX + 1] = { [ETHTOOL_A_COALESCE_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_COALESCE_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_COALESCE_RX_USECS] = { .type = NLA_REJECT }, @@ -206,7 +206,7 @@ const struct ethnl_request_ops ethnl_coalesce_request_ops = { .max_attr = ETHTOOL_A_COALESCE_MAX, .req_info_size = sizeof(struct coalesce_req_info), .reply_data_size = sizeof(struct coalesce_reply_data), - .request_policy = coalesce_get_policy, + .request_policy = ethnl_coalesce_get_policy, .prepare_data = coalesce_prepare_data, .reply_size = coalesce_reply_size, diff --git a/net/ethtool/debug.c b/net/ethtool/debug.c index 1bd026a29f3f..a007730320a4 100644 --- a/net/ethtool/debug.c +++ b/net/ethtool/debug.c @@ -16,8 +16,7 @@ struct debug_reply_data { #define DEBUG_REPDATA(__reply_base) \ container_of(__reply_base, struct debug_reply_data, base) -static const struct nla_policy -debug_get_policy[ETHTOOL_A_DEBUG_MAX + 1] = { +const struct nla_policy ethnl_debug_get_policy[ETHTOOL_A_DEBUG_MAX + 1] = { [ETHTOOL_A_DEBUG_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_DEBUG_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_DEBUG_MSGMASK] = { .type = NLA_REJECT }, @@ -72,7 +71,7 @@ const struct ethnl_request_ops ethnl_debug_request_ops = { .max_attr = ETHTOOL_A_DEBUG_MAX, .req_info_size = sizeof(struct debug_req_info), .reply_data_size = sizeof(struct debug_reply_data), - .request_policy = debug_get_policy, + .request_policy = ethnl_debug_get_policy, .prepare_data = debug_prepare_data, .reply_size = debug_reply_size, diff --git a/net/ethtool/eee.c b/net/ethtool/eee.c index 94aa19cff22f..ea9d071b5360 100644 --- a/net/ethtool/eee.c +++ b/net/ethtool/eee.c @@ -19,8 +19,7 @@ struct eee_reply_data { #define EEE_REPDATA(__reply_base) \ container_of(__reply_base, struct eee_reply_data, base) -static const struct nla_policy -eee_get_policy[ETHTOOL_A_EEE_MAX + 1] = { +const struct nla_policy ethnl_eee_get_policy[ETHTOOL_A_EEE_MAX + 1] = { [ETHTOOL_A_EEE_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_EEE_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_EEE_MODES_OURS] = { .type = NLA_REJECT }, @@ -122,7 +121,7 @@ const struct ethnl_request_ops ethnl_eee_request_ops = { .max_attr = ETHTOOL_A_EEE_MAX, .req_info_size = sizeof(struct eee_req_info), .reply_data_size = sizeof(struct eee_reply_data), - .request_policy = eee_get_policy, + .request_policy = ethnl_eee_get_policy, .prepare_data = eee_prepare_data, .reply_size = eee_reply_size, diff --git a/net/ethtool/features.c b/net/ethtool/features.c index 495635f152ba..c2979b3890f9 100644 --- a/net/ethtool/features.c +++ b/net/ethtool/features.c @@ -20,8 +20,8 @@ struct features_reply_data { #define FEATURES_REPDATA(__reply_base) \ container_of(__reply_base, struct features_reply_data, base) -static const struct nla_policy -features_get_policy[ETHTOOL_A_FEATURES_MAX + 1] = { +const struct nla_policy +ethnl_features_get_policy[ETHTOOL_A_FEATURES_MAX + 1] = { [ETHTOOL_A_FEATURES_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_FEATURES_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_FEATURES_HW] = { .type = NLA_REJECT }, @@ -123,7 +123,7 @@ const struct ethnl_request_ops ethnl_features_request_ops = { .max_attr = ETHTOOL_A_FEATURES_MAX, .req_info_size = sizeof(struct features_req_info), .reply_data_size = sizeof(struct features_reply_data), - .request_policy = features_get_policy, + .request_policy = ethnl_features_get_policy, .prepare_data = features_prepare_data, .reply_size = features_reply_size, diff --git a/net/ethtool/linkinfo.c b/net/ethtool/linkinfo.c index 5eaf173eaaca..676aa5a00ac0 100644 --- a/net/ethtool/linkinfo.c +++ b/net/ethtool/linkinfo.c @@ -16,8 +16,8 @@ struct linkinfo_reply_data { #define LINKINFO_REPDATA(__reply_base) \ container_of(__reply_base, struct linkinfo_reply_data, base) -static const struct nla_policy -linkinfo_get_policy[ETHTOOL_A_LINKINFO_MAX + 1] = { +const struct nla_policy +ethnl_linkinfo_get_policy[ETHTOOL_A_LINKINFO_MAX + 1] = { [ETHTOOL_A_LINKINFO_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKINFO_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_LINKINFO_PORT] = { .type = NLA_REJECT }, @@ -86,7 +86,7 @@ const struct ethnl_request_ops ethnl_linkinfo_request_ops = { .max_attr = ETHTOOL_A_LINKINFO_MAX, .req_info_size = sizeof(struct linkinfo_req_info), .reply_data_size = sizeof(struct linkinfo_reply_data), - .request_policy = linkinfo_get_policy, + .request_policy = ethnl_linkinfo_get_policy, .prepare_data = linkinfo_prepare_data, .reply_size = linkinfo_reply_size, diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c index 29dcd675b65a..f32ab3239d15 100644 --- a/net/ethtool/linkmodes.c +++ b/net/ethtool/linkmodes.c @@ -18,8 +18,8 @@ struct linkmodes_reply_data { #define LINKMODES_REPDATA(__reply_base) \ container_of(__reply_base, struct linkmodes_reply_data, base) -static const struct nla_policy -linkmodes_get_policy[ETHTOOL_A_LINKMODES_MAX + 1] = { +const struct nla_policy +ethnl_linkmodes_get_policy[ETHTOOL_A_LINKMODES_MAX + 1] = { [ETHTOOL_A_LINKMODES_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKMODES_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_LINKMODES_AUTONEG] = { .type = NLA_REJECT }, @@ -151,7 +151,7 @@ const struct ethnl_request_ops ethnl_linkmodes_request_ops = { .max_attr = ETHTOOL_A_LINKMODES_MAX, .req_info_size = sizeof(struct linkmodes_req_info), .reply_data_size = sizeof(struct linkmodes_reply_data), - .request_policy = linkmodes_get_policy, + .request_policy = ethnl_linkmodes_get_policy, .prepare_data = linkmodes_prepare_data, .reply_size = linkmodes_reply_size, diff --git a/net/ethtool/linkstate.c b/net/ethtool/linkstate.c index 4834091ec24c..c86ae67e2486 100644 --- a/net/ethtool/linkstate.c +++ b/net/ethtool/linkstate.c @@ -20,8 +20,8 @@ struct linkstate_reply_data { #define LINKSTATE_REPDATA(__reply_base) \ container_of(__reply_base, struct linkstate_reply_data, base) -static const struct nla_policy -linkstate_get_policy[ETHTOOL_A_LINKSTATE_MAX + 1] = { +const struct nla_policy +ethnl_linkstate_get_policy[ETHTOOL_A_LINKSTATE_MAX + 1] = { [ETHTOOL_A_LINKSTATE_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKSTATE_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_LINKSTATE_LINK] = { .type = NLA_REJECT }, @@ -182,7 +182,7 @@ const struct ethnl_request_ops ethnl_linkstate_request_ops = { .max_attr = ETHTOOL_A_LINKSTATE_MAX, .req_info_size = sizeof(struct linkstate_req_info), .reply_data_size = sizeof(struct linkstate_reply_data), - .request_policy = linkstate_get_policy, + .request_policy = ethnl_linkstate_get_policy, .prepare_data = linkstate_prepare_data, .reply_size = linkstate_reply_size, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 5c2072765be7..dbabac38c191 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -696,6 +696,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_strset_get_policy, + .maxattr = ARRAY_SIZE(ethnl_strset_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_LINKINFO_GET, @@ -703,6 +705,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_linkinfo_get_policy, + .maxattr = ARRAY_SIZE(ethnl_linkinfo_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_LINKINFO_SET, @@ -715,6 +719,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_linkmodes_get_policy, + .maxattr = ARRAY_SIZE(ethnl_linkmodes_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_LINKMODES_SET, @@ -727,6 +733,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_linkstate_get_policy, + .maxattr = ARRAY_SIZE(ethnl_linkstate_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_DEBUG_GET, @@ -734,6 +742,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_debug_get_policy, + .maxattr = ARRAY_SIZE(ethnl_debug_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_DEBUG_SET, @@ -747,6 +757,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_wol_get_policy, + .maxattr = ARRAY_SIZE(ethnl_wol_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_WOL_SET, @@ -759,6 +771,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_features_get_policy, + .maxattr = ARRAY_SIZE(ethnl_features_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_FEATURES_SET, @@ -771,6 +785,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_privflags_get_policy, + .maxattr = ARRAY_SIZE(ethnl_privflags_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_PRIVFLAGS_SET, @@ -783,6 +799,9 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_rings_get_policy, + .maxattr = ARRAY_SIZE(ethnl_rings_get_policy) - 1, + }, { .cmd = ETHTOOL_MSG_RINGS_SET, @@ -795,6 +814,9 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_channels_get_policy, + .maxattr = ARRAY_SIZE(ethnl_channels_get_policy) - 1, + }, { .cmd = ETHTOOL_MSG_CHANNELS_SET, @@ -807,6 +829,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_coalesce_get_policy, + .maxattr = ARRAY_SIZE(ethnl_coalesce_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_COALESCE_SET, @@ -819,6 +843,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_pause_get_policy, + .maxattr = ARRAY_SIZE(ethnl_pause_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_PAUSE_SET, @@ -831,6 +857,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_eee_get_policy, + .maxattr = ARRAY_SIZE(ethnl_eee_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_EEE_SET, @@ -843,6 +871,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .start = ethnl_default_start, .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, + .policy = ethnl_tsinfo_get_policy, + .maxattr = ARRAY_SIZE(ethnl_tsinfo_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_CABLE_TEST_ACT, @@ -859,6 +889,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .doit = ethnl_tunnel_info_doit, .start = ethnl_tunnel_info_start, .dumpit = ethnl_tunnel_info_dumpit, + .policy = ethnl_tunnel_info_get_policy, + .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1, }, }; diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index e2085005caac..0100fab5829e 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -349,6 +349,22 @@ extern const struct ethnl_request_ops ethnl_pause_request_ops; 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_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_linkmodes_get_policy[ETHTOOL_A_LINKMODES_MAX + 1]; +extern const struct nla_policy ethnl_linkstate_get_policy[ETHTOOL_A_LINKSTATE_MAX + 1]; +extern const struct nla_policy ethnl_debug_get_policy[ETHTOOL_A_DEBUG_MAX + 1]; +extern const struct nla_policy ethnl_wol_get_policy[ETHTOOL_A_WOL_MAX + 1]; +extern const struct nla_policy ethnl_features_get_policy[ETHTOOL_A_FEATURES_MAX + 1]; +extern const struct nla_policy ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1]; +extern const struct nla_policy ethnl_rings_get_policy[ETHTOOL_A_RINGS_MAX + 1]; +extern const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_MAX + 1]; +extern const struct nla_policy ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_MAX + 1]; +extern const struct nla_policy ethnl_pause_get_policy[ETHTOOL_A_PAUSE_MAX + 1]; +extern const struct nla_policy ethnl_eee_get_policy[ETHTOOL_A_EEE_MAX + 1]; +extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX + 1]; +extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_MAX + 1]; + int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info); int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info); int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info); diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c index 1980aa7eb2b6..40f36f8d6291 100644 --- a/net/ethtool/pause.c +++ b/net/ethtool/pause.c @@ -16,8 +16,7 @@ struct pause_reply_data { #define PAUSE_REPDATA(__reply_base) \ container_of(__reply_base, struct pause_reply_data, base) -static const struct nla_policy -pause_get_policy[ETHTOOL_A_PAUSE_MAX + 1] = { +const struct nla_policy ethnl_pause_get_policy[ETHTOOL_A_PAUSE_MAX + 1] = { [ETHTOOL_A_PAUSE_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_PAUSE_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_PAUSE_AUTONEG] = { .type = NLA_REJECT }, @@ -133,7 +132,7 @@ const struct ethnl_request_ops ethnl_pause_request_ops = { .max_attr = ETHTOOL_A_PAUSE_MAX, .req_info_size = sizeof(struct pause_req_info), .reply_data_size = sizeof(struct pause_reply_data), - .request_policy = pause_get_policy, + .request_policy = ethnl_pause_get_policy, .prepare_data = pause_prepare_data, .reply_size = pause_reply_size, diff --git a/net/ethtool/privflags.c b/net/ethtool/privflags.c index 77447dceb109..7ebab33f2244 100644 --- a/net/ethtool/privflags.c +++ b/net/ethtool/privflags.c @@ -18,8 +18,8 @@ struct privflags_reply_data { #define PRIVFLAGS_REPDATA(__reply_base) \ container_of(__reply_base, struct privflags_reply_data, base) -static const struct nla_policy -privflags_get_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1] = { +const struct nla_policy +ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1] = { [ETHTOOL_A_PRIVFLAGS_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_PRIVFLAGS_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_PRIVFLAGS_FLAGS] = { .type = NLA_REJECT }, @@ -127,7 +127,7 @@ const struct ethnl_request_ops ethnl_privflags_request_ops = { .max_attr = ETHTOOL_A_PRIVFLAGS_MAX, .req_info_size = sizeof(struct privflags_req_info), .reply_data_size = sizeof(struct privflags_reply_data), - .request_policy = privflags_get_policy, + .request_policy = ethnl_privflags_get_policy, .prepare_data = privflags_prepare_data, .reply_size = privflags_reply_size, diff --git a/net/ethtool/rings.c b/net/ethtool/rings.c index 5422526f4eef..eb52639b6ed3 100644 --- a/net/ethtool/rings.c +++ b/net/ethtool/rings.c @@ -15,8 +15,7 @@ struct rings_reply_data { #define RINGS_REPDATA(__reply_base) \ container_of(__reply_base, struct rings_reply_data, base) -static const struct nla_policy -rings_get_policy[ETHTOOL_A_RINGS_MAX + 1] = { +const struct nla_policy ethnl_rings_get_policy[ETHTOOL_A_RINGS_MAX + 1] = { [ETHTOOL_A_RINGS_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_RINGS_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_RINGS_RX_MAX] = { .type = NLA_REJECT }, @@ -100,7 +99,7 @@ const struct ethnl_request_ops ethnl_rings_request_ops = { .max_attr = ETHTOOL_A_RINGS_MAX, .req_info_size = sizeof(struct rings_req_info), .reply_data_size = sizeof(struct rings_reply_data), - .request_policy = rings_get_policy, + .request_policy = ethnl_rings_get_policy, .prepare_data = rings_prepare_data, .reply_size = rings_reply_size, diff --git a/net/ethtool/strset.c b/net/ethtool/strset.c index 82707b662fe4..8d30fe0fbe3b 100644 --- a/net/ethtool/strset.c +++ b/net/ethtool/strset.c @@ -99,7 +99,7 @@ struct strset_reply_data { #define STRSET_REPDATA(__reply_base) \ container_of(__reply_base, struct strset_reply_data, base) -static const struct nla_policy strset_get_policy[ETHTOOL_A_STRSET_MAX + 1] = { +const struct nla_policy ethnl_strset_get_policy[ETHTOOL_A_STRSET_MAX + 1] = { [ETHTOOL_A_STRSET_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_STRSET_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_STRSET_STRINGSETS] = { .type = NLA_NESTED }, @@ -448,7 +448,7 @@ const struct ethnl_request_ops ethnl_strset_request_ops = { .max_attr = ETHTOOL_A_STRSET_MAX, .req_info_size = sizeof(struct strset_req_info), .reply_data_size = sizeof(struct strset_reply_data), - .request_policy = strset_get_policy, + .request_policy = ethnl_strset_get_policy, .allow_nodev_do = true, .parse_request = strset_parse_request, diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c index 7cb5b512b77c..05d501563dc9 100644 --- a/net/ethtool/tsinfo.c +++ b/net/ethtool/tsinfo.c @@ -18,8 +18,7 @@ struct tsinfo_reply_data { #define TSINFO_REPDATA(__reply_base) \ container_of(__reply_base, struct tsinfo_reply_data, base) -static const struct nla_policy -tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX + 1] = { +const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX + 1] = { [ETHTOOL_A_TSINFO_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_TSINFO_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_TSINFO_TIMESTAMPING] = { .type = NLA_REJECT }, @@ -135,7 +134,7 @@ const struct ethnl_request_ops ethnl_tsinfo_request_ops = { .max_attr = ETHTOOL_A_TSINFO_MAX, .req_info_size = sizeof(struct tsinfo_req_info), .reply_data_size = sizeof(struct tsinfo_reply_data), - .request_policy = tsinfo_get_policy, + .request_policy = ethnl_tsinfo_get_policy, .prepare_data = tsinfo_prepare_data, .reply_size = tsinfo_reply_size, diff --git a/net/ethtool/tunnels.c b/net/ethtool/tunnels.c index d93bf2da0f34..d7d4964ea773 100644 --- a/net/ethtool/tunnels.c +++ b/net/ethtool/tunnels.c @@ -8,8 +8,8 @@ #include "common.h" #include "netlink.h" -static const struct nla_policy -ethtool_tunnel_info_policy[ETHTOOL_A_TUNNEL_INFO_MAX + 1] = { +const struct nla_policy +ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_MAX + 1] = { [ETHTOOL_A_TUNNEL_INFO_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_TUNNEL_INFO_HEADER] = { .type = NLA_NESTED }, }; @@ -170,7 +170,7 @@ ethnl_tunnel_info_req_parse(struct ethnl_req_info *req_info, int ret; ret = nlmsg_parse(nlhdr, GENL_HDRLEN, tb, ETHTOOL_A_TUNNEL_INFO_MAX, - ethtool_tunnel_info_policy, extack); + ethnl_tunnel_info_get_policy, extack); if (ret < 0) return ret; diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c index 1798421e9f1c..d234885fc265 100644 --- a/net/ethtool/wol.c +++ b/net/ethtool/wol.c @@ -17,8 +17,7 @@ struct wol_reply_data { #define WOL_REPDATA(__reply_base) \ container_of(__reply_base, struct wol_reply_data, base) -static const struct nla_policy -wol_get_policy[ETHTOOL_A_WOL_MAX + 1] = { +const struct nla_policy ethnl_wol_get_policy[ETHTOOL_A_WOL_MAX + 1] = { [ETHTOOL_A_WOL_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_WOL_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_WOL_MODES] = { .type = NLA_REJECT }, @@ -92,7 +91,7 @@ const struct ethnl_request_ops ethnl_wol_request_ops = { .max_attr = ETHTOOL_A_WOL_MAX, .req_info_size = sizeof(struct wol_req_info), .reply_data_size = sizeof(struct wol_reply_data), - .request_policy = wol_get_policy, + .request_policy = ethnl_wol_get_policy, .prepare_data = wol_prepare_data, .reply_size = wol_reply_size, From patchwork Mon Oct 5 15:57:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 268089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D3E4C4727D for ; Mon, 5 Oct 2020 15:58:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46882206DD for ; Mon, 5 Oct 2020 15:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913495; bh=M+OghuJdWV4ZfHwjzN+7JspN4oTehj/7fp2r7zd//9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Z4MA+fKDYA7vojdbhEIhwTljnXG1ktsCDG6MU+ZFH9br8wo2cBi1atC3T4LU4EqNO TD1WizF6bEnwq+SNfj0sQpwe+kv/32Ys6C62yiSajYXRjAlb1MGwPiKrgq/eXO/mxm SxGH2jeXvnjIpC/U8Ue4LbAewq9936nafDOkG+KY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728906AbgJEP6M (ORCPT ); Mon, 5 Oct 2020 11:58:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:56796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728855AbgJEP6I (ORCPT ); Mon, 5 Oct 2020 11:58:08 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6AE41207BC; Mon, 5 Oct 2020 15:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913486; bh=M+OghuJdWV4ZfHwjzN+7JspN4oTehj/7fp2r7zd//9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EvpkwgAiU68D6j8Y+xsF3vELpkuUUcRvEwTJ8SC+oqABI5NfvEY118rWGSg31zTlQ aduC5jDR37ugrfPLdhjSZldzbeihaqk0zKFDKyZWevWSZP6abxv5EzdoZ9lU9rfxQe FC89+uc94Pk8s52BYcWS463mX20Zdn/m4TFFS4BU= From: Jakub Kicinski 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 Subject: [PATCH net-next 2/6] ethtool: use the attributes parsed by the core in get commands Date: Mon, 5 Oct 2020 08:57:49 -0700 Message-Id: <20201005155753.2333882-3-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201005155753.2333882-1-kuba@kernel.org> References: <20201005155753.2333882-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now that policies are placed in op structs core will do the attribute parsing for us. Obviously core only record the first "layer" of parsed attrs so we still need to parse the sub-attrs of the nested header attribute. Signed-off-by: Jakub Kicinski --- net/ethtool/channels.c | 1 - net/ethtool/coalesce.c | 1 - net/ethtool/debug.c | 1 - net/ethtool/eee.c | 1 - net/ethtool/features.c | 1 - net/ethtool/linkinfo.c | 1 - net/ethtool/linkmodes.c | 1 - net/ethtool/linkstate.c | 1 - net/ethtool/netlink.c | 32 ++++++++++---------------------- net/ethtool/netlink.h | 2 -- net/ethtool/pause.c | 1 - net/ethtool/privflags.c | 1 - net/ethtool/rings.c | 1 - net/ethtool/strset.c | 1 - net/ethtool/tsinfo.c | 1 - net/ethtool/tunnels.c | 35 +++++++++++------------------------ net/ethtool/wol.c | 1 - 17 files changed, 21 insertions(+), 62 deletions(-) diff --git a/net/ethtool/channels.c b/net/ethtool/channels.c index d3ef94c5ee59..76994c8f32a0 100644 --- a/net/ethtool/channels.c +++ b/net/ethtool/channels.c @@ -102,7 +102,6 @@ const struct ethnl_request_ops ethnl_channels_request_ops = { .max_attr = ETHTOOL_A_CHANNELS_MAX, .req_info_size = sizeof(struct channels_req_info), .reply_data_size = sizeof(struct channels_reply_data), - .request_policy = ethnl_channels_get_policy, .prepare_data = channels_prepare_data, .reply_size = channels_reply_size, diff --git a/net/ethtool/coalesce.c b/net/ethtool/coalesce.c index e0d8a269a46d..77d83062faa2 100644 --- a/net/ethtool/coalesce.c +++ b/net/ethtool/coalesce.c @@ -206,7 +206,6 @@ const struct ethnl_request_ops ethnl_coalesce_request_ops = { .max_attr = ETHTOOL_A_COALESCE_MAX, .req_info_size = sizeof(struct coalesce_req_info), .reply_data_size = sizeof(struct coalesce_reply_data), - .request_policy = ethnl_coalesce_get_policy, .prepare_data = coalesce_prepare_data, .reply_size = coalesce_reply_size, diff --git a/net/ethtool/debug.c b/net/ethtool/debug.c index a007730320a4..f553ef6a99e4 100644 --- a/net/ethtool/debug.c +++ b/net/ethtool/debug.c @@ -71,7 +71,6 @@ const struct ethnl_request_ops ethnl_debug_request_ops = { .max_attr = ETHTOOL_A_DEBUG_MAX, .req_info_size = sizeof(struct debug_req_info), .reply_data_size = sizeof(struct debug_reply_data), - .request_policy = ethnl_debug_get_policy, .prepare_data = debug_prepare_data, .reply_size = debug_reply_size, diff --git a/net/ethtool/eee.c b/net/ethtool/eee.c index ea9d071b5360..9ee03444fb8f 100644 --- a/net/ethtool/eee.c +++ b/net/ethtool/eee.c @@ -121,7 +121,6 @@ const struct ethnl_request_ops ethnl_eee_request_ops = { .max_attr = ETHTOOL_A_EEE_MAX, .req_info_size = sizeof(struct eee_req_info), .reply_data_size = sizeof(struct eee_reply_data), - .request_policy = ethnl_eee_get_policy, .prepare_data = eee_prepare_data, .reply_size = eee_reply_size, diff --git a/net/ethtool/features.c b/net/ethtool/features.c index c2979b3890f9..99944190f398 100644 --- a/net/ethtool/features.c +++ b/net/ethtool/features.c @@ -123,7 +123,6 @@ const struct ethnl_request_ops ethnl_features_request_ops = { .max_attr = ETHTOOL_A_FEATURES_MAX, .req_info_size = sizeof(struct features_req_info), .reply_data_size = sizeof(struct features_reply_data), - .request_policy = ethnl_features_get_policy, .prepare_data = features_prepare_data, .reply_size = features_reply_size, diff --git a/net/ethtool/linkinfo.c b/net/ethtool/linkinfo.c index 676aa5a00ac0..b7142d8e2baf 100644 --- a/net/ethtool/linkinfo.c +++ b/net/ethtool/linkinfo.c @@ -86,7 +86,6 @@ const struct ethnl_request_ops ethnl_linkinfo_request_ops = { .max_attr = ETHTOOL_A_LINKINFO_MAX, .req_info_size = sizeof(struct linkinfo_req_info), .reply_data_size = sizeof(struct linkinfo_reply_data), - .request_policy = ethnl_linkinfo_get_policy, .prepare_data = linkinfo_prepare_data, .reply_size = linkinfo_reply_size, diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c index f32ab3239d15..e23e600b73cb 100644 --- a/net/ethtool/linkmodes.c +++ b/net/ethtool/linkmodes.c @@ -151,7 +151,6 @@ const struct ethnl_request_ops ethnl_linkmodes_request_ops = { .max_attr = ETHTOOL_A_LINKMODES_MAX, .req_info_size = sizeof(struct linkmodes_req_info), .reply_data_size = sizeof(struct linkmodes_reply_data), - .request_policy = ethnl_linkmodes_get_policy, .prepare_data = linkmodes_prepare_data, .reply_size = linkmodes_reply_size, diff --git a/net/ethtool/linkstate.c b/net/ethtool/linkstate.c index c86ae67e2486..3f0ab6e84fce 100644 --- a/net/ethtool/linkstate.c +++ b/net/ethtool/linkstate.c @@ -182,7 +182,6 @@ const struct ethnl_request_ops ethnl_linkstate_request_ops = { .max_attr = ETHTOOL_A_LINKSTATE_MAX, .req_info_size = sizeof(struct linkstate_req_info), .reply_data_size = sizeof(struct linkstate_reply_data), - .request_policy = ethnl_linkstate_get_policy, .prepare_data = linkstate_prepare_data, .reply_size = linkstate_reply_size, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index dbabac38c191..2f317caa077a 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -247,7 +247,7 @@ static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) /** * ethnl_default_parse() - Parse request message * @req_info: pointer to structure to put data into - * @nlhdr: pointer to request message header + * @tb: parsed attributes * @net: request netns * @request_ops: struct request_ops for request type * @extack: netlink extack for error reporting @@ -259,37 +259,24 @@ static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) * Return: 0 on success or negative error code */ static int ethnl_default_parse(struct ethnl_req_info *req_info, - const struct nlmsghdr *nlhdr, struct net *net, + struct nlattr **tb, struct net *net, const struct ethnl_request_ops *request_ops, struct netlink_ext_ack *extack, bool require_dev) { - struct nlattr **tb; int ret; - tb = kmalloc_array(request_ops->max_attr + 1, sizeof(tb[0]), - GFP_KERNEL); - if (!tb) - return -ENOMEM; - - ret = nlmsg_parse(nlhdr, GENL_HDRLEN, tb, request_ops->max_attr, - request_ops->request_policy, extack); - if (ret < 0) - goto out; ret = ethnl_parse_header_dev_get(req_info, tb[request_ops->hdr_attr], net, extack, require_dev); if (ret < 0) - goto out; + return ret; if (request_ops->parse_request) { ret = request_ops->parse_request(req_info, tb, extack); if (ret < 0) - goto out; + return ret; } - ret = 0; -out: - kfree(tb); - return ret; + return 0; } /** @@ -334,8 +321,8 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info) return -ENOMEM; } - ret = ethnl_default_parse(req_info, info->nlhdr, genl_info_net(info), ops, - info->extack, !ops->allow_nodev_do); + ret = ethnl_default_parse(req_info, info->attrs, genl_info_net(info), + ops, info->extack, !ops->allow_nodev_do); if (ret < 0) goto err_dev; ethnl_init_reply_data(reply_data, ops, req_info->dev); @@ -480,6 +467,7 @@ static int ethnl_default_dumpit(struct sk_buff *skb, /* generic ->start() handler for GET requests */ static int ethnl_default_start(struct netlink_callback *cb) { + const struct genl_dumpit_info *info = genl_dumpit_info(cb); struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); struct ethnl_reply_data *reply_data; const struct ethnl_request_ops *ops; @@ -502,8 +490,8 @@ static int ethnl_default_start(struct netlink_callback *cb) goto free_req_info; } - ret = ethnl_default_parse(req_info, cb->nlh, sock_net(cb->skb->sk), ops, - cb->extack, false); + ret = ethnl_default_parse(req_info, info->attrs, sock_net(cb->skb->sk), + ops, cb->extack, false); if (req_info->dev) { /* We ignore device specification in dump requests but as the * same parser as for non-dump (doit) requests is used, it diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 0100fab5829e..b67c41efaf7e 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -269,7 +269,6 @@ static inline void ethnl_ops_complete(struct net_device *dev) * @max_attr: maximum (top level) attribute type * @req_info_size: size of request info * @reply_data_size: size of reply data - * @request_policy: netlink policy for message contents * @allow_nodev_do: allow non-dump request with no device identification * @parse_request: * Parse request except common header (struct ethnl_req_info). Common @@ -315,7 +314,6 @@ struct ethnl_request_ops { unsigned int max_attr; unsigned int req_info_size; unsigned int reply_data_size; - const struct nla_policy *request_policy; bool allow_nodev_do; int (*parse_request)(struct ethnl_req_info *req_info, diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c index 40f36f8d6291..32f37240e04d 100644 --- a/net/ethtool/pause.c +++ b/net/ethtool/pause.c @@ -132,7 +132,6 @@ const struct ethnl_request_ops ethnl_pause_request_ops = { .max_attr = ETHTOOL_A_PAUSE_MAX, .req_info_size = sizeof(struct pause_req_info), .reply_data_size = sizeof(struct pause_reply_data), - .request_policy = ethnl_pause_get_policy, .prepare_data = pause_prepare_data, .reply_size = pause_reply_size, diff --git a/net/ethtool/privflags.c b/net/ethtool/privflags.c index 7ebab33f2244..c255c75a7ac0 100644 --- a/net/ethtool/privflags.c +++ b/net/ethtool/privflags.c @@ -127,7 +127,6 @@ const struct ethnl_request_ops ethnl_privflags_request_ops = { .max_attr = ETHTOOL_A_PRIVFLAGS_MAX, .req_info_size = sizeof(struct privflags_req_info), .reply_data_size = sizeof(struct privflags_reply_data), - .request_policy = ethnl_privflags_get_policy, .prepare_data = privflags_prepare_data, .reply_size = privflags_reply_size, diff --git a/net/ethtool/rings.c b/net/ethtool/rings.c index eb52639b6ed3..80545845a3c8 100644 --- a/net/ethtool/rings.c +++ b/net/ethtool/rings.c @@ -99,7 +99,6 @@ const struct ethnl_request_ops ethnl_rings_request_ops = { .max_attr = ETHTOOL_A_RINGS_MAX, .req_info_size = sizeof(struct rings_req_info), .reply_data_size = sizeof(struct rings_reply_data), - .request_policy = ethnl_rings_get_policy, .prepare_data = rings_prepare_data, .reply_size = rings_reply_size, diff --git a/net/ethtool/strset.c b/net/ethtool/strset.c index 8d30fe0fbe3b..e893f98505d0 100644 --- a/net/ethtool/strset.c +++ b/net/ethtool/strset.c @@ -448,7 +448,6 @@ const struct ethnl_request_ops ethnl_strset_request_ops = { .max_attr = ETHTOOL_A_STRSET_MAX, .req_info_size = sizeof(struct strset_req_info), .reply_data_size = sizeof(struct strset_reply_data), - .request_policy = ethnl_strset_get_policy, .allow_nodev_do = true, .parse_request = strset_parse_request, diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c index 05d501563dc9..185333d377c9 100644 --- a/net/ethtool/tsinfo.c +++ b/net/ethtool/tsinfo.c @@ -134,7 +134,6 @@ const struct ethnl_request_ops ethnl_tsinfo_request_ops = { .max_attr = ETHTOOL_A_TSINFO_MAX, .req_info_size = sizeof(struct tsinfo_req_info), .reply_data_size = sizeof(struct tsinfo_reply_data), - .request_policy = ethnl_tsinfo_get_policy, .prepare_data = tsinfo_prepare_data, .reply_size = tsinfo_reply_size, diff --git a/net/ethtool/tunnels.c b/net/ethtool/tunnels.c index d7d4964ea773..330817adcf62 100644 --- a/net/ethtool/tunnels.c +++ b/net/ethtool/tunnels.c @@ -161,35 +161,19 @@ ethnl_tunnel_info_fill_reply(const struct ethnl_req_info *req_base, return -EMSGSIZE; } -static int -ethnl_tunnel_info_req_parse(struct ethnl_req_info *req_info, - const struct nlmsghdr *nlhdr, struct net *net, - struct netlink_ext_ack *extack, bool require_dev) -{ - struct nlattr *tb[ETHTOOL_A_TUNNEL_INFO_MAX + 1]; - int ret; - - ret = nlmsg_parse(nlhdr, GENL_HDRLEN, tb, ETHTOOL_A_TUNNEL_INFO_MAX, - ethnl_tunnel_info_get_policy, extack); - if (ret < 0) - return ret; - - return ethnl_parse_header_dev_get(req_info, - tb[ETHTOOL_A_TUNNEL_INFO_HEADER], - net, extack, require_dev); -} - int ethnl_tunnel_info_doit(struct sk_buff *skb, struct genl_info *info) { struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; struct sk_buff *rskb; void *reply_payload; int reply_len; int ret; - ret = ethnl_tunnel_info_req_parse(&req_info, info->nlhdr, - genl_info_net(info), info->extack, - true); + ret = ethnl_parse_header_dev_get(&req_info, + tb[ETHTOOL_A_TUNNEL_INFO_HEADER], + genl_info_net(info), info->extack, + true); if (ret < 0) return ret; @@ -233,16 +217,19 @@ struct ethnl_tunnel_info_dump_ctx { int ethnl_tunnel_info_start(struct netlink_callback *cb) { + const struct genl_dumpit_info *info = genl_dumpit_info(cb); struct ethnl_tunnel_info_dump_ctx *ctx = (void *)cb->ctx; + struct nlattr **tb = info->attrs; int ret; BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx)); memset(ctx, 0, sizeof(*ctx)); - ret = ethnl_tunnel_info_req_parse(&ctx->req_info, cb->nlh, - sock_net(cb->skb->sk), cb->extack, - false); + ret = ethnl_parse_header_dev_get(&ctx->req_info, + tb[ETHTOOL_A_TUNNEL_INFO_HEADER], + sock_net(cb->skb->sk), cb->extack, + false); if (ctx->req_info.dev) { dev_put(ctx->req_info.dev); ctx->req_info.dev = NULL; diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c index d234885fc265..4a88c597890c 100644 --- a/net/ethtool/wol.c +++ b/net/ethtool/wol.c @@ -91,7 +91,6 @@ const struct ethnl_request_ops ethnl_wol_request_ops = { .max_attr = ETHTOOL_A_WOL_MAX, .req_info_size = sizeof(struct wol_req_info), .reply_data_size = sizeof(struct wol_reply_data), - .request_policy = ethnl_wol_get_policy, .prepare_data = wol_prepare_data, .reply_size = wol_reply_size, From patchwork Mon Oct 5 15:57:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 268090 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB65CC4363D for ; Mon, 5 Oct 2020 15:58:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B7B820663 for ; Mon, 5 Oct 2020 15:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913492; bh=tzhQb5iyKZBF0aNypxY2FEGtL+iJiB0jmgoRfP/PYF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=yNiRng8GTTr9tBacyL4q7vLVLvNKd/jDIRfxclp8BAkwXwy3i/gIANkASzNqE7klG 6lj05/QFZZhw4bEwxgGY7u7QITXT3KD3ZqkRRwZvFnLudRY7XvHGkewZaSZUCjjosB gJByXLbGq1HCVeKM/RrllhXWCY53kHJEF9hXnbOM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728896AbgJEP6K (ORCPT ); Mon, 5 Oct 2020 11:58:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:56814 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728858AbgJEP6J (ORCPT ); Mon, 5 Oct 2020 11:58:09 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D857F2085B; Mon, 5 Oct 2020 15:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913487; bh=tzhQb5iyKZBF0aNypxY2FEGtL+iJiB0jmgoRfP/PYF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U8TlhE1AgPsGVVshshlvK0eDE7iLeaOU0A314F4XUucKdzTAUOzgDadKenza1QkER a2EbfxSw+VcwDmh+1GBuIcEAgUVeWQQBHvHCJC7XS3KvwDt0jAUDIwDhddarJ54I0n lIMAw/Fr7GOi06jwGxs35GsCxMaIbbcUZUHzahOc= From: Jakub Kicinski 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 Subject: [PATCH net-next 3/6] ethtool: wire up set policies to ops Date: Mon, 5 Oct 2020 08:57:50 -0700 Message-Id: <20201005155753.2333882-4-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201005155753.2333882-1-kuba@kernel.org> References: <20201005155753.2333882-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Similarly to get commands wire up the policies of set commands to get parsing by the core and policy dumps. Signed-off-by: Jakub Kicinski --- net/ethtool/cabletest.c | 24 ++++++------------------ net/ethtool/channels.c | 11 +++-------- net/ethtool/coalesce.c | 11 +++-------- net/ethtool/debug.c | 10 ++-------- net/ethtool/eee.c | 11 +++-------- net/ethtool/features.c | 11 +++-------- net/ethtool/linkinfo.c | 11 +++-------- net/ethtool/linkmodes.c | 11 +++-------- net/ethtool/netlink.c | 26 ++++++++++++++++++++++++++ net/ethtool/netlink.h | 13 +++++++++++++ net/ethtool/pause.c | 9 ++------- net/ethtool/privflags.c | 11 +++-------- net/ethtool/rings.c | 10 ++-------- net/ethtool/wol.c | 9 ++------- 14 files changed, 74 insertions(+), 104 deletions(-) diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c index 888f6e101f34..beb85e0b7fc6 100644 --- a/net/ethtool/cabletest.c +++ b/net/ethtool/cabletest.c @@ -11,8 +11,8 @@ */ #define MAX_CABLE_LENGTH_CM (150 * 100) -static const struct nla_policy -cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = { +const struct nla_policy +ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = { [ETHTOOL_A_CABLE_TEST_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_CABLE_TEST_HEADER] = { .type = NLA_NESTED }, }; @@ -56,18 +56,12 @@ static int ethnl_cable_test_started(struct phy_device *phydev, u8 cmd) int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_CABLE_TEST_MAX + 1]; struct ethnl_req_info req_info = {}; const struct ethtool_phy_ops *ops; + struct nlattr **tb = info->attrs; struct net_device *dev; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_CABLE_TEST_MAX, - cable_test_act_policy, info->extack); - if (ret < 0) - return ret; - ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_CABLE_TEST_HEADER], genl_info_net(info), info->extack, @@ -226,8 +220,8 @@ cable_test_tdr_act_cfg_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX + 1] = { [ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR] = { .type = NLA_U8 }, }; -static const struct nla_policy -cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_MAX + 1] = { +const struct nla_policy +ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_MAX + 1] = { [ETHTOOL_A_CABLE_TEST_TDR_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_CABLE_TEST_TDR_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_CABLE_TEST_TDR_CFG] = { .type = NLA_NESTED }, @@ -313,19 +307,13 @@ static int ethnl_act_cable_test_tdr_cfg(const struct nlattr *nest, int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_CABLE_TEST_TDR_MAX + 1]; struct ethnl_req_info req_info = {}; const struct ethtool_phy_ops *ops; + struct nlattr **tb = info->attrs; struct phy_tdr_config cfg; struct net_device *dev; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_CABLE_TEST_TDR_MAX, - cable_test_tdr_act_policy, info->extack); - if (ret < 0) - return ret; - ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_CABLE_TEST_TDR_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/channels.c b/net/ethtool/channels.c index 76994c8f32a0..7e14e93adedb 100644 --- a/net/ethtool/channels.c +++ b/net/ethtool/channels.c @@ -110,8 +110,8 @@ const struct ethnl_request_ops ethnl_channels_request_ops = { /* CHANNELS_SET */ -static const struct nla_policy -channels_set_policy[ETHTOOL_A_CHANNELS_MAX + 1] = { +const struct nla_policy +ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_MAX + 1] = { [ETHTOOL_A_CHANNELS_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_CHANNELS_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_CHANNELS_RX_MAX] = { .type = NLA_REJECT }, @@ -126,22 +126,17 @@ channels_set_policy[ETHTOOL_A_CHANNELS_MAX + 1] = { int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_CHANNELS_MAX + 1]; unsigned int from_channel, old_total, i; bool mod = false, mod_combined = false; struct ethtool_channels channels = {}; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; const struct nlattr *err_attr; const struct ethtool_ops *ops; struct net_device *dev; u32 max_rx_in_use = 0; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_CHANNELS_MAX, channels_set_policy, - info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_CHANNELS_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/coalesce.c b/net/ethtool/coalesce.c index 77d83062faa2..261ef40f7f98 100644 --- a/net/ethtool/coalesce.c +++ b/net/ethtool/coalesce.c @@ -214,8 +214,8 @@ const struct ethnl_request_ops ethnl_coalesce_request_ops = { /* COALESCE_SET */ -static const struct nla_policy -coalesce_set_policy[ETHTOOL_A_COALESCE_MAX + 1] = { +const struct nla_policy +ethnl_coalesce_set_policy[ETHTOOL_A_COALESCE_MAX + 1] = { [ETHTOOL_A_COALESCE_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_COALESCE_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_COALESCE_RX_USECS] = { .type = NLA_U32 }, @@ -244,9 +244,9 @@ coalesce_set_policy[ETHTOOL_A_COALESCE_MAX + 1] = { int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_COALESCE_MAX + 1]; struct ethtool_coalesce coalesce = {}; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; const struct ethtool_ops *ops; struct net_device *dev; u32 supported_params; @@ -254,11 +254,6 @@ int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info) int ret; u16 a; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_COALESCE_MAX, coalesce_set_policy, - info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_COALESCE_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/debug.c b/net/ethtool/debug.c index f553ef6a99e4..33a4126ed80d 100644 --- a/net/ethtool/debug.c +++ b/net/ethtool/debug.c @@ -79,8 +79,7 @@ const struct ethnl_request_ops ethnl_debug_request_ops = { /* DEBUG_SET */ -static const struct nla_policy -debug_set_policy[ETHTOOL_A_DEBUG_MAX + 1] = { +const struct nla_policy ethnl_debug_set_policy[ETHTOOL_A_DEBUG_MAX + 1] = { [ETHTOOL_A_DEBUG_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_DEBUG_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_DEBUG_MSGMASK] = { .type = NLA_NESTED }, @@ -88,18 +87,13 @@ debug_set_policy[ETHTOOL_A_DEBUG_MAX + 1] = { int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_DEBUG_MAX + 1]; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; struct net_device *dev; bool mod = false; u32 msg_mask; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_DEBUG_MAX, debug_set_policy, - info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_DEBUG_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/eee.c b/net/ethtool/eee.c index 9ee03444fb8f..25b99f1cfe12 100644 --- a/net/ethtool/eee.c +++ b/net/ethtool/eee.c @@ -129,8 +129,7 @@ const struct ethnl_request_ops ethnl_eee_request_ops = { /* EEE_SET */ -static const struct nla_policy -eee_set_policy[ETHTOOL_A_EEE_MAX + 1] = { +const struct nla_policy ethnl_eee_set_policy[ETHTOOL_A_EEE_MAX + 1] = { [ETHTOOL_A_EEE_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_EEE_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_EEE_MODES_OURS] = { .type = NLA_NESTED }, @@ -143,18 +142,14 @@ eee_set_policy[ETHTOOL_A_EEE_MAX + 1] = { int ethnl_set_eee(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_EEE_MAX + 1]; - struct ethtool_eee eee = {}; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; const struct ethtool_ops *ops; + struct ethtool_eee eee = {}; struct net_device *dev; bool mod = false; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, ETHTOOL_A_EEE_MAX, - eee_set_policy, info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_EEE_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/features.c b/net/ethtool/features.c index 99944190f398..00c5b77852ec 100644 --- a/net/ethtool/features.c +++ b/net/ethtool/features.c @@ -131,8 +131,8 @@ const struct ethnl_request_ops ethnl_features_request_ops = { /* FEATURES_SET */ -static const struct nla_policy -features_set_policy[ETHTOOL_A_FEATURES_MAX + 1] = { +const struct nla_policy +ethnl_features_set_policy[ETHTOOL_A_FEATURES_MAX + 1] = { [ETHTOOL_A_FEATURES_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_FEATURES_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_FEATURES_HW] = { .type = NLA_REJECT }, @@ -228,17 +228,12 @@ int ethnl_set_features(struct sk_buff *skb, struct genl_info *info) DECLARE_BITMAP(new_wanted, NETDEV_FEATURE_COUNT); DECLARE_BITMAP(req_wanted, NETDEV_FEATURE_COUNT); DECLARE_BITMAP(req_mask, NETDEV_FEATURE_COUNT); - struct nlattr *tb[ETHTOOL_A_FEATURES_MAX + 1]; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; struct net_device *dev; bool mod; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_FEATURES_MAX, features_set_policy, - info->extack); - if (ret < 0) - return ret; if (!tb[ETHTOOL_A_FEATURES_WANTED]) return -EINVAL; ret = ethnl_parse_header_dev_get(&req_info, diff --git a/net/ethtool/linkinfo.c b/net/ethtool/linkinfo.c index b7142d8e2baf..eb801271b9bc 100644 --- a/net/ethtool/linkinfo.c +++ b/net/ethtool/linkinfo.c @@ -94,8 +94,8 @@ const struct ethnl_request_ops ethnl_linkinfo_request_ops = { /* LINKINFO_SET */ -static const struct nla_policy -linkinfo_set_policy[ETHTOOL_A_LINKINFO_MAX + 1] = { +const struct nla_policy +ethnl_linkinfo_set_policy[ETHTOOL_A_LINKINFO_MAX + 1] = { [ETHTOOL_A_LINKINFO_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKINFO_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_LINKINFO_PORT] = { .type = NLA_U8 }, @@ -107,19 +107,14 @@ linkinfo_set_policy[ETHTOOL_A_LINKINFO_MAX + 1] = { int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_LINKINFO_MAX + 1]; struct ethtool_link_ksettings ksettings = {}; struct ethtool_link_settings *lsettings; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; struct net_device *dev; bool mod = false; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_LINKINFO_MAX, linkinfo_set_policy, - info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_LINKINFO_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c index e23e600b73cb..b5f061f192b9 100644 --- a/net/ethtool/linkmodes.c +++ b/net/ethtool/linkmodes.c @@ -275,8 +275,8 @@ static const struct link_mode_info link_mode_params[] = { __DEFINE_LINK_MODE_PARAMS(100, FX, Full), }; -static const struct nla_policy -linkmodes_set_policy[ETHTOOL_A_LINKMODES_MAX + 1] = { +const struct nla_policy +ethnl_linkmodes_set_policy[ETHTOOL_A_LINKMODES_MAX + 1] = { [ETHTOOL_A_LINKMODES_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKMODES_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_LINKMODES_AUTONEG] = { .type = NLA_U8 }, @@ -391,18 +391,13 @@ static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb, int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_LINKMODES_MAX + 1]; struct ethtool_link_ksettings ksettings = {}; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; struct net_device *dev; bool mod = false; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_LINKMODES_MAX, linkmodes_set_policy, - info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_LINKMODES_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 2f317caa077a..f2d197e6c9d0 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -700,6 +700,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_LINKINFO_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_linkinfo, + .policy = ethnl_linkinfo_set_policy, + .maxattr = ARRAY_SIZE(ethnl_linkinfo_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_LINKMODES_GET, @@ -714,6 +716,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_LINKMODES_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_linkmodes, + .policy = ethnl_linkmodes_set_policy, + .maxattr = ARRAY_SIZE(ethnl_linkmodes_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_LINKSTATE_GET, @@ -737,6 +741,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_DEBUG_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_debug, + .policy = ethnl_debug_set_policy, + .maxattr = ARRAY_SIZE(ethnl_debug_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_WOL_GET, @@ -752,6 +758,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_WOL_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_wol, + .policy = ethnl_wol_set_policy, + .maxattr = ARRAY_SIZE(ethnl_wol_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_FEATURES_GET, @@ -766,6 +774,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_FEATURES_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_features, + .policy = ethnl_features_set_policy, + .maxattr = ARRAY_SIZE(ethnl_features_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_PRIVFLAGS_GET, @@ -780,6 +790,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_PRIVFLAGS_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_privflags, + .policy = ethnl_privflags_set_policy, + .maxattr = ARRAY_SIZE(ethnl_privflags_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_RINGS_GET, @@ -795,6 +807,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_RINGS_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_rings, + .policy = ethnl_rings_set_policy, + .maxattr = ARRAY_SIZE(ethnl_rings_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_CHANNELS_GET, @@ -810,6 +824,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_CHANNELS_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_channels, + .policy = ethnl_channels_get_policy, + .maxattr = ARRAY_SIZE(ethnl_channels_get_policy) - 1, }, { .cmd = ETHTOOL_MSG_COALESCE_GET, @@ -824,6 +840,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_COALESCE_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_coalesce, + .policy = ethnl_coalesce_set_policy, + .maxattr = ARRAY_SIZE(ethnl_coalesce_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_PAUSE_GET, @@ -838,6 +856,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_PAUSE_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_pause, + .policy = ethnl_pause_set_policy, + .maxattr = ARRAY_SIZE(ethnl_pause_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_EEE_GET, @@ -852,6 +872,8 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_EEE_SET, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_eee, + .policy = ethnl_eee_set_policy, + .maxattr = ARRAY_SIZE(ethnl_eee_set_policy) - 1, }, { .cmd = ETHTOOL_MSG_TSINFO_GET, @@ -866,11 +888,15 @@ static const struct genl_ops ethtool_genl_ops[] = { .cmd = ETHTOOL_MSG_CABLE_TEST_ACT, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_act_cable_test, + .policy = ethnl_cable_test_act_policy, + .maxattr = ARRAY_SIZE(ethnl_cable_test_act_policy) - 1, }, { .cmd = ETHTOOL_MSG_CABLE_TEST_TDR_ACT, .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_act_cable_test_tdr, + .policy = ethnl_cable_test_tdr_act_policy, + .maxattr = ARRAY_SIZE(ethnl_cable_test_tdr_act_policy) - 1, }, { .cmd = ETHTOOL_MSG_TUNNEL_INFO_GET, diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index b67c41efaf7e..53eeda056441 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -349,18 +349,31 @@ extern const struct ethnl_request_ops ethnl_tsinfo_request_ops; 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]; extern const struct nla_policy ethnl_linkmodes_get_policy[ETHTOOL_A_LINKMODES_MAX + 1]; +extern const struct nla_policy ethnl_linkmodes_set_policy[ETHTOOL_A_LINKMODES_MAX + 1]; extern const struct nla_policy ethnl_linkstate_get_policy[ETHTOOL_A_LINKSTATE_MAX + 1]; extern const struct nla_policy ethnl_debug_get_policy[ETHTOOL_A_DEBUG_MAX + 1]; +extern const struct nla_policy ethnl_debug_set_policy[ETHTOOL_A_DEBUG_MAX + 1]; extern const struct nla_policy ethnl_wol_get_policy[ETHTOOL_A_WOL_MAX + 1]; +extern const struct nla_policy ethnl_wol_set_policy[ETHTOOL_A_WOL_MAX + 1]; extern const struct nla_policy ethnl_features_get_policy[ETHTOOL_A_FEATURES_MAX + 1]; +extern const struct nla_policy ethnl_features_set_policy[ETHTOOL_A_FEATURES_MAX + 1]; extern const struct nla_policy ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1]; +extern const struct nla_policy ethnl_privflags_set_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1]; extern const struct nla_policy ethnl_rings_get_policy[ETHTOOL_A_RINGS_MAX + 1]; +extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_MAX + 1]; extern const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_MAX + 1]; +extern const struct nla_policy ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_MAX + 1]; extern const struct nla_policy ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_MAX + 1]; +extern const struct nla_policy ethnl_coalesce_set_policy[ETHTOOL_A_COALESCE_MAX + 1]; extern const struct nla_policy ethnl_pause_get_policy[ETHTOOL_A_PAUSE_MAX + 1]; +extern const struct nla_policy ethnl_pause_set_policy[ETHTOOL_A_PAUSE_MAX + 1]; extern const struct nla_policy ethnl_eee_get_policy[ETHTOOL_A_EEE_MAX + 1]; +extern const struct nla_policy ethnl_eee_set_policy[ETHTOOL_A_EEE_MAX + 1]; extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX + 1]; +extern const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1]; +extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_MAX + 1]; extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_MAX + 1]; int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info); diff --git a/net/ethtool/pause.c b/net/ethtool/pause.c index 32f37240e04d..26c73ba987d1 100644 --- a/net/ethtool/pause.c +++ b/net/ethtool/pause.c @@ -140,8 +140,7 @@ const struct ethnl_request_ops ethnl_pause_request_ops = { /* PAUSE_SET */ -static const struct nla_policy -pause_set_policy[ETHTOOL_A_PAUSE_MAX + 1] = { +const struct nla_policy ethnl_pause_set_policy[ETHTOOL_A_PAUSE_MAX + 1] = { [ETHTOOL_A_PAUSE_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_PAUSE_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_PAUSE_AUTONEG] = { .type = NLA_U8 }, @@ -152,18 +151,14 @@ pause_set_policy[ETHTOOL_A_PAUSE_MAX + 1] = { int ethnl_set_pause(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_PAUSE_MAX + 1]; struct ethtool_pauseparam params = {}; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; const struct ethtool_ops *ops; struct net_device *dev; bool mod = false; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, ETHTOOL_A_PAUSE_MAX, - pause_set_policy, info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_PAUSE_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/privflags.c b/net/ethtool/privflags.c index c255c75a7ac0..f8164e0f2f87 100644 --- a/net/ethtool/privflags.c +++ b/net/ethtool/privflags.c @@ -136,8 +136,8 @@ const struct ethnl_request_ops ethnl_privflags_request_ops = { /* PRIVFLAGS_SET */ -static const struct nla_policy -privflags_set_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1] = { +const struct nla_policy +ethnl_privflags_set_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1] = { [ETHTOOL_A_PRIVFLAGS_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_PRIVFLAGS_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_PRIVFLAGS_FLAGS] = { .type = NLA_NESTED }, @@ -145,9 +145,9 @@ privflags_set_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1] = { int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_PRIVFLAGS_MAX + 1]; const char (*names)[ETH_GSTRING_LEN] = NULL; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; const struct ethtool_ops *ops; struct net_device *dev; unsigned int nflags; @@ -156,11 +156,6 @@ int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info) u32 flags; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_PRIVFLAGS_MAX, privflags_set_policy, - info->extack); - if (ret < 0) - return ret; if (!tb[ETHTOOL_A_PRIVFLAGS_FLAGS]) return -EINVAL; ret = ethnl_bitset_is_compact(tb[ETHTOOL_A_PRIVFLAGS_FLAGS], &compact); diff --git a/net/ethtool/rings.c b/net/ethtool/rings.c index 80545845a3c8..73ee664f9b0b 100644 --- a/net/ethtool/rings.c +++ b/net/ethtool/rings.c @@ -107,8 +107,7 @@ const struct ethnl_request_ops ethnl_rings_request_ops = { /* RINGS_SET */ -static const struct nla_policy -rings_set_policy[ETHTOOL_A_RINGS_MAX + 1] = { +const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_MAX + 1] = { [ETHTOOL_A_RINGS_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_RINGS_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_RINGS_RX_MAX] = { .type = NLA_REJECT }, @@ -123,20 +122,15 @@ rings_set_policy[ETHTOOL_A_RINGS_MAX + 1] = { int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *tb[ETHTOOL_A_RINGS_MAX + 1]; struct ethtool_ringparam ringparam = {}; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; const struct nlattr *err_attr; const struct ethtool_ops *ops; struct net_device *dev; bool mod = false; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, - ETHTOOL_A_RINGS_MAX, rings_set_policy, - info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_RINGS_HEADER], genl_info_net(info), info->extack, diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c index 4a88c597890c..a5f396c8c69a 100644 --- a/net/ethtool/wol.c +++ b/net/ethtool/wol.c @@ -99,8 +99,7 @@ const struct ethnl_request_ops ethnl_wol_request_ops = { /* WOL_SET */ -static const struct nla_policy -wol_set_policy[ETHTOOL_A_WOL_MAX + 1] = { +const struct nla_policy ethnl_wol_set_policy[ETHTOOL_A_WOL_MAX + 1] = { [ETHTOOL_A_WOL_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_WOL_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_WOL_MODES] = { .type = NLA_NESTED }, @@ -111,16 +110,12 @@ wol_set_policy[ETHTOOL_A_WOL_MAX + 1] = { int ethnl_set_wol(struct sk_buff *skb, struct genl_info *info) { struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; - struct nlattr *tb[ETHTOOL_A_WOL_MAX + 1]; struct ethnl_req_info req_info = {}; + struct nlattr **tb = info->attrs; struct net_device *dev; bool mod = false; int ret; - ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, ETHTOOL_A_WOL_MAX, - wol_set_policy, info->extack); - if (ret < 0) - return ret; ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_WOL_HEADER], genl_info_net(info), info->extack, true); From patchwork Mon Oct 5 15:57:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 288984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B3BCC46466 for ; Mon, 5 Oct 2020 15:58:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1B8420663 for ; Mon, 5 Oct 2020 15:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913491; bh=0eRoRSZ7j9UMHnlBnA9fTPrkden7f8gFHt/+Dq3j4As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0LCtAlODauCFOvdxdU1Z0sFctSrV1ESy42q+r+T+Hl+e7j8EelcuL7M/XmtKeQGeq yow0lHFxjBygQGn165Ppj088+AkDE5hU+ZWRDUtF/yA9VspZhN3Dvfn78vz9PIlDZU jkQktLsmaFa1eeaFZ9kt0zBZiQoNgP/m9nRy6DZ0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728885AbgJEP6K (ORCPT ); Mon, 5 Oct 2020 11:58:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:56852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728859AbgJEP6I (ORCPT ); Mon, 5 Oct 2020 11:58:08 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 595562100A; Mon, 5 Oct 2020 15:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913487; bh=0eRoRSZ7j9UMHnlBnA9fTPrkden7f8gFHt/+Dq3j4As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bjFSx954so2iOnYaBNsvIKbx9j27cUQiQE4nbg6zRhctDFbGJnT4hq+Yhp7T2fkT/ BSLdnRCtKC/CMjilNnDj9bWXq8ogSTlaRxiOkfKuYP/9+cECFLD0S4cXPKz2DtbnYP TvWOtzxwtN77YjbvgygepZ7i9ajabGt9PpMUS8zw= From: Jakub Kicinski 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 Subject: [PATCH net-next 4/6] ethtool: link up ethnl_header_policy as a nested policy Date: Mon, 5 Oct 2020 08:57:51 -0700 Message-Id: <20201005155753.2333882-5-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201005155753.2333882-1-kuba@kernel.org> References: <20201005155753.2333882-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To get the most out of parsing by the core, and to allow dumping full policies we need to specify which policy applies to nested attrs. For headers it's ethnl_header_policy. $ sed -i 's@\(ETHTOOL_A_.*HEADER\].*=\) { .type = NLA_NESTED },@\1\n\t\tNLA_POLICY_NESTED(ethnl_header_policy),@' net/ethtool/* Signed-off-by: Jakub Kicinski --- net/ethtool/cabletest.c | 6 ++++-- net/ethtool/channels.c | 6 ++++-- net/ethtool/coalesce.c | 6 ++++-- net/ethtool/debug.c | 6 ++++-- net/ethtool/eee.c | 6 ++++-- net/ethtool/features.c | 6 ++++-- net/ethtool/linkinfo.c | 6 ++++-- net/ethtool/linkmodes.c | 6 ++++-- net/ethtool/linkstate.c | 3 ++- net/ethtool/netlink.c | 2 +- net/ethtool/netlink.h | 1 + net/ethtool/pause.c | 6 ++++-- net/ethtool/privflags.c | 6 ++++-- net/ethtool/rings.c | 6 ++++-- net/ethtool/strset.c | 3 ++- net/ethtool/tsinfo.c | 3 ++- net/ethtool/tunnels.c | 3 ++- net/ethtool/wol.c | 6 ++++-- 18 files changed, 58 insertions(+), 29 deletions(-) diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c index beb85e0b7fc6..17019ed74a02 100644 --- a/net/ethtool/cabletest.c +++ b/net/ethtool/cabletest.c @@ -14,7 +14,8 @@ const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = { [ETHTOOL_A_CABLE_TEST_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_CABLE_TEST_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_CABLE_TEST_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), }; static int ethnl_cable_test_started(struct phy_device *phydev, u8 cmd) @@ -223,7 +224,8 @@ cable_test_tdr_act_cfg_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX + 1] = { const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_MAX + 1] = { [ETHTOOL_A_CABLE_TEST_TDR_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_CABLE_TEST_TDR_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_CABLE_TEST_TDR_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_CABLE_TEST_TDR_CFG] = { .type = NLA_NESTED }, }; diff --git a/net/ethtool/channels.c b/net/ethtool/channels.c index 7e14e93adedb..dbbe2dcb21d6 100644 --- a/net/ethtool/channels.c +++ b/net/ethtool/channels.c @@ -20,7 +20,8 @@ struct channels_reply_data { const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_MAX + 1] = { [ETHTOOL_A_CHANNELS_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_CHANNELS_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_CHANNELS_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_CHANNELS_RX_MAX] = { .type = NLA_REJECT }, [ETHTOOL_A_CHANNELS_TX_MAX] = { .type = NLA_REJECT }, [ETHTOOL_A_CHANNELS_OTHER_MAX] = { .type = NLA_REJECT }, @@ -113,7 +114,8 @@ const struct ethnl_request_ops ethnl_channels_request_ops = { const struct nla_policy ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_MAX + 1] = { [ETHTOOL_A_CHANNELS_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_CHANNELS_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_CHANNELS_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_CHANNELS_RX_MAX] = { .type = NLA_REJECT }, [ETHTOOL_A_CHANNELS_TX_MAX] = { .type = NLA_REJECT }, [ETHTOOL_A_CHANNELS_OTHER_MAX] = { .type = NLA_REJECT }, diff --git a/net/ethtool/coalesce.c b/net/ethtool/coalesce.c index 261ef40f7f98..15adc9861421 100644 --- a/net/ethtool/coalesce.c +++ b/net/ethtool/coalesce.c @@ -54,7 +54,8 @@ __CHECK_SUPPORTED_OFFSET(COALESCE_RATE_SAMPLE_INTERVAL); const struct nla_policy ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_MAX + 1] = { [ETHTOOL_A_COALESCE_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_COALESCE_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_COALESCE_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_COALESCE_RX_USECS] = { .type = NLA_REJECT }, [ETHTOOL_A_COALESCE_RX_MAX_FRAMES] = { .type = NLA_REJECT }, [ETHTOOL_A_COALESCE_RX_USECS_IRQ] = { .type = NLA_REJECT }, @@ -217,7 +218,8 @@ const struct ethnl_request_ops ethnl_coalesce_request_ops = { const struct nla_policy ethnl_coalesce_set_policy[ETHTOOL_A_COALESCE_MAX + 1] = { [ETHTOOL_A_COALESCE_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_COALESCE_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_COALESCE_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_COALESCE_RX_USECS] = { .type = NLA_U32 }, [ETHTOOL_A_COALESCE_RX_MAX_FRAMES] = { .type = NLA_U32 }, [ETHTOOL_A_COALESCE_RX_USECS_IRQ] = { .type = NLA_U32 }, diff --git a/net/ethtool/debug.c b/net/ethtool/debug.c index 33a4126ed80d..b72980698ecb 100644 --- a/net/ethtool/debug.c +++ b/net/ethtool/debug.c @@ -18,7 +18,8 @@ struct debug_reply_data { const struct nla_policy ethnl_debug_get_policy[ETHTOOL_A_DEBUG_MAX + 1] = { [ETHTOOL_A_DEBUG_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_DEBUG_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_DEBUG_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_DEBUG_MSGMASK] = { .type = NLA_REJECT }, }; @@ -81,7 +82,8 @@ const struct ethnl_request_ops ethnl_debug_request_ops = { const struct nla_policy ethnl_debug_set_policy[ETHTOOL_A_DEBUG_MAX + 1] = { [ETHTOOL_A_DEBUG_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_DEBUG_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_DEBUG_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_DEBUG_MSGMASK] = { .type = NLA_NESTED }, }; diff --git a/net/ethtool/eee.c b/net/ethtool/eee.c index 25b99f1cfe12..646456d5d78a 100644 --- a/net/ethtool/eee.c +++ b/net/ethtool/eee.c @@ -21,7 +21,8 @@ struct eee_reply_data { const struct nla_policy ethnl_eee_get_policy[ETHTOOL_A_EEE_MAX + 1] = { [ETHTOOL_A_EEE_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_EEE_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_EEE_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_EEE_MODES_OURS] = { .type = NLA_REJECT }, [ETHTOOL_A_EEE_MODES_PEER] = { .type = NLA_REJECT }, [ETHTOOL_A_EEE_ACTIVE] = { .type = NLA_REJECT }, @@ -131,7 +132,8 @@ const struct ethnl_request_ops ethnl_eee_request_ops = { const struct nla_policy ethnl_eee_set_policy[ETHTOOL_A_EEE_MAX + 1] = { [ETHTOOL_A_EEE_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_EEE_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_EEE_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_EEE_MODES_OURS] = { .type = NLA_NESTED }, [ETHTOOL_A_EEE_MODES_PEER] = { .type = NLA_REJECT }, [ETHTOOL_A_EEE_ACTIVE] = { .type = NLA_REJECT }, diff --git a/net/ethtool/features.c b/net/ethtool/features.c index 00c5b77852ec..63ead0ca9eac 100644 --- a/net/ethtool/features.c +++ b/net/ethtool/features.c @@ -23,7 +23,8 @@ struct features_reply_data { const struct nla_policy ethnl_features_get_policy[ETHTOOL_A_FEATURES_MAX + 1] = { [ETHTOOL_A_FEATURES_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_FEATURES_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_FEATURES_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_FEATURES_HW] = { .type = NLA_REJECT }, [ETHTOOL_A_FEATURES_WANTED] = { .type = NLA_REJECT }, [ETHTOOL_A_FEATURES_ACTIVE] = { .type = NLA_REJECT }, @@ -134,7 +135,8 @@ const struct ethnl_request_ops ethnl_features_request_ops = { const struct nla_policy ethnl_features_set_policy[ETHTOOL_A_FEATURES_MAX + 1] = { [ETHTOOL_A_FEATURES_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_FEATURES_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_FEATURES_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_FEATURES_HW] = { .type = NLA_REJECT }, [ETHTOOL_A_FEATURES_WANTED] = { .type = NLA_NESTED }, [ETHTOOL_A_FEATURES_ACTIVE] = { .type = NLA_REJECT }, diff --git a/net/ethtool/linkinfo.c b/net/ethtool/linkinfo.c index eb801271b9bc..9d66679b3e21 100644 --- a/net/ethtool/linkinfo.c +++ b/net/ethtool/linkinfo.c @@ -19,7 +19,8 @@ struct linkinfo_reply_data { const struct nla_policy ethnl_linkinfo_get_policy[ETHTOOL_A_LINKINFO_MAX + 1] = { [ETHTOOL_A_LINKINFO_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_LINKINFO_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_LINKINFO_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_LINKINFO_PORT] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKINFO_PHYADDR] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKINFO_TP_MDIX] = { .type = NLA_REJECT }, @@ -97,7 +98,8 @@ const struct ethnl_request_ops ethnl_linkinfo_request_ops = { const struct nla_policy ethnl_linkinfo_set_policy[ETHTOOL_A_LINKINFO_MAX + 1] = { [ETHTOOL_A_LINKINFO_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_LINKINFO_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_LINKINFO_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_LINKINFO_PORT] = { .type = NLA_U8 }, [ETHTOOL_A_LINKINFO_PHYADDR] = { .type = NLA_U8 }, [ETHTOOL_A_LINKINFO_TP_MDIX] = { .type = NLA_REJECT }, diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c index b5f061f192b9..951ab02e688e 100644 --- a/net/ethtool/linkmodes.c +++ b/net/ethtool/linkmodes.c @@ -21,7 +21,8 @@ struct linkmodes_reply_data { const struct nla_policy ethnl_linkmodes_get_policy[ETHTOOL_A_LINKMODES_MAX + 1] = { [ETHTOOL_A_LINKMODES_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_LINKMODES_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_LINKMODES_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_LINKMODES_AUTONEG] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKMODES_OURS] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKMODES_PEER] = { .type = NLA_REJECT }, @@ -278,7 +279,8 @@ static const struct link_mode_info link_mode_params[] = { const struct nla_policy ethnl_linkmodes_set_policy[ETHTOOL_A_LINKMODES_MAX + 1] = { [ETHTOOL_A_LINKMODES_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_LINKMODES_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_LINKMODES_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_LINKMODES_AUTONEG] = { .type = NLA_U8 }, [ETHTOOL_A_LINKMODES_OURS] = { .type = NLA_NESTED }, [ETHTOOL_A_LINKMODES_PEER] = { .type = NLA_REJECT }, diff --git a/net/ethtool/linkstate.c b/net/ethtool/linkstate.c index 3f0ab6e84fce..ed713552029c 100644 --- a/net/ethtool/linkstate.c +++ b/net/ethtool/linkstate.c @@ -23,7 +23,8 @@ struct linkstate_reply_data { const struct nla_policy ethnl_linkstate_get_policy[ETHTOOL_A_LINKSTATE_MAX + 1] = { [ETHTOOL_A_LINKSTATE_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_LINKSTATE_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_LINKSTATE_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_LINKSTATE_LINK] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKSTATE_SQI] = { .type = NLA_REJECT }, [ETHTOOL_A_LINKSTATE_SQI_MAX] = { .type = NLA_REJECT }, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index f2d197e6c9d0..e78ff7ce2a7d 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -9,7 +9,7 @@ static struct genl_family ethtool_genl_family; static bool ethnl_ok __read_mostly; static u32 ethnl_bcast_seq; -static const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_MAX + 1] = { +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, diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 53eeda056441..4fcd2e8b259b 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -347,6 +347,7 @@ extern const struct ethnl_request_ops ethnl_pause_request_ops; 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_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 26c73ba987d1..a7fbe0e4dca6 100644 --- a/net/ethtool/pause.c +++ b/net/ethtool/pause.c @@ -18,7 +18,8 @@ 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] = { .type = NLA_NESTED }, + [ETHTOOL_A_PAUSE_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_PAUSE_AUTONEG] = { .type = NLA_REJECT }, [ETHTOOL_A_PAUSE_RX] = { .type = NLA_REJECT }, [ETHTOOL_A_PAUSE_TX] = { .type = NLA_REJECT }, @@ -142,7 +143,8 @@ const struct ethnl_request_ops ethnl_pause_request_ops = { const struct nla_policy ethnl_pause_set_policy[ETHTOOL_A_PAUSE_MAX + 1] = { [ETHTOOL_A_PAUSE_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_PAUSE_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_PAUSE_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_PAUSE_AUTONEG] = { .type = NLA_U8 }, [ETHTOOL_A_PAUSE_RX] = { .type = NLA_U8 }, [ETHTOOL_A_PAUSE_TX] = { .type = NLA_U8 }, diff --git a/net/ethtool/privflags.c b/net/ethtool/privflags.c index f8164e0f2f87..4a77a8a547f7 100644 --- a/net/ethtool/privflags.c +++ b/net/ethtool/privflags.c @@ -21,7 +21,8 @@ struct privflags_reply_data { const struct nla_policy ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1] = { [ETHTOOL_A_PRIVFLAGS_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_PRIVFLAGS_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_PRIVFLAGS_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_PRIVFLAGS_FLAGS] = { .type = NLA_REJECT }, }; @@ -139,7 +140,8 @@ const struct ethnl_request_ops ethnl_privflags_request_ops = { const struct nla_policy ethnl_privflags_set_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1] = { [ETHTOOL_A_PRIVFLAGS_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_PRIVFLAGS_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_PRIVFLAGS_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_PRIVFLAGS_FLAGS] = { .type = NLA_NESTED }, }; diff --git a/net/ethtool/rings.c b/net/ethtool/rings.c index 73ee664f9b0b..142d0902293a 100644 --- a/net/ethtool/rings.c +++ b/net/ethtool/rings.c @@ -17,7 +17,8 @@ struct rings_reply_data { const struct nla_policy ethnl_rings_get_policy[ETHTOOL_A_RINGS_MAX + 1] = { [ETHTOOL_A_RINGS_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_RINGS_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_RINGS_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_RINGS_RX_MAX] = { .type = NLA_REJECT }, [ETHTOOL_A_RINGS_RX_MINI_MAX] = { .type = NLA_REJECT }, [ETHTOOL_A_RINGS_RX_JUMBO_MAX] = { .type = NLA_REJECT }, @@ -109,7 +110,8 @@ const struct ethnl_request_ops ethnl_rings_request_ops = { const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_MAX + 1] = { [ETHTOOL_A_RINGS_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_RINGS_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_RINGS_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_RINGS_RX_MAX] = { .type = NLA_REJECT }, [ETHTOOL_A_RINGS_RX_MINI_MAX] = { .type = NLA_REJECT }, [ETHTOOL_A_RINGS_RX_JUMBO_MAX] = { .type = NLA_REJECT }, diff --git a/net/ethtool/strset.c b/net/ethtool/strset.c index e893f98505d0..8aec735216ca 100644 --- a/net/ethtool/strset.c +++ b/net/ethtool/strset.c @@ -101,7 +101,8 @@ struct strset_reply_data { const struct nla_policy ethnl_strset_get_policy[ETHTOOL_A_STRSET_MAX + 1] = { [ETHTOOL_A_STRSET_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_STRSET_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_STRSET_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_STRSET_STRINGSETS] = { .type = NLA_NESTED }, }; diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c index 185333d377c9..8a26e1620083 100644 --- a/net/ethtool/tsinfo.c +++ b/net/ethtool/tsinfo.c @@ -20,7 +20,8 @@ struct tsinfo_reply_data { const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX + 1] = { [ETHTOOL_A_TSINFO_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_TSINFO_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_TSINFO_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_TSINFO_TIMESTAMPING] = { .type = NLA_REJECT }, [ETHTOOL_A_TSINFO_TX_TYPES] = { .type = NLA_REJECT }, [ETHTOOL_A_TSINFO_RX_FILTERS] = { .type = NLA_REJECT }, diff --git a/net/ethtool/tunnels.c b/net/ethtool/tunnels.c index 330817adcf62..734e12147d34 100644 --- a/net/ethtool/tunnels.c +++ b/net/ethtool/tunnels.c @@ -11,7 +11,8 @@ const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_MAX + 1] = { [ETHTOOL_A_TUNNEL_INFO_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_TUNNEL_INFO_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_TUNNEL_INFO_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), }; static_assert(ETHTOOL_UDP_TUNNEL_TYPE_VXLAN == ilog2(UDP_TUNNEL_TYPE_VXLAN)); diff --git a/net/ethtool/wol.c b/net/ethtool/wol.c index a5f396c8c69a..0e1aa6acb4aa 100644 --- a/net/ethtool/wol.c +++ b/net/ethtool/wol.c @@ -19,7 +19,8 @@ struct wol_reply_data { const struct nla_policy ethnl_wol_get_policy[ETHTOOL_A_WOL_MAX + 1] = { [ETHTOOL_A_WOL_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_WOL_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_WOL_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_WOL_MODES] = { .type = NLA_REJECT }, [ETHTOOL_A_WOL_SOPASS] = { .type = NLA_REJECT }, }; @@ -101,7 +102,8 @@ const struct ethnl_request_ops ethnl_wol_request_ops = { const struct nla_policy ethnl_wol_set_policy[ETHTOOL_A_WOL_MAX + 1] = { [ETHTOOL_A_WOL_UNSPEC] = { .type = NLA_REJECT }, - [ETHTOOL_A_WOL_HEADER] = { .type = NLA_NESTED }, + [ETHTOOL_A_WOL_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy), [ETHTOOL_A_WOL_MODES] = { .type = NLA_NESTED }, [ETHTOOL_A_WOL_SOPASS] = { .type = NLA_BINARY, .len = SOPASS_MAX }, From patchwork Mon Oct 5 15:57:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 268088 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AFE0C4727D for ; Mon, 5 Oct 2020 15:58:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CACAD2075A for ; Mon, 5 Oct 2020 15:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913500; bh=IKqkisEMW4kh5aF7sM5EiUU+zhLKSMln3BEmEgs42Iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=D8cK4j8GroLnsL6JCAIRaP125KV6NSSjRbg6OfNrNb8tQVLIiFlI/yF2bRrCZL1Fi zqq9f99XK53brUqnQ717WrUtdsV56aVWZ6kW1vG0vJabgHJ/BaTnnVJ7DkJ0S0UQ81 WnO2W/DguHI7uHjH1l2xWr8S4QgKD1IOUr3YkMPQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728878AbgJEP6K (ORCPT ); Mon, 5 Oct 2020 11:58:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:56876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728860AbgJEP6I (ORCPT ); Mon, 5 Oct 2020 11:58:08 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C6B2B20B80; Mon, 5 Oct 2020 15:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913488; bh=IKqkisEMW4kh5aF7sM5EiUU+zhLKSMln3BEmEgs42Iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yBJtF2iTZRjDlYQqwgu1iR7VjXzygj4mP5KRIh3M45QhDBrvqnWx33NtCyPRdsPnW VoFerF2LQaqN3Nban/p9ao6Al9IwkCSC0A+As+3cu3ElpWKizNzPvzOHAxiHjPTOQS 2YDrwGYE81KLVWYImVp4N42XXuOZY7J1Gz/rsjqY= From: Jakub Kicinski 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 , dsahern@gmail.com, pablo@netfilter.org Subject: [PATCH net-next 5/6] netlink: add mask validation Date: Mon, 5 Oct 2020 08:57:52 -0700 Message-Id: <20201005155753.2333882-6-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201005155753.2333882-1-kuba@kernel.org> References: <20201005155753.2333882-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We don't have good validation policy for existing unsigned int attrs which serve as flags (for new ones we could use NLA_BITFIELD32). With increased use of policy dumping having the validation be expressed as part of the policy is important. Add validation policy in form of a mask of supported/valid bits. Support u64 in the uAPI to be future-proof, but really for now the embedded mask member can only hold 32 bits, so anything with bit 32+ set will always fail validation. Signed-off-by: Jakub Kicinski Reviewed-by: Johannes Berg --- CC: jiri@resnulli.us CC: dsahern@gmail.com CC: pablo@netfilter.org --- include/net/netlink.h | 11 +++++++++++ include/uapi/linux/netlink.h | 2 ++ lib/nlattr.c | 36 ++++++++++++++++++++++++++++++++++++ net/netlink/policy.c | 8 ++++++++ 4 files changed, 57 insertions(+) diff --git a/include/net/netlink.h b/include/net/netlink.h index 5a5ff97cc596..844b53dbba68 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h @@ -200,6 +200,7 @@ enum nla_policy_validation { NLA_VALIDATE_RANGE_WARN_TOO_LONG, NLA_VALIDATE_MIN, NLA_VALIDATE_MAX, + NLA_VALIDATE_MASK, NLA_VALIDATE_RANGE_PTR, NLA_VALIDATE_FUNCTION, }; @@ -317,6 +318,7 @@ struct nla_policy { u16 len; union { const u32 bitfield32_valid; + const u32 mask; const char *reject_message; const struct nla_policy *nested_policy; struct netlink_range_validation *range; @@ -363,6 +365,9 @@ struct nla_policy { { .type = NLA_BITFIELD32, .bitfield32_valid = valid } #define __NLA_ENSURE(condition) BUILD_BUG_ON_ZERO(!(condition)) +#define NLA_ENSURE_UINT_TYPE(tp) \ + (__NLA_ENSURE(tp == NLA_U8 || tp == NLA_U16 || \ + tp == NLA_U32 || tp == NLA_U64) + tp) #define NLA_ENSURE_UINT_OR_BINARY_TYPE(tp) \ (__NLA_ENSURE(tp == NLA_U8 || tp == NLA_U16 || \ tp == NLA_U32 || tp == NLA_U64 || \ @@ -415,6 +420,12 @@ struct nla_policy { .max = _max, \ } +#define NLA_POLICY_MASK(tp, _mask) { \ + .type = NLA_ENSURE_UINT_TYPE(tp), \ + .validation_type = NLA_VALIDATE_MASK, \ + .mask = _mask, \ +} + #define NLA_POLICY_VALIDATE_FN(tp, fn, ...) { \ .type = NLA_ENSURE_NO_VALIDATION_PTR(tp), \ .validation_type = NLA_VALIDATE_FUNCTION, \ diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h index eac8a6a648ea..d02e472ba54c 100644 --- a/include/uapi/linux/netlink.h +++ b/include/uapi/linux/netlink.h @@ -331,6 +331,7 @@ enum netlink_attribute_type { * the index, if limited inside the nesting (U32) * @NL_POLICY_TYPE_ATTR_BITFIELD32_MASK: valid mask for the * bitfield32 type (U32) + * @NL_POLICY_TYPE_ATTR_MASK: mask of valid bits for unsigned integers (U64) * @NL_POLICY_TYPE_ATTR_PAD: pad attribute for 64-bit alignment */ enum netlink_policy_type_attr { @@ -346,6 +347,7 @@ enum netlink_policy_type_attr { NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE, NL_POLICY_TYPE_ATTR_BITFIELD32_MASK, NL_POLICY_TYPE_ATTR_PAD, + NL_POLICY_TYPE_ATTR_MASK, /* keep last */ __NL_POLICY_TYPE_ATTR_MAX, diff --git a/lib/nlattr.c b/lib/nlattr.c index 80ff9fe83696..9c99f5daa4d2 100644 --- a/lib/nlattr.c +++ b/lib/nlattr.c @@ -323,6 +323,37 @@ static int nla_validate_int_range(const struct nla_policy *pt, } } +static int nla_validate_mask(const struct nla_policy *pt, + const struct nlattr *nla, + struct netlink_ext_ack *extack) +{ + u64 value; + + switch (pt->type) { + case NLA_U8: + value = nla_get_u8(nla); + break; + case NLA_U16: + value = nla_get_u16(nla); + break; + case NLA_U32: + value = nla_get_u32(nla); + break; + case NLA_U64: + value = nla_get_u64(nla); + break; + default: + return -EINVAL; + } + + if (value & ~(u64)pt->mask) { + NL_SET_ERR_MSG_ATTR(extack, nla, "reserved bit set"); + return -EINVAL; + } + + return 0; +} + static int validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *policy, unsigned int validate, struct netlink_ext_ack *extack, unsigned int depth) @@ -503,6 +534,11 @@ static int validate_nla(const struct nlattr *nla, int maxtype, if (err) return err; break; + case NLA_VALIDATE_MASK: + err = nla_validate_mask(pt, nla, extack); + if (err) + return err; + break; case NLA_VALIDATE_FUNCTION: if (pt->validate) { err = pt->validate(nla, extack); diff --git a/net/netlink/policy.c b/net/netlink/policy.c index cf23c0151721..ee26d01328ee 100644 --- a/net/netlink/policy.c +++ b/net/netlink/policy.c @@ -263,6 +263,14 @@ int netlink_policy_dump_write(struct sk_buff *skb, else type = NL_ATTR_TYPE_U64; + if (pt->validation_type == NLA_VALIDATE_MASK) { + if (nla_put_u64_64bit(skb, NL_POLICY_TYPE_ATTR_MASK, + pt->mask, + NL_POLICY_TYPE_ATTR_PAD)) + goto nla_put_failure; + break; + } + nla_get_range_unsigned(pt, &range); if (nla_put_u64_64bit(skb, NL_POLICY_TYPE_ATTR_MIN_VALUE_U, From patchwork Mon Oct 5 15:57:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 288982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58B33C4363A for ; Mon, 5 Oct 2020 15:58:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DEB520663 for ; Mon, 5 Oct 2020 15:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913498; bh=wPbUNIPCYKMciklekBnLyw9B0K8GkwzLZxVJsP2hOPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=DyyuxQaWgu1MKJCCa3rzT5QFpZPAohhgRnfvjCzCMgH6I3QoosxW0F+JBue1O/B1e goyRqoAB/Zk8BEHAsJu72Ktl2G6EyZvfxXjZTEAjGFwgJT/C99Kw2rxkjO6EabDcXs oNvOQl8UwVJZL6SIs78WcX+ykmdxn9+UIrs8y8tU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728913AbgJEP6R (ORCPT ); Mon, 5 Oct 2020 11:58:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:56924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728861AbgJEP6K (ORCPT ); Mon, 5 Oct 2020 11:58:10 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4E03D212CC; Mon, 5 Oct 2020 15:58:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601913488; bh=wPbUNIPCYKMciklekBnLyw9B0K8GkwzLZxVJsP2hOPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i/0eINU1vpN+M7EcEhfd3jy0PrKBRRf+IE34mSND9B7X+mMbB7OSP1IXS0IopHswh AUFp2O4Z98eA2Gy2gnxgE3Eoz4avfiFVfUrWd328aCkJBhz+Y4MgX3Xb7KzaAwf4b3 qvnk0Yu4tZQXlWJsZcTg0DTmlnWMkSrx68lvtYng= From: Jakub Kicinski 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 Subject: [PATCH net-next 6/6] ethtool: specify which header flags are supported per command Date: Mon, 5 Oct 2020 08:57:53 -0700 Message-Id: <20201005155753.2333882-7-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201005155753.2333882-1-kuba@kernel.org> References: <20201005155753.2333882-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.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 --- 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 },