Commit bf813b0a authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: genetlink: parse attrs and store in contect info struct during dumpit

Extend the dumpit info struct for attrs. Instead of existing attribute
validation do parse them and save in the info struct. Caller can benefit
from this and does not have to do parse itself. In order to properly
free attrs, genl_family pointer needs to be added to dumpit info struct
as well.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c10e6cf8
...@@ -129,10 +129,14 @@ enum genl_validate_flags { ...@@ -129,10 +129,14 @@ enum genl_validate_flags {
/** /**
* struct genl_info - info that is available during dumpit op call * struct genl_info - info that is available during dumpit op call
* @family: generic netlink family - for internal genl code usage
* @ops: generic netlink ops - for internal genl code usage * @ops: generic netlink ops - for internal genl code usage
* @attrs: netlink attributes
*/ */
struct genl_dumpit_info { struct genl_dumpit_info {
const struct genl_family *family;
const struct genl_ops *ops; const struct genl_ops *ops;
struct nlattr **attrs;
}; };
static inline const struct genl_dumpit_info * static inline const struct genl_dumpit_info *
......
...@@ -542,6 +542,7 @@ static int genl_lock_done(struct netlink_callback *cb) ...@@ -542,6 +542,7 @@ static int genl_lock_done(struct netlink_callback *cb)
rc = ops->done(cb); rc = ops->done(cb);
genl_unlock(); genl_unlock();
} }
genl_family_rcv_msg_attrs_free(info->family, info->attrs);
genl_dumpit_info_free(info); genl_dumpit_info_free(info);
return rc; return rc;
} }
...@@ -554,6 +555,7 @@ static int genl_parallel_done(struct netlink_callback *cb) ...@@ -554,6 +555,7 @@ static int genl_parallel_done(struct netlink_callback *cb)
if (ops->done) if (ops->done)
rc = ops->done(cb); rc = ops->done(cb);
genl_family_rcv_msg_attrs_free(info->family, info->attrs);
genl_dumpit_info_free(info); genl_dumpit_info_free(info);
return rc; return rc;
} }
...@@ -566,35 +568,38 @@ static int genl_family_rcv_msg_dumpit(const struct genl_family *family, ...@@ -566,35 +568,38 @@ static int genl_family_rcv_msg_dumpit(const struct genl_family *family,
int hdrlen, struct net *net) int hdrlen, struct net *net)
{ {
struct genl_dumpit_info *info; struct genl_dumpit_info *info;
struct nlattr **attrs = NULL;
int err; int err;
if (!ops->dumpit) if (!ops->dumpit)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!(ops->validate & GENL_DONT_VALIDATE_DUMP)) { if (ops->validate & GENL_DONT_VALIDATE_DUMP)
if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) goto no_attrs;
return -EINVAL;
if (family->maxattr) { if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
unsigned int validate = NL_VALIDATE_STRICT; return -EINVAL;
if (ops->validate & GENL_DONT_VALIDATE_DUMP_STRICT) if (!family->maxattr)
validate = NL_VALIDATE_LIBERAL; goto no_attrs;
err = __nla_validate(nlmsg_attrdata(nlh, hdrlen),
nlmsg_attrlen(nlh, hdrlen),
family->maxattr, family->policy,
validate, extack);
if (err)
return err;
}
}
attrs = genl_family_rcv_msg_attrs_parse(family, nlh, extack,
ops, hdrlen,
GENL_DONT_VALIDATE_DUMP_STRICT);
if (IS_ERR(attrs))
return PTR_ERR(attrs);
no_attrs:
/* Allocate dumpit info. It is going to be freed by done() callback. */ /* Allocate dumpit info. It is going to be freed by done() callback. */
info = genl_dumpit_info_alloc(); info = genl_dumpit_info_alloc();
if (!info) if (!info) {
genl_family_rcv_msg_attrs_free(family, attrs);
return -ENOMEM; return -ENOMEM;
}
info->family = family;
info->ops = ops; info->ops = ops;
info->attrs = attrs;
if (!family->parallel_ops) { if (!family->parallel_ops) {
struct netlink_dump_control c = { struct netlink_dump_control c = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment