summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2017-09-28 13:27:28 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2017-09-28 13:27:28 +0200
commitc9edd222c56cc2ecf55bba64012798c99252f64a (patch)
tree6f038b2692acf19b4bf14cc13a6515e200280925
parent8a5ebd3cb7bdfd524c84b30c51c9829cb5902dde (diff)
parent6a5363bc8b54d8ee71b7a25acec3a0baa2298879 (diff)
downloadNetworkManager-c9edd222c56cc2ecf55bba64012798c99252f64a.tar.gz
core: merge branch 'bg/parent-uuid'
https://mail.gnome.org/archives/networkmanager-list/2017-September/msg00032.html
-rw-r--r--src/devices/nm-device-ip-tunnel.c40
-rw-r--r--src/devices/nm-device-macvlan.c69
-rw-r--r--src/devices/nm-device-private.h5
-rw-r--r--src/devices/nm-device-vlan.c68
-rw-r--r--src/devices/nm-device-vxlan.c40
-rw-r--r--src/devices/nm-device.c59
-rw-r--r--src/nm-manager.c4
7 files changed, 77 insertions, 208 deletions
diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c
index 317a5d4e74..af3cfe4c98 100644
--- a/src/devices/nm-device-ip-tunnel.c
+++ b/src/devices/nm-device-ip-tunnel.c
@@ -442,40 +442,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)
{
NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL (device);
@@ -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),
diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c
index 8803beb524..2a461543b0 100644
--- a/src/devices/nm-device-macvlan.c
+++ b/src/devices/nm-device-macvlan.c
@@ -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;
diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h
index 28702f8af3..416ae845c8 100644
--- a/src/devices/nm-device-private.h
+++ b/src/devices/nm-device-private.h
@@ -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 */
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index 171af14e02..06f19c408c 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -315,68 +315,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)
{
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device);
@@ -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;
diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c
index 204b85c001..d9efe8404b 100644
--- a/src/devices/nm-device-vxlan.c
+++ b/src/devices/nm-device-vxlan.c
@@ -231,43 +231,6 @@ create_and_realize (NMDevice *device,
}
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)
{
in_addr_t new_addr4 = 0;
@@ -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))
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 86e2f9d36d..96e39bf768 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -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)
{
diff --git a/src/nm-manager.c b/src/nm-manager.c
index d0429fe9e5..2e47a97591 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -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;