mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 14:18:12 +02:00
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") (cherry picked from commite4aefbc556)
This commit is contained in:
parent
b671c36189
commit
324838bee1
2 changed files with 33 additions and 33 deletions
|
|
@ -115,9 +115,6 @@ typedef struct _NMDhcpClientPrivate {
|
||||||
in_addr_t addr;
|
in_addr_t addr;
|
||||||
NMOptionBool state;
|
NMOptionBool state;
|
||||||
} acd;
|
} acd;
|
||||||
struct {
|
|
||||||
GDBusMethodInvocation *invocation;
|
|
||||||
} bound;
|
|
||||||
} v4;
|
} v4;
|
||||||
struct {
|
struct {
|
||||||
GSource *lladdr_timeout_source;
|
GSource *lladdr_timeout_source;
|
||||||
|
|
@ -125,6 +122,8 @@ typedef struct _NMDhcpClientPrivate {
|
||||||
} v6;
|
} v6;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GDBusMethodInvocation *invocation;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
gulong id;
|
gulong id;
|
||||||
bool wait_dhcp_commit : 1;
|
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);
|
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
|
||||||
|
|
||||||
if (!NM_IS_IPv4(priv->config.addr_family))
|
if (!priv->invocation)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (!priv->v4.bound.invocation)
|
g_dbus_method_invocation_return_value(g_steal_pointer(&priv->invocation), NULL);
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
g_dbus_method_invocation_return_value(g_steal_pointer(&priv->v4.bound.invocation), NULL);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -939,20 +935,17 @@ decline(NMDhcpClient *self, const NML3ConfigData *l3cd, const char *error_messag
|
||||||
{
|
{
|
||||||
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
|
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) {
|
|
||||||
nm_utils_error_set(error,
|
nm_utils_error_set(error,
|
||||||
NM_UTILS_ERROR_UNKNOWN,
|
NM_UTILS_ERROR_UNKNOWN,
|
||||||
"calling decline in unexpected script state");
|
"calling decline in unexpected script state");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
g_dbus_method_invocation_return_error(g_steal_pointer(&priv->invocation),
|
||||||
g_dbus_method_invocation_return_error(g_steal_pointer(&priv->v4.bound.invocation),
|
|
||||||
NM_DEVICE_ERROR,
|
NM_DEVICE_ERROR,
|
||||||
NM_DEVICE_ERROR_FAILED,
|
NM_DEVICE_ERROR_FAILED,
|
||||||
"acd failed");
|
NM_IS_IPv4(priv->config.addr_family) ? "ACD failed"
|
||||||
|
: "DAD failed");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1424,8 +1417,8 @@ nm_dhcp_client_stop(NMDhcpClient *self, gboolean release)
|
||||||
|
|
||||||
priv->is_stopped = TRUE;
|
priv->is_stopped = TRUE;
|
||||||
|
|
||||||
if (NM_IS_IPv4(priv->config.addr_family) && priv->v4.bound.invocation) {
|
if (priv->invocation) {
|
||||||
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,
|
||||||
NM_DEVICE_ERROR_FAILED,
|
NM_DEVICE_ERROR_FAILED,
|
||||||
"dhcp stopping");
|
"dhcp stopping");
|
||||||
|
|
@ -1584,7 +1577,6 @@ nm_dhcp_client_handle_event(gpointer unused,
|
||||||
NMPlatformIP6Address prefix = {
|
NMPlatformIP6Address prefix = {
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
int IS_IPv4;
|
|
||||||
|
|
||||||
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
|
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
|
||||||
g_return_val_if_fail(iface != NULL, 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;
|
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)
|
if (NM_IN_SET(client_event_type,
|
||||||
g_dbus_method_invocation_return_value(g_steal_pointer(&priv->v4.bound.invocation), NULL);
|
NM_DHCP_CLIENT_EVENT_TYPE_BOUND,
|
||||||
|
NM_DHCP_CLIENT_EVENT_TYPE_EXTENDED))
|
||||||
if (IS_IPv4
|
priv->invocation = g_steal_pointer(&invocation);
|
||||||
&& 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);
|
|
||||||
|
|
||||||
_nm_dhcp_client_notify(self, client_event_type, l3cd);
|
_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. */
|
* explicitly initialize the respective union member. */
|
||||||
if (NM_IS_IPv4(priv->config.addr_family)) {
|
if (NM_IS_IPv4(priv->config.addr_family)) {
|
||||||
priv->v4 = (typeof(priv->v4)){
|
priv->v4 = (typeof(priv->v4)){
|
||||||
.bound =
|
|
||||||
{
|
|
||||||
.invocation = NULL,
|
|
||||||
},
|
|
||||||
.acd =
|
.acd =
|
||||||
{
|
{
|
||||||
.addr = INADDR_ANY,
|
.addr = INADDR_ANY,
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,8 @@ main(int argc, char *argv[])
|
||||||
gint64 time_start;
|
gint64 time_start;
|
||||||
gint64 time_end;
|
gint64 time_end;
|
||||||
gint64 remaining_time;
|
gint64 remaining_time;
|
||||||
|
gboolean IS_IPv4;
|
||||||
|
const char *reason;
|
||||||
|
|
||||||
/* Connecting to the unix socket can fail with EAGAIN if there are too
|
/* 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
|
* 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);
|
time_end = time_start + (5000 * 1000L);
|
||||||
try_count = 0;
|
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:
|
do_connect:
|
||||||
try_count++;
|
try_count++;
|
||||||
|
|
@ -244,5 +258,6 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOGi("success: %s", success ? "YES" : "NO");
|
_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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue