]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-154291: Fix socket.has_dualstack_ipv6() on DragonFly BSD (GH-154292) (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 20 Jul 2026 20:25:57 +0000 (22:25 +0200)
committerGitHub <noreply@github.com>
Mon, 20 Jul 2026 20:25:57 +0000 (20:25 +0000)
On DragonFly BSD setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0) succeeds without
actually clearing the flag, so has_dualstack_ipv6() wrongly returned True.
Verify with getsockopt() that IPV6_V6ONLY was cleared.
(cherry picked from commit c7bbf040e721781be8f11a3b0716220835d4de2f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Lib/socket.py
Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst [new file with mode: 0644]

index bbb476f2fc010e2e3178b97d1253b26f30f7e900..9ac0badc6606c19d9044dae32d987c1f8187bf71 100644 (file)
@@ -891,7 +891,9 @@ def has_dualstack_ipv6():
     try:
         with socket(AF_INET6, SOCK_STREAM) as sock:
             sock.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0)
-            return True
+            # On some platforms (e.g. DragonFly BSD) setting IPV6_V6ONLY to 0
+            # silently has no effect, so check that it was actually cleared.
+            return sock.getsockopt(IPPROTO_IPV6, IPV6_V6ONLY) == 0
     except error:
         return False
 
diff --git a/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst b/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst
new file mode 100644 (file)
index 0000000..d962f89
--- /dev/null
@@ -0,0 +1,3 @@
+Fix :func:`socket.has_dualstack_ipv6` to return ``False`` on platforms such as
+DragonFly BSD where setting ``IPV6_V6ONLY`` to 0 silently has no
+effect.