[systemd-commits] 3 commits - src/libsystemd-network
Tom Gundersen
tomegun at kemper.freedesktop.org
Sun Mar 30 11:49:03 PDT 2014
src/libsystemd-network/dhcp-packet.c | 36 ++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
New commits:
commit 2ad7561f9f658f8dee168a76654c7d918e2260c7
Author: Tom Gundersen <teg at jklm.no>
Date: Sun Mar 30 20:36:44 2014 +0200
sd-dhcp: avoid checksum calculation if possible
When receiving lots of packets that are not meant for us, we waste a relatively large amount
of cpu time computing their checksums before discarding them. Move the checksum calculation last
so we never compute it for packets which would otherwise be discarded.
diff --git a/src/libsystemd-network/dhcp-packet.c b/src/libsystemd-network/dhcp-packet.c
index 3b62c25..4f90c28 100644
--- a/src/libsystemd-network/dhcp-packet.c
+++ b/src/libsystemd-network/dhcp-packet.c
@@ -155,11 +155,6 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
return -EINVAL;
}
- if (dhcp_packet_checksum(&packet->ip, hdrlen)) {
- log_dhcp_client(client, "ignoring packet: invalid IP checksum");
- return -EINVAL;
- }
-
/* UDP */
if (packet->ip.protocol != IPPROTO_UDP) {
@@ -181,6 +176,22 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
return -EINVAL;
}
+ if (be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
+ log_dhcp_client(client, "ignoring packet: to port %u, which "
+ "is not the DHCP client port (%u)",
+ be16toh(packet->udp.dest), DHCP_PORT_CLIENT);
+ return -EINVAL;
+ }
+
+ /* checksums - computing these is relatively expensive, so only do it
+ if all the other checks have passed
+ */
+
+ if (dhcp_packet_checksum(&packet->ip, hdrlen)) {
+ log_dhcp_client(client, "ignoring packet: invalid IP checksum");
+ return -EINVAL;
+ }
+
if (checksum && packet->udp.check) {
packet->ip.check = packet->udp.len;
packet->ip.ttl = 0;
@@ -192,12 +203,5 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
}
}
- if (be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
- log_dhcp_client(client, "ignoring packet: to port %u, which "
- "is not the DHCP client port (%u)",
- be16toh(packet->udp.dest), DHCP_PORT_CLIENT);
- return -EINVAL;
- }
-
return 0;
}
commit 6e34949d7207f9dff4e2b01a3037a0af88e1c25c
Author: Tom Gundersen <teg at jklm.no>
Date: Sun Mar 30 20:33:57 2014 +0200
sd-dhcp: check for ipv4 packets
diff --git a/src/libsystemd-network/dhcp-packet.c b/src/libsystemd-network/dhcp-packet.c
index 9779cbd..3b62c25 100644
--- a/src/libsystemd-network/dhcp-packet.c
+++ b/src/libsystemd-network/dhcp-packet.c
@@ -130,6 +130,11 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
return -EINVAL;
}
+ if (packet->ip.version != IPVERSION) {
+ log_dhcp_client(client, "ignoring packet: not IPv4");
+ return -EINVAL;
+ }
+
if (packet->ip.ihl < 5) {
log_dhcp_client(client, "ignoring packet: IPv4 IHL (%u words) invalid",
packet->ip.ihl);
commit d454a6748c34f0f67eef618238e0a64b80c85303
Author: Umut Tezduyar Lindskog <umut.tezduyar at axis.com>
Date: Sun Mar 30 19:09:14 2014 +0200
sd-dhcp: check for udp packets
Do not try to parse ICMP packets
[tomegun: slightly tweaked debug message]
diff --git a/src/libsystemd-network/dhcp-packet.c b/src/libsystemd-network/dhcp-packet.c
index bed942f..9779cbd 100644
--- a/src/libsystemd-network/dhcp-packet.c
+++ b/src/libsystemd-network/dhcp-packet.c
@@ -157,6 +157,11 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
/* UDP */
+ if (packet->ip.protocol != IPPROTO_UDP) {
+ log_dhcp_client(client, "ignoring packet: not UDP");
+ return -EINVAL;
+ }
+
if (len < DHCP_IP_UDP_SIZE) {
log_dhcp_client(client, "ignoring packet: packet (%zu bytes) "
" smaller than IP+UDP header (%u bytes)", len,
More information about the systemd-commits
mailing list