aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2020-10-18 14:31:49 -0700
committerMichal Kubecek <mkubecek@suse.cz>2020-10-19 09:45:55 +0200
commit8d36270be3c06b99eba281ccf341ebfab555c6b6 (patch)
tree2622f5e592502959a30c2cbeaff77a4efcb76123
parent66ecd38ca8b4e6184af4c38c234a9dcfb6804a4a (diff)
downloadethtool-8d36270be3c06b99eba281ccf341ebfab555c6b6.tar.gz
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@kernel.org> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
-rw-r--r--netlink/netlink.c25
-rw-r--r--netlink/netlink.h6
2 files changed, 18 insertions, 13 deletions
diff --git a/netlink/netlink.c b/netlink/netlink.c
index e42d570..86dc1ef 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 1012e8e..e791430 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;