From owner-svn-src-head@FreeBSD.ORG Tue Jun 16 22:26:23 2015 Return-Path: Delivered-To: svn-src-head@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E1E87E3E; Tue, 16 Jun 2015 22:26:23 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CFB70E1E; Tue, 16 Jun 2015 22:26:23 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5GMQNt5040579; Tue, 16 Jun 2015 22:26:23 GMT (envelope-from rpaulo@FreeBSD.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t5GMQNYR040577; Tue, 16 Jun 2015 22:26:23 GMT (envelope-from rpaulo@FreeBSD.org) Message-Id: <201506162226.t5GMQNYR040577@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: rpaulo set sender to rpaulo@FreeBSD.org using -f From: Rui Paulo Date: Tue, 16 Jun 2015 22:26:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284474 - head/usr.sbin/syslogd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jun 2015 22:26:24 -0000 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 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++; }