syslogd: Add FreeBSD and NetBSD -n flag to disable DNS query

This patch re-adds the -n flag, but now to disable DNS reverse-query for
all incoming messages.  This can potentially speed up logging a lot for
small/embedded systems that act as log sink.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-13 17:16:51 +01:00
parent cf9d281e5b
commit 0f0f8f845d
2 changed files with 43 additions and 30 deletions

View File

@ -13,7 +13,7 @@
.Nd System Log Daemon .Nd System Log Daemon
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl ?46AdFksTv .Op Fl ?46AdFknsTv
.Op Fl a Ar addr[/len][:port] .Op Fl a Ar addr[/len][:port]
.Op Fl a Ar name[:port] .Op Fl a Ar name[:port]
.Op Fl b Ar addr[:port] .Op Fl b Ar addr[:port]
@ -177,19 +177,6 @@ for details.
.It Fl f Ar file .It Fl f Ar file
Specify an alternative configuration file instead of the default Specify an alternative configuration file instead of the default
.Pa /etc/syslog.conf . .Pa /etc/syslog.conf .
.It Fl m Ar seconds
.Nm
logs a mark timestamp regularly. The default interval between two
.Ql -- MARK --
lines is 20 minutes. This can be changed with this option. Setting
this to zero disables log marks entirely.
.Pp
Depending on other log messages generated these lines may not be written
consecutively. The
.Ql -- MARK --
message is only written if the log file hasn't been touched in
.Ar (seconds * 60) / 2
minutes.
.It Fl k .It Fl k
Disable the translation of messages received with facility Disable the translation of messages received with facility
.Ql kern .Ql kern
@ -203,6 +190,21 @@ facility is reserved for kernel log messages. When the
daemon runs alongside daemon runs alongside
.Nm , .Nm ,
this option is always set. this option is always set.
.It Fl m Ar seconds
.Nm
logs a mark timestamp regularly. The default interval between two
.Ql -- MARK --
lines is 20 minutes. This can be changed with this option. Setting
this to zero disables log marks entirely.
.Pp
Depending on other log messages generated these lines may not be written
consecutively. The
.Ql -- MARK --
message is only written if the log file hasn't been touched in
.Ar (seconds * 60) / 2
minutes.
.It Fl n
Disable DNS query for every request.
.It Fl P Ar file .It Fl P Ar file
Specify an alternate file in which to store the process ID. Specify an alternate file in which to store the process ID.
The default is The default is

View File

