[network-manager-openvpn: 1/3] properties: Add support for max-routes setting



commit c4d45e51280d5b0cb8c5e8f826d68c3262162080
Author: Justin Milam <jsmilam gmail com>
Date:   Tue Jul 26 09:18:30 2016 -0400

    properties: Add support for max-routes setting
    
    When an openvpn server specifies more than 100 routes to the client the
    client will end the connection specifying that max-routes must be
    configured to allow more than 100 routes. This change adds support for
    configuring the max-rotues option to openvpn.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=720097

 properties/auth-helpers.c       |   25 +++++++++++++++++-
 properties/import-export.c      |   11 ++++++++
 properties/nm-openvpn-dialog.ui |   55 +++++++++++++++++++++++++++++++++++++++
 shared/nm-service-defines.h     |    1 +
 shared/utils.h                  |    1 +
 src/nm-openvpn-service.c        |   16 +++++++++++
 6 files changed, 108 insertions(+), 1 deletions(-)
---
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index 7244df1..d388ed3 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -895,6 +895,7 @@ static const char *advanced_keys[] = {
        NM_OPENVPN_KEY_PING,
        NM_OPENVPN_KEY_PING_EXIT,
        NM_OPENVPN_KEY_PING_RESTART,
+       NM_OPENVPN_KEY_MAX_ROUTES,
        NULL
 };
 
@@ -1888,6 +1889,18 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
                gtk_widget_set_sensitive (widget, FALSE);
        }
 
+       /* max routes */
+       widget = GTK_WIDGET (gtk_builder_get_object (builder, "max_routes_checkbutton"));
+       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+               int max_routes;
+
+               widget = GTK_WIDGET (gtk_builder_get_object (builder, "max_routes_spinbutton"));
+               max_routes = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
+               g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_MAX_ROUTES), g_strdup_printf ("%d", 
max_routes));
+       }
+
+
+
 out:
        g_free (ui_file);
        return dialog;
@@ -2155,7 +2168,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
                }
        }
 
-       widget = GTK_WIDGET (gtk_builder_get_object (builder, "ping_checkbutton"));
+        widget = GTK_WIDGET (gtk_builder_get_object (builder, "ping_checkbutton"));
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
                int ping_val;
 
@@ -2184,6 +2197,16 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
                                     g_strdup_printf ("%d", ping_val));
        }
 
+       /* max routes */
+       widget = GTK_WIDGET (gtk_builder_get_object (builder, "max_routes_checkbutton"));
+       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+               int max_routes;
+
+               widget = GTK_WIDGET (gtk_builder_get_object (builder, "max_routes_spinbutton"));
+               max_routes = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
+               g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_MAX_ROUTES), g_strdup_printf ("%d", 
max_routes));
+       }
+
        return hash;
 }
 
diff --git a/properties/import-export.c b/properties/import-export.c
index 3b441d2..bbcbe0f 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -987,6 +987,15 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
                        continue;
                }
 
