Commit 5c670a01 authored by Jakub Kicinski's avatar Jakub Kicinski

genetlink: add a family pointer to struct genl_info

Having family in struct genl_info is quite useful. It cuts
down the number of arguments which need to be passed to
helpers which already take struct genl_info.
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20230814214723.2924989-7-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 7288dd2f
...@@ -93,6 +93,7 @@ struct genl_family { ...@@ -93,6 +93,7 @@ struct genl_family {
* struct genl_info - receiving information * struct genl_info - receiving information
* @snd_seq: sending sequence number * @snd_seq: sending sequence number
* @snd_portid: netlink portid of sender * @snd_portid: netlink portid of sender
* @family: generic netlink family
* @nlhdr: netlink message header * @nlhdr: netlink message header
* @genlhdr: generic netlink message header * @genlhdr: generic netlink message header
* @attrs: netlink attributes * @attrs: netlink attributes
...@@ -103,6 +104,7 @@ struct genl_family { ...@@ -103,6 +104,7 @@ struct genl_family {
struct genl_info { struct genl_info {
u32 snd_seq; u32 snd_seq;
u32 snd_portid; u32 snd_portid;
const struct genl_family *family;
const struct nlmsghdr * nlhdr; const struct nlmsghdr * nlhdr;
struct genlmsghdr * genlhdr; struct genlmsghdr * genlhdr;
struct nlattr ** attrs; struct nlattr ** attrs;
...@@ -247,13 +249,11 @@ struct genl_split_ops { ...@@ -247,13 +249,11 @@ struct genl_split_ops {
/** /**
* struct genl_dumpit_info - info that is available during dumpit op call * struct genl_dumpit_info - info that is available during dumpit op call
* @family: generic netlink family - for internal genl code usage
* @op: generic netlink ops - for internal genl code usage * @op: generic netlink ops - for internal genl code usage
* @attrs: netlink attributes * @attrs: netlink attributes
* @info: struct genl_info describing the request * @info: struct genl_info describing the request
*/ */
struct genl_dumpit_info { struct genl_dumpit_info {
const struct genl_family *family;
struct genl_split_ops op; struct genl_split_ops op;
struct genl_info info; struct genl_info info;
}; };
......
...@@ -844,8 +844,8 @@ static int genl_start(struct netlink_callback *cb) ...@@ -844,8 +844,8 @@ static int genl_start(struct netlink_callback *cb)
genl_family_rcv_msg_attrs_free(attrs); genl_family_rcv_msg_attrs_free(attrs);
return -ENOMEM; return -ENOMEM;
} }
info->family = ctx->family;
info->op = *ops; info->op = *ops;
info->info.family = ctx->family;
info->info.snd_seq = cb->nlh->nlmsg_seq; info->info.snd_seq = cb->nlh->nlmsg_seq;
info->info.snd_portid = NETLINK_CB(cb->skb).portid; info->info.snd_portid = NETLINK_CB(cb->skb).portid;
info->info.nlhdr = cb->nlh; info->info.nlhdr = cb->nlh;
...@@ -872,11 +872,12 @@ static int genl_start(struct netlink_callback *cb) ...@@ -872,11 +872,12 @@ static int genl_start(struct netlink_callback *cb)
static int genl_dumpit(struct sk_buff *skb, struct netlink_callback *cb) static int genl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
{ {
struct genl_dumpit_info *info = cb->data; struct genl_dumpit_info *dump_info = cb->data;
const struct genl_split_ops *ops = &info->op; const struct genl_split_ops *ops = &dump_info->op;
struct genl_info *info = &dump_info->info;
int rc; int rc;
info->info.extack = cb->extack; info->extack = cb->extack;
genl_op_lock(info->family); genl_op_lock(info->family);
rc = ops->dumpit(skb, cb); rc = ops->dumpit(skb, cb);
...@@ -886,19 +887,20 @@ static int genl_dumpit(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -886,19 +887,20 @@ static int genl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
static int genl_done(struct netlink_callback *cb) static int genl_done(struct netlink_callback *cb)
{ {
struct genl_dumpit_info *info = cb->data; struct genl_dumpit_info *dump_info = cb->data;
const struct genl_split_ops *ops = &info->op; const struct genl_split_ops *ops = &dump_info->op;
struct genl_info *info = &dump_info->info;
int rc = 0; int rc = 0;
info->info.extack = cb->extack; info->extack = cb->extack;
if (ops->done) { if (ops->done) {
genl_op_lock(info->family); genl_op_lock(info->family);
rc = ops->done(cb); rc = ops->done(cb);
genl_op_unlock(info->family); genl_op_unlock(info->family);
} }
genl_family_rcv_msg_attrs_free(info->info.attrs); genl_family_rcv_msg_attrs_free(info->attrs);
genl_dumpit_info_free(info); genl_dumpit_info_free(dump_info);
return rc; return rc;
} }
...@@ -952,6 +954,7 @@ static int genl_family_rcv_msg_doit(const struct genl_family *family, ...@@ -952,6 +954,7 @@ static int genl_family_rcv_msg_doit(const struct genl_family *family,
info.snd_seq = nlh->nlmsg_seq; info.snd_seq = nlh->nlmsg_seq;
info.snd_portid = NETLINK_CB(skb).portid; info.snd_portid = NETLINK_CB(skb).portid;
info.family = family;
info.nlhdr = nlh; info.nlhdr = nlh;
info.genlhdr = nlmsg_data(nlh); info.genlhdr = nlmsg_data(nlh);
info.attrs = attrbuf; info.attrs = attrbuf;
......
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