From: Yu Watanabe Date: Wed, 23 Jun 2021 16:14:12 +0000 (+0900) Subject: sd-dhcp-client: logs when dhcp client unexpectedly gains a new lease X-Git-Tag: v249-rc2~25^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=551ad0b7de9ebc3a5fb1d84a06e21fc0c0ca3017;p=thirdparty%2Fsystemd.git sd-dhcp-client: logs when dhcp client unexpectedly gains a new lease Previously, such situation is handled silently. --- diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index a16f7cc9aba..67a5a03eba6 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -1777,7 +1777,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) { static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, int len) { DHCP_CLIENT_DONT_DESTROY(client); char time_string[FORMAT_TIMESPAN_MAX]; - int r, notify_event = 0; + int r, notify_event; assert(client); assert(client->event); @@ -1832,16 +1832,16 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i if (r < 0) goto error; + if (IN_SET(client->state, DHCP_STATE_REQUESTING, DHCP_STATE_REBOOTING)) + notify_event = SD_DHCP_CLIENT_EVENT_IP_ACQUIRE; + else + notify_event = r; + client->start_delay = 0; (void) event_source_disable(client->timeout_resend); client->receive_message = sd_event_source_unref(client->receive_message); client->fd = safe_close(client->fd); - if (IN_SET(client->state, DHCP_STATE_REQUESTING, DHCP_STATE_REBOOTING)) - notify_event = SD_DHCP_CLIENT_EVENT_IP_ACQUIRE; - else if (r != SD_DHCP_CLIENT_EVENT_IP_ACQUIRE) - notify_event = r; - client->state = DHCP_STATE_BOUND; client->attempt = 0; @@ -1863,12 +1863,13 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i client_initialize_io_events(client, client_receive_message_udp); - if (notify_event) { + if (IN_SET(client->state, DHCP_STATE_RENEWING, DHCP_STATE_REBINDING) && + notify_event == SD_DHCP_CLIENT_EVENT_IP_ACQUIRE) + /* FIXME: hmm, maybe this is a bug... */ + log_dhcp_client(client, "client_handle_ack() returned SD_DHCP_CLIENT_EVENT_IP_ACQUIRE while DHCP client is %s the address, skipping callback.", + client->state == DHCP_STATE_RENEWING ? "renewing" : "rebinding"); + else client_notify(client, notify_event); - if (client->state == DHCP_STATE_STOPPED) - return 0; - } - break; case DHCP_STATE_BOUND: