Skip to content

Fix address-family matching in Linux ss socket checks - #828

Open
Aathi-27 wants to merge 5 commits into
pytest-dev:mainfrom
Aathi-27:fix/ss-ipv6-only-listening
Open

Aathi-27 wants to merge 5 commits into
pytest-dev:mainfrom
Aathi-27:fix/ss-ipv6-only-listening

Conversation

@Aathi-27

@Aathi-27 Aathi-27 commented Nov 8, 2026

Copy link
Copy Markdown

What does this PR do?

Prevents an IPv6-only wildcard listener from satisfying an IPv4 socket check in the Linux ss backend.

For TCP, ss distinguishes an IPv6-only listener ([::]:port) from a dual-stack listener (*:port). The parser already expands the dual-stack form into both families. The inherited matcher nevertheless treats any IPv6 wildcard as enough, even for an explicit IPv4 spec.

The Linux ss backend now matches wildcards to the requested address family. A host-less spec requires both wildcard families, as documented. Exact-address and Unix-socket checks are preserved. Netstat and BSD behavior is unchanged.

Issue

Partially addresses #827: verified for TCP on Linux with iproute2 5.15.

UDP is not fully fixed: this ss version prints * for both IPv6-only and dual-stack UDP sockets, so the existing parser cannot distinguish them. Older ss wildcard ambiguity from #389 is also outside this patch.

Validation

  • All 15 new tests pass on Python 3.10.12 and 3.12.15.
  • Without the fix, five new tests fail and ten pass, including failure of the real IPv6-only TCP listener test.
  • Real TCP tests cover IPV6_V6ONLY on and off and check direct IPv4 connection refusal/success alongside testinfra's results. Synthetic ss tests cover both protocols, wildcard and exact addresses, host-less specs, wrong ports and Unix sockets. Synthetic UDP cases are matcher coverage, not proof the UDP ambiguity is fixed.
  • Ruff 0.17.3 passes for both changed files; git diff --check passes.
  • Full local suite comparison: baseline 29 failed / 59 passed / 108 skipped; patched 24 failed / 64 passed / 108 skipped. The same 24 unrelated environment-dependent failures remain; no new failures. Docker-backed integration tests were not run.

@Aathi-27

Copy link
Copy Markdown
Author

When you have time, could a maintainer review the TCP address-family fix for #827 and approve the pending CI run? I saw the maintenance notice and understand review may take time. Thanks.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant