Add --quiet-* options.
diff --git a/CHANGELOG b/CHANGELOG
index cec8f67..b04fbd7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -137,6 +137,9 @@
servers where the original client is. Thanks to DNSthingy
for sponsoring this feature.
+ Add --quiet-dhcp, --quiet-dhcp6 and --quiet-ra. Thanks to
+ Kevin Darbyshire-Bryant for the initial patch.
+
version 2.66
Add the ability to act as an authoritative DNS
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
index a432be5..6bcd2f9 100644
--- a/man/dnsmasq.8
+++ b/man/dnsmasq.8
@@ -1260,6 +1260,11 @@
Extra logging for DHCP: log all the options sent to DHCP clients and
the tags used to determine them.
.TP
+.B --quiet-dhcp, --quiet-dhcp6, --quiet-ra
+Suppress logging of the routine operation of these protocols. Errors and
+problems will still be logged. --quiet-dhcp and quiet-dhcp6 are
+over-ridden by --log-dhcp.
+.TP
.B \-l, --dhcp-leasefile=<path>
Use the specified file to store DHCP lease information.
.TP
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 895d78f..24676ed 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -222,7 +222,10 @@
#define OPT_CLEVERBIND 39
#define OPT_TFTP 40
#define OPT_CLIENT_SUBNET 41
-#define OPT_LAST 42
+#define OPT_QUIET_DHCP 42
+#define OPT_QUIET_DHCP6 43
+#define OPT_QUIET_RA 44
+#define OPT_LAST 45
/* extra flags for my_syslog, we use a couple of facilities since they are known
not to occupy the same bits as priorities, no matter how syslog.h is set up. */
diff --git a/src/option.c b/src/option.c
index b2cc27d..329ad5a 100644
--- a/src/option.c
+++ b/src/option.c
@@ -64,77 +64,80 @@
#define OPTSTRING "951yZDNLERKzowefnbvhdkqr:m:p:c:l:s:i:t:u:g:a:x:S:C:A:T:H:Q:I:B:F:G:O:M:X:V:U:j:P:J:W:Y:2:4:6:7:8:0:3:"
/* options which don't have a one-char version */
-#define LOPT_RELOAD 256
-#define LOPT_NO_NAMES 257
-#define LOPT_TFTP 258
-#define LOPT_SECURE 259
-#define LOPT_PREFIX 260
-#define LOPT_PTR 261
-#define LOPT_BRIDGE 262
-#define LOPT_TFTP_MAX 263
-#define LOPT_FORCE 264
-#define LOPT_NOBLOCK 265
-#define LOPT_LOG_OPTS 266
-#define LOPT_MAX_LOGS 267
-#define LOPT_CIRCUIT 268
-#define LOPT_REMOTE 269
-#define LOPT_SUBSCR 270
-#define LOPT_INTNAME 271
-#define LOPT_BANK 272
-#define LOPT_DHCP_HOST 273
-#define LOPT_APREF 274
-#define LOPT_OVERRIDE 275
-#define LOPT_TFTPPORTS 276
-#define LOPT_REBIND 277
-#define LOPT_NOLAST 278
-#define LOPT_OPTS 279
-#define LOPT_DHCP_OPTS 280
-#define LOPT_MATCH 281
-#define LOPT_BROADCAST 282
-#define LOPT_NEGTTL 283
-#define LOPT_ALTPORT 284
-#define LOPT_SCRIPTUSR 285
-#define LOPT_LOCAL 286
-#define LOPT_NAPTR 287
-#define LOPT_MINPORT 288
-#define LOPT_DHCP_FQDN 289
-#define LOPT_CNAME 290
-#define LOPT_PXE_PROMT 291
-#define LOPT_PXE_SERV 292
-#define LOPT_TEST 293
-#define LOPT_TAG_IF 294
-#define LOPT_PROXY 295
-#define LOPT_GEN_NAMES 296
-#define LOPT_MAXTTL 297
-#define LOPT_NO_REBIND 298
-#define LOPT_LOC_REBND 299
-#define LOPT_ADD_MAC 300
-#define LOPT_DNSSEC 301
-#define LOPT_INCR_ADDR 302
-#define LOPT_CONNTRACK 303
-#define LOPT_FQDN 304
-#define LOPT_LUASCRIPT 305
-#define LOPT_RA 306
-#define LOPT_DUID 307
-#define LOPT_HOST_REC 308
-#define LOPT_TFTP_LC 309
-#define LOPT_RR 310
-#define LOPT_CLVERBIND 311
-#define LOPT_MAXCTTL 312
-#define LOPT_AUTHZONE 313
-#define LOPT_AUTHSERV 314
-#define LOPT_AUTHTTL 315
-#define LOPT_AUTHSOA 316
-#define LOPT_AUTHSFS 317
-#define LOPT_AUTHPEER 318
-#define LOPT_IPSET 319
-#define LOPT_SYNTH 320
+#define LOPT_RELOAD 256
+#define LOPT_NO_NAMES 257
+#define LOPT_TFTP 258
+#define LOPT_SECURE 259
+#define LOPT_PREFIX 260
+#define LOPT_PTR 261
+#define LOPT_BRIDGE 262
+#define LOPT_TFTP_MAX 263
+#define LOPT_FORCE 264
+#define LOPT_NOBLOCK 265
+#define LOPT_LOG_OPTS 266
+#define LOPT_MAX_LOGS 267
+#define LOPT_CIRCUIT 268
+#define LOPT_REMOTE 269
+#define LOPT_SUBSCR 270
+#define LOPT_INTNAME 271
+#define LOPT_BANK 272
+#define LOPT_DHCP_HOST 273
+#define LOPT_APREF 274
+#define LOPT_OVERRIDE 275
+#define LOPT_TFTPPORTS 276
+#define LOPT_REBIND 277
+#define LOPT_NOLAST 278
+#define LOPT_OPTS 279
+#define LOPT_DHCP_OPTS 280
+#define LOPT_MATCH 281
+#define LOPT_BROADCAST 282
+#define LOPT_NEGTTL 283
+#define LOPT_ALTPORT 284
+#define LOPT_SCRIPTUSR 285
+#define LOPT_LOCAL 286
+#define LOPT_NAPTR 287
+#define LOPT_MINPORT 288
+#define LOPT_DHCP_FQDN 289
+#define LOPT_CNAME 290
+#define LOPT_PXE_PROMT 291
+#define LOPT_PXE_SERV 292
+#define LOPT_TEST 293
+#define LOPT_TAG_IF 294
+#define LOPT_PROXY 295
+#define LOPT_GEN_NAMES 296
+#define LOPT_MAXTTL 297
+#define LOPT_NO_REBIND 298
+#define LOPT_LOC_REBND 299
+#define LOPT_ADD_MAC 300
+#define LOPT_DNSSEC 301
+#define LOPT_INCR_ADDR 302
+#define LOPT_CONNTRACK 303
+#define LOPT_FQDN 304
+#define LOPT_LUASCRIPT 305
+#define LOPT_RA 306
+#define LOPT_DUID 307
+#define LOPT_HOST_REC 308
+#define LOPT_TFTP_LC 309
+#define LOPT_RR 310
+#define LOPT_CLVERBIND 311
+#define LOPT_MAXCTTL 312
+#define LOPT_AUTHZONE 313
+#define LOPT_AUTHSERV 314
+#define LOPT_AUTHTTL 315
+#define LOPT_AUTHSOA 316
+#define LOPT_AUTHSFS 317
+#define LOPT_AUTHPEER 318
+#define LOPT_IPSET 319
+#define LOPT_SYNTH 320
#ifdef OPTION6_PREFIX_CLASS
-#define LOPT_PREF_CLSS 321
+#define LOPT_PREF_CLSS 321
#endif
-#define LOPT_RELAY 323
-#define LOPT_RA_PARAM 324
-#define LOPT_ADD_SBNET 325
+#define LOPT_RELAY 323
+#define LOPT_RA_PARAM 324
+#define LOPT_ADD_SBNET 325
+#define LOPT_QUIET_DHCP 326
+#define LOPT_QUIET_DHCP6 327
+#define LOPT_QUIET_RA 328
#ifdef HAVE_GETOPT_LONG
@@ -276,6 +279,9 @@
#endif
{ "dhcp-relay", 1, 0, LOPT_RELAY },
{ "ra-param", 1, 0, LOPT_RA_PARAM },
+ { "quiet-dhcp", 0, 0, LOPT_QUIET_DHCP },
+ { "quiet-dhcp6", 0, 0, LOPT_QUIET_DHCP6 },
+ { "quiet-ra", 0, 0, LOPT_QUIET_RA },
{ NULL, 0, 0, 0 }
};
@@ -422,6 +428,9 @@
{ LOPT_PREF_CLSS, ARG_DUP, "set:tag,<class>", gettext_noop("Specify DHCPv6 prefix class"), NULL },
#endif
{ LOPT_RA_PARAM, ARG_DUP, "<interface>,[high,|low,]<interval>[,<lifetime>]", gettext_noop("Set priority, resend-interval and router-lifetime"), NULL },
+ { LOPT_QUIET_DHCP, OPT_QUIET_DHCP, NULL, gettext_noop("Do not log routine DHCP."), NULL },
+ { LOPT_QUIET_DHCP6, OPT_QUIET_DHCP6, NULL, gettext_noop("Do not log routine DHCPv6."), NULL },
+ { LOPT_QUIET_RA, OPT_QUIET_RA, NULL, gettext_noop("Do not log RA."), NULL },
{ 0, 0, NULL, NULL, NULL }
};
diff --git a/src/radv.c b/src/radv.c
index d1147ba..8e0a730 100644
--- a/src/radv.c
+++ b/src/radv.c
@@ -189,7 +189,8 @@
mac = daemon->namebuff;
}
- my_syslog(MS_DHCP | LOG_INFO, "RTR-SOLICIT(%s) %s", interface, mac);
+ if (!option_bool(OPT_QUIET_RA))
+ my_syslog(MS_DHCP | LOG_INFO, "RTR-SOLICIT(%s) %s", interface, mac);
/* source address may not be valid in solicit request. */
send_ra(now, if_index, interface, !IN6_IS_ADDR_UNSPECIFIED(&from.sin6_addr) ? &from.sin6_addr : NULL);
}
@@ -288,7 +289,8 @@
opt->prefix = local;
inet_ntop(AF_INET6, &local, daemon->addrbuff, ADDRSTRLEN);
- my_syslog(MS_DHCP | LOG_INFO, "RTR-ADVERT(%s) %s old prefix", iface_name, daemon->addrbuff);
+ if (!option_bool(OPT_QUIET_RA))
+ my_syslog(MS_DHCP | LOG_INFO, "RTR-ADVERT(%s) %s old prefix", iface_name, daemon->addrbuff);
}
up = &context->next;
@@ -536,7 +538,8 @@
opt->prefix = *local;
inet_ntop(AF_INET6, local, daemon->addrbuff, ADDRSTRLEN);
- my_syslog(MS_DHCP | LOG_INFO, "RTR-ADVERT(%s) %s", param->if_name, daemon->addrbuff);
+ if (!option_bool(OPT_QUIET_RA))
+ my_syslog(MS_DHCP | LOG_INFO, "RTR-ADVERT(%s) %s", param->if_name, daemon->addrbuff);
}
}
diff --git a/src/rfc2131.c b/src/rfc2131.c
index cb1834b..d339fc9 100644
--- a/src/rfc2131.c
+++ b/src/rfc2131.c
@@ -34,7 +34,7 @@
static struct in_addr option_addr(unsigned char *opt);
static unsigned int option_uint(unsigned char *opt, int i, int size);
static void log_packet(char *type, void *addr, unsigned char *ext_mac,
- int mac_len, char *interface, char *string, u32 xid);
+ int mac_len, char *interface, char *string, char *err, u32 xid);
static unsigned char *option_find(struct dhcp_packet *mess, size_t size, int opt_type, int minsize);
static unsigned char *option_find1(unsigned char *p, unsigned char *end, int opt, int minsize);
static size_t dhcp_packet_size(struct dhcp_packet *mess, unsigned char *agent_id, unsigned char *real_end);
@@ -610,7 +610,7 @@
}
}
- log_packet("BOOTP", logaddr, mess->chaddr, mess->hlen, iface_name, message, mess->xid);
+ log_packet("BOOTP", logaddr, mess->chaddr, mess->hlen, iface_name, NULL, message, mess->xid);
return message ? 0 : dhcp_packet_size(mess, agent_id, real_end);
}
@@ -827,7 +827,7 @@
opt71.next = daemon->dhcp_opts;
do_encap_opts(&opt71, OPTION_VENDOR_CLASS_OPT, DHOPT_VENDOR_MATCH, mess, end, 0);
- log_packet("PXE", &mess->yiaddr, emac, emac_len, iface_name, (char *)mess->file, mess->xid);
+ log_packet("PXE", &mess->yiaddr, emac, emac_len, iface_name, (char *)mess->file, NULL, mess->xid);
log_tags(tagif_netid, ntohl(mess->xid));
return dhcp_packet_size(mess, agent_id, real_end);
}
@@ -887,7 +887,7 @@
prune_vendor_opts(tagif_netid);
do_encap_opts(pxe_opts(pxearch, tagif_netid, context->local, now), OPTION_VENDOR_CLASS_OPT, DHOPT_VENDOR_MATCH, mess, end, 0);
- log_packet("PXE", NULL, emac, emac_len, iface_name, ignore ? "proxy-ignored" : "proxy", mess->xid);
+ log_packet("PXE", NULL, emac, emac_len, iface_name, ignore ? "proxy-ignored" : "proxy", NULL, mess->xid);
log_tags(tagif_netid, ntohl(mess->xid));
return ignore ? 0 : dhcp_packet_size(mess, agent_id, real_end);
}
@@ -919,7 +919,7 @@
if (!(opt = option_find(mess, sz, OPTION_REQUESTED_IP, INADDRSZ)))
return 0;
- log_packet("DHCPDECLINE", option_ptr(opt, 0), emac, emac_len, iface_name, daemon->dhcp_buff, mess->xid);
+ log_packet("DHCPDECLINE", option_ptr(opt, 0), emac, emac_len, iface_name, NULL, daemon->dhcp_buff, mess->xid);
if (lease && lease->addr.s_addr == option_addr(opt).s_addr)
lease_prune(lease, now);
@@ -951,7 +951,7 @@
else
message = _("unknown lease");
- log_packet("DHCPRELEASE", &mess->ciaddr, emac, emac_len, iface_name, message, mess->xid);
+ log_packet("DHCPRELEASE", &mess->ciaddr, emac, emac_len, iface_name, NULL, message, mess->xid);
return 0;
@@ -1015,7 +1015,7 @@
message = _("no address available");
}
- log_packet("DHCPDISCOVER", opt ? option_ptr(opt, 0) : NULL, emac, emac_len, iface_name, message, mess->xid);
+ log_packet("DHCPDISCOVER", opt ? option_ptr(opt, 0) : NULL, emac, emac_len, iface_name, NULL, message, mess->xid);
if (message || !(context = narrow_context(context, mess->yiaddr, tagif_netid)))
return 0;
@@ -1028,7 +1028,7 @@
log_tags(tagif_netid, ntohl(mess->xid));
- log_packet("DHCPOFFER" , &mess->yiaddr, emac, emac_len, iface_name, NULL, mess->xid);
+ log_packet("DHCPOFFER" , &mess->yiaddr, emac, emac_len, iface_name, NULL, NULL, mess->xid);
time = calc_time(context, config, option_find(mess, sz, OPTION_LEASE_TIME, 4));
clear_packet(mess, end);
@@ -1144,7 +1144,7 @@
mess->yiaddr = mess->ciaddr;
}
- log_packet("DHCPREQUEST", &mess->yiaddr, emac, emac_len, iface_name, NULL, mess->xid);
+ log_packet("DHCPREQUEST", &mess->yiaddr, emac, emac_len, iface_name, NULL, NULL, mess->xid);
if (!message)
{
@@ -1216,7 +1216,7 @@
if (message)
{
- log_packet("DHCPNAK", &mess->yiaddr, emac, emac_len, iface_name, message, mess->xid);
+ log_packet("DHCPNAK", &mess->yiaddr, emac, emac_len, iface_name, NULL, message, mess->xid);
mess->yiaddr.s_addr = 0;
clear_packet(mess, end);
@@ -1355,7 +1355,7 @@
else
override = lease->override;
- log_packet("DHCPACK", &mess->yiaddr, emac, emac_len, iface_name, hostname, mess->xid);
+ log_packet("DHCPACK", &mess->yiaddr, emac, emac_len, iface_name, hostname, NULL, mess->xid);
clear_packet(mess, end);
option_put(mess, end, OPTION_MESSAGE_TYPE, 1, DHCPACK);
@@ -1378,7 +1378,7 @@
if (ignore || have_config(config, CONFIG_DISABLE))
message = _("ignored");
- log_packet("DHCPINFORM", &mess->ciaddr, emac, emac_len, iface_name, message, mess->xid);
+ log_packet("DHCPINFORM", &mess->ciaddr, emac, emac_len, iface_name, message, NULL, mess->xid);
if (message || mess->ciaddr.s_addr == 0)
return 0;
@@ -1404,7 +1404,7 @@
log_tags(tagif_netid, ntohl(mess->xid));
- log_packet("DHCPACK", &mess->ciaddr, emac, emac_len, iface_name, hostname, mess->xid);
+ log_packet("DHCPACK", &mess->ciaddr, emac, emac_len, iface_name, hostname, NULL, mess->xid);
if (lease)
{
@@ -1538,10 +1538,13 @@
#endif
static void log_packet(char *type, void *addr, unsigned char *ext_mac,
- int mac_len, char *interface, char *string, u32 xid)
+ int mac_len, char *interface, char *string, char *err, u32 xid)
{
struct in_addr a;
+ if (!err && (!option_bool(OPT_LOG_OPTS) || option_bool(OPT_QUIET_DHCP)))
+ return;
+
/* addr may be misaligned */
if (addr)
memcpy(&a, addr, sizeof(a));
@@ -1549,22 +1552,24 @@
print_mac(daemon->namebuff, ext_mac, mac_len);
if(option_bool(OPT_LOG_OPTS))
- my_syslog(MS_DHCP | LOG_INFO, "%u %s(%s) %s%s%s %s",
+ my_syslog(MS_DHCP | LOG_INFO, "%u %s(%s) %s%s%s %s%s",
ntohl(xid),
type,
interface,
addr ? inet_ntoa(a) : "",
addr ? " " : "",
daemon->namebuff,
- string ? string : "");
+ string ? string : "",
+ err ? err : "");
else
- my_syslog(MS_DHCP | LOG_INFO, "%s(%s) %s%s%s %s",
+ my_syslog(MS_DHCP | LOG_INFO, "%s(%s) %s%s%s %s%s",
type,
interface,
addr ? inet_ntoa(a) : "",
addr ? " " : "",
daemon->namebuff,
- string ? string : "");
+ string ? string : "",
+ err ? err : "");
}
static void log_options(unsigned char *start, u32 xid)
diff --git a/src/rfc3315.c b/src/rfc3315.c
index bbdc5a8..bf3bacf 100644
--- a/src/rfc3315.c
+++ b/src/rfc3315.c
@@ -41,6 +41,7 @@
static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_t sz, int is_unicast, time_t now);
static void log6_opts(int nest, unsigned int xid, void *start_opts, void *end_opts);
static void log6_packet(struct state *state, char *type, struct in6_addr *addr, char *string);
+static void log6_quiet(struct state *state, char *type, struct in6_addr *addr, char *string);
static void *opt6_find (void *opts, void *end, unsigned int search, unsigned int minsize);
static void *opt6_next(void *opts, void *end);
static unsigned int opt6_uint(unsigned char *opt, int offset, int size);
@@ -595,7 +596,7 @@
end_opt6(o);
}
- log6_packet(state, "DHCPSOLICIT", NULL, ignore ? _("ignored") : NULL);
+ log6_quiet(state, "DHCPSOLICIT", NULL, ignore ? _("ignored") : NULL);
request_no_address:
solicit_tags = tagif;
@@ -815,7 +816,7 @@
*outmsgtypep = DHCP6REPLY;
state->lease_allocate = 1;
- log6_packet(state, "DHCPREQUEST", NULL, ignore ? _("ignored") : NULL);
+ log6_quiet(state, "DHCPREQUEST", NULL, ignore ? _("ignored") : NULL);
if (ignore)
return 0;
@@ -928,7 +929,7 @@
/* set reply message type */
*outmsgtypep = DHCP6REPLY;
- log6_packet(state, "DHCPRENEW", NULL, NULL);
+ log6_quiet(state, "DHCPRENEW", NULL, NULL);
for (opt = state->packet_options; opt; opt = opt6_next(opt, state->end))
{
@@ -1011,8 +1012,11 @@
message = _("address invalid");
}
- log6_packet(state, "DHCPREPLY", req_addr, message);
-
+ if (message)
+ log6_packet(state, "DHCPREPLY", req_addr, message);
+ else
+ log6_quiet(state, "DHCPREPLY", req_addr, message);
+
o1 = new_opt6(OPTION6_IAADDR);
put_opt6(req_addr, sizeof(*req_addr));
put_opt6_long(preferred_time);
@@ -1034,7 +1038,7 @@
/* set reply message type */
*outmsgtypep = DHCP6REPLY;
- log6_packet(state, "DHCPCONFIRM", NULL, NULL);
+ log6_quiet(state, "DHCPCONFIRM", NULL, NULL);
for (opt = state->packet_options; opt; opt = opt6_next(opt, state->end))
{
@@ -1055,7 +1059,7 @@
return 1;
}
- log6_packet(state, "DHCPREPLY", req_addr, state->hostname);
+ log6_quiet(state, "DHCPREPLY", req_addr, state->hostname);
}
}
@@ -1084,7 +1088,7 @@
else
state->send_domain = get_domain6(NULL);
- log6_packet(state, "DHCPINFORMATION-REQUEST", NULL, ignore ? _("ignored") : state->hostname);
+ log6_quiet(state, "DHCPINFORMATION-REQUEST", NULL, ignore ? _("ignored") : state->hostname);
if (ignore)
return 0;
*outmsgtypep = DHCP6REPLY;
@@ -1098,7 +1102,7 @@
/* set reply message type */
*outmsgtypep = DHCP6REPLY;
- log6_packet(state, "DHCPRELEASE", NULL, NULL);
+ log6_quiet(state, "DHCPRELEASE", NULL, NULL);
for (opt = state->packet_options; opt; opt = opt6_next(opt, state->end))
{
@@ -1160,7 +1164,7 @@
/* set reply message type */
*outmsgtypep = DHCP6REPLY;
- log6_packet(state, "DHCPDECLINE", NULL, NULL);
+ log6_quiet(state, "DHCPDECLINE", NULL, NULL);
for (opt = state->packet_options; opt; opt = opt6_next(opt, state->end))
{
@@ -1610,7 +1614,7 @@
}
}
- log6_packet(state, state->lease_allocate ? "DHCPREPLY" : "DHCPADVERTISE", addr, state->hostname);
+ log6_quiet(state, state->lease_allocate ? "DHCPREPLY" : "DHCPADVERTISE", addr, state->hostname);
}
@@ -1880,6 +1884,12 @@
}
}
+static void log6_quiet(struct state *state, char *type, struct in6_addr *addr, char *string)
+{
+ if (option_bool(OPT_LOG_OPTS) || !option_bool(OPT_QUIET_DHCP6))
+ log6_packet(state, type, addr, string);
+}
+
static void log6_packet(struct state *state, char *type, struct in6_addr *addr, char *string)
{
int clid_len = state->clid_len;
diff --git a/src/slaac.c b/src/slaac.c
index 0229d9e..43c2c38 100644
--- a/src/slaac.c
+++ b/src/slaac.c
@@ -200,7 +200,8 @@
slaac->backoff = 0;
gotone = 1;
inet_ntop(AF_INET6, sender, daemon->addrbuff, ADDRSTRLEN);
- my_syslog(MS_DHCP | LOG_INFO, "SLAAC-CONFIRM(%s) %s %s", interface, daemon->addrbuff, lease->hostname);
+ if (!option_bool(OPT_QUIET_DHCP6))
+ my_syslog(MS_DHCP | LOG_INFO, "SLAAC-CONFIRM(%s) %s %s", interface, daemon->addrbuff, lease->hostname);
}
lease_update_dns(gotone);