master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
26#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_PROXY) && \
27 defined(USE_PROXY_HTTP3) && defined(USE_NGHTTP3) && \
28 defined(USE_NGTCP2) && defined(USE_OPENSSL)
30#include "urldata.h"
31#include "url.h"
32#include "curl_trc.h"
33#include "sendf.h"
34#include "multiif.h"
35#include "cfilters.h"
36#include "connect.h"
37#include "progress.h"
38#include "curlx/dynbuf.h"
39#include "http_proxy.h"
40#include "vquic/vquic.h"
41#include "vquic/cf-ngtcp2-cmn.h"
42#include "vquic/cf-ngtcp2-proxy.h"
43#include "capsule.h"
45/* A stream window is the maximum amount we need to buffer for
46 * each active transfer. We use HTTP/3 flow control and only ACK
47 * when we take things out of the buffer.
48 * Chunk size is large enough to take a full DATA frame */
49#define PROXY_H3_TUNNEL_RX_WIN (512 * 1024)
50#define PROXY_H3_TUNNEL_RECV_CHUNKS \
51 (PROXY_H3_TUNNEL_RX_WIN / H3_STREAM_CHUNK_SIZE)
53typedef enum {
54 H3_TUNNEL_INIT, /* init/default/no tunnel state */
55 H3_TUNNEL_CONNECT, /* CONNECT request is being sent */
56 H3_TUNNEL_RESPONSE, /* CONNECT response received completely */
57 H3_TUNNEL_ESTABLISHED,
58 H3_TUNNEL_FAILED
59} h3_tunnel_state;
61struct h3_tunnel_stream {
62 struct Curl_peer *dest; /* where the tunnel goes to */
63 struct http_resp *resp;
64 struct bufq recvbuf;
65 char *authority;
66 struct h3_stream_ctx *stream;
67 h3_tunnel_state state;
68 BIT(udp);
69 BIT(has_final_response);
70 BIT(closed);
71};
73static CURLcode h3_tunnel_stream_init(struct h3_tunnel_stream *ts,
74 struct Curl_peer *dest,
75 bool udp)
76{
77 ts->state = H3_TUNNEL_INIT;
78 Curl_peer_link(&ts->dest, dest);
79 Curl_bufq_init2(&ts->recvbuf, H3_STREAM_CHUNK_SIZE,
80 PROXY_H3_TUNNEL_RECV_CHUNKS, BUFQ_OPT_SOFT_LIMIT);
81 ts->udp = udp;
82 /* host:port with IPv6 support */
83 ts->authority = curl_maprintf("%s%s%s:%u", dest->ipv6 ? "[" : "",
84 dest->hostname,
85 dest->ipv6 ? "]" : "",
86 dest->port);
87 if(!ts->authority)
88 return CURLE_OUT_OF_MEMORY;
90 return CURLE_OK;
91}
93static void h3_tunnel_stream_reset(struct h3_tunnel_stream *ts)
94{
95 Curl_bufq_reset(&ts->recvbuf);
96 Curl_http_resp_free(ts->resp);
97 ts->resp = NULL;
98 ts->stream = NULL;
99 ts->has_final_response = FALSE;
100 ts->closed = FALSE;
101 ts->state = H3_TUNNEL_INIT;
102}
104static void h3_tunnel_stream_cleanup(struct h3_tunnel_stream *ts)
105{
106 Curl_peer_unlink(&ts->dest);
107 Curl_bufq_free(&ts->recvbuf);
108 Curl_http_resp_free(ts->resp);
109 curlx_safefree(ts->authority);
110 ts->state = H3_TUNNEL_INIT;
111}
113static void h3_tunnel_go_state(struct Curl_cfilter *cf,
114 struct h3_tunnel_stream *ts,
115 h3_tunnel_state new_state,
116 struct Curl_easy *data)
117{
118 VERBOSE(int64_t stream_id = ts->stream ? ts->stream->id : -1);
119 (void)cf;
121 if(ts->state == new_state)
122 return;
124 /* leaving this one */
125 switch(ts->state) {
126 case H3_TUNNEL_CONNECT:
127 data->req.ignorebody = FALSE;
128 break;
129 default:
130 break;
131 }
133 /* entering this one */
134 switch(new_state) {
135 case H3_TUNNEL_INIT:
136 CURL_TRC_CF(data, cf, "[%" PRId64 "] -> [init]", stream_id);
137 h3_tunnel_stream_reset(ts);
138 break;
139 case H3_TUNNEL_CONNECT:
140 CURL_TRC_CF(data, cf, "[%" PRId64 "] -> [connect]", stream_id);
141 ts->state = H3_TUNNEL_CONNECT;
142 break;
143 case H3_TUNNEL_RESPONSE:
144 CURL_TRC_CF(data, cf, "[%" PRId64 "] -> [response]", stream_id);
145 ts->state = H3_TUNNEL_RESPONSE;
146 break;
147 case H3_TUNNEL_ESTABLISHED:
148 CURL_TRC_CF(data, cf, "[%" PRId64 "] -> [established]", stream_id);
149 infof(data, "CONNECT%s phase completed for HTTP/3 proxy",
150 ts->udp ? "-UDP" : "");
151 data->state.authproxy.done = TRUE;
152 data->state.authproxy.multipass = FALSE;
153 ts->state = new_state;
154 curlx_safefree(data->req.hd_proxy_auth);
155 break;
156 case H3_TUNNEL_FAILED:
157 CURL_TRC_CF(data, cf, "[%" PRId64 "] -> [failed]", stream_id);
158 ts->state = new_state;
159 /* If a proxy-authorization header was used for the proxy, then we should
160 make sure that it is not accidentally used for the document request
161 after we have connected. So let's free and clear it here. */
162 curlx_safefree(data->req.hd_proxy_auth);
163 break;
164 }
165}
167struct cf_h3_proxy_ctx {
168 struct cf_ngtcp2_ctx ngtcp2_ctx;
169 struct h3_tunnel_stream tunnel; /* our tunnel CONNECT stream */
170 BIT(connected);
171};
173static CURLcode cf_ngtcp2_proxy_h3_init(struct Curl_cfilter *cf,
174 struct Curl_easy *data,
175 struct cf_ngtcp2_ctx *ctx);
177static CURLcode cf_h3_proxy_ctx_init(struct cf_h3_proxy_ctx *ctx,
178 struct Curl_peer *origin,
179 struct Curl_peer *peer,
180 struct ssl_filter_config *sslc,
181 struct Curl_peer *tunnel_peer,
182 uint8_t tunnel_transport)
183{
184 CURLcode result;
185 result = Curl_cf_ngtcp2_ctx_init(&ctx->ngtcp2_ctx, origin, peer,
186 sslc, cf_ngtcp2_proxy_h3_init);
187 if(!result)
188 result = h3_tunnel_stream_init(&ctx->tunnel, tunnel_peer,
189 TRNSPRT_IS_DGRAM(tunnel_transport));
190 return result;
191}
193static void cf_h3_proxy_ctx_free(struct cf_h3_proxy_ctx *ctx)
194{
195 if(ctx) {
196 Curl_cf_ngtcp2_ctx_cleanup(&ctx->ngtcp2_ctx);
197 h3_tunnel_stream_cleanup(&ctx->tunnel);
198 curlx_free(ctx);
199 }
200}
202static int cb_h3_proxy_acked_req_body(nghttp3_conn *conn, int64_t stream_id,
203 uint64_t datalen, void *user_data,
204 void *stream_user_data)
205{
206 struct Curl_cfilter *cf = user_data;
207 struct cf_h3_proxy_ctx *pctx = cf->ctx;
208 struct h3_stream_ctx *stream;
209 size_t skiplen;
210 (void)stream_user_data;
212 stream = pctx->tunnel.stream;
213 if(!stream || (stream->id != stream_id))
214 return 0;
216 /* The server acknowledged `datalen` of bytes from our request body.
217 * This is a delta. We have kept this data in `sendbuf` for
218 * re-transmissions and can free it now. */
219 if(datalen >= (uint64_t)stream->tx_in_flight_size)
220 skiplen = stream->tx_in_flight_size;
221 else
222 skiplen = (size_t)datalen;
223 Curl_bufq_skip(&stream->sendbuf, skiplen);
224 stream->tx_in_flight_size -= skiplen;
226 /* Resume upload processing if we have more data to send */
227 if(stream->tx_in_flight_size < Curl_bufq_len(&stream->sendbuf)) {
228 int rv = nghttp3_conn_resume_stream(conn, stream_id);
229 if(rv && rv != NGHTTP3_ERR_STREAM_NOT_FOUND) {
230 return NGHTTP3_ERR_CALLBACK_FAILURE;
231 }
232 }
233 return 0;
234}
236static int cb_h3_proxy_stream_close(nghttp3_conn *conn, int64_t stream_id,
237 uint64_t app_error_code, void *user_data,
238 void *stream_user_data)
239{
240 struct Curl_cfilter *cf = user_data;
241 struct cf_h3_proxy_ctx *pctx = cf->ctx;
242 struct Curl_easy *data = CF_DATA_CURRENT(cf);
243 struct h3_stream_ctx *stream;
245 (void)conn;
246 (void)stream_user_data;
247 if(!data)
248 return NGHTTP3_ERR_CALLBACK_FAILURE;
250 stream = pctx->tunnel.stream;
251 if(!stream || (stream->id != stream_id))
252 return 0;
254 stream->closed = TRUE;
255 stream->error3 = app_error_code;
256 if(stream->error3 != NGHTTP3_H3_NO_ERROR) {
257 stream->reset = TRUE;
258 stream->send_closed = TRUE;
259 CURL_TRC_CF(data, cf, "[%" PRId64 "] RESET: error %" PRIu64,
260 stream->id, stream->error3);
261 }
262 else
263 CURL_TRC_CF(data, cf, "[%" PRId64 "] CLOSED", stream->id);
264 pctx->tunnel.stream = NULL;
265 pctx->tunnel.closed = TRUE;
266 Curl_multi_mark_dirty(data);
267 return 0;
268}
270static void cf_h3_proxy_upd_rx_win(struct Curl_cfilter *cf,
271 struct Curl_easy *data,
272 struct h3_stream_ctx *stream)
273{
274 struct cf_h3_proxy_ctx *pctx = cf->ctx;
275 struct cf_ngtcp2_ctx *ctx = &pctx->ngtcp2_ctx;
276 uint64_t cur_win, wanted_win = 0;
277 size_t rx_buffered;
279 if(!stream) /* already closed */
280 return;
281 if(stream->rx_offset_max < stream->rx_offset) {
282 DEBUGASSERT(0);
283 return;
284 }
286 rx_buffered = Curl_bufq_len(&pctx->tunnel.recvbuf);
287 wanted_win = (rx_buffered < PROXY_H3_TUNNEL_RX_WIN) ?
288 (PROXY_H3_TUNNEL_RX_WIN - rx_buffered) : 0;
289 cur_win = stream->rx_offset_max - stream->rx_offset;
290 if(wanted_win > cur_win) {
291 uint64_t delta = wanted_win - cur_win;
293 if(UINT64_MAX - delta < stream->rx_offset_max)
294 delta = UINT64_MAX - stream->rx_offset_max;
295 if(delta) {
296 CURL_TRC_CF(data, cf, "[%" PRId64 "] rx window, extend %" PRIu64
297 " (buffered %zu) by %" PRIu64 " bytes",
298 stream->id, cur_win, rx_buffered, delta);
299 stream->rx_offset_max += delta;
300 ngtcp2_conn_extend_max_stream_offset(ctx->qconn, stream->id, delta);
301 ngtcp2_conn_extend_max_offset(ctx->qconn, delta);
302 }
303 }
304}
306static int cb_h3_proxy_recv_data(nghttp3_conn *conn, int64_t stream3_id,
307 const uint8_t *buf, size_t buflen,
308 void *user_data, void *stream_user_data)
309{
310 struct Curl_cfilter *cf = user_data;
311 struct cf_h3_proxy_ctx *pctx = cf->ctx;
312 struct Curl_easy *data = CF_DATA_CURRENT(cf);
313 struct h3_stream_ctx *stream;
314 size_t nwritten;
315 CURLcode result = CURLE_OK;
316 (void)conn;
317 (void)stream3_id;
318 (void)stream_user_data;
320 stream = pctx->tunnel.stream;
321 if(!data || !stream || (stream->id != stream3_id)) {
322 return NGHTTP3_ERR_CALLBACK_FAILURE;
323 }
325 stream->rx_total += (curl_off_t)buflen;
326 CURL_TRC_CF(data, cf, "[cb_h3_proxy_recv_data] "
327 "[%" PRId64 "] DATA len=%zu, total=%" FMT_OFF_T,
328 stream->id, buflen, stream->rx_total);
330 result = Curl_bufq_write(&pctx->tunnel.recvbuf, buf, buflen, &nwritten);
331 if(result || (nwritten < buflen)) {
332 return NGHTTP3_ERR_CALLBACK_FAILURE;
333 }
335 /* DATA has been moved into our local recv buffer. Update stream offsets. */
336 stream->rx_offset += buflen;
337 if(stream->rx_offset_max < stream->rx_offset)
338 stream->rx_offset_max = stream->rx_offset;
340 CURL_TRC_CF(data, cf, "[%" PRId64 "] DATA len=%zu, rx win=%" PRIu64,
341 stream->id, buflen, stream->rx_offset_max - stream->rx_offset);
342 cf_h3_proxy_upd_rx_win(cf, data, stream);
344 Curl_multi_mark_dirty(data);
345 return 0;
346}
348static int cb_h3_proxy_deferred_consume(nghttp3_conn *conn, int64_t stream_id,
349 size_t consumed, void *user_data,
350 void *stream_user_data)
351{
352 struct Curl_cfilter *cf = user_data;
353 struct cf_h3_proxy_ctx *pctx = cf->ctx;
354 struct cf_ngtcp2_ctx *ctx = &pctx->ngtcp2_ctx;
355 (void)conn;
356 (void)stream_user_data;
358 if(!ctx)
359 return 0;
361 /* nghttp3 has consumed bytes on the QUIC stream and we need to
362 * tell the QUIC connection to increase its flow control */
363 ngtcp2_conn_extend_max_stream_offset(ctx->qconn, stream_id, consumed);
364 ngtcp2_conn_extend_max_offset(ctx->qconn, consumed);
366 return 0;
367}
369static int cb_h3_proxy_recv_header(nghttp3_conn *conn, int64_t stream_id,
370 int32_t token, nghttp3_rcbuf *name,
371 nghttp3_rcbuf *value, uint8_t flags,
372 void *user_data, void *stream_user_data)
373{
374 struct Curl_cfilter *cf = user_data;
375 struct cf_h3_proxy_ctx *pctx = cf->ctx;
376 nghttp3_vec h3name = nghttp3_rcbuf_get_buf(name);
377 nghttp3_vec h3val = nghttp3_rcbuf_get_buf(value);
378 struct Curl_easy *data = CF_DATA_CURRENT(cf);
379 struct h3_stream_ctx *stream;
380 CURLcode result = CURLE_OK;
381 int http_status;
382 struct http_resp *resp;
383 (void)conn;
384 (void)stream_id;
385 (void)token;
386 (void)flags;
387 (void)stream_user_data;
389 /* stream_user_data might be NULL for control streams */
390 if(!data)
391 return NGHTTP3_ERR_CALLBACK_FAILURE;
393 stream = pctx->tunnel.stream;
394 if(!stream || (stream->id != stream_id)) {
395 CURL_TRC_CF(data, cf, "[%" PRId64 "] recv_header: stream lookup "
396 "failed for data=%p mid=%u",
397 stream_id, (void *)data, data ? data->mid : 0);
398 return 0;
399 }
401 if(pctx->tunnel.has_final_response) {
402 /* we do not do anything with trailers for tunnel streams */
403 return 0;
404 }
406 if(token == NGHTTP3_QPACK_TOKEN__STATUS) {
407 result = Curl_http_decode_status(&stream->status_code,
408 (const char *)h3val.base, h3val.len);
409 if(result)
410 return NGHTTP3_ERR_CALLBACK_FAILURE;
411 http_status = stream->status_code;
412 result = Curl_http_resp_make(&resp, http_status, NULL);
413 if(result)
414 return NGHTTP3_ERR_CALLBACK_FAILURE;
415 if(pctx->tunnel.resp)
416 Curl_http_resp_free(pctx->tunnel.resp);
417 pctx->tunnel.resp = resp;
418 }
419 else {
420 if(!pctx->tunnel.resp) {
421 return NGHTTP3_ERR_CALLBACK_FAILURE;
422 }
423 /* store as an HTTP1-style header */
424 CURL_TRC_CF(data, cf, "[%" PRId64 "] header: %.*s: %.*s", stream_id,
425 (int)h3name.len, h3name.base, (int)h3val.len, h3val.base);
426 result = Curl_dynhds_add(&pctx->tunnel.resp->headers,
427 (const char *)h3name.base, h3name.len,
428 (const char *)h3val.base, h3val.len);
429 if(result) {
430 return NGHTTP3_ERR_CALLBACK_FAILURE;
431 }
432 }
433 return 0;
434}
436static int cb_h3_proxy_end_headers(nghttp3_conn *conn, int64_t stream_id,
437 int fin, void *user_data,
438 void *stream_user_data)
439{
440 struct Curl_cfilter *cf = user_data;
441 struct cf_h3_proxy_ctx *pctx = cf->ctx;
442 struct Curl_easy *data = CF_DATA_CURRENT(cf);
443 struct h3_stream_ctx *stream;
444 (void)conn;
445 (void)stream_id;
446 (void)fin;
447 (void)stream_user_data;
449 if(!data)
450 return NGHTTP3_ERR_CALLBACK_FAILURE;
452 stream = pctx->tunnel.stream;
453 if(!stream || (stream->id != stream_id)) {
454 CURL_TRC_CF(data, cf, "[%" PRId64 "] end_headers: stream lookup "
455 "failed for data=%p mid=%u",
456 stream_id, (void *)data, data ? data->mid : 0);
457 return 0;
458 }
460 CURL_TRC_CF(data, cf, "[%" PRId64 "] end_headers, status=%d", stream_id,
461 stream->status_code);
463 if(!pctx->tunnel.has_final_response) {
464 if(stream->status_code / 100 != 1) {
465 pctx->tunnel.has_final_response = TRUE;
466 }
467 }
469 if(stream->status_code / 100 != 1) {
470 stream->resp_hds_complete = TRUE;
471 }
473 Curl_multi_mark_dirty(data);
474 return 0;
475}
477static int cb_h3_proxy_stop_sending(nghttp3_conn *conn, int64_t stream_id,
478 uint64_t app_error_code, void *user_data,
479 void *stream_user_data)
480{
481 struct Curl_cfilter *cf = user_data;
482 struct cf_h3_proxy_ctx *pctx = cf->ctx;
483 struct cf_ngtcp2_ctx *ctx = &pctx->ngtcp2_ctx;
484 (void)conn;
485 (void)stream_user_data;
487 if(ctx) {
488 int rv = ngtcp2_conn_shutdown_stream_read(ctx->qconn, 0, stream_id,
489 app_error_code);
491 if(rv && rv != NGTCP2_ERR_STREAM_NOT_FOUND) {
492 return NGHTTP3_ERR_CALLBACK_FAILURE;
493 }
494 }
496 return 0;
497}
499static int cb_h3_proxy_reset_stream(nghttp3_conn *conn, int64_t stream_id,
500 uint64_t app_error_code, void *user_data,
501 void *stream_user_data)
502{
503 struct Curl_cfilter *cf = user_data;
504 struct cf_h3_proxy_ctx *pctx = cf->ctx;
505 struct cf_ngtcp2_ctx *ctx = &pctx->ngtcp2_ctx;
506 struct Curl_easy *data = CF_DATA_CURRENT(cf);
507 int rv;
509 (void)conn;
510 (void)stream_user_data;
511 if(!data)
512 return NGHTTP3_ERR_CALLBACK_FAILURE;
514 if(!pctx->tunnel.stream ||
515 (stream_id != pctx->tunnel.stream->id))
516 return 0;
518 rv = ngtcp2_conn_shutdown_stream_write(ctx->qconn, 0, stream_id,
519 app_error_code);
520 CURL_TRC_CF(data, cf, "[%" PRId64 "] reset -> %d", stream_id, rv);
521 pctx->tunnel.stream = NULL;
522 pctx->tunnel.closed = TRUE;
523 if(rv && rv != NGTCP2_ERR_STREAM_NOT_FOUND) {
524 return NGHTTP3_ERR_CALLBACK_FAILURE;
525 }
526 return 0;
527}
529static nghttp3_ssize cb_h3_tunnel_read_data(nghttp3_conn *conn,
530 int64_t stream_id,
531 nghttp3_vec *vec,
532 size_t veccnt,
533 uint32_t *pflags,
534 void *user_data,
535 void *stream_user_data)
536{
537 struct Curl_cfilter *cf = user_data;
538 struct cf_h3_proxy_ctx *pctx = cf->ctx;
539 struct Curl_easy *data = CF_DATA_CURRENT(cf);
540 struct h3_stream_ctx *stream;
541 size_t nwritten = 0;
542 size_t nvecs = 0;
543 const unsigned char *buf_base;
545 (void)conn;
546 (void)stream_id;
547 (void)veccnt;
548 (void)stream_user_data;
549 (void)pflags;
551 stream = pctx->tunnel.stream;
552 if(!data || !stream || (stream->id != stream_id))
553 return NGHTTP3_ERR_CALLBACK_FAILURE;
555 /* nghttp3 keeps references to the sendbuf data until it is ACKed
556 * by the server (see `cb_h3_proxy_acked_req_body()` for updates).
557 * `tx_in_flight_size` is the amount of bytes in `sendbuf`
558 * that we have already passed to nghttp3, but which have not been
559 * ACKed yet.
560 * Any amount beyond `tx_in_flight_size` we need still to pass
561 * to nghttp3. Do that now, if we can. */
562 if(stream->tx_in_flight_size < Curl_bufq_len(&stream->sendbuf)) {
563 nvecs = 0;
564 while(nvecs < veccnt) {
565 if(!Curl_bufq_peek_at(&stream->sendbuf,
566 stream->tx_in_flight_size,
567 &buf_base,
568 &vec[nvecs].len))
569 break;
570 vec[nvecs].base = (uint8_t *)(uintptr_t)buf_base;
571 stream->tx_in_flight_size += vec[nvecs].len;
572 nwritten += vec[nvecs].len;
573 ++nvecs;
574 }
575 DEBUGASSERT(nvecs > 0); /* we SHOULD have been able to peek */
576 }
578 if(!nwritten) {
579 /* Not EOF, and nothing to give, we signal WOULDBLOCK. */
580 CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> AGAIN",
581 stream->id);
582 return NGHTTP3_ERR_WOULDBLOCK;
583 }
585 CURL_TRC_CF(data, cf, "[%" PRId64 "] read req body -> "
586 "%zu vecs%s with %zu (buffered=%zu)",
587 stream->id, nvecs,
588 *pflags == NGHTTP3_DATA_FLAG_EOF ? " EOF" : "",
589 nwritten, Curl_bufq_len(&stream->sendbuf));
590 return (nghttp3_ssize)nvecs;
591}
593#ifdef CURL_HAVE_DIAG
594#pragma GCC diagnostic push
595#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
596#endif
597static nghttp3_callbacks ngh3_proxy_callbacks = {
598 cb_h3_proxy_acked_req_body, /* acked_stream_data */
599 cb_h3_proxy_stream_close,
600 cb_h3_proxy_recv_data,
601 cb_h3_proxy_deferred_consume,
602 NULL, /* begin_headers */
603 cb_h3_proxy_recv_header,
604 cb_h3_proxy_end_headers,
605 NULL, /* begin_trailers */
606 cb_h3_proxy_recv_header,
607 NULL, /* end_trailers */
608 cb_h3_proxy_stop_sending,
609 NULL, /* end_stream */
610 cb_h3_proxy_reset_stream,
611 NULL, /* shutdown */
612 NULL, /* recv_settings (deprecated) */
613#ifdef NGHTTP3_CALLBACKS_V2 /* nghttp3 v1.11.0+ */
614 NULL, /* recv_origin */
615 NULL, /* end_origin */
616 NULL, /* rand */
617#endif
618#ifdef NGHTTP3_CALLBACKS_V3 /* nghttp3 v1.14.0+ */
619 NULL, /* recv_settings2 */
620#endif
621#ifdef NGHTTP3_CALLBACKS_V4 /* nghttp3 v1.18.0+ */
622 NULL, /* stream_close2 */
623#endif
624};
625#ifdef CURL_HAVE_DIAG
626#pragma GCC diagnostic pop
627#endif
629static CURLcode cf_ngtcp2_proxy_h3_init(struct Curl_cfilter *cf,
630 struct Curl_easy *data,
631 struct cf_ngtcp2_ctx *ctx)
632{
633 int rc;
635 if(ngtcp2_conn_get_streams_uni_left(ctx->qconn) < 3) {
636 failf(data, "QUIC connection lacks 3 uni streams to run HTTP/3");
637 return CURLE_QUIC_CONNECT_ERROR;
638 }
640 nghttp3_settings_default(&ctx->h3settings);
642 rc = nghttp3_conn_client_new(&ctx->h3conn,
643 &ngh3_proxy_callbacks,
644 &ctx->h3settings,
645 Curl_nghttp3_mem(),
646 cf);
647 if(rc) {
648 failf(data, "error creating nghttp3 connection instance");
649 return CURLE_OUT_OF_MEMORY;
650 }
652 return Curl_cf_ngtcp2_h3_init_ctrls(ctx, data);
653}
655static ssize_t cf_h3_proxy_recv_closed_stream(struct Curl_cfilter *cf,
656 struct Curl_easy *data,
657 struct h3_stream_ctx *stream,
658 CURLcode *err)
659{
660 ssize_t nread = -1;
661 *err = CURLE_OK;
663 if(stream->reset) {
664 if(stream->error3 == CURL_H3_ERR_REQUEST_REJECTED) {
665 infof(data, "HTTP/3 stream %" PRId64 " refused by server, try again "
666 "on a new connection", stream->id);
667 connclose(cf->conn);
668 data->state.refused_stream = TRUE;
669 *err = CURLE_RECV_ERROR;
670 goto out;
671 }
672 else if(stream->resp_hds_complete && data->req.no_body) {
673 CURL_TRC_CF(data, cf, "[%" PRId64 "] error after response headers, "
674 "but we did not want a body anyway, ignore error 0x%"
675 PRIx64 " %s", stream->id, stream->error3,
676 Curl_vquic_h3_err_str(stream->error3));
677 nread = 0;
678 goto out;
679 }
680 failf(data, "HTTP/3 stream %" PRId64 " reset by server (error 0x%" PRIx64
681 " %s)", stream->id, stream->error3,
682 Curl_vquic_h3_err_str(stream->error3));
683 *err = data->req.bytecount ? CURLE_PARTIAL_FILE : CURLE_HTTP3;
684 goto out;
685 }
686 else if(!stream->resp_hds_complete) {
687 failf(data,
688 "HTTP/3 stream %" PRId64 " was closed cleanly, but before "
689 "getting all response header fields, treated as error",
690 stream->id);
691 *err = CURLE_HTTP3;
692 goto out;
693 }
694 nread = 0;
696out:
697 return nread;
698}
700static CURLcode cf_h3_proxy_sendbuf_add(struct Curl_easy *data,
701 struct h3_stream_ctx *stream,
702 const uint8_t *buf, size_t len,
703 size_t *pnwritten)
704{
705 CURLcode result;
706 *pnwritten = 0;
707 (void)data;
709 result = Curl_bufq_write(&stream->sendbuf, buf, len, pnwritten);
710 return result;
711}
713static CURLcode cf_h3_proxy_send(struct Curl_cfilter *cf,
714 struct Curl_easy *data,
715 const uint8_t *buf, size_t len,
716 bool eos, size_t *pnwritten)
717{
718 struct cf_h3_proxy_ctx *pctx = cf->ctx;
719 struct cf_ngtcp2_ctx *ctx = &pctx->ngtcp2_ctx;
720 struct h3_stream_ctx *stream = NULL;
721 struct cf_call_data save;
722 struct cf_ngtcp2_io_ctx pktx;
723 CURLcode result = CURLE_OK;
725 CF_DATA_SAVE(save, cf, data);
726 DEBUGASSERT(cf->connected);
727 DEBUGASSERT(ctx->qconn);
728 DEBUGASSERT(ctx->h3conn);
729 Curl_cf_ngtcp2_io_ctx_init(&pktx, cf, data);
730 *pnwritten = 0;
732 /* handshake verification failed in callback, do not send anything */
733 if(ctx->tls_vrfy_result) {
734 result = ctx->tls_vrfy_result;
735 goto denied;
736 }
738 (void)eos; /* use for stream EOF and block handling */
739 result = Curl_cf_ngtcp2_progress_ingress(cf, data, &pktx);
740 if(result)
741 goto out;
743 if(pctx->tunnel.closed) {
744 result = CURLE_SEND_ERROR;
745 goto denied;
746 }
748 stream = pctx->tunnel.stream;
749 if(!stream) {
750 result = CURLE_SEND_ERROR;
751 goto denied;
752 }
754 if(stream->closed) {
755 if(stream->resp_hds_complete) {
756 /* Server decided to close the stream after having sent us a final
757 * response. This is valid if it is not interested in the request
758 * body. This happens on 30x or 40x responses.
759 * We silently discard the data sent, since this is not a transport
760 * error situation. */
761 CURL_TRC_CF(data, cf, "[%" PRId64 "] discarding data"
762 "on closed stream with response", stream->id);
763 result = CURLE_OK;
764 *pnwritten = len;
765 goto out;
766 }
767 CURL_TRC_CF(data, cf, "[%" PRId64 "] send_body(len=%zu) "
768 "-> stream closed", stream->id, len);
769 result = CURLE_HTTP3;
770 goto out;
771 }
772 else {
773 result = cf_h3_proxy_sendbuf_add(data, stream, buf, len, pnwritten);
774 CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send, add to "
775 "sendbuf(len=%zu) -> %d, %zu",
776 stream->id, len, (int)result, *pnwritten);
777 if(result)
778 goto out;
779 (void)nghttp3_conn_resume_stream(ctx->h3conn, stream->id);
780 }
782 if(*pnwritten > 0 && !ctx->tls_handshake_complete && ctx->use_earlydata)
783 ctx->earlydata_skip += *pnwritten;
785 DEBUGASSERT(!result);
786 result = Curl_cf_ngtcp2_progress_egress(cf, data, &pktx);
788out:
789 result = Curl_1st_fatal(result,
790 Curl_cf_ngtcp2_cmn_set_expiry(cf, data, &pktx));
791denied:
792 CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_send(len=%zu) -> %d, %zu",
793 stream ? stream->id : -1, len, (int)result, *pnwritten);
794 CF_DATA_RESTORE(cf, save);
795 return result;
796}
798/* incoming data frames on the h3 stream */
799static CURLcode cf_h3_proxy_recv(struct Curl_cfilter *cf,
800 struct Curl_easy *data,
801 char *buf, size_t len, size_t *pnread)
802{
803 struct cf_h3_proxy_ctx *pctx = cf->ctx;
804 struct cf_ngtcp2_ctx *ctx = &pctx->ngtcp2_ctx;
805 struct h3_stream_ctx *stream = pctx->tunnel.stream;
806 struct cf_call_data save;
807 struct cf_ngtcp2_io_ctx pktx;
808 CURLcode result = CURLE_OK;
810 CF_DATA_SAVE(save, cf, data);
811 DEBUGASSERT(cf->connected);
812 DEBUGASSERT(ctx);
813 DEBUGASSERT(ctx->qconn);
814 DEBUGASSERT(ctx->h3conn);
815 *pnread = 0;
817 /* handshake verification failed in callback, do not recv anything */
818 if(ctx->tls_vrfy_result) {
819 result = ctx->tls_vrfy_result;
820 goto denied;
821 }
823 Curl_cf_ngtcp2_io_ctx_init(&pktx, cf, data);
825 if(!stream || ctx->shutdown_started) {
826 result = CURLE_RECV_ERROR;
827 goto out;
828 }
830 if(!Curl_bufq_is_empty(&pctx->tunnel.recvbuf)) {
831 result = Curl_bufq_cread(&pctx->tunnel.recvbuf, buf, len, pnread);
832 if(result)
833 goto out;
834 cf_h3_proxy_upd_rx_win(cf, data, pctx->tunnel.stream);
835 }
837 result = Curl_cf_ngtcp2_progress_ingress(cf, data, &pktx);
838 if(result)
839 goto out;
841 /* inbufq had nothing before, maybe after progressing ingress? */
842 if(!*pnread && !Curl_bufq_is_empty(&pctx->tunnel.recvbuf)) {
843 result = Curl_bufq_cread(&pctx->tunnel.recvbuf, buf, len, pnread);
844 if(result) {
845 CURL_TRC_CF(data, cf, "[%" PRId64 "] read inbufq(len=%zu) -> %zu, %d",
846 stream->id, len, *pnread, (int)result);
847 goto out;
848 }
849 cf_h3_proxy_upd_rx_win(cf, data, pctx->tunnel.stream);
850 }
852 if(*pnread) {
853 Curl_multi_mark_dirty(data);
854 }
855 else {
856 if(stream->xfer_result) {
857 CURL_TRC_CF(data, cf, "[%" PRId64 "] xfer write failed", stream->id);
858 Curl_cf_ngtcp2_h3_stream_close(cf, data, stream);
859 result = stream->xfer_result;
860 goto out;
861 }
862 else if(stream->closed) {
863 ssize_t nread =
864 cf_h3_proxy_recv_closed_stream(cf, data, stream, &result);
865 if(nread > 0)
866 *pnread = (size_t)nread;
867 goto out;
868 }
869 result = CURLE_AGAIN;
870 }
872out:
873 result = Curl_1st_fatal(result,
874 Curl_cf_ngtcp2_progress_egress(cf, data, &pktx));
875 result = Curl_1st_fatal(result,
876 Curl_cf_ngtcp2_cmn_set_expiry(cf, data, &pktx));
877denied:
878 CURL_TRC_CF(data, cf, "[%" PRId64 "] cf_recv(len=%zu) -> %d, %zu",
879 stream ? stream->id : -1, len, (int)result, *pnread);
880 CF_DATA_RESTORE(cf, save);
881 return result;
882}
884static CURLcode cf_h3_proxy_submit(struct Curl_cfilter *cf,
885 struct Curl_easy *data,
886 struct h3_tunnel_stream *ts,
887 struct httpreq *req)
888{
889 struct cf_h3_proxy_ctx *pctx = cf->ctx;
890 struct cf_ngtcp2_ctx *ctx = &pctx->ngtcp2_ctx;
891 struct h3_stream_ctx *stream = NULL;
892 struct dynhds h2_headers;
893 nghttp3_nv *nva = NULL;
894 size_t nheader;
895 int rc = 0;
896 unsigned int i;
897 nghttp3_data_reader reader;
898 nghttp3_data_reader *preader = NULL;
899 CURLcode result;
901 Curl_dynhds_init(&h2_headers, 0, DYN_HTTP_REQUEST);
902 result = Curl_http_req_to_h2(&h2_headers, req, data);
903 if(result)
904 goto out;
906 result = Curl_cf_ngtcp2_h3_stream_setup(cf, data, &stream);
907 if(result)
908 goto out;
910 nheader = Curl_dynhds_count(&h2_headers);
911 nva = curlx_malloc(sizeof(nghttp3_nv) * nheader);
912 if(!nva) {
913 result = CURLE_OUT_OF_MEMORY;
914 goto out;
915 }
917 for(i = 0; i < nheader; ++i) {
918 struct dynhds_entry *e = Curl_dynhds_getn(&h2_headers, i);
919 nva[i].name = (unsigned char *)e->name;
920 nva[i].namelen = e->namelen;
921 nva[i].value = (unsigned char *)e->value;
922 nva[i].valuelen = e->valuelen;
923 nva[i].flags = NGHTTP3_NV_FLAG_NONE;
924 }
926 /* Open a bidirectional stream */
927 {
928 int64_t sid;
929 int rv;
931 DEBUGASSERT(stream->id == -1);
932 /* Do NOT set `data` as stream user data. The transfer `data` may
933 * get cleaned up long before the tunnel goes down. */
934 rv = ngtcp2_conn_open_bidi_stream(ctx->qconn, &sid, NULL);
935 if(rv) {
936 failf(data, "cannot get bidi streams: %s", ngtcp2_strerror(rv));
937 result = CURLE_SEND_ERROR;
938 goto out;
939 }
940 stream->id = sid;
941 ts->stream = stream;
942 ++ctx->used_bidi_streams;
943 CURL_TRC_CF(data, cf, "[%" PRId64 "] opened bidi stream", sid);
944 }
946 /* CONNECT-UDP request stream remains open for capsules, no fixed EOF. */
947 stream->send_closed = 0;
948 reader.read_data = cb_h3_tunnel_read_data;
949 preader = &reader;
951 rc = nghttp3_conn_submit_request(ctx->h3conn, stream->id,
952 nva, nheader, preader, stream);
954 if(rc) {
955 switch(rc) {
956 case NGHTTP3_ERR_CONN_CLOSING:
957 CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send, "
958 "connection is closing", stream->id);
959 break;
960 default:
961 CURL_TRC_CF(data, cf, "h3sid[%" PRId64 "] failed to send -> %d (%s)",
962 stream->id, rc, nghttp3_strerror(rc));
963 break;
964 }
965 result = CURLE_SEND_ERROR;
966 goto out;
967 }
969 if(Curl_trc_is_verbose(data)) {
970 CURL_TRC_CF(data, cf, "[H3-PROXY] [%" PRId64 "] OPENED stream "
971 "for %s", stream->id,
972 Curl_bufref_ptr(&data->state.url));
973 }
975out:
976 curlx_free(nva);
977 Curl_dynhds_free(&h2_headers);
978 return result;
979}
981static CURLcode cf_h3_proxy_adjust_pollset(struct Curl_cfilter *cf,
982 struct Curl_easy *data,
983 struct easy_pollset *ps)
984{
985 struct cf_h3_proxy_ctx *pctx = cf->ctx;
986 struct cf_ngtcp2_ctx *ctx = &pctx->ngtcp2_ctx;
987 bool want_recv, want_send;
988 CURLcode result = CURLE_OK;
989 curl_socket_t sock = (ctx->q.sockfd != CURL_SOCKET_BAD) ?
990 ctx->q.sockfd : Curl_conn_cf_get_socket(cf, data);
992 if(!ctx->qconn || !pctx->tunnel.stream || (sock == CURL_SOCKET_BAD))
993 return CURLE_OK;
995 Curl_pollset_check(data, ps, sock, &want_recv, &want_send);
997 if(want_recv || want_send || !Curl_bufq_is_empty(&ctx->q.sendbuf)) {
998 struct h3_stream_ctx *stream = pctx->tunnel.stream;
999 bool c_exhaust, s_exhaust;
1001 c_exhaust = want_send &&
1002 (!ngtcp2_conn_get_cwnd_left(ctx->qconn) ||
1003 !ngtcp2_conn_get_max_data_left(ctx->qconn));
1004 s_exhaust = want_send && stream && stream->id >= 0 &&
1005 stream->quic_flow_blocked;
1006 want_recv = (want_recv || c_exhaust || s_exhaust);
1007 want_send = (!s_exhaust && want_send) ||
1008 !Curl_bufq_is_empty(&ctx->q.sendbuf);
1010 result = Curl_pollset_set(data, ps, sock, want_recv, want_send);
1011 }
1012 return result;
1013}
1015static bool cf_h3_proxy_data_pending(struct Curl_cfilter *cf,
1016 const struct Curl_easy *data)
1017{
1018 struct cf_h3_proxy_ctx *pctx = cf->ctx;
1019 if(!Curl_bufq_is_empty(&pctx->tunnel.recvbuf))
1020 return TRUE;
1021 return cf->next ?
1022 cf->next->cft->has_data_pending(cf->next, data) : FALSE;
1023}
1025static CURLcode cf_h3_proxy_submit_CONNECT(struct Curl_cfilter *cf,
1026 struct Curl_easy *data,
1027 struct h3_tunnel_stream *ts)
1028{
1029 struct cf_h3_proxy_ctx *ctx = cf->ctx;
1030 CURLcode result;
1031 struct httpreq *req = NULL;
1033 result = Curl_http_proxy_create_tunnel_request(
1034 &req, cf, data, ctx->ngtcp2_ctx.ssl_peer.peer,
1035 ts->dest, PROXY_HTTP_V3, (bool)ts->udp);
1036 if(!result)
1037 result = Curl_creader_set_null(data);
1038 if(!result)
1039 result = cf_h3_proxy_submit(cf, data, ts, req);
1041 if(req)
1042 Curl_http_req_free(req);
1043 if(result)
1044 failf(data, "Failed sending CONNECT to proxy");
1045 return result;
1046}
1048static CURLcode cf_h3_proxy_inspect_response(struct Curl_cfilter *cf,
1049 struct Curl_easy *data,
1050 struct h3_tunnel_stream *ts)
1051{
1052 struct cf_h3_proxy_ctx *pctx = cf->ctx;
1053 proxy_inspect_result res;
1054 CURLcode result;
1056 result = Curl_http_proxy_inspect_tunnel_response(
1057 cf, data, ts->resp, (bool)pctx->tunnel.udp, &res);
1058 if(result)
1059 return result;
1060 switch(res) {
1061 case PROXY_INSPECT_OK:
1062 h3_tunnel_go_state(cf, ts, H3_TUNNEL_ESTABLISHED, data);
1063 break;
1064 case PROXY_INSPECT_FAILED:
1065 h3_tunnel_go_state(cf, ts, H3_TUNNEL_FAILED, data);
1066 result = CURLE_COULDNT_CONNECT;
1067 break;
1068 case PROXY_INSPECT_AUTH_RETRY:
1069 h3_tunnel_go_state(cf, ts, H3_TUNNEL_INIT, data);
1070 break;
1071 }
1072 return result;
1073}
1075static CURLcode cf_h3_proxy_tunnel(struct Curl_cfilter *cf,
1076 struct Curl_easy *data,
1077 struct h3_tunnel_stream *ts,
1078 bool *pdone)
1079{
1080 struct cf_h3_proxy_ctx *ctx = cf->ctx;
1081 CURLcode result = CURLE_OK;
1083 DEBUGASSERT(ts);
1084 DEBUGASSERT(ts->authority);
1085 *pdone = FALSE;
1086 do {
1087 switch(ts->state) {
1088 case H3_TUNNEL_INIT:
1089 CURL_TRC_CF(data, cf, "[0] CONNECT start for %s", ts->authority);
1090 result = cf_h3_proxy_submit_CONNECT(cf, data, ts);
1091 if(result)
1092 goto out;
1093 h3_tunnel_go_state(cf, ts, H3_TUNNEL_CONNECT, data);
1095 result = Curl_cf_ngtcp2_progress_egress(cf, data, NULL);
1096 if(result)
1097 goto out;
1098 FALLTHROUGH();
1100 case H3_TUNNEL_CONNECT:
1101 /* Non-blocking: call ingress/egress once and return.
1102 * The multi interface will call us again when ready. */
1103 result = Curl_cf_ngtcp2_progress_ingress(cf, data, NULL);
1104 if(result)
1105 goto out;
1106 result = Curl_cf_ngtcp2_progress_egress(cf, data, NULL);
1107 if(result && result != CURLE_AGAIN) {
1108 h3_tunnel_go_state(cf, ts, H3_TUNNEL_FAILED, data);
1109 goto out;
1110 }
1112 if(ts->has_final_response) {
1113 h3_tunnel_go_state(cf, ts, H3_TUNNEL_RESPONSE, data);
1114 }
1115 else {
1116 /* Not done yet, return and let multi interface call us again */
1117 result = CURLE_OK;
1118 goto out;
1119 }
1120 FALLTHROUGH();
1122 case H3_TUNNEL_RESPONSE:
1123 DEBUGASSERT(ts->has_final_response);
1124 result = cf_h3_proxy_inspect_response(cf, data, ts);
1125 if(result)
1126 goto out;
1127 ctx->connected = TRUE;
1128 break;
1130 case H3_TUNNEL_ESTABLISHED:
1131 *pdone = TRUE;
1132 return CURLE_OK;
1134 case H3_TUNNEL_FAILED:
1135 return CURLE_RECV_ERROR;
1137 default:
1138 break;
1139 }
1141 } while(ts->state == H3_TUNNEL_INIT);
1143out:
1144 if((result && (result != CURLE_AGAIN)) || ctx->tunnel.closed)
1145 h3_tunnel_go_state(cf, ts, H3_TUNNEL_FAILED, data);
1146 return result;
1147}
1149static CURLcode cf_h3_proxy_connect(struct Curl_cfilter *cf,
1150 struct Curl_easy *data, bool *done)
1151{
1152 struct cf_h3_proxy_ctx *pctx = cf->ctx;
1153 struct cf_call_data save = { 0 };
1154 CURLcode result = CURLE_OK;
1155 struct h3_tunnel_stream *ts = &pctx->tunnel;
1156 bool data_saved = FALSE;
1158 result = Curl_cf_ngtcp2_cmn_connect(cf, data, done);
1159 if(result || !*done)
1160 goto out;
1162 CF_DATA_SAVE(save, cf, data);
1163 data_saved = TRUE;
1165 /* At this point the QUIC is connected, but the proxy is not connected */
1166 result = cf_h3_proxy_tunnel(cf, data, ts, done);
1168out:
1169 if(*done) {
1170 cf->connected = TRUE;
1171 /* The real request will follow the CONNECT, reset request partially */
1172 Curl_req_soft_reset(&data->req, data);
1173 Curl_client_reset(data);
1174 }
1176 if(data_saved)
1177 CF_DATA_RESTORE(cf, save);
1178 return result;
1179}
1181static void cf_h3_proxy_destroy(struct Curl_cfilter *cf,
1182 struct Curl_easy *data)
1183{
1184 struct cf_h3_proxy_ctx *ctx = cf->ctx;
1186 (void)data;
1187 if(ctx) {
1188 CURL_TRC_CF(data, cf, "cf_h3_proxy_destroy()");
1189 if(ctx->ngtcp2_ctx.qconn) {
1190 struct cf_call_data save;
1191 CF_DATA_SAVE(save, cf, data);
1192 Curl_cf_ngtcp2_cmn_conn_close(cf, data);
1193 CF_DATA_RESTORE(cf, save);
1194 }
1195 cf_h3_proxy_ctx_free(ctx);
1196 cf->ctx = NULL;
1197 }
1198}
1200static CURLcode cf_h3_proxy_shutdown(struct Curl_cfilter *cf,
1201 struct Curl_easy *data, bool *done)
1202{
1203 return Curl_cf_ngtcp2_cmn_shutdown(cf, data, done);
1204}
1206struct Curl_cftype Curl_cft_h3_proxy = {
1207 "H3-PROXY",
1208 CF_TYPE_IP_CONNECT | CF_TYPE_PROXY | CF_TYPE_SSL,
1209 CURL_LOG_LVL_NONE,
1210 cf_h3_proxy_destroy,
1211 cf_h3_proxy_connect,
1212 cf_h3_proxy_shutdown,
1213 cf_h3_proxy_adjust_pollset,
1214 cf_h3_proxy_data_pending,
1215 cf_h3_proxy_send,
1216 cf_h3_proxy_recv,
1217 Curl_cf_def_cntrl,
1218 Curl_cf_ngtcp2_cmn_conn_is_alive,
1219 Curl_cf_def_conn_keep_alive,
1220 Curl_cf_ngtcp2_cmn_query,
1221};
1223CURLcode Curl_cf_ngtcp2_proxy_create(struct Curl_cfilter **pcf,
1224 struct Curl_easy *data,
1225 struct Curl_peer *origin,
1226 struct Curl_peer *peer,
1227 uint8_t transport_peer,
1228 struct connectdata *conn,
1229 struct Curl_sockaddr_ex *addr,
1230 struct Curl_peer *tunnel_peer,
1231 uint8_t tunnel_transport)
1232{
1233 struct Curl_cfilter *cf = NULL;
1234 struct cf_h3_proxy_ctx *ctx;
1235 CURLcode result = CURLE_OUT_OF_MEMORY;
1237 if(!tunnel_peer)
1238 return CURLE_FAILED_INIT;
1239 if((transport_peer != TRNSPRT_QUIC) || (!conn->http_proxy.peer))
1240 return CURLE_FAILED_INIT;
1242 ctx = curlx_calloc(1, sizeof(*ctx));
1243 if(!ctx) {
1244 result = CURLE_OUT_OF_MEMORY;
1245 goto out;
1246 }
1247 result = cf_h3_proxy_ctx_init(ctx, origin, peer, &conn->proxy_ssl_config,
1248 tunnel_peer, tunnel_transport);
1249 if(result)
1250 goto out;
1252 result = Curl_cf_create(&cf, &Curl_cft_h3_proxy, ctx);
1253 if(result)
1254 goto out;
1255 cf->conn = conn;
1257 result = Curl_cf_udp_create(&cf->next, data, origin, peer, TRNSPRT_QUIC,
1258 conn, addr, NULL, TRNSPRT_QUIC);
1259 if(result)
1260 goto out;
1261 cf->next->conn = cf->conn;
1262 cf->next->sockindex = cf->sockindex;
1264out:
1265 *pcf = (!result) ? cf : NULL;
1266 if(result) {
1267 if(cf)
1268 Curl_conn_cf_discard_chain(&cf, data);
1269 else if(ctx)
1270 cf_h3_proxy_ctx_free(ctx);
1271 }
1272 else
1273 CURL_TRC_CF(data, cf, "created, udp_tunnel=%d", ctx->tunnel.udp);
1274 return result;
1275}
1277CURLcode Curl_cf_ngtcp2_proxy_insert_after(struct Curl_cfilter *cf_at,
1278 struct Curl_easy *data,
1279 struct Curl_peer *origin,
1280 struct Curl_peer *peer,
1281 struct Curl_peer *tunnel_peer,
1282 uint8_t tunnel_transport)
1283{
1284 struct Curl_cfilter *cf = NULL;
1285 struct cf_h3_proxy_ctx *ctx;
1286 CURLcode result = CURLE_OUT_OF_MEMORY;
1287 (void)data;
1289 ctx = curlx_calloc(1, sizeof(*ctx));
1290 if(!ctx)
1291 goto out;
1292 result = cf_h3_proxy_ctx_init(ctx, origin, peer,
1293 &cf_at->conn->proxy_ssl_config,
1294 tunnel_peer, tunnel_transport);
1295 if(result)
1296 goto out;
1298 result = Curl_cf_create(&cf, &Curl_cft_h3_proxy, ctx);
1299 if(result)
1300 goto out;
1302 /* H3-PROXY uses the UDP socket created by happy eyeballs below it.
1303 Curl_conn_cf_insert_after chains the existing sub-filters, i.e.
1304 "HAPPY-EYEBALLS -> UDP" as cf->next of H3-PROXY. */
1305 Curl_conn_cf_insert_after(cf_at, cf);
1307out:
1308 if(result) {
1309 if(cf)
1310 Curl_conn_cf_discard_chain(&cf, data);
1311 else if(ctx)
1312 cf_h3_proxy_ctx_free(ctx);
1313 }
1314 return result;
1315}
1317#endif
Diagnostics4 git calls · 57 ms
CallStatusSizeTime057 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=52 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch20010 KiB · hit53 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=10715 git.response.cache=HIT git.response.duration_ms=53 git.fetch.wants=043ee3c6a788ad382613251a28e86bf0874a0ccc git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=10715 git.pkt.payload.max=10694 git.sideband.band1.bytes=10693 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e352716f62224d
- Request
- 2ead6752…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format