From: Jakub Kicinski <kuba@kernel.org>
To: netdev@vger.kernel.org
Cc: andrew@lunn.ch, johannes@sipsolutions.net, jiri@resnulli.us,
mkubecek@suse.cz, dsahern@kernel.org, pablo@netfilter.org,
Jakub Kicinski <kuba@kernel.org>
Subject: [RFC net-next 7/9] genetlink: bring back per op policy
Date: Wed, 30 Sep 2020 17:05:16 -0700 [thread overview]
Message-ID: <20201001000518.685243-8-kuba@kernel.org> (raw)
In-Reply-To: <20201001000518.685243-1-kuba@kernel.org>
Add policy to the struct genl_ops structure, this time
with maxattr, so it can be used properly.
Propagate .policy and .maxattr from the family
in genl_get_cmd() if needed, this say the rest of the
code does not have to worry if the policy is per op
or global.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
include/net/genetlink.h | 4 ++++
net/netlink/genetlink.c | 18 +++++++++++++-----
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index d781f2a240b5..48bfd8308938 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -156,6 +156,8 @@ struct genl_small_ops {
* @internal_flags: flags used by the family
* @flags: flags
* @validate: validation flags from enum genl_validate_flags
+ * @maxattr: maximum number of attributes supported
+ * @policy: netlink policy (takes precedence over family policy)
* @doit: standard command callback
* @start: start callback for dumps
* @dumpit: callback for dumpers
@@ -168,6 +170,8 @@ struct genl_ops {
int (*dumpit)(struct sk_buff *skb,
struct netlink_callback *cb);
int (*done)(struct netlink_callback *cb);
+ const struct nla_policy *policy;
+ unsigned int maxattr;
u8 cmd;
u8 internal_flags;
u8 flags;
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index dfa8a00640c0..7ceb2dc92a09 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -116,6 +116,11 @@ static void genl_op_from_full(const struct genl_family *family,
unsigned int i, struct genl_ops *op)
{
memcpy(op, &family->ops[i], sizeof(*op));
+
+ if (!op->maxattr)
+ op->maxattr = family->maxattr;
+ if (!op->policy)
+ op->policy = family->policy;
}
static int genl_get_cmd_full(u8 cmd, const struct genl_family *family,
@@ -142,6 +147,9 @@ static void genl_op_from_light(const struct genl_family *family,
op->internal_flags = family->small_ops[i].internal_flags;
op->flags = family->small_ops[i].flags;
op->validate = family->small_ops[i].validate;
+
+ op->maxattr = family->maxattr;
+ op->policy = family->policy;
}
static int genl_get_cmd_light(u8 cmd, const struct genl_family *family,
@@ -529,16 +537,16 @@ genl_family_rcv_msg_attrs_parse(const struct genl_family *family,
struct nlattr **attrbuf;
int err;
- if (!family->maxattr)
+ if (!ops->maxattr)
return NULL;
- attrbuf = kmalloc_array(family->maxattr + 1,
+ attrbuf = kmalloc_array(ops->maxattr + 1,
sizeof(struct nlattr *), GFP_KERNEL);
if (!attrbuf)
return ERR_PTR(-ENOMEM);
- err = __nlmsg_parse(nlh, hdrlen, attrbuf, family->maxattr,
- family->policy, validate, extack);
+ err = __nlmsg_parse(nlh, hdrlen, attrbuf, ops->maxattr, ops->policy,
+ validate, extack);
if (err) {
kfree(attrbuf);
return ERR_PTR(err);
@@ -845,7 +853,7 @@ static int ctrl_fill_info(const struct genl_family *family, u32 portid, u32 seq,
op_flags |= GENL_CMD_CAP_DUMP;
if (op.doit)
op_flags |= GENL_CMD_CAP_DO;
- if (family->policy)
+ if (op.policy)
op_flags |= GENL_CMD_CAP_HASPOL;
nest = nla_nest_start_noflag(skb, i + 1);
--
2.26.2
next prev parent reply other threads:[~2020-10-01 0:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 0:05 [RFC net-next 0/9] genetlink: support per-command policy dump Jakub Kicinski
2020-10-01 0:05 ` [RFC net-next 1/9] genetlink: add missing kdoc for validation flags Jakub Kicinski
2020-10-01 0:05 ` [RFC net-next 2/9] genetlink: reorg struct genl_family Jakub Kicinski
2020-10-01 7:34 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 3/9] genetlink: add small version of ops Jakub Kicinski
2020-10-01 7:40 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 4/9] genetlink: move to smaller ops wherever possible Jakub Kicinski
2020-10-01 7:42 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 5/9] genetlink: add a structure for dump state Jakub Kicinski
2020-10-01 7:48 ` Johannes Berg
2020-10-01 8:04 ` Michal Kubecek
2020-10-01 0:05 ` [RFC net-next 6/9] genetlink: use .start callback for dumppolicy Jakub Kicinski
2020-10-01 7:49 ` Johannes Berg
2020-10-01 0:05 ` Jakub Kicinski [this message]
2020-10-01 7:53 ` [RFC net-next 7/9] genetlink: bring back per op policy Johannes Berg
2020-10-01 0:05 ` [RFC net-next 8/9] genetlink: use per-op policy for CTRL_CMD_GETPOLICY Jakub Kicinski
2020-10-01 7:56 ` Johannes Berg
2020-10-01 0:05 ` [RFC net-next 9/9] genetlink: allow dumping command-specific policy Jakub Kicinski
2020-10-01 7:59 ` Johannes Berg
2020-10-01 15:41 ` Jakub Kicinski
2020-10-01 16:00 ` Johannes Berg
2020-10-01 16:24 ` Jakub Kicinski
2020-10-01 16:57 ` Johannes Berg
2020-10-01 17:09 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201001000518.685243-8-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew@lunn.ch \
--cc=dsahern@kernel.org \
--cc=jiri@resnulli.us \
--cc=johannes@sipsolutions.net \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).