aboutsummaryrefslogtreecommitdiffstats
path: root/tools/net
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2024-02-27 14:30:18 -0800
committerJakub Kicinski <kuba@kernel.org>2024-02-28 15:25:41 -0800
commit21f6986d19b01ecda3d8ae2e79780aa3603d4eeb (patch)
tree1cfd0f752f08eb5391d8deb9cde4a24ea958c5a9 /tools/net
parent3bfe90527d6387e19078c9f774d6328448bac201 (diff)
downloadlinux-21f6986d19b01ecda3d8ae2e79780aa3603d4eeb.tar.gz
tools: ynl: give up on libmnl for auto-ints
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. Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://lore.kernel.org/r/20240227223032.1835527-2-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/net')
-rw-r--r--tools/net/ynl/lib/ynl-priv.h45
1 files changed, 36 insertions, 9 deletions
diff --git a/tools/net/ynl/lib/ynl-priv.h b/tools/net/ynl/lib/ynl-priv.h
index 7491da8e7555d..eaa0d432366c9 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)
+{
+ 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 __s64 mnl_attr_get_sint(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 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