merge: branch 'bg/device-check-compatible'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1522
This commit is contained in:
Beniamino Galvani 2023-03-16 12:01:13 +01:00
commit b3583ec69c
25 changed files with 141 additions and 61 deletions

View file

@ -67,13 +67,16 @@ get_generic_capabilities(NMDevice *dev)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMSettingAdsl *s_adsl;
const char *protocol;
if (!NM_DEVICE_CLASS(nm_device_adsl_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_adsl = nm_connection_get_setting_adsl(connection);

View file

@ -192,7 +192,10 @@ can_auto_connect(NMDevice *device, NMSettingsConnection *sett_conn, char **speci
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceBt *self = NM_DEVICE_BT(device);
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(self);
@ -200,7 +203,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError *
const char *bdaddr;
if (!NM_DEVICE_CLASS(nm_device_bt_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (!get_connection_bt_type_check(self, connection, NULL, error))

View file

@ -101,13 +101,16 @@ check_connection_available(NMDevice *device,
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMSettingBridge *s_bridge;
const char *mac_address;
if (!NM_DEVICE_CLASS(nm_device_bridge_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (nm_connection_is_type(connection, NM_SETTING_BLUETOOTH_SETTING_NAME)

View file

@ -344,13 +344,16 @@ match_subchans(NMDeviceEthernet *self, NMSettingWired *s_wired, gboolean *try_ma
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET(device);
NMSettingWired *s_wired;
if (!NM_DEVICE_CLASS(nm_device_ethernet_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (nm_connection_is_type(connection, NM_SETTING_PPPOE_SETTING_NAME)

View file

@ -72,12 +72,15 @@ realize_start_notify(NMDevice *device, const NMPlatformLink *plink)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMSettingConnection *s_con;
if (!NM_DEVICE_CLASS(nm_device_generic_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_con = nm_connection_get_setting_connection(connection);

View file

@ -108,15 +108,18 @@ get_configured_mtu(NMDevice *device, NMDeviceMtuSource *out_source, gboolean *ou
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMSettingInfiniband *s_infiniband;
if (!NM_DEVICE_CLASS(nm_device_infiniband_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (nm_device_is_real(device)) {
if (check_properties && nm_device_is_real(device)) {
const char *mac;
const char *hw_addr;

View file

@ -498,7 +498,10 @@ update_connection(NMDevice *device, NMConnection *connection)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceIPTunnel *self = NM_DEVICE_IP_TUNNEL(device);
NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE(self);
@ -507,7 +510,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError *
const char *parent;
if (!NM_DEVICE_CLASS(nm_device_ip_tunnel_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_ip_tunnel = nm_connection_get_setting_ip_tunnel(connection);
@ -520,7 +523,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError *
return FALSE;
}
if (nm_device_is_real(device)) {
if (check_properties && 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 && !nm_device_match_parent(device, parent)) {

View file

@ -282,14 +282,17 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
/*****************************************************************************/
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE(device);
NMSettingMacvlan *s_macvlan;
const char *parent = NULL;
if (!NM_DEVICE_CLASS(nm_device_macvlan_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_macvlan = nm_connection_get_setting_macvlan(connection);
@ -308,7 +311,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError *
}
/* Before the device is realized some properties will not be set */
if (nm_device_is_real(device)) {
if (check_properties && nm_device_is_real(device)) {
if (setting_mode_to_platform(nm_setting_macvlan_get_mode(s_macvlan)) != priv->props.mode) {
nm_utils_error_set_literal(error,
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,

View file

@ -149,12 +149,15 @@ _ppp_mgr_callback(NMPppMgr *ppp_mgr, const NMPppMgrCallbackData *callback_data,
/*****************************************************************************/
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMSettingPppoe *s_pppoe;
if (!NM_DEVICE_CLASS(nm_device_ppp_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_pppoe = nm_connection_get_setting_pppoe(connection);

View file

@ -284,7 +284,10 @@ _same_og(const char *str, gboolean og_valid, guint32 og_num)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceTun *self = NM_DEVICE_TUN(device);
NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self);
@ -292,10 +295,10 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError *
NMSettingTun *s_tun;
if (!NM_DEVICE_CLASS(nm_device_tun_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (nm_device_is_real(device)) {
if (check_properties && nm_device_is_real(device)) {
switch (priv->props.type) {
case IFF_TUN:
mode = NM_SETTING_TUN_MODE_TUN;

View file

@ -303,17 +303,20 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
/*****************************************************************************/
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(device);
NMSettingVlan *s_vlan;
const char *parent;
if (!NM_DEVICE_CLASS(nm_device_vlan_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (nm_device_is_real(device)) {
if (check_properties && nm_device_is_real(device)) {
s_vlan = nm_connection_get_setting_vlan(connection);
if (nm_setting_vlan_get_id(s_vlan) != priv->vlan_id) {

View file

@ -142,16 +142,19 @@ create_and_realize(NMDevice *device,
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceVrfPrivate *priv = NM_DEVICE_VRF_GET_PRIVATE(device);
NMSettingVrf *s_vrf;
if (!NM_DEVICE_CLASS(nm_device_vrf_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (nm_device_is_real(device)) {
if (check_properties && nm_device_is_real(device)) {
s_vrf = _nm_connection_get_setting(connection, NM_TYPE_SETTING_VRF);
if (priv->props.table != nm_setting_vrf_get_table(s_vrf)) {

View file

@ -238,17 +238,20 @@ address_matches(const char *candidate, in_addr_t addr4, struct in6_addr *addr6)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE(device);
NMSettingVxlan *s_vxlan;
const char *parent;
if (!NM_DEVICE_CLASS(nm_device_vxlan_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (nm_device_is_real(device)) {
if (check_properties && nm_device_is_real(device)) {
s_vxlan = nm_connection_get_setting_vxlan(connection);
parent = nm_setting_vxlan_get_parent(s_vxlan);

View file

@ -75,13 +75,16 @@ update_connection(NMDevice *device, NMConnection *connection)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMSettingWpan *s_wpan;
const char *mac, *hw_addr;
if (!NM_DEVICE_CLASS(nm_device_wpan_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_wpan = NM_SETTING_WPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_WPAN));

View file

@ -4887,6 +4887,7 @@ nm_device_parent_find_for_connection(NMDevice *self, const char *current_setting
&& nm_device_check_connection_compatible(
parent_device,
nm_settings_connection_get_connection(parent_connection),
TRUE,
NULL))
return current_setting_parent;
}
@ -8860,7 +8861,7 @@ nm_device_complete_connection(NMDevice *self,
if (!nm_connection_normalize(connection, NULL, NULL, error))
return FALSE;
return nm_device_check_connection_compatible(self, connection, error);
return nm_device_check_connection_compatible(self, connection, TRUE, error);
}
gboolean
@ -8920,7 +8921,10 @@ nm_device_match_parent_hwaddr(NMDevice *device,
}
static gboolean
check_connection_compatible(NMDevice *self, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *self,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
const char *device_iface = nm_device_get_iface(self);
@ -9047,12 +9051,18 @@ check_connection_compatible(NMDevice *self, NMConnection *connection, GError **e
* @self.
*/
gboolean
nm_device_check_connection_compatible(NMDevice *self, NMConnection *connection, GError **error)
nm_device_check_connection_compatible(NMDevice *self,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
g_return_val_if_fail(NM_IS_DEVICE(self), FALSE);
g_return_val_if_fail(NM_IS_CONNECTION(connection), FALSE);
return NM_DEVICE_GET_CLASS(self)->check_connection_compatible(self, connection, error);
return NM_DEVICE_GET_CLASS(self)->check_connection_compatible(self,
connection,
check_properties,
error);
}
gboolean
@ -15051,7 +15061,10 @@ _nm_device_check_connection_available(NMDevice *self,
/* an unrealized software device is always available, hardware devices never. */
if (!nm_device_is_real(self)) {
if (nm_device_is_software(self)) {
if (!nm_device_check_connection_compatible(self, connection, error ? &local : NULL)) {
if (!nm_device_check_connection_compatible(self,
connection,
TRUE,
error ? &local : NULL)) {
if (error) {
g_return_val_if_fail(local, FALSE);
nm_utils_error_set(error,
@ -15115,7 +15128,7 @@ _nm_device_check_connection_available(NMDevice *self,
}
}
if (!nm_device_check_connection_compatible(self, connection, error ? &local : NULL)) {
if (!nm_device_check_connection_compatible(self, connection, TRUE, error ? &local : NULL)) {
if (error) {
nm_utils_error_set(error,
local->domain == NM_UTILS_ERROR ? local->code

View file

@ -322,6 +322,7 @@ typedef struct _NMDeviceClass {
*/
gboolean (*check_connection_compatible)(NMDevice *self,
NMConnection *connection,
gboolean check_properties,
GError **error);
/* Checks whether the connection is likely available to be activated,
@ -531,8 +532,10 @@ gboolean nm_device_complete_connection(NMDevice *device,
NMConnection *const *existing_connections,
GError **error);
gboolean
nm_device_check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error);
gboolean nm_device_check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error);
gboolean nm_device_check_slave_connection_compatible(NMDevice *device, NMConnection *connection);

View file

@ -91,12 +91,15 @@ can_auto_connect(NMDevice *device, NMSettingsConnection *sett_conn, char **speci
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMSettingOvsInterface *s_ovs_iface;
if (!NM_DEVICE_CLASS(nm_device_ovs_interface_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_ovs_iface = nm_connection_get_setting_ovs_interface(connection);

View file

@ -126,14 +126,17 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMSettingWifiP2P *s_wifi_p2p;
GBytes *wfd_ies;
NMSettingIPConfig *s_ip;
if (!NM_DEVICE_CLASS(nm_device_iwd_p2p_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_wifi_p2p =

View file

@ -723,7 +723,10 @@ is_ap_known_network(NMIwdManager *manager, NMWifiAP *ap)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceIwd *self = NM_DEVICE_IWD(device);
NMDeviceIwdPrivate *priv = NM_DEVICE_IWD_GET_PRIVATE(self);
@ -739,7 +742,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError *
gsize ssid_len;
if (!NM_DEVICE_CLASS(nm_device_iwd_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_wireless = nm_connection_get_setting_wireless(connection);

View file

@ -233,10 +233,13 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
if (!NM_DEVICE_CLASS(nm_device_wifi_p2p_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
/* TODO: Allow limitting the interface using the HW-address? */

View file

@ -981,7 +981,10 @@ deactivate_reset_hw_addr(NMDevice *device)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
NMDeviceWifi *self = NM_DEVICE_WIFI(device);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self);
@ -995,7 +998,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError *
const char *key_mgmt;
if (!NM_DEVICE_CLASS(nm_device_wifi_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
s_wireless = nm_connection_get_setting_wireless(connection);

View file

@ -383,12 +383,15 @@ get_type_description(NMDevice *device)
}
static gboolean
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
check_connection_compatible(NMDevice *device,
NMConnection *connection,
gboolean check_properties,
GError **error)
{
GError *local = NULL;
if (!NM_DEVICE_CLASS(nm_device_modem_parent_class)
->check_connection_compatible(device, connection, error))
->check_connection_compatible(device, connection, check_properties, error))
return FALSE;
if (!nm_modem_check_connection_compatible(NM_DEVICE_MODEM_GET_PRIVATE(device)->modem,

View file

@ -1865,7 +1865,7 @@ find_device_by_iface(NMManager *self,
c_list_for_each_entry (candidate, &priv->devices_lst_head, devices_lst) {
if (!nm_streq(nm_device_get_iface(candidate), iface))
continue;
if (connection && !nm_device_check_connection_compatible(candidate, connection, NULL))
if (connection && !nm_device_check_connection_compatible(candidate, connection, TRUE, NULL))
continue;
if (slave) {
if (!nm_device_is_master(candidate))
@ -2369,6 +2369,7 @@ find_parent_device_for_connection(NMManager *self,
&& nm_device_check_connection_compatible(
candidate,
nm_settings_connection_get_connection(parent_connection),
TRUE,
NULL))
first_compatible = candidate;
}
@ -2548,7 +2549,7 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
/* See if there's a device that is already compatible with this connection */
c_list_for_each_entry (dev_candidate, &priv->devices_lst_head, devices_lst) {
if (nm_device_check_connection_compatible(dev_candidate, connection, NULL)) {
if (nm_device_check_connection_compatible(dev_candidate, connection, FALSE, NULL)) {
if (nm_device_is_real(dev_candidate)) {
_LOG3D(LOGD_DEVICE, connection, "already created virtual interface name %s", iface);
return NULL;
@ -2617,7 +2618,7 @@ system_create_virtual_device(NMManager *self, NMConnection *connection)
NMConnection *candidate = nm_settings_connection_get_connection(connections[i]);
NMSettingConnection *s_con;
if (!nm_device_check_connection_compatible(device, candidate, NULL))
if (!nm_device_check_connection_compatible(device, candidate, TRUE, NULL))
continue;
s_con = nm_connection_get_setting_connection(candidate);
@ -3376,6 +3377,7 @@ get_existing_connection(NMManager *self, NMDevice *device, gboolean *out_generat
&& nm_device_check_connection_compatible(
device,
nm_settings_connection_get_connection(connection_checked),
TRUE,
NULL)) {
if (connection) {
NMConnection *con = nm_settings_connection_get_connection(connection_checked);
@ -3414,6 +3416,7 @@ get_existing_connection(NMManager *self, NMDevice *device, gboolean *out_generat
&& nm_device_check_connection_compatible(
device,
nm_settings_connection_get_connection(sett_conn),
TRUE,
NULL))
sett_conns[j++] = sett_conn;
}
@ -4259,7 +4262,7 @@ _check_remove_dev_on_link_deleted(NMManager *self, NMDevice *device)
NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED))
continue;
if (!nm_device_check_connection_compatible(device, con, NULL))
if (!nm_device_check_connection_compatible(device, con, TRUE, NULL))
continue;
/* Found a virtual connection compatible, the device must

View file

@ -1640,6 +1640,7 @@ reset_autoconnect_all(
&& !nm_device_check_connection_compatible(
device,
nm_settings_connection_get_connection(sett_conn),
TRUE,
NULL))
continue;

View file

@ -535,7 +535,7 @@ _startup_complete_check_is_ready(NMSettings *self,
/* Check that device is compatible with the device. We are also happy
* with a device compatible but for which the connection is disallowed
* by NM configuration. */
if (!nm_device_check_connection_compatible(device, conn, &error)
if (!nm_device_check_connection_compatible(device, conn, TRUE, &error)
&& !g_error_matches(error,
NM_UTILS_ERROR,
NM_UTILS_ERROR_CONNECTION_AVAILABLE_DISALLOWED))
@ -3641,7 +3641,7 @@ have_connection_for_device(NMSettings *self, NMDevice *device)
c_list_for_each_entry (sett_conn, &priv->connections_lst_head, _connections_lst) {
NMConnection *connection = nm_settings_connection_get_connection(sett_conn);
if (!nm_device_check_connection_compatible(device, connection, NULL))
if (!nm_device_check_connection_compatible(device, connection, TRUE, NULL))
continue;
if (nm_settings_connection_default_wired_get_device(sett_conn))