File netlink-add-netlink-handler-for-sprivflags-set-priv-.patch of Package ethtool

From: Michal Kubecek <mkubecek@suse.cz>
Date: Fri, 7 Sep 2018 14:23:10 +0200
Subject: netlink: add netlink handler for sprivflags
 (--set-priv-flags)
Patch-mainline: Not yet, work in progress
References: none

Implement "ethtool --set-priv-flags <dev>" subcommand using netlink
interface command ETHNL_CMD_SET_SETTINGS.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 ethtool.c          |  3 ++-
 netlink/extapi.h   |  1 +
 netlink/settings.c | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/ethtool.c b/ethtool.c
index 67e8c4512639..a9e91efd9bd0 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4859,6 +4859,7 @@ static int show_usage(struct cmd_context *ctx);
 #define nl_phys_id	NULL
 #define nl_reset	NULL
 #define nl_gprivflags	NULL
+#define nl_sprivflags	NULL
 #endif
 
 static const struct option {
@@ -5020,7 +5021,7 @@ static const struct option {
 	  "               [ combined N ]\n" },
 	{ "--show-priv-flags", 1, do_gprivflags, nl_gprivflags,
 	  "Query private flags" },
-	{ "--set-priv-flags", 1, do_sprivflags, NULL,
+	{ "--set-priv-flags", 1, do_sprivflags, nl_sprivflags,
 	  "Set private flags",
 	  "		FLAG on|off ...\n" },
 	{ "-m|--dump-module-eeprom|--module-info", 1, do_getmodule, NULL,
diff --git a/netlink/extapi.h b/netlink/extapi.h
index a9820609f3b8..cfef7baf923f 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -36,6 +36,7 @@ int nl_nway_rst(struct cmd_context *ctx);
 int nl_phys_id(struct cmd_context *ctx);
 int nl_reset(struct cmd_context *ctx);
 int nl_gprivflags(struct cmd_context *ctx);
+int nl_sprivflags(struct cmd_context *ctx);
 int nl_monitor(struct cmd_context *ctx);
 
 void monitor_usage();
diff --git a/netlink/settings.c b/netlink/settings.c
index 8c1e60a47085..185c54294387 100644
--- a/netlink/settings.c
+++ b/netlink/settings.c
@@ -1098,3 +1098,36 @@ int nl_sfeatures(struct cmd_context *ctx)
 		return 0;
 	return nlctx->exit_code ?: 92;
 }
+
+/* private flags */
+
+int nl_sprivflags(struct cmd_context *ctx)
+{
+	struct nl_context *nlctx = ctx->nlctx;
+	int ret;
+
+	nlctx->cmd = "--set-priv-flags";
+	nlctx->argp = ctx->argp;
+	nlctx->argc = ctx->argc;
+	nlctx->devname = ctx->devname;
+
+	ret = msg_init(nlctx, ETHNL_CMD_SET_SETTINGS,
+		       NLM_F_REQUEST | NLM_F_ACK);
+	if (ret < 0)
+		return 2;
+	if (ethnla_put_dev(nlctx, ETHA_SETTINGS_DEV, ctx->devname))
+		return -EMSGSIZE;
+
+	ret = nl_parse_bitset(nlctx, ETHA_SETTINGS_PRIV_FLAGS, NULL, NULL);
+	if (ret < 0)
+		return -EINVAL;
+
+	ret = ethnl_sendmsg(nlctx);
+	if (ret < 0)
+		return 2;
+	ret = ethnl_process_reply(nlctx, nomsg_reply_cb);
+	if (ret == 0)
+		return 0;
+	else
+		return nlctx->exit_code ?: 1;
+}
-- 
2.19.0