From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, dsahern@gmail.com
Subject: [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint()
Date: Mon, 16 Mar 2026 16:44:17 +0100 [thread overview]
Message-ID: <20260316154418.625026-3-jiri@resnulli.us> (raw)
In-Reply-To: <20260316154418.625026-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
libmnl introduced mnl_attr_get_uint() to handle NLA_UINT
variable-width attributes. Add a configure check to detect it
and provide a fallback implementation for older libmnl versions.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
configure | 22 ++++++++++++++++++++++
include/mnl_utils.h | 4 ++++
lib/mnl_utils.c | 17 +++++++++++++++++
3 files changed, 43 insertions(+)
diff --git a/configure b/configure
index 7437db4f22a8..ebc0d97a6f26 100755
--- a/configure
+++ b/configure
@@ -366,6 +366,24 @@ check_tirpc()
fi
}
+have_mnl_attr_get_uint()
+{
+ cat >$TMPDIR/mnl_attr_get_uint_test.c <<EOF
+#include <libmnl/libmnl.h>
+int main(int argc, char **argv)
+{
+ return !!mnl_attr_get_uint(NULL);
+}
+EOF
+
+ $CC -I$INCLUDE $(${PKG_CONFIG} libmnl --cflags --libs 2>/dev/null) \
+ -o $TMPDIR/mnl_attr_get_uint_test $TMPDIR/mnl_attr_get_uint_test.c >/dev/null 2>&1
+ local ret=$?
+
+ rm -f $TMPDIR/mnl_attr_get_uint_test.c $TMPDIR/mnl_attr_get_uint_test
+ return $ret
+}
+
check_mnl()
{
if ${PKG_CONFIG} libmnl --exists; then
@@ -374,6 +392,10 @@ check_mnl()
echo 'CFLAGS += -DHAVE_LIBMNL' "$(${PKG_CONFIG} libmnl --cflags)" >>$CONFIG
echo 'LDLIBS +=' "$(${PKG_CONFIG} libmnl --libs)" >> $CONFIG
+
+ if have_mnl_attr_get_uint; then
+ echo "CFLAGS += -DHAVE_MNL_ATTR_GET_UINT" >>$CONFIG
+ fi
else
echo "no"
fi
diff --git a/include/mnl_utils.h b/include/mnl_utils.h
index 0ddf2932db62..4df9e398e591 100644
--- a/include/mnl_utils.h
+++ b/include/mnl_utils.h
@@ -33,4 +33,8 @@ int mnlu_gen_socket_recv_run(struct mnlu_gen_socket *nlg, mnl_cb_t cb,
void *data);
int mnlu_gen_cmd_dump_policy(struct mnlu_gen_socket *nlg, uint8_t cmd);
+#ifndef HAVE_MNL_ATTR_GET_UINT
+uint64_t mnl_attr_get_uint(const struct nlattr *attr);
+#endif
+
#endif /* __MNL_UTILS_H__ */
diff --git a/lib/mnl_utils.c b/lib/mnl_utils.c
index 5f6671bf94cc..43b4cd1a9e40 100644
--- a/lib/mnl_utils.c
+++ b/lib/mnl_utils.c
@@ -381,3 +381,20 @@ int mnlu_gen_cmd_dump_policy(struct mnlu_gen_socket *nlg, uint8_t cmd)
return 0;
}
+
+#ifndef HAVE_MNL_ATTR_GET_UINT
+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;
+}
+#endif
--
2.51.1
next prev parent reply other threads:[~2026-03-16 15:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 15:44 [PATCH iproute2-next 0/3] devlink: show devlink instance index in dev output Jiri Pirko
2026-03-16 15:44 ` [PATCH iproute2-next 1/3] update kernel headers Jiri Pirko
2026-03-16 15:44 ` Jiri Pirko [this message]
2026-03-16 16:12 ` [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint() Stephen Hemminger
2026-03-17 8:17 ` Jiri Pirko
2026-03-18 2:31 ` David Ahern
2026-03-16 15:44 ` [PATCH iproute2-next 3/3] devlink: show devlink instance index in dev output Jiri Pirko
2026-03-23 0:20 ` [PATCH iproute2-next 0/3] " patchwork-bot+netdevbpf
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=20260316154418.625026-3-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox