diff options
Diffstat (limited to 'src/dhcp/nm-dhcp-systemd.c')
| -rw-r--r-- | src/dhcp/nm-dhcp-systemd.c | 115 |
1 files changed, 46 insertions, 69 deletions
diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index f79b7cb1..4f37f069 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -29,6 +29,7 @@ #include <net/if_arp.h> #include "nm-utils/nm-dedup-multi.h" +#include "nm-utils/unaligned.h" #include "nm-utils.h" #include "nm-dhcp-utils.h" @@ -60,8 +61,7 @@ typedef struct { guint request_count; - gboolean privacy; - gboolean info_only; + bool privacy:1; } NMDhcpSystemdPrivate; struct _NMDhcpSystemd { @@ -451,36 +451,6 @@ get_leasefile_path (int addr_family, const char *iface, const char *uuid) iface); } -static GSList * -nm_dhcp_systemd_get_lease_ip_configs (NMDedupMultiIndex *multi_idx, - int addr_family, - const char *iface, - int ifindex, - const char *uuid, - guint32 route_table, - guint32 route_metric) -{ - GSList *leases = NULL; - gs_free char *path = NULL; - sd_dhcp_lease *lease = NULL; - NMIP4Config *ip4_config; - int r; - - if (addr_family != AF_INET) - return NULL; - - path = get_leasefile_path (addr_family, iface, uuid); - r = dhcp_lease_load (&lease, path); - if (r == 0 && lease) { - ip4_config = lease_to_ip4_config (multi_idx, iface, ifindex, lease, NULL, route_table, route_metric, FALSE, NULL); - if (ip4_config) - leases = g_slist_append (leases, ip4_config); - sd_dhcp_lease_unref (lease); - } - - return leases; -} - /*****************************************************************************/ static void @@ -584,14 +554,16 @@ dhcp_event_cb (sd_dhcp_client *client, int event, gpointer user_data) } static guint16 -get_arp_type (const GByteArray *hwaddr) +get_arp_type (GBytes *hwaddr) { - if (hwaddr->len == ETH_ALEN) + switch (g_bytes_get_size (hwaddr)) { + case ETH_ALEN: return ARPHRD_ETHER; - else if (hwaddr->len == INFINIBAND_ALEN) + case INFINIBAND_ALEN: return ARPHRD_INFINIBAND; - else + default: return ARPHRD_NONE; + } } static gboolean @@ -600,7 +572,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last NMDhcpSystemd *self = NM_DHCP_SYSTEMD (client); NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self); const char *iface = nm_dhcp_client_get_iface (client); - const GByteArray *hwaddr; + GBytes *hwaddr; sd_dhcp_lease *lease = NULL; GBytes *override_client_id; const uint8_t *client_id = NULL; @@ -609,7 +581,6 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last const char *hostname; int r, i; gboolean success = FALSE; - guint16 arp_type; g_assert (priv->client4 == NULL); g_assert (priv->client6 == NULL); @@ -633,16 +604,14 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last hwaddr = nm_dhcp_client_get_hw_addr (client); if (hwaddr) { - arp_type= get_arp_type (hwaddr); - if (arp_type == ARPHRD_NONE) { - _LOGW ("failed to determine ARP type"); - goto error; - } + const uint8_t *data; + gsize len; + data = g_bytes_get_data (hwaddr, &len); r = sd_dhcp_client_set_mac (priv->client4, - hwaddr->data, - hwaddr->len, - arp_type); + data, + len, + get_arp_type (hwaddr)); if (r < 0) { _LOGW ("failed to set MAC address (%d)", r); goto error; @@ -661,12 +630,6 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last goto error; } - r = sd_dhcp_client_set_request_broadcast (priv->client4, true); - if (r < 0) { - _LOGW ("failed to enable broadcast mode (%d)", r); - goto error; - } - dhcp_lease_load (&lease, priv->lease_file); if (last_ip4_address) @@ -854,7 +817,7 @@ bound6_handle (NMDhcpSystemd *self) lease, options, TRUE, - priv->info_only, + nm_dhcp_client_get_info_only (NM_DHCP_CLIENT (self)), &error); if (ip6_config) { @@ -900,24 +863,29 @@ static gboolean ip6_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const struct in6_addr *ll_addr, - gboolean info_only, NMSettingIP6ConfigPrivacy privacy, - const GByteArray *duid, + GBytes *duid, guint needed_prefixes) { NMDhcpSystemd *self = NM_DHCP_SYSTEMD (client); NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self); const char *iface = nm_dhcp_client_get_iface (client); - const GByteArray *hwaddr; + GBytes *hwaddr; + const char *hostname; int r, i; + const guint8 *duid_arr; + gsize duid_len; g_assert (priv->client4 == NULL); g_assert (priv->client6 == NULL); g_return_val_if_fail (duid != NULL, FALSE); + duid_arr = g_bytes_get_data (duid, &duid_len); + if (!duid_arr || duid_len < 2) + g_return_val_if_reached (FALSE); + g_free (priv->lease_file); priv->lease_file = get_leasefile_path (AF_INET6, iface, nm_dhcp_client_get_uuid (client)); - priv->info_only = info_only; r = sd_dhcp6_client_new (&priv->client6); if (r < 0) { @@ -932,16 +900,13 @@ ip6_start (NMDhcpClient *client, _LOGT ("dhcp-client6: set %p", priv->client6); - if (info_only) - sd_dhcp6_client_set_information_request (priv->client6, 1); + if (nm_dhcp_client_get_info_only (client)) + sd_dhcp6_client_set_information_request (priv->client6, 1); - /* NM stores the entire DUID which includes the uint16 "type", while systemd - * wants the type passed separately from the following data. - */ r = sd_dhcp6_client_set_duid (priv->client6, - ntohs (((const guint16 *) duid->data)[0]), - duid->data + 2, - duid->len - 2); + unaligned_read_be16 (&duid_arr[0]), + &duid_arr[2], + duid_len - 2); if (r < 0) { _LOGW ("failed to set DUID (%d)", r); return FALSE; @@ -955,9 +920,13 @@ ip6_start (NMDhcpClient *client, hwaddr = nm_dhcp_client_get_hw_addr (client); if (hwaddr) { + const uint8_t *data; + gsize len; + + data = g_bytes_get_data (hwaddr, &len); r = sd_dhcp6_client_set_mac (priv->client6, - hwaddr->data, - hwaddr->len, + data, + len, get_arp_type (hwaddr)); if (r < 0) { _LOGW ("failed to set MAC address (%d)", r); @@ -989,6 +958,13 @@ ip6_start (NMDhcpClient *client, goto error; } + hostname = nm_dhcp_client_get_hostname (client); + r = sd_dhcp6_client_set_fqdn (priv->client6, hostname); + if (r < 0) { + _LOGW ("failed to set DHCP hostname to '%s' (%d)", hostname, r); + goto error; + } + r = sd_dhcp6_client_start (priv->client6); if (r < 0) { _LOGW ("failed to start client (%d)", r); @@ -1006,12 +982,14 @@ error: } static void -stop (NMDhcpClient *client, gboolean release, const GByteArray *duid) +stop (NMDhcpClient *client, gboolean release, GBytes *duid) { NMDhcpSystemd *self = NM_DHCP_SYSTEMD (client); NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self); int r = 0; + NM_DHCP_CLIENT_CLASS (nm_dhcp_systemd_parent_class)->stop (client, release, duid); + _LOGT ("dhcp-client%d: stop %p", priv->client4 ? '4' : '6', priv->client4 ? (gpointer) priv->client4 : (gpointer) priv->client6); @@ -1074,5 +1052,4 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_internal = { .name = "internal", .get_type = nm_dhcp_systemd_get_type, .get_path = NULL, - .get_lease_ip_configs = nm_dhcp_systemd_get_lease_ip_configs, }; |