summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-dhcp-client.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-04-06 19:35:36 +0200
committerTom Gundersen <teg@jklm.no>2014-04-06 19:42:11 +0200
commit0c79c68d93d721d37ba088fb50dbf07bb0d447e5 (patch)
tree597fbd5e1524af6e0479ceea2813e20148aea653 /src/libsystemd-network/sd-dhcp-client.c
parent3b7ca119fdc501e21f017695dc9b6f82fdbd1d93 (diff)
sd-dhcp-client: eagerly drop too small packets
If they are too small to fit the IP+UDP+DHCP headers they can be of no use, so don't waste resources parsing them. This is at the cost of losing some verbosity in the logging.
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-client.c')
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 5824e6ee91..722f862832 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -931,12 +931,6 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message,
assert(client->event);
assert(message);
- if (len < DHCP_MESSAGE_SIZE) {
- log_dhcp_client(client, "message too small (%d bytes): "
- "ignoring", len);
- return 0;
- }
-
if (be32toh(message->magic) != DHCP_MAGIC_COOKIE) {
log_dhcp_client(client, "not a DHCP message: ignoring");
return 0;
@@ -1081,7 +1075,11 @@ static int client_receive_message_udp(sd_event_source *s, int fd,
return -ENOMEM;
len = read(fd, message, buflen);
- if (len < 0)
+ if (len < 0) {
+ log_dhcp_client(client, "could not receive message from UDP "
+ "socket: %s", strerror(errno));
+ return 0;
+ } else if ((size_t)len < sizeof(DHCPMessage))
return 0;
return client_handle_message(client, message, len);
@@ -1122,7 +1120,8 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
log_dhcp_client(client, "could not receive message from raw "
"socket: %s", strerror(errno));
return 0;
- }
+ } else if ((size_t)len < sizeof(DHCPPacket))
+ return 0;
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level == SOL_PACKET && cmsg->cmsg_type == PACKET_AUXDATA) {