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 ***************************************************************************/
25#include "unitcheck.h"
27#include "bufq.h"
28#include "vquic/capsule.h"
30#if defined(USE_PROXY_HTTP3) && defined(USE_NGTCP2) && \
31 !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
32static void queue_bytes(struct bufq *q, const unsigned char *src, size_t len)
33{
34 size_t nwritten = 0;
35 CURLcode result = Curl_bufq_write(q, src, len, &nwritten);
36 fail_unless(result == CURLE_OK, "queue failed");
37 fail_unless(nwritten == len, "queue short write");
38}
39#endif
41#if defined(USE_PROXY_HTTP3) && \
42 !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
43static void check_capsule_hdr(size_t payload_len,
44 const unsigned char *expected,
45 size_t expected_len)
46{
47 unsigned char hdr[HTTP_CAPSULE_HEADER_MAX_SIZE];
48 size_t hdr_len;
50 memset(hdr, 0xA5, sizeof(hdr));
51 hdr_len = capsule_encap_udp_hdr(hdr, sizeof(hdr), payload_len);
52 fail_unless(hdr_len == expected_len, "capsule header length mismatch");
53 fail_unless(!memcmp(hdr, expected, expected_len),
54 "capsule header bytes mismatch");
55}
57static void test_capsule_encap_udp_hdr_boundaries(void)
58{
59 static const unsigned char p0[] = { 0x00, 0x01, 0x00 };
60 static const unsigned char p62[] = { 0x00, 0x3F, 0x00 };
61 static const unsigned char p63[] = { 0x00, 0x40, 0x40, 0x00 };
62 static const unsigned char p64[] = { 0x00, 0x40, 0x41, 0x00 };
63 static const unsigned char p16382[] = { 0x00, 0x7F, 0xFF, 0x00 };
64 static const unsigned char p16383[] = { 0x00, 0x80, 0x00, 0x40, 0x00, 0x00 };
65 static const unsigned char p16384[] = { 0x00, 0x80, 0x00, 0x40, 0x01, 0x00 };
67 check_capsule_hdr(0, p0, sizeof(p0));
68 check_capsule_hdr(62, p62, sizeof(p62));
69 check_capsule_hdr(63, p63, sizeof(p63));
70 check_capsule_hdr(64, p64, sizeof(p64));
71 check_capsule_hdr(16382, p16382, sizeof(p16382));
72 check_capsule_hdr(16383, p16383, sizeof(p16383));
73 check_capsule_hdr(16384, p16384, sizeof(p16384));
74}
76#endif /* !CURL_DISABLE_PROXY && !CURL_DISABLE_HTTP */
78#if defined(USE_PROXY_HTTP3) && defined(USE_NGTCP2) && \
79 !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
80static void check_capsule_result(struct bufq *q,
81 const unsigned char *capsule, size_t capslen,
82 size_t outlen, CURLcode expect_err,
83 size_t expect_nread)
84{
85 unsigned char out[32];
86 CURLcode err = CURLE_OK;
87 size_t nread;
89 memset(out, 0, sizeof(out));
90 Curl_bufq_reset(q);
91 if(capsule && capslen)
92 queue_bytes(q, capsule, capslen);
94 nread = Curl_capsule_process_udp_raw(NULL, NULL, q, out, outlen, &err);
95 fail_unless(err == expect_err, "unexpected capsule error");
96 fail_unless(nread == expect_nread, "unexpected capsule read size");
97}
99static void test_capsule_encode_decode_roundtrip(void)
100{
101 struct bufq q;
102 unsigned char payload[128];
103 unsigned char out[128];
104 CURLcode result, err;
105 size_t payload_len;
106 size_t i, nread;
108 Curl_bufq_init2(&q, 32, 8, BUFQ_OPT_NONE);
110 for(i = 0; i < sizeof(payload); ++i)
111 payload[i] = (unsigned char)i;
113 for(i = 0; i < 2; ++i) {
114 payload_len = i ? 64 : 7;
115 memset(out, 0, sizeof(out));
116 Curl_bufq_reset(&q);
118 result = Curl_capsule_encap_udp_datagram(&q, payload, payload_len);
119 fail_unless(result == CURLE_OK, "failed to encapsulate UDP datagram");
121 err = CURLE_OK;
122 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, sizeof(out),
123 &err);
124 fail_unless(err == CURLE_OK, "failed to decode UDP datagram");
125 fail_unless(nread == payload_len, "decoded payload length mismatch");
126 fail_unless(!memcmp(out, payload, payload_len),
127 "decoded payload bytes mismatch");
128 fail_unless(Curl_bufq_is_empty(&q), "decoded capsule must be consumed");
129 }
130 Curl_bufq_free(&q);
131}
133static void test_capsule_sequential_decode(void)
134{
135 /* Verify that multiple back-to-back capsules in the same bufq are
136 each decoded in turn and the buffer is fully consumed. */
137 struct bufq q;
138 unsigned char out[8];
139 CURLcode err;
140 size_t nread;
141 /* Two back-to-back 3-byte UDP capsules */
142 static const unsigned char two_caps[] = {
143 0x00, 0x04, 0x00, 0x11, 0x22, 0x33, /* capsule 1: [0x11,0x22,0x33] */
144 0x00, 0x04, 0x00, 0xAA, 0xBB, 0xCC /* capsule 2: [0xAA,0xBB,0xCC] */
145 };
147 Curl_bufq_init2(&q, 32, 4, BUFQ_OPT_NONE);
149 queue_bytes(&q, two_caps, sizeof(two_caps));
151 /* First capsule */
152 memset(out, 0, sizeof(out));
153 err = CURLE_OK;
154 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, sizeof(out), &err);
155 fail_unless(err == CURLE_OK, "sequential: first capsule decode failed");
156 fail_unless(nread == 3, "sequential: first capsule size mismatch");
157 fail_unless(out[0] == 0x11 && out[1] == 0x22 && out[2] == 0x33,
158 "sequential: first capsule bytes mismatch");
160 /* Second capsule */
161 memset(out, 0, sizeof(out));
162 err = CURLE_OK;
163 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, sizeof(out), &err);
164 fail_unless(err == CURLE_OK, "sequential: second capsule decode failed");
165 fail_unless(nread == 3, "sequential: second capsule size mismatch");
166 fail_unless(out[0] == 0xAA && out[1] == 0xBB && out[2] == 0xCC,
167 "sequential: second capsule bytes mismatch");
169 /* Buffer must be empty after both capsules */
170 fail_unless(Curl_bufq_is_empty(&q),
171 "sequential: buffer must be empty after two capsules");
173 /* No more data - CURLE_AGAIN expected */
174 err = CURLE_OK;
175 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, sizeof(out), &err);
176 fail_unless(err == CURLE_AGAIN,
177 "sequential: empty queue should return AGAIN");
178 fail_unless(nread == 0, "sequential: empty queue should read zero bytes");
180 Curl_bufq_free(&q);
181}
183static void test_capsule_decode_paths(void)
184{
185 struct bufq q;
186 unsigned char out[8];
187 CURLcode err = CURLE_OK;
188 size_t nread;
189 static const unsigned char invalid_type[] = { 0x01 };
190 static const unsigned char partial_len[] = { 0x00, 0x40 };
191 static const unsigned char invalid_context[] = { 0x00, 0x01, 0x01 };
192 static const unsigned char invalid_caps_len[] = { 0x00, 0x00, 0x00 };
193 static const unsigned char partial_payload[] = { 0x00, 0x04, 0x00, 0x11,
194 0x22 };
195 static const unsigned char payload_3b[] = { 0x00, 0x04, 0x00,
196 0x11, 0x22, 0x33 };
197 static const unsigned char payload_empty[] = { 0x00, 0x01, 0x00 };
199 Curl_bufq_init2(&q, 32, 4, BUFQ_OPT_NONE);
201 check_capsule_result(&q, NULL, 0, 0, CURLE_BAD_FUNCTION_ARGUMENT, 0);
202 check_capsule_result(&q, NULL, 0, sizeof(out), CURLE_AGAIN, 0);
203 check_capsule_result(&q, invalid_type, sizeof(invalid_type), sizeof(out),
204 CURLE_RECV_ERROR, 0);
205 check_capsule_result(&q, partial_len, sizeof(partial_len), sizeof(out),
206 CURLE_AGAIN, 0);
207 check_capsule_result(&q, invalid_context, sizeof(invalid_context),
208 sizeof(out), CURLE_RECV_ERROR, 0);
209 check_capsule_result(&q, invalid_caps_len, sizeof(invalid_caps_len),
210 sizeof(out), CURLE_RECV_ERROR, 0);
211 check_capsule_result(&q, partial_payload, sizeof(partial_payload),
212 sizeof(out), CURLE_AGAIN, 0);
214 /* oversized payload is rejected and discarded */
215 Curl_bufq_reset(&q);
216 queue_bytes(&q, payload_3b, sizeof(payload_3b));
217 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, 2, &err);
218 fail_unless(err == CURLE_RECV_ERROR,
219 "expected RECV_ERROR for short output buffer");
220 fail_unless(nread == 0, "expected zero read on short output buffer");
221 fail_unless(Curl_bufq_is_empty(&q), "oversized capsule must be discarded");
223 /* zero-length UDP payload is accepted and consumed */
224 Curl_bufq_reset(&q);
225 queue_bytes(&q, payload_empty, sizeof(payload_empty));
226 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, sizeof(out), &err);
227 fail_unless(err == CURLE_OK, "zero-length UDP payload should succeed");
228 fail_unless(nread == 0, "zero-length UDP payload should read zero");
229 fail_unless(Curl_bufq_is_empty(&q), "zero-length capsule must be consumed");
231 /* normal payload decode */
232 Curl_bufq_reset(&q);
233 queue_bytes(&q, payload_3b, sizeof(payload_3b));
234 memset(out, 0, sizeof(out));
235 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, sizeof(out), &err);
236 fail_unless(err == CURLE_OK, "payload decode should succeed");
237 fail_unless(nread == 3, "payload decode size mismatch");
238 fail_unless(out[0] == 0x11 && out[1] == 0x22 && out[2] == 0x33,
239 "payload decode bytes mismatch");
240 fail_unless(Curl_bufq_is_empty(&q), "payload capsule must be consumed");
242 Curl_bufq_free(&q);
243}
245static void test_capsule_full_buffer_reject(void)
246{
247 /* A capsule whose payload can never fit the bounded bufq must fail
248 instead of asking for more data forever. */
249 struct bufq q;
250 unsigned char out[256];
251 unsigned char cap[128];
252 CURLcode err = CURLE_OK;
253 size_t nread;
254 /* type 0x00, length 201 as a 2-byte varint, context 0x00 */
255 static const unsigned char hdr[] = { 0x00, 0x40, 0xC9, 0x00 };
257 Curl_bufq_init2(&q, 32, 4, BUFQ_OPT_NONE);
259 memset(cap, 0x5A, sizeof(cap));
260 memcpy(cap, hdr, sizeof(hdr));
262 /* the queue can still grow, so wait for the rest */
263 queue_bytes(&q, cap, 64);
264 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, sizeof(out), &err);
265 fail_unless(err == CURLE_AGAIN, "partial capsule should return AGAIN");
266 fail_unless(nread == 0, "partial capsule should read zero bytes");
268 /* the queue is full and the capsule is still short, it never completes */
269 queue_bytes(&q, cap + 64, sizeof(cap) - 64);
270 fail_unless(Curl_bufq_is_full(&q), "queue should be full");
271 nread = Curl_capsule_process_udp_raw(NULL, NULL, &q, out, sizeof(out), &err);
272 fail_unless(err == CURLE_RECV_ERROR,
273 "unbufferable capsule should return RECV_ERROR");
274 fail_unless(nread == 0, "unbufferable capsule should read zero bytes");
276 Curl_bufq_free(&q);
277}
279#endif /* USE_NGTCP2 && !CURL_DISABLE_PROXY && !CURL_DISABLE_HTTP */
281static CURLcode test_unit3400(const char *arg)
282{
283 UNITTEST_BEGIN_SIMPLE
285#if defined(USE_PROXY_HTTP3) && \
286 !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
287 test_capsule_encap_udp_hdr_boundaries();
288#endif
290#if defined(USE_PROXY_HTTP3) && defined(USE_NGTCP2) && \
291 !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
292 test_capsule_encode_decode_roundtrip();
293 test_capsule_decode_paths();
294 test_capsule_sequential_decode();
295 test_capsule_full_buffer_reject();
296#endif
298 UNITTEST_END_SIMPLE
299}
Diagnostics4 git calls · 215 ms
CallStatusSizeTime0215 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs 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 · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 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
fetch2003.0 KiB210 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=210 git.response.bytes=3095 git.response.cache=MISS git.response.duration_ms=210 git.fetch.wants=539f16f84d87871eb4c127572d7e7390f7c758b5 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=3095 git.pkt.payload.max=3074 git.sideband.band1.bytes=3073 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
- a5e2f89f597690c0
- Request
- cf2544af…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format