From 1605fa460d3e839f114305b52c699d5852944137 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Wed, 11 Aug 2021 08:33:08 -0400 Subject: [PATCH] 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 --- src/core/devices/nm-device.c | 12 +++++++----- src/libnm-platform/nm-linux-platform.c | 11 +++++++++-- src/libnm-platform/nm-platform.c | 11 +++++------ src/libnm-platform/nm-platform.h | 9 ++++----- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 46fd75b60e..fb40f05d67 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -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; } diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index f2f4223717..3cf8ba87b7 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -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 diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index bb51924379..a010566ceb 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -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; } diff --git a/src/libnm-platform/nm-platform.h b/src/libnm-platform/nm-platform.h index e5e2f45d20..6ff6b91118 100644 --- a/src/libnm-platform/nm-platform.h +++ b/src/libnm-platform/nm-platform.h @@ -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);