From: Roy Marples Date: Tue, 1 Oct 2019 18:33:22 +0000 (+0100) Subject: DHCP: Don't log diagnostics when state is not running X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d54fcf0105e7c3a511cafde42fecb8089d45349a;p=thirdparty%2Fdhcpcd.git DHCP: Don't log diagnostics when state is not running --- diff --git a/src/dhcp.c b/src/dhcp.c index 4763d8aa..6145ce9c 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -2864,14 +2864,18 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, #define LOGDHCP(l, m) \ log_dhcp((l), (m), ifp, bootp, bootp_len, from, 1) +#define IS_STATE_ACTIVE(s) ((s)-state != DHS_NONE && \ + (s)->state != DHS_INIT && (s)->state != DHS_BOUND) + if (bootp->op != BOOTREPLY) { - logdebugx("%s: op (%d) is not BOOTREPLY", - ifp->name, bootp->op); + if (IS_STATE_ACTIVE(state)) + logdebugx("%s: op (%d) is not BOOTREPLY", + ifp->name, bootp->op); return; } if (state->xid != ntohl(bootp->xid)) { - if (state->state != DHS_BOUND && state->state != DHS_NONE) + if (IS_STATE_ACTIVE(state)) logdebugx("%s: wrong xid 0x%x (expecting 0x%x) from %s", ifp->name, ntohl(bootp->xid), state->xid, inet_ntoa(*from)); @@ -2882,12 +2886,14 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, if (ifp->hwlen <= sizeof(bootp->chaddr) && memcmp(bootp->chaddr, ifp->hwaddr, ifp->hwlen)) { - char buf[sizeof(bootp->chaddr) * 3]; + if (IS_STATE_ACTIVE(state)) { + char buf[sizeof(bootp->chaddr) * 3]; - logdebugx("%s: xid 0x%x is for hwaddr %s", - ifp->name, ntohl(bootp->xid), - hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr), - buf, sizeof(buf))); + logdebugx("%s: xid 0x%x is for hwaddr %s", + ifp->name, ntohl(bootp->xid), + hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr), + buf, sizeof(buf))); + } dhcp_redirect_dhcp(ifp, bootp, bootp_len, from); return; }