From bb0889f1cd2d9e9bd73b52d9dcf6f75f903dd67b Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sun, 2 Feb 2014 18:32:53 +0100 Subject: Make block-local feature under 4.3 --- src/de/blinkt/openvpn/core/NetworkSpace.java | 42 ++++++++++++++++++++++++---- 1 file 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 ipAddresses = new TreeSet(); + TreeSet mIpAddresses = new TreeSet(); public Collection getNetworks(boolean included) { Vector ips = new Vector(); - 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 generateIPList() { - TreeSet ipsSorted = new TreeSet(ipAddresses); + TreeSet ipsSorted = new TreeSet(mIpAddresses); Iterator 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; } -- cgit v1.2.3