static gboolean nmt_slave_list_connection_filter (NmtEditConnectionList *list, NMConnection *connection, gpointer user_data) { NmtSlaveListPrivate *priv = NMT_SLAVE_LIST_GET_PRIVATE (list); NMSettingConnection *s_con; const char *master, *master_ifname, *slave_type; s_con = nm_connection_get_setting_connection (connection); g_return_val_if_fail (s_con != NULL, FALSE); slave_type = nm_setting_connection_get_slave_type (s_con); if (g_strcmp0 (slave_type, priv->master_type) != 0) return FALSE; master = nm_setting_connection_get_master (s_con); if (!master) return FALSE; master_ifname = nm_connection_get_virtual_iface_name (priv->master); if (g_strcmp0 (master, master_ifname) != 0 && g_strcmp0 (master, priv->master_uuid) != 0) return FALSE; return TRUE; }
/* Returns an editor for @slave's master, if any */ NMConnectionEditor * nm_connection_editor_get_master (NMConnection *slave) { GHashTableIter iter; gpointer connection, editor; NMSettingConnection *s_con; const char *master; if (!active_editors) return NULL; s_con = nm_connection_get_setting_connection (slave); master = nm_setting_connection_get_master (s_con); if (!master) return NULL; g_hash_table_iter_init (&iter, active_editors); while (g_hash_table_iter_next (&iter, &connection, &editor)) { if (!g_strcmp0 (master, nm_connection_get_uuid (connection))) return editor; if (!g_strcmp0 (master, nm_connection_get_interface_name (connection))) return editor; } return NULL; }
static GSList * valid_connections_for_device (NMRemoteSettings *remote_settings, NMDevice *device) { GSList *all, *filtered, *iterator, *valid; NMConnection *connection; NMSettingConnection *s_con; all = nm_remote_settings_list_connections (remote_settings); filtered = nm_device_filter_connections (device, all); g_slist_free (all); valid = NULL; for (iterator = filtered; iterator; iterator = iterator->next) { connection = iterator->data; s_con = nm_connection_get_setting_connection (connection); if (!s_con) continue; if (nm_setting_connection_get_master (s_con)) continue; valid = g_slist_prepend (valid, connection); } g_slist_free (filtered); return g_slist_reverse (valid); }
static void delete_slaves_of_connection (NMConnectionList *list, NMConnection *connection) { const char *uuid, *iface; GtkTreeIter iter, types_iter; if (!gtk_tree_model_get_iter_first (list->model, &types_iter)) return; uuid = nm_connection_get_uuid (connection); iface = nm_connection_get_virtual_iface_name (connection); do { if (!gtk_tree_model_iter_children (list->model, &iter, &types_iter)) continue; do { NMRemoteConnection *candidate = NULL; NMSettingConnection *s_con; const char *master; gtk_tree_model_get (list->model, &iter, COL_CONNECTION, &candidate, -1); s_con = nm_connection_get_setting_connection (NM_CONNECTION (candidate)); master = nm_setting_connection_get_master (s_con); if (master) { if (!g_strcmp0 (master, uuid) || !g_strcmp0 (master, iface)) nm_remote_connection_delete (candidate, NULL, NULL); } g_object_unref (candidate); } while (gtk_tree_model_iter_next (list->model, &iter)); } while (gtk_tree_model_iter_next (list->model, &types_iter)); }
const char * nm_utils_get_ip_config_method (NMConnection *connection, GType ip_setting_type) { NMSettingConnection *s_con; NMSettingIPConfig *s_ip4, *s_ip6; const char *method; s_con = nm_connection_get_setting_connection (connection); if (ip_setting_type == NM_TYPE_SETTING_IP4_CONFIG) { g_return_val_if_fail (s_con != NULL, NM_SETTING_IP4_CONFIG_METHOD_AUTO); if (nm_setting_connection_get_master (s_con)) return NM_SETTING_IP4_CONFIG_METHOD_DISABLED; else { s_ip4 = nm_connection_get_setting_ip4_config (connection); if (!s_ip4) return NM_SETTING_IP4_CONFIG_METHOD_DISABLED; method = nm_setting_ip_config_get_method (s_ip4); g_return_val_if_fail (method != NULL, NM_SETTING_IP4_CONFIG_METHOD_AUTO); return method; } } else if (ip_setting_type == NM_TYPE_SETTING_IP6_CONFIG) { g_return_val_if_fail (s_con != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO); if (nm_setting_connection_get_master (s_con)) return NM_SETTING_IP6_CONFIG_METHOD_IGNORE; else { s_ip6 = nm_connection_get_setting_ip6_config (connection); if (!s_ip6) return NM_SETTING_IP6_CONFIG_METHOD_IGNORE; method = nm_setting_ip_config_get_method (s_ip6); g_return_val_if_fail (method != NULL, NM_SETTING_IP6_CONFIG_METHOD_AUTO); return method; } } else g_assert_not_reached (); }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMSettingConnection *setting = NM_SETTING_CONNECTION (object); NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting); switch (prop_id) { case PROP_ID: g_value_set_string (value, nm_setting_connection_get_id (setting)); break; case PROP_UUID: g_value_set_string (value, nm_setting_connection_get_uuid (setting)); break; case PROP_TYPE: g_value_set_string (value, nm_setting_connection_get_connection_type (setting)); break; case PROP_PERMISSIONS: g_value_take_boxed (value, perm_permlist_to_stringlist (priv->permissions)); break; case PROP_AUTOCONNECT: g_value_set_boolean (value, nm_setting_connection_get_autoconnect (setting)); break; case PROP_TIMESTAMP: g_value_set_uint64 (value, nm_setting_connection_get_timestamp (setting)); break; case PROP_READ_ONLY: g_value_set_boolean (value, nm_setting_connection_get_read_only (setting)); break; case PROP_ZONE: g_value_set_string (value, nm_setting_connection_get_zone (setting)); break; case PROP_MASTER: g_value_set_string (value, nm_setting_connection_get_master (setting)); break; case PROP_SLAVE_TYPE: g_value_set_string (value, nm_setting_connection_get_slave_type (setting)); break; case PROP_SECONDARIES: g_value_set_boxed (value, priv->secondaries); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
void nmt_remove_connection (NMRemoteConnection *connection) { const GPtrArray *all_conns; GSList *slaves, *iter; int i; NMRemoteConnection *slave; NMSettingConnection *s_con; const char *uuid, *iface, *master; int choice; choice = nmt_newt_choice_dialog (_("Cancel"), _("Delete"), _("Are you sure you want to delete the connection '%s'?"), nm_connection_get_id (NM_CONNECTION (connection))); if (choice == 1) return; g_object_ref (connection); remove_one_connection (connection); uuid = nm_connection_get_uuid (NM_CONNECTION (connection)); iface = nm_connection_get_interface_name (NM_CONNECTION (connection)); all_conns = nm_client_get_connections (nm_client); slaves = NULL; for (i = 0; i < all_conns->len; i++) { slave = all_conns->pdata[i]; s_con = nm_connection_get_setting_connection (NM_CONNECTION (slave)); master = nm_setting_connection_get_master (s_con); if (master) { if (!g_strcmp0 (master, uuid) || !g_strcmp0 (master, iface)) slaves = g_slist_prepend (slaves, g_object_ref (slave)); } } for (iter = slaves; iter; iter = iter->next) remove_one_connection (iter->data); g_slist_free_full (slaves, g_object_unref); g_object_unref (connection); }
static gboolean tree_model_visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { NMConnectionList *self = user_data; NMConnection *connection; NMSettingConnection *s_con; const char *master; const char *slave_type; gtk_tree_model_get (model, iter, COL_CONNECTION, &connection, -1); if (!connection) { /* Top-level type nodes are visible iff they have children */ return gtk_tree_model_iter_has_child (model, iter); } /* A connection node is visible unless it is a slave to a known * bond or bridge. */ s_con = nm_connection_get_setting_connection (connection); g_object_unref (connection); g_return_val_if_fail (s_con != NULL, FALSE); master = nm_setting_connection_get_master (s_con); if (!master) return TRUE; slave_type = nm_setting_connection_get_slave_type (s_con); if ( g_strcmp0 (slave_type, NM_SETTING_BOND_SETTING_NAME) != 0 && g_strcmp0 (slave_type, NM_SETTING_BRIDGE_SETTING_NAME) != 0) return TRUE; if (nm_remote_settings_get_connection_by_uuid (self->settings, master)) return FALSE; if (nm_connection_editor_get_master (connection)) return FALSE; /* FIXME: what if master is an interface name */ return TRUE; }
static gboolean edit_connection_list_filter (NmtEditConnectionList *list, NMConnection *connection, gpointer user_data) { NMSettingConnection *s_con; const char *master, *slave_type; const char *uuid, *ifname; const GPtrArray *conns; int i; gboolean found_master = FALSE; s_con = nm_connection_get_setting_connection (connection); g_return_val_if_fail (s_con != NULL, FALSE); master = nm_setting_connection_get_master (s_con); if (!master) return TRUE; slave_type = nm_setting_connection_get_slave_type (s_con); if ( g_strcmp0 (slave_type, NM_SETTING_BOND_SETTING_NAME) != 0 && g_strcmp0 (slave_type, NM_SETTING_TEAM_SETTING_NAME) != 0 && g_strcmp0 (slave_type, NM_SETTING_BRIDGE_SETTING_NAME) != 0) return TRUE; conns = nm_client_get_connections (nm_client); for (i = 0; i < conns->len; i++) { NMConnection *candidate = conns->pdata[i]; uuid = nm_connection_get_uuid (candidate); ifname = nm_connection_get_interface_name (candidate); if (!g_strcmp0 (master, uuid) || !g_strcmp0 (master, ifname)) { found_master = TRUE; break; } } return !found_master; }
static void add_connections_for_device (NmtConnectDevice *nmtdev, const GPtrArray *connections) { int i; for (i = 0; i < connections->len; i++) { NMConnection *conn = connections->pdata[i]; NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (conn); if (nm_setting_connection_get_master (s_con)) continue; if (nm_device_connection_valid (nmtdev->device, conn)) { NmtConnectConnection *nmtconn = g_slice_new0 (NmtConnectConnection); nmtconn->name = nm_connection_get_id (conn); nmtconn->device = nmtdev->device; nmtconn->conn = g_object_ref (conn); nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn); } } }
static void add_connections_for_device (NmtConnectDevice *nmtdev, GSList *connections) { GSList *iter; for (iter = connections; iter; iter = iter->next) { NMConnection *conn = iter->data; NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (conn); if (nm_setting_connection_get_master (s_con)) continue; if (nm_device_connection_valid (nmtdev->device, conn)) { NmtConnectConnection *nmtconn = g_slice_new0 (NmtConnectConnection); nmtconn->name = nm_connection_get_id (conn); nmtconn->device = nmtdev->device; nmtconn->conn = g_object_ref (conn); nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn); } } }
static void build_vlan_parent_list (CEPageVlan *self, GSList *devices) { CEPageVlanPrivate *priv = CE_PAGE_VLAN_GET_PRIVATE (self); GSList *connections, *c_iter, *d_iter; GPtrArray *parents; VlanParent *parent; NMDevice *device; const char *iface, *mac, *id; int i; parents = g_ptr_array_new (); /* Devices with no L2 configuration can spawn VLANs directly. At the * moment, this means just Ethernet. */ for (d_iter = devices; d_iter; d_iter = d_iter->next) { device = d_iter->data; if (!NM_IS_DEVICE_ETHERNET (device)) continue; parent = g_slice_new (VlanParent); parent->device = device; parent->connection = NULL; iface = nm_device_get_iface (device); mac = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); parent->label = g_strdup_printf ("%s (%s)", iface, mac); g_ptr_array_add (parents, parent); } /* Otherwise, VLANs have to be built on top of configured connections */ connections = nm_remote_settings_list_connections (CE_PAGE (self)->settings); for (c_iter = connections; c_iter; c_iter = c_iter->next) { NMConnection *candidate = c_iter->data; NMSettingConnection *s_con = nm_connection_get_setting_connection (candidate); if (nm_setting_connection_get_master (s_con)) continue; for (d_iter = devices; d_iter; d_iter = d_iter->next) { device = d_iter->data; if (nm_device_connection_valid (device, candidate)) { parent = g_slice_new (VlanParent); parent->device = device; parent->connection = candidate; iface = nm_device_get_iface (device); id = nm_setting_connection_get_id (s_con); parent->label = g_strdup_printf ("%s (%s)", iface, id); g_ptr_array_add (parents, parent); /* no break here; the connection may apply to multiple devices */ } } } g_slist_free (connections); g_ptr_array_sort (parents, sort_parents); g_ptr_array_add (parents, NULL); priv->parent_labels = g_new (char *, parents->len); priv->parents = (VlanParent **)g_ptr_array_free (parents, FALSE); for (i = 0; priv->parents[i]; i++) priv->parent_labels[i] = priv->parents[i]->label; priv->parent_labels[i] = NULL; }
static gboolean verify (NMSetting *setting, GSList *all_settings, GError **error) { NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting); NMSettingConnection *s_con = NULL; NMSettingWired *s_wired = NULL; GSList *iter; for (iter = all_settings; iter; iter = iter->next) { if (NM_IS_SETTING_CONNECTION (iter->data)) s_con = iter->data; else if (NM_IS_SETTING_WIRED (iter->data)) s_wired = iter->data; } /* If iface_name is specified, it must be a valid interface name. We * don't check that it matches parent and/or id, because we allowing * renaming vlans to arbitrary names. */ if (priv->iface_name && !nm_utils_iface_valid_name (priv->iface_name)) { g_set_error (error, NM_SETTING_VLAN_ERROR, NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, NM_SETTING_VLAN_INTERFACE_NAME); return FALSE; } if (priv->parent) { if (nm_utils_is_uuid (priv->parent)) { /* If we have an NMSettingConnection:master with slave-type="vlan", * then it must be the same UUID. */ if (s_con) { const char *master = NULL, *slave_type = NULL; slave_type = nm_setting_connection_get_slave_type (s_con); if (!g_strcmp0 (slave_type, NM_SETTING_VLAN_SETTING_NAME)) master = nm_setting_connection_get_master (s_con); if (master && g_strcmp0 (priv->parent, master) != 0) { g_set_error (error, NM_SETTING_VLAN_ERROR, NM_SETTING_VLAN_ERROR_INVALID_PARENT, NM_SETTING_CONNECTION_MASTER); return FALSE; } } } else if (!nm_utils_iface_valid_name (priv->parent)) { /* parent must be either a UUID or an interface name */ g_set_error (error, NM_SETTING_VLAN_ERROR, NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, NM_SETTING_VLAN_PARENT); return FALSE; } } else { /* If parent is NULL, the parent must be specified via * NMSettingWired:mac-address. */ if (!s_wired || !nm_setting_wired_get_mac_address (s_wired)) { g_set_error (error, NM_SETTING_VLAN_ERROR, NM_SETTING_VLAN_ERROR_MISSING_PROPERTY, NM_SETTING_VLAN_PARENT); return FALSE; } } if (priv->flags & ~(NM_VLAN_FLAG_REORDER_HEADERS | NM_VLAN_FLAG_GVRP | NM_VLAN_FLAG_LOOSE_BINDING)) { g_set_error (error, NM_SETTING_VLAN_ERROR, NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, NM_SETTING_VLAN_FLAGS); return FALSE; } return TRUE; }
static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting); NMSettingConnection *s_con; NMSettingWired *s_wired; if (connection) { s_con = nm_connection_get_setting_connection (connection); s_wired = nm_connection_get_setting_wired (connection); } else { s_con = NULL; s_wired = NULL; } if (priv->parent) { if (nm_utils_is_uuid (priv->parent)) { /* If we have an NMSettingConnection:master with slave-type="vlan", * then it must be the same UUID. */ if (s_con) { const char *master = NULL, *slave_type = NULL; slave_type = nm_setting_connection_get_slave_type (s_con); if (!g_strcmp0 (slave_type, NM_SETTING_VLAN_SETTING_NAME)) master = nm_setting_connection_get_master (s_con); if (master && g_strcmp0 (priv->parent, master) != 0) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("'%s' value doesn't match '%s=%s'"), priv->parent, NM_SETTING_CONNECTION_MASTER, master); g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT); return FALSE; } } } else if (!nm_utils_iface_valid_name (priv->parent)) { /* parent must be either a UUID or an interface name */ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("'%s' is neither an UUID nor an interface name"), priv->parent); g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT); return FALSE; } } else { /* If parent is NULL, the parent must be specified via * NMSettingWired:mac-address. */ if ( connection && (!s_wired || !nm_setting_wired_get_mac_address (s_wired))) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, _("property is not specified and neither is '%s:%s'"), NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS); g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT); return FALSE; } } if (priv->id >= 4095) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("the vlan id must be in range 0-4094 but is %u"), priv->id); g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_ID); } if (priv->flags & ~NM_VLAN_FLAGS_ALL) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("flags are invalid")); g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_FLAGS); return FALSE; } return TRUE; }