summaryrefslogtreecommitdiff
path: root/src/connection-editor/page-ethernet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/connection-editor/page-ethernet.c')
-rw-r--r--src/connection-editor/page-ethernet.c84
1 files changed, 43 insertions, 41 deletions
diff --git a/src/connection-editor/page-ethernet.c b/src/connection-editor/page-ethernet.c
index e82c1b94..5363d9a7 100644
--- a/src/connection-editor/page-ethernet.c
+++ b/src/connection-editor/page-ethernet.c
@@ -37,8 +37,8 @@ G_DEFINE_TYPE (CEPageEthernet, ce_page_ethernet, CE_TYPE_PAGE)
typedef struct {
NMSettingWired *setting;
- GtkComboBoxText *device_mac; /* Permanent MAC of the device */
- GtkEntry *cloned_mac; /* Cloned MAC - used for MAC spoofing */
+ GtkComboBoxText *device_combo; /* Device identification (ifname and/or MAC) */
+ GtkEntry *cloned_mac; /* Cloned MAC - used for MAC spoofing */
GtkComboBox *port;
GtkComboBox *speed;
GtkToggleButton *duplex;
@@ -68,19 +68,21 @@ ethernet_private_init (CEPageEthernet *self)
builder = CE_PAGE (self)->builder;
- priv->device_mac = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
- gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (priv->device_mac), 0);
- gtk_widget_set_tooltip_text (GTK_WIDGET (priv->device_mac),
- _("This option locks this connection to the network device specified by its permanent MAC address entered here. Example: 00:11:22:33:44:55"));
+ priv->device_combo = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
+ gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (priv->device_combo), 0);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (priv->device_combo),
+ _("This option locks this connection to the network device specified "
+ "either by its interface name or permanent MAC or both. Examples: "
+ "\"em1\", \"3C:97:0E:42:1A:19\", \"em1 (3C:97:0E:42:1A:19)\""));
- vbox = GTK_WIDGET (gtk_builder_get_object (builder, "ethernet_device_mac_vbox"));
- gtk_container_add (GTK_CONTAINER (vbox), GTK_WIDGET (priv->device_mac));
- gtk_widget_set_halign (GTK_WIDGET (priv->device_mac), GTK_ALIGN_FILL);
- gtk_widget_show_all (GTK_WIDGET (priv->device_mac));
+ vbox = GTK_WIDGET (gtk_builder_get_object (builder, "ethernet_device_vbox"));
+ gtk_container_add (GTK_CONTAINER (vbox), GTK_WIDGET (priv->device_combo));
+ gtk_widget_set_halign (GTK_WIDGET (priv->device_combo), GTK_ALIGN_FILL);
+ gtk_widget_show_all (GTK_WIDGET (priv->device_combo));
- /* Set mnemonic widget for device MAC label */
- label = GTK_LABEL (gtk_builder_get_object (builder, "ethernet_device_mac_label"));
- gtk_label_set_mnemonic_widget (label, GTK_WIDGET (priv->device_mac));
+ /* Set mnemonic widget for Device label */
+ label = GTK_LABEL (gtk_builder_get_object (builder, "ethernet_device_label"));
+ gtk_label_set_mnemonic_widget (label, GTK_WIDGET (priv->device_combo));
priv->cloned_mac = GTK_ENTRY (gtk_builder_get_object (builder, "ethernet_cloned_mac"));
priv->port = GTK_COMBO_BOX (gtk_builder_get_object (builder, "ethernet_port"));
@@ -106,8 +108,7 @@ populate_ui (CEPageEthernet *self)
int port_idx = PORT_DEFAULT;
int speed_idx;
int mtu_def;
- char **mac_list;
- const char *s_mac_str;
+ const char *s_mac, *s_ifname;
/* Port */
port = nm_setting_wired_get_port (setting);
@@ -154,19 +155,18 @@ populate_ui (CEPageEthernet *self)
gtk_toggle_button_set_active (priv->autonegotiate,
nm_setting_wired_get_auto_negotiate (setting));
- /* Device MAC address */
- mac_list = ce_page_get_mac_list (CE_PAGE (self), NM_TYPE_DEVICE_ETHERNET,
- NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
- s_mac_str = nm_setting_wired_get_mac_address (setting);
- ce_page_setup_mac_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_mac),
- s_mac_str, mac_list);
- g_strfreev (mac_list);
- g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);
+ /* Device ifname/MAC */
+ s_ifname = nm_connection_get_interface_name (CE_PAGE (self)->connection);
+ s_mac = nm_setting_wired_get_mac_address (setting);
+ ce_page_setup_device_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_combo),
+ NM_TYPE_DEVICE_ETHERNET, s_ifname,
+ s_mac, NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, TRUE);
+ g_signal_connect (priv->device_combo, "changed", G_CALLBACK (stuff_changed), self);
/* Cloned MAC address */
- s_mac_str = nm_setting_wired_get_cloned_mac_address (setting);
- if (s_mac_str)
- gtk_entry_set_text (priv->cloned_mac, s_mac_str);
+ s_mac = nm_setting_wired_get_cloned_mac_address (setting);
+ if (s_mac)
+ gtk_entry_set_text (priv->cloned_mac, s_mac);
g_signal_connect (priv->cloned_mac, "changed", G_CALLBACK (stuff_changed), self);
/* MTU */
@@ -253,12 +253,17 @@ static void
ui_to_setting (CEPageEthernet *self)
{
CEPageEthernetPrivate *priv = CE_PAGE_ETHERNET_GET_PRIVATE (self);
+ NMSettingConnection *s_con;
const char *port;
guint32 speed;
+ char *ifname = NULL;
char *device_mac = NULL;
- char *cloned_mac = NULL;
+ const char *cloned_mac;
GtkWidget *entry;
+ s_con = nm_connection_get_setting_connection (CE_PAGE (self)->connection);
+ g_return_if_fail (s_con != NULL);
+
/* Port */
switch (gtk_combo_box_get_active (priv->port)) {
case PORT_TP:
@@ -297,14 +302,17 @@ ui_to_setting (CEPageEthernet *self)
break;
}
- entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+ entry = gtk_bin_get_child (GTK_BIN (priv->device_combo));
if (entry)
- device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, NULL);
- cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, NULL);
+ ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, &ifname, &device_mac);
+ cloned_mac = gtk_entry_get_text (priv->cloned_mac);
+ g_object_set (s_con,
+ NM_SETTING_CONNECTION_INTERFACE_NAME, ifname,
+ NULL);
g_object_set (priv->setting,
NM_SETTING_WIRED_MAC_ADDRESS, device_mac,
- NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac,
+ NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac && *cloned_mac ? cloned_mac : NULL,
NM_SETTING_WIRED_PORT, port,
NM_SETTING_WIRED_SPEED, speed,
NM_SETTING_WIRED_DUPLEX, gtk_toggle_button_get_active (priv->duplex) ? "full" : "half",
@@ -312,8 +320,8 @@ ui_to_setting (CEPageEthernet *self)
NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (priv->mtu),
NULL);
+ g_free (ifname);
g_free (device_mac);
- g_free (cloned_mac);
}
static gboolean
@@ -321,22 +329,16 @@ validate (CEPage *page, NMConnection *connection, GError **error)
{
CEPageEthernet *self = CE_PAGE_ETHERNET (page);
CEPageEthernetPrivate *priv = CE_PAGE_ETHERNET_GET_PRIVATE (self);
- gboolean invalid = FALSE;
- char *ignore;
GtkWidget *entry;
- entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+ entry = gtk_bin_get_child (GTK_BIN (priv->device_combo));
if (entry) {
- ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid);
- if (invalid)
+ if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, NULL, NULL))
return FALSE;
- g_free (ignore);
}
- ignore = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, &invalid);
- if (invalid)
+ if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER))
return FALSE;
- g_free (ignore);
ui_to_setting (self);
return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);