Subject: Re: [RFC] netlink: add variable-length / auto integers

From: Jiri Pirko <[email-masked]>
Date: Wed, 11 Oct 2023 19:01:53 +0200

Wed, Oct 11, 2023 at 06:16:24PM CEST, [email-masked] wrote:
>On Wed, 11 Oct 2023 15:46:47 +0200 Jiri Pirko wrote:
>> >Thoughts?  
>> 
>> Hmm, I assume that genetlink.yaml schema should only allow uint and sint
>> to be defined after this, so new genetlink implementations use just uint
>> and sint, correct?
>
>No, fixed types are still allowed, just discouraged.

Why? Is there goint to be warn in ynl gen?

>
>> Than we have genetlink.yaml genetlink-legacy.yaml genetlink-legacy2.yaml
>> ?
>> I guess in the future there might be other changes to require new
>> implemetation not to use legacy things. How does this scale?
>>
>> >This is completely untested. YNL to follow.
>> >---
>> > include/net/netlink.h        | 62 ++++++++++++++++++++++++++++++++++--
>> > include/uapi/linux/netlink.h |  5 +++
>> > lib/nlattr.c                 |  9 ++++++
>> > net/netlink/policy.c         | 14 ++++++--
>> > 4 files changed, 85 insertions(+), 5 deletions(-)
>> >
>> >diff --git a/include/net/netlink.h b/include/net/netlink.h
>> >index 8a7cd1170e1f..523486dfe4f3 100644
>> >--- a/include/net/netlink.h
>> >+++ b/include/net/netlink.h
>> >@@ -183,6 +183,8 @@ enum {
>> > 	NLA_REJECT,
>> > 	NLA_BE16,
>> > 	NLA_BE32,
>> >+	NLA_SINT,  
>> 
>> Why not just NLA_INT?
>
>Coin toss. Signed types are much less common in netlink
>so it shouldn't matter much.
>
>> >+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);  
>> 
>> It's a bit confusing, perheps better just to use nla_put() here as well?
>
>I want to underscore the equivalency to u32 for smaller types.