Blame SOURCES/0022-netlink-prepare-for-more-per-op-info.patch

c96cf6
From 15e57173470b0929fd649bc7b0376d41c786ddbe Mon Sep 17 00:00:00 2001
c96cf6
From: Jakub Kicinski <kuba@kernel.org>
c96cf6
Date: Sun, 18 Oct 2020 14:31:49 -0700
c96cf6
Subject: [PATCH 22/26] netlink: prepare for more per-op info
c96cf6
c96cf6
We stored an array of op flags, to check if operations are
c96cf6
supported. Make that array a structure rather than plain
c96cf6
uint32_t in preparation for storing more state.
c96cf6
c96cf6
v3: new patch
c96cf6
c96cf6
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
c96cf6
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
c96cf6
(cherry picked from commit 8d36270be3c06b99eba281ccf341ebfab555c6b6)
c96cf6
---
c96cf6
 netlink/netlink.c | 25 +++++++++++++------------
c96cf6
 netlink/netlink.h |  6 +++++-
c96cf6
 2 files changed, 18 insertions(+), 13 deletions(-)
c96cf6
c96cf6
diff --git a/netlink/netlink.c b/netlink/netlink.c
c96cf6
index e42d57076a4b..86dc1efdf5ce 100644
c96cf6
--- a/netlink/netlink.c
c96cf6
+++ b/netlink/netlink.c
c96cf6
@@ -120,19 +120,19 @@ bool netlink_cmd_check(struct cmd_context *ctx, unsigned int cmd,
c96cf6
 		nlctx->wildcard_unsupported = true;
c96cf6
 		return true;
c96cf6
 	}
c96cf6
-	if (!nlctx->ops_flags) {
c96cf6
+	if (!nlctx->ops_info) {
c96cf6
 		nlctx->ioctl_fallback = true;
c96cf6
 		return false;
c96cf6
 	}
c96cf6
-	if (cmd > ETHTOOL_MSG_USER_MAX || !nlctx->ops_flags[cmd]) {
c96cf6
+	if (cmd > ETHTOOL_MSG_USER_MAX || !nlctx->ops_info[cmd].op_flags) {
c96cf6
 		nlctx->ioctl_fallback = true;
c96cf6
 		return true;
c96cf6
 	}
c96cf6
 
c96cf6
-	if (is_dump && !(nlctx->ops_flags[cmd] & GENL_CMD_CAP_DUMP))
c96cf6
+	if (is_dump && !(nlctx->ops_info[cmd].op_flags & GENL_CMD_CAP_DUMP))
c96cf6
 		nlctx->wildcard_unsupported = true;
c96cf6
 
c96cf6
-	return !(nlctx->ops_flags[cmd] & cap);
c96cf6
+	return !(nlctx->ops_info[cmd].op_flags & cap);
c96cf6
 }
c96cf6
 
c96cf6
 /* initialization */
c96cf6
@@ -140,12 +140,12 @@ bool netlink_cmd_check(struct cmd_context *ctx, unsigned int cmd,
c96cf6
 static int genl_read_ops(struct nl_context *nlctx,
c96cf6
 			 const struct nlattr *ops_attr)
c96cf6
 {
c96cf6
+	struct nl_op_info *ops_info;
c96cf6
 	struct nlattr *op_attr;
c96cf6
-	uint32_t *ops_flags;
c96cf6
 	int ret;
c96cf6
 
c96cf6
-	ops_flags = calloc(__ETHTOOL_MSG_USER_CNT, sizeof(ops_flags[0]));
c96cf6
-	if (!ops_flags)
c96cf6
+	ops_info = calloc(__ETHTOOL_MSG_USER_CNT, sizeof(ops_info[0]));
c96cf6
+	if (!ops_info)
c96cf6
 		return -ENOMEM;
c96cf6
 
c96cf6
 	mnl_attr_for_each_nested(op_attr, ops_attr) {
c96cf6
@@ -163,13 +163,14 @@ static int genl_read_ops(struct nl_context *nlctx,
c96cf6
 		if (op_id >= __ETHTOOL_MSG_USER_CNT)
c96cf6
 			continue;
c96cf6
 
c96cf6
-		ops_flags[op_id] = mnl_attr_get_u32(tb[CTRL_ATTR_OP_FLAGS]);
c96cf6
+		ops_info[op_id].op_flags =
c96cf6
+			mnl_attr_get_u32(tb[CTRL_ATTR_OP_FLAGS]);
c96cf6
 	}
c96cf6
 
c96cf6
-	nlctx->ops_flags = ops_flags;
c96cf6
+	nlctx->ops_info = ops_info;
c96cf6
 	return 0;
c96cf6
 err:
c96cf6
-	free(ops_flags);
c96cf6
+	free(ops_info);
c96cf6
 	return ret;
c96cf6
 }
c96cf6
 
c96cf6
@@ -273,7 +274,7 @@ int netlink_init(struct cmd_context *ctx)
c96cf6
 out_nlsk:
c96cf6
 	nlsock_done(nlctx->ethnl_socket);
c96cf6
 out_free:
c96cf6
-	free(nlctx->ops_flags);
c96cf6
+	free(nlctx->ops_info);
c96cf6
 	free(nlctx);
c96cf6
 	return ret;
c96cf6
 }
c96cf6
@@ -283,7 +284,7 @@ static void netlink_done(struct cmd_context *ctx)
c96cf6
 	if (!ctx->nlctx)
c96cf6
 		return;
c96cf6
 
c96cf6
-	free(ctx->nlctx->ops_flags);
c96cf6
+	free(ctx->nlctx->ops_info);
c96cf6
 	free(ctx->nlctx);
c96cf6
 	ctx->nlctx = NULL;
c96cf6
 	cleanup_all_strings();
c96cf6
diff --git a/netlink/netlink.h b/netlink/netlink.h
c96cf6
index dd4a02bcc916..61a072db8ed9 100644
c96cf6
--- a/netlink/netlink.h
c96cf6
+++ b/netlink/netlink.h
c96cf6
@@ -25,6 +25,10 @@ enum link_mode_class {
c96cf6
 	LM_CLASS_FEC,
c96cf6
 };
c96cf6
 
c96cf6
+struct nl_op_info {
c96cf6
+	uint32_t		op_flags;
c96cf6
+};
c96cf6
+
c96cf6
 struct nl_context {
c96cf6
 	struct cmd_context	*ctx;
c96cf6
 	void			*cmd_private;
c96cf6
@@ -34,7 +38,7 @@ struct nl_context {
c96cf6
 	unsigned int		suppress_nlerr;
c96cf6
 	uint16_t		ethnl_fam;
c96cf6
 	uint32_t		ethnl_mongrp;
c96cf6
-	uint32_t		*ops_flags;
c96cf6
+	struct nl_op_info	*ops_info;
c96cf6
 	struct nl_socket	*ethnl_socket;
c96cf6
 	struct nl_socket	*ethnl2_socket;
c96cf6
 	struct nl_socket	*rtnl_socket;
c96cf6
-- 
c96cf6
2.26.2
c96cf6