]> git.ipfire.org Git - thirdparty/postfix.git/commitdiff
postfix-2.4.4 v2.4.4
authorWietse Venema <wietse@porcupine.org>
Tue, 31 Jul 2007 05:00:00 +0000 (00:00 -0500)
committerViktor Dukhovni <postfix-users@dukhovni.org>
Sat, 10 Feb 2018 20:20:37 +0000 (15:20 -0500)
14 files changed:
postfix/HISTORY
postfix/src/cleanup/cleanup_envelope.c
postfix/src/cleanup/cleanup_milter.c
postfix/src/global/mail_version.h
postfix/src/milter/milter.c
postfix/src/milter/milter.h
postfix/src/milter/milter8.c
postfix/src/smtp/smtp_connect.c
postfix/src/smtpd/smtpd.c
postfix/src/smtpstone/qmqp-source.c
postfix/src/smtpstone/smtp-source.c
postfix/src/util/Makefile.in
postfix/src/util/vstream.h
postfix/src/util/vstream_tweak.c [new file with mode: 0644]

index 38de6866191a8349c15c8ec5acf8e0cb209864ce..14d5ea8719f14729a4265d149252fee3d2742440 100644 (file)
@@ -13512,8 +13512,25 @@ Apologies for any names omitted.
 
 20070719
 
