- 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));
+ if (be16toh(packet->udp.dest) != DHCP_PORT_CLIENT) {
+ log_debug("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_debug("ignoring packet: invalid IP checksum");