1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 16:42:56 -08:00

Send and receive UDP syslog packets on the IPv6 socket.

OK henning@
This commit is contained in:
bluhm 2014-08-21 17:00:34 +00:00
parent e4f7a38755
commit e470716cac
2 changed files with 45 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: privsep.c,v 1.39 2014/08/21 00:04:58 bluhm Exp $ */
/* $OpenBSD: privsep.c,v 1.40 2014/08/21 17:00:34 bluhm Exp $ */
/*
* Copyright (c) 2003 Anil Madhavapeddy <anil@recoil.org>
@ -177,6 +177,8 @@ priv_init(char *conf, int numeric, int lockfd, int nullfd, char *argv[])
close(pfd[PFD_UNIX_0 + i].fd);
if (pfd[PFD_INET].fd != -1)
close(pfd[PFD_INET].fd);
if (pfd[PFD_INET6].fd != -1)
close(pfd[PFD_INET6].fd);
if (pfd[PFD_CTLSOCK].fd != -1)
close(pfd[PFD_CTLSOCK].fd);
if (pfd[PFD_CTLCONN].fd != -1)
@ -306,8 +308,8 @@ priv_init(char *conf, int numeric, int lockfd, int nullfd, char *argv[])
must_read(socks[0], &servname, servname_len);
servname[servname_len - 1] = '\0';
memset(&hints, '\0', sizeof(hints));
hints.ai_family = AF_INET;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
i = getaddrinfo(hostname, servname, &hints, &res0);
if (i != 0 || res0 == NULL) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: syslogd.c,v 1.115 2014/08/21 00:04:58 bluhm Exp $ */
/* $OpenBSD: syslogd.c,v 1.116 2014/08/21 17:00:34 bluhm Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
@ -189,7 +189,6 @@ int Debug; /* debug flag */
int Startup = 1; /* startup flag */
char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */
char *LocalDomain; /* our local domain name */
int InetInuse = 0; /* non-zero if INET sockets are being used */
int Initialized = 0; /* set when we have initialized ourselves */
int MarkInterval = 20 * 60; /* interval between marks in seconds */
@ -284,7 +283,7 @@ main(int argc, char *argv[])
{
int ch, i, linesize, fd;
struct sockaddr_un fromunix;
struct sockaddr_in frominet;
struct sockaddr_storage from;
socklen_t len;
char *p, *line;
char resolve[MAXHOSTNAMELEN];
@ -371,7 +370,7 @@ main(int argc, char *argv[])
}
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_flags = AI_PASSIVE;
@ -386,13 +385,14 @@ main(int argc, char *argv[])
for (res = res0; res; res = res->ai_next) {
struct pollfd *pfdp;
if (res->ai_family == AF_INET)
switch (res->ai_family) {
case AF_INET:
pfdp = &pfd[PFD_INET];
else {
/*
* XXX AF_INET6 is skipped on purpose, need to
* fix '@' handling first.
*/
break;
case AF_INET6:
pfdp = &pfd[PFD_INET6];
break;
default:
continue;
}
@ -412,7 +412,6 @@ main(int argc, char *argv[])
continue;
}
InetInuse = 1;
pfdp->fd = fd;
if (SecureMode)
shutdown(pfdp->fd, SHUT_RD);
@ -584,18 +583,31 @@ main(int argc, char *argv[])
}
}
if ((pfd[PFD_INET].revents & POLLIN) != 0) {
len = sizeof(frominet);
len = sizeof(from);
i = recvfrom(pfd[PFD_INET].fd, line, MAXLINE, 0,
(struct sockaddr *)&frominet, &len);
(struct sockaddr *)&from, &len);
if (i > 0) {
line[i] = '\0';
cvthname((struct sockaddr *)&frominet, resolve,
sizeof resolve);
cvthname((struct sockaddr *)&from, resolve,
sizeof(resolve));
dprintf("cvthname res: %s\n", resolve);
printline(resolve, line);
} else if (i < 0 && errno != EINTR)
logerror("recvfrom inet");
}
if ((pfd[PFD_INET6].revents & POLLIN) != 0) {
len = sizeof(from);
i = recvfrom(pfd[PFD_INET6].fd, line, MAXLINE, 0,
(struct sockaddr *)&from, &len);
if (i > 0) {
line[i] = '\0';
cvthname((struct sockaddr *)&from, resolve,
sizeof(resolve));
dprintf("cvthname res: %s\n", resolve);
printline(resolve, line);
} else if (i < 0 && errno != EINTR)
logerror("recvfrom inet6");
}
if ((pfd[PFD_CTLSOCK].revents & POLLIN) != 0)
ctlsock_accept_handler();
if ((pfd[PFD_CTLCONN].revents & POLLIN) != 0)
@ -851,7 +863,7 @@ fprintlog(struct filed *f, int flags, char *msg)
{
struct iovec iov[6];
struct iovec *v;
int l, retryonce;
int fd, l, retryonce;
char line[MAXLINE + 1], repbuf[80], greetings[500];
v = iov;
@ -908,13 +920,24 @@ fprintlog(struct filed *f, int flags, char *msg)
case F_FORW:
dprintf(" %s\n", f->f_un.f_forw.f_loghost);
switch (f->f_un.f_forw.f_addr.ss_family) {
case AF_INET:
fd = pfd[PFD_INET].fd;
break;
case AF_INET6:
fd = pfd[PFD_INET6].fd;
break;
default:
fd = -1;
break;
}
if ((l = snprintf(line, sizeof(line), "<%d>%.15s %s%s%s",
f->f_prevpri, (char *)iov[0].iov_base,
IncludeHostname ? LocalHostName : "",
IncludeHostname ? " " : "",
(char *)iov[4].iov_base)) >= sizeof(line) || l == -1)
l = strlen(line);
if (sendto(pfd[PFD_INET].fd, line, l, 0,
if (sendto(fd, line, l, 0,
(struct sockaddr *)&f->f_un.f_forw.f_addr,
f->f_un.f_forw.f_addr.ss_len) != l) {
switch (errno) {
@ -1510,8 +1533,6 @@ cfline(char *line, char *prog)
switch (*p) {
case '@':
if (!InetInuse)
break;
if ((strlcpy(f->f_un.f_forw.f_loghost, p,
sizeof(f->f_un.f_forw.f_loghost)) >=
sizeof(f->f_un.f_forw.f_loghost))) {