diff options
author | Arne Schwabe <arne@rfc2549.org> | 2022-09-23 11:09:24 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2022-09-23 11:09:24 +0200 |
commit | d22a65811c0a68f62a44af11611ec39210eb64f4 (patch) | |
tree | b83eb19dacee876f823fe59b77fb83f271311f59 /main/src | |
parent | 3647868bb0f7a94531155e12f366967382efb10c (diff) |
Make excluded network canonical for OpenVPN 3 core
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java | 22 | ||||
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java | 3 |
2 files changed, 19 insertions, 6 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java b/main/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java index 8b2a1b1c..67cdb243 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java +++ b/main/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java @@ -14,14 +14,18 @@ import android.text.TextUtils; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Vector; +import de.blinkt.openvpn.R; + public class NetworkUtils { public static Vector<String> getLocalNetworks(Context c, boolean ipv6) { - Vector<String> nets = new Vector<>(); ConnectivityManager conn = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); + Vector<String> nets = new Vector<>(); Network[] networks = conn.getAllNetworks(); for (Network network : networks) { NetworkInfo ni = conn.getNetworkInfo(network); @@ -44,8 +48,20 @@ public class NetworkUtils { for (LinkAddress la : li.getLinkAddresses()) { if ((la.getAddress() instanceof Inet4Address && !ipv6) || - (la.getAddress() instanceof Inet6Address && ipv6)) - nets.add(la.toString()); + (la.getAddress() instanceof Inet6Address && ipv6)) { + //nets.add(la.toString()); + NetworkSpace.IpAddress ipaddress; + if (la.getAddress() instanceof Inet6Address) + ipaddress = new NetworkSpace.IpAddress((Inet6Address) la.getAddress(), la.getPrefixLength(), true); + else + ipaddress = new NetworkSpace.IpAddress(new CIDRIP(la.getAddress().getHostAddress(), la.getPrefixLength()), true); + + try { + nets.add(ipaddress.getPrefix().toString()); + } catch (UnknownHostException ia) { + VpnStatus.logError("getLocalNetworks error: " + ipaddress + " " + ia.getLocalizedMessage()); + } + } } } 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 d3de35f9..910dc43e 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -994,15 +994,12 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac mRoutes.addIP(new CIDRIP(ipAddr, netMask), false); } - // IPv6 is Lollipop+ only so we can skip the lower than KITKAT case if (mProfile.mAllowLocalLAN) { for (String net : NetworkUtils.getLocalNetworks(this, true)) { addRoutev6(net, false); ; } } - - } private void setAllowedVpnPackages(Builder builder) { |