device: cleanup get_connection_iface() callbacks

Some of them are wrong: they assert a connection has a particular
setting even though this can be called on AddAndActivate against a
connection that is not complete or normalized:

  impl_manager_add_and_activate_connection ()
    validate_activation_request ()
      nm_manager_get_best_device_for_connection ()
      iface = nm_manager_get_connection_iface ()
        find_parent_device_for_connection ()
          nm_device_factory_get_connection_parent ()
        nm_device_factory_get_connection_iface () <====== here
      find_device_by_iface (iface)
    nm_device_complete_connection ()

Fix those by removing the assertions.

Some of them are also fall back to just calling
nm_connection_get_interface_name() which is a pretty useless thing to do
because nm_device_factory_get_connection_iface() only calls the
device-specific routine if nm_device_factory_get_connection_iface()
doesn't return anything, to give the factory a chance to make up a name
(like <parent>.<vlan-id> for Vlan) on its own. Drop those.
This commit is contained in:
Lubomir Rintel
2024-12-13 10:27:40 +01:00
parent e3d3f1315a
commit b7a8486c53
9 changed files with 20 additions and 154 deletions

View File

@@ -281,24 +281,6 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
return nm_setting_6lowpan_get_parent(s_6lowpan); return nm_setting_6lowpan_get_parent(s_6lowpan);
} }
static char *
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
{
NMSetting6Lowpan *s_6lowpan;
const char *ifname;
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_6LOWPAN_SETTING_NAME), NULL);
s_6lowpan = NM_SETTING_6LOWPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_6LOWPAN));
g_assert(s_6lowpan);
if (!parent_iface)
return NULL;
ifname = nm_connection_get_interface_name(connection);
return g_strdup(ifname);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(
6LOWPAN, 6LOWPAN,
6Lowpan, 6Lowpan,
@@ -306,5 +288,4 @@ NM_DEVICE_FACTORY_DEFINE_INTERNAL(
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_6LOWPAN) NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_6LOWPAN)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_6LOWPAN_SETTING_NAME), NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_6LOWPAN_SETTING_NAME),
factory_class->create_device = create_device; factory_class->create_device = create_device;
factory_class->get_connection_parent = get_connection_parent; factory_class->get_connection_parent = get_connection_parent;);
factory_class->get_connection_iface = get_connection_iface;);

View File

@@ -477,17 +477,19 @@ get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const c
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_INFINIBAND_SETTING_NAME), g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_INFINIBAND_SETTING_NAME),
NULL); NULL);
s_infiniband = nm_connection_get_setting_infiniband(connection);
g_assert(s_infiniband);
if (!parent_iface) if (!parent_iface)
return NULL; return NULL;
g_return_val_if_fail(g_strcmp0(parent_iface, nm_setting_infiniband_get_parent(s_infiniband)) s_infiniband = nm_connection_get_setting_infiniband(connection);
== 0, if (s_infiniband) {
NULL); g_return_val_if_fail(g_strcmp0(parent_iface, nm_setting_infiniband_get_parent(s_infiniband))
== 0,
NULL);
return g_strdup(nm_setting_infiniband_get_virtual_interface_name(s_infiniband)); return g_strdup(nm_setting_infiniband_get_virtual_interface_name(s_infiniband));
} else {
return NULL;
}
} }
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(

View File

@@ -1374,26 +1374,6 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
return nm_setting_ip_tunnel_get_parent(s_ip_tunnel); return nm_setting_ip_tunnel_get_parent(s_ip_tunnel);
} }
static char *
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
{
const char *ifname;
NMSettingIPTunnel *s_ip_tunnel;
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_IP_TUNNEL_SETTING_NAME),
NULL);
s_ip_tunnel = nm_connection_get_setting_ip_tunnel(connection);
g_assert(s_ip_tunnel);
if (nm_setting_ip_tunnel_get_parent(s_ip_tunnel) && !parent_iface)
return NULL;
ifname = nm_connection_get_interface_name(connection);
return g_strdup(ifname);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(
IP_TUNNEL, IP_TUNNEL,
IPTunnel, IPTunnel,
@@ -1409,5 +1389,4 @@ NM_DEVICE_FACTORY_DEFINE_INTERNAL(
NM_LINK_TYPE_VTI6) NM_LINK_TYPE_VTI6)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_IP_TUNNEL_SETTING_NAME), NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_IP_TUNNEL_SETTING_NAME),
factory_class->create_device = create_device; factory_class->create_device = create_device;
factory_class->get_connection_parent = get_connection_parent; factory_class->get_connection_parent = get_connection_parent;);
factory_class->get_connection_iface = get_connection_iface;);

View File

@@ -458,24 +458,6 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
return NULL; return NULL;
} }
static char *
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
{
NMSettingIpvlan *s_ipvlan;
const char *ifname;
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_IPVLAN_SETTING_NAME), NULL);
s_ipvlan = _nm_connection_get_setting(connection, NM_TYPE_SETTING_IPVLAN);
nm_assert(s_ipvlan);
if (!parent_iface)
return NULL;
ifname = nm_connection_get_interface_name(connection);
return g_strdup(ifname);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(
IPVLAN, IPVLAN,
Ipvlan, Ipvlan,
@@ -483,5 +465,4 @@ NM_DEVICE_FACTORY_DEFINE_INTERNAL(
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_IPVLAN) NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_IPVLAN)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_IPVLAN_SETTING_NAME), NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_IPVLAN_SETTING_NAME),
factory_class->create_device = create_device; factory_class->create_device = create_device;
factory_class->get_connection_parent = get_connection_parent; factory_class->get_connection_parent = get_connection_parent;);
factory_class->get_connection_iface = get_connection_iface;);

