From: Christian Glombek Date: Thu, 18 Dec 2025 11:46:56 +0000 (+0100) Subject: resolved: Add test for ifindex=0 BrowseServices functionality X-Git-Tag: v260-rc1~33^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fcd11d56c52b293a9d77e2bda1614308f1d8a4b;p=thirdparty%2Fsystemd.git resolved: Add test for ifindex=0 BrowseServices functionality Add integration tests for the new ifindex=0 support in BrowseServices that allows browsing all mDNS interfaces. Integration test (in TEST-89-RESOLVED-MDNS.sh): - testcase_browse_all_interfaces_ifindex_zero: Test with ifindex=0 Assisted-by: Claude Opus 4.5 (Preview) --- diff --git a/test/units/TEST-89-RESOLVED-MDNS.sh b/test/units/TEST-89-RESOLVED-MDNS.sh index ae18cd49e8a..8e8c4e38a97 100755 --- a/test/units/TEST-89-RESOLVED-MDNS.sh +++ b/test/units/TEST-89-RESOLVED-MDNS.sh @@ -193,6 +193,50 @@ testcase_single_service_multiple_times() { done } +# Helper function to run browse services with a custom ifindex +run_and_check_services_with_ifindex() { + local service_id="${1:?}" + local check_func="${2:?}" + local ifindex="${3:?}" + local unit_name="varlinkctl-$service_id-$SRANDOM.service" + local i out_file parameters service_type svc tmp_file + + out_file="$(mktemp)" + error_file="$(mktemp)" + tmp_file="$(mktemp)" + service_type="_testService$service_id._udp" + parameters="{ \"domain\": \"$service_type.local\", \"type\": \"\", \"ifindex\": $ifindex, \"flags\": 16785432 }" + + systemd-run --unit="$unit_name" --service-type=exec -p StandardOutput="file:$out_file" -p StandardError="file:$error_file" \ + varlinkctl call --more /run/systemd/resolve/io.systemd.Resolve io.systemd.Resolve.BrowseServices "$parameters" + + # shellcheck disable=SC2064 + # Note: same as above about unregistering the trap once it's fired + trap "trap - RETURN; systemctl stop $unit_name" RETURN + + for _ in {0..14}; do + if [[ -s "$out_file" ]]; then + grep -o '"name":"[^"]*"' "$out_file" | sed 's/"name":"//;s/"//g' | sort | tee "$tmp_file" + if "$check_func" "$service_id" "$tmp_file"; then + return 0 + fi + fi + + sleep 2 + done + + cat "$out_file" + cat "$error_file" + return 1 +} + +testcase_browse_all_interfaces_ifindex_zero() { + : "Test browsing all interfaces with ifindex=0" + resolvectl flush-caches + # Using ifindex=0 should discover services on all mDNS interfaces + run_and_check_services_with_ifindex 0 check_both 0 +} + testcase_second_unreachable() { : "Test each service type while the second container is unreachable" systemd-run -M "$CONTAINER_2" --wait --pipe -- networkctl down host0