Commit 4f30974f authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller
Browse files

ethtool: wire up get policies to ops



Wire up policies for get commands in struct nla_policy of the ethtool
family. Make use of genetlink code attr validation and parsing, as well
as allow dumping policies to user space.

For every ETHTOOL_MSG_*_GET:
 - add 'ethnl_' prefix to policy name
 - add extern declaration in net/ethtool/netlink.h
 - wire up the policy & attr in ethtool_genl_ops[].
 - remove .request_policy and .max_attr from ethnl_request_ops.

Obviously core only records the first "layer" of parsed attrs
so we still need to parse the sub-attrs of the nested header
attribute.

v2:
 - merge of patches 1 and 2 from v1
 - remove stray empty lines in ops
 - also remove .max_attr

Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 02da0b61
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -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 },
@@ -99,10 +99,8 @@ const struct ethnl_request_ops ethnl_channels_request_ops = {
	.request_cmd		= ETHTOOL_MSG_CHANNELS_GET,
	.reply_cmd		= ETHTOOL_MSG_CHANNELS_GET_REPLY,
	.hdr_attr		= ETHTOOL_A_CHANNELS_HEADER,
	.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,

	.prepare_data		= channels_prepare_data,
	.reply_size		= channels_reply_size,
+2 −4
Original line number Diff line number Diff line
@@ -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 },
@@ -203,10 +203,8 @@ const struct ethnl_request_ops ethnl_coalesce_request_ops = {
	.request_cmd		= ETHTOOL_MSG_COALESCE_GET,
	.reply_cmd		= ETHTOOL_MSG_COALESCE_GET_REPLY,
	.hdr_attr		= ETHTOOL_A_COALESCE_HEADER,
	.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,

	.prepare_data		= coalesce_prepare_data,
	.reply_size		= coalesce_reply_size,
+1 −4
Original line number Diff line number Diff line
@@ -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 },
@@ -69,10 +68,8 @@ const struct ethnl_request_ops ethnl_debug_request_ops = {
	.request_cmd		= ETHTOOL_MSG_DEBUG_GET,
	.reply_cmd		= ETHTOOL_MSG_DEBUG_GET_REPLY,
	.hdr_attr		= ETHTOOL_A_DEBUG_HEADER,
	.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,

	.prepare_data		= debug_prepare_data,
	.reply_size		= debug_reply_size,
+1 −4
Original line number Diff line number Diff line
@@ -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 },
@@ -119,10 +118,8 @@ const struct ethnl_request_ops ethnl_eee_request_ops = {
	.request_cmd		= ETHTOOL_MSG_EEE_GET,
	.reply_cmd		= ETHTOOL_MSG_EEE_GET_REPLY,
	.hdr_attr		= ETHTOOL_A_EEE_HEADER,
	.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,

	.prepare_data		= eee_prepare_data,
	.reply_size		= eee_reply_size,
+2 −4
Original line number Diff line number Diff line
@@ -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 },
@@ -120,10 +120,8 @@ const struct ethnl_request_ops ethnl_features_request_ops = {
	.request_cmd		= ETHTOOL_MSG_FEATURES_GET,
	.reply_cmd		= ETHTOOL_MSG_FEATURES_GET_REPLY,
	.hdr_attr		= ETHTOOL_A_FEATURES_HEADER,
	.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,

	.prepare_data		= features_prepare_data,
	.reply_size		= features_reply_size,
Loading