platform: update nm_platform_link_get_permanent_address() to accept NMPLinkAddress argument

Replace the arguments "buf+length" of
`nm_platform_link_get_permanent_address()` with "NMPLinkAddress *out_addr"

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2021-08-11 08:33:08 -04:00 committed by Thomas Haller
parent 585257509f
commit 1605fa460d
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
4 changed files with 25 additions and 18 deletions

View file

@ -17089,11 +17089,11 @@ nm_device_update_permanent_hw_address(NMDevice *self, gboolean force_freeze)
{
NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self);
guint8 buf[_NM_UTILS_HWADDR_LEN_MAX];
size_t len = 0;
gboolean success_read;
int ifindex;
const NMPlatformLink * pllink;
const NMConfigDeviceStateData *dev_state;
NMPLinkAddress cached_hw_addr_perm;
if (priv->hw_addr_perm) {
/* the permanent hardware address is only read once and not
@ -17132,11 +17132,13 @@ nm_device_update_permanent_hw_address(NMDevice *self, gboolean force_freeze)
return;
}
success_read =
nm_platform_link_get_permanent_address(nm_device_get_platform(self), ifindex, buf, &len);
if (success_read && priv->hw_addr_len == len) {
success_read = nm_platform_link_get_permanent_address(nm_device_get_platform(self),
ifindex,
&cached_hw_addr_perm);
if (success_read && priv->hw_addr_len == cached_hw_addr_perm.len) {
priv->hw_addr_perm_fake = FALSE;
priv->hw_addr_perm = nm_utils_hwaddr_ntoa(buf, len);
priv->hw_addr_perm =
nm_utils_hwaddr_ntoa(cached_hw_addr_perm.data, cached_hw_addr_perm.len);
_LOGD(LOGD_DEVICE, "hw-addr: read permanent MAC address '%s'", priv->hw_addr_perm);
goto notify_and_out;
}

View file

@ -7636,14 +7636,21 @@ nla_put_failure:
}
static gboolean
link_get_permanent_address(NMPlatform *platform, int ifindex, guint8 *buf, size_t *length)
link_get_permanent_address(NMPlatform *platform, int ifindex, NMPLinkAddress *out_address)
{
nm_auto_pop_netns NMPNetns *netns = NULL;
guint8 buffer[_NM_UTILS_HWADDR_LEN_MAX];
gsize len;
if (!nm_platform_netns_push(platform, &netns))
return FALSE;
return nmp_utils_ethtool_get_permanent_address(ifindex, buf, length);
if (!nmp_utils_ethtool_get_permanent_address(ifindex, buffer, &len))
return FALSE;
nm_assert(len <= _NM_UTILS_HWADDR_LEN_MAX);
memcpy(out_address->data, buffer, len);
out_address->len = len;
return TRUE;
}
static int

View file

@ -1748,19 +1748,18 @@ nm_platform_link_get_address(NMPlatform *self, int ifindex, size_t *length)
* address.
*/
gboolean
nm_platform_link_get_permanent_address(NMPlatform *self, int ifindex, guint8 *buf, size_t *length)
nm_platform_link_get_permanent_address(NMPlatform *self, int ifindex, NMPLinkAddress *out_address)
{
_CHECK_SELF(self, klass, FALSE);
if (length)
*length = 0;
if (out_address)
out_address->len = 0;
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(buf, FALSE);
g_return_val_if_fail(length, FALSE);
g_return_val_if_fail(out_address, FALSE);
if (klass->link_get_permanent_address)
return klass->link_get_permanent_address(self, ifindex, buf, length);
return klass->link_get_permanent_address(self, ifindex, out_address);
return FALSE;
}

View file

@ -1111,10 +1111,9 @@ typedef struct {
int (*link_set_user_ipv6ll_enabled)(NMPlatform *self, int ifindex, gboolean enabled);
gboolean (*link_set_token)(NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId iid);
gboolean (*link_get_permanent_address)(NMPlatform *self,
int ifindex,
guint8 * buf,
size_t * length);
gboolean (*link_get_permanent_address)(NMPlatform * self,
int ifindex,
NMPLinkAddress *out_address);
int (*link_set_address)(NMPlatform *self, int ifindex, gconstpointer address, size_t length);
int (*link_set_mtu)(NMPlatform *self, int ifindex, guint32 mtu);
gboolean (*link_set_name)(NMPlatform *self, int ifindex, const char *name);
@ -1865,7 +1864,7 @@ int nm_platform_link_set_user_ipv6ll_enabled(NMPlatform *self, int ifindex,
gboolean nm_platform_link_set_ipv6_token(NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId iid);
gboolean
nm_platform_link_get_permanent_address(NMPlatform *self, int ifindex, guint8 *buf, size_t *length);
nm_platform_link_get_permanent_address(NMPlatform *self, int ifindex, NMPLinkAddress *out_address);
int nm_platform_link_set_address(NMPlatform *self, int ifindex, const void *address, size_t length);
int nm_platform_link_set_mtu(NMPlatform *self, int ifindex, guint32 mtu);
gboolean nm_platform_link_set_name(NMPlatform *self, int ifindex, const char *name);