From: Roy Marples Date: Fri, 13 Sep 2019 09:43:51 +0000 (+0100) Subject: DHCP: Give a better message when packet validation failes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7623bb1bd11f906ce1618a5fa07d5b095eb53709;p=thirdparty%2Fdhcpcd.git DHCP: Give a better message when packet validation failes We return ERANGE for underflow and ENOBUFS for overflow, but these error strings could be misleading. For EINVAL report invalid checksum, otherwise invalid UDP packet. --- diff --git a/src/dhcp.c b/src/dhcp.c index eafd6e7a..ac523824 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -3338,12 +3338,13 @@ dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len) const struct dhcp_state *state = D_CSTATE(ifp); if (valid_udp_packet(data, len, &from, state->bpf_flags) == -1) { + const char *errstr; + if (errno == EINVAL) - logerrx("%s: checksum failure from %s", - ifp->name, inet_ntoa(from)); + errstr = "checksum failure"; else - logerr("%s: invalid UDP packet from %s", - ifp->name, inet_ntoa(from)); + errstr = "invalid UDP packet"; + logerrx("%s: %s from %s", errstr, ifp->name, inet_ntoa(from)); return; }