diff options
author | Arne Schwabe <arne@rfc2549.org> | 2014-02-02 18:32:53 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2014-02-02 18:32:53 +0100 |
commit | bb0889f1cd2d9e9bd73b52d9dcf6f75f903dd67b (patch) | |
tree | 5a5ba9dbe492db96b6ae2a4788904a84bbfa08f9 /src | |
parent | 83a741a917e56f1d6079a95394f72a2c7cf709ed (diff) |
Make block-local feature under 4.3
Diffstat (limited to 'src')
-rw-r--r-- | src/de/blinkt/openvpn/core/NetworkSpace.java | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/de/blinkt/openvpn/core/NetworkSpace.java b/src/de/blinkt/openvpn/core/NetworkSpace.java index 821565b8..c7d09065 100644 --- a/src/de/blinkt/openvpn/core/NetworkSpace.java +++ b/src/de/blinkt/openvpn/core/NetworkSpace.java @@ -1,5 +1,6 @@ package de.blinkt.openvpn.core; +import android.os.Build; import android.text.TextUtils; import java.math.BigInteger; @@ -137,12 +138,12 @@ public class NetworkSpace { } - TreeSet<ipAddress> ipAddresses = new TreeSet<ipAddress>(); + TreeSet<ipAddress> mIpAddresses = new TreeSet<ipAddress>(); public Collection<ipAddress> getNetworks(boolean included) { Vector<ipAddress> ips = new Vector<ipAddress>(); - for (ipAddress ip : ipAddresses) { + for (ipAddress ip : mIpAddresses) { if (ip.included == included) ips.add(ip); } @@ -150,21 +151,21 @@ public class NetworkSpace { } public void clear() { - ipAddresses.clear(); + mIpAddresses.clear(); } void addIP(CIDRIP cidrIp, boolean include) { - ipAddresses.add(new ipAddress(cidrIp, include)); + mIpAddresses.add(new ipAddress(cidrIp, include)); } void addIPv6(Inet6Address address, int mask, boolean included) { - ipAddresses.add(new ipAddress(address, mask, included)); + mIpAddresses.add(new ipAddress(address, mask, included)); } TreeSet<ipAddress> generateIPList() { - TreeSet<ipAddress> ipsSorted = new TreeSet<ipAddress>(ipAddresses); + TreeSet<ipAddress> ipsSorted = new TreeSet<ipAddress>(mIpAddresses); Iterator<ipAddress> it = ipsSorted.iterator(); ipAddress currentNet = null; @@ -238,6 +239,35 @@ public class NetworkSpace { if (ia.included) ips.add(ia); } + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + // Include postive routes from the original set under < 4.4 since these might overrule the local + // network but only if no smaller negative route exists + for(ipAddress origIp: mIpAddresses){ + if (!origIp.included) + continue; + + // The netspace exists + if(ipsSorted.contains(origIp)) + continue; + + boolean skipIp=false; + // If there is any smaller net that is excluded we may not add the positive route back + for (ipAddress calculatedIp: ipsSorted) { + if(!calculatedIp.included && origIp.containsNet(calculatedIp)) { + skipIp=true; + break; + } + } + if (skipIp) + continue; + + // It is safe to include the IP + ips.add(origIp); + } + + } + return ips; } |