ethtool: wire up get policies to ops
Wire up policies for get commands in struct nla_policy of the ethtool family. Make use of genetlink code attr validation and parsing, as well as allow dumping policies to user space. For every ETHTOOL_MSG_*_GET: - add 'ethnl_' prefix to policy name - add extern declaration in net/ethtool/netlink.h - wire up the policy & attr in ethtool_genl_ops[]. - remove .request_policy and .max_attr from ethnl_request_ops. Obviously core only records the first "layer" of parsed attrs so we still need to parse the sub-attrs of the nested header attribute. v2: - merge of patches 1 and 2 from v1 - remove stray empty lines in ops - also remove .max_attr Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
02da0b615b
commit
4f30974feb
@@ -8,8 +8,8 @@
|
||||
#include "common.h"
|
||||
#include "netlink.h"
|
||||
|
||||
static const struct nla_policy
|
||||
ethtool_tunnel_info_policy[ETHTOOL_A_TUNNEL_INFO_MAX + 1] = {
|
||||
const struct nla_policy
|
||||
ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_MAX + 1] = {
|
||||
[ETHTOOL_A_TUNNEL_INFO_UNSPEC] = { .type = NLA_REJECT },
|
||||
[ETHTOOL_A_TUNNEL_INFO_HEADER] = { .type = NLA_NESTED },
|
||||
};
|
||||
@@ -161,35 +161,19 @@ err_cancel_ports:
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
static int
|
||||
ethnl_tunnel_info_req_parse(struct ethnl_req_info *req_info,
|
||||
const struct nlmsghdr *nlhdr, struct net *net,
|
||||
struct netlink_ext_ack *extack, bool require_dev)
|
||||
{
|
||||
struct nlattr *tb[ETHTOOL_A_TUNNEL_INFO_MAX + 1];
|
||||
int ret;
|
||||
|
||||
ret = nlmsg_parse(nlhdr, GENL_HDRLEN, tb, ETHTOOL_A_TUNNEL_INFO_MAX,
|
||||
ethtool_tunnel_info_policy, extack);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return ethnl_parse_header_dev_get(req_info,
|
||||
tb[ETHTOOL_A_TUNNEL_INFO_HEADER],
|
||||
net, extack, require_dev);
|
||||
}
|
||||
|
||||
int ethnl_tunnel_info_doit(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct ethnl_req_info req_info = {};
|
||||
struct nlattr **tb = info->attrs;
|
||||
struct sk_buff *rskb;
|
||||
void *reply_payload;
|
||||
int reply_len;
|
||||
int ret;
|
||||
|
||||
ret = ethnl_tunnel_info_req_parse(&req_info, info->nlhdr,
|
||||
genl_info_net(info), info->extack,
|
||||
true);
|
||||
ret = ethnl_parse_header_dev_get(&req_info,
|
||||
tb[ETHTOOL_A_TUNNEL_INFO_HEADER],
|
||||
genl_info_net(info), info->extack,
|
||||
true);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -233,16 +217,19 @@ struct ethnl_tunnel_info_dump_ctx {
|
||||
|
||||
int ethnl_tunnel_info_start(struct netlink_callback *cb)
|
||||
{
|
||||
const struct genl_dumpit_info *info = genl_dumpit_info(cb);
|
||||
struct ethnl_tunnel_info_dump_ctx *ctx = (void *)cb->ctx;
|
||||
struct nlattr **tb = info->attrs;
|
||||
int ret;
|
||||
|
||||
BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ret = ethnl_tunnel_info_req_parse(&ctx->req_info, cb->nlh,
|
||||
sock_net(cb->skb->sk), cb->extack,
|
||||
false);
|
||||
ret = ethnl_parse_header_dev_get(&ctx->req_info,
|
||||
tb[ETHTOOL_A_TUNNEL_INFO_HEADER],
|
||||
sock_net(cb->skb->sk), cb->extack,
|
||||
false);
|
||||
if (ctx->req_info.dev) {
|
||||
dev_put(ctx->req_info.dev);
|
||||
ctx->req_info.dev = NULL;
|
||||
|
||||
Reference in New Issue
Block a user