Added internal network redirect. Fixed #4

This commit is contained in:
PeratX 2017-05-20 13:23:50 +08:00
parent 9ea61b0b95
commit a528add071
2 changed files with 17 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import android.util.Log;
import de.measite.minidns.DNSMessage;
import de.measite.minidns.Record;
import de.measite.minidns.record.A;
import de.measite.minidns.util.InetAddressUtil;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.DnsServerHelper;
import org.itxtech.daedalus.util.RulesResolver;
@ -309,6 +310,7 @@ public class UdpDnsProvider extends DnsProvider {
InetAddress destAddr = parsedPacket.getHeader().getDstAddr();
if (destAddr == null)
return;
destAddr = InetAddressUtil.ipv4From(service.dnsServers.get(destAddr.getHostAddress()));
UdpPacket parsedUdp = (UdpPacket) parsedPacket.getPayload();

View File

@ -23,6 +23,7 @@ import org.itxtech.daedalus.util.DnsServerHelper;
import org.itxtech.daedalus.util.RulesResolver;
import java.net.Inet4Address;
import java.util.HashMap;
/**
* Daedalus Project
@ -56,6 +57,8 @@ public class DaedalusVpnService extends VpnService implements Runnable {
private Thread mThread = null;
public HashMap<String, String> dnsServers;
@Override
public void onCreate() {
super.onCreate();
@ -180,15 +183,24 @@ public class DaedalusVpnService extends VpnService implements Runnable {
} catch (IllegalArgumentException e) {
continue;
}
format = prefix;
format = prefix + ".%d";
break;
}
boolean advanced = Daedalus.getPrefs().getBoolean("settings_advanced_switch", false);
statisticQuery = Daedalus.getPrefs().getBoolean("settings_count_query_times", false);
Log.d(TAG, "tun0 add " + format + " pServ " + primaryServer + " sServ " + secondaryServer);
Inet4Address primaryDNSServer = InetAddressUtil.ipv4From(primaryServer);
Inet4Address secondaryDNSServer = InetAddressUtil.ipv4From(secondaryServer);
dnsServers = new HashMap<>();
String aliasPrimary = String.format(format, dnsServers.size() + 1);
dnsServers.put(aliasPrimary, primaryServer);
String aliasSecondary = String.format(format, dnsServers.size() + 1);
dnsServers.put(aliasSecondary, secondaryServer);
Inet4Address primaryDNSServer = InetAddressUtil.ipv4From(aliasPrimary);
Inet4Address secondaryDNSServer = InetAddressUtil.ipv4From(aliasSecondary);
Log.d(TAG, "listening on " + format + " pServ " + primaryDNSServer.getHostAddress() + " sServ " + secondaryDNSServer.getHostAddress());
builder.setSession("Daedalus")
.addDnsServer(primaryDNSServer)
.addDnsServer(secondaryDNSServer)