From 11dfc1c9439a79881c2d2e73ab1e2c5c71f88499 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Fri, 13 Mar 2020 20:44:32 +0300 Subject: Fixed sanitizer errors. --- src/core/ngx_connection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/ngx_connection.c') diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 33682532a..9ec1cd7ac 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -1178,11 +1178,6 @@ ngx_close_connection(ngx_connection_t *c) ngx_uint_t log_error, level; ngx_socket_t fd; - if (c->fd == (ngx_socket_t) -1) { - ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed"); - return; - } - if (c->read->timer_set) { ngx_del_timer(c->read); } @@ -1191,7 +1186,7 @@ ngx_close_connection(ngx_connection_t *c) ngx_del_timer(c->write); } - if (!c->shared) { + if (!c->shared && c->fd != (ngx_socket_t) -1) { if (ngx_del_conn) { ngx_del_conn(c, NGX_CLOSE_EVENT); @@ -1223,6 +1218,11 @@ ngx_close_connection(ngx_connection_t *c) ngx_free_connection(c); + if (c->fd == (ngx_socket_t) -1) { + ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, "connection has no fd"); + return; + } + fd = c->fd; c->fd = (ngx_socket_t) -1; -- cgit From 9d465009149c67325d9ac49503891cc84e5eaef8 Mon Sep 17 00:00:00 2001 From: Sergey Kandaurov Date: Tue, 23 Jun 2020 11:57:00 +0300 Subject: Do not close QUIC sockets in ngx_close_listening_sockets(). This breaks graceful shutdown of QUIC connections in terms of quic-transport. --- src/core/ngx_connection.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/ngx_connection.c') diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 9ec1cd7ac..5bae54502 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -1034,6 +1034,10 @@ ngx_close_listening_sockets(ngx_cycle_t *cycle) ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { + if (ls[i].quic) { + continue; + } + c = ls[i].connection; if (c) { -- cgit From b813b9ec358862a2a94868bc057420d6eca5c05d Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Tue, 21 Jul 2020 23:09:22 +0300 Subject: QUIC: added "quic" listen parameter. The parameter allows processing HTTP/0.9-2 over QUIC. Also, introduced ngx_http_quic_module and moved QUIC settings there --- src/core/ngx_connection.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/ngx_connection.c') diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index ba07c63e8..1fb569d30 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -1034,9 +1034,11 @@ ngx_close_listening_sockets(ngx_cycle_t *cycle) ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { +#if (NGX_QUIC) if (ls[i].quic) { continue; } +#endif c = ls[i].connection; -- cgit From 465362e0664a4fe31cb5df8e757bc99b3c68f5fa Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Mon, 6 Sep 2021 16:59:00 +0300 Subject: QUIC: store QUIC connection fd in stream fake connection. Previously it had -1 as fd. This fixes proxying, which relies on downstream connection having a real fd. Also, this reduces diff to the default branch for ngx_close_connection(). --- src/core/ngx_connection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/ngx_connection.c') diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 974f48c9a..4a7d2fe79 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -1185,6 +1185,11 @@ ngx_close_connection(ngx_connection_t *c) ngx_uint_t log_error, level; ngx_socket_t fd; + if (c->fd == (ngx_socket_t) -1) { + ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed"); + return; + } + if (c->read->timer_set) { ngx_del_timer(c->read); } @@ -1193,7 +1198,7 @@ ngx_close_connection(ngx_connection_t *c) ngx_del_timer(c->write); } - if (!c->shared && c->fd != (ngx_socket_t) -1) { + if (!c->shared) { if (ngx_del_conn) { ngx_del_conn(c, NGX_CLOSE_EVENT); @@ -1225,11 +1230,6 @@ ngx_close_connection(ngx_connection_t *c) ngx_free_connection(c); - if (c->fd == (ngx_socket_t) -1) { - ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, "connection has no fd"); - return; - } - fd = c->fd; c->fd = (ngx_socket_t) -1; -- cgit From 9d81ef744cdaacf1e52bcaec4224d375af5ba59b Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Wed, 20 Apr 2022 16:01:17 +0400 Subject: QUIC: separate UDP framework for QUIC. Previously, QUIC used the existing UDP framework, which was created for UDP in Stream. However the way QUIC connections are created and looked up is different from the way UDP connections in Stream are created and looked up. Now these two implementations are decoupled. --- src/core/ngx_connection.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/core/ngx_connection.c') diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 4a7d2fe79..cbd5803be 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -72,10 +72,6 @@ ngx_create_listening(ngx_conf_t *cf, struct sockaddr *sockaddr, ngx_memcpy(ls->addr_text.data, text, len); -#if !(NGX_WIN32) - ngx_rbtree_init(&ls->rbtree, &ls->sentinel, ngx_udp_rbtree_insert_value); -#endif - ls->fd = (ngx_socket_t) -1; ls->type = SOCK_STREAM; -- cgit From 1465a34067b927963b311136bf15a79981cb9d6e Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Sat, 6 May 2023 16:23:27 +0400 Subject: QUIC: disabled datagram fragmentation. As per RFC 9000, Section 14: UDP datagrams MUST NOT be fragmented at the IP layer. --- src/core/ngx_connection.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'src/core/ngx_connection.c') diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 57c5a8aa1..5e5683928 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -1009,6 +1009,78 @@ ngx_configure_listening_sockets(ngx_cycle_t *cycle) } } +#endif + +#if (NGX_HAVE_IP_MTU_DISCOVER) + + if (ls[i].quic && ls[i].sockaddr->sa_family == AF_INET) { + value = IP_PMTUDISC_DO; + + if (setsockopt(ls[i].fd, IPPROTO_IP, IP_MTU_DISCOVER, + (const void *) &value, sizeof(int)) + == -1) + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, + "setsockopt(IP_MTU_DISCOVER) " + "for %V failed, ignored", + &ls[i].addr_text); + } + } + +#elif (NGX_HAVE_IP_DONTFRAG) + + if (ls[i].quic && ls[i].sockaddr->sa_family == AF_INET) { + value = 1; + + if (setsockopt(ls[i].fd, IPPROTO_IP, IP_DONTFRAG, + (const void *) &value, sizeof(int)) + == -1) + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, + "setsockopt(IP_DONTFRAG) " + "for %V failed, ignored", + &ls[i].addr_text); + } + } + +#endif + +#if (NGX_HAVE_INET6) + +#if (NGX_HAVE_IPV6_MTU_DISCOVER) + + if (ls[i].quic && ls[i].sockaddr->sa_family == AF_INET6) { + value = IPV6_PMTUDISC_DO; + + if (setsockopt(ls[i].fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, + (const void *) &value, sizeof(int)) + == -1) + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, + "setsockopt(IPV6_MTU_DISCOVER) " + "for %V failed, ignored", + &ls[i].addr_text); + } + } + +#elif (NGX_HAVE_IP_DONTFRAG) + + if (ls[i].quic && ls[i].sockaddr->sa_family == AF_INET6) { + value = 1; + + if (setsockopt(ls[i].fd, IPPROTO_IPV6, IPV6_DONTFRAG, + (const void *) &value, sizeof(int)) + == -1) + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, + "setsockopt(IPV6_DONTFRAG) " + "for %V failed, ignored", + &ls[i].addr_text); + } + } + +#endif + #endif } -- cgit From 0a3c79614521d7612b63eff4e09c25ed219fb65b Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Sun, 14 May 2023 12:30:11 +0400 Subject: Common tree insert function for QUIC and UDP connections. Previously, ngx_udp_rbtree_insert_value() was used for plain UDP and ngx_quic_rbtree_insert_value() was used for QUIC. Because of this it was impossible to initialize connection tree in ngx_create_listening() since this function is not aware what kind of listening it creates. Now ngx_udp_rbtree_insert_value() is used for both QUIC and UDP. To make is possible, a generic key field is added to ngx_udp_connection_t. It keeps client address for UDP and connection ID for QUIC. --- src/core/ngx_connection.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/ngx_connection.c') diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 5e5683928..10f4d9b91 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -72,6 +72,10 @@ ngx_create_listening(ngx_conf_t *cf, struct sockaddr *sockaddr, ngx_memcpy(ls->addr_text.data, text, len); +#if !(NGX_WIN32) + ngx_rbtree_init(&ls->rbtree, &ls->sentinel, ngx_udp_rbtree_insert_value); +#endif + ls->fd = (ngx_socket_t) -1; ls->type = SOCK_STREAM; -- cgit