aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Arutyunyan <arut@nginx.com>2023-01-31 14:12:18 +0400
committerRoman Arutyunyan <arut@nginx.com>2023-01-31 14:12:18 +0400
commit341c21c9f6373ceeb0ad2513e14c5cd97e958b28 (patch)
treef2a7369f0f992f1ba534e9a399c68503f252c5ed /src
parentc3edcc17b6843bbfeb61f2dc7c51115b6a4272b0 (diff)
downloadnginx-341c21c9f6373ceeb0ad2513e14c5cd97e958b28.tar.gz
nginx-341c21c9f6373ceeb0ad2513e14c5cd97e958b28.zip
QUIC: ngx_quic_copy_buffer() function.
The function copies passed data to QUIC buffer chain and returns it. The chain can be used in ngx_quic_frame_t data field.
Diffstat (limited to 'src')
-rw-r--r--src/event/quic/ngx_event_quic_frames.c33
-rw-r--r--src/event/quic/ngx_event_quic_frames.h2
-rw-r--r--src/event/quic/ngx_event_quic_ssl.c23
3 files changed, 37 insertions, 21 deletions
diff --git a/src/event/quic/ngx_event_quic_frames.c b/src/event/quic/ngx_event_quic_frames.c
index 9a1a6afe5..9fcc97e02 100644
--- a/src/event/quic/ngx_event_quic_frames.c
+++ b/src/event/quic/ngx_event_quic_frames.c
@@ -387,6 +387,39 @@ ngx_quic_split_frame(ngx_connection_t *c, ngx_quic_frame_t *f, size_t len)
ngx_chain_t *
+ngx_quic_copy_buffer(ngx_connection_t *c, u_char *data, size_t len)
+{
+ ngx_buf_t buf;
+ ngx_chain_t cl, *out;
+ ngx_quic_buffer_t qb;
+
+ ngx_memzero(&buf, sizeof(ngx_buf_t));
+
+ buf.pos = data;
+ buf.last = buf.pos + len;
+ buf.temporary = 1;
+
+ cl.buf = &buf;
+ cl.next = NULL;
+
+ ngx_memzero(&qb, sizeof(ngx_quic_buffer_t));
+
+ if (ngx_quic_write_buffer(c, &qb, &cl, len, 0) == NGX_CHAIN_ERROR) {
+ return NGX_CHAIN_ERROR;
+ }
+
+ out = ngx_quic_read_buffer(c, &qb, len);
+ if (out == NGX_CHAIN_ERROR) {
+ return NGX_CHAIN_ERROR;
+ }
+
+ ngx_quic_free_buffer(c, &qb);
+
+ return out;
+}
+
+
+ngx_chain_t *
ngx_quic_read_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb, uint64_t limit)
{
uint64_t n;
diff --git a/src/event/quic/ngx_event_quic_frames.h b/src/event/quic/ngx_event_quic_frames.h
index fbff68e5d..2d55af9de 100644
--- a/src/event/quic/ngx_event_quic_frames.h
+++ b/src/event/quic/ngx_event_quic_frames.h
@@ -26,6 +26,8 @@ ngx_int_t ngx_quic_split_frame(ngx_connection_t *c, ngx_quic_frame_t *f,
ngx_chain_t *ngx_quic_alloc_chain(ngx_connection_t *c);
void ngx_quic_free_chain(ngx_connection_t *c, ngx_chain_t *in);
+ngx_chain_t *ngx_quic_copy_buffer(ngx_connection_t *c, u_char *data,
+ size_t len);
ngx_chain_t *ngx_quic_read_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
uint64_t limit);
ngx_chain_t *ngx_quic_write_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
diff --git a/src/event/quic/ngx_event_quic_ssl.c b/src/event/quic/ngx_event_quic_ssl.c
index 0c982bc62..b3059cb4b 100644
--- a/src/event/quic/ngx_event_quic_ssl.c
+++ b/src/event/quic/ngx_event_quic_ssl.c
@@ -160,13 +160,11 @@ ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
{
u_char *p, *end;
size_t client_params_len;
- ngx_buf_t buf;
- ngx_chain_t *out, cl;
+ ngx_chain_t *out;
const uint8_t *client_params;
ngx_quic_tp_t ctp;
ngx_quic_frame_t *frame;
ngx_connection_t *c;
- ngx_quic_buffer_t qb;
ngx_quic_send_ctx_t *ctx;
ngx_quic_connection_t *qc;
#if defined(TLSEXT_TYPE_application_layer_protocol_negotiation)
@@ -243,28 +241,11 @@ ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
ctx = ngx_quic_get_send_ctx(qc, level);
- ngx_memzero(&buf, sizeof(ngx_buf_t));
-
- buf.pos = (u_char *) data;
- buf.last = buf.pos + len;
- buf.temporary = 1;
-
- cl.buf = &buf;
- cl.next = NULL;
-
- ngx_memzero(&qb, sizeof(ngx_quic_buffer_t));
-
- if (ngx_quic_write_buffer(c, &qb, &cl, len, 0) == NGX_CHAIN_ERROR) {
- return 0;
- }
-
- out = ngx_quic_read_buffer(c, &qb, len);
+ out = ngx_quic_copy_buffer(c, (u_char *) data, len);
if (out == NGX_CHAIN_ERROR) {
return 0;
}
- ngx_quic_free_buffer(c, &qb);
-
frame = ngx_quic_alloc_frame(c);
if (frame == NULL) {
return 0;