-       Cleanup: streamlined Milter client error handling, so that
-       the (Postfix SMTP server's Milter client) does not get out
-       of sync with Milter applications after the (cleanup server's
-       Milter client) encounters some non-recoverable problem.
-       Files: milter/milter8.c, smtpd/smtpd.c.
+       Cleanup: Milter client error handling, so that the (Postfix
+       SMTP server's Milter client) does not get out of sync with
+       Milter applications after the (cleanup server's Milter
+       client) encounters some non-recoverable problem.  Files:
+       milter/milter8.c, smtpd/smtpd.c.
+
+20070729
+
+       Performance: workaround for poor TCP performance on loopback
+       (127.0.0.1) connections. Problem reported by Mark Martinec.
+       Files: util/vstream_tweak.c, milter/milter8.c, smtp/smtp_connect.c,
+       smtpstone/*source.c.
+
+20070730
+
+       Bugfix: when a milter replied with ACCEPT at or before the
+       first RCPT command, the cleanup server would apply the
+       non_smtpd_milters setting as if the message was a local
+       submission. Problem reported by Jukka Salmi. Also, the
+       cleanup server would get out of sync with the milter when
+       a milter replied with ACCEPT at the DATA command. Files:
+       cleanup/cleanup_envelope.c, smtpd/smtpd.c, milter/milters.c.
index ef4dbc7dc36302c23a15590260a7e1aee5a9fbf8..830f37093dbe10525cab539f608bd011a428f503 100644 (file)
@@ -148,13 +148,7 @@ static void cleanup_envelope_process(CLEANUP_STATE *state, int type,
 #endif
     if (type == REC_TYPE_MILT_COUNT) {
        /* Not part of queue file format. */
-       if (state->milters != 0) {
-           msg_warn("%s: message rejected: too many milter instances",
-                    state->queue_id);
-           state->errs |= CLEANUP_STAT_BAD;
-           return;
-       }
-       if ((milter_count = atoi(buf)) > 0)
+       if ((milter_count = atoi(buf)) >= 0)
            cleanup_milter_receive(state, milter_count);
        return;
     }
index 2212604a39bb96fdeba2c21d7c8d7f0eae1929a7..51755e8f308558deed174ab49de95273732e7881 100644 (file)
@@ -1314,6 +1314,8 @@ static const char *cleanup_milter_eval(const char *name, void *ptr)
 
 void    cleanup_milter_receive(CLEANUP_STATE *state, int count)
 {
+    if (state->milters)
+       milter_free(state->milters);
     state->milters = milter_receive(state->src, count);
     milter_macro_callback(state->milters, cleanup_milter_eval, (void *) state);
     milter_edit_callback(state->milters,
index d260a5ce2a4323e61c29878ef5fb5cc2319b7c7b..570cb2613e34d47c44b2cb6234673cef6647eaca 100644 (file)
@@ -20,8 +20,8 @@
   * Patches change both the patchlevel and the release date. Snapshots have no
   * patchlevel; they change the release date only.
   */
-#define MAIL_RELEASE_DATE      "20070720"
-#define MAIL_VERSION_NUMBER    "2.4.4-RC4"
+#define MAIL_RELEASE_DATE      "20070731"
+#define MAIL_VERSION_NUMBER    "2.4.4"
 
 #ifdef SNAPSHOT
 # define MAIL_VERSION_DATE     "-" MAIL_RELEASE_DATE
index 51f968d80bddee06ef0d35a62c41cae2a3117798..2e0c73128459f304fd99077b0fa218399d7918d6 100644 (file)
 /*     MILTERS *milter_receive(fp, count)
 /*     VSTREAM *fp;
 /*     int     count;
+/*
+/*     int     milter_dummy(milters, fp)
+/*     MILTERS *milters;
+/*     VSTREAM *fp;
 /* DESCRIPTION
 /*     The functions in this module manage one or more milter (mail
 /*     filter) clients. Currently, only the Sendmail 8 filter
 /*     milter_receive() receives the specified number of mail
 /*     filters over the specified stream. The result is a null
 /*     pointer when no milters were sent, or when an error happened.
+/*
+/*     milter_dummy() is like milter_send(), except that it sends
+/*     a dummy, but entirely valid, mail filter list.
 /* SEE ALSO
 /*     milter8(3) Sendmail 8 Milter protocol
 /* DIAGNOSTICS
@@ -587,6 +594,16 @@ void    milter_free(MILTERS *milters)
 #define MAIL_ATTR_MILT_EOD     "eod_macros"
 #define MAIL_ATTR_MILT_UNK     "unk_macros"
 
+/* milter_dummy - send empty milter list */
+
+int     milter_dummy(MILTERS *milters, VSTREAM *stream)
+{
+    MILTERS dummy = *milters;
+
+    dummy.milter_list = 0;
+    return (milter_send(&dummy, stream));
+}
+
 /* milter_send - send Milter instances over stream */
 
 int     milter_send(MILTERS *milters, VSTREAM *stream)
@@ -606,8 +623,6 @@ int     milter_send(MILTERS *milters, VSTREAM *stream)
        for (m = milters->milter_list; m != 0; m = m->next)
            if (m->active(m))
                count++;
-    if (count == 0)
-       return (0);
     (void) rec_fprintf(stream, REC_TYPE_MILT_COUNT, "%d", count);
 
     /*
@@ -656,9 +671,6 @@ MILTERS *milter_receive(VSTREAM *stream, int count)
     VSTRING *eod_macros;
     VSTRING *unk_macros;
 
-    if (count == 0)
-       return (0);
-
     /*
      * Receive filter macros.
      */
index 676322d4a4b9a6b52036676c0f329487c9fbac8c..a1989e2792771945b76dd87851cae0626c5a309b 100644 (file)
@@ -99,6 +99,7 @@ extern const char *milter_unknown_event(MILTERS *, const char *);
 extern const char *milter_other_event(MILTERS *);
 extern void milter_abort(MILTERS *);
 extern void milter_disc_event(MILTERS *);
+extern int milter_dummy(MILTERS *, VSTREAM *);
 extern int milter_send(MILTERS *, VSTREAM *);
 extern MILTERS *milter_receive(VSTREAM *, int);
 extern void milter_free(MILTERS *);
index 2753d7c4b9443bab8681602ce3818de9e4bd29f3..2a0dc75004c961c859cc3d41441f0ef154afe63b 100644 (file)
@@ -442,15 +442,9 @@ static int milter8_conf_error(MILTER8 *milter)
     const char *reply;
 
     /*
-     * While reading the following, keep in mind that a client-side Milter
-     * socket is shared between the Postfix SMTP server and the cleanup
-     * server. The SMTP server reports only the SMTP events to the Milter.
-     * The cleanup server reports the headers and body to the Milter, and
-     * receives the header or body modification requests from the Milter.
-     * 
-     * XXX When the cleanup server closes its end of the Milter socket after
-     * some local/remote configuration error, the SMTP server is left out of
-     * sync with the Milter. Sending an ABORT to the Milters will not restore
+     * XXX When the cleanup server closes its end of the Milter socket while
+     * editing a queue file, the SMTP server is left out of sync with the
+     * Milter. Sending an ABORT to the Milters will not restore
      * synchronization, because there may be any number of Milter replies
      * already in flight. Workaround: poison the socket and force the SMTP
      * server to abandon it.
@@ -476,18 +470,12 @@ static int milter8_comm_error(MILTER8 *milter)
     const char *reply;
 
     /*
-     * While reading the following, keep in mind that a client-side Milter
-     * socket is shared between the Postfix SMTP server and the cleanup
-     * server. The SMTP server reports only the SMTP events to the Milter.
-     * The cleanup server reports the headers and body to the Milter, and
-     * receives the header or body modification requests from the Milter.
-     * 
-     * XXX When the cleanup server closes its end of the Milter socket after
-     * some local or remote remote protocol error, the SMTP server is left
-     * out of sync with the Milter. Sending an ABORT to the Milters will not
-     * restore synchronization, because there may be any number of Milter
-     * replies already in flight. Workaround: poison the socket and force the
-     * SMTP server to abandon it.
+     * XXX When the cleanup server closes its end of the Milter socket while
+     * editing a queue file, the SMTP server is left out of sync with the
+     * Milter. Sending an ABORT to the Milters will not restore
+     * synchronization, because there may be any number of Milter replies
+     * already in flight. Workaround: poison the socket and force the SMTP
+     * server to abandon it.
      */
     if (milter->fp != 0) {
        (void) shutdown(vstream_fileno(milter->fp), SHUT_RDWR);
@@ -1009,26 +997,21 @@ static const char *milter8_event(MILTER8 *milter, int event,
     /*
      * Receive the reply or replies.
      * 
-     * Intercept all loop exits so that we can do post body replacement
+     * Intercept all loop exits so that we can do post header/body edit
      * processing.
      * 
      * XXX Bound the loop iteration count.
      * 
-     * While reading the following, keep in mind that a client-side Milter
-     * socket is shared between the Postfix SMTP server and the cleanup
-     * server. The SMTP server reports only the SMTP events to the Milter.
-     * The cleanup server reports the headers and body to the Milter, and
-     * receives the header or body modification requests from the Milter.
-     * 
      * In the end-of-body stage, the Milter may reply with one or more queue
      * file edit requests before it replies with its final decision: accept,
-     * reject, etc. After a local queue file edit error, do not close the
-     * Milter socket in the cleanup server. Instead skip all further Milter
-     * replies until the final decision. This way the Postfix SMTP server
-     * stays in sync with the Milter, and Postfix doesn't have to lose the
-     * ability to handle multiple deliveries within the same SMTP session.
-     * This requires that the Postfix SMTP server uses something other than
-     * CLEANUP_STAT_WRITE when it loses contact with the cleanup server.
+     * reject, etc. After a local queue file edit error (file too big, media
+     * write error), do not close the Milter socket in the cleanup server.
+     * Instead skip all further Milter replies until the final decision. This
+     * way the Postfix SMTP server stays in sync with the Milter, and Postfix
+     * doesn't have to lose the ability to handle multiple deliveries within
+     * the same SMTP session. This requires that the Postfix SMTP server uses
+     * something other than CLEANUP_STAT_WRITE when it loses contact with the
+     * cleanup server.
      */
 #define IN_CONNECT_EVENT(e) ((e) == SMFIC_CONNECT || (e) == SMFIC_HELO)
 
@@ -1608,6 +1591,9 @@ static void milter8_connect(MILTER8 *milter)
                    VSTREAM_CTL_DOUBLE,
                    VSTREAM_CTL_TIMEOUT, milter->cmd_timeout,
                    VSTREAM_CTL_END);
+    /* Avoid poor performance when TCP MSS > VSTREAM_BUFSIZE. */
+    if (connect_fn == inet_connect)
+       vstream_tweak_tcp(milter->fp);
 
     /*
      * Open the negotiations by sending what actions the Milter may request
@@ -2510,6 +2496,8 @@ MILTER *milter8_receive(VSTREAM *stream, MILTERS *parent)
                            msg_timeout, NO_PROTOCOL, STR(act_buf), parent);
        milter->fp = vstream_fdopen(fd, O_RDWR);
        vstream_control(milter->fp, VSTREAM_CTL_DOUBLE, VSTREAM_CTL_END);
+       /* Avoid poor performance when TCP MSS > VSTREAM_BUFSIZE. */
+       vstream_tweak_sock(milter->fp);
        milter->version = version;
        milter->rq_mask = rq_mask;
        milter->ev_mask = ev_mask;
index 1430c8ced224e75aa5b30440ca6521b17dcc841b..61e753ef8c6acef8de48252dc9c594aa77f0e126 100644 (file)
@@ -303,6 +303,16 @@ static SMTP_SESSION *smtp_connect_sock(int sock, struct sockaddr * sa,
     }
     stream = vstream_fdopen(sock, O_RDWR);
 
+    /*
+     * Avoid poor performance when TCP MSS > VSTREAM_BUFSIZE.
+     */
+    if (sa->sa_family == AF_INET
+#ifdef AF_INET6
+       || sa->sa_family == AF_INET6
+#endif
+       )
+       vstream_tweak_tcp(stream);
+
     /*
      * Bundle up what we have into a nice SMTP_SESSION object.
      */
@@ -380,7 +390,7 @@ static void smtp_cleanup_session(SMTP_STATE *state)
     if (THIS_SESSION_IS_EXPIRED)
        smtp_quit(state);                       /* also disables caching */
     if (THIS_SESSION_IS_CACHED
-       /* Redundant tests for safety... */
+    /* Redundant tests for safety... */
        && vstream_ferror(session->stream) == 0
        && vstream_feof(session->stream) == 0) {
        smtp_save_session(state);
index a0fa7e9cf7c546cfcc46c571309cdf24b9bd770f..6a4aa1bec9b0f5f30cd7d8f5f4fa69ce9f73d988 100644 (file)
@@ -1618,7 +1618,8 @@ static int mail_open_stream(SMTPD_STATE *state)
        if (SMTPD_STAND_ALONE(state) == 0) {
            if (smtpd_milters != 0
                && (state->saved_flags & MILTER_SKIP_FLAGS) == 0)
-               (void) milter_send(smtpd_milters, state->dest->stream);
+               /* Send place-holder smtpd_milters list. */
+               (void) milter_dummy(smtpd_milters, state->cleanup);
            rec_fprintf(state->cleanup, REC_TYPE_TIME, REC_TYPE_TIME_FORMAT,
                        REC_TYPE_TIME_ARG(state->arrival_time));
            if (*var_filter_xport)
@@ -2521,6 +2522,10 @@ static int data_cmd(SMTPD_STATE *state, int argc, SMTPD_TOKEN *unused_argv)
      */
     if (state->cleanup) {
        if (SMTPD_STAND_ALONE(state) == 0) {
+           if (smtpd_milters != 0
+               && (state->saved_flags & MILTER_SKIP_FLAGS) == 0)
+               /* Send actual smtpd_milters list. */
+               (void) milter_send(smtpd_milters, state->cleanup);
            if (state->saved_flags)
                rec_fprintf(state->cleanup, REC_TYPE_FLGS, "%d",
                            state->saved_flags);
@@ -2737,19 +2742,20 @@ static int data_cmd(SMTPD_STATE *state, int argc, SMTPD_TOKEN *unused_argv)
     }
 
     /*
-     * XXX If we lost the cleanup server, the Postfix SMTP server will be out
-     * of sync with Milter applications. Sending an ABORT to the Milters is
-     * not sufficient to restore synchronization, because there may be any
-     * number of Milter replies already in flight. Destroying and recreating
-     * the Milters (and faking the connect and ehlo events) is too much
-     * trouble for testing and maintenance. Workaround: force the Postfix
-     * SMTP server to hang up with a 421 response in the rare case that the
-     * cleanup server breaks AND that the remote SMTP client continues the
-     * session after end-of-data.
+     * XXX If we lose the cleanup server while it is editing a queue file,
+     * the Postfix SMTP server will be out of sync with Milter applications.
+     * Sending an ABORT to the Milters is not sufficient to restore
+     * synchronization, because there may be any number of Milter replies
+     * already in flight. Destroying and recreating the Milters (and faking
+     * the connect and ehlo events) is too much trouble for testing and
+     * maintenance. Workaround: force the Postfix SMTP server to hang up with
+     * a 421 response in the rare case that the cleanup server breaks AND
+     * that the remote SMTP client continues the session after end-of-data.
      * 
      * XXX Should use something other than CLEANUP_STAT_WRITE when we lose
-     * contact with the cleanup server. This requires changes to among others
-     * the mail_stream module.
+     * contact with the cleanup server. This requires changes to the
+     * mail_stream module and its users (smtpd, qmqpd, perhaps sendmail).
+     * That is too much change for a stable release.
      */
     if (smtpd_milters != 0 && (state->err & CLEANUP_STAT_WRITE) != 0)
        state->access_denied = mystrdup("421 4.3.0 Mail system error");
index 33282ac40a5e72aed3cea212f1e62bf3777e63bb..a69089a115a62f5c6ec031e18c26f05b63887dc2 100644 (file)
@@ -356,6 +356,13 @@ static void connect_done(int unused_event, char *context)
        dequeue_connect(session);
        non_blocking(fd, BLOCKING);
        event_disable_readwrite(fd);
+       /* Avoid poor performance when TCP MSS > VSTREAM_BUFSIZE. */
+       if (sa->sa_family == AF_INET
+#ifdef AF_INET6
+           || sa->sa_family == AF_INET6
+#endif
+           )
+           vstream_tweak_tcp(session->stream);
        send_data(session);
     }
 }
index 52306cf8c9017ed946119e05587365ef250f2305..d6d8739b47e7b436022455bb5e977c53f3689e45 100644 (file)
@@ -472,6 +472,13 @@ static void connect_done(int unused_event, char *context)
        event_disable_readwrite(fd);
        event_enable_read(fd, read_banner, (char *) session);
        dequeue_connect(session);
+       /* Avoid poor performance when TCP MSS > VSTREAM_BUFSIZE. */
+       if (sa->sa_family == AF_INET
+#ifdef AF_INET6
+           || sa->sa_family == AF_INET6
+#endif
+           )
+           vstream_tweak_tcp(session->stream);
     }
 }
 
index 707f47cb5aac3d4346f6c4f33669712a9a59d04a..5e8a6c47e73b299db06f7b6bf9faeba4fb853e05 100644 (file)
@@ -30,7 +30,7 @@ SRCS  = alldig.c allprint.c argv.c argv_split.c attr_clnt.c attr_print0.c \
        username.c valid_hostname.c vbuf.c vbuf_print.c vstream.c \
        vstream_popen.c vstring.c vstring_vstream.c watchdog.c writable.c \
        write_buf.c write_wait.c sane_basename.c format_tv.c allspace.c \
-       allascii.c load_file.c killme_after.c
+       allascii.c load_file.c killme_after.c vstream_tweak.c
 OBJS   = alldig.o allprint.o argv.o argv_split.o attr_clnt.o attr_print0.o \
        attr_print64.o attr_print_plain.o attr_scan0.o attr_scan64.o \
        attr_scan_plain.o auto_clnt.o base64_code.o basename.o binhash.o \
@@ -62,7 +62,7 @@ OBJS  = alldig.o allprint.o argv.o argv_split.o attr_clnt.o attr_print0.o \
        username.o valid_hostname.o vbuf.o vbuf_print.o vstream.o \
        vstream_popen.o vstring.o vstring_vstream.o watchdog.o writable.o \
        write_buf.o write_wait.o sane_basename.o format_tv.o allspace.o \
-       allascii.o load_file.o killme_after.o
+       allascii.o load_file.o killme_after.o vstream_tweak.o
 HDRS   = argv.h attr.h attr_clnt.h auto_clnt.h base64_code.h binhash.h \
        chroot_uid.h cidr_match.h clean_env.h connect.h ctable.h dict.h \
        dict_cdb.h dict_cidr.h dict_db.h dict_dbm.h dict_env.h dict_ht.h \
@@ -1600,6 +1600,11 @@ vstream_popen.o: sys_defs.h
 vstream_popen.o: vbuf.h
 vstream_popen.o: vstream.h
 vstream_popen.o: vstream_popen.c
+vstream_tweak.o: msg.h
+vstream_tweak.o: sys_defs.h
+vstream_tweak.o: vbuf.h
+vstream_tweak.o: vstream.h
+vstream_tweak.o: vstream_tweak.c
 vstring.o: msg.h
 vstring.o: mymalloc.h
 vstring.o: sys_defs.h
index dc2ebb9f8fea360fdb68175c0e35e7d6ed182574..e96e60cb36c2a4c879ad6b53024ca75cfdac9014 100644 (file)
@@ -153,6 +153,12 @@ extern ssize_t vstream_peek(VSTREAM *);
 #define vstream_setjmp(stream)         setjmp((stream)->jbuf[0])
 #define vstream_longjmp(stream, val)   longjmp((stream)->jbuf[0], (val))
 
+ /*
+  * Tweaks and workarounds.
+  */
+extern int vstream_tweak_sock(VSTREAM *);
+extern int vstream_tweak_tcp(VSTREAM *);
+
 /* LICENSE
 /* .ad
 /* .fi
diff --git a/postfix/src/util/vstream_tweak.c b/postfix/src/util/vstream_tweak.c
new file mode 100644 (file)
index 0000000..1456511
--- /dev/null
@@ -0,0 +1,139 @@
+/*++
+/* NAME
+/*     vstream_tweak 3
+/* SUMMARY
+/*     performance tweaks
+/* SYNOPSIS
+/*     #include <vstream.h>
+/*
+/*     VSTREAM *vstream_tweak_sock(stream)
+/*     VSTREAM *stream;
+/*
+/*     VSTREAM *vstream_tweak_tcp(stream)
+/*     VSTREAM *stream;
+/* DESCRIPTION
+/*     vstream_tweak_sock() does a best effort to boost your
+/*     network performance on the specified generic stream.
+/*
+/*     vstream_tweak_tcp() does a best effort to boost your
+/*     Internet performance on the specified TCP stream.
+/*
+/*     Arguments:
+/* .IP stream
+/*     The stream being boosted.
+/* DIAGNOSTICS
+/*     Panics: interface violations.
+/* LICENSE
+/* .ad
+/* .fi
+/*     The Secure Mailer license must be distributed with this software.
+/* AUTHOR(S)
+/*     Wietse Venema
+/*     IBM T.J. Watson Research
+/*     P.O. Box 704
+/*     Yorktown Heights, NY 10598, USA
+/*--*/
+
+/* System library. */
+
+#include <sys_defs.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
+/* Utility library. */
+
+#include <msg.h>
+#include <vstream.h>
+
+/* Application-specific. */
+
+#ifdef HAS_IPV6
+#define SOCKADDR_STORAGE struct sockaddr_storage
+#else
+#define SOCKADDR_STORAGE struct sockaddr
+#endif
+
+/* vstream_tweak_sock - boost your generic network performance */
+
+int     vstream_tweak_sock(VSTREAM *fp)
+{
+    SOCKADDR_STORAGE ss;
+    struct sockaddr *sa = (struct sockaddr *) & ss;
+    SOCKADDR_SIZE sa_length = sizeof(ss);
+    int     ret;
+
+    /*
+     * If the caller doesn't know if this socket is AF_LOCAL, AF_INET, etc.,
+     * figure it out for them.
+     */
+    if ((ret = getsockname(vstream_fileno(fp), sa, &sa_length)) >= 0) {
+       switch (sa->sa_family) {
+#ifdef AF_INET6
+       case AF_INET6:
+#endif
+       case AF_INET:
+           ret = vstream_tweak_tcp(fp);
+           break;
+       }
+    }
+    return (ret);
+}
+
+/* vstream_tweak_tcp - boost your TCP performance */
+
+int     vstream_tweak_tcp(VSTREAM *fp)
+{
+    const char *myname = "vstream_tweak_tcp";
+    int     mss;
+    SOCKOPT_SIZE mss_len = sizeof(mss);
+    int     err;
+
+    /*
+     * Avoid Nagle delays when VSTREAM buffers are smaller than the MSS.
+     * 
+     * Forcing TCP_NODELAY to be "always on" would hurt performance in the
+     * common case where VSTREAM buffers are larger than the MSS.
+     * 
+     * Instead we ask the kernel what the current MSS is, and take appropriate
+     * action. Linux <= 2.2 getsockopt(TCP_MAXSEG) always returns zero (or
+     * whatever value was stored last with setsockopt()).
+     */
+    if ((err = getsockopt(vstream_fileno(fp), IPPROTO_TCP, TCP_MAXSEG,
+                         (char *) &mss, &mss_len)) < 0) {
+       msg_warn("%s: getsockopt TCP_MAXSEG: %m", myname);
+       return (err);
+    }
+    if (msg_verbose)
+       msg_info("%s: TCP_MAXSEG %d", myname, mss);
+
+    /*
+     * Fix for recent Postfix versions: increase the VSTREAM buffer size if
+     * the VSTREAM buffer is smaller than the MSS. Note: the MSS may change
+     * when the route changes and IP path MTU discovery is turned on, so we
+     * choose a somewhat larger buffer.
+     */
+#ifdef VSTREAM_CTL_BUFSIZE
+    if (mss > 0) {
+       if (mss < __MAXINT__(ssize_t) /2)
+           mss *= 2;
+       vstream_control(fp,
+                       VSTREAM_CTL_BUFSIZE, (ssize_t) mss,
+                       VSTREAM_CTL_END);
+    }
+
+    /*
+     * Workaround for older Postfix versions: turn on TCP_NODELAY if the
+     * VSTREAM buffer size is smaller than the MSS.
+     */
+#else
+    if (mss > VSTREAM_BUFSIZE) {
+       int     nodelay = 0;
+
+       if ((err = setsockopt(vstream_fileno(fp), IPPROTO_TCP, TCP_NODELAY,
+                             (char *) &nodelay, sizeof(nodelay))) < 0)
+           msg_warn("%s: setsockopt TCP_NODELAY: %m", myname);
+    }
+#endif
+    return (err);
+}