From 23220475f47f5d124eadb119176e74f824324274 Mon Sep 17 00:00:00 2001 From: krw Date: Thu, 25 Jan 2018 15:43:51 +0000 Subject: [PATCH] Add DPRINTF() and use it to replace log_debug() statements inside #ifdef DEBUG/#endif blocks. Suggestions on correct idiom (C99 vs gcc) from millert@ ok tom@ --- sbin/dhclient/dhclient.c | 22 ++++++---------------- sbin/dhclient/dhcpd.h | 8 +++++++- sbin/dhclient/dispatch.c | 30 ++++++++---------------------- sbin/dhclient/packet.c | 10 +++------- 4 files changed, 24 insertions(+), 46 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index f0393d0aa0b..926fa4fdcfd 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.544 2018/01/24 19:12:49 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.545 2018/01/25 15:43:51 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -368,11 +368,9 @@ routehandler(struct interface_info *ifi, int routefd) linkstat = interface_status(ifi->name); if (linkstat != ifi->linkstat) { -#ifdef DEBUG - log_debug("%s: link %s -> %s", log_procname, + DPRINTF("%s: link %s -> %s", log_procname, (ifi->linkstat != 0) ? "up" : "down", (linkstat != 0) ? "up" : "down"); -#endif /* DEBUG */ ifi->linkstat = linkstat; if (ifi->linkstat != 0) { if (ifi->state == S_PREBOOT) { @@ -839,10 +837,8 @@ dhcpoffer(struct interface_info *ifi, struct option_data *options, char *info) time_t cur_time, stop_selecting; if (ifi->state != S_SELECTING) { -#ifdef DEBUG - log_debug("%s: unexpected %s - state #%d", log_procname, info, + DPRINTF("%s: unexpected %s - state #%d", log_procname, info, ifi->state); -#endif /* DEBUG */ return; } @@ -885,10 +881,8 @@ dhcpack(struct interface_info *ifi, struct option_data *options, char *info) ifi->state != S_REQUESTING && ifi->state != S_RENEWING && ifi->state != S_REBINDING) { -#ifdef DEBUG - log_debug("%s: unexpected %s - state #%d", log_procname, info, + DPRINTF("%s: unexpected %s - state #%d", log_procname, info, ifi->state); -#endif /* DEBUG */ return; } @@ -918,18 +912,14 @@ dhcpnak(struct interface_info *ifi, struct option_data *options, char *info) ifi->state != S_REQUESTING && ifi->state != S_RENEWING && ifi->state != S_REBINDING) { -#ifdef DEBUG - log_debug("%s: unexpected %s - state #%d", log_procname, info, + DPRINTF("%s: unexpected %s - state #%d", log_procname, info, ifi->state); -#endif /* DEBUG */ return; } if (ifi->active == NULL) { -#ifdef DEBUG - log_debug("%s: unexpected %s - no active lease", log_procname, + DPRINTF("%s: unexpected %s - no active lease", log_procname, info); -#endif /* DEBUG */ return; } diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 7e31a0ac6b7..dd90342bb8f 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.245 2018/01/04 03:02:05 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.246 2018/01/25 15:43:51 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -149,6 +149,12 @@ struct interface_info { struct client_lease_tq lease_db; }; +#if DEBUG +#define DPRINTF(...) log_debug(__VA_ARGS__) +#else +#define DPRINTF(...) do {} while(0) +#endif + #define _PATH_DHCLIENT_CONF "/etc/dhclient.conf" #define _PATH_LEASE_DB "/var/db/dhclient.leases" diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index ef3005baf92..3a9e6582c74 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.147 2018/01/24 19:12:49 krw Exp $ */ +/* $OpenBSD: dispatch.c,v 1.148 2018/01/25 15:43:51 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -202,35 +202,27 @@ packethandler(struct interface_info *ifi) ifrom.s_addr = from.sin_addr.s_addr; if (packet->hlen != ETHER_ADDR_LEN) { -#ifdef DEBUG - log_debug("%s: discarding packet with hlen == %u", log_procname, + DPRINTF("%s: discarding packet with hlen == %u", log_procname, packet->hlen); -#endif /* DEBUG */ return; } else if (memcmp(&ifi->hw_address, packet->chaddr, sizeof(ifi->hw_address))) { -#ifdef DEBUG - log_debug("%s: discarding packet with chaddr == %s", + DPRINTF("%s: discarding packet with chaddr == %s", log_procname, ether_ntoa((struct ether_addr *)packet->chaddr)); -#endif /* DEBUG */ return; } if (ifi->xid != packet->xid) { -#ifdef DEBUG - log_debug("%s: discarding packet with XID != %u (%u)", + DPRINTF("%s: discarding packet with XID != %u (%u)", log_procname, ifi->xid, packet->xid); -#endif /* DEBUG */ return; } TAILQ_FOREACH(ap, &config->reject_list, next) if (ifrom.s_addr == ap->addr.s_addr) { -#ifdef DEBUG - log_debug("%s: discarding packet from address on reject " + DPRINTF("%s: discarding packet from address on reject " "list (%s)", log_procname, inet_ntoa(ifrom)); -#endif /* DEBUG */ return; } @@ -245,10 +237,8 @@ packethandler(struct interface_info *ifi) ((options[i].len != config->send_options[i].len) || memcmp(options[i].data, config->send_options[i].data, options[i].len) != 0)) { -#ifdef DEBUG - log_debug("%s: discarding packet with client-identifier %s'", + DPRINTF("%s: discarding packet with client-identifier %s'", log_procname, pretty_print_option(i, &options[i], 0)); -#endif /* DEBUG */ return; } @@ -272,20 +262,16 @@ packethandler(struct interface_info *ifi) type = "DHCPACK"; break; default: -#ifdef DEBUG - log_debug("%s: discarding DHCP packet of unknown type " + DPRINTF("%s: discarding DHCP packet of unknown type " "(%d)", log_procname, options[i].data[0]); -#endif /* DEBUG */ return; } } else if (packet->op == BOOTREPLY) { handler = dhcpoffer; type = "BOOTREPLY"; } else { -#ifdef DEBUG - log_debug("%s: discarding packet which is neither DHCP nor " + DPRINTF("%s: discarding packet which is neither DHCP nor " "BOOTP", log_procname); -#endif /* DEBUG */ return; } diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c index e20a11623c7..405f5ed3a1d 100644 --- a/sbin/dhclient/packet.c +++ b/sbin/dhclient/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.41 2017/09/17 21:20:23 krw Exp $ */ +/* $OpenBSD: packet.c,v 1.42 2018/01/25 15:43:51 krw Exp $ */ /* Packet assembly code, originally contributed by Archie Cobbs. */ @@ -159,11 +159,9 @@ decode_udp_ip_header(unsigned char *buf, uint32_t buflen, memcpy(&from->sin_addr, &ip->ip_src, sizeof(from->sin_addr)); -#ifdef DEBUG if (ntohs(ip->ip_len) != buflen) - log_debug("%s: ip length %hu disagrees with bytes received %d", + DPRINTF("%s: ip length %hu disagrees with bytes received %d", log_procname, ntohs(ip->ip_len), buflen); -#endif /* DEBUG */ /* Assure that the entire IP packet is within the buffer. */ if (ntohs(ip->ip_len) > buflen) @@ -201,11 +199,9 @@ decode_udp_ip_header(unsigned char *buf, uint32_t buflen, } return -1; } -#ifdef DEBUG if (len + data != buf + buflen) - log_debug("%s: accepting packet with data after udp payload", + DPRINTF("%s: accepting packet with data after udp payload", log_procname); -#endif /* DEBUG */ usum = udp->uh_sum; udp->uh_sum = 0; -- 2.20.1