libifconfig: Fix bridge status member list

When this functionality was moved to libifconfig in 3dfbda3401,
the end of list calculation was modified for unknown reasons, practically
limiting the number of bridge member returned to (about) 102.

This patch changes the calculation back to what it was originally and
adds a unit test to verify it works as expected.

Reported by:	Patrick M. Hausen (via ML)
Reviewed by:	kp
Approved by:	kp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43135

(cherry picked from commit 3d36053ca6)
This commit is contained in:
Michael Gmelin 2023-12-20 21:21:55 +01:00
parent 5e78db7b45
commit c2299997ce
2 changed files with 29 additions and 1 deletions

View File

@ -111,7 +111,7 @@ ifconfig_bridge_get_bridge_status(ifconfig_handle_t *h,
free(bridge);
return (-1);
}
if (members.ifbic_len <= len)
if ((members.ifbic_len + sizeof(*members.ifbic_req)) < len)
break;
}
if (buf == NULL) {

View File

@ -516,6 +516,33 @@ gif_cleanup()
vnet_cleanup
}
atf_test_case "many_bridge_members" "cleanup"
many_bridge_members_head()
{
atf_set descr 'many_bridge_members ifconfig test'
atf_set require.user root
}
many_bridge_members_body()
{
vnet_init
bridge=$(vnet_mkbridge)
ifcount=256
for _ in $(seq 1 $ifcount); do
epair=$(vnet_mkepair)
ifconfig "${bridge}" addm "${epair}"a
done
atf_check -s exit:0 -o inline:"$ifcount\n" \
sh -c "ifconfig ${bridge} | grep member: | wc -l | xargs"
}
many_bridge_members_cleanup()
{
vnet_cleanup
}
atf_init_test_cases()
{
atf_add_test_case "bridge_transmit_ipv4_unicast"
@ -528,4 +555,5 @@ atf_init_test_cases()
atf_add_test_case "mac_conflict"
atf_add_test_case "stp_validation"
atf_add_test_case "gif"
atf_add_test_case "many_bridge_members"
}