diff mbox series

[net-next,01/15] tools: ynl: give up on libmnl for auto-ints

Message ID 20240222235614.180876-2-kuba@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series tools: ynl: stop using libmnl | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; GEN HAS DIFF 11 files changed, 2731 insertions(+), 2692 deletions(-);
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 56 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-23--18-00 (tests: 1457)

Commit Message

Jakub Kicinski Feb. 22, 2024, 11:56 p.m. UTC
The temporary auto-int helpers are not really correct.
We can't treat signed and unsigned ints the same when
determining whether we need full 8B. I realized this
before sending the patch to add support in libmnl.
Unfortunately, that patch has not been merged,
so time to fix our local helpers. Use the mnl* name
for now, subsequent patches will address that.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/net/ynl/lib/ynl-priv.h | 45 ++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 9 deletions(-)

Comments

Nicolas Dichtel Feb. 23, 2024, 1:51 p.m. UTC | #1
Le 23/02/2024 à 00:56, Jakub Kicinski a écrit :
> The temporary auto-int helpers are not really correct.
> We can't treat signed and unsigned ints the same when
> determining whether we need full 8B. I realized this
> before sending the patch to add support in libmnl.
> Unfortunately, that patch has not been merged,
> so time to fix our local helpers. Use the mnl* name
> for now, subsequent patches will address that.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>> ---
>  tools/net/ynl/lib/ynl-priv.h | 45 ++++++++++++++++++++++++++++--------
>  1 file changed, 36 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/net/ynl/lib/ynl-priv.h b/tools/net/ynl/lib/ynl-priv.h
> index 7491da8e7555..eaa0d432366c 100644
> --- a/tools/net/ynl/lib/ynl-priv.h
> +++ b/tools/net/ynl/lib/ynl-priv.h
> @@ -125,20 +125,47 @@ int ynl_exec_dump(struct ynl_sock *ys, struct nlmsghdr *req_nlh,
>  void ynl_error_unknown_notification(struct ynl_sock *ys, __u8 cmd);
>  int ynl_error_parse(struct ynl_parse_arg *yarg, const char *msg);
>  
> -#ifndef MNL_HAS_AUTO_SCALARS
> -static inline uint64_t mnl_attr_get_uint(const struct nlattr *attr)
> +/* Attribute helpers */
> +
> +static inline __u64 mnl_attr_get_uint(const struct nlattr *attr)
>  {
> -	if (mnl_attr_get_payload_len(attr) == 4)
> +	switch (mnl_attr_get_payload_len(attr)) {
> +	case 4:
>  		return mnl_attr_get_u32(attr);
> -	return mnl_attr_get_u64(attr);
> +	case 8:
> +		return mnl_attr_get_u64(attr);
> +	default:
> +		return 0;
> +	}
> +}
> +
> +static inline __s64 mnl_attr_get_sint(const struct nlattr *attr)
> +{
> +	switch (mnl_attr_get_payload_len(attr)) {
> +	case 4:
> +		return mnl_attr_get_u32(attr);
> +	case 8:
> +		return mnl_attr_get_u64(attr);
> +	default:
> +		return 0;
> +	}
>  }
mnl_attr_get_uint() and mnl_attr_get_sint() are identical. What about
#define mnl_attr_get_sint mnl_attr_get_uint
?

>  
>  static inline void
> -mnl_attr_put_uint(struct nlmsghdr *nlh, uint16_t type, uint64_t data)
> +mnl_attr_put_uint(struct nlmsghdr *nlh, __u16 type, __u64 data)
Is there a reason to switch from uint*_t to __u* types?

>  {
> -	if ((uint32_t)data == (uint64_t)data)
> -		return mnl_attr_put_u32(nlh, type, data);
> -	return mnl_attr_put_u64(nlh, type, data);
> +	if ((__u32)data == (__u64)data)
> +		mnl_attr_put_u32(nlh, type, data);
> +	else
> +		mnl_attr_put_u64(nlh, type, data);
> +}
> +
> +static inline void
> +mnl_attr_put_sint(struct nlmsghdr *nlh, __u16 type, __s64 data)
> +{
> +	if ((__s32)data == (__s64)data)
> +		mnl_attr_put_u32(nlh, type, data);
> +	else
> +		mnl_attr_put_u64(nlh, type, data);
>  }
>  #endif
> -#endif
Jakub Kicinski Feb. 23, 2024, 2:35 p.m. UTC | #2
On Fri, 23 Feb 2024 14:51:12 +0100 Nicolas Dichtel wrote:
> > +static inline __s64 mnl_attr_get_sint(const struct nlattr *attr)
> > +{
> > +	switch (mnl_attr_get_payload_len(attr)) {
> > +	case 4:
> > +		return mnl_attr_get_u32(attr);
> > +	case 8:
> > +		return mnl_attr_get_u64(attr);
> > +	default:
> > +		return 0;
> > +	}
> >  }  
> mnl_attr_get_uint() and mnl_attr_get_sint() are identical. What about
> #define mnl_attr_get_sint mnl_attr_get_uint
> ?

I like to have the helpers written out 
Nicolas Dichtel Feb. 23, 2024, 3:07 p.m. UTC | #3
Le 23/02/2024 à 15:35, Jakub Kicinski a écrit :
> On Fri, 23 Feb 2024 14:51:12 +0100 Nicolas Dichtel wrote:
>>> +static inline __s64 mnl_attr_get_sint(const struct nlattr *attr)
>>> +{
>>> +	switch (mnl_attr_get_payload_len(attr)) {
>>> +	case 4:
>>> +		return mnl_attr_get_u32(attr);
>>> +	case 8:
>>> +		return mnl_attr_get_u64(attr);
>>> +	default:
>>> +		return 0;
>>> +	}
>>>  }  
>> mnl_attr_get_uint() and mnl_attr_get_sint() are identical. What about
>> #define mnl_attr_get_sint mnl_attr_get_uint
>> ?
> 
> I like to have the helpers written out 
Donald Hunter Feb. 23, 2024, 3:34 p.m. UTC | #4
Jakub Kicinski <kuba@kernel.org> writes:

> The temporary auto-int helpers are not really correct.
> We can't treat signed and unsigned ints the same when
> determining whether we need full 8B. I realized this
> before sending the patch to add support in libmnl.
> Unfortunately, that patch has not been merged,
> so time to fix our local helpers. Use the mnl* name
> for now, subsequent patches will address that.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
diff mbox series

Patch

diff --git a/tools/net/ynl/lib/ynl-priv.h b/tools/net/ynl/lib/ynl-priv.h
index 7491da8e7555..eaa0d432366c 100644
--- a/tools/net/ynl/lib/ynl-priv.h
+++ b/tools/net/ynl/lib/ynl-priv.h
@@ -125,20 +125,47 @@  int ynl_exec_dump(struct ynl_sock *ys, struct nlmsghdr *req_nlh,
 void ynl_error_unknown_notification(struct ynl_sock *ys, __u8 cmd);
 int ynl_error_parse(struct ynl_parse_arg *yarg, const char *msg);
 
-#ifndef MNL_HAS_AUTO_SCALARS
-static inline uint64_t mnl_attr_get_uint(const struct nlattr *attr)
+/* Attribute helpers */
+
+static inline __u64 mnl_attr_get_uint(const struct nlattr *attr)
 {
-	if (mnl_attr_get_payload_len(attr) == 4)
+	switch (mnl_attr_get_payload_len(attr)) {
+	case 4:
 		return mnl_attr_get_u32(attr);
-	return mnl_attr_get_u64(attr);
+	case 8:
+		return mnl_attr_get_u64(attr);
+	default:
+		return 0;
+	}
+}
+
+static inline __s64 mnl_attr_get_sint(const struct nlattr *attr)
+{
+	switch (mnl_attr_get_payload_len(attr)) {
+	case 4:
+		return mnl_attr_get_u32(attr);
+	case 8:
+		return mnl_attr_get_u64(attr);
+	default:
+		return 0;
+	}
 }
 
 static inline void
-mnl_attr_put_uint(struct nlmsghdr *nlh, uint16_t type, uint64_t data)
+mnl_attr_put_uint(struct nlmsghdr *nlh, __u16 type, __u64 data)
 {
-	if ((uint32_t)data == (uint64_t)data)
-		return mnl_attr_put_u32(nlh, type, data);
-	return mnl_attr_put_u64(nlh, type, data);
+	if ((__u32)data == (__u64)data)
+		mnl_attr_put_u32(nlh, type, data);
+	else
+		mnl_attr_put_u64(nlh, type, data);
+}
+
+static inline void
+mnl_attr_put_sint(struct nlmsghdr *nlh, __u16 type, __s64 data)
+{
+	if ((__s32)data == (__s64)data)
+		mnl_attr_put_u32(nlh, type, data);
+	else
+		mnl_attr_put_u64(nlh, type, data);
 }
 #endif
-#endif