From 49d5623c091852e1aa4ed68404035ff6dcca4587 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 13 Sep 2019 10:43:51 +0100 Subject: [PATCH] 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. --- src/dhcp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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; } -- 2.47.2