8241336: Some java.net tests failed with NoRouteToHostException on MacOS with special network configuration

NetworkConfiguration updated to skip interfaces that have only IPv6 link local addresses.

Reviewed-by: alanb, chegar
This commit is contained in:
Daniel Fuchs 2020-03-27 12:42:03 +00:00
parent bb7a8f643f
commit 5ddbcb7a51
5 changed files with 114 additions and 52 deletions

View file

@ -32,7 +32,11 @@
import java.io.IOException;
import static java.lang.System.out;
import java.io.UncheckedIOException;
import java.net.*;
import jdk.test.lib.NetworkConfiguration;
import jdk.test.lib.net.IPSupport;
public class Promiscuous {
@ -69,8 +73,9 @@ public class Promiscuous {
}
} catch (SocketTimeoutException e) {
if (datagramExpected)
throw new RuntimeException("Expected message not received, "
+ e.getMessage());
throw new RuntimeException(mc.getLocalSocketAddress()
+ ": Expected message not received, "
+ e.getMessage());
else
out.printf("Message not received, as expected\n");
}
@ -90,6 +95,10 @@ public class Promiscuous {
UUID = "<" + s1 + s2 + ">";
}
static SocketAddress toSocketAddress(InetAddress group) {
return new InetSocketAddress(group, 0);
}
static void test(InetAddress group1, InetAddress group2)
throws IOException
{
@ -107,10 +116,21 @@ public class Promiscuous {
p.setAddress(group1);
p.setPort(port);
mc1.joinGroup(group1);
out.printf("mc1 joined the MC group: %s\n", group1);
mc2.joinGroup(group2);
out.printf("mc2 joined the MC group: %s\n", group2);
// join groups on all network interfaces
NetworkConfiguration.probe()
.multicastInterfaces(false)
.forEach((nic) -> {
try {
mc1.joinGroup(toSocketAddress(group1), nic);
out.printf("mc1 joined the MC group on %s: %s\n",
nic.getDisplayName(), group1);
mc2.joinGroup(toSocketAddress(group2), nic);
out.printf("mc2 joined the MC group on %s: %s\n",
nic.getDisplayName(), group2);
} catch (IOException io) {
throw new UncheckedIOException(io);
}
});
out.printf("Sending datagram to: %s/%d\n", group1, port);
ds.send(p);
@ -132,8 +152,21 @@ public class Promiscuous {
receive(mc2, true, nextId);
receive(mc1, false, 0);
mc1.leaveGroup(group1);
mc2.leaveGroup(group2);
// leave groups on all network interfaces
NetworkConfiguration.probe()
.multicastInterfaces(false)
.forEach((nic) -> {
try {
mc1.leaveGroup(toSocketAddress(group1), nic);
out.printf("mc1 left the MC group on %s: %s\n",
nic.getDisplayName(), group1);
mc2.leaveGroup(toSocketAddress(group2), nic);
out.printf("mc2 left the MC group on %s: %s\n",
nic.getDisplayName(), group2);
} catch (IOException io) {
throw new UncheckedIOException(io);
}
});
}
}
@ -155,8 +188,8 @@ public class Promiscuous {
}
// multicast groups used for the test
InetAddress ip4Group1 = InetAddress.getByName("224.0.0.120");
InetAddress ip4Group2 = InetAddress.getByName("224.0.0.121");
InetAddress ip4Group1 = InetAddress.getByName("224.1.1.120");
InetAddress ip4Group2 = InetAddress.getByName("224.1.1.121");
test(ip4Group1, ip4Group2);
}

View file

@ -24,15 +24,27 @@
/*
* @test
* @bug 4742177
* @library /test/lib
* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
*/
import java.io.IOException;
import java.net.*;
import java.util.*;
import jdk.test.lib.NetworkConfiguration;
public class SetOutgoingIf {
private static int PORT = 9001;
public class SetOutgoingIf implements AutoCloseable {
private static String osname;
private final MulticastSocket SOCKET;
private final int PORT;
private SetOutgoingIf() {
try {
SOCKET = new MulticastSocket();
PORT = SOCKET.getLocalPort();
} catch (IOException io) {
throw new ExceptionInInitializerError(io);
}
}
static boolean isWindows() {
if (osname == null)
@ -45,20 +57,24 @@ public class SetOutgoingIf {
}
private static boolean hasIPv6() throws Exception {
List<NetworkInterface> nics = Collections.list(
NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nic : nics) {
List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
for (InetAddress addr : addrs) {
if (addr instanceof Inet6Address)
return true;
}
}
return false;
return NetworkConfiguration.probe()
.ip6Addresses()
.findAny()
.isPresent();
}
public static void main(String[] args) throws Exception {
try (var test = new SetOutgoingIf()) {
test.run();
}
}
@Override
public void close() {
SOCKET.close();
}
public void run() throws Exception {
if (isWindows()) {
System.out.println("The test only run on non-Windows OS. Bye.");
return;
@ -99,11 +115,14 @@ public class SetOutgoingIf {
System.out.println("Ignore NetworkInterface nic == " + nic);
}
}
Collections.reverse(netIfs);
if (netIfs.size() <= 1) {
System.out.println("Need 2 or more network interfaces to run. Bye.");
return;
}
System.out.println("Using PORT: " + PORT);
// We will send packets to one ipv4, and one ipv6
// multicast group using each network interface :-
// 224.1.1.1 --|
@ -177,12 +196,8 @@ public class SetOutgoingIf {
}
private static boolean isTestExcludedInterface(NetworkInterface nif) {
if (isMacOS() && nif.getName().contains("awdl"))
return true;
String dName = nif.getDisplayName();
if (isWindows() && dName != null && dName.contains("Teredo"))
return true;
return false;
return !NetworkConfiguration.isTestable(nif)
|| isMacOS() && nif.getName().startsWith("utun");
}
private static boolean debug = true;
@ -281,4 +296,3 @@ class NetIf {
this.groups = groups;
}
}