From: Jacob Keller <jacob.e.keller@intel.com>
To: netdev@vger.kernel.org
Cc: Jacob Keller <jacob.e.keller@intel.com>,
Jonathan Corbet <corbet@lwn.net>, Jiri Pirko <jiri@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>,
Stephen Hemminger <stephen@networkplumber.org>
Subject: [RFC iproute2 2/6] utils: extract CTRL_ATTR_MAXATTR and save it
Date: Fri, 5 Aug 2022 16:41:51 -0700 [thread overview]
Message-ID: <20220805234155.2878160-3-jacob.e.keller@intel.com> (raw)
In-Reply-To: <20220805234155.2878160-1-jacob.e.keller@intel.com>
mnlu_gen_socket_open opens a socket and configures it for use with a
generic netlink family. As part of this process it sends a
CTRL_CMD_GETFAMILY to get the ID for the family name requested.
In addition to the family id, this command reports a few other useful
values including the maximum attribute. The maximum attribute is useful in
order to know whether a given attribute is supported and for knowing the
necessary size to allocate for other operations such as policy dumping.
Since we already have to issue a CTRL_CMD_GETFAMILY to get the id, we can
also store the maximum attribute as well. Modify the callback functions to
parse the maximum attribute NLA and store it in the mnlu_gen_socket
structure.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
include/mnl_utils.h | 1 +
lib/mnl_utils.c | 18 ++++++++++++------
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/mnl_utils.h b/include/mnl_utils.h
index aa5f0a9b17c7..2193934849e1 100644
--- a/include/mnl_utils.h
+++ b/include/mnl_utils.h
@@ -6,6 +6,7 @@ struct mnlu_gen_socket {
struct mnl_socket *nl;
char *buf;
uint32_t family;
+ uint32_t maxattr;
unsigned int seq;
uint8_t version;
};
diff --git a/lib/mnl_utils.c b/lib/mnl_utils.c
index d5abff58d816..79bac5cfd4de 100644
--- a/lib/mnl_utils.c
+++ b/lib/mnl_utils.c
@@ -110,7 +110,7 @@ int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, siz
return err;
}
-static int get_family_id_attr_cb(const struct nlattr *attr, void *data)
+static int get_family_attrs_cb(const struct nlattr *attr, void *data)
{
int type = mnl_attr_get_type(attr);
const struct nlattr **tb = data;
@@ -121,20 +121,26 @@ static int get_family_id_attr_cb(const struct nlattr *attr, void *data)
if (type == CTRL_ATTR_FAMILY_ID &&
mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
return MNL_CB_ERROR;
+ if (type == CTRL_ATTR_MAXATTR &&
+ mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
+ return MNL_CB_ERROR;
tb[type] = attr;
return MNL_CB_OK;
}
-static int get_family_id_cb(const struct nlmsghdr *nlh, void *data)
+static int get_family_cb(const struct nlmsghdr *nlh, void *data)
{
struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
struct nlattr *tb[CTRL_ATTR_MAX + 1] = {};
- uint32_t *p_id = data;
+ struct mnlu_gen_socket *nlg = data;
- mnl_attr_parse(nlh, sizeof(*genl), get_family_id_attr_cb, tb);
+ mnl_attr_parse(nlh, sizeof(*genl), get_family_attrs_cb, tb);
if (!tb[CTRL_ATTR_FAMILY_ID])
return MNL_CB_ERROR;
- *p_id = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
+ if (!tb[CTRL_ATTR_MAXATTR])
+ return MNL_CB_ERROR;
+ nlg->family = mnl_attr_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
+ nlg->maxattr = mnl_attr_get_u32(tb[CTRL_ATTR_MAXATTR]);
return MNL_CB_OK;
}
@@ -159,7 +165,7 @@ static int family_get(struct mnlu_gen_socket *nlg, const char *family_name)
err = mnlu_socket_recv_run(nlg->nl, nlh->nlmsg_seq, nlg->buf,
MNL_SOCKET_BUFFER_SIZE,
- get_family_id_cb, &nlg->family);
+ get_family_cb, nlg);
return err;
}
--
2.37.1.208.ge72d93e88cb2
next prev parent reply other threads:[~2022-08-05 23:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-05 23:41 [RFC iproute2 0/6] devlink: add policy check for all attributes Jacob Keller
2022-08-05 23:41 ` [RFC iproute2 1/6] mnlg: remove unnused mnlg_socket structure Jacob Keller
2022-08-05 23:41 ` Jacob Keller [this message]
2022-08-05 23:41 ` [RFC iproute2 3/6] mnl_utils: add function to dump command policy Jacob Keller
2022-08-05 23:41 ` [RFC iproute2 4/6] devlink: use dl_no_arg instead of checking dl_argc == 0 Jacob Keller
2022-08-05 23:41 ` [RFC iproute2 5/6] devlink: remove dl_argv_parse_put Jacob Keller
2022-08-05 23:41 ` [RFC iproute2 6/6] devlink: check attributes against policy Jacob Keller
2022-08-08 10:32 ` [RFC iproute2 0/6] devlink: add policy check for all attributes Jiri Pirko
2022-08-08 17:02 ` Keller, Jacob E
2022-08-09 7:07 ` Jiri Pirko
2022-08-09 9:50 ` Jiri Pirko
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=20220805234155.2878160-3-jacob.e.keller@intel.com \
--to=jacob.e.keller@intel.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stephen@networkplumber.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