Date: Tue, 16 Jun 2015 22:26:23 +0000 (UTC) From: Rui Paulo <rpaulo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284474 - head/usr.sbin/syslogd Message-ID: <201506162226.t5GMQNYR040577@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rpaulo Date: Tue Jun 16 22:26:22 2015 New Revision: 284474 URL: https://svnweb.freebsd.org/changeset/base/284474 Log: syslogd: support multiple -b options. It's now possible to bind multiple sockets to different IP addresses. PR: 159305 Submitted by: Kurt Lidl <lidl pix.net> Sponsored by: Pi-Coral, Inc. Modified: head/usr.sbin/syslogd/syslogd.8 head/usr.sbin/syslogd/syslogd.c Modified: head/usr.sbin/syslogd/syslogd.8 ============================================================================== --- head/usr.sbin/syslogd/syslogd.8 Tue Jun 16 22:25:08 2015 (r284473) +++ head/usr.sbin/syslogd/syslogd.8 Tue Jun 16 22:26:22 2015 (r284474) @@ -28,7 +28,7 @@ .\" @(#)syslogd.8 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd March 3, 2015 +.Dd June 16, 2015 .Dt SYSLOGD 8 .Os .Sh NAME @@ -194,6 +194,8 @@ The default .Ar service is .Ql syslog . +This option can be specified multiple times to bind to +multiple addresses and/or ports. .It Fl C Create log files that do not exist (permission is set to .Li 0600 ) . Modified: head/usr.sbin/syslogd/syslogd.c ============================================================================== --- head/usr.sbin/syslogd/syslogd.c Tue Jun 16 22:25:08 2015 (r284473) +++ head/usr.sbin/syslogd/syslogd.c Tue Jun 16 22:26:22 2015 (r284474) @@ -124,6 +124,15 @@ const char ctty[] = _PATH_CONSOLE; #define MAXUNAMES 20 /* maximum number of user names */ /* + * List of hosts for binding. + */ +static STAILQ_HEAD(, host) hqueue; +struct host { + char *name; + STAILQ_ENTRY(host) next; +}; + +/* * Unix sockets. * We have two default sockets, one with 666 permissions, * and one for privileged programs. @@ -275,7 +284,7 @@ static int Foreground = 0; /* Run in for static int resolve = 1; /* resolve hostname */ static char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ static const char *LocalDomain; /* our local domain name */ -static int *finet; /* Internet datagram socket */ +static int *finet; /* Internet datagram sockets */ static int fklog = -1; /* /dev/klog */ static int Initialized; /* set when we have initialized ourselves */ static int MarkInterval = 20 * 60; /* interval between marks in seconds */ @@ -348,10 +357,10 @@ main(int argc, char *argv[]) struct sockaddr_storage frominet; fd_set *fdsr = NULL; char line[MAXLINE + 1]; - char *bindhostname; const char *hname; struct timeval tv, *tvp; struct sigaction sact; + struct host *host; struct funix *fx, *fx1; sigset_t mask; pid_t ppid = 1, spid; @@ -360,7 +369,8 @@ main(int argc, char *argv[]) if (madvise(NULL, 0, MADV_PROTECT) != 0) dprintf("madvise() failed: %s\n", strerror(errno)); - bindhostname = NULL; + STAILQ_INIT(&hqueue); + while ((ch = getopt(argc, argv, "468Aa:b:cCdf:Fkl:m:nNop:P:sS:Tuv")) != -1) switch (ch) { @@ -383,8 +393,13 @@ main(int argc, char *argv[]) usage(); break; case 'b': - bindhostname = optarg; + { + if ((host = malloc(sizeof(struct host))) == NULL) + err(1, "malloc failed"); + host->name = optarg; + STAILQ_INSERT_TAIL(&hqueue, host, next); break; + } case 'c': no_compress++; break; @@ -433,7 +448,7 @@ main(int argc, char *argv[]) if (strlen(name) >= sizeof(sunx.sun_path)) errx(1, "%s path too long, exiting", name); if ((fx = malloc(sizeof(struct funix))) == NULL) - errx(1, "malloc failed"); + err(1, "malloc failed"); fx->s = -1; fx->name = name; fx->mode = mode; @@ -555,8 +570,26 @@ main(int argc, char *argv[]) } increase_rcvbuf(fx->s); } - if (SecureMode <= 1) - finet = socksetup(family, bindhostname); + if (SecureMode <= 1) { + if (STAILQ_EMPTY(&hqueue)) + finet = socksetup(family, NULL); + STAILQ_FOREACH(host, &hqueue, next) { + int *finet0, total; + finet0 = socksetup(family, host->name); + if (finet0 && !finet) { + finet = finet0; + } else if (finet0 && finet) { + total = *finet0 + *finet + 1; + finet = realloc(finet, total * sizeof(int)); + if (finet == NULL) + err(1, "realloc failed"); + for (i = 1; i <= *finet0; i++) { + finet[(*finet)+i] = finet0[i]; + } + *finet = total - 1; + } + } + } if (finet) { if (SecureMode) { @@ -2730,6 +2763,7 @@ socksetup(int af, char *bindhostname) } (*socks)++; + dprintf("socksetup: new socket fd is %d\n", *s); s++; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201506162226.t5GMQNYR040577>