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

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