[network-manager-vpnc] vpnc: add support to change interface name



commit 65b0275f589a5de4429dcc80edc51d9140f8a1a9
Author: Christian Hesse <mail eworm de>
Date:   Mon Sep 29 10:27:33 2014 +0200

    vpnc: add support to change interface name
    
    By default interface name is 'tun' with an incrementing number (tun0,
    tun1, ...). By specifying 'Interface name' in vpnc config you can change
    the name to something more descriptive.

 properties/nm-vpnc-dialog.ui |  179 ++++++++++++++++++++++++------------------
 properties/nm-vpnc.c         |   41 +++++++++-
 src/nm-vpnc-service.c        |   13 +++-
 3 files changed, 156 insertions(+), 77 deletions(-)
---
diff --git a/properties/nm-vpnc-dialog.ui b/properties/nm-vpnc-dialog.ui
index 4256335..b892413 100644
--- a/properties/nm-vpnc-dialog.ui
+++ b/properties/nm-vpnc-dialog.ui
@@ -571,20 +571,6 @@ config: Vendor &lt;cisco/netscreen&gt;</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkEntry" id="application_version_entry">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="tooltip_text" translatable="yes">Application version to report. 
-config: Application version &lt;ASCII string&gt;</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">3</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
                       <object class="GtkLabel" id="label28">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
@@ -607,7 +593,6 @@ config: Application version &lt;ASCII string&gt;</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">Ve_rsion:</property>
                         <property name="use_underline">True</property>
-                        <property name="mnemonic_widget">application_version_entry</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -617,6 +602,20 @@ config: Application version &lt;ASCII string&gt;</property>
                       </packing>
                     </child>
                     <child>
+                      <object class="GtkEntry" id="application_version_entry">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="tooltip_text" translatable="yes">Application version to report. 
+config: Application version &lt;ASCII string&gt;</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">3</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
                       <placeholder/>
                     </child>
                     <child>
@@ -672,58 +671,63 @@ config: Application version &lt;ASCII string&gt;</property>
                     <property name="row_spacing">6</property>
                     <property name="column_spacing">6</property>
                     <child>
-                      <object class="GtkLabel" id="label31">
+                      <object class="GtkCheckButton" id="disable_dpd_checkbutton">
+                        <property name="label" translatable="yes">Disable Dead _Peer Detection</property>
+                        <property name="use_action_appearance">False</property>
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
-                        <property name="label" translatable="yes">_Encryption method:</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="tooltip_text" translatable="yes">Disable sending DPD packets (sets 
timeout to 0)
+config: DPD idle timeout (our side) 0</property>
                         <property name="use_underline">True</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
                       </object>
                       <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">0</property>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">6</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label41">
+                      <object class="GtkLabel" id="local_port_label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">_NAT traversal:</property>
+                        <property name="label" translatable="yes">_Local port:</property>
                         <property name="use_underline">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
-                        <property name="top_attach">1</property>
+                        <property name="top_attach">5</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label5">
+                      <object class="GtkLabel" id="label6">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">_IKE DH Group:</property>
+                        <property name="label" translatable="yes">Perfect _Forward Secrecy:</property>
                         <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">pfsecrecy_combo</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
-                        <property name="top_attach">2</property>
+                        <property name="top_attach">4</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label6">
+                      <object class="GtkLabel" id="label5">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">Perfect _Forward Secrecy:</property>
+                        <property name="label" translatable="yes">_IKE DH Group:</property>
                         <property name="use_underline">True</property>
-                        <property name="mnemonic_widget">pfsecrecy_combo</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -733,29 +737,48 @@ config: Application version &lt;ASCII string&gt;</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="local_port_label">
+                      <object class="GtkLabel" id="label41">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">_Local port:</property>
+                        <property name="label" translatable="yes">_NAT traversal:</property>
                         <property name="use_underline">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
