summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libsystemd-network/dhcp-protocol.c18
-rw-r--r--src/libsystemd-network/dhcp-protocol.h22
-rw-r--r--src/libsystemd-network/meson.build1
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c5
4 files changed, 37 insertions, 9 deletions
diff --git a/src/libsystemd-network/dhcp-protocol.c b/src/libsystemd-network/dhcp-protocol.c
new file mode 100644
index 0000000000..955d08720d
--- /dev/null
+++ b/src/libsystemd-network/dhcp-protocol.c
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "dhcp-protocol.h"
+#include "string-table.h"
+
+static const char* const dhcp_state_table[_DHCP_STATE_MAX] = {
+ [DHCP_STATE_STOPPED] = "stopped",
+ [DHCP_STATE_INIT] = "initialization",
+ [DHCP_STATE_SELECTING] = "selecting",
+ [DHCP_STATE_INIT_REBOOT] = "init-reboot",
+ [DHCP_STATE_REBOOTING] = "rebooting",
+ [DHCP_STATE_REQUESTING] = "requesting",
+ [DHCP_STATE_BOUND] = "bound",
+ [DHCP_STATE_RENEWING] = "renewing",
+ [DHCP_STATE_REBINDING] = "rebinding",
+};
+
+DEFINE_STRING_TABLE_LOOKUP_TO_STRING(dhcp_state, DHCPState);
diff --git a/src/libsystemd-network/dhcp-protocol.h b/src/libsystemd-network/dhcp-protocol.h
index 2dc0660cc7..dd330ae839 100644
--- a/src/libsystemd-network/dhcp-protocol.h
+++ b/src/libsystemd-network/dhcp-protocol.h
@@ -55,15 +55,17 @@ enum {
};
enum DHCPState {
- DHCP_STATE_STOPPED = 0,
- DHCP_STATE_INIT = 1,
- DHCP_STATE_SELECTING = 2,
- DHCP_STATE_INIT_REBOOT = 3,
- DHCP_STATE_REBOOTING = 4,
- DHCP_STATE_REQUESTING = 5,
- DHCP_STATE_BOUND = 6,
- DHCP_STATE_RENEWING = 7,
- DHCP_STATE_REBINDING = 8,
+ DHCP_STATE_STOPPED,
+ DHCP_STATE_INIT,
+ DHCP_STATE_SELECTING,
+ DHCP_STATE_INIT_REBOOT,
+ DHCP_STATE_REBOOTING,
+ DHCP_STATE_REQUESTING,
+ DHCP_STATE_BOUND,
+ DHCP_STATE_RENEWING,
+ DHCP_STATE_REBINDING,
+ _DHCP_STATE_MAX,
+ _DHCP_STATE_INVALID = -EINVAL,
};
typedef enum DHCPState DHCPState;
@@ -107,3 +109,5 @@ enum {
DHCP_FQDN_FLAG_E = (1 << 2),
DHCP_FQDN_FLAG_N = (1 << 3),
};
+
+const char *dhcp_state_to_string(DHCPState s) _const_;
diff --git a/src/libsystemd-network/meson.build b/src/libsystemd-network/meson.build
index 043d3bc254..0b35eeec34 100644
--- a/src/libsystemd-network/meson.build
+++ b/src/libsystemd-network/meson.build
@@ -6,6 +6,7 @@ sources = files(
'dhcp-network.c',
'dhcp-option.c',
'dhcp-packet.c',
+ 'dhcp-protocol.c',
'dhcp6-network.c',
'dhcp6-option.c',
'dhcp6-protocol.c',
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index cbea55dd63..2e17f3cfd5 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -736,6 +736,9 @@ static void client_set_state(sd_dhcp_client *client, DHCPState state) {
if (client->state == state)
return;
+ log_dhcp_client(client, "State changed: %s -> %s",
+ dhcp_state_to_string(client->state), dhcp_state_to_string(state));
+
client->state = state;
}
@@ -1192,6 +1195,7 @@ static int client_send_request(sd_dhcp_client *client) {
case DHCP_STATE_REBOOTING:
case DHCP_STATE_BOUND:
case DHCP_STATE_STOPPED:
+ default:
return -EINVAL;
}
@@ -1349,6 +1353,7 @@ static int client_timeout_resend(
break;
case DHCP_STATE_STOPPED:
+ default:
r = -EINVAL;
goto error;
}