From 2d2349cc3ed43153344807892332c9fa626c8d8a Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 17 May 2014 21:23:20 +0200 Subject: [PATCH] sd-dhcp-client: drop event DHCP_EVENT_NO_LEASE Keep this internal to the client and simply restart it when NAK is receieved, as per the RFC. --- src/libsystemd-network/sd-dhcp-client.c | 57 ++++++++++--------------- src/network/networkd-link.c | 3 -- src/systemd/sd-dhcp-client.h | 9 ++-- 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 64c67b477c5..1a60f4439a6 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 c346df45a99..ac9f4737efa 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 08aa0dca692..36b8710493f 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;