libnm-base: move nmp_utils_new_infiniband_name() to nm_net_devname_infiniband()

This commit is contained in:
Thomas Haller 2023-05-25 21:33:02 +02:00
parent 3d71eddf63
commit b8b74f4000
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
8 changed files with 40 additions and 36 deletions

View file

@ -849,7 +849,7 @@ infiniband_partition_add(NMPlatform *platform,
parent_device = link_get(platform, parent);
g_return_val_if_fail(parent_device != NULL, FALSE);
nmp_utils_new_infiniband_name(name, parent_device->obj->link.name, p_key);
nm_net_devname_infiniband(name, parent_device->obj->link.name, p_key);
link_add_one(platform, name, NM_LINK_TYPE_INFINIBAND, _infiniband_add_prepare, &d, out_link);
return TRUE;
@ -864,7 +864,7 @@ infiniband_partition_delete(NMPlatform *platform, int parent, int p_key)
parent_device = link_get(platform, parent);
g_return_val_if_fail(parent_device != NULL, FALSE);
nmp_utils_new_infiniband_name(name, parent_device->obj->link.name, p_key);
nm_net_devname_infiniband(name, parent_device->obj->link.name, p_key);
return link_delete(platform, nm_platform_link_get_ifindex(platform, name));
}

View file

@ -5424,7 +5424,7 @@ parse_infiniband_p_key(shvarFile *ifcfg, int *out_p_key, char **out_parent, GErr
* automatically sets.
*
* NetworkManager supports p-keys without the high bit set. That affects
* the interface name (nmp_utils_new_infiniband_name()) and is what
* the interface name (nm_net_devname_infiniband()) and is what
* we write to "create_child"/"delete_child" sysctl. Kernel will honor
* such p-keys for the interface name, but for other purposes it adds the
* highest bit. That makes using p-keys without the highest bit odd.

View file

@ -39,3 +39,32 @@ nm_dhcp_iaid_from_hexstr(const char *str, guint32 *out_value)
NM_SET_OUT(out_value, be32toh(iaid.num));
return TRUE;
}
/*****************************************************************************/
/* nm_net_devname_infiniband:
* @name: the output-buffer where the value will be written. Must be
* not %NULL and point to a string buffer of at least IFNAMSIZ bytes.
* @parent_name: the parent interface name
* @p_key: the partition key.
*
* Returns: the infiniband name will be written to @name and @name
* is returned.
*/
const char *
nm_net_devname_infiniband(char name[static NM_IFNAMSIZ], const char *parent_name, int p_key)
{
g_return_val_if_fail(name, NULL);
g_return_val_if_fail(parent_name && parent_name[0], NULL);
g_return_val_if_fail(strlen(parent_name) < NM_IFNAMSIZ, NULL);
/* technically, p_key of 0x0000 and 0x8000 is not allowed either. But we don't
* want to assert against that in nm_net_devname_infiniband(). So be more
* resilient here, and accept those. */
g_return_val_if_fail(p_key >= 0 && p_key <= 0xffff, NULL);
/* If parent+suffix is too long, kernel would just truncate
* the name. We do the same. See ipoib_vlan_add(). */
g_snprintf(name, NM_IFNAMSIZ, "%s.%04x", parent_name, p_key);
return name;
}

View file

@ -432,4 +432,9 @@ char *nm_dhcp_iaid_to_hexstr(guint32 iaid, char buf[static NM_DHCP_IAID_TO_HEXST
gboolean nm_dhcp_iaid_from_hexstr(const char *str, guint32 *out_value);
/*****************************************************************************/
const char *
nm_net_devname_infiniband(char name[static NM_IFNAMSIZ], const char *parent_name, int p_key);
#endif /* __NM_LIBNM_BASE_H__ */

View file

@ -9387,7 +9387,7 @@ _infiniband_partition_action(NMPlatform *platform,
return FALSE;
}
nmp_utils_new_infiniband_name(name, ifname_parent, p_key);
nm_net_devname_infiniband(name, ifname_parent, p_key);
do_request_link(platform, 0, name);
if (action == INFINIBAND_ACTION_DELETE_CHILD)

View file

@ -2064,35 +2064,6 @@ nmp_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id)
/*****************************************************************************/
/* nmp_utils_new_infiniband_name:
* @name: the output-buffer where the value will be written. Must be
* not %NULL and point to a string buffer of at least IFNAMSIZ bytes.
* @parent_name: the parent interface name
* @p_key: the partition key.
*
* Returns: the infiniband name will be written to @name and @name
* is returned.
*/
const char *
nmp_utils_new_infiniband_name(char *name, const char *parent_name, int p_key)
{
g_return_val_if_fail(name, NULL);
g_return_val_if_fail(parent_name && parent_name[0], NULL);
g_return_val_if_fail(strlen(parent_name) < IFNAMSIZ, NULL);
/* technically, p_key of 0x0000 and 0x8000 is not allowed either. But we don't
* want to assert against that in nmp_utils_new_infiniband_name(). So be more
* resilient here, and accept those. */
g_return_val_if_fail(p_key >= 0 && p_key <= 0xffff, NULL);
/* If parent+suffix is too long, kernel would just truncate
* the name. We do the same. See ipoib_vlan_add(). */
g_snprintf(name, IFNAMSIZ, "%s.%04x", parent_name, p_key);
return name;
}
/*****************************************************************************/
/**
* Takes a pair @timestamp and @duration, and returns the remaining duration based
* on the new timestamp @now.

View file

@ -77,8 +77,7 @@ int nmp_utils_if_nametoindex(const char *ifname);
int nmp_utils_sysctl_open_netdir(int ifindex, const char *ifname_guess, char *out_ifname);
char *nmp_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id);
const char *nmp_utils_new_infiniband_name(char *name, const char *parent_name, int p_key);
char *nmp_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id);
guint32
nmp_utils_lifetime_rebase_relative_time_on_now(guint32 timestamp, guint32 duration, gint32 now);

View file

@ -2999,7 +2999,7 @@ _infiniband_add_add_or_delete(NMPlatform *self,
if (parent_link->type != NM_LINK_TYPE_INFINIBAND)
return -NME_PL_WRONG_TYPE;
nmp_utils_new_infiniband_name(name, parent_link->name, p_key);
nm_net_devname_infiniband(name, parent_link->name, p_key);
if (add) {
r = _link_add_check_existing(self, name, NM_LINK_TYPE_INFINIBAND, out_link);