Re: [PATCH 1/1] vpnc: add support to change interface name



On Mon, 2014-09-22 at 10:02 +0200, Christian Hesse wrote:
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 descriptice.

So this is great, and ties in with some other stuff we're doing.
However, one change I'd like to request.  Instead of putting the
interface name into the VPN data (like the other vpnc-specific options),
lets put it into the NMSettingConnection setting's 'interface-name'
property.

So in init_plugin_ui() instead of reading the VPN setting, you'd do
something like:

    NMSettingConnection *s_con;

    gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
    s_con = nm_connection_get_setting_connection (connection);
    value = NULL;
    if (s_con)
        value = nm_setting_connection_get_interface_name (s_con);
    if (value)
        gtk_entry_set_text (GTK_ENTRY (widget), value);
    g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK
(stuff_changed_cb), self);

And do the reverse in update_connection(), except that you'd use:

    g_object_set (G_OBJECT (s_con),
NM_SETTING_CONNECTION_INTERFACE_NAME, str, NULL);

instead of nm_setting_vpn_add_data_item().  Also, this means we don't
need NM_VPNC_KEY_INTERFACE_NAME either, since the name is carried in a
standard connection property.

Does that make sense?  If not, let me know and I'll happily clarify.

Thanks!
Dan

---
 properties/nm-vpnc-dialog.ui | 89 +++++++++++++++++++++++++++++---------------
 properties/nm-vpnc.c         | 30 +++++++++++++++
 src/nm-vpnc-service.c        |  1 +
 src/nm-vpnc-service.h        |  1 +
 4 files changed, 92 insertions(+), 29 deletions(-)

diff --git a/properties/nm-vpnc-dialog.ui b/properties/nm-vpnc-dialog.ui
index 168782e..6c46785 100644
--- a/properties/nm-vpnc-dialog.ui
+++ b/properties/nm-vpnc-dialog.ui
@@ -555,7 +555,7 @@ config: DPD idle timeout (our side) 0</property>
               <object class="GtkTable" id="table2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="n_rows">8</property>
+                <property name="n_rows">9</property>
                 <property name="n_columns">3</property>
                 <property name="column_spacing">6</property>
                 <property name="row_spacing">6</property>
@@ -574,8 +574,8 @@ config: DPD idle timeout (our side) 0</property>
                   <packing>
                     <property name="left_attach">2</property>
                     <property name="right_attach">3</property>
-                    <property name="top_attach">4</property>
-                    <property name="bottom_attach">5</property>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
                   </packing>
                 </child>
                 <child>
@@ -593,8 +593,8 @@ config: DPD idle timeout (our side) 0</property>
                   <packing>
                     <property name="left_attach">2</property>
                     <property name="right_attach">3</property>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
                   </packing>
                 </child>
                 <child>
@@ -611,8 +611,8 @@ config: DPD idle timeout (our side) 0</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">5</property>
-                    <property name="bottom_attach">6</property>
+                    <property name="top_attach">6</property>
+                    <property name="bottom_attach">7</property>
                   </packing>
                 </child>
                 <child>
@@ -626,8 +626,8 @@ config: IPSec secret &lt;group_password&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">4</property>
-                    <property name="bottom_attach">5</property>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
@@ -641,8 +641,8 @@ config: IPSec secret &lt;group_password&gt;</property>
                     <property name="mnemonic_widget">group_password_entry</property>
                   </object>
                   <packing>
-                    <property name="top_attach">4</property>
-                    <property name="bottom_attach">5</property>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -657,6 +657,8 @@ config: IPSec secret &lt;group_password&gt;</property>
                     <property name="mnemonic_widget">gateway_entry</property>
                   </object>
                   <packing>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -666,13 +668,27 @@ config: IPSec secret &lt;group_password&gt;</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
+                    <property name="label" translatable="yes">_Interface name:</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">interface_name_entry</property>
+                  </object>
+                  <packing>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label25">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
                     <property name="label" translatable="yes">G_roup name:</property>
                     <property name="use_underline">True</property>
                     <property name="mnemonic_widget">group_entry</property>
                   </object>
                   <packing>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -687,6 +703,21 @@ config: IPSec gateway &lt;gateway&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="interface_name_entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                 <property name="tooltip_text" translatable="yes">Name of the tun/tap
+network interface</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
@@ -700,8 +731,8 @@ config: IPSec ID &lt;group_name&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
@@ -715,8 +746,8 @@ config: IPSec ID &lt;group_name&gt;</property>
                     <property name="mnemonic_widget">user_password_entry</property>
                   </object>
                   <packing>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -732,8 +763,8 @@ config: Xauth password &lt;password&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
@@ -749,8 +780,8 @@ config: Xauth username &lt;user_name&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
@@ -764,8 +795,8 @@ config: Xauth username &lt;user_name&gt;</property>
                     <property name="mnemonic_widget">user_entry</property>
                   </object>
                   <packing>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -785,8 +816,8 @@ config: IKE Authmode hybrid</property>
                   </object>
                   <packing>
                     <property name="right_attach">3</property>
-                    <property name="top_attach">6</property>
-                    <property name="bottom_attach">7</property>
+                    <property name="top_attach">7</property>
+                    <property name="bottom_attach">8</property>
                   </packing>
                 </child>
                 <child>
@@ -806,8 +837,8 @@ config: IKE Authmode hybrid</property>
                     </child>
                   </object>
                   <packing>
-                    <property name="top_attach">7</property>
-                    <property name="bottom_attach">8</property>
+                    <property name="top_attach">8</property>
+                    <property name="bottom_attach">9</property>
                   </packing>
                 </child>
                 <child>
@@ -820,8 +851,8 @@ config: CA-File</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">7</property>
-                    <property name="bottom_attach">8</property>
+                    <property name="top_attach">8</property>
+                    <property name="bottom_attach">9</property>
                   </packing>
                 </child>
                 <child>
diff --git a/properties/nm-vpnc.c b/properties/nm-vpnc.c
index 7e7dcb3..3428a62 100644
--- a/properties/nm-vpnc.c
+++ b/properties/nm-vpnc.c
@@ -481,6 +481,16 @@ init_plugin_ui (VpncPluginUiWidget *self,
      }
      g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
 
+     widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "interface_name_entry"));
+     g_return_val_if_fail (widget != NULL, FALSE);
+     gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
+     if (s_vpn) {
+             value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_INTERFACE_NAME);
+             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);
+
      widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "group_entry"));
      g_return_val_if_fail (widget != NULL, FALSE);
      gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
@@ -911,6 +921,12 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
      if (str && strlen (str))
              nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_GATEWAY, str);
 
+     /* 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))
+             nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_INTERFACE_NAME, str);
+
      /* Group name */
      widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "group_entry"));
      str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
@@ -1357,6 +1373,13 @@ import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
              goto error;
      }
 
+     /* Interface name */
+     buf = key_file_get_string_helper (keyfile, "main", "InterfaceName", NULL);
+     if (buf) {
+             nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_INTERFACE_NAME, buf);
+             g_free (buf);
+     }
+
      /* Group name */
      buf = key_file_get_string_helper (keyfile, "main", "GroupName", NULL);
      if (buf) {
@@ -1582,6 +1605,7 @@ export (NMVpnPluginUiInterface *iface,
      FILE *f;
      const char *value;
      const char *gateway = NULL;
+     const char *interface_name = NULL;
      gboolean enablenat = TRUE;
      gboolean singledes = FALSE;
      const char *groupname = NULL;
@@ -1625,6 +1649,10 @@ export (NMVpnPluginUiInterface *iface,
              goto done;
      }
 
+     value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_INTERFACE_NAME);
+     if (value && strlen (value))
+             interface_name = value;
+
      value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_ID);
      if (value && strlen (value))
              groupname = value;
@@ -1729,6 +1757,7 @@ export (NMVpnPluginUiInterface *iface,
      fprintf (f, 
               "[main]\n"
               "Description=%s\n"
+              "InterfaceName=%s\n"
               "Host=%s\n"
               "AuthType=1\n"
               "GroupName=%s\n"
@@ -1770,6 +1799,7 @@ export (NMVpnPluginUiInterface *iface,
               "X-NM-SaveGroupPassword=%s\n"
               "%s\n",
               /* Description */   nm_setting_connection_get_id (s_con),
+              /* InterfaceName */ interface_name,
               /* Host */          gateway,
               /* GroupName */     groupname,
               /* GroupPassword */ group_pw ? group_pw : "",
diff --git a/src/nm-vpnc-service.c b/src/nm-vpnc-service.c
index d5bee61..e82a968 100644
--- a/src/nm-vpnc-service.c
+++ b/src/nm-vpnc-service.c
@@ -85,6 +85,7 @@ typedef struct {
 #define LEGACY_NAT_KEEPALIVE "NAT-Keepalive packet interval"
 
 static ValidProperty valid_properties[] = {
+     { NM_VPNC_KEY_INTERFACE_NAME,        ITEM_TYPE_STRING, 0, 0 },
      { NM_VPNC_KEY_GATEWAY,               ITEM_TYPE_STRING, 0, 0 },
      { NM_VPNC_KEY_ID,                    ITEM_TYPE_STRING, 0, 0 },
      { NM_VPNC_KEY_XAUTH_USER,            ITEM_TYPE_STRING, 0, 0 },
diff --git a/src/nm-vpnc-service.h b/src/nm-vpnc-service.h
index 579a7d0..54b7a09 100644
--- a/src/nm-vpnc-service.h
+++ b/src/nm-vpnc-service.h
@@ -37,6 +37,7 @@
 #define NM_DBUS_INTERFACE_VPNC  "org.freedesktop.NetworkManager.vpnc"
 #define NM_DBUS_PATH_VPNC       "/org/freedesktop/NetworkManager/vpnc"
 
+#define NM_VPNC_KEY_INTERFACE_NAME "Interface name"
 #define NM_VPNC_KEY_GATEWAY "IPSec gateway"
 #define NM_VPNC_KEY_ID "IPSec ID"
 #define NM_VPNC_KEY_SECRET "IPSec secret"




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