By default interface name is 'tun' or 'tap' with an incrementing number (tun0, tun1, ... or tap0, tap1, ...). By specifying 'Interface name' in vpnc config you can change the name to something more descriptice. --- properties/import-export.c | 12 ++++++++++-- properties/nm-openvpn-dialog.ui | 40 ++++++++++++++++++++++++++++++++++++++++ properties/nm-openvpn.c | 26 +++++++++++++++++++++++++- src/nm-openvpn-service.c | 11 +++++++++-- 4 files changed, 84 insertions(+), 5 deletions(-)
diff --git a/properties/import-export.c b/properties/import-export.c index 6b1dad7..2ee9819 100644 --- a/properties/import-export.c +++ b/properties/import-export.c @@ -326,7 +326,8 @@ do_import (const char *path, char **lines, GError **error) if (!strncmp (*line, DEV_TAG, strlen (DEV_TAG))) { items = get_args (*line + strlen (DEV_TAG), &nitems); if (nitems == 1) { - nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_DEV, items[0]); + g_object_set (G_OBJECT (s_con), + NM_SETTING_CONNECTION_INTERFACE_NAME, items[0], NULL); } else g_warning ("%s: invalid number of arguments in option '%s'", __func__, *line); @@ -865,6 +866,8 @@ do_export (const char *path, NMConnection *connection, GError **error) if (value && !strcmp (value, "yes")) proto_udp = FALSE; + /* interface name is read from generic connection setting. Read this + * for backwards compatibility. */ value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_DEV); if (value && strlen (value)) device = value; @@ -980,7 +983,12 @@ do_export (const char *path, NMConnection *connection, GError **error) if (value && strlen (value)) fprintf (f, FRAGMENT_TAG " %d\n", (int) strtol (value, NULL, 10)); - fprintf (f, "dev %s\n", device ? device : (device_type ? device_type : device_default)); + value = nm_setting_connection_get_interface_name (s_con); + if (value && strlen (value)) + fprintf (f, "dev %s\n", value); + else + fprintf (f, "dev %s\n", device ? device : (device_type ? device_type : device_default)); + if (device_type) fprintf (f, "dev-type %s\n", device_type); fprintf (f, "proto %s\n", proto_udp ? "udp" : "tcp"); diff --git a/properties/nm-openvpn-dialog.ui b/properties/nm-openvpn-dialog.ui index 6dfda15..21c730d 100644 --- a/properties/nm-openvpn-dialog.ui +++ b/properties/nm-openvpn-dialog.ui @@ -1313,9 +1313,45 @@ config: http-proxy-retry or socks-proxy-retry</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="n_columns">2</property> + <property name="n_rows">2</property> <property name="column_spacing">6</property> <property name="row_spacing">6</property> <child> + <object class="GtkLabel" id="label36"> + <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"></property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment30"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="xscale">0</property> + <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> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="y_options"></property> + </packing> + </child> + <child> <object class="GtkLabel" id="label23"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -1325,6 +1361,8 @@ config: http-proxy-retry or socks-proxy-retry</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"></property> <property name="y_options"></property> </packing> @@ -1345,6 +1383,8 @@ config: remote</property> </child> </object> <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> <property name="left_attach">1</property> <property name="right_attach">2</property> <property name="y_options"></property> diff --git a/properties/nm-openvpn.c b/properties/nm-openvpn.c index b49fece..ad5f1e5 100644 --- a/properties/nm-openvpn.c +++ b/properties/nm-openvpn.c @@ -320,6 +320,7 @@ static gboolean init_plugin_ui (OpenvpnPluginUiWidget *self, NMConnection *connection, GError **error) { OpenvpnPluginUiWidgetPrivate *priv = OPENVPN_PLUGIN_UI_WIDGET_GET_PRIVATE (self); + NMSettingConnection *s_con = NULL; NMSettingVPN *s_vpn; GtkWidget *widget; GtkListStore *store; @@ -328,10 +329,23 @@ init_plugin_ui (OpenvpnPluginUiWidget *self, NMConnection *connection, GError ** const char *value; const char *contype = NM_OPENVPN_CONTYPE_TLS; - s_vpn = nm_connection_get_setting_vpn (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); + 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_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); + widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "gateway_entry")); g_return_val_if_fail (widget != NULL, FALSE); gtk_size_group_add_widget (priv->group, widget); @@ -470,6 +484,7 @@ update_connection (NMVpnPluginUiWidgetInterface *iface, { OpenvpnPluginUiWidget *self = OPENVPN_PLUGIN_UI_WIDGET (iface); OpenvpnPluginUiWidgetPrivate *priv = OPENVPN_PLUGIN_UI_WIDGET_GET_PRIVATE (self); + NMSettingConnection *s_con; NMSettingVPN *s_vpn; GtkWidget *widget; char *str, *auth_type; @@ -478,9 +493,18 @@ 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_OPENVPN, 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)); diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c index c8c9240..f5cd4be 100644 --- a/src/nm-openvpn-service.c +++ b/src/nm-openvpn-service.c @@ -859,6 +859,7 @@ update_io_data_from_vpn_setting (NMOpenvpnPluginIOData *io_data, static gboolean nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin, + NMSettingConnection *s_con, NMSettingVPN *s_vpn, const char *default_username, GError **error) @@ -993,7 +994,9 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin, add_openvpn_arg (args, "--nobind"); /* Device and device type, defaults to tun */ - tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_DEV); + tmp = nm_setting_connection_get_interface_name(s_con); + if (!tmp) + 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); tmp3 = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TAP_DEV); add_openvpn_arg (args, "--dev"); @@ -1352,10 +1355,14 @@ _connect_common (NMVPNPlugin *plugin, GHashTable *details, GError **error) { + NMSettingConnection *s_con; NMSettingVPN *s_vpn; const char *connection_type; const char *user_name; + s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); + g_assert (s_con); + s_vpn = nm_connection_get_setting_vpn (connection); if (!s_vpn) { g_set_error_literal (error, @@ -1384,7 +1391,7 @@ _connect_common (NMVPNPlugin *plugin, /* Finally try to start OpenVPN */ user_name = nm_setting_vpn_get_user_name (s_vpn); - if (!nm_openvpn_start_openvpn_binary (NM_OPENVPN_PLUGIN (plugin), s_vpn, user_name, error)) + if (!nm_openvpn_start_openvpn_binary (NM_OPENVPN_PLUGIN (plugin), s_con, s_vpn, user_name, error)) return FALSE; return TRUE; -- 2.1.1 _______________________________________________ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list