int dhcp6_configure(Link *link) { sd_dhcp6_client *client = NULL; int r; assert(link); if (link->dhcp6_client) return 0; r = sd_dhcp6_client_new(&client); if (r < 0) return r; r = sd_dhcp6_client_attach_event(client, NULL, 0); if (r < 0) goto error; r = sd_dhcp6_client_set_information_request(client, true); if (r < 0) goto error; r = sd_dhcp6_client_set_mac(client, (const uint8_t *) &link->mac, sizeof (link->mac), ARPHRD_ETHER); if (r < 0) goto error; r = sd_dhcp6_client_set_iaid(client, link->network->iaid); if (r < 0) goto error; if (link->network->duid_type != _DUID_TYPE_INVALID) r = sd_dhcp6_client_set_duid(client, link->network->dhcp_duid_type, link->network->dhcp_duid, link->network->dhcp_duid_len); else r = sd_dhcp6_client_set_duid(client, link->manager->dhcp_duid_type, link->manager->dhcp_duid, link->manager->dhcp_duid_len); if (r < 0) goto error; r = sd_dhcp6_client_set_index(client, link->ifindex); if (r < 0) goto error; r = sd_dhcp6_client_set_callback(client, dhcp6_handler, link); if (r < 0) goto error; link->dhcp6_client = client; return 0; error: sd_dhcp6_client_unref(client); return r; }
int dhcp6_configure(Link *link) { sd_dhcp6_client *client = NULL; int r; const DUID *duid; assert(link); if (link->dhcp6_client) return 0; r = sd_dhcp6_client_new(&client); if (r < 0) return r; r = sd_dhcp6_client_attach_event(client, NULL, 0); if (r < 0) goto error; r = sd_dhcp6_client_set_mac(client, (const uint8_t *) &link->mac, sizeof (link->mac), ARPHRD_ETHER); if (r < 0) goto error; r = sd_dhcp6_client_set_iaid(client, link->network->iaid); if (r < 0) goto error; duid = link_duid(link); r = sd_dhcp6_client_set_duid(client, duid->type, duid->raw_data_len > 0 ? duid->raw_data : NULL, duid->raw_data_len); if (r < 0) goto error; r = dhcp6_set_hostname(client, link); if (r < 0) goto error; r = sd_dhcp6_client_set_ifindex(client, link->ifindex); if (r < 0) goto error; r = sd_dhcp6_client_set_callback(client, dhcp6_handler, link); if (r < 0) goto error; link->dhcp6_client = client; return 0; error: sd_dhcp6_client_unref(client); return r; }
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) { 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; int r, i; g_assert (priv->client4 == NULL); g_assert (priv->client6 == NULL); g_return_val_if_fail (duid != NULL, FALSE); g_free (priv->lease_file); priv->lease_file = get_leasefile_path (iface, nm_dhcp_client_get_uuid (client), TRUE); priv->info_only = info_only; r = sd_dhcp6_client_new (&priv->client6); if (r < 0) { _LOGW ("failed to create client (%d)", r); return FALSE; } _LOGT ("dhcp-client6: set %p", priv->client4); if (info_only) 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); if (r < 0) { _LOGW ("failed to set DUID (%d)", r); return FALSE; } r = sd_dhcp6_client_attach_event (priv->client6, NULL, 0); if (r < 0) { _LOGW ("failed to attach event (%d)", r); goto error; } hwaddr = nm_dhcp_client_get_hw_addr (client); if (hwaddr) { r = sd_dhcp6_client_set_mac (priv->client6, hwaddr->data, hwaddr->len, get_arp_type (hwaddr)); if (r < 0) { _LOGW ("failed to set MAC address (%d)", r); goto error; } } r = sd_dhcp6_client_set_index (priv->client6, nm_dhcp_client_get_ifindex (client)); if (r < 0) { _LOGW ("failed to set ifindex (%d)", r); goto error; } r = sd_dhcp6_client_set_callback (priv->client6, dhcp6_event_cb, client); if (r < 0) { _LOGW ("failed to set callback (%d)", r); goto error; } /* Add requested options */ for (i = 0; dhcp6_requests[i].name; i++) { if (dhcp6_requests[i].include) sd_dhcp6_client_set_request_option (priv->client6, dhcp6_requests[i].num); } r = sd_dhcp6_client_set_local_address (priv->client6, ll_addr); if (r < 0) { _LOGW ("failed to set local address (%d)", r); goto error; } r = sd_dhcp6_client_start (priv->client6); if (r < 0) { _LOGW ("failed to start client (%d)", r); goto error; } return TRUE; error: sd_dhcp6_client_unref (priv->client6); priv->client6 = NULL; return FALSE; }