diff options
author | Michal Kubecek <mkubecek@suse.cz> | 2020-05-29 01:22:18 +0200 |
---|---|---|
committer | Michal Kubecek <mkubecek@suse.cz> | 2020-06-07 19:11:06 +0200 |
commit | dd3ab0945d33fa3170d6b6806805bc974ba3e426 (patch) | |
tree | 4c83dfb7bbd80f2e1d58e5ee8d57d6ca1da2aa9c | |
parent | a3f56ba616ed2279e87db58ae82526529428bcb5 (diff) | |
download | ethtool-dd3ab0945d33fa3170d6b6806805bc974ba3e426.tar.gz |
netlink: add netlink handler for schannels (-L)
Implement "ethtool -L <dev> ..." subcommand to set network device channel
counts using ETHTOOL_MSG_CHANNELS_SET netlink message. These are
traditionally set using ETHTOOL_SCHANNELS ioctl request.
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
-rw-r--r-- | ethtool.c | 1 | ||||
-rw-r--r-- | netlink/channels.c | 72 | ||||
-rw-r--r-- | netlink/extapi.h | 2 |
3 files changed, 74 insertions, 1 deletions
@@ -5371,6 +5371,7 @@ static const struct option args[] = { { .opts = "-L|--set-channels", .func = do_schannels, + .nlfunc = nl_schannels, .help = "Set Channels", .xhelp = " [ rx N ]\n" " [ tx N ]\n" diff --git a/netlink/channels.c b/netlink/channels.c index ddea17b..c6002ce 100644 --- a/netlink/channels.c +++ b/netlink/channels.c @@ -1,7 +1,7 @@ /* * channels.c - netlink implementation of channel commands * - * Implementation of "ethtool -l <dev>" + * Implementation of "ethtool -l <dev>" and "ethtool -L <dev> ..." */ #include <errno.h> @@ -11,6 +11,7 @@ #include "../internal.h" #include "../common.h" #include "netlink.h" +#include "parser.h" /* CHANNELS_GET */ @@ -69,3 +70,72 @@ int nl_gchannels(struct cmd_context *ctx) return ret; return nlsock_send_get_request(nlsk, channels_reply_cb); } + +/* CHANNELS_SET */ + +static const struct param_parser schannels_params[] = { + { + .arg = "rx", + .type = ETHTOOL_A_CHANNELS_RX_COUNT, + .handler = nl_parse_direct_u32, + .min_argc = 1, + }, + { + .arg = "tx", + .type = ETHTOOL_A_CHANNELS_TX_COUNT, + .handler = nl_parse_direct_u32, + .min_argc = 1, + }, + { + .arg = "other", + .type = ETHTOOL_A_CHANNELS_OTHER_COUNT, + .handler = nl_parse_direct_u32, + .min_argc = 1, + }, + { + .arg = "combined", + .type = ETHTOOL_A_CHANNELS_COMBINED_COUNT, + .handler = nl_parse_direct_u32, + .min_argc = 1, + }, + {} +}; + +int nl_schannels(struct cmd_context *ctx) +{ + struct nl_context *nlctx = ctx->nlctx; + struct nl_msg_buff *msgbuff; + struct nl_socket *nlsk; + int ret; + + if (netlink_cmd_check(ctx, ETHTOOL_MSG_CHANNELS_SET, false)) + return -EOPNOTSUPP; + + nlctx->cmd = "-L"; + nlctx->argp = ctx->argp; + nlctx->argc = ctx->argc; + nlctx->devname = ctx->devname; + nlsk = nlctx->ethnl_socket; + msgbuff = &nlsk->msgbuff; + + ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_CHANNELS_SET, + NLM_F_REQUEST | NLM_F_ACK); + if (ret < 0) + return 2; + if (ethnla_fill_header(msgbuff, ETHTOOL_A_CHANNELS_HEADER, + ctx->devname, 0)) + return -EMSGSIZE; + + ret = nl_parser(nlctx, schannels_params, NULL, PARSER_GROUP_NONE); + if (ret < 0) + return 1; + + ret = nlsock_sendmsg(nlsk, NULL); + if (ret < 0) + return 1; + ret = nlsock_process_reply(nlsk, nomsg_reply_cb, nlctx); + if (ret == 0) + return 0; + else + return nlctx->exit_code ?: 1; +} diff --git a/netlink/extapi.h b/netlink/extapi.h index 9438dcd..9cea57a 100644 --- a/netlink/extapi.h +++ b/netlink/extapi.h @@ -27,6 +27,7 @@ int nl_sprivflags(struct cmd_context *ctx); int nl_gring(struct cmd_context *ctx); int nl_sring(struct cmd_context *ctx); int nl_gchannels(struct cmd_context *ctx); +int nl_schannels(struct cmd_context *ctx); int nl_monitor(struct cmd_context *ctx); void nl_monitor_usage(void); @@ -58,6 +59,7 @@ static inline void nl_monitor_usage(void) #define nl_gring NULL #define nl_sring NULL #define nl_gchannels NULL +#define nl_schannels NULL #endif /* ETHTOOL_ENABLE_NETLINK */ |