[systemd-devel] [PATCH 4/6] libsystemd-dhcp: Compute UDP checksum only if set

Patrik Flykt patrik.flykt at linux.intel.com
Fri Jan 31 01:31:23 PST 2014


A checksum field with value zero means no UDP checksum has been
computed for the packet.
---
 src/libsystemd-dhcp/sd-dhcp-client.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 79a92e5..7e79dc1 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -881,13 +881,18 @@ static int client_verify_headers(sd_dhcp_client *client, DHCPPacket *message,
                                                            hdrlen))
                 return -EINVAL;
 
-        message->ip.check = message->udp.len;
-        message->ip.ttl = 0;
-
-        if (hdrlen + be16toh(message->udp.len) > len ||
-            client_checksum(&message->ip.ttl, be16toh(message->udp.len) + 12))
+        if (hdrlen + be16toh(message->udp.len) > len)
                 return -EINVAL;
 
+        if (message->udp.check) {
+                message->ip.check = message->udp.len;
+                message->ip.ttl = 0;
+
+                if (client_checksum(&message->ip.ttl,
+                                    be16toh(message->udp.len) + 12))
+                        return -EINVAL;
+        }
+
         if (be16toh(message->udp.source) != DHCP_PORT_SERVER ||
             be16toh(message->udp.dest) != DHCP_PORT_CLIENT)
                 return -EINVAL;
-- 
1.8.5.2



More information about the systemd-devel mailing list