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.
This commit is contained in:
Beniamino Galvani
2019-07-04 11:14:35 +02:00
parent 36348c7dc5
commit 1609f50866
4 changed files with 26 additions and 17 deletions

View File

@@ -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 (),

View File

@@ -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;

View File

@@ -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

View File

@@ -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);