Commit 7314256b authored by Dan Winship's avatar Dan Winship

libnm-core: drop nm_{setting,connection}_get_virtual_iface_name()

Since we enforce the fact that bond, bridge, team, and vlan
interface-name properties match NMSettingConnection:interface-name,
nm_connection_get_virtual_iface_name() can be replaced with
nm_connection_get_interface_name() basically everywhere.

The one place this doesn't work is with InfiniBand partitions (where
get_virtual_iface_name() was actually computing the name), but for the
most part we only need to care about the interface names of InfiniBand
partitions in places where we also already need to do some other
InfiniBand-specific handling as well, so we can use an
InfiniBand-specific method
(nm_setting_infiniband_get_virtual_interface_name()) to get it.

(Also, while updating nm_device_get_virtual_device_description(), fix
it to handle InfiniBand partitions too.)
parent 608b13e7
......@@ -2726,7 +2726,7 @@ _strip_master_prefix (const char *master, const char *(**func)(NMConnection *))
if (g_str_has_prefix (master, "ifname/")) {
master = master + strlen ("ifname/");
if (func)
*func = nm_connection_get_virtual_iface_name;
*func = nm_connection_get_interface_name;
} else if (g_str_has_prefix (master, "uuid/")) {
master = master + strlen ("uuid/");
if (func)
......@@ -2788,7 +2788,7 @@ verify_master_for_slave (GSList *connections,
} else {
id = nm_connection_get_id (connection);
uuid = nm_connection_get_uuid (connection);
ifname = nm_connection_get_virtual_iface_name (connection);
ifname = nm_connection_get_interface_name (connection);
if ( g_strcmp0 (master, uuid) == 0
|| g_strcmp0 (master, ifname) == 0) {
out_master = master;
......@@ -5094,7 +5094,7 @@ gen_func_master_ifnames (const char *text, int state)
con_type = nm_setting_connection_get_connection_type (s_con);
if (g_strcmp0 (con_type, nmc_tab_completion.con_type) != 0)
continue;
ifname = nm_connection_get_virtual_iface_name (con);
ifname = nm_connection_get_interface_name (con);
g_ptr_array_add (ifnames, (gpointer) ifname);
}
g_ptr_array_add (ifnames, (gpointer) NULL);
......
......@@ -122,7 +122,7 @@ nmt_slave_list_connection_filter (NmtEditConnectionList *list,
if (!master)
return FALSE;
master_ifname = nm_connection_get_virtual_iface_name (priv->master);
master_ifname = nm_connection_get_interface_name (priv->master);
if (g_strcmp0 (master, master_ifname) != 0 && g_strcmp0 (master, priv->master_uuid) != 0)
return FALSE;
......
......@@ -242,28 +242,6 @@ nm_connection_get_setting_by_name (NMConnection *connection, const char *name)
return type ? nm_connection_get_setting (connection, type) : NULL;
}
/* not exposed until we actually need it */
static NMSetting *
_get_type_setting (NMConnection *connection)
{
NMSettingConnection *s_con;
const char *type;
NMSetting *base;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
type = nm_setting_connection_get_connection_type (s_con);
g_assert (type);
base = nm_connection_get_setting_by_name (connection, type);
g_assert (base);
return base;
}
static gboolean
validate_permissions_type (GHashTable *hash, GError **error)
{
......@@ -1432,30 +1410,6 @@ nm_connection_get_interface_name (NMConnection *connection)
return s_con ? nm_setting_connection_get_interface_name (s_con) : NULL;
}
/**
* nm_connection_get_virtual_iface_name:
* @connection: The #NMConnection
*
* Returns the name of the virtual kernel interface which the connection
* needs to use if specified in the settings. This function abstracts all
* connection types which require this functionality. For all other
* connection types, this function will return %NULL.
*
* Returns: Name of the kernel interface or %NULL
*/
const char *
nm_connection_get_virtual_iface_name (NMConnection *connection)
{
NMSetting *base;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
base = _get_type_setting (connection);
g_assert (base);
return nm_setting_get_virtual_iface_name (base);
}
/**
* nm_connection_get_uuid:
* @connection: the #NMConnection
......@@ -1533,16 +1487,13 @@ nm_connection_get_connection_type (NMConnection *connection)
char *
nm_connection_get_virtual_device_description (NMConnection *connection)
{
const char *iface, *type, *display_type;
NMSettingConnection *s_con;
const char *type;
const char *iface = NULL, *display_type = NULL;
iface = nm_connection_get_virtual_iface_name (connection);
if (!iface)
return NULL;
iface = nm_connection_get_interface_name (connection);
s_con = nm_connection_get_setting_connection (connection);
g_return_val_if_fail (s_con != NULL, NULL);
type = nm_setting_connection_get_connection_type (s_con);
type = nm_connection_get_connection_type (connection);
g_return_val_if_fail (type != NULL, FALSE);
if (!strcmp (type, NM_SETTING_BOND_SETTING_NAME))
display_type = _("Bond");
......@@ -1552,11 +1503,14 @@ nm_connection_get_virtual_device_description (NMConnection *connection)
display_type = _("Bridge");
else if (!strcmp (type, NM_SETTING_VLAN_SETTING_NAME))
display_type = _("VLAN");
else {
g_warning ("Unrecognized virtual device type '%s'", type);
display_type = type;
else if (!strcmp (type, NM_SETTING_INFINIBAND_SETTING_NAME)) {
display_type = _("InfiniBand");
iface = nm_setting_infiniband_get_virtual_interface_name (nm_connection_get_setting_infiniband (connection));
}
if (!iface || !display_type)
return NULL;
return g_strdup_printf ("%s (%s)", display_type, iface);
}
......
......@@ -202,8 +202,6 @@ void nm_connection_set_path (NMConnection *connection,
const char * nm_connection_get_path (NMConnection *connection);
const char * nm_connection_get_virtual_iface_name (NMConnection *connection);
const char * nm_connection_get_interface_name (NMConnection *connection);
gboolean nm_connection_is_type (NMConnection *connection, const char *type);
......
......@@ -674,14 +674,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
all_settings, error);
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
NMSettingBond *self = NM_SETTING_BOND (setting);
return nm_setting_bond_get_interface_name (self);
}
static void
nm_setting_bond_init (NMSettingBond *setting)
{
......@@ -768,7 +760,6 @@ nm_setting_bond_class_init (NMSettingBondClass *setting_class)
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
/**
......
......@@ -300,14 +300,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
all_settings, error);
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
NMSettingBridge *self = NM_SETTING_BRIDGE (setting);
return nm_setting_bridge_get_interface_name (self);
}
static void
nm_setting_bridge_init (NMSettingBridge *setting)
{
......@@ -417,7 +409,6 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *setting_class)
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
/**
......
......@@ -175,8 +175,18 @@ nm_setting_infiniband_get_parent (NMSettingInfiniband *setting)
return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->parent;
}
static const char *
get_virtual_iface_name (NMSetting *setting)
/**
* nm_setting_infiniband_get_virtual_interface_name:
* @setting: the #NMSettingInfiniband
*
* Returns the interface name created by combining #NMSettingInfiniband:parent
* and #NMSettingInfiniband:p-key. (If either property is unset, this will
* return %NULL.)
*
* Returns: the interface name, or %NULL
**/
const char *
nm_setting_infiniband_get_virtual_interface_name (NMSettingInfiniband *setting)
{
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (setting);
......@@ -397,8 +407,7 @@ nm_setting_infiniband_class_init (NMSettingInfinibandClass *setting_class)
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
parent_class->verify = verify;
/* Properties */
/**
......
......@@ -81,6 +81,8 @@ const char * nm_setting_infiniband_get_transport_mode (NMSettingInfiniband
int nm_setting_infiniband_get_p_key (NMSettingInfiniband *setting);
const char * nm_setting_infiniband_get_parent (NMSettingInfiniband *setting);
const char * nm_setting_infiniband_get_virtual_interface_name (NMSettingInfiniband *setting);
G_END_DECLS
#endif /* __NM_SETTING_INFINIBAND_H__ */
......@@ -132,14 +132,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
all_settings, error);
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
NMSettingTeam *self = NM_SETTING_TEAM (setting);
return nm_setting_team_get_interface_name (self);
}
static void
nm_setting_team_init (NMSettingTeam *setting)
{
......@@ -209,7 +201,6 @@ nm_setting_team_class_init (NMSettingTeamClass *setting_class)
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
/**
......
......@@ -602,12 +602,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
all_settings, error);
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
return nm_setting_vlan_get_interface_name (NM_SETTING_VLAN (setting));
}
static GSList *
priority_stringlist_to_maplist (NMVlanPriorityMap map, GSList *strlist)
{
......@@ -733,7 +727,6 @@ nm_setting_vlan_class_init (NMSettingVlanClass *setting_class)
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
......
......@@ -1534,27 +1534,6 @@ nm_setting_to_string (NMSetting *setting)
return g_string_free (string, FALSE);
}
/**
* nm_setting_get_virtual_iface_name:
* @setting: the #NMSetting
*
* Returns the name of the virtual kernel interface which the connection
* needs to use if specified in the settings.
*
* Returns: Name of the virtual interface or %NULL if the setting does not
* support this feature
**/
const char *
nm_setting_get_virtual_iface_name (NMSetting *setting)
{
g_return_val_if_fail (NM_IS_SETTING (setting), NULL);
if (NM_SETTING_GET_CLASS (setting)->get_virtual_iface_name)
return NM_SETTING_GET_CLASS (setting)->get_virtual_iface_name (setting);
return NULL;
}
NMSetting *
_nm_setting_find_in_list_required (GSList *all_settings,
const char *setting_name,
......
......@@ -205,8 +205,6 @@ typedef struct {
const GParamSpec *prop_spec,
NMSettingCompareFlags flags);
const char *(*get_virtual_iface_name) (NMSetting *setting);
/*< private >*/
gpointer padding[8];
} NMSettingClass;
......@@ -289,8 +287,6 @@ gboolean nm_setting_set_secret_flags (NMSetting *setting,
NMSettingSecretFlags flags,
GError **error);
const char *nm_setting_get_virtual_iface_name (NMSetting *setting);
G_END_DECLS
#endif /* __NM_SETTING_H__ */
......@@ -117,7 +117,6 @@ global:
nm_connection_get_type;
nm_connection_get_uuid;
nm_connection_get_virtual_device_description;
nm_connection_get_virtual_iface_name;
nm_connection_is_type;
nm_connection_need_secrets;
nm_connection_normalize;
......@@ -579,7 +578,6 @@ global:
nm_setting_get_name;
nm_setting_get_secret_flags;
nm_setting_get_type;
nm_setting_get_virtual_iface_name;
nm_setting_gsm_error_get_type;
nm_setting_gsm_error_quark;
nm_setting_gsm_get_apn;
......@@ -601,6 +599,7 @@ global:
nm_setting_infiniband_get_parent;
nm_setting_infiniband_get_transport_mode;
nm_setting_infiniband_get_type;
nm_setting_infiniband_get_virtual_interface_name;
nm_setting_infiniband_new;
nm_setting_ip4_config_add_address;
nm_setting_ip4_config_add_dns;
......
......@@ -111,7 +111,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
/* Bond connections must specify the virtual interface name */
iface = nm_connection_get_virtual_iface_name (connection);
iface = nm_connection_get_interface_name (connection);
if (!iface || strcmp (nm_device_get_iface (device), iface))
return FALSE;
......@@ -508,7 +508,7 @@ nm_device_bond_new_for_connection (NMConnection *connection)
g_return_val_if_fail (connection != NULL, NULL);
iface = nm_connection_get_virtual_iface_name (connection);
iface = nm_connection_get_interface_name (connection);
g_return_val_if_fail (iface != NULL, NULL);
if ( !nm_platform_bond_add (iface)
......
......@@ -111,7 +111,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
/* Bridge connections must specify the virtual interface name */
iface = nm_connection_get_virtual_iface_name (connection);
iface = nm_connection_get_interface_name (connection);
if (!iface || strcmp (nm_device_get_iface (device), iface))
return FALSE;
......@@ -461,7 +461,7 @@ nm_device_bridge_new_for_connection (NMConnection *connection)
g_return_val_if_fail (connection != NULL, NULL);
iface = nm_connection_get_virtual_iface_name (connection);
iface = nm_connection_get_interface_name (connection);
g_return_val_if_fail (iface != NULL, NULL);
s_bridge = nm_connection_get_setting_bridge (connection);
......
......@@ -92,11 +92,12 @@ nm_device_infiniband_new_partition (NMConnection *connection,
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (parent), NULL);
iface = nm_connection_get_virtual_iface_name (connection);
s_infiniband = nm_connection_get_setting_infiniband (connection);
iface = nm_setting_infiniband_get_virtual_interface_name (s_infiniband);
g_return_val_if_fail (iface != NULL, NULL);
parent_ifindex = nm_device_get_ifindex (parent);
s_infiniband = nm_connection_get_setting_infiniband (connection);
p_key = nm_setting_infiniband_get_p_key (s_infiniband);
if ( !nm_platform_infiniband_partition_add (parent_ifindex, p_key)
......
......@@ -205,7 +205,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
* since both the parent interface and the VLAN ID matched by the time we
* get here.
*/
iface = nm_connection_get_virtual_iface_name (connection);
iface = nm_connection_get_interface_name (connection);
if (iface) {
if (g_strcmp0 (nm_device_get_ip_iface (device), iface) != 0)
return FALSE;
......@@ -470,7 +470,7 @@ nm_device_vlan_new_for_connection (NMConnection *connection, NMDevice *parent)
s_vlan = nm_connection_get_setting_vlan (connection);
g_return_val_if_fail (s_vlan != NULL, NULL);
iface = g_strdup (nm_connection_get_virtual_iface_name (connection));
iface = g_strdup (nm_connection_get_interface_name (connection));
if (!iface) {
iface = nm_utils_new_vlan_name (nm_device_get_ip_iface (parent),
nm_setting_vlan_get_id (s_vlan));
......
......@@ -122,7 +122,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
/* Team connections must specify the virtual interface name */
iface = nm_connection_get_virtual_iface_name (connection);
iface = nm_connection_get_interface_name (connection);
if (!iface || strcmp (nm_device_get_iface (device), iface))
return FALSE;
......@@ -716,7 +716,7 @@ nm_device_team_new_for_connection (NMConnection *connection, GError **error)
g_return_val_if_fail (connection != NULL, NULL);
iface = nm_connection_get_virtual_iface_name (connection);
iface = nm_connection_get_interface_name (connection);
g_return_val_if_fail (iface != NULL, NULL);
if ( !nm_platform_team_add (iface)
......
......@@ -966,13 +966,13 @@ get_virtual_iface_name (NMManager *self,
*out_parent = NULL;
if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME))
return g_strdup (nm_connection_get_virtual_iface_name (connection));
return g_strdup (nm_connection_get_interface_name (connection));
if (nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME))
return g_strdup (nm_connection_get_virtual_iface_name (connection));
return g_strdup (nm_connection_get_interface_name (connection));
if (nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME))
return g_strdup (nm_connection_get_virtual_iface_name (connection));
return g_strdup (nm_connection_get_interface_name (connection));
if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
NMSettingVlan *s_vlan;
......@@ -984,7 +984,7 @@ get_virtual_iface_name (NMManager *self,
parent = find_vlan_parent (self, connection);
if (parent) {
ifname = nm_connection_get_virtual_iface_name (connection);
ifname = nm_connection_get_interface_name (connection);
if (!nm_device_supports_vlans (parent)) {
nm_log_warn (LOGD_DEVICE, "(%s): No support for VLANs on interface %s of type %s",
......@@ -1011,26 +1011,14 @@ get_virtual_iface_name (NMManager *self,
}
if (nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) {
const char *ifname;
char *name;
parent = find_infiniband_parent (self, connection);
if (parent) {
ifname = nm_connection_get_virtual_iface_name (connection);
if (ifname)
name = g_strdup (ifname);
else {
NMSettingInfiniband *s_infiniband;
int p_key;
NMSettingInfiniband *s_infiniband;
ifname = nm_device_get_iface (parent);
s_infiniband = nm_connection_get_setting_infiniband (connection);
p_key = nm_setting_infiniband_get_p_key (s_infiniband);
name = g_strdup_printf ("%s.%04x", ifname, p_key);
}
s_infiniband = nm_connection_get_setting_infiniband (connection);
if (out_parent)
*out_parent = parent;
return name;
return g_strdup (nm_setting_infiniband_get_virtual_interface_name (s_infiniband));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment