Adding dhcp_state_to_string and dhcp client state change logging
This commit is contained in:
@@ -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);
|
||||
@@ -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_;
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user