[network-manager-openvpn/nm-1-2] better support comp-lzo setting



commit b37fda4cc99470e7671a3da02f5d31d61f9ad243
Author: Thomas Haller <thaller redhat com>
Date:   Fri May 13 16:20:04 2016 +0200

    better support comp-lzo setting
    
    Openvpn understands more options with --comp-lzo:
    
     1a) --comp-lzo
     1b) --comp-lzo adaptive
     2)  --comp-lzo yes
     3)  --comp-lzo no
     4)  (unspecified)
    
    This already works for a long time, so it's safe to assume
    that the openvpn version at hand understands these options
    (https://github.com/OpenVPN/openvpn/commit/537073fd55b3e35720e759c5c13e9da128a2b0bb).
    
    Add support for all combinations for import/export and running the
    service.
    
    But don't extend the GUI plugin which only shows a checkbox.
    When configuring via gnome plugin, only 2) and 4) can be expressed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739519
    (cherry picked from commit 2ecf18c25a7bee7f0122d9d666a7e11cd8b55ea3)

 properties/auth-helpers.c             |   13 +++++++++++--
 properties/import-export.c            |   17 +++++++----------
 properties/tests/test-import-export.c |    6 +++---
 src/nm-openvpn-service.c              |    6 ++++--
 4 files changed, 25 insertions(+), 17 deletions(-)
---
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index a356b0f..f033441 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -1640,7 +1640,12 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
        }
 
        value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_COMP_LZO);
-       if (value && !strcmp (value, "yes")) {
+       if (NM_IN_STRSET (value, "yes", "adaptive")) {
+               /* the UI currently only supports "--comp-lzo yes" or omitting the "--comp-lzo"
+                * flag.
+                *
+                * Internally, we also support "--comp-lzo [adaptive]" and "--comp-lzo no"
+                * which have different meaning for openvpn. */
                widget = GTK_WIDGET (gtk_builder_get_object (builder, "lzo_checkbutton"));
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
        }
@@ -2008,8 +2013,12 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
        }
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "lzo_checkbutton"));
-       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+               /* we only have a checkbox, which we either map to "--comp-lzo yes" or
+                * no "--comp-lzo" flag. In the UI, we cannot express "--comp-lzo [adaptive]"
+                * or "--comp-lzo no". */
                g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_COMP_LZO), g_strdup ("yes"));
+       }
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "mssfix_checkbutton"));
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
diff --git a/properties/import-export.c b/properties/import-export.c
index b77628e..91fd826 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -907,15 +907,11 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
                if (NM_IN_STRSET (params[0], NMV_OVPN_TAG_COMP_LZO)) {
                        if (!args_params_check_nargs_minmax (params, 0, 1, &line_error))
                                goto handle_line_error;
-                       if (params[1]) {
-                               if (nm_streq (params[1], "no"))
-                                       continue;
-                               if (!nm_streq (params[1], "yes")) {
-                                       line_error = g_strdup_printf (_("unsupported comp-lzo argument"));
-                                       goto handle_line_error;
-                               }
+                       if (!NM_IN_STRSET (params[1], NULL, "no", "yes", "adaptive")) {
+                               line_error = g_strdup_printf (_("unsupported comp-lzo argument"));
+                               goto handle_line_error;
                        }
-                       setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "yes");
+                       setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, params[1] ?: "adaptive");
                        continue;
                }
 
@@ -1752,8 +1748,9 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
 
        args_write_line_setting_value_int (f, NMV_OVPN_TAG_KEYSIZE, s_vpn, NM_OPENVPN_KEY_KEYSIZE);
 
-       if (nm_streq0 (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO), "yes"))
-               args_write_line (f, NMV_OVPN_TAG_COMP_LZO, "yes");
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO);
+       if (value)
+               args_write_line (f, NMV_OVPN_TAG_COMP_LZO, value);
 
        if (nm_streq0 (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_FLOAT), "yes"))
                args_write_line (f, NMV_OVPN_TAG_FLOAT);
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index 744bfe7..f783b4d 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -231,7 +231,7 @@ test_tls_import (void)
        _check_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE, NM_OPENVPN_CONTYPE_TLS);
        _check_item (s_vpn, NM_OPENVPN_KEY_DEV, "tun");
        _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, NULL);
-       _check_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "yes");
+       _check_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "adaptive");
        _check_item (s_vpn, NM_OPENVPN_KEY_FLOAT, "yes");
        _check_item (s_vpn, NM_OPENVPN_KEY_RENEG_SECONDS, NULL);
        _check_item (s_vpn, NM_OPENVPN_KEY_REMOTE, "173.8.149.245:1194");
@@ -324,7 +324,7 @@ test_tls_inline_import (void)
        _check_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE, NM_OPENVPN_CONTYPE_TLS);
        _check_item (s_vpn, NM_OPENVPN_KEY_DEV, "tun");
        _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, NULL);
-       _check_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "yes");
+       _check_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "adaptive");
        _check_item (s_vpn, NM_OPENVPN_KEY_FLOAT, "yes");
        _check_item (s_vpn, NM_OPENVPN_KEY_RENEG_SECONDS, NULL);
        _check_item (s_vpn, NM_OPENVPN_KEY_REMOTE, "173.8.149.245:1194");
@@ -418,7 +418,7 @@ test_pkcs12_import (void)
        _check_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE, NM_OPENVPN_CONTYPE_TLS);
        _check_item (s_vpn, NM_OPENVPN_KEY_DEV, "tun");
        _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, NULL);
-       _check_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "yes");
+       _check_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "adaptive");
        _check_item (s_vpn, NM_OPENVPN_KEY_FLOAT, NULL);
        _check_item (s_vpn, NM_OPENVPN_KEY_RENEG_SECONDS, NULL);
        _check_item (s_vpn, NM_OPENVPN_KEY_REMOTE, "173.8.149.245:1194");
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 84e10b9..d4d660d 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -105,7 +105,7 @@ static ValidProperty valid_properties[] = {
        { NM_OPENVPN_KEY_CERT,                 G_TYPE_STRING, 0, 0, FALSE },
        { NM_OPENVPN_KEY_CIPHER,               G_TYPE_STRING, 0, 0, FALSE },
        { NM_OPENVPN_KEY_KEYSIZE,              G_TYPE_INT, 1, 65535, FALSE },
-       { NM_OPENVPN_KEY_COMP_LZO,             G_TYPE_BOOLEAN, 0, 0, FALSE },
+       { NM_OPENVPN_KEY_COMP_LZO,             G_TYPE_STRING, 0, 0, FALSE },
        { NM_OPENVPN_KEY_CONNECTION_TYPE,      G_TYPE_STRING, 0, 0, FALSE },
        { NM_OPENVPN_KEY_FLOAT,                G_TYPE_BOOLEAN, 0, 0, FALSE },
        { NM_OPENVPN_KEY_FRAGMENT_SIZE,        G_TYPE_INT, 0, G_MAXINT, FALSE },
@@ -1242,8 +1242,10 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        }
 
        tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO);
-       if (tmp && !strcmp (tmp, "yes"))
+       if (NM_IN_STRSET (tmp, "yes", "no", "adaptive")) {
                add_openvpn_arg (args, "--comp-lzo");
+               add_openvpn_arg (args, tmp);
+       }
 
        tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_FLOAT);
        if (tmp && !strcmp (tmp, "yes"))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]