8222562: Don't set IPV6_V6ONLY when IPv4 is not available

Reviewed-by: dfuchs, chegar
This commit is contained in:
Arthur Eubanks 2019-04-16 13:16:49 -07:00 committed by Arthur Eubanks
parent 6f8821cadc
commit 0465104af6
7 changed files with 37 additions and 6 deletions

View file

@ -915,8 +915,10 @@ Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
return;
}
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
/*
* If IPv4 is available, disable IPV6_V6ONLY to ensure dual-socket support.
*/
if (domain == AF_INET6 && ipv4_available()) {
arg = 0;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
sizeof(int)) < 0) {

View file

@ -187,8 +187,10 @@ Java_java_net_PlainSocketImpl_socketCreate(JNIEnv *env, jobject this,
return;
}
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
/*
* If IPv4 is available, disable IPV6_V6ONLY to ensure dual-socket support.
*/
if (domain == AF_INET6 && ipv4_available()) {
int arg = 0;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
sizeof(int)) < 0) {

View file

@ -278,6 +278,16 @@ NET_GetFileDescriptorID(JNIEnv *env)
return (*env)->GetFieldID(env, cls, "fd", "I");
}
jint IPv4_supported()
{
int fd = socket(AF_INET, SOCK_STREAM, 0) ;
if (fd < 0) {
return JNI_FALSE;
}
close(fd);
return JNI_TRUE;
}
#if defined(DONT_ENABLE_IPV6)
jint IPv6_supported()
{

View file

@ -216,8 +216,10 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
return handleSocketError(env, errno);
}
/* Disable IPV6_V6ONLY to ensure dual-socket support */
if (domain == AF_INET6) {
/*
* If IPv4 is available, disable IPV6_V6ONLY to ensure dual-socket support.
*/
if (domain == AF_INET6 && ipv4_available()) {
int arg = 0;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
sizeof(int)) < 0) {