+               if (NM_IN_STRSET (params[0], NMV_OVPN_TAG_MAX_ROUTES)) {
+                       if (!args_params_check_nargs_n (params, 1, &line_error))
+                               goto handle_line_error;
+                       if (!args_params_parse_int64 (params, 1, 0, 604800, &v_int64, &line_error))
+                               goto handle_line_error;
+                       setting_vpn_add_data_item_int64 (s_vpn, NM_OPENVPN_KEY_MAX_ROUTES, v_int64);
+                       continue;
+               }
+
                if (NM_IN_STRSET (params[0], NMV_OVPN_TAG_HTTP_PROXY_RETRY, NMV_OVPN_TAG_SOCKS_PROXY_RETRY)) {
                        if (!args_params_check_nargs_n (params, 0, &line_error))
                                goto handle_line_error;
@@ -1819,6 +1828,8 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
 
        args_write_line_setting_value_int (f, NMV_OVPN_TAG_RENEG_SEC, s_vpn, NM_OPENVPN_KEY_RENEG_SECONDS);
 
+       args_write_line_setting_value_int (f, NMV_OVPN_TAG_MAX_ROUTES, s_vpn, NM_OPENVPN_KEY_MAX_ROUTES);
+
        args_write_line_setting_value (f, NMV_OVPN_TAG_CIPHER, s_vpn, NM_OPENVPN_KEY_CIPHER);
 
        args_write_line_setting_value (f, NMV_OVPN_TAG_TLS_CIPHER, s_vpn, NM_OPENVPN_KEY_TLS_CIPHER);
diff --git a/properties/nm-openvpn-dialog.ui b/properties/nm-openvpn-dialog.ui
index a58cf60..cd702b5 100644
--- a/properties/nm-openvpn-dialog.ui
+++ b/properties/nm-openvpn-dialog.ui
@@ -53,6 +53,14 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkAdjustment" id="adjustment9">
+    <property name="lower">1</property>
+    <property name="upper">65535</property>
+    <property name="value">200</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+
   <object class="GtkListStore" id="liststore1"/>
   <object class="GtkListStore" id="liststore2"/>
   <object class="GtkListStore" id="model1">
@@ -1558,6 +1566,53 @@ config: ping &lt;n&gt;</property>
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkBox" id="hbox10">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkCheckButton" id="max_routes_checkbutton">
+                        <property name="label" translatable="yes">Specify max routes:</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="tooltip_text" translatable="yes">Specify the maximum number of 
routes the server is allowed so specify.
+config: max-routes &lt;n&gt;</property>
+                        <property name="use_underline">True</property>
+                        <property name="xalign">0.5</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkSpinButton" id="max_routes_spinbutton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="tooltip_text" translatable="yes">Specify the maximum number of 
routes the server is allowed so specify.
+config: max-routes&lt;n&gt;</property>
+                        <property name="adjustment">adjustment9</property>
+                        <property name="climb_rate">1</property>
+                        <property name="numeric">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">12</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkBox" id="hbox9">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
diff --git a/shared/nm-service-defines.h b/shared/nm-service-defines.h
index b204bdb..906fde5 100644
--- a/shared/nm-service-defines.h
+++ b/shared/nm-service-defines.h
@@ -67,6 +67,7 @@
 #define NM_OPENVPN_KEY_TLS_CIPHER "tls-cipher"
 #define NM_OPENVPN_KEY_TLS_REMOTE "tls-remote"
 #define NM_OPENVPN_KEY_REMOTE_CERT_TLS "remote-cert-tls"
+#define NM_OPENVPN_KEY_MAX_ROUTES "max-routes"
 
 #define NM_OPENVPN_KEY_PASSWORD "password"
 #define NM_OPENVPN_KEY_CERTPASS "cert-pass"
diff --git a/shared/utils.h b/shared/utils.h
index 6370871..9ab2c48 100644
--- a/shared/utils.h
+++ b/shared/utils.h
@@ -71,6 +71,7 @@
 #define NMV_OVPN_TAG_TUN_MTU            "tun-mtu"
 #define NMV_OVPN_TAG_TUN_IPV6           "tun-ipv6"
 #define NMV_OVPN_TAG_USER               "user"
+#define NMV_OVPN_TAG_MAX_ROUTES         "max-routes"
 
 gboolean is_pkcs12 (const char *filepath);
 
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 9238a45..40db92a 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -120,6 +120,7 @@ static ValidProperty valid_properties[] = {
        { 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 },
+       { NM_OPENVPN_KEY_MAX_ROUTES,           G_TYPE_INT, 0, 65535, FALSE },
        { NM_OPENVPN_KEY_PROTO_TCP,            G_TYPE_BOOLEAN, 0, 0, FALSE },
        { NM_OPENVPN_KEY_PORT,                 G_TYPE_INT, 1, 65535, FALSE },
        { NM_OPENVPN_KEY_PROXY_TYPE,           G_TYPE_STRING, 0, 0, FALSE },
@@ -1328,6 +1329,21 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
 
        add_openvpn_arg (args, "--nobind");
 
+       /* max routes allowed from openvpn server */
+       tmp = nm_setting_vpn_get_data_item(s_vpn, NM_OPENVPN_KEY_MAX_ROUTES);
+       if (tmp) {
+               add_openvpn_arg (args, "--max-routes");
+               if (!add_openvpn_arg_int (args, tmp)) {
+                       g_set_error (error,
+                                       NM_VPN_PLUGIN_ERROR,
+                                       NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+                                       _("Invalid max-routes argument '%s'."),
+                                       tmp);
+                       free_openvpn_args (args);
+                       return FALSE;
+               }
+       }
+
        /* Device and device type, defaults to tun */
        tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_DEV);
        tmp2 = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_DEV_TYPE);


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