dhcp: implement decline on IPv6 DAD failure with dhclient

The dhclient plugin already supports sending a decline when IPv4 ACD
fails. Also implement support for IPv6 DAD.

See-also: 156d84217c ("dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin")
This commit is contained in:
Beniamino Galvani 2022-09-02 09:43:15 +02:00
parent a7eb77260a
commit e4aefbc556
2 changed files with 33 additions and 33 deletions

View file

@ -115,9 +115,6 @@ typedef struct _NMDhcpClientPrivate {
in_addr_t addr;
NMOptionBool state;
} acd;
struct {
GDBusMethodInvocation *invocation;
} bound;
} v4;
struct {
GSource *lladdr_timeout_source;
@ -125,6 +122,8 @@ typedef struct _NMDhcpClientPrivate {
} v6;
};
GDBusMethodInvocation *invocation;
struct {
gulong id;
bool wait_dhcp_commit : 1;
@ -909,13 +908,10 @@ _accept(NMDhcpClient *self, const NML3ConfigData *l3cd, GError **error)
{
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
if (!NM_IS_IPv4(priv->config.addr_family))
if (!priv->invocation)
return TRUE;
if (!priv->v4.bound.invocation)
return TRUE;
g_dbus_method_invocation_return_value(g_steal_pointer(&priv->v4.bound.invocation), NULL);
g_dbus_method_invocation_return_value(g_steal_pointer(&priv->invocation), NULL);
return TRUE;
}
@ -939,20 +935,17 @@ decline(NMDhcpClient *self, const NML3ConfigData *l3cd, const char *error_messag
{
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
if (!NM_IS_IPv4(priv->config.addr_family))
return TRUE;
if (!priv->v4.bound.invocation) {
if (!priv->invocation) {
nm_utils_error_set(error,
NM_UTILS_ERROR_UNKNOWN,
"calling decline in unexpected script state");
return FALSE;
}
g_dbus_method_invocation_return_error(g_steal_pointer(&priv->v4.bound.invocation),
g_dbus_method_invocation_return_error(g_steal_pointer(&priv->invocation),
NM_DEVICE_ERROR,
NM_DEVICE_ERROR_FAILED,
"acd failed");
NM_IS_IPv4(priv->config.addr_family) ? "ACD failed"
: "DAD failed");
return TRUE;
}
@ -1424,8 +1417,8 @@ nm_dhcp_client_stop(NMDhcpClient *self, gboolean release)
priv->is_stopped = TRUE;
if (NM_IS_IPv4(priv->config.addr_family) && priv->v4.bound.invocation) {
g_dbus_method_invocation_return_error(g_steal_pointer(&priv->v4.bound.invocation),
if (priv->invocation) {
g_dbus_method_invocation_return_error(g_steal_pointer(&priv->invocation),
NM_DEVICE_ERROR,
NM_DEVICE_ERROR_FAILED,
"dhcp stopping");
@ -1584,7 +1577,6 @@ nm_dhcp_client_handle_event(gpointer unused,
NMPlatformIP6Address prefix = {
0,
};
int IS_IPv4;
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
g_return_val_if_fail(iface != NULL, FALSE);
@ -1681,16 +1673,13 @@ nm_dhcp_client_handle_event(gpointer unused,
client_event_type = NM_DHCP_CLIENT_EVENT_TYPE_FAIL;
}
IS_IPv4 = NM_IS_IPv4(priv->config.addr_family);
if (priv->invocation)
g_dbus_method_invocation_return_value(g_steal_pointer(&priv->invocation), NULL);
if (IS_IPv4 && priv->v4.bound.invocation)
g_dbus_method_invocation_return_value(g_steal_pointer(&priv->v4.bound.invocation), NULL);
if (IS_IPv4
&& NM_IN_SET(client_event_type,
NM_DHCP_CLIENT_EVENT_TYPE_BOUND,
NM_DHCP_CLIENT_EVENT_TYPE_EXTENDED))
priv->v4.bound.invocation = g_steal_pointer(&invocation);
if (NM_IN_SET(client_event_type,
NM_DHCP_CLIENT_EVENT_TYPE_BOUND,
NM_DHCP_CLIENT_EVENT_TYPE_EXTENDED))
priv->invocation = g_steal_pointer(&invocation);
_nm_dhcp_client_notify(self, client_event_type, l3cd);
@ -1841,10 +1830,6 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
* explicitly initialize the respective union member. */
if (NM_IS_IPv4(priv->config.addr_family)) {
priv->v4 = (typeof(priv->v4)){
.bound =
{
.invocation = NULL,
},
.acd =
{
.addr = INADDR_ANY,

View file

@ -114,6 +114,8 @@ main(int argc, char *argv[])
gint64 time_start;
gint64 time_end;
gint64 remaining_time;
gboolean IS_IPv4;
const char *reason;
/* Connecting to the unix socket can fail with EAGAIN if there are too
* many pending connections and the server can't accept them in time
@ -124,7 +126,19 @@ main(int argc, char *argv[])
time_end = time_start + (5000 * 1000L);
try_count = 0;
_LOGi("nm-dhcp-helper: event called");
reason = getenv("reason");
_LOGi("nm-dhcp-helper: event called: %s", reason);
IS_IPv4 = !NM_IN_STRSET(reason,
"PREINIT6",
"BOUND6",
"RENEW6",
"REBIND6",
"DEPREF6",
"EXPIRE6",
"RELEASE6",
"STOP6");
do_connect:
try_count++;
@ -244,5 +258,6 @@ out:
}
_LOGi("success: %s", success ? "YES" : "NO");
return success ? EXIT_SUCCESS : EXIT_FAILURE;
/* The error code to send a decline depends on the address family */
return success ? EXIT_SUCCESS : (IS_IPv4 ? 1 : 3);
}