1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-27 18:04:05 +03:00

sd-dhcp-client: check error earlier and reduce indentation

This commit is contained in:
Yu Watanabe 2021-06-24 00:48:23 +09:00
parent 4dbad977ff
commit 67d8cd8193

View File

@ -1787,7 +1787,10 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i
case DHCP_STATE_SELECTING: case DHCP_STATE_SELECTING:
r = client_handle_offer(client, message, len); r = client_handle_offer(client, message, len);
if (r >= 0) { if (r == -ENOMSG)
return 0; /* invalid message, let's ignore it */
if (r < 0)
goto error;
client->state = DHCP_STATE_REQUESTING; client->state = DHCP_STATE_REQUESTING;
client->attempt = 0; client->attempt = 0;
@ -1799,9 +1802,6 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i
client->event_priority, "dhcp4-resend-timer", true); client->event_priority, "dhcp4-resend-timer", true);
if (r < 0) if (r < 0)
goto error; goto error;
} else if (r == -ENOMSG)
/* invalid message, let's ignore it */
return 0;
break; break;
@ -1811,15 +1811,37 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i
case DHCP_STATE_REBINDING: case DHCP_STATE_REBINDING:
r = client_handle_ack(client, message, len); r = client_handle_ack(client, message, len);
if (r >= 0) { if (r == -ENOMSG)
return 0; /* invalid message, let's ignore it */
if (r == -EADDRNOTAVAIL) {
/* got a NAK, let's restart the client */
client_notify(client, SD_DHCP_CLIENT_EVENT_EXPIRED);
r = client_initialize(client);
if (r < 0)
goto error;
r = client_start_delayed(client);
if (r < 0)
goto error;
log_dhcp_client(client, "REBOOT in %s", format_timespan(time_string, FORMAT_TIMESPAN_MAX,
client->start_delay, USEC_PER_SEC));
client->start_delay = CLAMP(client->start_delay * 2,
RESTART_AFTER_NAK_MIN_USEC, RESTART_AFTER_NAK_MAX_USEC);
return 0;
}
if (r < 0)
goto error;
client->start_delay = 0; client->start_delay = 0;
(void) event_source_disable(client->timeout_resend); (void) event_source_disable(client->timeout_resend);
client->receive_message = client->receive_message = sd_event_source_unref(client->receive_message);
sd_event_source_unref(client->receive_message);
client->fd = safe_close(client->fd); client->fd = safe_close(client->fd);
if (IN_SET(client->state, DHCP_STATE_REQUESTING, if (IN_SET(client->state, DHCP_STATE_REQUESTING, DHCP_STATE_REBOOTING))
DHCP_STATE_REBOOTING))
notify_event = SD_DHCP_CLIENT_EVENT_IP_ACQUIRE; notify_event = SD_DHCP_CLIENT_EVENT_IP_ACQUIRE;
else if (r != SD_DHCP_CLIENT_EVENT_IP_ACQUIRE) else if (r != SD_DHCP_CLIENT_EVENT_IP_ACQUIRE)
notify_event = r; notify_event = r;
@ -1851,40 +1873,18 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i
return 0; return 0;
} }
} else if (r == -EADDRNOTAVAIL) {
/* got a NAK, let's restart the client */
client_notify(client, SD_DHCP_CLIENT_EVENT_EXPIRED);
r = client_initialize(client);
if (r < 0)
goto error;
r = client_start_delayed(client);
if (r < 0)
goto error;
log_dhcp_client(client, "REBOOT in %s", format_timespan(time_string, FORMAT_TIMESPAN_MAX,
client->start_delay, USEC_PER_SEC));
client->start_delay = CLAMP(client->start_delay * 2,
RESTART_AFTER_NAK_MIN_USEC, RESTART_AFTER_NAK_MAX_USEC);
return 0;
} else if (r == -ENOMSG)
/* invalid message, let's ignore it */
return 0;
break; break;
case DHCP_STATE_BOUND: case DHCP_STATE_BOUND:
r = client_handle_forcerenew(client, message, len); r = client_handle_forcerenew(client, message, len);
if (r >= 0) { if (r == -ENOMSG)
return 0; /* invalid message, let's ignore it */
if (r < 0)
goto error;
r = client_timeout_t1(NULL, 0, client); r = client_timeout_t1(NULL, 0, client);
if (r < 0) if (r < 0)
goto error; goto error;
} else if (r == -ENOMSG)
/* invalid message, let's ignore it */
return 0;
break; break;