static void update_connection (NMDevice *device, NMConnection *connection) { NMDeviceVlan *self = NM_DEVICE_VLAN (device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device); NMSettingVlan *s_vlan = nm_connection_get_setting_vlan (connection); int ifindex = nm_device_get_ifindex (device); int parent_ifindex = -1, vlan_id = -1; NMDevice *parent; const char *setting_parent, *new_parent; if (!s_vlan) { s_vlan = (NMSettingVlan *) nm_setting_vlan_new (); nm_connection_add_setting (connection, (NMSetting *) s_vlan); } if (!nm_platform_vlan_get_info (NM_PLATFORM_GET, ifindex, &parent_ifindex, &vlan_id)) { _LOGW (LOGD_VLAN, "failed to get VLAN interface info while updating connection."); return; } if (priv->vlan_id != vlan_id) { priv->vlan_id = vlan_id; g_object_notify (G_OBJECT (device), NM_DEVICE_VLAN_ID); } if (vlan_id != nm_setting_vlan_get_id (s_vlan)) g_object_set (s_vlan, NM_SETTING_VLAN_ID, priv->vlan_id, NULL); if (parent_ifindex != NM_PLATFORM_LINK_OTHER_NETNS) parent = nm_manager_get_device_by_ifindex (nm_manager_get (), parent_ifindex); else parent = NULL; nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent); /* Update parent in the connection; default to parent's interface name */ if (parent) { new_parent = nm_device_get_iface (parent); setting_parent = nm_setting_vlan_get_parent (s_vlan); if (setting_parent && nm_utils_is_uuid (setting_parent)) { NMConnection *parent_connection; /* Don't change a parent specified by UUID if it's still valid */ parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), setting_parent); if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection)) new_parent = NULL; } if (new_parent) g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, new_parent, NULL); } else g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, NULL, NULL); }
void vlan_connection_new (GtkWindow *parent, const char *detail, NMRemoteSettings *settings, PageNewConnectionResultFunc result_func, NMClient *client, gpointer user_data) { NMConnection *connection; connection = ce_page_new_connection (_("VLAN connection %d"), NM_SETTING_VLAN_SETTING_NAME, TRUE, settings, user_data); nm_connection_add_setting (connection, nm_setting_vlan_new ()); (*result_func) (connection, FALSE, NULL, user_data); }
CEPage * ce_page_vlan_new (NMConnection *connection, GtkWindow *parent_window, NMClient *client, NMRemoteSettings *settings, const char **out_secrets_setting_name, GError **error) { CEPageVlan *self; CEPageVlanPrivate *priv; self = CE_PAGE_VLAN (ce_page_new (CE_TYPE_PAGE_VLAN, connection, parent_window, client, settings, UIDIR "/ce-page-vlan.ui", "VlanPage", _("VLAN"))); if (!self) { g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load vlan user interface.")); return NULL; } vlan_private_init (self); priv = CE_PAGE_VLAN_GET_PRIVATE (self); priv->setting = nm_connection_get_setting_vlan (connection); if (!priv->setting) { priv->setting = NM_SETTING_VLAN (nm_setting_vlan_new ()); nm_connection_add_setting (connection, NM_SETTING (priv->setting)); } priv->s_hw = nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED); g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL); return CE_PAGE (self); }