chiark / gitweb /
sd-dhcp: don't reject packets with the 'wrong' source port
authorTom Gundersen <teg@jklm.no>
Sun, 23 Feb 2014 18:21:50 +0000 (19:21 +0100)
committerTom Gundersen <teg@jklm.no>
Sun, 23 Feb 2014 21:59:43 +0000 (22:59 +0100)
The RFC does not specify that the packets from the DHCP server must come from
the DHCP server port, only that that's where they should be sent.

This fixes a problem when running networkd in VirtualBox.

Thanks to Sébastien Luttringer for reporting the bug and very patiently testing
various fixes.

src/libsystemd-dhcp/dhcp-packet.c

index 8f9ec43c43d2891f57c1270362c2305fbcc9ee92..13881ea0ddd719593a78b87c9015d01b243d9bfc 100644 (file)
@@ -164,7 +164,7 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len) {
                 return -EINVAL;
         }
 
-        if (hdrlen + be16toh(packet->udp.len) > len) {
+        if (len < hdrlen + be16toh(packet->udp.len)) {
                 log_dhcp_client(client, "ignoring packet: packet (%zu bytes) "
                                 "smaller than expected (%zu) by UDP header", len,
                                 hdrlen + be16toh(packet->udp.len));
@@ -182,10 +182,10 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len) {
                 }
         }
 
-        if (be16toh(packet->udp.source) != DHCP_PORT_SERVER ||
-            be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
-                log_dhcp_client(client, "ignoring packet: wrong ports (source: %u, destination: %u)",
-                                be16toh(packet->udp.source), be16toh(packet->udp.dest));
+        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;
         }