static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingVlan *s_vlan; NMSettingWired *s_wired; const char *ctype, *dev_iface_name, *vlan_iface_name; const GByteArray *mac_address; char *mac_address_str; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_VLAN_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_NOT_VLAN_CONNECTION, "The connection was not a VLAN connection."); return FALSE; } s_vlan = nm_connection_get_setting_vlan (connection); if (!s_vlan) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_INVALID_VLAN_CONNECTION, "The connection was not a valid VLAN connection."); return FALSE; } if (nm_setting_vlan_get_id (s_vlan) != nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device))) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_ID_MISMATCH, "The VLAN identifiers of the device and the connection didn't match."); return FALSE; } dev_iface_name = nm_device_get_iface (device); vlan_iface_name = nm_setting_vlan_get_interface_name (s_vlan); if (vlan_iface_name && g_strcmp0 (dev_iface_name, vlan_iface_name) != 0) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_INTERFACE_MISMATCH, "The interfaces of the device and the connection didn't match."); return FALSE; } s_wired = nm_connection_get_setting_wired (connection); if (s_wired) mac_address = nm_setting_wired_get_mac_address (s_wired); else mac_address = NULL; if (mac_address) { mac_address_str = nm_utils_hwaddr_ntoa_len (mac_address->data, mac_address->len); if (!g_strcmp0 (mac_address_str, NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address)) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_MAC_MISMATCH, "The hardware address of the device and the connection didn't match."); } g_free (mac_address_str); } return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->connection_compatible (device, connection, error); }
static void populate_ui (CEPageVlan *self) { CEPageVlanPrivate *priv = CE_PAGE_VLAN_GET_PRIVATE (self); GSList *devices, *d_iter; NMConnection *parent_connection = NULL; NMDevice *device, *parent_device = NULL; const char *parent, *iface, *current_parent; int i, mtu_def, mtu_val; devices = get_vlan_devices (self); /* Parent */ build_vlan_parent_list (self, devices); parent = nm_setting_vlan_get_parent (priv->setting); if (parent) { /* UUID? */ parent_connection = (NMConnection *)nm_remote_settings_get_connection_by_uuid (CE_PAGE (self)->settings, parent); if (!parent_connection) { /* Interface name? */ for (d_iter = devices; d_iter; d_iter = d_iter->next) { device = d_iter->data; if (!g_strcmp0 (parent, nm_device_get_iface (device))) { parent_device = device; break; } } } } /* If NMSettingVlan:parent didn't indicate a device, but we have a * wired setting, figure out the device from that. */ if (priv->s_hw && !parent_device) { const GByteArray *mac; const char *device_mac_str; char *mac_str; if (NM_IS_SETTING_WIRED (priv->s_hw)) mac = nm_setting_wired_get_mac_address (NM_SETTING_WIRED (priv->s_hw)); else mac = NULL; if (mac) { mac_str = nm_utils_hwaddr_ntoa (mac->data, ARPHRD_ETHER); for (d_iter = devices; d_iter; d_iter = d_iter->next) { device = d_iter->data; if (NM_IS_DEVICE_ETHERNET (device)) device_mac_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); else device_mac_str = NULL; if (!g_strcmp0 (mac_str, device_mac_str)) { parent_device = device; break; } } } } current_parent = parent; if (parent_device || parent_connection) { for (i = 0; priv->parents[i]; i++) { if (parent_device && parent_device != priv->parents[i]->device) continue; if (parent_connection != priv->parents[i]->connection) continue; current_parent = priv->parents[i]->label; break; } } ce_page_setup_mac_combo (CE_PAGE (self), priv->parent, current_parent, priv->parent_labels); g_signal_connect (priv->parent, "changed", G_CALLBACK (parent_changed), self); if (current_parent) priv->last_parent = g_strndup (current_parent, strcspn (current_parent, " ")); /* Name */ iface = nm_setting_vlan_get_interface_name (priv->setting); if (iface) gtk_entry_set_text (priv->name_entry, iface); g_signal_connect (priv->name_entry, "changed", G_CALLBACK (name_changed), self); /* ID */ priv->last_id = nm_setting_vlan_get_id (priv->setting); gtk_spin_button_set_value (priv->id_entry, priv->last_id); g_signal_connect (priv->id_entry, "value-changed", G_CALLBACK (id_changed), self); /* Cloned MAC address */ if (NM_IS_SETTING_WIRED (priv->s_hw)) { ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (NM_SETTING_WIRED (priv->s_hw)), ARPHRD_ETHER, priv->cloned_mac); } g_signal_connect (priv->cloned_mac, "changed", G_CALLBACK (stuff_changed), self); /* MTU */ if (NM_IS_SETTING_WIRED (priv->s_hw)) { mtu_def = ce_get_property_default (priv->s_hw, NM_SETTING_WIRED_MTU); mtu_val = nm_setting_wired_get_mtu (NM_SETTING_WIRED (priv->s_hw)); } else { mtu_def = mtu_val = 1500; } g_signal_connect (priv->mtu, "output", G_CALLBACK (ce_spin_output_with_default), GINT_TO_POINTER (mtu_def)); gtk_spin_button_set_value (priv->mtu, (gdouble) mtu_val); g_signal_connect (priv->mtu, "value-changed", G_CALLBACK (stuff_changed), self); g_slist_free (devices); }
static const char * get_virtual_iface_name (NMSetting *setting) { return nm_setting_vlan_get_interface_name (NM_SETTING_VLAN (setting)); }