@ -119,6 +119,7 @@ struct filed consfile;
static int Debug; /* debug flag */ static int Debug; /* debug flag */
static int Foreground = 0; /* don't fork - don't run in daemon mode */ static int Foreground = 0; /* don't fork - don't run in daemon mode */
static int resolve = 1; /* resolve hostname */
static char LocalHostName[MAXHOSTNAMELEN + 1]; /* our hostname */ static char LocalHostName[MAXHOSTNAMELEN + 1]; /* our hostname */
static char *LocalDomain; /* our local domain name */ static char *LocalDomain; /* our local domain name */
static char *emptystring = ""; static char *emptystring = "";
@ -165,7 +166,7 @@ void endtty();
void wallmsg(struct filed *f, struct iovec *iov, int iovcnt); void wallmsg(struct filed *f, struct iovec *iov, int iovcnt);
void reapchild(); void reapchild();
const char *cvtaddr(struct sockaddr_storage *f, int len); const char *cvtaddr(struct sockaddr_storage *f, int len);
const char *cvthname(struct sockaddr_storage *f, socklen_t len); const char *cvthname(struct sockaddr *f, socklen_t len);
void domark(); void domark();
void debug_switch(); void debug_switch();
void die(int sig); void die(int sig);
@ -194,8 +195,8 @@ static int addpeer(struct peer *pe0)
int usage(int code) int usage(int code)
{ {
printf("Usage:\n" printf("Usage:\n"
" syslogd [-46AdFkrsv?] [-a PEER] [-b :PORT] [-b ADDR[:PORT]] [-f FILE] [-m SEC]\n" " syslogd [-46AdFknsTv?] [-a PEER] [-b :PORT] [-b ADDR[:PORT]] [-f FILE]\n"
" [-P PID_FILE] [-p SOCK_PATH] [-R SIZE[:NUM]]\n" " [-m SEC] [-P PID_FILE] [-p SOCK_PATH] [-R SIZE[:NUM]]\n"
"Options:\n" "Options:\n"
" -4 Force IPv4 only\n" " -4 Force IPv4 only\n"
" -6 Force IPv6 only\n" " -6 Force IPv6 only\n"
@ -225,6 +226,7 @@ int usage(int code)
" -f FILE Alternate .conf file, default: /etc/syslog.conf\n" " -f FILE Alternate .conf file, default: /etc/syslog.conf\n"
" -k Allow logging with facility 'kernel', otherwise remapped to 'user'.\n" " -k Allow logging with facility 'kernel', otherwise remapped to 'user'.\n"
" -m SEC Interval between MARK messages in log, 0 to disable, default: 20 min\n" " -m SEC Interval between MARK messages in log, 0 to disable, default: 20 min\n"
" -n Disable DNS query for every request\n"
" -P FILE File to store the process ID, default: %s\n" " -P FILE File to store the process ID, default: %s\n"
" -p PATH Path to UNIX domain socket, multiple -p create multiple sockets. If\n" " -p PATH Path to UNIX domain socket, multiple -p create multiple sockets. If\n"
" no -p argument is given the default %s is used\n" " no -p argument is given the default %s is used\n"
@ -263,7 +265,7 @@ int main(int argc, char *argv[])
KeepKernFac = 1; KeepKernFac = 1;
#endif #endif
while ((ch = getopt(argc, argv, "46Aa:b:dHFf:m:P:p:r:sv?")) != EOF) { while ((ch = getopt(argc, argv, "46Aa:b:dHFf:m:nP:p:r:sv?")) != EOF) {
switch ((char)ch) { switch ((char)ch) {
case '4': case '4':
family = PF_INET; family = PF_INET;
@ -317,6 +319,10 @@ int main(int argc, char *argv[])
MarkInterval = atoi(optarg) * 60; MarkInterval = atoi(optarg) * 60;
break; break;
case 'n':
resolve = 0;
break;
case 'P': case 'P':
PidFile = optarg; PidFile = optarg;
break; break;
@ -613,7 +619,7 @@ static void inet_cb(int sd, void *arg)
return; return;
} }
hname = cvthname(&ss, sslen); hname = cvthname((struct sockaddr *)&ss, sslen);
unmapped(sa); unmapped(sa);
if (!validate(sa, hname)) { if (!validate(sa, hname)) {
logit("Message from %s was ignored.\n", hname); logit("Message from %s was ignored.\n", hname);
@ -1851,26 +1857,30 @@ const char *cvtaddr(struct sockaddr_storage *f, int len)
* Callers of cvthname() need to know that if NULL is returned then * Callers of cvthname() need to know that if NULL is returned then
* the host is to be ignored. * the host is to be ignored.
*/ */
const char *cvthname(struct sockaddr_storage *f, socklen_t len) const char *cvthname(struct sockaddr *f, socklen_t len)
{ {
static char hname[NI_MAXHOST]; static char hname[NI_MAXHOST], ip[NI_MAXHOST];
char *p; char *p;
int err; int err;
err = getnameinfo((struct sockaddr *)f, len, hname, NI_MAXHOST, NULL, 0, NI_NAMEREQD); err = getnameinfo(f, len, ip, sizeof(ip), NULL, 0, NI_NUMERICHOST);
if (err) { if (err) {
logit("Host name for your address (%s) unknown: %s\n", hname, gai_strerror(err)); logit("Malformed from address: %s\n", gai_strerror(err));
return "???";
}
err = getnameinfo((struct sockaddr *)f, len, hname, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (!resolve)
if (err) { return ip;
logit("Malformed from address: %s\n", gai_strerror(err));
return "???"; err = getnameinfo(f, len, hname, sizeof(hname), NULL, 0, NI_NAMEREQD);
} if (err) {
return hname; logit("Host name for your address (%s) unknown: %s\n",
ip, gai_strerror(err));
return ip;
} }
/* /*
* Convert to lower case, just like LocalDomain above * Convert to lower case, just like LocalDomain in init()
*/ */
for (p = hname; *p; p++) { for (p = hname; *p; p++) {
if (isupper(*p)) if (isupper(*p))
@ -1878,6 +1888,7 @@ const char *cvthname(struct sockaddr_storage *f, socklen_t len)
} }
/* /*
* BSD has trimdomain(h1, ...), we implement our own here.
* Notice that the string still contains the fqdn, but your * Notice that the string still contains the fqdn, but your
* hostname and domain are separated by a '\0'. * hostname and domain are separated by a '\0'.
*/ */