summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/blinkt/openvpn')
-rw-r--r--src/de/blinkt/openvpn/VpnProfile.java29
-rw-r--r--src/de/blinkt/openvpn/core/ConfigParser.java28
-rw-r--r--src/de/blinkt/openvpn/fragments/Settings_Routing.java17
3 files changed, 56 insertions, 18 deletions
diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java
index 215efe78..d18fc72a 100644
--- a/src/de/blinkt/openvpn/VpnProfile.java
+++ b/src/de/blinkt/openvpn/VpnProfile.java
@@ -11,7 +11,6 @@ import android.preference.PreferenceManager;
import android.security.KeyChain;
import android.security.KeyChainException;
import android.util.Base64;
-import android.widget.Toast;
import de.blinkt.openvpn.core.NativeUtils;
import de.blinkt.openvpn.core.VpnStatus;
@@ -129,6 +128,8 @@ public class VpnProfile implements Serializable {
private UUID mUuid;
public boolean mAllowLocalLAN;
private int mProfileVersion;
+ public String mExcludedRoutes;
+ public String mExcludedRoutesv6;
public VpnProfile(String name) {
mUuid = UUID.randomUUID();
@@ -324,11 +325,17 @@ public class VpnProfile implements Serializable {
if (mUseDefaultRoute)
routes += "route 0.0.0.0 0.0.0.0 vpn_gateway\n";
else
- for (String route : getCustomRoutes()) {
+ {
+ for (String route : getCustomRoutes(mCustomRoutes)) {
routes += "route " + route + " vpn_gateway\n";
numroutes++;
}
+ for (String route: getCustomRoutes(mExcludedRoutes)) {
+ routes += "route " + route + " net_gateway";
+ }
+ }
+
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)
@@ -338,7 +345,7 @@ public class VpnProfile implements Serializable {
if (mUseDefaultRoutev6)
cfg += "route-ipv6 ::/0\n";
else
- for (String route : getCustomRoutesv6()) {
+ for (String route : getCustomRoutesv6(mCustomRoutesv6)) {
routes += "route-ipv6 " + route + "\n";
numroutes++;
}
@@ -346,7 +353,7 @@ public class VpnProfile implements Serializable {
// Round number to next 100
if (numroutes > 90) {
numroutes = ((numroutes / 100) + 1) * 100;
- cfg += "# Alot of routes are set, increase max-routes\n";
+ cfg += "# A lot of routes are set, increase max-routes\n";
cfg += "max-routes " + numroutes + "\n";
}
cfg += routes;
@@ -470,13 +477,13 @@ public class VpnProfile implements Serializable {
return true;
}
- private Collection<String> getCustomRoutes() {
+ private Collection<String> getCustomRoutes(String routes) {
Vector<String> cidrRoutes = new Vector<String>();
- if (mCustomRoutes == null) {
+ if (routes == null) {
// No routes set, return empty vector
return cidrRoutes;
}
- for (String route : mCustomRoutes.split("[\n \t]")) {
+ for (String route : routes.split("[\n \t]")) {
if (!route.equals("")) {
String cidrroute = cidrToIPAndNetmask(route);
if (cidrroute == null)
@@ -489,13 +496,13 @@ public class VpnProfile implements Serializable {
return cidrRoutes;
}
- private Collection<String> getCustomRoutesv6() {
+ private Collection<String> getCustomRoutesv6(String routes) {
Vector<String> cidrRoutes = new Vector<String>();
- if (mCustomRoutesv6 == null) {
+ if (routes == null) {
// No routes set, return empty vector
return cidrRoutes;
}
- for (String route : mCustomRoutesv6.split("[\n \t]")) {
+ for (String route : routes.split("[\n \t]")) {
if (!route.equals("")) {
cidrRoutes.add(route);
}
@@ -703,7 +710,7 @@ public class VpnProfile implements Serializable {
if (mIPv4Address == null || cidrToIPAndNetmask(mIPv4Address) == null)
return R.string.ipv4_format_error;
}
- if (!mUseDefaultRoute && getCustomRoutes() == null)
+ if (!mUseDefaultRoute && (getCustomRoutes(mCustomRoutes) == null || getCustomRoutes(mExcludedRoutes) ==null))
return R.string.custom_route_format_error;
// Everything okay
diff --git a/src/de/blinkt/openvpn/core/ConfigParser.java b/src/de/blinkt/openvpn/core/ConfigParser.java
index 895f048e..6ce7467f 100644
--- a/src/de/blinkt/openvpn/core/ConfigParser.java
+++ b/src/de/blinkt/openvpn/core/ConfigParser.java
@@ -322,14 +322,23 @@ public class ConfigParser {
Vector<Vector<String>> routes = getAllOption("route", 1, 4);
if(routes!=null) {
String routeopt = "";
- for(Vector<String> route:routes){
+ String routeExcluded = "";
+ for(Vector<String> route:routes){
String netmask = "255.255.255.255";
- if(route.size() >= 3)
+ String gateway = "vpn_gateway";
+
+ if(route.size() >= 3)
netmask = route.get(2);
+ if (route.size() >= 4)
+ gateway = route.get(3);
+
String net = route.get(1);
try {
CIDRIP cidr = new CIDRIP(net, netmask);
- routeopt+=cidr.toString() + " ";
+ if (gateway.equals("net_gateway"))
+ routeExcluded += cidr.toString() + " ";
+ else
+ routeopt+=cidr.toString() + " ";
} catch (ArrayIndexOutOfBoundsException aioob) {
throw new ConfigParseError("Could not parse netmask of route " + netmask);
} catch (NumberFormatException ne) {
@@ -338,9 +347,20 @@ public class ConfigParser {
}
np.mCustomRoutes=routeopt;
+ np.mExcludedRoutes=routeExcluded;
}
- // Also recognize tls-auth [inline] direction ...
+ Vector<Vector<String>> routesV6 = getAllOption("route-ipv6", 1, 4);
+ if (routesV6!=null) {
+ String customIPv6Routes = "";
+ for (Vector<String> route:routesV6){
+ customIPv6Routes += route.get(1) + " ";
+ }
+
+ np.mCustomRoutesv6 = customIPv6Routes;
+ }
+
+ // Also recognize tls-auth [inline] direction ...
Vector<Vector<String>> tlsauthoptions = getAllOption("tls-auth", 1, 2);
if(tlsauthoptions!=null) {
for(Vector<String> tlsauth:tlsauthoptions) {
diff --git a/src/de/blinkt/openvpn/fragments/Settings_Routing.java b/src/de/blinkt/openvpn/fragments/Settings_Routing.java
index 7216e0ff..c6f0dcf8 100644
--- a/src/de/blinkt/openvpn/fragments/Settings_Routing.java
+++ b/src/de/blinkt/openvpn/fragments/Settings_Routing.java
@@ -14,17 +14,22 @@ public class Settings_Routing extends OpenVpnPreferencesFragment implements OnPr
private CheckBoxPreference mUseDefaultRoutev6;
private CheckBoxPreference mRouteNoPull;
private CheckBoxPreference mLocalVPNAccess;
+ private EditTextPreference mExcludedRoutes;
+ private EditTextPreference mExcludedRoutesv6;
- @Override
+ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.vpn_routing);
- mCustomRoutes = (EditTextPreference) findPreference("customRoutes");
+ mCustomRoutes = (EditTextPreference) findPreference("customRoutes");
mUseDefaultRoute = (CheckBoxPreference) findPreference("useDefaultRoute");
mCustomRoutesv6 = (EditTextPreference) findPreference("customRoutesv6");
mUseDefaultRoutev6 = (CheckBoxPreference) findPreference("useDefaultRoutev6");
+ mExcludedRoutes = (EditTextPreference) findPreference("excludedRoutes");
+ mExcludedRoutesv6 = (EditTextPreference) findPreference("excludedRoutesv6");
+
mRouteNoPull = (CheckBoxPreference) findPreference("routenopull");
mLocalVPNAccess = (CheckBoxPreference) findPreference("unblockLocal");
@@ -43,6 +48,9 @@ public class Settings_Routing extends OpenVpnPreferencesFragment implements OnPr
mCustomRoutes.setText(mProfile.mCustomRoutes);
mCustomRoutesv6.setText(mProfile.mCustomRoutesv6);
+ mExcludedRoutes.setText(mProfile.mExcludedRoutes);
+ mExcludedRoutes.setText(mProfile.mExcludedRoutesv6);
+
mRouteNoPull.setChecked(mProfile.mRoutenopull);
mLocalVPNAccess.setChecked(mProfile.mAllowLocalLAN);
@@ -61,12 +69,15 @@ public class Settings_Routing extends OpenVpnPreferencesFragment implements OnPr
mProfile.mCustomRoutesv6 = mCustomRoutesv6.getText();
mProfile.mRoutenopull = mRouteNoPull.isChecked();
mProfile.mAllowLocalLAN =mLocalVPNAccess.isChecked();
+ mProfile.mExcludedRoutes = mExcludedRoutes.getText();
+ mProfile.mExcludedRoutesv6 = mExcludedRoutesv6.getText();
}
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
- if( preference == mCustomRoutes || preference == mCustomRoutesv6 )
+ if( preference == mCustomRoutes || preference == mCustomRoutesv6
+ || preference == mExcludedRoutes || preference == mExcludedRoutesv6)
preference.setSummary((String)newValue);
saveSettings();