View File

@@ -1036,24 +1036,6 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
return NULL; return NULL;
} }
static char *
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
{
NMSettingMacsec *s_macsec;
const char *ifname;
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_MACSEC_SETTING_NAME), NULL);
s_macsec = nm_connection_get_setting_macsec(connection);
g_assert(s_macsec);
if (!parent_iface)
return NULL;
ifname = nm_connection_get_interface_name(connection);
return g_strdup(ifname);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(
MACSEC, MACSEC,
Macsec, Macsec,
@@ -1061,5 +1043,4 @@ NM_DEVICE_FACTORY_DEFINE_INTERNAL(
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_MACSEC) NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_MACSEC)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_MACSEC_SETTING_NAME), NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_MACSEC_SETTING_NAME),
factory_class->create_device = create_device; factory_class->create_device = create_device;
factory_class->get_connection_parent = get_connection_parent; factory_class->get_connection_parent = get_connection_parent;);
factory_class->get_connection_iface = get_connection_iface;)

View File

@@ -604,24 +604,6 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
return NULL; return NULL;
} }
static char *
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
{
NMSettingMacvlan *s_macvlan;
const char *ifname;
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_MACVLAN_SETTING_NAME), NULL);
s_macvlan = nm_connection_get_setting_macvlan(connection);
g_assert(s_macvlan);
if (!parent_iface)
return NULL;
ifname = nm_connection_get_interface_name(connection);
return g_strdup(ifname);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(
MACVLAN, MACVLAN,
Macvlan, Macvlan,
@@ -629,5 +611,4 @@ NM_DEVICE_FACTORY_DEFINE_INTERNAL(
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_MACVLAN, NM_LINK_TYPE_MACVTAP) NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_MACVLAN, NM_LINK_TYPE_MACVTAP)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_MACVLAN_SETTING_NAME), NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_MACVLAN_SETTING_NAME),
factory_class->create_device = create_device; factory_class->create_device = create_device;
factory_class->get_connection_parent = get_connection_parent; factory_class->get_connection_parent = get_connection_parent;);
factory_class->get_connection_iface = get_connection_iface;);

View File

@@ -385,17 +385,6 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
return nm_setting_pppoe_get_parent(s_pppoe); return nm_setting_pppoe_get_parent(s_pppoe);
} }
static char *
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
{
nm_assert(nm_connection_is_type(connection, NM_SETTING_PPPOE_SETTING_NAME));
if (!parent_iface)
return NULL;
return g_strdup(nm_connection_get_interface_name(connection));
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(
PPP, PPP,
Ppp, Ppp,
@@ -403,6 +392,5 @@ NM_DEVICE_FACTORY_DEFINE_INTERNAL(
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_PPP) NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_PPP)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_PPPOE_SETTING_NAME), NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_PPPOE_SETTING_NAME),
factory_class->get_connection_parent = get_connection_parent; factory_class->get_connection_parent = get_connection_parent;
factory_class->get_connection_iface = get_connection_iface;
factory_class->create_device = create_device; factory_class->create_device = create_device;
factory_class->match_connection = match_connection;); factory_class->match_connection = match_connection;);

View File

@@ -635,26 +635,18 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
static char * static char *
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface) get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
{ {
const char *ifname;
NMSettingVlan *s_vlan; NMSettingVlan *s_vlan;
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_VLAN_SETTING_NAME), NULL); g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_VLAN_SETTING_NAME), NULL);
s_vlan = nm_connection_get_setting_vlan(connection);
g_assert(s_vlan);
if (!parent_iface) if (!parent_iface)
return NULL; return NULL;
ifname = nm_connection_get_interface_name(connection); s_vlan = nm_connection_get_setting_vlan(connection);
if (ifname) if (s_vlan)
return g_strdup(ifname); return nmp_utils_new_vlan_name(parent_iface, nm_setting_vlan_get_id(s_vlan));
else
/* If the connection doesn't specify the interface name for the VLAN return NULL;
* device, we create one for it using the VLAN ID and the parent
* interface's name.
*/
return nmp_utils_new_vlan_name(parent_iface, nm_setting_vlan_get_id(s_vlan));
} }
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(

View File

@@ -782,24 +782,6 @@ get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
return nm_setting_vxlan_get_parent(s_vxlan); return nm_setting_vxlan_get_parent(s_vxlan);
} }
static char *
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
{
const char *ifname;
NMSettingVxlan *s_vxlan;
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_VXLAN_SETTING_NAME), NULL);
s_vxlan = nm_connection_get_setting_vxlan(connection);
g_assert(s_vxlan);
if (nm_setting_vxlan_get_parent(s_vxlan) && !parent_iface)
return NULL;
ifname = nm_connection_get_interface_name(connection);
return g_strdup(ifname);
}
NM_DEVICE_FACTORY_DEFINE_INTERNAL( NM_DEVICE_FACTORY_DEFINE_INTERNAL(
VXLAN, VXLAN,
Vxlan, Vxlan,
@@ -807,5 +789,4 @@ NM_DEVICE_FACTORY_DEFINE_INTERNAL(
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_VXLAN) NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_VXLAN)
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_VXLAN_SETTING_NAME), NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_VXLAN_SETTING_NAME),
factory_class->create_device = create_device; factory_class->create_device = create_device;
factory_class->get_connection_parent = get_connection_parent; factory_class->get_connection_parent = get_connection_parent;);
factory_class->get_connection_iface = get_connection_iface;);