Fixed IPv6 internal NAT

This commit is contained in:
PeratX 2017-07-06 15:11:04 +08:00
parent 9c4e5361f4
commit 3cffe55387
2 changed files with 25 additions and 6 deletions

View File

@ -244,12 +244,12 @@ public class UdpProvider extends Provider {
* @param responsePayload The payload of the response * @param responsePayload The payload of the response
*/ */
void handleDnsResponse(IpPacket requestPacket, byte[] responsePayload) { void handleDnsResponse(IpPacket requestPacket, byte[] responsePayload) {
try { /*try {
DNSMessage message = new DNSMessage(responsePayload); DNSMessage message = new DNSMessage(responsePayload);
Logger.info(message.toString()); Logger.info(message.toString());
} catch (IOException e) { } catch (IOException e) {
Logger.logException(e); Logger.logException(e);
} }*/
UdpPacket udpOutPacket = (UdpPacket) requestPacket.getPayload(); UdpPacket udpOutPacket = (UdpPacket) requestPacket.getPayload();
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder(udpOutPacket) UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder(udpOutPacket)
.srcPort(udpOutPacket.getHeader().getDstPort()) .srcPort(udpOutPacket.getHeader().getDstPort())

View File

@ -10,6 +10,7 @@ import android.net.VpnService;
import android.os.Build; import android.os.Build;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.support.v7.app.NotificationCompat; import android.support.v7.app.NotificationCompat;
import android.system.OsConstants;
import android.util.Log; import android.util.Log;
import org.itxtech.daedalus.Daedalus; import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R; import org.itxtech.daedalus.R;
@ -181,17 +182,18 @@ public class DaedalusVpnService extends VpnService implements Runnable {
private InetAddress addDnsServer(Builder builder, String format, byte[] ipv6Template, InetAddress address) throws UnknownHostException { private InetAddress addDnsServer(Builder builder, String format, byte[] ipv6Template, InetAddress address) throws UnknownHostException {
int size = dnsServers.size(); int size = dnsServers.size();
size++; size++;
if (address instanceof Inet4Address) { if (address instanceof Inet6Address && ipv6Template == null) {
Log.i(TAG, "addDnsServer: Ignoring DNS server " + address);
} else if (address instanceof Inet4Address) {
String alias = String.format(format, size + 1); String alias = String.format(format, size + 1);
dnsServers.put(alias, address.getHostAddress()); dnsServers.put(alias, address.getHostAddress());
builder.addRoute(alias, 32); builder.addRoute(alias, 32);
return InetAddress.getByName(alias); return InetAddress.getByName(alias);
} else if (address instanceof Inet6Address) { } else if (address instanceof Inet6Address) {
/*ipv6Template[ipv6Template.length - 1] = (byte) (size + 1); ipv6Template[ipv6Template.length - 1] = (byte) (size + 1);
InetAddress i6addr = Inet6Address.getByAddress(ipv6Template); InetAddress i6addr = Inet6Address.getByAddress(ipv6Template);
dnsServers.put(i6addr.getHostAddress(), address.getHostAddress()); dnsServers.put(i6addr.getHostAddress(), address.getHostAddress());
return i6addr;*/ return i6addr;
return address;
} }
return null; return null;
} }
@ -221,6 +223,20 @@ public class DaedalusVpnService extends VpnService implements Runnable {
statisticQuery = Daedalus.getPrefs().getBoolean("settings_count_query_times", false); statisticQuery = Daedalus.getPrefs().getBoolean("settings_count_query_times", false);
byte[] ipv6Template = new byte[]{32, 1, 13, (byte) (184 & 0xFF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; byte[] ipv6Template = new byte[]{32, 1, 13, (byte) (184 & 0xFF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (primaryServer.contains(":") || secondaryServer.contains(":")) {//IPv6
try {
InetAddress addr = Inet6Address.getByAddress(ipv6Template);
Log.d(TAG, "configure: Adding IPv6 address" + addr);
builder.addAddress(addr, 120);
} catch (Exception e) {
e.printStackTrace();
ipv6Template = null;
}
} else {
ipv6Template = null;
}
InetAddress aliasPrimary; InetAddress aliasPrimary;
InetAddress aliasSecondary; InetAddress aliasSecondary;
if (advanced) { if (advanced) {
@ -242,6 +258,9 @@ public class DaedalusVpnService extends VpnService implements Runnable {
builder.setBlocking(true); builder.setBlocking(true);
} }
builder.allowFamily(OsConstants.AF_INET);
builder.allowFamily(OsConstants.AF_INET6);
descriptor = builder.establish(); descriptor = builder.establish();
Logger.info("Daedalus VPN service is started"); Logger.info("Daedalus VPN service is started");