diff --git a/src/libsystemd-network/dhcp-protocol.h b/src/libsystemd-network/dhcp-protocol.h index 062ce006f3..2dc0660cc7 100644 --- a/src/libsystemd-network/dhcp-protocol.h +++ b/src/libsystemd-network/dhcp-protocol.h @@ -55,15 +55,15 @@ enum { }; enum DHCPState { - DHCP_STATE_INIT = 0, - DHCP_STATE_SELECTING = 1, - DHCP_STATE_INIT_REBOOT = 2, - DHCP_STATE_REBOOTING = 3, - DHCP_STATE_REQUESTING = 4, - DHCP_STATE_BOUND = 5, - DHCP_STATE_RENEWING = 6, - DHCP_STATE_REBINDING = 7, - DHCP_STATE_STOPPED = 8, + 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, }; typedef enum DHCPState DHCPState; diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 8f330c8f14..265750d090 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -753,7 +753,7 @@ static int client_initialize(sd_dhcp_client *client) { client->attempt = 0; - client->state = DHCP_STATE_INIT; + client->state = DHCP_STATE_STOPPED; client->xid = 0; client->lease = sd_dhcp_lease_unref(client->lease); @@ -1434,7 +1434,7 @@ static int client_start_delayed(sd_dhcp_client *client) { assert_return(client->ifindex > 0, -EINVAL); assert_return(client->fd < 0, -EBUSY); assert_return(client->xid == 0, -EINVAL); - assert_return(IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_INIT_REBOOT), -EBUSY); + assert_return(IN_SET(client->state, DHCP_STATE_STOPPED, DHCP_STATE_INIT_REBOOT), -EBUSY); client->xid = random_u32(); @@ -1448,8 +1448,10 @@ static int client_start_delayed(sd_dhcp_client *client) { } client->fd = r; - if (IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_INIT_REBOOT)) - client->start_time = now(CLOCK_BOOTTIME); + client->start_time = now(CLOCK_BOOTTIME); + + if (client->state == DHCP_STATE_STOPPED) + client->state = DHCP_STATE_INIT; return client_initialize_events(client, client_receive_message_raw); } @@ -2061,7 +2063,7 @@ int sd_dhcp_client_is_running(sd_dhcp_client *client) { if (!client) return 0; - return !IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_STOPPED); + return client->state != DHCP_STATE_STOPPED; } int sd_dhcp_client_start(sd_dhcp_client *client) { @@ -2263,7 +2265,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) { *client = (sd_dhcp_client) { .n_ref = 1, - .state = DHCP_STATE_INIT, + .state = DHCP_STATE_STOPPED, .ifindex = -1, .fd = -EBADF, .mtu = DHCP_MIN_PACKET_SIZE,