]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Merge r1927885, r1927916, r1928022 from trunk:
authorRuediger Pluem <rpluem@apache.org>
Fri, 7 Nov 2025 08:32:34 +0000 (08:32 +0000)
committerRuediger Pluem <rpluem@apache.org>
Fri, 7 Nov 2025 08:32:34 +0000 (08:32 +0000)
Make the value set for the socket option TCP_DEFER_ACCEPT configurable

* include/ap_listen.h:
  - Add prototype for ap_set_listentcpdeferaccept
  - Wire in new directive ListenTCPDeferAccept

* include/mpm_common.h:
  Define the previous static value as default value via DEFAULT_TCP_DEFER_ACCEPT

* server/listen.c:
  - Add static int ap_listentcpdeferaccept
  - ap_apply_accept_filter: Use value of ap_listenbacklog for setting TCP_DEFER_ACCEPT
  - ap_listen_pre_config: Set default value
  - Add ap_set_listentcpdeferaccept

* Follow up to r1927885: Use correct configuration variable. Thanks to @ylavic
  for finding this.

* Follow up to r1927885: Changelog entry and documentation

Reviewed by: rpluem, jorton, covener

Github: closes #555

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1929574 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
docs/manual/mod/mpm_common.xml
include/ap_listen.h
include/mpm_common.h
server/listen.c

diff --git a/CHANGES b/CHANGES
index f608213a84b8c9d3b1ecd43ea9dad098c1584c3a..d15c415132bc4001177b476087f940bb9dd167b4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.4.66
 
+  *) mpm_common: Add new ListenTCPDeferAccept directive that allows to specify
+     the value set for the TCP_DEFER_ACCEPT socket option on listen sockets.
+     [Ruediger Pluem]
+
   *) mod_ssl: Add SSLVHostSNIPolicy directive to control the virtual
      host compatibility policy.  PR 69743.  [Joe Orton]
 
diff --git a/STATUS b/STATUS
index b655880142ca0b37c37a1cc3e1faf8e1849f8e85..ff1836cb5755dc12ecc4c67836b812b77474c618 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -175,17 +175,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
      2.4.x patch: svn merge -c 1927792 ^/httpd/httpd/trunk .
      +1: icing, rpluem, jorton
 
-  *) mpm_common: Add new ListenTCPDeferAccept directive that allows to specify
-     the value set for the TCP_DEFER_ACCEPT socket option on listen sockets.
-     Trunk version of patch:
-        https://svn.apache.org/r1927885
-        https://svn.apache.org/r1927916
-        https://svn.apache.org/r1928022
-     Backport version for 2.4.x of patch:
-       https://patch-diff.githubusercontent.com/raw/apache/httpd/pull/555.diff
-     Can be applied via apply_backport_pr.sh 555
-     +1: rpluem, jorton, covener
-
   *) mod_http2: Fix handling of 304 responses from mod_cache. PR 69580.
      Trunk version of patch:
         https://svn.apache.org/r1924267
index cab75eed3063055dc48b2a311c8310678a2a333e..252890851e82d281e2f694bc9f62f0f295ac7fb5 100644 (file)
@@ -363,6 +363,29 @@ in *BSDs.</compatibility>
 </usage>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>ListenTCPDeferAccept</name>
+<description>Value set for the socket option TCP_DEFER_ACCEPT if it is set</description>
+<syntax>ListenTCPDeferAccept <var>integer</var></syntax>
+<default>ListenTCPDeferAccept 30</default>
+<contextlist><context>server config</context></contextlist>
+<modulelist><module>event</module><module>worker</module>
+<module>prefork</module>
+</modulelist>
+<compatibility>Available in Apache HTTP Server 2.5.1 and later</compatibility>
+
+<usage>
+    <p>The value specified here is set as a value for the socket option
+    <code>TCP_DEFER_ACCEPT</code> if it is set on the listen socket.
+    This happens when running on Linux and <directive
+    module="core">AcceptFilter</directive> is set to anything besides
+    <code>none</code>. In any other cases this setting is ignored.
+    For more details see the Linux
+    <a href="http://man7.org/linux/man-pages/man7/tcp.7.html">
+    tcp(7)</a> man page.</p>
+</usage>
+</directivesynopsis>
+
 <directivesynopsis>
 <name>MaxRequestWorkers</name>
 <description>Maximum number of connections that will be processed
