This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.0.x by this push: new f1db089 Simplify AprEndpoint socket bind for all platforms f1db089 is described below commit f1db08931a27f808f4cbe235ee92cc22545e5757 Author: Michael Osipov <micha...@apache.org> AuthorDate: Sat May 22 13:36:57 2021 +0200 Simplify AprEndpoint socket bind for all platforms * Unconditionally use APR_UNSPEC on all platforms and especially on *BSD which runs fine on IPv4 and IPv6 hosts. * Apply IPV6_V6ONLY only if libapr has been compiled with IPv6 support and the socket address is of family APR_INET6. This mimics the behavior of HTTPd's listen.c for apr_sockaddr_info_get() along with open_listeners() and make_sock() with IPV6_V6ONLY flag. --- java/org/apache/tomcat/util/net/AprEndpoint.java | 16 ++++------------ test/org/apache/tomcat/util/net/TestXxxEndpoint.java | 8 +------- webapps/docs/changelog.xml | 3 +++ 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index b388d04..d11d69a 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -351,16 +351,7 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB if (getAddress() != null) { hostname = getAddress().getHostAddress(); } - family = Socket.APR_INET; - if (Library.APR_HAVE_IPV6) { - if (hostname == null) { - if (!OS.IS_BSD) { - family = Socket.APR_UNSPEC; - } - } else if (hostname.indexOf(':') >= 0) { - family = Socket.APR_UNSPEC; - } - } + family = Socket.APR_UNSPEC; } long sockAddress = Address.info(hostname, family, getPortWithOffset(), 0, rootPool); @@ -370,13 +361,14 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB serverSock = Socket.create(family, Socket.SOCK_STREAM, 0, rootPool); } else { - serverSock = Socket.create(Address.getInfo(sockAddress).family, + int saFamily = Address.getInfo(sockAddress).family; + serverSock = Socket.create(saFamily, Socket.SOCK_STREAM, Socket.APR_PROTO_TCP, rootPool); if (OS.IS_UNIX) { Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1); } - if (Library.APR_HAVE_IPV6) { + if (Library.APR_HAVE_IPV6 && saFamily == Socket.APR_INET6) { if (getIpv6v6only()) { Socket.optSet(serverSock, Socket.APR_IPV6_V6ONLY, 1); } else { diff --git a/test/org/apache/tomcat/util/net/TestXxxEndpoint.java b/test/org/apache/tomcat/util/net/TestXxxEndpoint.java index d77132f..1bdd1b1 100644 --- a/test/org/apache/tomcat/util/net/TestXxxEndpoint.java +++ b/test/org/apache/tomcat/util/net/TestXxxEndpoint.java @@ -68,13 +68,7 @@ public class TestXxxEndpoint extends TomcatBaseTest { String address = InetAddress.getByName("localhost").getHostAddress(); // Create the APR address that will be bound - int family = org.apache.tomcat.jni.Socket.APR_INET; - if (Library.APR_HAVE_IPV6) { - if (!org.apache.tomcat.jni.OS.IS_BSD && !org.apache.tomcat.jni.OS.IS_WIN32 && - !org.apache.tomcat.jni.OS.IS_WIN64) { - family = org.apache.tomcat.jni.Socket.APR_UNSPEC; - } - } + int family = org.apache.tomcat.jni.Socket.APR_UNSPEC; long inetAddress = 0; try { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index c2c3b5a..ba7c4b2 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -148,6 +148,9 @@ an error occurs on an HTTP/1.1 connection being upgraded to HTTP/2 or on a pushed HTTP/2 stream. (markt) </fix> + <update> + Simplify AprEndpoint socket bind for all platforms. (michaelo) + </update> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org