summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c57
-rw-r--r--src/network/networkd-link.c3
-rw-r--r--src/systemd/sd-dhcp-client.h9
3 files changed, 27 insertions, 42 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 64c67b477c..1a60f4439a 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -276,19 +276,10 @@ static void client_stop(sd_dhcp_client *client, int error) {
if (error < 0)
log_dhcp_client(client, "STOPPED: %s", strerror(-error));
- else {
- switch(error) {
- case DHCP_EVENT_STOP:
- log_dhcp_client(client, "STOPPED");
- break;
- case DHCP_EVENT_NO_LEASE:
- log_dhcp_client(client, "STOPPED: No lease");
- break;
- default:
- log_dhcp_client(client, "STOPPED: Unknown reason");
- break;
- }
- }
+ else if (error == DHCP_EVENT_STOP)
+ log_dhcp_client(client, "STOPPED");
+ else
+ log_dhcp_client(client, "STOPPED: Unknown event");
client_notify(client, error);
@@ -925,7 +916,7 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
r = dhcp_option_parse(ack, len, dhcp_lease_parse_options, lease);
if (r == DHCP_NAK) {
log_dhcp_client(client, "NAK");
- return DHCP_EVENT_NO_LEASE;
+ return -EADDRNOTAVAIL;
}
if (r != DHCP_ACK) {
@@ -1165,25 +1156,7 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
case DHCP_STATE_REBINDING:
r = client_handle_ack(client, message, len);
- if (r == DHCP_EVENT_NO_LEASE) {
-
- client->timeout_resend =
- sd_event_source_unref(client->timeout_resend);
-
- if (client->state == DHCP_STATE_REBOOTING) {
- r = client_initialize(client);
- if (r < 0)
- goto error;
-
- r = client_start(client);
- if (r < 0)
- goto error;
-
- log_dhcp_client(client, "REBOOTED");
- }
-
- goto error;
- } else if (r >= 0) {
+ if (r >= 0) {
client->timeout_resend =
sd_event_source_unref(client->timeout_resend);
@@ -1211,6 +1184,22 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
client->receive_message =
sd_event_source_unref(client->receive_message);
client->fd = asynchronous_close(client->fd);
+ } else if (r == -EADDRNOTAVAIL) {
+ /* got a NAK, let's restart the client */
+ client->timeout_resend =
+ sd_event_source_unref(client->timeout_resend);
+
+ r = client_initialize(client);
+ if (r < 0)
+ goto error;
+
+ r = client_start(client);
+ if (r < 0)
+ goto error;
+
+ log_dhcp_client(client, "REBOOTED");
+
+ return 0;
} else if (r == -ENOMSG)
/* invalid message, let's ignore it */
return 0;
@@ -1229,7 +1218,7 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
}
error:
- if (r < 0 || r == DHCP_EVENT_NO_LEASE)
+ if (r < 0)
client_stop(client, r);
return r;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index c346df45a9..ac9f4737ef 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1172,9 +1172,6 @@ static void dhcp_handler(sd_dhcp_client *client, int event, void *userdata) {
return;
switch (event) {
- case DHCP_EVENT_NO_LEASE:
- log_debug_link(link, "IP address in use.");
- break;
case DHCP_EVENT_EXPIRED:
case DHCP_EVENT_STOP:
case DHCP_EVENT_IP_CHANGE:
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index 08aa0dca69..36b8710493 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -30,11 +30,10 @@
enum {
DHCP_EVENT_STOP = 0,
- DHCP_EVENT_NO_LEASE = 1,
- DHCP_EVENT_IP_ACQUIRE = 2,
- DHCP_EVENT_IP_CHANGE = 3,
- DHCP_EVENT_EXPIRED = 4,
- DHCP_EVENT_RENEW = 5,
+ DHCP_EVENT_IP_ACQUIRE = 1,
+ DHCP_EVENT_IP_CHANGE = 2,
+ DHCP_EVENT_EXPIRED = 3,
+ DHCP_EVENT_RENEW = 4,
};
typedef struct sd_dhcp_client sd_dhcp_client;