From 67e09d168a5ffaf98e3e72edd9001573c3d65db3 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 6 Aug 2014 00:00:45 +0200 Subject: Resort VPN preferences add mss fix --HG-- rename : main/src/main/java/de/blinkt/openvpn/fragments/Settings_Obscure.java => main/src/main/java/de/blinkt/openvpn/fragments/Settings_Behaviour.java --- .../main/java/de/blinkt/openvpn/VpnProfile.java | 12 +++ .../blinkt/openvpn/activities/VPNPreferences.java | 4 +- .../java/de/blinkt/openvpn/core/ConfigParser.java | 13 +++ .../openvpn/fragments/Settings_Behaviour.java | 77 +++++++++++++++++ .../blinkt/openvpn/fragments/Settings_Obscure.java | 99 +++++++++++----------- main/src/main/res/layout/viewconfig.xml | 1 + main/src/main/res/values/strings.xml | 6 +- main/src/main/res/xml/vpn_behaviour.xml | 24 ++++++ main/src/main/res/xml/vpn_headers.xml | 5 ++ main/src/main/res/xml/vpn_obscure.xml | 26 +++--- 10 files changed, 198 insertions(+), 69 deletions(-) create mode 100644 main/src/main/java/de/blinkt/openvpn/fragments/Settings_Behaviour.java create mode 100644 main/src/main/res/xml/vpn_behaviour.xml diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java index 14f0627b..679aa2fa 100644 --- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -65,6 +65,7 @@ public class VpnProfile implements Serializable { private static final String OVPNCONFIGFILE = "android.conf"; public static final int MAXLOGLEVEL = 4; public static final int CURRENT_PROFILE_VERSION = 2; + public static final int DEFAULT_MSSFIX_SIZE = 1450; public static String DEFAULT_DNS1 = "8.8.8.8"; public static String DEFAULT_DNS2 = "8.8.4.4"; @@ -143,6 +144,9 @@ public class VpnProfile implements Serializable { private int mProfileVersion; public String mExcludedRoutes; public String mExcludedRoutesv6; + public int mMssFix =0; // -1 is default, + + public VpnProfile(String name) { mUuid = UUID.randomUUID(); @@ -182,6 +186,7 @@ public class VpnProfile implements Serializable { mCheckRemoteCN = false; mPersistTun = false; mAllowLocalLAN = true; + mMssFix = 0; } public UUID getUUID() { @@ -385,6 +390,13 @@ public class VpnProfile implements Serializable { } + if (mMssFix !=0){ + if (mMssFix!=1450) + cfg+=String.format("mssfix %d\n", mMssFix, Locale.US); + else + cfg+="mssfix\n"; + } + if (mNobind) cfg += "nobind\n"; diff --git a/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java b/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java index 1ebb16b2..22b02c66 100644 --- a/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java +++ b/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java @@ -19,6 +19,7 @@ import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.fragments.Settings_Authentication; import de.blinkt.openvpn.fragments.Settings_Basic; +import de.blinkt.openvpn.fragments.Settings_Behaviour; import de.blinkt.openvpn.fragments.Settings_IP; import de.blinkt.openvpn.fragments.Settings_Obscure; import de.blinkt.openvpn.fragments.Settings_Routing; @@ -30,7 +31,8 @@ public class VPNPreferences extends PreferenceActivity { static final Class validFragments[] = new Class[] { Settings_Authentication.class, Settings_Basic.class, Settings_IP.class, - Settings_Obscure.class, Settings_Routing.class, ShowConfigFragment.class + Settings_Obscure.class, Settings_Routing.class, ShowConfigFragment.class, + Settings_Behaviour.class }; private String mProfileUUID; diff --git a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java index d23b521f..9c3621e0 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java @@ -432,6 +432,19 @@ public class ConfigParser { throw new ConfigParseError("Sorry. Only tun mode is supported. See the FAQ for more detail"); } + Vector mssfix = getOption("mssfix",0,1); + + if (mssfix!=null) { + if (mssfix.size()>=2) { + try { + np.mMssFix=Integer.parseInt(mssfix.get(1)); + } catch(NumberFormatException e) { + throw new ConfigParseError("Argument to --mssfix has to be an integer"); + } + } else { + np.mMssFix = VpnProfile.DEFAULT_MSSFIX_SIZE; + } + } Vector mode =getOption("mode",1,1); diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Behaviour.java b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Behaviour.java new file mode 100644 index 00000000..73343037 --- /dev/null +++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Behaviour.java @@ -0,0 +1,77 @@ +package de.blinkt.openvpn.fragments; + +import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; + +import de.blinkt.openvpn.R; + +public class Settings_Behaviour extends OpenVpnPreferencesFragment implements OnPreferenceChangeListener { + private CheckBoxPreference mPersistent; + private ListPreference mConnectretrymax; + private EditTextPreference mConnectretry; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.vpn_behaviour); + + mPersistent = (CheckBoxPreference) findPreference("usePersistTun"); + mConnectretrymax = (ListPreference) findPreference("connectretrymax"); + mConnectretry = (EditTextPreference) findPreference("connectretry"); + + mConnectretrymax.setOnPreferenceChangeListener(this); + mConnectretrymax.setSummary("%s"); + + mConnectretry.setOnPreferenceChangeListener(this); + + + loadSettings(); + + } + + protected void loadSettings() { + mPersistent.setChecked(mProfile.mPersistTun); + + mConnectretrymax.setValue(mProfile.mConnectRetryMax); + onPreferenceChange(mConnectretrymax, mProfile.mConnectRetryMax); + + mConnectretry.setText(mProfile.mConnectRetry); + onPreferenceChange(mConnectretry, mProfile.mConnectRetry); + } + + + protected void saveSettings() { + mProfile.mConnectRetryMax = mConnectretrymax.getValue(); + mProfile.mPersistTun = mPersistent.isChecked(); + mProfile.mConnectRetry = mConnectretry.getText(); + } + + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (preference == mConnectretrymax) { + if(newValue==null) { + newValue="5"; + } + mConnectretrymax.setDefaultValue(newValue); + + for(int i=0;i 9000) + throw new NumberFormatException("mssfix value"); + setMssSummary(v); + + } catch(NumberFormatException e) { + Toast.makeText(getActivity(), R.string.mssfix_invalid_value, Toast.LENGTH_LONG).show(); + return false; + } + return true; } } \ No newline at end of file diff --git a/main/src/main/res/layout/viewconfig.xml b/main/src/main/res/layout/viewconfig.xml index 5ae34ef0..68107972 100644 --- a/main/src/main/res/layout/viewconfig.xml +++ b/main/src/main/res/layout/viewconfig.xml @@ -1,5 +1,6 @@ diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index a054d16b..ad46dd97 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -254,7 +254,7 @@ Connecting to VPN %s Some versions of Android 4.1 have problems if the name of the keystore certificate contains non alphanumeric characters (like spaces, underscores or dashes). Try to reimport the certificate without special characters Encryption cipher - Packets authentication + Packet authentication Enter packet authentication method Running on %1$s (%2$s) %3$s, Android API %4$d, version %5$s, %6$s built by %s @@ -319,4 +319,8 @@ To use this app you need a VPN provider/VPN gateway supporting OpenVPN (often provided by your employer). Check out http://community.openvpn.net/ for more information on OpenVPN and how to setup your own OpenVPN server. Import log: Vpn topology \"%3$s\" specified but ifconfig %1$s %2$s looks more like an IP address with a network mask. Assuming \"subnet\" topology. + mssfix value has to be a integer between 0 and 9000 + Announce to TCP sessions running over the tunnel that they should limit their send packet sizes such that after OpenVPN has encapsulated them, the resulting UDP packet size that OpenVPN sends to its peer will not exceed this number of bytes. (default is 1450) + Override MSS value of TCP payload + Set MSS of TCP payload diff --git a/main/src/main/res/xml/vpn_behaviour.xml b/main/src/main/res/xml/vpn_behaviour.xml new file mode 100644 index 00000000..106e90da --- /dev/null +++ b/main/src/main/res/xml/vpn_behaviour.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/xml/vpn_headers.xml b/main/src/main/res/xml/vpn_headers.xml index 7f2a97d9..3877306f 100644 --- a/main/src/main/res/xml/vpn_headers.xml +++ b/main/src/main/res/xml/vpn_headers.xml @@ -1,6 +1,11 @@ + +
+ android:title="Obscure Settings"> - - - + - + android:title="@string/mssfix_checkbox" /> + android:title="@string/mssfix_dialogtitle" /> - +