[PATCH] Stream: added config option for TCP_FASTOPEN

Anbang Wen anb at papla.net
Thu Apr 15 04:41:42 UTC 2021


# HG changeset patch
# User Anbang Wen <anb at papla.net>
# Date 1618433103 25200
#      Wed Apr 14 13:45:03 2021 -0700
# Node ID 495a4d1d58835f7a05b24fb1aad84027f43f90c9
# Parent  b56c45e3bd5029f98e1e847eebad75430e2cca27
Stream: added config option for TCP_FASTOPEN

This commit adds a "fastopen" option to stream module. The option
behaves exactly the same as the one in HTTP core module.

diff -r b56c45e3bd50 -r 495a4d1d5883 src/stream/ngx_stream.c
--- a/src/stream/ngx_stream.c	Tue Apr 13 18:13:59 2021 +0300
+++ b/src/stream/ngx_stream.c	Wed Apr 14 13:45:03 2021 -0700
@@ -514,6 +514,10 @@
             ls->reuseport = addr[i].opt.reuseport;
 #endif
 
+#if (NGX_HAVE_TCP_FASTOPEN)
+            ls->fastopen = addr[i].opt.fastopen;
+#endif
+
             stport = ngx_palloc(cf->pool, sizeof(ngx_stream_port_t));
             if (stport == NULL) {
                 return NGX_CONF_ERROR;
diff -r b56c45e3bd50 -r 495a4d1d5883 src/stream/ngx_stream.h
--- a/src/stream/ngx_stream.h	Tue Apr 13 18:13:59 2021 +0300
+++ b/src/stream/ngx_stream.h	Wed Apr 14 13:45:03 2021 -0700
@@ -66,6 +66,9 @@
     int                            rcvbuf;
     int                            sndbuf;
     int                            type;
+#if (NGX_HAVE_TCP_FASTOPEN)
+    int                            fastopen;
+#endif
 } ngx_stream_listen_t;
 
 
diff -r b56c45e3bd50 -r 495a4d1d5883 src/stream/ngx_stream_core_module.c
--- a/src/stream/ngx_stream_core_module.c	Tue Apr 13 18:13:59 2021 +0300
+++ b/src/stream/ngx_stream_core_module.c	Wed Apr 14 13:45:03 2021 -0700
@@ -619,6 +619,10 @@
     ls->ipv6only = 1;
 #endif
 
+#if (NGX_HAVE_TCP_FASTOPEN)
+    ls->fastopen = -1;
+#endif
+
     backlog = 0;
 
     for (i = 2; i < cf->args->nelts; i++) {
@@ -836,6 +840,19 @@
             continue;
         }
 
+#if (NGX_HAVE_TCP_FASTOPEN)
+        if (ngx_strncmp(value[i].data, "fastopen=", 9) == 0) {
+            ls->fastopen = ngx_atoi(value[i].data + 9, value[i].len - 9);
+            if (ls->fastopen == NGX_ERROR) {
+                ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                                   "invalid fastopen \"%V\"", &value[i]);
+                return NGX_CONF_ERROR;
+            }
+
+            continue;
+        }
+#endif
+
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "the invalid \"%V\" parameter", &value[i]);
         return NGX_CONF_ERROR;
@@ -859,6 +876,10 @@
         if (ls->proxy_protocol) {
             return "\"proxy_protocol\" parameter is incompatible with \"udp\"";
         }
+
+        if (ls->fastopen >= 0) {
+            return "\"fastopen\" parameter is incompatible with \"udp\"";
+        }
     }
 
     als = cmcf->listen.elts;




More information about the nginx-devel mailing list