Commit 46eee484 authored by Dan Williams's avatar Dan Williams

core: fix matching VLAN connections to interfaces

The check for virtual interface name was too loose, so
restrict it to VLAN only which is what actually uses it,
and ensure we have an interface name to compare against
the device.

Found by Weiping Pan <wpan@redhat.com>
parent 0c61a516
......@@ -594,24 +594,21 @@ static gboolean
match_ethernet_connection (NMDevice *device, NMConnection *connection,
gboolean check_blacklist, GError **error)
{
const char *iface;
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
NMSettingWired *s_wired;
s_wired = nm_connection_get_setting_wired (connection);
iface = nm_connection_get_virtual_iface_name (connection);
if (iface && strcmp (nm_device_get_iface (device), iface))
return FALSE;
if (nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME)) {
/* NOP */
} else if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
NMSettingConnection *s_con = nm_connection_get_setting_connection (connection);
NMSettingVlan *s_vlan = nm_connection_get_setting_vlan (connection);
const char *master;
int con_master_ifindex;
const char *master, *iface = NULL;
char *tmp_iface = NULL;
int con_master_ifindex = -1;
gboolean iface_matches;
g_assert (s_vlan);
g_assert (s_con);
......@@ -643,6 +640,7 @@ match_ethernet_connection (NMDevice *device, NMConnection *connection,
* all active NMDevices to see if they are using the given
* connection UUID.
*/
g_warn_if_reached ();
} else {
/* It's an interface name; match it against our master */
con_master_ifindex = nm_netlink_iface_to_index (master);
......@@ -652,6 +650,26 @@ match_ethernet_connection (NMDevice *device, NMConnection *connection,
return FALSE;
}
}
/* Ensure the interface name matches, if it's given */
iface = nm_connection_get_virtual_iface_name (connection);
if (!iface) {
/* If the connection doesn't specify an interface name for the
* VLAN interface, we construct it from the master interface name
* and the VLAN ID.
*/
if (con_master_ifindex >= 0)
iface = tmp_iface = nm_utils_new_vlan_name (master, nm_setting_vlan_get_id (s_vlan));
}
iface_matches = (g_strcmp0 (nm_device_get_ip_iface (device), iface) == 0);
g_free (tmp_iface);
if (!iface_matches) {
g_set_error (error, NM_ETHERNET_ERROR, NM_ETHERNET_ERROR_CONNECTION_INVALID,
"The VLAN connection virtual interface name did not match.");
return FALSE;
}
} else if (nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME)) {
if (!s_wired) {
g_set_error (error,
......
......@@ -894,6 +894,8 @@ handle_slave_activation (NMDevice *slave, NMDevice *master)
return FALSE;
nm_device_hw_bring_up (slave, TRUE, NULL);
} else if (nm_setting_connection_is_slave_type (s_con, NM_SETTING_VLAN_SETTING_NAME)) {
/* NOP */
} else {
nm_log_warn (LOGD_DEVICE, "(%s): Unable to enslave. Unknown slave type '%s'",
nm_device_get_iface (slave), nm_setting_connection_get_slave_type (s_con));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment