]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Give a better message when packet validation failes
authorRoy Marples <roy@marples.name>
Fri, 13 Sep 2019 09:43:51 +0000 (10:43 +0100)
committerRoy Marples <roy@marples.name>
Fri, 13 Sep 2019 09:47:14 +0000 (10:47 +0100)
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

index eafd6e7aa49967f97d438ad8a98e19e156c5b48f..ac52382424266a8a40afc062f6d8a088ee26e3f8 100644 (file)
@@ -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;
        }