It seems that the topic is interesting for others as well, so I am describing my current solution.
- The software detects whether IPv6 is working or not, and remembers the state β This is done by connecting TCP to a known IPv6 address (Ping of isReachable () is not reliable, see this error report: https://josm.openstreetmap.de/ ticket / 11452 ).
- Based on the memorized state, the software starts with "java.net.preferIPv6Addresses" set to true.
- This means that to migrate from IPv4 to an IPv6 network, it will use IPv4 until the next restart, which is normal.
- To switch from IPv6, which is included in the network only with IPv4, it will not work at all, which will be allowed by restarting the software.
- If in doubt, assume that IPv6 is not working.
- It is not possible to change "java.net.preferIPv6Addresses" after detection, since these values ββseem to be read only until the first network connection. If at runtime there is a reset method that I would like to know about it.
This solution works, we have about 4% of IPv6 connections in our ATM logs, but this is actually not a satisfactory solution.
private static void checkIPv6() { if ("auto".equals(Main.pref.get("prefer.ipv6", "auto"))) { new Thread(new Runnable() { public void run() { boolean hasv6 = false; boolean wasv6 = Main.pref.getBoolean("validated.ipv6", false); try { if (wasv6) { Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true"); } for (InetAddress a : InetAddress.getAllByName("josm.openstreetmap.de")) { if (a instanceof Inet6Address) { if (a.isReachable(1000)) { Socket s = new Socket(); s.connect(new InetSocketAddress(a, 80), 1000); s.close(); Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true"); if (!wasv6) { Main.info(tr("Detected useable IPv6 network, prefering IPv6 over IPv4 after next restart.")); } else { Main.info(tr("Detected useable IPv6 network, prefering IPv6 over IPv4.")); } hasv6 = true; } break; } } } catch (IOException | SecurityException e) { if (Main.isDebugEnabled()) { Main.debug("Exception while checking IPv6 connectivity: "+e); } } if (wasv6 && !hasv6) { Main.info(tr("Detected no useable IPv6 network, prefering IPv4 over IPv6 after next restart.")); Main.pref.put("validated.ipv6", hasv6);
Dirk stΓΆcker
source share