core: use VLAN parent instead of master for creating the virtual interface

The 'parent' property of NMSettingVlan is now what describes the
interface from which the VLAN gets created, not master.
This commit is contained in:
Dan Williams 2012-02-21 13:46:04 -06:00
parent 10b32be37b
commit 51edc6ae97

View file

@ -917,7 +917,7 @@ get_active_connections (NMManager *manager, NMConnection *filter)
static const char *
get_iface_from_hwaddr (NMManager *self,
NMConnection *connection,
int *out_master_ifindex)
int *out_ifindex)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
GSList *iter;
@ -926,8 +926,8 @@ get_iface_from_hwaddr (NMManager *self,
NMDevice *candidate = iter->data;
if (nm_device_hwaddr_matches (candidate, connection, TRUE)) {
if (out_master_ifindex)
*out_master_ifindex = nm_device_get_ip_ifindex (candidate);
if (out_ifindex)
*out_ifindex = nm_device_get_ip_ifindex (candidate);
return nm_device_get_ip_iface (candidate);
}
}
@ -935,60 +935,60 @@ get_iface_from_hwaddr (NMManager *self,
}
static const char *
find_master_iface (NMManager *self,
NMConnection *connection,
gboolean check_hwaddr,
int *out_master_ifindex)
find_vlan_parent_iface (NMManager *self,
NMConnection *connection,
gboolean check_hwaddr,
int *out_parent_ifindex)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
NMSettingConnection *s_con;
const char *master;
NMConnection *master_connection;
NMSettingVlan *s_vlan;
const char *parent;
NMConnection *parent_connection;
GSList *iter;
NMDevice *device;
/* The 'master' property could be either an interface name, a connection
/* The 'parent' property could be either an interface name, a connection
* UUID, or even given by the MAC address of the connection's ethernet,
* Infiniband, or WiFi setting.
*/
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
master = nm_setting_connection_get_master (s_con);
if (!master)
return NULL;
s_vlan = nm_connection_get_setting_vlan (connection);
g_return_val_if_fail (s_vlan != NULL, NULL);
device = find_device_by_ip_iface (self, master);
if (device) {
if (out_master_ifindex)
*out_master_ifindex = nm_device_get_ip_ifindex (device);
return master;
}
if (nm_utils_is_uuid (master)) {
/* Try as a connection UUID */
master_connection = (NMConnection *) nm_settings_get_connection_by_uuid (priv->settings, master);
if (master_connection) {
/* Check if the master connection is activated on some device already */
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
NMDevice *candidate = NM_DEVICE (iter->data);
if (nm_device_get_connection (candidate) == master_connection) {
if (out_master_ifindex)
*out_master_ifindex = nm_device_get_ip_ifindex (candidate);
return nm_device_get_iface (candidate);
}
}
/* Check the hardware address of the master connection */
if (check_hwaddr)
return get_iface_from_hwaddr (self, master_connection, out_master_ifindex);
parent = nm_setting_vlan_get_parent (s_vlan);
if (parent) {
device = find_device_by_ip_iface (self, parent);
if (device) {
if (out_parent_ifindex)
*out_parent_ifindex = nm_device_get_ip_ifindex (device);
return parent;
}
if (nm_utils_is_uuid (parent)) {
/* Try as a connection UUID */
parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (priv->settings, parent);
if (parent_connection) {
/* Check if the parent connection is activated on some device already */
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
NMDevice *candidate = NM_DEVICE (iter->data);
if (nm_device_get_connection (candidate) == parent_connection) {
if (out_parent_ifindex)
*out_parent_ifindex = nm_device_get_ip_ifindex (candidate);
return nm_device_get_iface (candidate);
}
}
/* Check the hardware address of the parent connection */
if (check_hwaddr)
return get_iface_from_hwaddr (self, parent_connection, out_parent_ifindex);
}
return NULL;
}
return NULL;
}
/* Try the hardware address from the VLAN connection's hardware setting */
if (check_hwaddr)
return get_iface_from_hwaddr (self, connection, out_master_ifindex);
return get_iface_from_hwaddr (self, connection, out_parent_ifindex);
return NULL;
}
@ -997,7 +997,7 @@ find_master_iface (NMManager *self,
* get_virtual_iface_name:
* @self: the #NMManager
* @connection: the #NMConnection representing a virtual interface
* @out_master_ifindex: on success, the master interface index if any
* @out_parent_ifindex: on success, the parent interface index if any
*
* Given @connection, returns the interface name that the connection
* would represent. If the interface name is not given by the connection,
@ -1009,34 +1009,34 @@ find_master_iface (NMManager *self,
static char *
get_virtual_iface_name (NMManager *self,
NMConnection *connection,
int *out_master_ifindex)
int *out_parent_ifindex)
{
char *vname = NULL;
if (out_master_ifindex)
*out_master_ifindex = -1;
if (out_parent_ifindex)
*out_parent_ifindex = -1;
if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME))
return g_strdup (nm_connection_get_virtual_iface_name (connection));
if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
NMSettingVlan *s_vlan;
const char *ifname, *master;
const char *ifname, *parent;
s_vlan = nm_connection_get_setting_vlan (connection);
g_return_val_if_fail (s_vlan != NULL, NULL);
master = find_master_iface (self, connection, TRUE, out_master_ifindex);
if (master) {
parent = find_vlan_parent_iface (self, connection, TRUE, out_parent_ifindex);
if (parent) {
/* If the connection doesn't specify the interface name for the VLAN
* device, we create one for it using the VLAN ID and the master
* device, we create one for it using the VLAN ID and the parent
* interface's name.
*/
ifname = nm_connection_get_virtual_iface_name (connection);
if (ifname)
vname = g_strdup (ifname);
else
vname = nm_utils_new_vlan_name (master, nm_setting_vlan_get_id (s_vlan));
vname = nm_utils_new_vlan_name (parent, nm_setting_vlan_get_id (s_vlan));
}
}
@ -1079,9 +1079,9 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
GSList *iter;
char *iface = NULL, *udi;
NMDevice *device = NULL;
int master_ifindex = -1;
int parent_ifindex = -1;
iface = get_virtual_iface_name (self, connection, &master_ifindex);
iface = get_virtual_iface_name (self, connection, &parent_ifindex);
if (!iface) {
nm_log_warn (LOGD_DEVICE, "(%s) failed to determine virtual interface name",
nm_connection_get_id (connection));
@ -1112,9 +1112,9 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
device = nm_device_bond_new (udi, iface);
g_free (udi);
} else if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
g_return_val_if_fail (master_ifindex >= 0, FALSE);
g_return_val_if_fail (parent_ifindex >= 0, FALSE);
if (!nm_system_add_vlan_iface (connection, iface, master_ifindex)) {
if (!nm_system_add_vlan_iface (connection, iface, parent_ifindex)) {
nm_log_warn (LOGD_DEVICE, "(%s): failed to add VLAN interface for '%s'",
iface, nm_connection_get_id (connection));
goto out;