From c68a8e00e87c817ef711b3050da52b2cdec25274 Mon Sep 17 00:00:00 2001 From: christos Date: Mon, 27 May 2013 23:15:51 +0000 Subject: [PATCH] PR/47861: Fredrik Pettai: keep track of the address family for each socket opened and don't send the a message to the wrong family type. --- usr.sbin/syslogd/syslogd.c | 7 +++++-- usr.sbin/syslogd/syslogd.h | 3 ++- usr.sbin/syslogd/tls.c | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index d5c7ec7835bb..92d0c965dfff 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $NetBSD: syslogd.c,v 1.114 2013/01/17 18:54:28 christos Exp $ */ +/* $NetBSD: syslogd.c,v 1.115 2013/05/27 23:15:51 christos Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993, 1994\ #if 0 static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94"; #else -__RCSID("$NetBSD: syslogd.c,v 1.114 2013/01/17 18:54:28 christos Exp $"); +__RCSID("$NetBSD: syslogd.c,v 1.115 2013/05/27 23:15:51 christos Exp $"); #endif #endif /* not lint */ @@ -2496,6 +2496,8 @@ udp_send(struct filed *f, char *line, size_t len) for (r = f->f_un.f_forw.f_addr; r; r = r->ai_next) { retry = 0; for (j = 0; j < finet->fd; j++) { + if (finet[j+1].af != r->ai_family) + continue; sendagain: lsent = sendto(finet[j+1].fd, line, len, 0, r->ai_addr, r->ai_addrlen); @@ -3994,6 +3996,7 @@ socksetup(int af, const char *hostname) logerror("socket() failed"); continue; } + s->af = r->ai_family; if (r->ai_family == AF_INET6 && setsockopt(s->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) { logerror("setsockopt(IPV6_V6ONLY) failed"); diff --git a/usr.sbin/syslogd/syslogd.h b/usr.sbin/syslogd/syslogd.h index 171e74d30061..a11f7f9e5dc8 100644 --- a/usr.sbin/syslogd/syslogd.h +++ b/usr.sbin/syslogd/syslogd.h @@ -1,4 +1,4 @@ -/* $NetBSD: syslogd.h,v 1.3 2009/04/20 09:56:08 mschuett Exp $ */ +/* $NetBSD: syslogd.h,v 1.4 2013/05/27 23:15:51 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -302,6 +302,7 @@ STAILQ_HEAD(buf_queue_head, buf_queue); /* a pair of a socket and an associated event object */ struct socketEvent { int fd; + int af; struct event *ev; }; diff --git a/usr.sbin/syslogd/tls.c b/usr.sbin/syslogd/tls.c index 1f3e2ddcfc54..243ef2581e68 100644 --- a/usr.sbin/syslogd/tls.c +++ b/usr.sbin/syslogd/tls.c @@ -1,4 +1,4 @@ -/* $NetBSD: tls.c,v 1.10 2012/06/06 00:33:45 christos Exp $ */ +/* $NetBSD: tls.c,v 1.11 2013/05/27 23:15:51 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -45,7 +45,7 @@ */ #include -__RCSID("$NetBSD: tls.c,v 1.10 2012/06/06 00:33:45 christos Exp $"); +__RCSID("$NetBSD: tls.c,v 1.11 2013/05/27 23:15:51 christos Exp $"); #ifndef DISABLE_TLS #include "syslogd.h" @@ -851,6 +851,7 @@ socksetup_tls(const int af, const char *bindhostname, const char *port) logerror("socket() failed: %s", strerror(errno)); continue; } + s->af = r->ai_family; if (r->ai_family == AF_INET6 && setsockopt(s->fd, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {