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