diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2019-07-04 11:14:35 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2019-07-05 11:06:01 +0200 |
commit | 1609f508666985c84713a93d987bada59aa646ff (patch) | |
tree | e9a9618b1f1b90e3248db6ba0902e219c34ec9be | |
parent | 36348c7dc5354ccb648b058cd8aa9c03a98dd375 (diff) | |
download | NetworkManager-1609f508666985c84713a93d987bada59aa646ff.tar.gz |
core: drop nm_platform_link_get_address_as_bytes()
Drop nm_platform_link_get_address_as_bytes() and introduce
nmp_link_address_get_as_bytes() so that it becomes possible to obtain
also the broadcast address without an additional lookup of the link.
-rw-r--r-- | src/devices/nm-device.c | 12 | ||||
-rw-r--r-- | src/nm-iface-helper.c | 5 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 13 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 13 |
4 files changed, 26 insertions, 17 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index e649d267fe..f707919478 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7969,6 +7969,7 @@ dhcp4_start (NMDevice *self) gs_unref_bytes GBytes *client_id = NULL; NMConnection *connection; GError *error = NULL; + const NMPlatformLink *pllink; connection = nm_device_get_applied_connection (self); g_return_val_if_fail (connection, FALSE); @@ -7979,8 +7980,9 @@ dhcp4_start (NMDevice *self) nm_dbus_object_clear_and_unexport (&priv->dhcp4.config); priv->dhcp4.config = nm_dhcp4_config_new (); - hwaddr = nm_platform_link_get_address_as_bytes (nm_device_get_platform (self), - nm_device_get_ip_ifindex (self)); + pllink = nm_platform_link_get (nm_device_get_platform (self), nm_device_get_ip_ifindex (self)); + if (pllink) + hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address); client_id = dhcp4_get_client_id (self, connection, hwaddr); @@ -8769,6 +8771,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection) gs_unref_bytes GBytes *hwaddr = NULL; gs_unref_bytes GBytes *duid = NULL; gboolean enforce_duid = FALSE; + const NMPlatformLink *pllink; GError *error = NULL; const NMPlatformIP6Address *ll_addr = NULL; @@ -8788,8 +8791,9 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection) return FALSE; } - hwaddr = nm_platform_link_get_address_as_bytes (nm_device_get_platform (self), - nm_device_get_ip_ifindex (self)); + pllink = nm_platform_link_get (nm_device_get_platform (self), nm_device_get_ip_ifindex (self)); + if (pllink) + hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address); duid = dhcp6_get_duid (self, connection, hwaddr, &enforce_duid); priv->dhcp6.client = nm_dhcp_manager_start_ip6 (nm_dhcp_manager_get (), diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index adf64c7515..c8f7d5ccc7 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -383,6 +383,7 @@ main (int argc, char *argv[]) gs_unref_bytes GBytes *hwaddr = NULL; gs_unref_bytes GBytes *client_id = NULL; gs_free NMUtilsIPv6IfaceId *iid = NULL; + const NMPlatformLink *pllink; guint sd_id; int errsv; @@ -469,7 +470,9 @@ main (int argc, char *argv[]) /* Set up platform interaction layer */ nm_linux_platform_setup (); - hwaddr = nm_platform_link_get_address_as_bytes (NM_PLATFORM_GET, gl.ifindex); + pllink = nm_platform_link_get (NM_PLATFORM_GET, gl.ifindex); + if (pllink) + hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address); if (global_opt.iid_str) { GBytes *bytes; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 2ed46fe444..6ead15ed35 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -100,6 +100,19 @@ nmp_link_address_get (const NMPLinkAddress *addr, size_t *length) return addr->data; } +GBytes * +nmp_link_address_get_as_bytes (const NMPLinkAddress *addr) +{ + gconstpointer data; + size_t length; + + data = nmp_link_address_get (addr, &length); + + return length > 0 + ? g_bytes_new (data, length) + : NULL; +} + /*****************************************************************************/ #define _NMLOG_DOMAIN LOGD_PLATFORM diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 1e6007e1f1..248eca44f9 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -164,6 +164,7 @@ typedef struct { } NMPLinkAddress; gconstpointer nmp_link_address_get (const NMPLinkAddress *addr, size_t *length); +GBytes *nmp_link_address_get_as_bytes (const NMPLinkAddress *addr); typedef enum { @@ -1407,18 +1408,6 @@ gboolean nm_platform_link_get_user_ipv6ll_enabled (NMPlatform *self, int ifindex gconstpointer nm_platform_link_get_address (NMPlatform *self, int ifindex, size_t *length); -static inline GBytes * -nm_platform_link_get_address_as_bytes (NMPlatform *self, int ifindex) -{ - gconstpointer p; - gsize l; - - p = nm_platform_link_get_address (self, ifindex, &l); - return p - ? g_bytes_new (p, l) - : NULL; -} - int nm_platform_link_get_master (NMPlatform *self, int slave); gboolean nm_platform_link_can_assume (NMPlatform *self, int ifindex); |