netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, petrm@nvidia.com,
	danieller@nvidia.com, mlxsw@nvidia.com, kuba@kernel.org
Subject: Re: [PATCH libmnl] attr: expand mnl_attr_get_uint() documentation
Date: Sun, 13 Oct 2024 00:58:26 +0200	[thread overview]
Message-ID: <Zwr_EhpLQoNdEaNF@orbyte.nwl.cc> (raw)
In-Reply-To: <20241012222725.55023-1-pablo@netfilter.org>

On Sun, Oct 13, 2024 at 12:27:25AM +0200, Pablo Neira Ayuso wrote:
> This function is modelled after rta_getattr_uint() in libnetlink to fetch the
> netlink attribute payload of NLA_UINT, although it was extended to make it
> universal for 2^3..2^6 byte integers.
                         ~~~~
This should be bits, not bytes.

> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
>  src/attr.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/src/attr.c b/src/attr.c
> index 399318eebaa8..afabe5fbc8d9 100644
> --- a/src/attr.c
> +++ b/src/attr.c
> @@ -393,7 +393,24 @@ EXPORT_SYMBOL uint64_t mnl_attr_get_u64(const struct nlattr *attr)
>   * mnl_attr_get_uint - returns 64-bit unsigned integer attribute.
>   * \param attr pointer to netlink attribute
>   *
> - * This function returns the 64-bit value of the attribute payload.
> + * This helper function reads the variable-length netlink attribute NLA_UINT
> + * that provides a 32-bit or 64-bit integer payload. Its use is recommended only
> + * in these cases.
> + *
> + * Recommended validation for NLA_UINT is:
> + *
> + * \verbatim
> +	if (!mnl_attr_validate(attr, NLA_U32) &&
> +	    !mnl_attr_validate(attr, NLA_U64)) {
> +		perror("mnl_attr_validate");
> +		return MNL_CB_ERROR;
> +	}
> +\endverbatim
> + *
> + * \returns the 64-bit value of the attribute payload. On error, it returns
> + * UINT64_MAX if the length of the netlink attribute is not 2^3..2^6 bytes.
                                                                        ~~~~~
Same here.

Apart from that, LGTM!

Cheers, Phil

      reply	other threads:[~2024-10-12 22:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-12 22:27 [PATCH libmnl] attr: expand mnl_attr_get_uint() documentation Pablo Neira Ayuso
2024-10-12 22:58 ` Phil Sutter [this message]

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=Zwr_EhpLQoNdEaNF@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=danieller@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=mlxsw@nvidia.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=petrm@nvidia.com \
    /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).