dhcp: support notifying the client of the result of DAD

The DHCP client is not meant to use the assigned address before DAD
has completed successfully, if enabled. And if DAD fails, the server
should be notified with a DECLINE, in order to potentially blacklist
the address.

Currently, none of the clients support this, but add the required
callbacks, and allow clients to opt in if they want.
This commit is contained in:
Tom Gundersen 2019-05-21 21:52:44 +02:00 committed by Beniamino Galvani
parent be8f7b5a5d
commit 401fee7c20
3 changed files with 50 additions and 2 deletions

View file

@ -7694,9 +7694,13 @@ clear_config:
static void
dhcp4_dad_cb (NMDevice *self, NMIP4Config **configs, gboolean success)
{
if (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]));
else {
} else {
nm_dhcp_client_decline (priv->dhcp4.client, "Address conflict detected", NULL);
nm_device_ip_method_failed (self, AF_INET,
NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE);
}

View file

@ -530,6 +530,36 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self,
error);
}
gboolean
nm_dhcp_client_accept (NMDhcpClient *self,
GError **error)
{
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE);
if (NM_DHCP_CLIENT_GET_CLASS (self)->accept) {
return NM_DHCP_CLIENT_GET_CLASS (self)->accept (self,
error);
}
return TRUE;
}
gboolean
nm_dhcp_client_decline (NMDhcpClient *self,
const char *error_message,
GError **error)
{
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE);
if (NM_DHCP_CLIENT_GET_CLASS (self)->decline) {
return NM_DHCP_CLIENT_GET_CLASS (self)->decline (self,
error_message,
error);
}
return TRUE;
}
static GBytes *
get_duid (NMDhcpClient *self)
{

View file

@ -82,6 +82,13 @@ typedef struct {
const char *last_ip4_address,
GError **error);
gboolean (*accept) (NMDhcpClient *self,
GError **error);
gboolean (*decline) (NMDhcpClient *self,
const char *error_message,
GError **error);
gboolean (*ip6_start) (NMDhcpClient *self,
const char *anycast_addr,
const struct in6_addr *ll_addr,
@ -155,6 +162,13 @@ gboolean nm_dhcp_client_start_ip6 (NMDhcpClient *self,
guint needed_prefixes,
GError **error);
gboolean nm_dhcp_client_accept (NMDhcpClient *self,
GError **error);
gboolean nm_dhcp_client_decline (NMDhcpClient *self,
const char *error_message,
GError **error);
void nm_dhcp_client_stop (NMDhcpClient *self, gboolean release);
/* Backend helpers for subclasses */