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

From: Jakub Kicinski <[email-masked]>
Date: Wed, 11 Oct 2023 09:16:24 -0700

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.

> 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.