device: accept lease only after addresses are configured

In the accept() callback, the nettools client creates a UDP socket
with the received address as source, so the address must be already
configured on the interface.

Also, handle errors returned by nm_dhcp_client_accept().

Fixes: 401fee7c20 ('dhcp: support notifying the client of the result of DAD')
This commit is contained in:
Beniamino Galvani 2019-08-21 08:54:03 +02:00
parent 687d0dd95e
commit 8b5bf6e4d1

View file

@ -7787,8 +7787,8 @@ dhcp4_dad_cb (NMDevice *self, NMIP4Config **configs, gboolean success)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
if (success) {
nm_dhcp_client_accept (priv->dhcp4.client, NULL);
nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (configs[1]));
nm_device_activate_schedule_ip_config_result (self, AF_INET,
NM_IP_CONFIG_CAST (configs[1]));
} else {
nm_dhcp_client_decline (priv->dhcp4.client, "Address conflict detected", NULL);
nm_device_ip_method_failed (self, AF_INET,
@ -10774,6 +10774,18 @@ activate_stage5_ip_config_result_4 (NMDevice *self)
}
}
if (priv->dhcp4.client) {
gs_free_error GError *error = NULL;
if (!nm_dhcp_client_accept (priv->dhcp4.client, &error)) {
_LOGW (LOGD_DHCP4,
"Activation: Stage 5 of 5 (IPv4 Commit) error accepting lease: %s",
error->message);
nm_device_ip_method_failed (self, AF_INET, NM_DEVICE_STATE_REASON_DHCP_ERROR);
return;
}
}
/* If IPv4 wasn't the first to complete, and DHCP was used, then ensure
* dispatcher scripts get the DHCP lease information.
*/