Configurable log facility
Glenn Satchell
glenn.satchell at uniq.com.au
Wed Nov 21 04:05:27 UTC 2012
Hi Chris
There's already a log-facility command you can put in dhcpd.conf. So what
benefit does a command line option have?
regards,
-glenn
On Wed, November 21, 2012 2:57 pm, chris packham wrote:
> (Sorry if this is a duplicate but I can't see this message in the list
> archives
> so maybe it got lost in transit when I sent it the first time).
>
> Hi,
>
> We're using ISC dhcp server for 2 distinct purposes on the same device.
> The first is a user facing dhcp server, the second is a internal facing
> dhcp server used for card management in a bladed chassis. We wanted a way
> of identifying/filtering log messages from the internal server separately
> from the user facing server.
>
> So here's a patch that allows you to specify a --log-facility on the
> command line. It needs cleaning up to remove some tags we use for tracking
> our changes to upstream code if there is interest I'll do so.
>
> Thanks,
> Chris
>
> --- 8< ---
> From 699fd72596026b911ce64a86a7000fb704da12c1 Mon Sep 17 00:00:00 2001
> From: Chris Packham <chris.packham at alliedtelesis.co.nz>
> Date: Mon, 12 Nov 2012 12:40:57 +1300
> Subject: [dhcp PATCH] server: Add --log-facility option
>
> The --log-facility option allows the user to specify which log facility
> should be used when generating log messages. If not specified the
> default DHCPD_LOG_FACILITY is used.
>
> Note that because this is set by a command line option, log messages
> related to the command line options will still have the facility set to
> DHCPD_LOG_FACILITY. The log facility is updated after option parsing is
> done.
>
> Reviewed-by: Mark McKinstry <mark.mckinstry at alliedtelesis.co.nz>
> ---
> common/Makefile.am | 2 +-
> common/Makefile.in | 5 +++--
> common/log.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> server/dhcpd.c | 24 +++++++++++++++++++++++-
> 4 files changed, 69 insertions(+), 4 deletions(-)
> create mode 100644 common/log.c
>
> diff --git a/common/Makefile.am b/common/Makefile.am
> index e4d4f9c..689b38d 100644
> --- a/common/Makefile.am
> +++ b/common/Makefile.am
> @@ -6,7 +6,7 @@ libdhcp_a_SOURCES = alloc.c bpf.c comapi.c conflex.c
> ctrace.c discover.c \
> dispatch.c dlpi.c dns.c ethernet.c execute.c fddi.c \
> icmp.c inet.c lpf.c memory.c nit.c ns_name.c options.c \
> packet.c parse.c print.c raw.c resolv.c socket.c \
> - tables.c tr.c tree.c upf.c
> + tables.c tr.c tree.c upf.c log.c
> man_MANS = dhcp-eval.5 dhcp-options.5
> EXTRA_DIST = $(man_MANS)
>
> diff --git a/common/Makefile.in b/common/Makefile.in
> index 3c39008..842f8a0 100644
> --- a/common/Makefile.in
> +++ b/common/Makefile.in
> @@ -52,7 +52,7 @@ am_libdhcp_a_OBJECTS = alloc.$(OBJEXT) bpf.$(OBJEXT)
> comapi.$(OBJEXT) \
> nit.$(OBJEXT) ns_name.$(OBJEXT) options.$(OBJEXT) \
> packet.$(OBJEXT) parse.$(OBJEXT) print.$(OBJEXT) raw.$(OBJEXT) \
> resolv.$(OBJEXT) socket.$(OBJEXT) tables.$(OBJEXT) \
> - tr.$(OBJEXT) tree.$(OBJEXT) upf.$(OBJEXT)
> + tr.$(OBJEXT) tree.$(OBJEXT) upf.$(OBJEXT) log.$(OBJEXT)
> libdhcp_a_OBJECTS = $(am_libdhcp_a_OBJECTS)
> DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)/includes
> depcomp = $(SHELL) $(top_srcdir)/depcomp
> @@ -178,7 +178,7 @@ libdhcp_a_SOURCES = alloc.c bpf.c comapi.c conflex.c
> ctrace.c discover.c \
> dispatch.c dlpi.c dns.c ethernet.c execute.c fddi.c \
> icmp.c inet.c lpf.c memory.c nit.c ns_name.c options.c \
> packet.c parse.c print.c raw.c resolv.c socket.c \
> - tables.c tr.c tree.c upf.c
> + tables.c tr.c tree.c upf.c log.c
>
> man_MANS = dhcp-eval.5 dhcp-options.5
> EXTRA_DIST = $(man_MANS)
> @@ -244,6 +244,7 @@ distclean-compile:
> @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/fddi.Po at am__quote@
> @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/icmp.Po at am__quote@
> @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/inet.Po at am__quote@
> + at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/log.Po at am__quote@
> @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/lpf.Po at am__quote@
> @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/memory.Po at am__quote@
> @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/nit.Po at am__quote@
> diff --git a/common/log.c b/common/log.c
> new file mode 100644
> index 0000000..28552ac
> --- /dev/null
> +++ b/common/log.c
> @@ -0,0 +1,42 @@
> +/* ATL addition - add --log-facility option */
> +/*
> + * log.c
> + *
> + * There is a naming conflict between the dhctoken.h enum member "CODE"
> + * and the syslog.h typedef "CODE" (which appears when you define
> + * SYSLOG_NAMES). To avoid this conflict it is necessary to have the
> + * syslog name parsing in a file that does not include dhctoken.h.
> + *
> + * Copyright (c) 2012 Allied Telesis Labs
> + */
> +#include "config.h"
> +#include <stdio.h>
> +#define SYSLOG_NAMES
> +#include <syslog.h>
> +
> +static int decode_syslog_name(char *name, CODE *codetab)
> +{
> + CODE *c;
> +
> + if (isdigit(*name))
> + return atoi(name);
> + for (c = codetab; c->c_name; c++) {
> + if (!strcasecmp(name, c->c_name)) {
> + return c->c_val;
> + }
> + }
> +
> + return -1;
> +}
> +
> +int parse_log_facility (const char *name, int def)
> +{
> + int facility;
> +
> + if ((facility = decode_syslog_name(name, facilitynames)) < 0)
> + facility = def;
> +
> + return facility;
> +}
> +/* ATL addition end. */
> +
> diff --git a/server/dhcpd.c b/server/dhcpd.c
> index 4c32c59..37816a3 100644
> --- a/server/dhcpd.c
> +++ b/server/dhcpd.c
> @@ -71,6 +71,10 @@ static const char url [] =
> # undef group
> #endif /* PARANOIA */
>
> +/* ATL addition - add --log-facility option */
> +extern int parse_log_facility (const char *name, int def);
> +/* ATL addition end. */
> +
> static void usage(void);
>
> struct iaddr server_identifier;
> @@ -272,7 +276,6 @@ dhcp_signal_init ()
> }
> /* ATL addition end. */
>
> -
> #if defined (PARANOIA)
> /* to be used in one of two possible scenarios */
> static void setup_chroot (char *chroot_dir) {
> @@ -331,6 +334,9 @@ main(int argc, char **argv) {
> uid_t set_uid = 0;
> gid_t set_gid = 0;
> #endif /* PARANOIA */
> +/* ATL addition - add --log-facility option */
> + int log_facility;
> +/* ATL addition end */
>
> /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
> 2 (stderr) are open. To do this, we assume that when we
> @@ -471,6 +477,12 @@ main(int argc, char **argv) {
> traceinfile = argv [i];
> trace_replay_init ();
> #endif /* TRACING */
> +/* ATL addition - add --log-facility option */
> + } else if (!strcmp (argv [i], "--log-facility")) {
> + if (++i == argc)
> + usage();
> + log_facility = parse_log_facility(argv[i], DHCPD_LOG_FACILITY);
> +/* ATL addition end */
> } else if (argv [i][0] == '-') {
> usage ();
> } else {
> @@ -496,6 +508,13 @@ main(int argc, char **argv) {
> }
> }
>
> +/* ATL addition - add --log-facility option */
> + if (log_facility != DHCPD_LOG_FACILITY) {
> + closelog();
> + openlog ("dhcpd", LOG_NDELAY|LOG_PID, log_facility);
> + }
> +/* ATL addition end */
> +
> if (!no_dhcpd_conf && (s = getenv ("PATH_DHCPD_CONF"))) {
> path_dhcpd_conf = s;
> }
> @@ -1375,6 +1394,9 @@ usage(void) {
> " [-play trace-input-file]\n"
> #endif /* TRACING */
> " [-pf pid-file] [--no-pid] [-s server]\n"
> +/* ATL addition - add --log-facility option */
> + " [--log-facility facility]\n"
> +/* ATL addition end */
> " [if0 [...ifN]]");
> }
>
> --
> 1.7.10.2.dirty
>
>
>
> NOTICE: This message contains privileged and confidential
> information intended only for the use of the addressee
> named above. If you are not the intended recipient of
> this message you are hereby notified that you must not
> disseminate, copy or take any action in reliance on it.
> If you have received this message in error please
> notify Allied Telesis Labs Ltd immediately.
> Any views expressed in this message are those of the
> individual sender, except where the sender has the
> authority to issue and specifically states them to
> be the views of Allied Telesis Labs.
> _______________________________________________
> dhcp-users mailing list
> dhcp-users at lists.isc.org
> https://lists.isc.org/mailman/listinfo/dhcp-users
>
More information about the dhcp-users
mailing list