All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Machata <petrm@nvidia.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jakub Kicinski <kuba@kernel.org>,
	Danielle Ratson <danieller@nvidia.com>, Phil Sutter <phil@nwl.cc>,
	"netfilter-devel@vger.kernel.org"
	<netfilter-devel@vger.kernel.org>, "fw@strlen.de" <fw@strlen.de>,
	mlxsw <mlxsw@nvidia.com>
Subject: Re: [PATCH libmnl] src: attr: Add mnl_attr_get_uint() function
Date: Mon, 30 Sep 2024 18:25:17 +0200	[thread overview]
Message-ID: <87cyklm7i2.fsf@nvidia.com> (raw)
In-Reply-To: <ZvqeEa_37KEmL8li@calendula>


Pablo Neira Ayuso <pablo@netfilter.org> writes:

> On Mon, Sep 30, 2024 at 01:45:09PM +0200, Jakub Kicinski wrote:
>> On Mon, 30 Sep 2024 12:56:20 +0200 Pablo Neira Ayuso wrote:
>> > On Mon, Sep 30, 2024 at 12:28:08PM +0200, Pablo Neira Ayuso wrote:
>> > > On Sun, Sep 29, 2024 at 10:42:44AM +0000, Danielle Ratson wrote:  
>> > > > Hi,
>> > > > 
>> > > > Is there a plan to build a new version soon? 
>> > > > I am asking since I am planning to use this function in ethtool.  
>> > > 
>> > > ASAP  
>> > 
>> > but one question before... Is this related to NLA_UINT in the kernel?
>> > 
>> > /**
>> >  * nla_put_uint - Add a variable-size unsigned int to a socket buffer
>> >  * @skb: socket buffer to add attribute to
>> >  * @attrtype: attribute type
>> >  * @value: numeric value
>> >  */
>> > static inline int nla_put_uint(struct sk_buff *skb, int attrtype, u64 value)
>> > {
>> >         u64 tmp64 = value;
>> >         u32 tmp32 = value;
>> > 
>> >         if (tmp64 == tmp32)
>> >                 return nla_put_u32(skb, attrtype, tmp32);
>> >         return nla_put(skb, attrtype, sizeof(u64), &tmp64);
>> > }
>> > 
>> > if I'm correct, it seems kernel always uses either u32 or u64.
>> > 
>> > Userspace assumes u8 and u16 are possible though:
>> > 
>> > +/**
>> > + * 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.
>> > + */
>> > +EXPORT_SYMBOL uint64_t mnl_attr_get_uint(const struct nlattr *attr)
>> > +{
>> > +       switch (mnl_attr_get_payload_len(attr)) {
>> > +       case sizeof(uint8_t):
>> > +               return mnl_attr_get_u8(attr);
>> > +       case sizeof(uint16_t):
>> > +               return mnl_attr_get_u16(attr);
>> > +       case sizeof(uint32_t):
>> > +               return mnl_attr_get_u32(attr);
>> > +       case sizeof(uint64_t):
>> > +               return mnl_attr_get_u64(attr);
>> > +       }
>> > +
>> > +       return -1ULL;
>> > +}
>> > 
>> > Or this is an attempt to provide a helper that allows you fetch for
>> > payload value of 2^3..2^6 bytes?
>> 
>> No preference here, FWIW. Looks like this patch does a different thing
>> than the kernel. But maybe a broader "automatic" helper is useful for
>> user space code.
>
> Not sure. @Danielle: could you clarify your intention?

This follows the iproute2 helper, where I was asked to support >32-bit
fields purely as a service to the users, so that one helper can be used
for any integral field.

  reply	other threads:[~2024-09-30 16:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31  6:35 [PATCH libmnl] src: attr: Add mnl_attr_get_uint() function Danielle Ratson
2024-07-31  7:14 ` Phil Sutter
2024-09-29 10:42   ` Danielle Ratson
2024-09-30 10:28     ` Pablo Neira Ayuso
2024-09-30 10:56       ` Pablo Neira Ayuso
2024-09-30 11:45         ` Jakub Kicinski
2024-09-30 12:48           ` Pablo Neira Ayuso
2024-09-30 16:25             ` Petr Machata [this message]
2024-09-30 17:01               ` Pablo Neira Ayuso
2024-09-30 17:10                 ` Pablo Neira Ayuso
2024-09-30 17:52                   ` Pablo Neira Ayuso
2024-10-01  8:16                     ` Petr Machata
2024-10-01  7:51                   ` Petr Machata
2024-10-01  9:19             ` Danielle Ratson

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=87cyklm7i2.fsf@nvidia.com \
    --to=petrm@nvidia.com \
    --cc=danieller@nvidia.com \
    --cc=fw@strlen.de \
    --cc=kuba@kernel.org \
    --cc=mlxsw@nvidia.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.