iplink: bond: fix partner LACP state decoding
Subsystems (2)
v2 cover iplink: bond: fix partner LACP state decoding
G'day,
Thanks Stephen for the feedback.
While porting iproute2 to Go, I noticed ip reads the u16 IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE as a u8. For normal LACP state values, this makes the partner state print as 0 on big-endian systems.
Patch 1 fixes the attribute read. Patch 2 fixes the absence check used by the regression test in patch 3.
v2:
- .gitignore and make clean: use tests/ip/link/*.nl
- trim the test comment
- shorter commit messages
v1: https://lore.kernel.org/netdev/[email protected]/
Dave Seddon (3):
iplink_bond_slave: read ad_partner_oper_port_state as u16
testsuite: fix test_on_not on multi-line output
testsuite: add bond slave LACP port state test
.gitignore | 2 +- ip/iplink_bond_slave.c | 2 +- testsuite/Makefile | 2 +- testsuite/lib/generic.sh | 5 +- .../ip/link/show_bond_slave_lacp_state.t | 26 +++++ testsuite/tools/generate_nlmsg.c | 103 ++++++++++++++++-- 6 files changed, 126 insertions(+), 14 deletions(-) create mode 100755 testsuite/tests/ip/link/show_bond_slave_lacp_state.t
Signature · 1 line
2.55.0
PATCH v2 1/3 iplink_bond_slave: read ad_partner_oper_port_state as u16
The kernel sends IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE as a u16, but ip reads it as a u8. On big endian that is the high byte, so the partner state always prints as 0.
--- ip/iplink_bond_slave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/iplink_bond_slave.c +1 -1
@@ -145,7 +145,7 @@ static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *t }if (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE ]) { -__u16 state =rta_getattr_u8 (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE ]); +__u16 state =rta_getattr_u16 (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE ]); print_int(PRINT_ANY, "ad_partner_oper_port_state",
Signature · 1 line
2.55.0
PATCH v2 2/3 testsuite: fix test_on_not on multi-line output
In reply to Dave Seddontest_on_not used grep -vq, which passes if any line does not match, even when another line does. Pass only when no line matches.
--- testsuite/lib/generic.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
testsuite/lib/generic.sh +3 -2
@@ -113,8 +113,9 @@ test_on() test_on_not() { - echo -n "test on: \"$1\"" - if cat "$STD_OUT" | grep -vqE "$1" + echo -n "test on absence: \"$1\"" + grep -qE -- "$1" "$STD_OUT" + if [ "$?" -eq 1 ] then pr_success else
Signature · 1 line
2.55.0
PATCH v2 3/3 testsuite: add bond slave LACP port state test
In reply to Dave SeddonDecode generated bond slave messages with ip -d monitor file. Use a synthetic partner state of 0x0100 to catch a u8 reader on either endianness. Also check normal and zero states, actor state output, and an absent partner attribute.
--- .gitignore | 2 +- testsuite/Makefile | 2 +- .../ip/link/show_bond_slave_lacp_state.t | 26 +++++ testsuite/tools/generate_nlmsg.c | 103 ++++++++++++++++-- 4 files changed, 122 insertions(+), 11 deletions(-) create mode 100755 testsuite/tests/ip/link/show_bond_slave_lacp_state.t
.gitignore +1 -1
@@ -38,4 +38,4 @@ series testsuite/results testsuite/iproute2/iproute2-this testsuite/tools/generate_nlmsg -testsuite/tests/ip/link/dev_wo_vf_rate.nl +testsuite/tests/ip/link/*.nl
testsuite/Makefile +1 -1
@@ -47,7 +47,7 @@ testclean: clean: testclean @rm -f iproute2/iproute2-this - @rm -f tests/ip/link/dev_wo_vf_rate.nl + @rm -f tests/ip/link/*.nl $(MAKE) -C tools clean distclean: clean
testsuite/tests/ip/link/show_bond_slave_lacp_state.t new file +26 -0
@@ -0,0 +1,26 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +. lib/generic.sh + +# suffix|description|expected regex (leading ! = must not match) +while IFS='|' read -r suffix desc expect; do + [ -z "$suffix" ] && continue + NL_FILE="tests/ip/link/bond_slave_partner_${suffix}.nl" + ts_ip "$0" "$desc" -d monitor file "$NL_FILE" + case "$expect" in + !*) + test_on "ad_actor_oper_port_state 63[^0-9]" + test_on_not "${expect#!}" + ;; + *) + test_on "$expect" + ;; + esac +done <<EOF +fast|partner state 0x3f|ad_partner_oper_port_state 63 ad_partner_oper_port_state_str <active,short_timeout,aggregating,in_sync,collecting,distributing> +fast|actor state stays u8|ad_actor_oper_port_state 63[^0-9] +zero|partner state 0|ad_partner_oper_port_state 0 ad_partner_oper_port_state_str <> +hionly|partner state 0x0100, high byte only|ad_partner_oper_port_state 256[^0-9] +absent|no partner attribute|!ad_partner_oper_port_state +EOF
testsuite/tools/generate_nlmsg.c +94 -9
132 lines not on this page · raw message
Signature · 1 line
2.55.0
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Hello:
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Quoted 10 lines · On Mon, 19 Oct 2026 13:38:40 -0700 you wrote:
G'day,
Thanks Stephen for the feedback.
While porting iproute2 to Go, I noticed ip reads the u16
IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATEas a u8. For normal LACP state values, this makes the partner state print as 0 on big-endian systems.[...]
Here is the summary with links:
- [iproute2,v2,1/3] iplink_bond_slave: read ad_partner_oper_port_state as u16
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=0067cbc8166e - [iproute2,v2,2/3] testsuite: fix test_on_not on multi-line output https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=075f1b6f6a79 - [iproute2,v2,3/3] testsuite: add bond slave LACP port state test https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=4f49441d2be0
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html