Hi, Following a discussion with Sergey, here's a new version with a simplified ngx_quic_run().
On Fri, Dec 09, 2022 at 09:38:48AM +0000, Roman Arutyunyan wrote: > # HG changeset patch > # User Roman Arutyunyan <a...@nginx.com> > # Date 1670428292 0 > # Wed Dec 07 15:51:32 2022 +0000 > # Branch quic > # Node ID 8a7f2c71db202141d169f3ab292027bfc16ff8ec > # Parent 1038d7300c29eea02b47eac3f205e293b1e55f5b > QUIC: handle datagrams directly in ngx_quic_recvmsg(). > > Previously, ngx_quic_recvmsg() called client connection's read event handler > to emulate normal event processing. Further, the read event handler handled > the datagram by calling ngx_quic_handle_datagram(). > > Now ngx_quic_handle_datagram() is called directly from ngx_quic_recvmsg(), > which simplifies the code. [..] -- Roman Arutyunyan
# HG changeset patch # User Roman Arutyunyan <a...@nginx.com> # Date 1672752567 -14400 # Tue Jan 03 17:29:27 2023 +0400 # Branch quic # Node ID aaa2a3831eefe4315dfb8a9be7178c79ff67f163 # Parent a8f6e9a1d1674915501a8322004d04e6eac245d8 QUIC: handle datagrams directly in ngx_quic_recvmsg(). Previously, ngx_quic_recvmsg() called client connection's read event handler to emulate normal event processing. Further, the read event handler handled the datagram by calling ngx_quic_handle_datagram(). Now ngx_quic_handle_datagram() is called directly from ngx_quic_recvmsg(), which simplifies the code. diff --git a/src/event/quic/ngx_event_quic.c b/src/event/quic/ngx_event_quic.c --- a/src/event/quic/ngx_event_quic.c +++ b/src/event/quic/ngx_event_quic.c @@ -17,8 +17,6 @@ static ngx_int_t ngx_quic_handle_statele static void ngx_quic_input_handler(ngx_event_t *rev); static void ngx_quic_close_handler(ngx_event_t *ev); -static ngx_int_t ngx_quic_handle_datagram(ngx_connection_t *c, ngx_buf_t *b, - ngx_quic_conf_t *conf); static ngx_int_t ngx_quic_handle_packet(ngx_connection_t *c, ngx_quic_conf_t *conf, ngx_quic_header_t *pkt); static ngx_int_t ngx_quic_handle_payload(ngx_connection_t *c, @@ -201,8 +199,7 @@ ngx_quic_apply_transport_params(ngx_conn void ngx_quic_run(ngx_connection_t *c, ngx_quic_conf_t *conf) { - ngx_int_t rc; - ngx_quic_connection_t *qc; + ngx_int_t rc; ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic run"); @@ -211,16 +208,6 @@ ngx_quic_run(ngx_connection_t *c, ngx_qu ngx_quic_close_connection(c, rc); return; } - - /* quic connection is now created */ - qc = ngx_quic_get_connection(c); - - ngx_add_timer(c->read, qc->tp.max_idle_timeout); - ngx_quic_connstate_dbg(c); - - c->read->handler = ngx_quic_input_handler; - - return; } @@ -340,6 +327,8 @@ ngx_quic_new_connection(ngx_connection_t c->idle = 1; ngx_reusable_connection(c, 1); + c->read->handler = ngx_quic_input_handler; + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic connection created"); @@ -397,8 +386,6 @@ ngx_quic_handle_stateless_reset(ngx_conn static void ngx_quic_input_handler(ngx_event_t *rev) { - ngx_int_t rc; - ngx_buf_t *b; ngx_connection_t *c; ngx_quic_connection_t *qc; @@ -432,29 +419,6 @@ ngx_quic_input_handler(ngx_event_t *rev) return; } - - b = c->udp->buffer; - if (b == NULL) { - return; - } - - rc = ngx_quic_handle_datagram(c, b, NULL); - - if (rc == NGX_ERROR) { - ngx_quic_close_connection(c, NGX_ERROR); - return; - } - - if (rc == NGX_DONE) { - return; - } - - /* rc == NGX_OK */ - - qc->send_timer_set = 0; - ngx_add_timer(rev, qc->tp.max_idle_timeout); - - ngx_quic_connstate_dbg(c); } @@ -654,7 +618,7 @@ ngx_quic_close_handler(ngx_event_t *ev) } -static ngx_int_t +ngx_int_t ngx_quic_handle_datagram(ngx_connection_t *c, ngx_buf_t *b, ngx_quic_conf_t *conf) { @@ -753,6 +717,11 @@ ngx_quic_handle_datagram(ngx_connection_ qc->error_reason = "QUIC flood detected"; return NGX_ERROR; } + + qc->send_timer_set = 0; + ngx_add_timer(c->read, qc->tp.max_idle_timeout); + + ngx_quic_connstate_dbg(c); } return NGX_OK; diff --git a/src/event/quic/ngx_event_quic_connection.h b/src/event/quic/ngx_event_quic_connection.h --- a/src/event/quic/ngx_event_quic_connection.h +++ b/src/event/quic/ngx_event_quic_connection.h @@ -260,6 +260,8 @@ struct ngx_quic_connection_s { }; +ngx_int_t ngx_quic_handle_datagram(ngx_connection_t *c, ngx_buf_t *b, + ngx_quic_conf_t *conf); ngx_int_t ngx_quic_apply_transport_params(ngx_connection_t *c, ngx_quic_tp_t *ctp); void ngx_quic_discard_ctx(ngx_connection_t *c, diff --git a/src/event/quic/ngx_event_quic_migration.c b/src/event/quic/ngx_event_quic_migration.c --- a/src/event/quic/ngx_event_quic_migration.c +++ b/src/event/quic/ngx_event_quic_migration.c @@ -264,12 +264,6 @@ ngx_quic_set_path(ngx_connection_t *c, n len = pkt->raw->last - pkt->raw->start; - if (c->udp->buffer == NULL) { - /* first ever packet in connection, path already exists */ - path = qc->path; - goto update; - } - probe = NULL; for (q = ngx_queue_head(&qc->paths); diff --git a/src/event/quic/ngx_event_quic_socket.c b/src/event/quic/ngx_event_quic_socket.c --- a/src/event/quic/ngx_event_quic_socket.c +++ b/src/event/quic/ngx_event_quic_socket.c @@ -61,6 +61,9 @@ ngx_quic_open_sockets(ngx_connection_t * } ngx_memcpy(qc->tp.initial_scid.data, qsock->sid.id, qsock->sid.len); + ngx_memcpy(&qsock->sockaddr.sockaddr, c->sockaddr, c->socklen); + qsock->socklen = c->socklen; + /* for all packets except first, this is set at udp layer */ c->udp = &qsock->udp; diff --git a/src/event/quic/ngx_event_quic_udp.c b/src/event/quic/ngx_event_quic_udp.c --- a/src/event/quic/ngx_event_quic_udp.c +++ b/src/event/quic/ngx_event_quic_udp.c @@ -186,21 +186,11 @@ ngx_quic_recvmsg(ngx_event_t *ev) ngx_memcpy(&qsock->sockaddr.sockaddr, sockaddr, socklen); qsock->socklen = socklen; - c->udp->buffer = &buf; - - rev = c->read; - rev->ready = 1; - rev->active = 0; - - rev->handler(rev); - - if (c->udp) { - c->udp->buffer = NULL; + if (ngx_quic_handle_datagram(c, &buf, NULL) == NGX_ERROR) { + ngx_quic_close_connection(c, NGX_ERROR); + return; } - rev->ready = 0; - rev->active = 1; - goto next; }
_______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel