mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-30 20:10:10 +01:00
core: merge branch 'bg/parent-uuid'
https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00032.html
This commit is contained in:
commit
c9edd222c5
7 changed files with 77 additions and 208 deletions
|
|
@ -441,40 +441,6 @@ update_connection (NMDevice *device, NMConnection *connection)
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
match_parent (NMDevice *dev_parent, const char *setting_parent)
|
||||
{
|
||||
g_return_val_if_fail (setting_parent, FALSE);
|
||||
|
||||
if (!dev_parent)
|
||||
return FALSE;
|
||||
|
||||
if (nm_utils_is_uuid (setting_parent)) {
|
||||
NMActRequest *parent_req;
|
||||
NMConnection *parent_connection;
|
||||
|
||||
/* If the parent is a UUID, the connection matches if our parent
|
||||
* device has that connection activated.
|
||||
*/
|
||||
parent_req = nm_device_get_act_request (dev_parent);
|
||||
if (!parent_req)
|
||||
return FALSE;
|
||||
|
||||
parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req));
|
||||
if (!parent_connection)
|
||||
return FALSE;
|
||||
|
||||
if (g_strcmp0 (setting_parent, nm_connection_get_uuid (parent_connection)) != 0)
|
||||
return FALSE;
|
||||
} else {
|
||||
/* interface name */
|
||||
if (g_strcmp0 (setting_parent, nm_device_get_ip_iface (dev_parent)) != 0)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||
{
|
||||
|
|
@ -496,10 +462,8 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
|||
if (nm_device_is_real (device)) {
|
||||
/* Check parent interface; could be an interface name or a UUID */
|
||||
parent = nm_setting_ip_tunnel_get_parent (s_ip_tunnel);
|
||||
if (parent) {
|
||||
if (!match_parent (nm_device_parent_get_device (device), parent))
|
||||
return FALSE;
|
||||
}
|
||||
if (parent && !nm_device_match_parent (device, parent))
|
||||
return FALSE;
|
||||
|
||||
if (!address_equal_pp (priv->addr_family,
|
||||
nm_setting_ip_tunnel_get_local (s_ip_tunnel),
|
||||
|
|
|
|||
|
|
@ -286,69 +286,6 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
static gboolean
|
||||
match_parent (NMDeviceMacvlan *self, const char *parent)
|
||||
{
|
||||
NMDevice *parent_device;
|
||||
|
||||
g_return_val_if_fail (parent != NULL, FALSE);
|
||||
|
||||
parent_device = nm_device_parent_get_device (NM_DEVICE (self));
|
||||
if (!parent_device)
|
||||
return FALSE;
|
||||
|
||||
if (nm_utils_is_uuid (parent)) {
|
||||
NMActRequest *parent_req;
|
||||
NMConnection *parent_connection;
|
||||
|
||||
/* If the parent is a UUID, the connection matches if our parent
|
||||
* device has that connection activated.
|
||||
*/
|
||||
|
||||
parent_req = nm_device_get_act_request (parent_device);
|
||||
if (!parent_req)
|
||||
return FALSE;
|
||||
|
||||
parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req));
|
||||
if (!parent_connection)
|
||||
return FALSE;
|
||||
|
||||
if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0)
|
||||
return FALSE;
|
||||
} else {
|
||||
/* interface name */
|
||||
if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
|
||||
{
|
||||
NMSettingWired *s_wired;
|
||||
NMDevice *parent_device;
|
||||
const char *setting_mac;
|
||||
const char *parent_mac;
|
||||
|
||||
s_wired = nm_connection_get_setting_wired (connection);
|
||||
if (!s_wired)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
if (!setting_mac)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
parent_device = nm_device_parent_get_device (device);
|
||||
if (!parent_device)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
parent_mac = nm_device_get_permanent_hw_address (parent_device);
|
||||
return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||
{
|
||||
|
|
@ -378,11 +315,11 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
|||
/* Check parent interface; could be an interface name or a UUID */
|
||||
parent = nm_setting_macvlan_get_parent (s_macvlan);
|
||||
if (parent) {
|
||||
if (!match_parent (NM_DEVICE_MACVLAN (device), parent))
|
||||
if (!nm_device_match_parent (device, parent))
|
||||
return FALSE;
|
||||
} else {
|
||||
/* Parent could be a MAC address in an NMSettingWired */
|
||||
if (!match_hwaddr (device, connection, TRUE))
|
||||
if (!nm_device_match_hwaddr (device, connection, TRUE))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
@ -419,7 +356,7 @@ complete_connection (NMDevice *device,
|
|||
* settings, then there's not enough information to complete the setting.
|
||||
*/
|
||||
if ( !nm_setting_macvlan_get_parent (s_macvlan)
|
||||
&& !match_hwaddr (device, connection, TRUE)) {
|
||||
&& !nm_device_match_hwaddr (device, connection, TRUE)) {
|
||||
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
|
||||
"The 'macvlan' setting had no interface name, parent, or hardware address.");
|
||||
return FALSE;
|
||||
|
|
|
|||
|
|
@ -132,4 +132,9 @@ gboolean _nm_device_hash_check_invalid_keys (GHashTable *hash, const char *setti
|
|||
#define nm_device_hash_check_invalid_keys(hash, setting_name, error, ...) \
|
||||
_nm_device_hash_check_invalid_keys (hash, setting_name, error, ((const char *[]) { __VA_ARGS__, NULL }))
|
||||
|
||||
gboolean nm_device_match_parent (NMDevice *device, const char *parent);
|
||||
gboolean nm_device_match_hwaddr (NMDevice *device,
|
||||
NMConnection *connection,
|
||||
gboolean fail_if_no_hwaddr);
|
||||
|
||||
#endif /* NM_DEVICE_PRIVATE_H */
|
||||
|
|
|
|||
|
|
@ -314,68 +314,6 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
match_parent (NMDeviceVlan *self, const char *parent)
|
||||
{
|
||||
NMDevice *parent_device;
|
||||
|
||||
g_return_val_if_fail (parent != NULL, FALSE);
|
||||
|
||||
parent_device = nm_device_parent_get_device (NM_DEVICE (self));
|
||||
if (!parent_device)
|
||||
return FALSE;
|
||||
|
||||
if (nm_utils_is_uuid (parent)) {
|
||||
NMActRequest *parent_req;
|
||||
NMConnection *parent_connection;
|
||||
|
||||
/* If the parent is a UUID, the connection matches if our parent
|
||||
* device has that connection activated.
|
||||
*/
|
||||
|
||||
parent_req = nm_device_get_act_request (parent_device);
|
||||
if (!parent_req)
|
||||
return FALSE;
|
||||
|
||||
parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req));
|
||||
if (!parent_connection)
|
||||
return FALSE;
|
||||
|
||||
if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0)
|
||||
return FALSE;
|
||||
} else {
|
||||
/* interface name */
|
||||
if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
|
||||
{
|
||||
NMSettingWired *s_wired;
|
||||
NMDevice *parent_device;
|
||||
const char *setting_mac;
|
||||
const char *parent_mac;
|
||||
|
||||
s_wired = nm_connection_get_setting_wired (connection);
|
||||
if (!s_wired)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
if (!setting_mac)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
parent_device = nm_device_parent_get_device (device);
|
||||
if (!parent_device)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
parent_mac = nm_device_get_permanent_hw_address (parent_device);
|
||||
return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
||||
{
|
||||
|
|
@ -398,11 +336,11 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
|||
/* Check parent interface; could be an interface name or a UUID */
|
||||
parent = nm_setting_vlan_get_parent (s_vlan);
|
||||
if (parent) {
|
||||
if (!match_parent (NM_DEVICE_VLAN (device), parent))
|
||||
if (!nm_device_match_parent (device, parent))
|
||||
return FALSE;
|
||||
} else {
|
||||
/* Parent could be a MAC address in an NMSettingWired */
|
||||
if (!match_hwaddr (device, connection, TRUE))
|
||||
if (!nm_device_match_hwaddr (device, connection, TRUE))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
@ -451,7 +389,7 @@ complete_connection (NMDevice *device,
|
|||
* settings, then there's not enough information to complete the setting.
|
||||
*/
|
||||
if ( !nm_setting_vlan_get_parent (s_vlan)
|
||||
&& !match_hwaddr (device, connection, TRUE)) {
|
||||
&& !nm_device_match_hwaddr (device, connection, TRUE)) {
|
||||
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
|
||||
"The 'vlan' setting had no interface name, parent, or hardware address.");
|
||||
return FALSE;
|
||||
|
|
|
|||
|
|
@ -230,43 +230,6 @@ create_and_realize (NMDevice *device,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
match_parent (NMDeviceVxlan *self, const char *parent)
|
||||
{
|
||||
NMDevice *parent_device;
|
||||
|
||||
g_return_val_if_fail (parent != NULL, FALSE);
|
||||
|
||||
parent_device = nm_device_parent_get_device (NM_DEVICE (self));
|
||||
if (!parent_device)
|
||||
return FALSE;
|
||||
|
||||
if (nm_utils_is_uuid (parent)) {
|
||||
NMActRequest *parent_req;
|
||||
NMConnection *parent_connection;
|
||||
|
||||
/* If the parent is a UUID, the connection matches if our parent
|
||||
* device has that connection activated.
|
||||
*/
|
||||
parent_req = nm_device_get_act_request (parent_device);
|
||||
if (!parent_req)
|
||||
return FALSE;
|
||||
|
||||
parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req));
|
||||
if (!parent_connection)
|
||||
return FALSE;
|
||||
|
||||
if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0)
|
||||
return FALSE;
|
||||
} else {
|
||||
/* interface name */
|
||||
if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
address_matches (const char *str, in_addr_t addr4, struct in6_addr *addr6)
|
||||
{
|
||||
|
|
@ -302,8 +265,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
|
|||
|
||||
if (nm_device_is_real (device)) {
|
||||
parent = nm_setting_vxlan_get_parent (s_vxlan);
|
||||
if ( parent
|
||||
&& !match_parent (NM_DEVICE_VXLAN (device), parent))
|
||||
if (parent && !nm_device_match_parent (device, parent))
|
||||
return FALSE;
|
||||
|
||||
if (priv->props.id != nm_setting_vxlan_get_id (s_vxlan))
|
||||
|
|
|
|||
|
|
@ -4390,6 +4390,65 @@ nm_device_complete_connection (NMDevice *self,
|
|||
return success;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_device_match_parent (NMDevice *self, const char *parent)
|
||||
{
|
||||
NMDevice *parent_device;
|
||||
|
||||
g_return_val_if_fail (parent, FALSE);
|
||||
|
||||
parent_device = nm_device_parent_get_device (self);
|
||||
if (!parent_device)
|
||||
return FALSE;
|
||||
|
||||
if (nm_utils_is_uuid (parent)) {
|
||||
NMConnection *connection;
|
||||
|
||||
/* If the parent is a UUID, the connection matches when there is
|
||||
* no connection active on the device or when a connection with
|
||||
* that UUID is active.
|
||||
*/
|
||||
connection = nm_device_get_applied_connection (self);
|
||||
if (!connection)
|
||||
return TRUE;
|
||||
|
||||
if (!nm_streq0 (parent, nm_connection_get_uuid (connection)))
|
||||
return FALSE;
|
||||
} else {
|
||||
/* Interface name */
|
||||
if (!nm_streq0 (parent, nm_device_get_ip_iface (parent_device)))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_device_match_hwaddr (NMDevice *device,
|
||||
NMConnection *connection,
|
||||
gboolean fail_if_no_hwaddr)
|
||||
{
|
||||
NMSettingWired *s_wired;
|
||||
NMDevice *parent_device;
|
||||
const char *setting_mac;
|
||||
const char *parent_mac;
|
||||
|
||||
s_wired = nm_connection_get_setting_wired (connection);
|
||||
if (!s_wired)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
if (!setting_mac)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
parent_device = nm_device_parent_get_device (device);
|
||||
if (!parent_device)
|
||||
return !fail_if_no_hwaddr;
|
||||
|
||||
parent_mac = nm_device_get_permanent_hw_address (parent_device);
|
||||
return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMDevice *self, NMConnection *connection)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1155,6 +1155,10 @@ find_parent_device_for_connection (NMManager *self, NMConnection *connection, NM
|
|||
for (iter = priv->devices; iter; iter = iter->next) {
|
||||
NMDevice *candidate = iter->data;
|
||||
|
||||
/* Unmanaged devices are not compatible with any connection */
|
||||
if (!nm_device_get_managed (candidate, FALSE))
|
||||
continue;
|
||||
|
||||
if (nm_device_get_settings_connection (candidate) == parent_connection)
|
||||
return candidate;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue