aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Homutov <vl@nginx.com>2021-12-27 13:49:56 +0300
committerVladimir Homutov <vl@nginx.com>2021-12-27 13:49:56 +0300
commitfa21bf0cc7ba2d94f66a061d644163547d79e6a2 (patch)
tree28624696137192ff0adacaa280f4b26f133aff12
parent05a32b5ec44e8fb54ea1976ec025a6ea650c36f9 (diff)
downloadnginx-fa21bf0cc7ba2d94f66a061d644163547d79e6a2.tar.gz
nginx-fa21bf0cc7ba2d94f66a061d644163547d79e6a2.zip
QUIC: got rid of ngx_quic_create_temp_socket().
It was mostly copy of the ngx_quic_listen(). Now ngx_quic_listen() no longer generates server id and increments seqnum. Instead, the server id is generated when the socket is created. The ngx_quic_alloc_socket() function is renamed to ngx_quic_create_socket().
-rw-r--r--src/event/quic/ngx_event_quic_connid.c2
-rw-r--r--src/event/quic/ngx_event_quic_socket.c88
-rw-r--r--src/event/quic/ngx_event_quic_socket.h2
3 files changed, 29 insertions, 63 deletions
diff --git a/src/event/quic/ngx_event_quic_connid.c b/src/event/quic/ngx_event_quic_connid.c
index d87948021..9f2f7ab33 100644
--- a/src/event/quic/ngx_event_quic_connid.c
+++ b/src/event/quic/ngx_event_quic_connid.c
@@ -497,7 +497,7 @@ ngx_quic_create_sockets(ngx_connection_t *c)
while (qc->nsockets < n) {
- qsock = ngx_quic_alloc_socket(c, qc);
+ qsock = ngx_quic_create_socket(c, qc);
if (qsock == NULL) {
return NGX_ERROR;
}
diff --git a/src/event/quic/ngx_event_quic_socket.c b/src/event/quic/ngx_event_quic_socket.c
index a04ad6202..426e1ebae 100644
--- a/src/event/quic/ngx_event_quic_socket.c
+++ b/src/event/quic/ngx_event_quic_socket.c
@@ -10,17 +10,12 @@
#include <ngx_event_quic_connection.h>
-static ngx_int_t ngx_quic_create_temp_socket(ngx_connection_t *c,
- ngx_quic_connection_t *qc, ngx_str_t *dcid, ngx_quic_path_t *path,
- ngx_quic_client_id_t *cid);
-
-
ngx_int_t
ngx_quic_open_sockets(ngx_connection_t *c, ngx_quic_connection_t *qc,
ngx_quic_header_t *pkt)
{
ngx_quic_path_t *path;
- ngx_quic_socket_t *qsock;
+ ngx_quic_socket_t *qsock, *tmp;
ngx_quic_client_id_t *cid;
/*
@@ -45,13 +40,13 @@ ngx_quic_open_sockets(ngx_connection_t *c, ngx_quic_connection_t *qc,
return NGX_ERROR;
}
- /* socket to use for further processing */
- qsock = ngx_quic_alloc_socket(c, qc);
+ /* socket to use for further processing (id auto-generated) */
+ qsock = ngx_quic_create_socket(c, qc);
if (qsock == NULL) {
return NGX_ERROR;
}
- /* socket is listening at new server id (autogenerated) */
+ /* socket is listening at new server id */
if (ngx_quic_listen(c, qc, qsock) != NGX_OK) {
return NGX_ERROR;
}
@@ -88,10 +83,22 @@ ngx_quic_open_sockets(ngx_connection_t *c, ngx_quic_connection_t *qc,
/* now bind socket to client and path */
ngx_quic_connect(c, qsock, path, cid);
- if (ngx_quic_create_temp_socket(c, qc, &pkt->odcid, path, cid) != NGX_OK) {
+ tmp = ngx_pcalloc(c->pool, sizeof(ngx_quic_socket_t));
+ if (tmp == NULL) {
+ goto failed;
+ }
+
+ tmp->sid.seqnum = NGX_QUIC_UNSET_PN; /* temporary socket */
+
+ ngx_memcpy(tmp->sid.id, pkt->odcid.data, pkt->odcid.len);
+ tmp->sid.len = pkt->odcid.len;
+
+ if (ngx_quic_listen(c, qc, tmp) != NGX_OK) {
goto failed;
}
+ ngx_quic_connect(c, tmp, path, cid);
+
/* use this socket as default destination */
qc->socket = qsock;
@@ -111,48 +118,8 @@ failed:
}
-static ngx_int_t
-ngx_quic_create_temp_socket(ngx_connection_t *c, ngx_quic_connection_t *qc,
- ngx_str_t *dcid, ngx_quic_path_t *path, ngx_quic_client_id_t *cid)
-{
- ngx_str_t id;
- ngx_quic_socket_t *qsock;
- ngx_quic_server_id_t *sid;
-
- qsock = ngx_quic_alloc_socket(c, qc);
- if (qsock == NULL) {
- return NGX_ERROR;
- }
-
- sid = &qsock->sid;
-
- sid->seqnum = NGX_QUIC_UNSET_PN; /* mark socket as temporary */
-
- sid->len = dcid->len;
- ngx_memcpy(sid->id, dcid->data, dcid->len);
-
- id.len = sid->len;
- id.data = sid->id;
-
- ngx_insert_udp_connection(c, &qsock->udp, &id);
-
- ngx_queue_insert_tail(&qc->sockets, &qsock->queue);
-
- qc->nsockets++;
- qsock->quic = qc;
-
- ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "quic socket #%L listening at sid:%xV nsock:%ui",
- (int64_t) sid->seqnum, &id, qc->nsockets);
-
- ngx_quic_connect(c, qsock, path, cid);
-
- return NGX_OK;
-}
-
-
ngx_quic_socket_t *
-ngx_quic_alloc_socket(ngx_connection_t *c, ngx_quic_connection_t *qc)
+ngx_quic_create_socket(ngx_connection_t *c, ngx_quic_connection_t *qc)
{
ngx_queue_t *q;
ngx_quic_socket_t *sock;
@@ -174,6 +141,13 @@ ngx_quic_alloc_socket(ngx_connection_t *c, ngx_quic_connection_t *qc)
}
}
+ sock->sid.len = NGX_QUIC_SERVER_CID_LEN;
+ if (ngx_quic_create_server_id(c, sock->sid.id) != NGX_OK) {
+ return NULL;
+ }
+
+ sock->sid.seqnum = qc->server_seqnum++;
+
return sock;
}
@@ -236,14 +210,6 @@ ngx_quic_listen(ngx_connection_t *c, ngx_quic_connection_t *qc,
sid = &qsock->sid;
- sid->len = NGX_QUIC_SERVER_CID_LEN;
-
- if (ngx_quic_create_server_id(c, sid->id) != NGX_OK) {
- return NGX_ERROR;
- }
-
- sid->seqnum = qc->server_seqnum++;
-
id.data = sid->id;
id.len = sid->len;
@@ -255,8 +221,8 @@ ngx_quic_listen(ngx_connection_t *c, ngx_quic_connection_t *qc,
qsock->quic = qc;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "quic socket #%uL listening at sid:%xV nsock:%ui",
- sid->seqnum, &id, qc->nsockets);
+ "quic socket #%L listening at sid:%xV nsock:%ui",
+ (int64_t) sid->seqnum, &id, qc->nsockets);
return NGX_OK;
}
diff --git a/src/event/quic/ngx_event_quic_socket.h b/src/event/quic/ngx_event_quic_socket.h
index 72ed67ad0..51f01a1fa 100644
--- a/src/event/quic/ngx_event_quic_socket.h
+++ b/src/event/quic/ngx_event_quic_socket.h
@@ -16,7 +16,7 @@ ngx_int_t ngx_quic_open_sockets(ngx_connection_t *c,
ngx_quic_connection_t *qc, ngx_quic_header_t *pkt);
void ngx_quic_close_sockets(ngx_connection_t *c);
-ngx_quic_socket_t *ngx_quic_alloc_socket(ngx_connection_t *c,
+ngx_quic_socket_t *ngx_quic_create_socket(ngx_connection_t *c,
ngx_quic_connection_t *qc);
ngx_int_t ngx_quic_listen(ngx_connection_t *c, ngx_quic_connection_t *qc,
ngx_quic_socket_t *qsock);