-                        <property name="top_attach">4</property>
+                        <property name="top_attach">2</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkComboBox" id="encryption_combo">
+                      <object class="GtkSpinButton" id="local_port_spinbutton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="tooltip_text" translatable="yes">Local ISAKMP port to use (0 means 
random port; 500 is vpnc's default)
+config: Local Port &lt;0-65535&gt;</property>
+                        <property name="width_chars">5</property>
+                        <property name="text" translatable="yes">0</property>
+                        <property name="adjustment">adjustment1</property>
+                        <property name="climb_rate">1</property>
+                        <property name="numeric">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">5</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBox" id="pfsecrecy_combo">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="tooltip_text" translatable="yes">Encryption method
-config: nothing for Secure, 'Enable Single DES' for Weak, 'Enable no encryption' for None</property>
-                        <property name="model">model3</property>
+                        <property name="tooltip_text" translatable="yes">Diffie-Hellman group to use for PFS
+config: Perfect Forward Secrecy &lt;nopfs/dh1/dh2/dh5/server&gt;</property>
+                        <property name="model">model7</property>
                         <child>
-                          <object class="GtkCellRendererText" id="renderer3"/>
+                          <object class="GtkCellRendererText" id="renderer7"/>
                           <attributes>
                             <attribute name="text">0</attribute>
                           </attributes>
@@ -763,20 +786,20 @@ config: nothing for Secure, 'Enable Single DES' for Weak, 'Enable no encryption'
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
-                        <property name="top_attach">0</property>
+                        <property name="top_attach">4</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkComboBox" id="natt_combo">
+                      <object class="GtkComboBox" id="dhgroup_combo">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="tooltip_text" translatable="yes">NAT traversal method to use
-config: NAT Traversal Mode &lt;natt/none/force-natt/cisco-udp&gt;</property>
-                        <property name="model">model4</property>
+                        <property name="tooltip_text" translatable="yes">Name of the IKE DH group
+config: IKE DH Group &lt;dh1/dh2/dh5&gt;</property>
+                        <property name="model">model5</property>
                         <child>
-                          <object class="GtkCellRendererText" id="renderer4"/>
+                          <object class="GtkCellRendererText" id="renderer5"/>
                           <attributes>
                             <attribute name="text">0</attribute>
                           </attributes>
@@ -784,20 +807,20 @@ config: NAT Traversal Mode &lt;natt/none/force-natt/cisco-udp&gt;</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
-                        <property name="top_attach">1</property>
+                        <property name="top_attach">3</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkComboBox" id="dhgroup_combo">
+                      <object class="GtkComboBox" id="natt_combo">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="tooltip_text" translatable="yes">Name of the IKE DH group
-config: IKE DH Group &lt;dh1/dh2/dh5&gt;</property>
-                        <property name="model">model5</property>
+                        <property name="tooltip_text" translatable="yes">NAT traversal method to use
+config: NAT Traversal Mode &lt;natt/none/force-natt/cisco-udp&gt;</property>
+                        <property name="model">model4</property>
                         <child>
-                          <object class="GtkCellRendererText" id="renderer5"/>
+                          <object class="GtkCellRendererText" id="renderer4"/>
                           <attributes>
                             <attribute name="text">0</attribute>
                           </attributes>
@@ -811,14 +834,14 @@ config: IKE DH Group &lt;dh1/dh2/dh5&gt;</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkComboBox" id="pfsecrecy_combo">
+                      <object class="GtkComboBox" id="encryption_combo">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="tooltip_text" translatable="yes">Diffie-Hellman group to use for PFS
-config: Perfect Forward Secrecy &lt;nopfs/dh1/dh2/dh5/server&gt;</property>
-                        <property name="model">model7</property>
+                        <property name="tooltip_text" translatable="yes">Encryption method
+config: nothing for Secure, 'Enable Single DES' for Weak, 'Enable no encryption' for None</property>
+                        <property name="model">model3</property>
                         <child>
-                          <object class="GtkCellRendererText" id="renderer7"/>
+                          <object class="GtkCellRendererText" id="renderer3"/>
                           <attributes>
                             <attribute name="text">0</attribute>
                           </attributes>
@@ -826,46 +849,52 @@ config: Perfect Forward Secrecy &lt;nopfs/dh1/dh2/dh5/server&gt;</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
-                        <property name="top_attach">3</property>
+                        <property name="top_attach">1</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkSpinButton" id="local_port_spinbutton">
+                      <object class="GtkEntry" id="interface_name_entry">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="tooltip_text" translatable="yes">Local ISAKMP port to use (0 means 
random port; 500 is vpnc's default)
-config: Local Port &lt;0-65535&gt;</property>
-                        <property name="width_chars">5</property>
-                        <property name="text" translatable="yes">0</property>
-                        <property name="adjustment">adjustment1</property>
-                        <property name="climb_rate">1</property>
-                        <property name="numeric">True</property>
+                        <property name="tooltip_text" translatable="yes">Tunnel interface name to use
+config: Interface name &lt;name&gt;</property>
+                        <property name="max_length">15</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
-                        <property name="top_attach">4</property>
+                        <property name="top_attach">0</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkCheckButton" id="disable_dpd_checkbutton">
-                        <property name="label" translatable="yes">Disable Dead _Peer Detection</property>
-                        <property name="use_action_appearance">False</property>
+                      <object class="GtkLabel" id="label31">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="tooltip_text" translatable="yes">Disable sending DPD packets (sets 
timeout to 0)
-config: DPD idle timeout (our side) 0</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">_Encryption method:</property>
                         <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">1</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label7">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
                         <property name="xalign">0</property>
-                        <property name="draw_indicator">True</property>
+                        <property name="label" translatable="yes">Tunnel _interface name:</property>
+                        <property name="use_underline">True</property>
                       </object>
                       <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">5</property>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
                         <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
diff --git a/properties/nm-vpnc.c b/properties/nm-vpnc.c
index 7e7dcb3..57ac61c 100644
--- a/properties/nm-vpnc.c
+++ b/properties/nm-vpnc.c
@@ -453,6 +453,7 @@ init_plugin_ui (VpncPluginUiWidget *self,
                 GError **error)
 {
        VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
+       NMSettingConnection *s_con = NULL;
        NMSettingVPN *s_vpn = NULL;
        GtkWidget *widget;
        GtkListStore *store;
@@ -466,8 +467,10 @@ init_plugin_ui (VpncPluginUiWidget *self,
        gboolean enabled = FALSE;
        GtkFileFilter *filter;
 
-       if (connection)
+       if (connection) {
+               s_con = nm_connection_get_setting_connection (connection);
                s_vpn = nm_connection_get_setting_vpn (connection);
+       }
 
        priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
@@ -607,6 +610,16 @@ init_plugin_ui (VpncPluginUiWidget *self,
        }
        g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
 
+       /* Interface name */
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "interface_name_entry"));
+       g_return_val_if_fail (widget != NULL, FALSE);
+       if (s_con) {
+               value = nm_setting_connection_get_interface_name (s_con);
+               if (value && strlen (value))
+                       gtk_entry_set_text (GTK_ENTRY (widget), value);
+       }
+       g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
+
        active = -1;
        store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
        if (s_vpn)
@@ -892,6 +905,7 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
 {
        VpncPluginUiWidget *self = VPNC_PLUGIN_UI_WIDGET (iface);
        VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
+       NMSettingConnection *s_con;
        NMSettingVPN *s_vpn;
        GtkWidget *widget;
        char *str;
@@ -902,9 +916,17 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
        if (!check_validity (self, error))
                return FALSE;
 
+       s_con = nm_connection_get_setting_connection (connection);
+
        s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
        g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_DBUS_SERVICE_VPNC, NULL);
 
+       /* Interface name */
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "interface_name_entry"));
+       str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+       if (str && strlen (str))
+               g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, str, NULL);
+
        /* Gateway */
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "gateway_entry"));
        str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
@@ -1343,6 +1365,13 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
        s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
        nm_connection_add_setting (connection, NM_SETTING (s_ip4));
 
+       /* Interface Name */
+       buf = key_file_get_string_helper (keyfile, "main", "InterfaceName", NULL);
+       if (buf) {
+               g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, buf, NULL);
+               g_free (buf);
+       }
+
        /* Gateway */
        buf = key_file_get_string_helper (keyfile, "main", "Host", NULL);
        if (buf) {
@@ -1582,6 +1611,7 @@ export (NMVpnPluginUiInterface *iface,
        FILE *f;
        const char *value;
        const char *gateway = NULL;
+       GString *interface_name = NULL;
        gboolean enablenat = TRUE;
        gboolean singledes = FALSE;
        const char *groupname = NULL;
@@ -1614,6 +1644,11 @@ export (NMVpnPluginUiInterface *iface,
                return FALSE;
        }
 
+       interface_name = g_string_new("");
+       value = nm_setting_connection_get_interface_name (s_con);
+       if (value && strlen (value))
+               g_string_printf (interface_name, "InterfaceName=%s\n", value);
+
        value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_GATEWAY);
        if (value && strlen (value))
                gateway = value;
@@ -1729,6 +1764,7 @@ export (NMVpnPluginUiInterface *iface,
        fprintf (f, 
                 "[main]\n"
                 "Description=%s\n"
+                "%s"
                 "Host=%s\n"
                 "AuthType=1\n"
                 "GroupName=%s\n"
@@ -1770,6 +1806,7 @@ export (NMVpnPluginUiInterface *iface,
                 "X-NM-SaveGroupPassword=%s\n"
                 "%s\n",
                 /* Description */   nm_setting_connection_get_id (s_con),
+                /* InterfaceName */ (interface_name->len) ? interface_name->str : "",
                 /* Host */          gateway,
                 /* GroupName */     groupname,
                 /* GroupPassword */ group_pw ? group_pw : "",
@@ -1789,6 +1826,8 @@ export (NMVpnPluginUiInterface *iface,
        success = TRUE;
 
 done:
+       if (interface_name)
+               g_string_free (interface_name, TRUE);
        if (routes)
                g_string_free (routes, TRUE);
        if (uselegacyikeport)
diff --git a/src/nm-vpnc-service.c b/src/nm-vpnc-service.c
index fc77c51..7e2dc86 100644
--- a/src/nm-vpnc-service.c
+++ b/src/nm-vpnc-service.c
@@ -757,6 +757,7 @@ write_one_property (const char *key, const char *value, gpointer user_data)
 
 static gboolean
 nm_vpnc_config_write (gint vpnc_fd,
+                      NMSettingConnection *s_con,
                       NMSettingVPN *s_vpn,
                       GError **error)
 {
@@ -766,13 +767,19 @@ nm_vpnc_config_write (gint vpnc_fd,
        const char *default_username;
        const char *pw_type;
        const char *local_port;
+       const char *interface_name;
        NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
 
+       interface_name = nm_setting_connection_get_interface_name(s_con);
+
        default_username = nm_setting_vpn_get_user_name (s_vpn);
 
        if (debug)
                write_config_option (vpnc_fd, "Debug 3\n");
 
+       if (interface_name && strlen(interface_name) > 0)
+               write_config_option (vpnc_fd, "Interface name %s\n", interface_name);
+
        write_config_option (vpnc_fd, "Script " NM_VPNC_HELPER_PATH "\n");
 
        write_config_option (vpnc_fd,
@@ -852,8 +859,12 @@ _connect_common (NMVPNPlugin   *plugin,
 {
        NMVPNCPluginPrivate *priv = NM_VPNC_PLUGIN_GET_PRIVATE (plugin);
        NMSettingVPN *s_vpn;
+       NMSettingConnection *s_con;
        char end[] = { 0x04 };
 
+       s_con = nm_connection_get_setting_connection (connection);
+       g_assert (s_con);
+
        s_vpn = nm_connection_get_setting_vpn (connection);
        g_assert (s_vpn);
 
@@ -871,7 +882,7 @@ _connect_common (NMVPNPlugin   *plugin,
        if (getenv ("NM_VPNC_DUMP_CONNECTION") || debug)
                nm_connection_dump (connection);
 
-       if (!nm_vpnc_config_write (priv->infd, s_vpn, error))
+       if (!nm_vpnc_config_write (priv->infd, s_con, s_vpn, error))
                goto out;
 
        if (interactive)


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