From 5dc503314511f3041b4674569ba03c10714f7625 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 26 Nov 2014 00:04:25 +0100 Subject: Implement getting local interfaces via native API and without OpenVPN. Fixes allow local LAN on Android 5.0 --HG-- extra : rebase_source : ac79c41800905f3aeb23ce49a617ab226a6473c0 --- .../main/java/de/blinkt/openvpn/VpnProfile.java | 5 ---- .../de/blinkt/openvpn/core/OpenVPNService.java | 28 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'main/src') diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java index 4b483b8f..c8cf7ac8 100644 --- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -398,11 +398,6 @@ public class VpnProfile implements Serializable { } } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && !mAllowLocalLAN) - cfg+="redirect-private block-local\n"; - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && mAllowLocalLAN) - cfg+="redirect-private unblock-local\n"; - if (mUseDefaultRoutev6) cfg += "route-ipv6 ::/0\n"; diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index be803392..037be5f2 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -471,6 +471,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac if (mLocalIPv6 != null) cfg += mLocalIPv6; + + cfg += "routes: " + TextUtils.join("|", mRoutes.getNetworks(true)) + TextUtils.join("|", mRoutesv6.getNetworks(true)); cfg += "excl. routes:" + TextUtils.join("|", mRoutes.getNetworks(false)) + TextUtils.join("|", mRoutesv6.getNetworks(false)); cfg += "dns: " + TextUtils.join("|", mDnslist); @@ -487,6 +489,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac VpnStatus.logInfo(R.string.last_openvpn_tun_config); + addLocalNetworksToRoutes(); if (mLocalIP == null && mLocalIPv6 == null) { VpnStatus.logError(getString(R.string.opentun_no_ipaddr)); @@ -602,6 +605,31 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac } + private void addLocalNetworksToRoutes() { + // Add local network interfaces + String[] localRoutes = NativeUtils.getIfconfig(); + + // The format of mLocalRoutes is kind of broken because I don't really like JNI + for (int i=0; i < localRoutes.length; i+=3){ + String intf = localRoutes[i]; + String ipAddr = localRoutes[i+1]; + String netMask = localRoutes[i+2]; + + if (intf == null || intf.equals("lo") || + intf.startsWith("tun") || intf.startsWith("rmnet")) + continue; + + if (ipAddr.equals(mLocalIP.mIp)) + continue; + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && !mProfile.mAllowLocalLAN) { + mRoutes.addIP(new CIDRIP(ipAddr,netMask), true); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && mProfile.mAllowLocalLAN) + mRoutes.addIP(new CIDRIP(ipAddr,netMask), false); + } + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void setAllowedVpnPackages(Builder builder) { for (String pkg : mProfile.mAllowedAppsVpn) { -- cgit v1.2.3