summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2022-09-02 09:43:15 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2022-09-05 09:40:08 +0200
commite4aefbc5561375bf89a09c051a9c48a16855d234 (patch)
tree39fc201cf42473d93c934a54c23ecb4f81a88ffd /src
parenta7eb77260ae6cfc56313e99f6178daa0b8283226 (diff)
downloadNetworkManager-e4aefbc5561375bf89a09c051a9c48a16855d234.tar.gz
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: 156d84217ced ("dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin")
Diffstat (limited to 'src')
-rw-r--r--src/core/dhcp/nm-dhcp-client.c47
-rw-r--r--src/core/dhcp/nm-dhcp-helper.c19
2 files changed, 33 insertions, 33 deletions
diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c
index 9ca8f77684..68246280e3 100644
--- a/src/core/dhcp/nm-dhcp-client.c
+++ b/src/core/dhcp/nm-dhcp-client.c
@@ -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))
- return TRUE;
-
- if (!priv->v4.bound.invocation)
+ if (!priv->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 (IS_IPv4 && priv->v4.bound.invocation)
- g_dbus_method_invocation_return_value(g_steal_pointer(&priv->v4.bound.invocation), NULL);
+ if (priv->invocation)
+ g_dbus_method_invocation_return_value(g_steal_pointer(&priv->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,
diff --git a/src/core/dhcp/nm-dhcp-helper.c b/src/core/dhcp/nm-dhcp-helper.c
index 5a17f4e8ab..78db617c6a 100644
--- a/src/core/dhcp/nm-dhcp-helper.c
+++ b/src/core/dhcp/nm-dhcp-helper.c
@@ -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);
}