May 17, 2021 09:42AM
Hi,

Thanks for the patch. A few comments and an updated patch below.

On Wed, Apr 14, 2021 at 09:41:42PM -0700, Anbang Wen wrote:
> # HG changeset patch
> # User Anbang Wen <anb@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_core_module.c
[...]
> @@ -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);

Here, ls->bind should also be set.

> + if (ls->fastopen == NGX_ERROR) {
> + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
> + "invalid fastopen \"%V\"", &value[i]);
> + return NGX_CONF_ERROR;
> + }
> +
> + continue;
> + }

> @@ -859,6 +876,10 @@
> if (ls->proxy_protocol) {
> return "\"proxy_protocol\" parameter is incompatible with \"udp\"";
> }
> +
> + if (ls->fastopen >= 0) {

Here I changed the comparison to -1 to match the initial value.

I also relocated code inserts to match the http code better.

# HG changeset patch
# User Ruslan Ermilov <ru@nginx.com>
# Date 1620909454 -10800
# Thu May 13 15:37:34 2021 +0300
# Node ID edb473720b4dcdb57acae615c21b1f9075d0c63f
# Parent 9bb2b3dc5efe4099ce1f86da1ae3e846054836b1
Stream: the "fastopen" parameter of the "listen" directive.

Based on a patch by Anbang Wen.

diff --git a/src/stream/ngx_stream.c b/src/stream/ngx_stream.c
--- a/src/stream/ngx_stream.c
+++ b/src/stream/ngx_stream.c
@@ -510,6 +510,10 @@ ngx_stream_optimize_servers(ngx_conf_t *
ls->ipv6only = addr[i].opt.ipv6only;
#endif

+#if (NGX_HAVE_TCP_FASTOPEN)
+ ls->fastopen = addr[i].opt.fastopen;
+#endif
+
#if (NGX_HAVE_REUSEPORT)
ls->reuseport = addr[i].opt.reuseport;
#endif
diff --git a/src/stream/ngx_stream.h b/src/stream/ngx_stream.h
--- a/src/stream/ngx_stream.h
+++ b/src/stream/ngx_stream.h
@@ -65,6 +65,9 @@ typedef struct {
int backlog;
int rcvbuf;
int sndbuf;
+#if (NGX_HAVE_TCP_FASTOPEN)
+ int fastopen;
+#endif
int type;
} ngx_stream_listen_t;

diff --git a/src/stream/ngx_stream_core_module.c b/src/stream/ngx_stream_core_module.c
--- a/src/stream/ngx_stream_core_module.c
+++ b/src/stream/ngx_stream_core_module.c
@@ -615,6 +615,10 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
ls->type = SOCK_STREAM;
ls->ctx = cf->ctx;

+#if (NGX_HAVE_TCP_FASTOPEN)
+ ls->fastopen = -1;
+#endif
+
#if (NGX_HAVE_INET6)
ls->ipv6only = 1;
#endif
@@ -635,6 +639,21 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
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);
+ ls->bind = 1;
+
+ 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
+
if (ngx_strncmp(value[i].data, "backlog=", 8) == 0) {
ls->backlog = ngx_atoi(value[i].data + 8, value[i].len - 8);
ls->bind = 1;
@@ -859,6 +878,12 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
if (ls->proxy_protocol) {
return "\"proxy_protocol\" parameter is incompatible with \"udp\"";
}
+
+#if (NGX_HAVE_TCP_FASTOPEN)
+ if (ls->fastopen != -1) {
+ return "\"fastopen\" parameter is incompatible with \"udp\"";
+ }
+#endif
}

als = cmcf->listen.elts;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Stream: added config option for TCP_FASTOPEN

Anbang Wen 200 April 15, 2021 12:42AM

Re: [PATCH] Stream: added config option for TCP_FASTOPEN

ru@nginx.com 85 May 17, 2021 09:42AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 77
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready