[network-manager-openvpn/bg/options: 4/5] service, properties: add support for --mtu-disc
- From: Beniamino Galvani <bgalvani src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn/bg/options: 4/5] service, properties: add support for --mtu-disc
- Date: Fri, 12 May 2017 15:37:57 +0000 (UTC)
commit 3418f5d1c259559d5b55f0e83fcb69d11b00dff6
Author: Beniamino Galvani <bgalvani redhat com>
Date: Thu May 11 19:12:34 2017 +0200
service,properties: add support for --mtu-disc
https://bugzilla.gnome.org/show_bug.cgi?id=781592
Makefile.am | 1 +
properties/auth-helpers.c | 53 ++++++++++++++++++++
properties/import-export.c | 12 +++++
properties/nm-openvpn-dialog.ui | 86 +++++++++++++++++++++++++++++++++
properties/tests/test-import-export.c | 63 ++++++++++++++++++++++++
shared/nm-service-defines.h | 1 +
shared/utils.h | 1 +
src/nm-openvpn-service.c | 8 +++
8 files changed, 225 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4d39522..439368b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -276,6 +276,7 @@ properties_tests_test_import_export_glib_LDADD = \
EXTRA_DIST += \
properties/tests/conf/iso885915.ovpn \
+ properties/tests/conf/mtu-disc.ovpn \
properties/tests/conf/password.conf \
properties/tests/conf/pkcs12.ovpn \
properties/tests/conf/port.ovpn \
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index defaee4..e7173e9 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -952,6 +952,7 @@ static const char *advanced_keys[] = {
NM_OPENVPN_KEY_PING_EXIT,
NM_OPENVPN_KEY_PING_RESTART,
NM_OPENVPN_KEY_MAX_ROUTES,
+ NM_OPENVPN_KEY_MTU_DISC,
NULL
};
@@ -1448,6 +1449,19 @@ populate_ns_cert_type_combo (GtkComboBox *box, const char *type)
g_object_unref (store);
}
+static void
+mtu_disc_toggled_cb (GtkWidget *widget, gpointer user_data)
+{
+ GtkBuilder *builder = (GtkBuilder *) user_data;
+ gboolean use_mtu_disc;
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "mtu_disc_checkbutton"));
+ use_mtu_disc = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "mtu_disc_combo"));
+ gtk_widget_set_sensitive (widget, use_mtu_disc);
+}
+
#define PROXY_TYPE_NONE 0
#define PROXY_TYPE_HTTP 1
#define PROXY_TYPE_SOCKS 2
@@ -1989,6 +2003,21 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
gtk_widget_set_sensitive (spin, !!value);
gtk_toggle_button_set_active ((GtkToggleButton *) widget, !!value);
+ /* MTU discovery */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "mtu_disc_checkbutton"));
+ value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_MTU_DISC);
+ if (value && value[0]) {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+ combo = GTK_WIDGET (gtk_builder_get_object (builder, "mtu_disc_combo"));
+ if (nm_streq (value, "maybe"))
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
+ else if (nm_streq (value, "yes"))
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 2);
+ else
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+ }
+ g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (mtu_disc_toggled_cb), builder);
+ mtu_disc_toggled_cb (widget, builder);
value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_MAX_ROUTES);
_builder_init_optional_spinbutton (builder, "max_routes_checkbutton", "max_routes_spinbutton",
!!value,
@@ -2323,6 +2352,30 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_MAX_ROUTES), g_strdup_printf ("%d",
max_routes));
}
+ /* MTU discovery */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "mtu_disc_checkbutton"));
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+ char *val = NULL;
+
+ combo = GTK_WIDGET (gtk_builder_get_object (builder, "mtu_disc_combo"));
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
+ case 0:
+ val = "no";
+ break;
+ case 1:
+ val = "maybe";
+ break;
+ case 2:
+ val = "yes";
+ break;
+ }
+ if (val) {
+ g_hash_table_insert (hash,
+ g_strdup (NM_OPENVPN_KEY_MTU_DISC),
+ g_strdup (val));
+ }
+ }
+
return hash;
}
diff --git a/properties/import-export.c b/properties/import-export.c
index ec3ef05..8d3078c 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -926,6 +926,16 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
continue;
}
+ if (NM_IN_STRSET (params[0], NMV_OVPN_TAG_MTU_DISC)) {
+ if (!args_params_check_nargs_n (params, 1, &line_error))
+ goto handle_line_error;
+ if (!NM_IN_STRSET (params[1], "no", "maybe", "yes")) {
+ line_error = g_strdup_printf (_("unsupported mtu-disc argument"));
+ goto handle_line_error;
+ }
+ setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_MTU_DISC, params[1]);
+ }
+
if (NM_IN_STRSET (params[0], NMV_OVPN_TAG_NS_CERT_TYPE)) {
if (!args_params_check_nargs_n (params, 1, &line_error))
goto handle_line_error;
@@ -1899,6 +1909,8 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
else if (value)
args_write_line_setting_value_int (f, NMV_OVPN_TAG_MSSFIX, s_vpn, NM_OPENVPN_KEY_MSSFIX);
+ args_write_line_setting_value (f, NMV_OVPN_TAG_MTU_DISC, s_vpn, NM_OPENVPN_KEY_MTU_DISC);
+
args_write_line_setting_value_int (f, NMV_OVPN_TAG_TUN_MTU, s_vpn, NM_OPENVPN_KEY_TUNNEL_MTU);
args_write_line_setting_value_int (f, NMV_OVPN_TAG_FRAGMENT, s_vpn, NM_OPENVPN_KEY_FRAGMENT_SIZE);
diff --git a/properties/nm-openvpn-dialog.ui b/properties/nm-openvpn-dialog.ui
index bdc1b0c..73d8bec 100644
--- a/properties/nm-openvpn-dialog.ui
+++ b/properties/nm-openvpn-dialog.ui
@@ -89,6 +89,23 @@
</row>
</data>
</object>
+ <object class="GtkListStore" id="model11">
+ <columns>
+ <!-- column-name gchararray -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0">No</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Maybe</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Yes</col>
+ </row>
+ </data>
+ </object>
<object class="GtkListStore" id="model2">
<columns>
<!-- column-name gchararray -->
@@ -2537,6 +2554,75 @@ config: http-proxy-retry or socks-proxy-retry</property>
<property name="tab_fill">False</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkCheckButton" id="mtu_disc_checkbutton">
+ <property name="label" translatable="yes">Path mtu discovery</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="mtu_disc_combo">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="model">model11</property>
+ <property name="active">0</property>
+ <property name="id_column">0</property>
+ <child>
+ <object class="GtkCellRendererText" id="renderer51"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label33">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Misc</property>
+ </object>
+ <packing>
+ <property name="position">4</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index b532759..8c26258 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -1182,6 +1182,66 @@ test_device_export (gconstpointer test_data)
}
static void
+test_mtu_disc_import (gconstpointer test_data)
+{
+ _CREATE_PLUGIN (plugin);
+ NMConnection *connection;
+ NMSettingVpn *s_vpn;
+ const char *file, *expected_val;
+
+ nmtst_test_data_unpack (test_data, &file, &expected_val);
+
+ connection = get_basic_connection (plugin, SRCDIR, file);
+ g_assert (connection);
+
+ /* VPN setting */
+ s_vpn = nm_connection_get_setting_vpn (connection);
+ g_assert (s_vpn);
+
+ /* Data items */
+ _check_item (s_vpn, NM_OPENVPN_KEY_MTU_DISC, expected_val);
+
+ g_object_unref (connection);
+}
+
+static void
+test_mtu_disc_export (gconstpointer test_data)
+{
+ _CREATE_PLUGIN (plugin);
+ NMConnection *connection;
+ NMConnection *reimported;
+ char *path;
+ gboolean success;
+ GError *error = NULL;
+ const char *file, *exported_name;
+
+ nmtst_test_data_unpack (test_data, &file, &exported_name);
+
+ connection = get_basic_connection (plugin, SRCDIR, file);
+ g_assert (connection);
+
+ path = g_build_path ("/", TMPDIR, exported_name, NULL);
+ success = nm_vpn_editor_plugin_export (plugin, path, connection, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ /* Now re-import it and compare the connections to ensure they are the same */
+ reimported = get_basic_connection (plugin, TMPDIR, exported_name);
+ (void) unlink (path);
+ g_assert (reimported);
+
+ /* Clear secrets first, since they don't get exported, and thus would
+ * make the connection comparison below fail.
+ */
+ remove_secrets (connection);
+ g_assert (nm_connection_compare (connection, reimported, NM_SETTING_COMPARE_FLAG_EXACT));
+
+ g_object_unref (reimported);
+ g_object_unref (connection);
+ g_free (path);
+}
+
+static void
test_route_import (void)
{
_CREATE_PLUGIN (plugin);
@@ -1553,6 +1613,9 @@ int main (int argc, char **argv)
_add_test_func ("device-import-notype", test_device_import, "device-notype.ovpn", "tap", NULL);
_add_test_func ("device-export-notype", test_device_export, "device-notype.ovpn",
"device-notype.ovpntest");
+ _add_test_func ("mtu-disc-import", test_mtu_disc_import, "mtu-disc.ovpn", "yes");
+ _add_test_func ("mtu-disc-export", test_mtu_disc_export, "mtu-disc.ovpn", "mtu-disc.ovpntest");
+
_add_test_func_simple (test_route_import);
_add_test_func_simple (test_route_export);
diff --git a/shared/nm-service-defines.h b/shared/nm-service-defines.h
index 86a0233..513fec4 100644
--- a/shared/nm-service-defines.h
+++ b/shared/nm-service-defines.h
@@ -40,6 +40,7 @@
#define NM_OPENVPN_KEY_KEY "key"
#define NM_OPENVPN_KEY_LOCAL_IP "local-ip" /* ??? */
#define NM_OPENVPN_KEY_MSSFIX "mssfix"
+#define NM_OPENVPN_KEY_MTU_DISC "mtu-disc"
#define NM_OPENVPN_KEY_NS_CERT_TYPE "ns-cert-type"
#define NM_OPENVPN_KEY_PING "ping"
#define NM_OPENVPN_KEY_PING_EXIT "ping-exit"
diff --git a/shared/utils.h b/shared/utils.h
index 05b8076..cb16d32 100644
--- a/shared/utils.h
+++ b/shared/utils.h
@@ -44,6 +44,7 @@
#define NMV_OVPN_TAG_KEYSIZE "keysize"
#define NMV_OVPN_TAG_MAX_ROUTES "max-routes"
#define NMV_OVPN_TAG_MSSFIX "mssfix"
+#define NMV_OVPN_TAG_MTU_DISC "mtu-disc"
#define NMV_OVPN_TAG_NOBIND "nobind"
#define NMV_OVPN_TAG_NS_CERT_TYPE "ns-cert-type"
#define NMV_OVPN_TAG_PERSIST_KEY "persist-key"
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index c636c9e..aa12475 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -151,6 +151,7 @@ static const ValidProperty valid_properties[] = {
{ NM_OPENVPN_KEY_KEY, G_TYPE_STRING, 0, 0, FALSE },
{ NM_OPENVPN_KEY_LOCAL_IP, G_TYPE_STRING, 0, 0, TRUE },
{ NM_OPENVPN_KEY_MSSFIX, G_TYPE_STRING, 0, 0, FALSE },
+ { NM_OPENVPN_KEY_MTU_DISC, G_TYPE_STRING, 0, 0, FALSE },
{ NM_OPENVPN_KEY_PING, G_TYPE_INT, 0, G_MAXINT, FALSE },
{ NM_OPENVPN_KEY_PING_EXIT, G_TYPE_INT, 0, G_MAXINT, FALSE },
{ NM_OPENVPN_KEY_PING_RESTART, G_TYPE_INT, 0, G_MAXINT, FALSE },
@@ -1732,6 +1733,13 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
}
}
+ /* mtu-disc */
+ tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_MTU_DISC);
+ if (NM_IN_STRSET (tmp, "no", "maybe", "yes")) {
+ add_openvpn_arg (args, "--mtu-disc");
+ add_openvpn_arg (args, tmp);
+ }
+
/* Punch script security in the face; this option was added to OpenVPN 2.1-rc9
* and defaults to disallowing any scripts, a behavior change from previous
* versions.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]