index d5ed9685c54eed61e26a0e046ca9303ca5cdb1fd..9b3431e0cb35d51605c9c9938fd7f89813c555d3 100644 (file)
@@ -135,6 +135,7 @@ AP_DECLARE_NONSTD(int) ap_close_selected_listeners(ap_slave_t *);
  * called.
  */
 AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg);
+AP_DECLARE_NONSTD(const char *) ap_set_listentcpdeferaccept(cmd_parms *cmd, void *dummy, const char *arg);
 AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd, void *dummy, const char *arg);
 AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy,
                                                 int argc, char *const argv[]);
@@ -163,7 +164,9 @@ AP_INIT_TAKE_ARGV("Listen", ap_set_listener, NULL, RSRC_CONF, \
 AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \
   "Send buffer size in bytes"), \
 AP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \
-              RSRC_CONF, "Receive buffer size in bytes")
+              RSRC_CONF, "Receive buffer size in bytes"), \
+AP_INIT_TAKE1("ListenTCPDeferAccept", ap_set_listentcpdeferaccept, NULL, RSRC_CONF, \
+  "Value set for the socket option TCP_DEFER_ACCEPT if it is set")
 
 #ifdef __cplusplus
 }
index 539d6401bb3a8608d5f22e2b93f21a59f00e4732..6b3d1f536fb5b4405e0af3056984e345eb8f6ed5 100644 (file)
@@ -63,6 +63,14 @@ extern "C" {
 #define DEFAULT_LISTENBACKLOG 511
 #endif
 
+/*
+ * Define the default value set for the socket option TCP_DEFER_ACCEPT
+ * if it is set.
+ */
+#ifndef DEFAULT_TCP_DEFER_ACCEPT
+#define DEFAULT_TCP_DEFER_ACCEPT 30
+#endif
+
 /* Signal used to gracefully restart */
 #define AP_SIG_GRACEFUL SIGUSR1
 
index cb7e59eb34c39e9aad6796f65d14a05f951f4ae0..aff5348d9a6556486a5fd111bfed17ae5e9ddbc2 100644 (file)
@@ -57,6 +57,7 @@ AP_DECLARE_DATA int ap_have_so_reuseport = -1;
 
 static ap_listen_rec *old_listeners;
 static int ap_listenbacklog;
+static int ap_listentcpdeferaccept;
 static int ap_listencbratio;
 static int send_buffer_size;
 static int receive_buffer_size;
@@ -268,7 +269,7 @@ static void ap_apply_accept_filter(apr_pool_t *p, ap_listen_rec *lis,
                           accf);
         }
 #else
-        rv = apr_socket_opt_set(s, APR_TCP_DEFER_ACCEPT, 30);
+        rv = apr_socket_opt_set(s, APR_TCP_DEFER_ACCEPT, ap_listentcpdeferaccept);
         if (rv != APR_SUCCESS && !APR_STATUS_IS_ENOTIMPL(rv)) {
             ap_log_perror(APLOG_MARK, APLOG_WARNING, rv, p, APLOGNO(00076)
                               "Failed to enable APR_TCP_DEFER_ACCEPT");
@@ -947,6 +948,7 @@ AP_DECLARE(void) ap_listen_pre_config(void)
     ap_listen_buckets = NULL;
     ap_num_listen_buckets = 0;
     ap_listenbacklog = DEFAULT_LISTENBACKLOG;
+    ap_listentcpdeferaccept = DEFAULT_TCP_DEFER_ACCEPT;
     ap_listencbratio = 0;
 
     /* Check once whether or not SO_REUSEPORT is supported. */
@@ -1076,6 +1078,26 @@ AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd,
     return NULL;
 }
 
+AP_DECLARE_NONSTD(const char *) ap_set_listentcpdeferaccept(cmd_parms *cmd,
+                                                            void *dummy,
+                                                            const char *arg)
+{
+    int b;
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+    if (err != NULL) {
+        return err;
+    }
+
+    b = atoi(arg);
+    if (b < 1) {
+        return "ListenTCPDeferAccept must be > 0";
+    }
+
+    ap_listentcpdeferaccept = b;
+    return NULL;
+}
+
 AP_DECLARE_NONSTD(const char *) ap_set_listencbratio(cmd_parms *cmd,
                                                      void *dummy,
                                                      const char *arg)