lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 18 Oct 2020 14:31:49 -0700
From:   Jakub Kicinski <kuba@...nel.org>
To:     mkubecek@...e.cz
Cc:     netdev@...r.kernel.org, kernel-team@...com, idosch@...sch.org,
        Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH ethtool v3 5/7] netlink: prepare for more per-op info

We stored an array of op flags, to check if operations are
supported. Make that array a structure rather than plain
uint32_t in preparation for storing more state.

v3: new patch

Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
 netlink/netlink.c | 25 +++++++++++++------------
 netlink/netlink.h |  6 +++++-
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/netlink/netlink.c b/netlink/netlink.c
index e42d57076a4b..86dc1efdf5ce 100644
--- a/netlink/netlink.c
+++ b/netlink/netlink.c
@@ -120,19 +120,19 @@ bool netlink_cmd_check(struct cmd_context *ctx, unsigned int cmd,
 		nlctx->wildcard_unsupported = true;
 		return true;
 	}
-	if (!nlctx->ops_flags) {
+	if (!nlctx->ops_info) {
 		nlctx->ioctl_fallback = true;
 		return false;
 	}
-	if (cmd > ETHTOOL_MSG_USER_MAX || !nlctx->ops_flags[cmd]) {
+	if (cmd > ETHTOOL_MSG_USER_MAX || !nlctx->ops_info[cmd].op_flags) {
 		nlctx->ioctl_fallback = true;
 		return true;
 	}
 
-	if (is_dump && !(nlctx->ops_flags[cmd] & GENL_CMD_CAP_DUMP))
+	if (is_dump && !(nlctx->ops_info[cmd].op_flags & GENL_CMD_CAP_DUMP))
 		nlctx->wildcard_unsupported = true;
 
-	return !(nlctx->ops_flags[cmd] & cap);
+	return !(nlctx->ops_info[cmd].op_flags & cap);
 }
 
 /* initialization */
@@ -140,12 +140,12 @@ bool netlink_cmd_check(struct cmd_context *ctx, unsigned int cmd,
 static int genl_read_ops(struct nl_context *nlctx,
 			 const struct nlattr *ops_attr)
 {
+	struct nl_op_info *ops_info;
 	struct nlattr *op_attr;
-	uint32_t *ops_flags;
 	int ret;
 
-	ops_flags = calloc(__ETHTOOL_MSG_USER_CNT, sizeof(ops_flags[0]));
-	if (!ops_flags)
+	ops_info = calloc(__ETHTOOL_MSG_USER_CNT, sizeof(ops_info[0]));
+	if (!ops_info)
 		return -ENOMEM;
 
 	mnl_attr_for_each_nested(op_attr, ops_attr) {
@@ -163,13 +163,14 @@ static int genl_read_ops(struct nl_context *nlctx,
 		if (op_id >= __ETHTOOL_MSG_USER_CNT)
 			continue;
 
-		ops_flags[op_id] = mnl_attr_get_u32(tb[CTRL_ATTR_OP_FLAGS]);
+		ops_info[op_id].op_flags =
+			mnl_attr_get_u32(tb[CTRL_ATTR_OP_FLAGS]);
 	}
 
-	nlctx->ops_flags = ops_flags;
+	nlctx->ops_info = ops_info;
 	return 0;
 err:
-	free(ops_flags);
+	free(ops_info);
 	return ret;
 }
 
@@ -273,7 +274,7 @@ int netlink_init(struct cmd_context *ctx)
 out_nlsk:
 	nlsock_done(nlctx->ethnl_socket);
 out_free:
-	free(nlctx->ops_flags);
+	free(nlctx->ops_info);
 	free(nlctx);
 	return ret;
 }
@@ -283,7 +284,7 @@ static void netlink_done(struct cmd_context *ctx)
 	if (!ctx->nlctx)
 		return;
 
-	free(ctx->nlctx->ops_flags);
+	free(ctx->nlctx->ops_info);
 	free(ctx->nlctx);
 	ctx->nlctx = NULL;
 	cleanup_all_strings();
diff --git a/netlink/netlink.h b/netlink/netlink.h
index 1012e8e32cd8..e79143016bd5 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -25,6 +25,10 @@ enum link_mode_class {
 	LM_CLASS_FEC,
 };
 
+struct nl_op_info {
+	uint32_t		op_flags;
+};
+
 struct nl_context {
 	struct cmd_context	*ctx;
 	void			*cmd_private;
@@ -34,7 +38,7 @@ struct nl_context {
 	unsigned int		suppress_nlerr;
 	uint16_t		ethnl_fam;
 	uint32_t		ethnl_mongrp;
-	uint32_t		*ops_flags;
+	struct nl_op_info	*ops_info;
 	struct nl_socket	*ethnl_socket;
 	struct nl_socket	*ethnl2_socket;
 	struct nl_socket	*rtnl_socket;
-- 
2.26.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