AdVpnThread implements Runnable, DnsPacketProxy.EventLoop { boolean hasIpV6Servers(Configuration config, List<InetAddress> dnsServers) { if (!config.ipV6Support) return false; if (config.dnsServers.enabled) { for (Configuration.Item item : config.dnsServers.items) { if (item.state == Configuration.Item.STATE_ALLOW && item.location.contains(":")) return true; } } for (InetAddress inetAddress : dnsServers) { if (inetAddress instanceof Inet6Address) return true; } return false; } AdVpnThread(VpnService vpnService, Notify notify); void startThread(); void stopThread(); @Override synchronized void run(); void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket); void queueDeviceWrite(IpPacket ipOutPacket);  }
@Test public void testHasIpV6Servers() throws Exception { Configuration.Item item0 = new Configuration.Item(); Configuration.Item item1 = new Configuration.Item(); config.ipV6Support = true; config.dnsServers.enabled = true; config.dnsServers.items.add(item0); config.dnsServers.items.add(item1); item0.location = "::1"; item0.state = Configuration.Item.STATE_ALLOW; item1.location = "127.0.0.1"; item1.state = Configuration.Item.STATE_ALLOW; List<InetAddress> servers = new ArrayList<>(); assertTrue(thread.hasIpV6Servers(config, servers)); config.ipV6Support = false; assertFalse(thread.hasIpV6Servers(config, servers)); config.ipV6Support = true; item0.state = Configuration.Item.STATE_DENY; assertFalse(thread.hasIpV6Servers(config, servers)); servers.add(Inet6Address.getByName("127.0.0.1")); assertFalse(thread.hasIpV6Servers(config, servers)); servers.add(Inet6Address.getByName("::1")); assertTrue(thread.hasIpV6Servers(config, servers)); }