summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libsystemd-dhcp/dhcp-internal.h2
-rw-r--r--src/libsystemd-dhcp/sd-dhcp-client.c28
2 files changed, 27 insertions, 3 deletions
diff --git a/src/libsystemd-dhcp/dhcp-internal.h b/src/libsystemd-dhcp/dhcp-internal.h
index 7639069cf2..efb8ea5411 100644
--- a/src/libsystemd-dhcp/dhcp-internal.h
+++ b/src/libsystemd-dhcp/dhcp-internal.h
@@ -51,3 +51,5 @@ int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid, uint8_t ty
void dhcp_packet_append_ip_headers(DHCPPacket *packet, uint8_t op, uint16_t len);
int dhcp_packet_verify_headers(DHCPPacket *packet, uint8_t op, size_t len);
+
+#define log_dhcp_client(client, fmt, ...) log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, "DHCP CLIENT: " fmt, ##__VA_ARGS__)
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 53abe22257..3506755304 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -195,6 +195,8 @@ static int client_stop(sd_dhcp_client *client, int error) {
if (client->lease)
client->lease = sd_dhcp_lease_unref(client->lease);
+ log_dhcp_client(client, "STOPPED");
+
return 0;
}
@@ -214,7 +216,7 @@ static int client_message_init(sd_dhcp_client *client, DHCPMessage *message,
client->state == DHCP_STATE_REBINDING)
message->ciaddr = client->lease->address;
- /* Some DHCP servers will refuse to issue an DHCP lease if the Cliient
+ /* Some DHCP servers will refuse to issue an DHCP lease if the Client
Identifier option is not set */
r = dhcp_option_append(opt, optlen, DHCP_OPTION_CLIENT_IDENTIFIER,
ETH_ALEN, &client->mac_addr);
@@ -282,6 +284,8 @@ static int client_send_discover(sd_dhcp_client *client, uint16_t secs) {
err = dhcp_network_send_raw_socket(client->fd, &client->link,
discover, len);
+ log_dhcp_client(client, "DISCOVER");
+
return err;
}
@@ -334,6 +338,8 @@ static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
request, len);
}
+ log_dhcp_client(client, "REQUEST");
+
return err;
}
@@ -503,6 +509,8 @@ static int client_timeout_expire(sd_event_source *s, uint64_t usec,
void *userdata) {
sd_dhcp_client *client = userdata;
+ log_dhcp_client(client, "EXPIRED");
+
client_stop(client, DHCP_EVENT_EXPIRED);
return 0;
@@ -530,6 +538,8 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
client->fd = r;
+ log_dhcp_client(client, "TIMEOUT T2");
+
return client_initialize_events(client, client_receive_message_raw,
usec);
}
@@ -552,6 +562,8 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec,
client->fd = r;
+ log_dhcp_client(client, "TIMEOUT T1");
+
return client_initialize_events(client, client_receive_message_udp, usec);
}
@@ -579,6 +591,8 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
client->lease = lease;
lease = NULL;
+ log_dhcp_client(client, "OFFER");
+
return 0;
}
@@ -592,8 +606,10 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
return r;
r = dhcp_option_parse(ack, len, dhcp_lease_parse_options, lease);
- if (r == DHCP_NAK)
+ if (r == DHCP_NAK) {
+ log_dhcp_client(client, "NAK");
return DHCP_EVENT_NO_LEASE;
+ }
if (r != DHCP_ACK)
return -ENOMSG;
@@ -619,6 +635,8 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
client->lease = lease;
lease = NULL;
+ log_dhcp_client(client, "ACK");
+
return r;
}
@@ -852,8 +870,10 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
packet = (DHCPPacket *) buf;
r = dhcp_packet_verify_headers(packet, BOOTREPLY, len);
- if (r < 0)
+ if (r < 0) {
+ log_dhcp_client(client, "ignoring DHCP packet with invalid headers");
return 0;
+ }
len -= DHCP_IP_UDP_SIZE;
@@ -886,6 +906,8 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
client->start_time = now(CLOCK_MONOTONIC);
client->secs = 0;
+ log_dhcp_client(client, "STARTED");
+
return client_initialize_events(client, client_receive_message_raw,
client->start_time);
}