devlink: show devlink instance index in dev output
Subsystems (4)
Jiri Pirko
maintainercover devlink: show devlink instance index in dev output
From: Jiri Pirko <[email protected]>
Support for identifying devlink instances by a unique index was recently added on the kernel side:
https://lore.kernel.org/all/[email protected]/
This patchset adds the necessary userspace support.
First, as a dependency, introduce a fallback for mnl_attr_get_uint() to handle the NLA_UINT variable-width attribute type used by the kernel for the index, with backward compatibility for older libmnl versions.
Then, display the devlink instance index in dev show output when the kernel provides it.
Jiri Pirko (3):
update kernel headers
mnl: add fallback implementation for mnl_attr_get_uint()
devlink: show devlink instance index in dev output
configure | 22 ++++++++++++++++++++++ devlink/devlink.c | 6 +++++- include/mnl_utils.h | 4 ++++ include/uapi/linux/devlink.h | 4 ++++ lib/mnl_utils.c | 17 +++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.1
Jiri Pirko
maintainerPATCH 1/3 update kernel headers
From: Jiri Pirko <[email protected]>
--- include/uapi/linux/devlink.h | 4 ++++ 1 file changed, 4 insertions(+)
include/uapi/linux/devlink.h +4 -0
@@ -19,6 +19,8 @@#define DEVLINK_GENL_VERSION 0x1#define DEVLINK_GENL_MCGRP_CONFIG_NAME "config" +#define DEVLINK_INDEX_BUS_NAME "devlink_index" +enum devlink_command {/* don't change the order or add anything between, this is ABI! */ DEVLINK_CMD_UNSPEC ,
@@ -642,6 +644,8 @@ enum devlink_attr {DEVLINK_ATTR_PARAM_VALUE_DEFAULT ,/* dynamic */ DEVLINK_ATTR_PARAM_RESET_DEFAULT ,/* flag */ +DEVLINK_ATTR_INDEX ,/* uint */ +/* Add new attributes above here, update the spec in * Documentation/netlink/specs/devlink.yaml and re-generate * net/devlink/netlink_gen.c.
Signature · 1 line
2.51.1
Jiri Pirko
maintainerPATCH 2/3 mnl: add fallback implementation for mnl_attr_get_uint()
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
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.
--- configure | 22 ++++++++++++++++++++++ include/mnl_utils.h | 4 ++++ lib/mnl_utils.c | 17 +++++++++++++++++ 3 files changed, 43 insertions(+)
configure +22 -0
@@ -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
include/mnl_utils.h +4 -0
@@ -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__ */
lib/mnl_utils.c +17 -0
@@ -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
Signature · 1 line
2.51.1
Re: [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint()
Quoted 7 lines · On Mon, 16 Mar 2026 16:44:17 +0100 Jiri Pirko <[email protected]> wrote:
From: Jiri Pirko <[email protected]>
libmnl introduced
mnl_attr_get_uint()to handleNLA_UINTvariable-width attributes. Add a configure check to detect it and provide a fallback implementation for older libmnl versions.Signed-off-by Jiri Pirko <[email protected]>
How far back was this? If it was relatively recent would prefer not adding another set of config tests.
Jiri Pirko
maintainerRe: [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint()
Quoted 5 lines · Mon, Mar 16, 2026 at 05:12:45PM +0100, [email protected] wrote:
Quoted 2 lines · On Mon, 16 Mar 2026 16:44:17 +0100 Jiri Pirko <[email protected]> wrote:
From: Jiri Pirko <[email protected]>
Quoted 8 lines
Quoted 5 lines
libmnl introduced
mnl_attr_get_uint()to handleNLA_UINTvariable-width attributes. Add a configure check to detect it and provide a fallback implementation for older libmnl versions.Signed-off-by Jiri Pirko <[email protected]>How far back was this? If it was relatively recent would prefer not adding another set of config tests.
https://git.netfilter.org/libmnl/commit/?id=102942be401a99943b2c68981b238dadfa788f2d
I'm not sure what you suggest as alternative...
Re: [PATCH iproute2-next 2/3] mnl: add fallback implementation for mnl_attr_get_uint()
Quoted 10 lines · Jiri Pirko
Quoted 9 lines · Mon, Mar 16, 2026 at 05:12:45PM +0100, [email protected] wrote:
Quoted 6 lines · On Mon, 16 Mar 2026 16:44:17 +0100 Jiri Pirko <[email protected]> wrote:
From: Jiri Pirko <[email protected]>
libmnl introduced
mnl_attr_get_uint()to handleNLA_UINTvariable-width attributes. Add a configure check to detect it and provide a fallback implementation for older libmnl versions.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Jiri Pirko <[email protected]>How far back was this? If it was relatively recent would prefer not adding another set of config tests.
https://git.netfilter.org/libmnl/commit/?id=102942be401a99943b2c68981b238dadfa788f2d
I'm not sure what you suggest as alternative...
that is less than 1 stable release cycle. I think we should keep the configure probe and fallback.
Jiri Pirko
maintainerPATCH 3/3 devlink: show devlink instance index in dev output
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Print devlink instance index in dev show output when the kernel provides it.
--- devlink/devlink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
devlink/devlink.c +5 -1
@@ -4095,8 +4095,12 @@ static void pr_out_dev(struct dl *dl, const struct nlmsghdr *nlh, {if ((tb[DEVLINK_ATTR_RELOAD_FAILED ] &&mnl_attr_get_u8 (tb[DEVLINK_ATTR_RELOAD_FAILED ])) || (tb[DEVLINK_ATTR_DEV_STATS ] && dl->stats) || - tb[DEVLINK_ATTR_NESTED_DEVLINK ]) { + tb[DEVLINK_ATTR_NESTED_DEVLINK ] || + tb[DEVLINK_ATTR_INDEX ]) {__pr_out_handle_start (dl, tb, true, false); +if (tb[DEVLINK_ATTR_INDEX ]) +print_uint (PRINT_ANY ,"index" ," index %u" , +mnl_attr_get_uint (tb[DEVLINK_ATTR_INDEX ]));pr_out_reload_data (dl, tb);pr_out_dev_nested (dl, nlh);pr_out_handle_end (dl);
Signature · 1 line
2.51.1
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Hello:
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Quoted 9 lines · On Mon, 16 Mar 2026 16:44:15 +0100 you wrote:
From: Jiri Pirko <[email protected]>
Support for identifying devlink instances by a unique index was recently added on the kernel side:
https://lore.kernel.org/all/[email protected]/This patchset adds the necessary userspace support.
[...]
Here is the summary with links:
- [iproute2-next,1/3] update kernel headers
(no matching commit)
- [iproute2-next,2/3] mnl: add fallback implementation for mnl_attr_get_uint()
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=bef61beb2edf
- [iproute2-next,3/3] devlink: show devlink instance index in dev output
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=36252727bfc6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html