summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2019-09-19 16:01:00 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2019-09-19 16:01:00 +0000
commitb7b5a3b76ceb4906268281b75a2371db531d142a (patch)
tree6e63cd34d02e18bd0fd64e00751ddea482a14230 /usr.sbin
parent2c2ca45372aad7e879307504802ce50f04545a8b (diff)
second attempt at fixing how we display inet6 addresses in smtpd. this diff
is simpler than my initial reverted attempt, corrects the likely reason for the initial revert and has been running successfully for the day on my MX with tons of incoming and outgoing inet6 trafic. ok millert@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/envelope.c11
-rw-r--r--usr.sbin/smtpd/smtp_session.c21
-rw-r--r--usr.sbin/smtpd/to.c25
3 files changed, 44 insertions, 13 deletions
diff --git a/usr.sbin/smtpd/envelope.c b/usr.sbin/smtpd/envelope.c
index 77c5bf1e847..01957dc5953 100644
--- a/usr.sbin/smtpd/envelope.c
+++ b/usr.sbin/smtpd/envelope.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: envelope.c,v 1.45 2019/08/14 21:11:25 gilles Exp $ */
+/* $OpenBSD: envelope.c,v 1.46 2019/09/19 16:00:59 gilles Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -297,12 +297,21 @@ ascii_load_sockaddr(struct sockaddr_storage *ss, char *buf)
ss->ss_family = AF_LOCAL;
}
else if (strncasecmp("IPv6:", buf, 5) == 0) {
+ /* XXX - remove this after 6.6 release */
if (inet_pton(AF_INET6, buf + 5, &ssin6.sin6_addr) != 1)
return 0;
ssin6.sin6_family = AF_INET6;
memcpy(ss, &ssin6, sizeof(ssin6));
ss->ss_len = sizeof(struct sockaddr_in6);
}
+ else if (buf[0] == '[' && buf[strlen(buf)-1] == ']') {
+ buf[strlen(buf)-1] = '\0';
+ if (inet_pton(AF_INET6, buf+1, &ssin6.sin6_addr) != 1)
+ return 0;
+ ssin6.sin6_family = AF_INET6;
+ memcpy(ss, &ssin6, sizeof(ssin6));
+ ss->ss_len = sizeof(struct sockaddr_in6);
+ }
else {
if (inet_pton(AF_INET, buf, &ssin.sin_addr) != 1)
return 0;
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index 3ca60d2526d..4e4978e4847 100644
--- a/usr.sbin/smtpd/smtp_session.c
+++ b/usr.sbin/smtpd/smtp_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp_session.c,v 1.410 2019/09/11 04:19:19 martijn Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.411 2019/09/19 16:00:59 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -1744,10 +1744,13 @@ smtp_proceed_helo(struct smtp_session *s, const char *args)
report_smtp_link_identify("smtp-in", s->id, "HELO", s->helo);
smtp_enter_state(s, STATE_HELO);
- smtp_reply(s, "250 %s Hello %s [%s], pleased to meet you",
+
+ smtp_reply(s, "250 %s Hello %s %s%s%s, pleased to meet you",
s->smtpname,
s->helo,
- ss_to_text(&s->ss));
+ s->ss.ss_family == AF_INET6 ? "" : "[",
+ ss_to_text(&s->ss),
+ s->ss.ss_family == AF_INET6 ? "" : "]");
}
static void
@@ -1761,10 +1764,12 @@ smtp_proceed_ehlo(struct smtp_session *s, const char *args)
report_smtp_link_identify("smtp-in", s->id, "EHLO", s->helo);
smtp_enter_state(s, STATE_HELO);
- smtp_reply(s, "250-%s Hello %s [%s], pleased to meet you",
+ smtp_reply(s, "250-%s Hello %s %s%s%s, pleased to meet you",
s->smtpname,
s->helo,
- ss_to_text(&s->ss));
+ s->ss.ss_family == AF_INET6 ? "" : "[",
+ ss_to_text(&s->ss),
+ s->ss.ss_family == AF_INET6 ? "" : "]");
smtp_reply(s, "250-8BITMIME");
smtp_reply(s, "250-ENHANCEDSTATUSCODES");
@@ -2835,10 +2840,12 @@ smtp_message_begin(struct smtp_tx *tx)
m_printf(tx, "Received: ");
if (!(s->listener->flags & F_MASK_SOURCE)) {
- m_printf(tx, "from %s (%s [%s])",
+ m_printf(tx, "from %s (%s %s%s%s)",
s->helo,
s->rdns,
- ss_to_text(&s->ss));
+ s->ss.ss_family == AF_INET6 ? "" : "[",
+ ss_to_text(&s->ss),
+ s->ss.ss_family == AF_INET6 ? "" : "]");
}
m_printf(tx, "\n\tby %s (%s) with %sSMTP%s%s id %08x",
s->smtpname,
diff --git a/usr.sbin/smtpd/to.c b/usr.sbin/smtpd/to.c
index 1ad991e2fda..addeda1c0a1 100644
--- a/usr.sbin/smtpd/to.c
+++ b/usr.sbin/smtpd/to.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: to.c,v 1.42 2019/09/02 21:59:27 gilles Exp $ */
+/* $OpenBSD: to.c,v 1.43 2019/09/19 16:00:59 gilles Exp $ */
/*
* Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
@@ -169,10 +169,9 @@ sa_to_text(const struct sockaddr *sa)
const struct in6_addr *in6_addr;
in6 = (const struct sockaddr_in6 *)sa;
- (void)strlcpy(buf, "IPv6:", sizeof(buf));
- p = buf + 5;
+ p = buf;
in6_addr = &in6->sin6_addr;
- (void)bsnprintf(p, NI_MAXHOST, "%s", in6addr_to_text(in6_addr));
+ (void)bsnprintf(p, NI_MAXHOST, "[%s]", in6addr_to_text(in6_addr));
}
return (buf);
@@ -270,6 +269,8 @@ text_to_netaddr(struct netaddr *netaddr, const char *s)
struct sockaddr_in ssin;
struct sockaddr_in6 ssin6;
int bits;
+ char buf[NI_MAXHOST];
+ size_t len;
memset(&ssin, 0, sizeof(struct sockaddr_in));
memset(&ssin6, 0, sizeof(struct sockaddr_in6));
@@ -284,7 +285,21 @@ text_to_netaddr(struct netaddr *netaddr, const char *s)
memcpy(&ss, &ssin, sizeof(ssin));
ss.ss_len = sizeof(struct sockaddr_in);
} else {
- bits = inet_net_pton(AF_INET6, s, &ssin6.sin6_addr,
+ if (s[0] != '[') {
+ if ((len = strlcpy(buf, s, sizeof buf)) >= sizeof buf)
+ return 0;
+ }
+ else {
+ s++;
+ if (strncasecmp("IPv6:", s, 5) == 0)
+ s += 5;
+ if ((len = strlcpy(buf, s, sizeof buf)) >= sizeof buf)
+ return 0;
+ if (buf[len-1] != ']')
+ return 0;
+ buf[len-1] = 0;
+ }
+ bits = inet_net_pton(AF_INET6, buf, &ssin6.sin6_addr,
sizeof(struct in6_addr));
if (bits == -1)
return 0;