mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 18:20:07 +01:00
device: deduplicate match_parent()
This commit is contained in:
parent
ed640f857a
commit
27c281ac5a
6 changed files with 39 additions and 156 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,45 +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)
|
||||
{
|
||||
|
|
@ -378,7 +339,7 @@ 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 */
|
||||
|
|
|
|||
|
|
@ -132,4 +132,6 @@ 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);
|
||||
|
||||
#endif /* NM_DEVICE_PRIVATE_H */
|
||||
|
|
|
|||
|
|
@ -314,44 +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)
|
||||
{
|
||||
|
|
@ -398,7 +360,7 @@ 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 */
|
||||
|
|
|
|||
|
|
@ -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,38 @@ 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 if our parent
|
||||
* device has that connection activated.
|
||||
*/
|
||||
connection = nm_device_get_applied_connection (self);
|
||||
if (!connection)
|
||||
return FALSE;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
check_connection_compatible (NMDevice *self, NMConnection *connection)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue