summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-05-05 21:18:00 +0200
committerThomas Haller <thaller@redhat.com>2022-05-16 16:37:40 +0200
commitf102051a29836c3dc5b876e591b31f21a79cfa81 (patch)
tree0f92d1bbea1eb75f6edaa67ba2aa5fc208fb2f24
parent70cbf3dc1ef2c068410574b8c4e791edba45cb70 (diff)
dhcp: drop most of NMDhcpState usage from nm_dhcp_client_handle_event()
NMDhcpState is very tied to events from dhclient. But most of these states we don't care about, and NMDhcpClient definitely should abstract and hide them. We should repurpose NMDhcpState to simpler state. For that, first drop the state from nm_dhcp_client_handle_event(). This is only the first step (which arguably makes the code more complicated, because reason_to_state() gets spread out and the logic happens more than once). That will be addressed next.
-rw-r--r--src/core/dhcp/nm-dhcp-client.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c
index ebdf25b388..7875a04adf 100644
--- a/src/core/dhcp/nm-dhcp-client.c
+++ b/src/core/dhcp/nm-dhcp-client.c
@@ -49,7 +49,6 @@ typedef struct _NMDhcpClientPrivate {
GSource *watch_source;
GBytes *effective_client_id;
pid_t pid;
- NMDhcpState state;
bool iaid_explicit : 1;
bool is_stopped : 1;
struct {
@@ -88,27 +87,6 @@ NM_UTILS_LOOKUP_STR_DEFINE(nm_dhcp_state_to_string,
NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_TIMEOUT, "timeout"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_UNKNOWN, "unknown"), );
-static NMDhcpState
-reason_to_state(const char *reason)
-{
- if (NM_IN_STRSET_ASCII_CASE(reason, "bound", "bound6", "static"))
- return NM_DHCP_STATE_BOUND;
- if (NM_IN_STRSET_ASCII_CASE(reason, "renew", "renew6", "reboot", "rebind", "rebind6"))
- return NM_DHCP_STATE_EXTENDED;
- if (NM_IN_STRSET_ASCII_CASE(reason, "timeout"))
- return NM_DHCP_STATE_TIMEOUT;
- if (NM_IN_STRSET_ASCII_CASE(reason, "nak", "expire", "expire6"))
- return NM_DHCP_STATE_EXPIRE;
- if (NM_IN_STRSET_ASCII_CASE(reason, "end", "stop", "stopped"))
- return NM_DHCP_STATE_DONE;
- if (NM_IN_STRSET_ASCII_CASE(reason, "fail", "abend"))
- return NM_DHCP_STATE_FAIL;
- if (NM_IN_STRSET_ASCII_CASE(reason, "preinit"))
- return NM_DHCP_STATE_NOOP;
-
- return NM_DHCP_STATE_UNKNOWN;
-}
-
/*****************************************************************************/
static void
@@ -891,11 +869,12 @@ nm_dhcp_client_handle_event(gpointer unused,
NMDhcpClient *self)
{
NMDhcpClientPrivate *priv;
- guint32 new_state;
- nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
+ NMDhcpState new_state;
NMPlatformIP6Address prefix = {
0,
};
+ gboolean reason_is_bound;
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
g_return_val_if_fail(iface != NULL, FALSE);
@@ -910,21 +889,22 @@ nm_dhcp_client_handle_event(gpointer unused,
if (priv->pid != pid)
return FALSE;
- new_state = reason_to_state(reason);
-
- if (new_state == NM_DHCP_STATE_UNKNOWN)
- _LOGD("unmapped DHCP state '%s'", reason);
+ _LOGD("DHCP event (reason: '%s')", reason);
- if (new_state == NM_DHCP_STATE_NOOP)
+ if (NM_IN_STRSET_ASCII_CASE(reason, "preinit"))
return TRUE;
- _LOGD("DHCP state '%s' -> '%s' (reason: '%s')",
- nm_dhcp_state_to_string(priv->state),
- nm_dhcp_state_to_string(new_state),
- reason);
- priv->state = new_state;
-
- if (NM_IN_SET(new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)) {
+ reason_is_bound = NM_IN_STRSET_ASCII_CASE(reason,
+ "bound",
+ "bound6",
+ "static",
+ "renew",
+ "renew6",
+ "reboot",
+ "rebind",
+ "rebind6");
+
+ if (reason_is_bound) {
gs_unref_hashtable GHashTable *str_options = NULL;
GVariantIter iter;
const char *name;
@@ -974,9 +954,26 @@ nm_dhcp_client_handle_event(gpointer unused,
}
/* Fail if no valid IP config was received */
- if (NM_IN_SET(new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED) && !l3cd) {
+ if (reason_is_bound && !l3cd) {
_LOGW("client bound but IP config not received");
new_state = NM_DHCP_STATE_FAIL;
+ } else {
+ if (NM_IN_STRSET_ASCII_CASE(reason, "bound", "bound6", "static"))
+ new_state = NM_DHCP_STATE_BOUND;
+ else if (NM_IN_STRSET_ASCII_CASE(reason, "renew", "renew6", "reboot", "rebind", "rebind6"))
+ new_state = NM_DHCP_STATE_EXTENDED;
+ else if (NM_IN_STRSET_ASCII_CASE(reason, "timeout"))
+ new_state = NM_DHCP_STATE_TIMEOUT;
+ else if (NM_IN_STRSET_ASCII_CASE(reason, "nak", "expire", "expire6"))
+ new_state = NM_DHCP_STATE_EXPIRE;
+ else if (NM_IN_STRSET_ASCII_CASE(reason, "end", "stop", "stopped"))
+ new_state = NM_DHCP_STATE_DONE;
+ else if (NM_IN_STRSET_ASCII_CASE(reason, "fail", "abend"))
+ new_state = NM_DHCP_STATE_FAIL;
+ else if (NM_IN_STRSET_ASCII_CASE(reason, "preinit"))
+ new_state = NM_DHCP_STATE_NOOP;
+ else
+ new_state = NM_DHCP_STATE_UNKNOWN;
}
nm_dhcp_client_set_state(self, new_state, l3cd);