From ae176509145ba1db766e30aac55e1ef62ff902aa Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 29 Feb 2020 23:28:50 +0100 Subject: [PATCH 1/4] bpo-35569: Expose RFC 3542 socket options on macOS From macOS SDK netinet6/in6.h: RFC 3542 define the following socket options in a manner incompatible with RFC 2292: IPV6_PKTINFO IPV6_HOPLIMIT IPV6_NEXTHOP IPV6_HOPOPTS IPV6_DSTOPTS IPV6_RTHDR To use the new IPv6 Sockets options introduced by RFC 3542 the constant __APPLE_USE_RFC_3542 must be defined before including [...] Note that eventually RFC 3542 is going to be the default and RFC 2292 will be obsolete. --- .../NEWS.d/next/macOS/2020-04-15-00-02-47.bpo-35569.02_1MV.rst | 1 + configure | 3 +++ configure.ac | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/macOS/2020-04-15-00-02-47.bpo-35569.02_1MV.rst diff --git a/Misc/NEWS.d/next/macOS/2020-04-15-00-02-47.bpo-35569.02_1MV.rst b/Misc/NEWS.d/next/macOS/2020-04-15-00-02-47.bpo-35569.02_1MV.rst new file mode 100644 index 00000000000000..ed48efd7f5c492 --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2020-04-15-00-02-47.bpo-35569.02_1MV.rst @@ -0,0 +1 @@ +Expose RFC 3542 IPv6 socket options. diff --git a/configure b/configure index 29d5f4ce667352..38d48cdcae3e7e 100755 --- a/configure +++ b/configure @@ -7421,6 +7421,9 @@ $as_echo "$ac_cv_enable_visibility" >&6; } ;; Darwin*) + # Issue #35569: Expose the RFC 3542 socket options. + CFLAGS="-D__APPLE_USE_RFC_3542 ${CFLAGS}" + # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd # used to be here, but non-Apple gcc doesn't accept them. if test "${CC}" = gcc diff --git a/configure.ac b/configure.ac index 240ddeb9b3d22d..51702bae4ab35d 100644 --- a/configure.ac +++ b/configure.ac @@ -1844,6 +1844,9 @@ yes) ;; Darwin*) + # Issue #35569: Expose the RFC 3542 socket options. + CFLAGS="-D__APPLE_USE_RFC_3542 ${CFLAGS}" + # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd # used to be here, but non-Apple gcc doesn't accept them. if test "${CC}" = gcc From fe71bb755bae8a6134fad4c1d8734c7faf74cfb1 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 13 Apr 2020 20:41:41 +0200 Subject: [PATCH 2/4] bpo-35569: Add unit tests --- Lib/test/test_socket.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index a70e28219ed23d..c4c7ec1ce20b64 100755 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -947,6 +947,37 @@ def testWindowsSpecificConstants(self): socket.IPPROTO_L2TP socket.IPPROTO_SCTP + @unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test') + @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test') + def test3542SocketOptions(self): + # Ref. issue #35569 and https://tools.ietf.org/html/rfc3542 + opts = { + 'IPV6_CHECKSUM', + 'IPV6_DONTFRAG', + 'IPV6_DSTOPTS', + 'IPV6_HOPLIMIT', + 'IPV6_HOPOPTS', + 'IPV6_NEXTHOP', + 'IPV6_PATHMTU', + 'IPV6_PKTINFO', + 'IPV6_RECVDSTOPTS', + 'IPV6_RECVHOPLIMIT', + 'IPV6_RECVHOPOPTS', + 'IPV6_RECVPATHMTU', + 'IPV6_RECVPKTINFO', + 'IPV6_RECVRTHDR', + 'IPV6_RECVTCLASS', + 'IPV6_RTHDR', + 'IPV6_RTHDRDSTOPTS', + 'IPV6_RTHDR_TYPE_0', + 'IPV6_TCLASS', + 'IPV6_USE_MIN_MTU', + } + for opt in opts: + self.assertTrue( + hasattr(socket, opt), f"Missing RFC3542 socket option '{opt}'" + ) + def testHostnameRes(self): # Testing hostname resolution mechanisms hostname = socket.gethostname() From ebfde1f29f11a2041ba38757ba9e9a87fd261ec4 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 27 Apr 2020 11:01:48 +0200 Subject: [PATCH 3/4] Use `socket_helper` (see PR #19603) --- Lib/test/test_socket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index c4c7ec1ce20b64..976c7fc5e30e0b 100755 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -948,7 +948,7 @@ def testWindowsSpecificConstants(self): socket.IPPROTO_SCTP @unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test') - @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test') + @unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test') def test3542SocketOptions(self): # Ref. issue #35569 and https://tools.ietf.org/html/rfc3542 opts = { From f6bda5d49fef82ad424e5b85e6e7fa29a2bc3cfd Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 27 Apr 2020 11:41:35 +0200 Subject: [PATCH 4/4] Only define __APPLE_USE_RFC_3542 when building socket lib --- configure | 3 --- configure.ac | 3 --- setup.py | 8 ++++++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 38d48cdcae3e7e..29d5f4ce667352 100755 --- a/configure +++ b/configure @@ -7421,9 +7421,6 @@ $as_echo "$ac_cv_enable_visibility" >&6; } ;; Darwin*) - # Issue #35569: Expose the RFC 3542 socket options. - CFLAGS="-D__APPLE_USE_RFC_3542 ${CFLAGS}" - # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd # used to be here, but non-Apple gcc doesn't accept them. if test "${CC}" = gcc diff --git a/configure.ac b/configure.ac index 51702bae4ab35d..240ddeb9b3d22d 100644 --- a/configure.ac +++ b/configure.ac @@ -1844,9 +1844,6 @@ yes) ;; Darwin*) - # Issue #35569: Expose the RFC 3542 socket options. - CFLAGS="-D__APPLE_USE_RFC_3542 ${CFLAGS}" - # -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd # used to be here, but non-Apple gcc doesn't accept them. if test "${CC}" = gcc diff --git a/setup.py b/setup.py index 878372154d411a..5b8ec707fcf020 100644 --- a/setup.py +++ b/setup.py @@ -1094,8 +1094,12 @@ def detect_crypt(self): def detect_socket(self): # socket(2) if not VXWORKS: - self.add(Extension('_socket', ['socketmodule.c'], - depends=['socketmodule.h'])) + kwargs = {'depends': ['socketmodule.h']} + if MACOS: + # Issue #35569: Expose RFC 3542 socket options. + kwargs['extra_compile_args'] = ['-D__APPLE_USE_RFC_3542'] + + self.add(Extension('_socket', ['socketmodule.c'], **kwargs)) elif self.compiler.find_library_file(self.lib_dirs, 'net'): libs = ['net'] self.add(Extension('_socket', ['socketmodule.c'],