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 "first.h"
26/* Purpose
27 *
28 * 1. Accept a TCP connection on a custom port (IPv4 or IPv6), or connect
29 * to a given (localhost) port.
30 *
31 * 2. Get commands on STDIN. Pass data on to the TCP stream.
32 * Get data from TCP stream and pass on to STDOUT.
33 *
34 * This program is made to perform all the socket/stream/connection stuff for
35 * the test suite's (perl) FTP server. Previously the perl code did all of
36 * this by its own, but I decided to let this program do the socket layer
37 * because of several things:
38 *
39 * o We want the perl code to work with rather old perl installations, thus
40 * we cannot use recent perl modules or features.
41 *
42 * o We want IPv6 support for systems that provide it, and doing optional IPv6
43 * support in perl seems if not impossible so at least awkward.
44 *
45 * o We want FTP-SSL support, which means that a connection that starts with
46 * plain sockets needs to be able to "go SSL" in the midst. This would also
47 * require some nasty perl stuff I would rather avoid.
48 *
49 * (Source originally based on sws.c)
50 */
52/*
53 * Signal handling notes for sockfilt
54 * ----------------------------------
55 *
56 * This program is a single-threaded process.
57 *
58 * This program is intended to be highly portable and as such it must be kept
59 * as simple as possible, due to this the only signal handling mechanisms used
60 * are those of ANSI C, and used only in the most basic form which is good
61 * enough for the purpose of this program.
62 *
63 * For the above reason and the specific needs of this program signals SIGHUP,
64 * SIGPIPE and SIGALRM are ignored on systems where this can be
65 * done. If possible, signals SIGINT and SIGTERM are handled by this
66 * program as an indication to cleanup and finish execution as soon as
67 * possible. This is achieved with a single signal handler
68 * 'exit_signal_handler' for both signals.
69 *
70 * The 'exit_signal_handler' upon the first SIGINT or SIGTERM received signal
71 * sets to one the global var 'got_exit_signal' storing in global var
72 * 'exit_signal' the signal that triggered this change.
73 *
74 * Nothing fancy that could introduce problems is used, the program at certain
75 * points in its normal flow checks if var 'got_exit_signal' is set and in
76 * case this is true it makes its way out of loops and functions in structured
77 * and well behaved manner to achieve proper program cleanup and termination.
78 *
79 * Even with the above mechanism implemented it is worthwhile to note that
80 * other signals might still be received, or that there might be systems on
81 * which it is not possible to trap and ignore some of the above signals.
82 * This implies that for increased portability and reliability the program
83 * must be coded as if no signal was being ignored or handled at all. Enjoy
84 * it!
85 */
87/* buffer is this excessively large only to be able to support things like
88 test 1003 which tests exceedingly large server response lines */
89#define BUFFER_SIZE 17010
91static bool verbose = FALSE;
92static bool s_bind_only = FALSE;
93static uint16_t server_connectport = 0; /* if non-zero,
94 we activate this mode */
96enum sockmode {
97 PASSIVE_LISTEN, /* as a server waiting for connections */
98 PASSIVE_CONNECT, /* as a server, connected to a client */
99 ACTIVE, /* as a client, connected to a server */
100 ACTIVE_DISCONNECT /* as a client, disconnected from server */
101};
103#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP)
104/*
105 * read-wrapper to support reading from stdin on Windows.
106 */
107static ssize_t read_wincon(int fd, void *buf, size_t count)
108{
109 HANDLE handle = NULL;
110 DWORD mode, rcount = 0;
111 BOOL success;
113 if(fd == fileno(stdin)) {
114 handle = GetStdHandle(STD_INPUT_HANDLE);
115 }
116 else {
117 return read(fd, buf, count);
118 }
120 if(GetConsoleMode(handle, &mode)) {
121 success = ReadConsole(handle, buf, curlx_uztoul(count), &rcount, NULL);
122 }
123 else {
124 success = ReadFile(handle, buf, curlx_uztoul(count), &rcount, NULL);
125 }
126 if(success) {
127 return rcount;
128 }
130 errno = (int)GetLastError();
131 return -1;
132}
134/*
135 * write-wrapper to support writing to stdout and stderr on Windows.
136 */
137static ssize_t write_wincon(int fd, const void *buf, size_t count)
138{
139 HANDLE handle = NULL;
140 DWORD mode, wcount = 0;
141 BOOL success;
143 if(fd == fileno(stdout)) {
144 handle = GetStdHandle(STD_OUTPUT_HANDLE);
145 }
146 else if(fd == fileno(stderr)) {
147 handle = GetStdHandle(STD_ERROR_HANDLE);
148 }
149 else {
150 return write(fd, buf, count);
151 }
153 if(GetConsoleMode(handle, &mode)) {
154 success = WriteConsole(handle, buf, curlx_uztoul(count), &wcount, NULL);
155 }
156 else {
157 success = WriteFile(handle, buf, curlx_uztoul(count), &wcount, NULL);
158 }
159 if(success) {
160 return wcount;
161 }
163 errno = (int)GetLastError();
164 return -1;
165}
166#define SOCKFILT_read read_wincon
167#define SOCKFILT_write write_wincon
168#else
169#define SOCKFILT_read read
170#define SOCKFILT_write write
171#endif
173/* On Windows, we sometimes get this for a broken pipe, seemingly
174 * when the client closed stdin? */
175#define CURL_WIN32_EPIPE 109
177/*
178 * fullread is a wrapper around the read() function. This repeats the call
179 * to read() until it actually has read the complete number of bytes indicated
180 * in nbytes or it fails with a condition that cannot be handled with a simple
181 * retry of the read call.
182 */
183static ssize_t fullread(int filedes, void *buffer, size_t nbytes)
184{
185 int error;
186 ssize_t nread = 0;
188 do {
189 ssize_t rc = SOCKFILT_read(filedes,
190 (unsigned char *)buffer + nread,
191 nbytes - nread);
193 if(got_exit_signal) {
194 logmsg("signalled to die");
195 return -1;
196 }
198 if(rc < 0) {
199 char errbuf[STRERROR_LEN];
200 error = errno;
201 /* !checksrc! disable ERRNOVAR 1 */
202 if((error == EINTR) || (error == EAGAIN))
203 continue;
204 if(error == CURL_WIN32_EPIPE) {
205 logmsg("got Windows ERROR_BROKEN_PIPE on fd=%d, treating as close",
206 filedes);
207 return 0;
208 }
209 logmsg("reading from file descriptor: %d,", filedes);
210 logmsg("unrecoverable read() failure (%d) %s",
211 error, curlx_strerror(error, errbuf, sizeof(errbuf)));
212 return -1;
213 }
215 if(rc == 0) {
216 logmsg("got 0 reading from stdin");
217 return 0;
218 }
220 nread += rc;
222 } while((size_t)nread < nbytes);
224 if(verbose)
225 logmsg("read %ld bytes", (long)nread);
227 return nread;
228}
230/*
231 * fullwrite is a wrapper around the write() function. This repeats the
232 * call to write() until it actually has written the complete number of bytes
233 * indicated in nbytes or it fails with a condition that cannot be handled
234 * with a simple retry of the write call.
235 */
236static ssize_t fullwrite(int filedes, const void *buffer, size_t nbytes)
237{
238 int error;
239 ssize_t nwrite = 0;
241 do {
242 ssize_t wc = SOCKFILT_write(filedes,
243 (const unsigned char *)buffer + nwrite,
244 nbytes - nwrite);
246 if(got_exit_signal) {
247 logmsg("signalled to die");
248 return -1;
249 }
251 if(wc < 0) {
252 char errbuf[STRERROR_LEN];
253 error = errno;
254 /* !checksrc! disable ERRNOVAR 1 */
255 if((error == EINTR) || (error == EAGAIN))
256 continue;
257 logmsg("writing to file descriptor: %d,", filedes);
258 logmsg("unrecoverable write() failure (%d) %s",
259 error, curlx_strerror(error, errbuf, sizeof(errbuf)));
260 return -1;
261 }
263 if(wc == 0) {
264 logmsg("put 0 writing to stdout");
265 return 0;
266 }
268 nwrite += wc;
270 } while((size_t)nwrite < nbytes);
272 if(verbose)
273 logmsg("wrote %ld bytes", (long)nwrite);
275 return nwrite;
276}
278/*
279 * read_stdin tries to read from stdin nbytes into the given buffer. This is a
280 * blocking function that only returns TRUE when nbytes have actually been
281 * read or FALSE when an unrecoverable error has been detected. Failure of this
282 * function is an indication that the sockfilt process should terminate.
283 */
284static bool read_stdin(void *buffer, size_t nbytes)
285{
286 ssize_t nread = fullread(fileno(stdin), buffer, nbytes);
287 if(nread != (ssize_t)nbytes) {
288 logmsg("exiting...");
289 return FALSE;
290 }
291 return TRUE;
292}
294/*
295 * write_stdout tries to write to stdio nbytes from the given buffer. This is a
296 * blocking function that only returns TRUE when nbytes have actually been
297 * written or FALSE when an unrecoverable error has been detected. Failure of
298 * this function is an indication that the sockfilt process should terminate.
299 */
300static bool write_stdout(const void *buffer, size_t nbytes)
301{
302 ssize_t nwrite;
303 nwrite = fullwrite(fileno(stdout), buffer, nbytes);
304 if(nwrite != (ssize_t)nbytes) {
305 logmsg("exiting...");
306 return FALSE;
307 }
308 return TRUE;
309}
311static void lograw(const unsigned char *buffer, ssize_t len)
312{
313 char data[120];
314 ssize_t i;
315 const unsigned char *ptr = buffer;
316 char *optr = data;
317 ssize_t width = 0;
318 int left = sizeof(data);
320 for(i = 0; i < len; i++) {
321 switch(ptr[i]) {
322 case '\n':
323 snprintf(optr, left, "\\n");
324 width += 2;
325 optr += 2;
326 left -= 2;
327 break;
328 case '\r':
329 snprintf(optr, left, "\\r");
330 width += 2;
331 optr += 2;
332 left -= 2;
333 break;
334 default:
335 snprintf(optr, left, "%c", (ISGRAPH(ptr[i]) ||
336 ptr[i] == 0x20) ? ptr[i] : '.');
337 width++;
338 optr++;
339 left--;
340 break;
341 }
343 if(width > 60) {
344 logmsg("'%s'", data);
345 width = 0;
346 optr = data;
347 left = sizeof(data);
348 }
349 }
350 if(width)
351 logmsg("'%s'", data);
352}
354/*
355 * handle the DATA command
356 * maxlen is the available space in buffer (input)
357 * *buffer_len is the amount of data in the buffer (output)
358 */
359static bool read_data_block(unsigned char *buffer, ssize_t maxlen,
360 ssize_t *buffer_len)
361{
362 curl_off_t value;
363 const char *endp;
365 if(!read_stdin(buffer, 5))
366 return FALSE;
368 buffer[5] = '\0';
370 endp = (const char *)buffer;
371 if(curlx_str_hex(&endp, &value, 0xfffff)) {
372 logmsg("Failed to decode buffer size");
373 return FALSE;
374 }
375 *buffer_len = (ssize_t)value;
376 if(*buffer_len > maxlen) {
377 logmsg("Buffer size (%ld bytes) too small for data size error "
378 "(%ld bytes)", (long)maxlen, (long)*buffer_len);
379 return FALSE;
380 }
381 logmsg("> %ld bytes data, server => client", (long)*buffer_len);
383 if(!read_stdin(buffer, *buffer_len))
384 return FALSE;
386 lograw(buffer, *buffer_len);
388 return TRUE;
389}
391#if defined(USE_WINSOCK) && !defined(CURL_WINDOWS_UWP)
392/*
393 * Winsock select() does not support standard file descriptors,
394 * it can only check SOCKETs. The following function is an attempt
395 * to re-create a select() function with support for other handle types.
396 *
397 * select() function with support for Winsock2 sockets and all
398 * other handle types supported by WaitForMultipleObjectsEx() as
399 * well as disk files, anonymous and names pipes, and character input.
400 *
401 * https://learn.microsoft.com/windows/win32/api/synchapi/nf-synchapi-waitformultipleobjectsex
402 * https://learn.microsoft.com/windows/win32/api/winsock2/nf-winsock2-wsaenumnetworkevents
403 */
404struct select_ws_wait_data {
405 HANDLE handle; /* actual handle to wait for during select */
406 HANDLE signal; /* internal event to signal handle trigger */
407 HANDLE abort; /* internal event to abort waiting threads */
408};
409static DWORD WINAPI select_ws_wait_thread(void *lpParameter)
410{
411 struct select_ws_wait_data *data;
412 HANDLE signal, handle, handles[2];
413 INPUT_RECORD inputrecord;
414 LARGE_INTEGER size, pos;
415 DWORD type, length, ret;
417 /* retrieve handles from internal structure */
418 data = (struct select_ws_wait_data *)lpParameter;
419 if(data) {
420 handle = data->handle;
421 handles[0] = data->abort;
422 handles[1] = handle;
423 signal = data->signal;
424 free(data);
425 }
426 else
427 return (DWORD)-1;
429 /* retrieve the type of file to wait on */
430 type = GetFileType(handle);
431 switch(type) {
432 case FILE_TYPE_DISK:
433 /* The handle represents a file on disk, this means:
434 * - WaitForMultipleObjectsEx is always signalled for it.
435 * - comparison of current position in file and total size of
436 * the file can be used to check if we reached the end yet.
437 *
438 * Approach: Loop till either the internal event is signalled
439 * or if the end of the file has already been reached.
440 */
441 while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE)
442 == WAIT_TIMEOUT) {
443 /* get total size of file */
444 length = 0;
445 size.QuadPart = 0;
446 size.LowPart = GetFileSize(handle, &length);
447 if((size.LowPart != INVALID_FILE_SIZE) ||
448 (GetLastError() == NO_ERROR)) {
449 size.HighPart = (LONG)length;
450 /* get the current position within the file */
451 pos.QuadPart = 0;
452 pos.LowPart = SetFilePointer(handle, 0, &pos.HighPart, FILE_CURRENT);
453 if((pos.LowPart != INVALID_SET_FILE_POINTER) ||
454 (GetLastError() == NO_ERROR)) {
455 /* compare position with size, abort if not equal */
456 if(size.QuadPart == pos.QuadPart) {
457 /* sleep and continue waiting */
458 SleepEx(0, FALSE);
459 continue;
460 }
461 }
462 }
463 /* there is some data available, stop waiting */
464 logmsg("[select_ws_wait_thread] data available, DISK: %p", handle);
465 SetEvent(signal);
466 }
467 break;
469 case FILE_TYPE_CHAR:
470 /* The handle represents a character input, this means:
471 * - WaitForMultipleObjectsEx is signalled on any kind of input,
472 * including mouse and window size events we do not care about.
473 *
474 * Approach: Loop till either the internal event is signalled
475 * or we get signalled for an actual key-event.
476 */
477 while(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE)
478 == WAIT_OBJECT_0 + 1) {
479 /* check if this is an actual console handle */
480 if(GetConsoleMode(handle, &ret)) {
481 /* retrieve an event from the console buffer */
482 length = 0;
483 if(PeekConsoleInput(handle, &inputrecord, 1, &length)) {
484 /* check if the event is not an actual key-event */
485 if(length == 1 && inputrecord.EventType != KEY_EVENT) {
486 /* purge the non-key-event and continue waiting */
487 ReadConsoleInput(handle, &inputrecord, 1, &length);
488 continue;
489 }
490 }
491 }
492 /* there is some data available, stop waiting */
493 logmsg("[select_ws_wait_thread] data available, CHAR: %p", handle);
494 SetEvent(signal);
495 }
496 break;
498 case FILE_TYPE_PIPE:
499 /* The handle represents an anonymous or named pipe, this means:
500 * - WaitForMultipleObjectsEx is always signalled for it.
501 * - peek into the pipe and retrieve the amount of data available.
502 *
503 * Approach: Loop till either the internal event is signalled
504 * or there is data in the pipe available for reading.
505 */
506 while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE)
507 == WAIT_TIMEOUT) {
508 /* peek into the pipe and retrieve the amount of data available */
509 length = 0;
510 if(PeekNamedPipe(handle, NULL, 0, NULL, &length, NULL)) {
511 /* if there is no data available, sleep and continue waiting */
512 if(length == 0) {
513 SleepEx(0, FALSE);
514 continue;
515 }
516 else {
517 logmsg("[select_ws_wait_thread] PeekNamedPipe len: %lu", length);
518 }
519 }
520 else {
521 /* if the pipe has NOT been closed, sleep and continue waiting */
522 ret = GetLastError();
523 if(ret != ERROR_BROKEN_PIPE) {
524 char buffer[WINAPI_ERROR_LEN];
525 curlx_winapi_strerror(ret, buffer, sizeof(buffer));
526 logmsg("[select_ws_wait_thread] PeekNamedPipe error: (0x%08lx) - %s",
527 ret, buffer);
528 if(ret == ERROR_NOT_SUPPORTED) /* avoid potential endless loop */
529 break;
530 SleepEx(0, FALSE);
531 continue;
532 }
533 else {
534 logmsg("[select_ws_wait_thread] pipe closed, PIPE: %p", handle);
535 }
536 }
537 /* there is some data available, stop waiting */
538 logmsg("[select_ws_wait_thread] data available, PIPE: %p", handle);
539 SetEvent(signal);
540 }
541 break;
543 default:
544 /* The handle has an unknown type, try to wait on it */
545 if(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE)
546 == WAIT_OBJECT_0 + 1) {
547 logmsg("[select_ws_wait_thread] data available, HANDLE: %p", handle);
548 SetEvent(signal);
549 }
550 break;
551 }
553 return 0;
554}
556static HANDLE select_ws_wait(HANDLE handle, HANDLE signal, HANDLE abort)
557{
558 struct select_ws_wait_data *data;
560 /* allocate internal waiting data structure */
561 data = malloc(sizeof(struct select_ws_wait_data));
562 if(data) {
563 HANDLE thread;
565 data->handle = handle;
566 data->signal = signal;
567 data->abort = abort;
569 /* launch waiting thread */
570 thread = CreateThread(NULL, 0, &select_ws_wait_thread, data, 0, NULL);
572 /* free data if thread failed to launch */
573 if(!thread) {
574 free(data);
575 }
576 return thread;
577 }
578 return NULL;
579}
581struct select_ws_data {
582 int fd; /* provided file descriptor (indexed by nfd) */
583 long wsastate; /* internal preselect state (indexed by nfd) */
584 curl_socket_t wsasock; /* internal socket handle (indexed by nws) */
585 WSAEVENT wsaevent; /* internal select event (indexed by nws) */
586 HANDLE signal; /* internal thread signal (indexed by nth) */
587 HANDLE thread; /* internal thread handle (indexed by nth) */
588};
590static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
591 fd_set *exceptfds, struct timeval *tv)
592{
593 DWORD timeout_ms, wait, nfd, nth, nws, i;
594 HANDLE abort, signal, handle, *handles;
595 struct select_ws_data *data;
596 WSANETWORKEVENTS wsaevents;
597 curl_socket_t wsasock;
598 int ret, fd;
600 /* check if the input value is valid */
601 if(nfds < 0) {
602 SET_SOCKERRNO(SOCKEINVAL);
603 return -1;
604 }
606 /* convert struct timeval to milliseconds */
607 if(tv) {
608 timeout_ms = (DWORD)curlx_tvtoms(tv);
609 }
610 else {
611 timeout_ms = INFINITE;
612 }
614 /* check if we got descriptors, sleep in case we got none */
615 if(!nfds) {
616 SleepEx(timeout_ms, FALSE);
617 return 0;
618 }
620 /* create internal event to abort waiting threads */
621 abort = CreateEvent(NULL, TRUE, FALSE, NULL);
622 if(!abort) {
623 SET_SOCKERRNO(SOCKENOMEM);
624 return -1;
625 }
627 /* allocate internal array for the internal data */
628 data = calloc(nfds, sizeof(struct select_ws_data));
629 if(!data) {
630 CloseHandle(abort);
631 SET_SOCKERRNO(SOCKENOMEM);
632 return -1;
633 }
635 /* allocate internal array for the internal event handles */
636 handles = calloc(nfds + 1, sizeof(HANDLE));
637 if(!handles) {
638 CloseHandle(abort);
639 free(data);
640 SET_SOCKERRNO(SOCKENOMEM);
641 return -1;
642 }
644 /* loop over the handles in the input descriptor sets */
645 nfd = 0; /* number of handled file descriptors */
646 nth = 0; /* number of internal waiting threads */
647 nws = 0; /* number of handled Winsock sockets */
648 for(fd = 0; fd < nfds; fd++) {
649 fd_set readsock, writesock, exceptsock;
651 wsasock = (curl_socket_t)fd;
652 wsaevents.lNetworkEvents = 0;
653 handles[nfd] = 0;
655 FD_ZERO(&readsock);
656 FD_ZERO(&writesock);
657 FD_ZERO(&exceptsock);
659 if(FD_ISSET(wsasock, readfds)) {
660 FD_SET(wsasock, &readsock);
661 wsaevents.lNetworkEvents |= FD_READ | FD_ACCEPT | FD_CLOSE;
662 }
664 if(FD_ISSET(wsasock, writefds)) {
665 FD_SET(wsasock, &writesock);
666 wsaevents.lNetworkEvents |= FD_WRITE | FD_CONNECT | FD_CLOSE;
667 }
669 if(FD_ISSET(wsasock, exceptfds)) {
670 FD_SET(wsasock, &exceptsock);
671 wsaevents.lNetworkEvents |= FD_OOB;
672 }
674 /* only wait for events for which we actually care */
675 if(wsaevents.lNetworkEvents) {
676 data[nfd].fd = fd;
677 if(fd == fileno(stdin)) {
678 signal = CreateEvent(NULL, TRUE, FALSE, NULL);
679 if(signal) {
680 handle = GetStdHandle(STD_INPUT_HANDLE);
681 handle = select_ws_wait(handle, signal, abort);
682 if(handle) {
683 handles[nfd] = signal;
684 data[nth].signal = signal;
685 data[nth].thread = handle;
686 nfd++;
687 nth++;
688 }
689 else {
690 CloseHandle(signal);
691 }
692 }
693 }
694 else if(fd == fileno(stdout)) {
695 handles[nfd] = GetStdHandle(STD_OUTPUT_HANDLE);
696 nfd++;
697 }
698 else if(fd == fileno(stderr)) {
699 handles[nfd] = GetStdHandle(STD_ERROR_HANDLE);
700 nfd++;
701 }
702 else {
703 WSAEVENT wsaevent;
704 wsaevent = WSACreateEvent();
705 if(wsaevent != WSA_INVALID_EVENT) {
706 if(wsaevents.lNetworkEvents & FD_WRITE) {
707 swrite(wsasock, NULL, 0); /* reset FD_WRITE */
708 }
709 if(!WSAEventSelect(wsasock, wsaevent, wsaevents.lNetworkEvents)) {
710 handles[nfd] = (HANDLE)wsaevent;
711 data[nws].wsasock = wsasock;
712 data[nws].wsaevent = wsaevent;
713 data[nfd].wsastate = 0;
714 if(tv) {
715 tv->tv_sec = 0;
716 tv->tv_usec = 0;
717 }
718 /* check if the socket is already ready */
719 if(select(fd + 1, &readsock, &writesock, &exceptsock, tv) == 1) {
720 logmsg("[select_ws] socket %d is ready", fd);
721 WSASetEvent(wsaevent);
722 if(FD_ISSET(wsasock, &readsock))
723 data[nfd].wsastate |= FD_READ;
724 if(FD_ISSET(wsasock, &writesock))
725 data[nfd].wsastate |= FD_WRITE;
726 if(FD_ISSET(wsasock, &exceptsock))
727 data[nfd].wsastate |= FD_OOB;
728 }
729 nfd++;
730 nws++;
731 }
732 else {
733 WSACloseEvent(wsaevent);
734 signal = CreateEvent(NULL, TRUE, FALSE, NULL);
735 if(signal) {
736 handle = (HANDLE)wsasock;
737 handle = select_ws_wait(handle, signal, abort);
738 if(handle) {
739 handles[nfd] = signal;
740 data[nth].signal = signal;
741 data[nth].thread = handle;
742 nfd++;
743 nth++;
744 }
745 else {
746 CloseHandle(signal);
747 }
748 }
749 }
750 }
751 }
752 }
753 }
755 /* wait on the number of handles */
756 wait = nfd;
758 /* make sure we stop waiting on exit signal event */
759 if(exit_event) {
760 /* we allocated handles nfds + 1 for this */
761 handles[nfd] = exit_event;
762 wait += 1;
763 }
765 /* wait for one of the internal handles to trigger */
766 wait = WaitForMultipleObjectsEx(wait, handles, FALSE, timeout_ms, FALSE);
768 /* signal the abort event handle and join the other waiting threads */
769 SetEvent(abort);
770 for(i = 0; i < nth; i++) {
771 WaitForSingleObjectEx(data[i].thread, INFINITE, FALSE);
772 CloseHandle(data[i].thread);
773 }
775 /* loop over the internal handles returned in the descriptors */
776 ret = 0; /* number of ready file descriptors */
777 for(i = 0; i < nfd; i++) {
778 fd = data[i].fd;
779 handle = handles[i];
780 wsasock = (curl_socket_t)fd;
782 /* check if the current internal handle was triggered */
783 if(wait != WAIT_FAILED && (wait - WAIT_OBJECT_0) <= i &&
784 WaitForSingleObjectEx(handle, 0, FALSE) == WAIT_OBJECT_0) {
785 /* first handle stdin, stdout and stderr */
786 if(fd == fileno(stdin)) {
787 /* stdin is never ready for write or exceptional */
788 FD_CLR(wsasock, writefds);
789 FD_CLR(wsasock, exceptfds);
790 }
791 else if(fd == fileno(stdout) || fd == fileno(stderr)) {
792 /* stdout and stderr are never ready for read or exceptional */
793 FD_CLR(wsasock, readfds);
794 FD_CLR(wsasock, exceptfds);
795 }
796 else {
797 /* try to handle the event with the Winsock2 functions */
798 wsaevents.lNetworkEvents = 0;
799 if(WSAEnumNetworkEvents(wsasock, handle, &wsaevents) == 0) {
800 /* merge result from pre-check using select */
801 wsaevents.lNetworkEvents |= data[i].wsastate;
803 /* remove from descriptor set if not ready for read/accept/close */
804 if(!(wsaevents.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)))
805 FD_CLR(wsasock, readfds);
807 /* remove from descriptor set if not ready for write/connect */
808 if(!(wsaevents.lNetworkEvents & (FD_WRITE | FD_CONNECT | FD_CLOSE)))
809 FD_CLR(wsasock, writefds);
811 /* remove from descriptor set if not exceptional */
812 if(!(wsaevents.lNetworkEvents & FD_OOB))
813 FD_CLR(wsasock, exceptfds);
814 }
815 }
817 /* check if the event has not been filtered using specific tests */
818 if(FD_ISSET(wsasock, readfds) || FD_ISSET(wsasock, writefds) ||
819 FD_ISSET(wsasock, exceptfds)) {
820 ret++;
821 }
822 }
823 else {
824 /* remove from all descriptor sets since this handle did not trigger */
825 FD_CLR(wsasock, readfds);
826 FD_CLR(wsasock, writefds);
827 FD_CLR(wsasock, exceptfds);
828 }
829 }
831 for(fd = 0; fd < nfds; fd++) {
832 if(FD_ISSET(fd, readfds))
833 logmsg("[select_ws] %d is readable", fd);
834 if(FD_ISSET(fd, writefds))
835 logmsg("[select_ws] %d is writable", fd);
836 if(FD_ISSET(fd, exceptfds))
837 logmsg("[select_ws] %d is exceptional", fd);
838 }
840 for(i = 0; i < nws; i++) {
841 WSAEventSelect(data[i].wsasock, NULL, 0);
842 WSACloseEvent(data[i].wsaevent);
843 }
845 for(i = 0; i < nth; i++) {
846 CloseHandle(data[i].signal);
847 }
848 CloseHandle(abort);
850 free(handles);
851 free(data);
853 return ret;
854}
855#define SOCKFILT_select(a, b, c, d, e) select_ws(a, b, c, d, e)
856#else
857#define SOCKFILT_select(a, b, c, d, e) select(a, b, c, d, e)
858#endif /* USE_WINSOCK */
860/* Perform the disconnect handshake with sockfilt
861 * This involves waiting for the disconnect acknowledgment after the DISC
862 * command, while throwing away anything else that might come in before
863 * that.
864 */
865static bool disc_handshake(void)
866{
867 if(!write_stdout("DISC\n", 5))
868 return FALSE;
870 do {
871 unsigned char buffer[BUFFER_SIZE];
872 ssize_t buffer_len;
873 if(!read_stdin(buffer, 5))
874 return FALSE;
875 logmsg("Received %c%c%c%c (on stdin)",
876 buffer[0], buffer[1], buffer[2], buffer[3]);
878 if(!memcmp("ACKD", buffer, 4)) {
879 /* got the ack we were waiting for */
880 break;
881 }
882 else if(!memcmp("DISC", buffer, 4)) {
883 logmsg("Crikey! Client also wants to disconnect");
884 if(!write_stdout("ACKD\n", 5))
885 return FALSE;
886 }
887 else if(!memcmp("DATA", buffer, 4)) {
888 /* We must read more data to stay in sync */
889 logmsg("Throwing away data bytes");
890 if(!read_data_block(buffer, sizeof(buffer), &buffer_len))
891 return FALSE;
892 }
893 else if(!memcmp("QUIT", buffer, 4)) {
894 /* die */
895 logmsg("quits");
896 return FALSE;
897 }
898 else {
899 logmsg("Unexpected message error; aborting");
900 /*
901 * The only other messages that could occur here are PING and PORT,
902 * and both of them occur at the start of a test when nothing should be
903 * trying to DISC. Therefore, we should not ever get here, but if we
904 * do, it is probably due to some kind of unclean shutdown situation so
905 * us shutting down is what we probably ought to be doing, anyway.
906 */
907 return FALSE;
908 }
909 } while(TRUE);
910 return TRUE;
911}
913/* sockfdp is a pointer to an established stream or CURL_SOCKET_BAD
915 if sockfd is CURL_SOCKET_BAD, listendfd is a listening socket we must
916 accept() */
917static bool juggle(curl_socket_t *sockfdp,
918 curl_socket_t listenfd,
919 enum sockmode *mode)
920{
921 struct timeval timeout;
922 fd_set fds_read;
923 fd_set fds_write;
924 fd_set fds_err;
925 curl_socket_t sockfd = CURL_SOCKET_BAD;
926 int maxfd = -99;
927 ssize_t rc;
928 int sockerr = 0;
929 char errbuf[STRERROR_LEN];
931 unsigned char buffer[BUFFER_SIZE];
932 char data[16];
934 if(got_exit_signal) {
935 logmsg("signalled to die, exiting...");
936 return FALSE;
937 }
939#ifdef HAVE_GETPPID
940 /* As a last resort, quit if sockfilt process becomes orphan. In case
941 parent ftpserver process has died without killing its sockfilt children */
942 if(getppid() <= 1) {
943 logmsg("process becomes orphan, exiting");
944 return FALSE;
945 }
946#endif
948 timeout.tv_sec = 120;
949 timeout.tv_usec = 0;
951 FD_ZERO(&fds_read);
952 FD_ZERO(&fds_write);
953 FD_ZERO(&fds_err);
955 FD_SET((curl_socket_t)fileno(stdin), &fds_read);
957 switch(*mode) {
959 case PASSIVE_LISTEN:
961 /* server mode */
962 sockfd = listenfd;
963 /* there is always a socket to wait for */
964 FD_SET(sockfd, &fds_read);
965 maxfd = (int)sockfd;
966 break;
968 case PASSIVE_CONNECT:
970 sockfd = *sockfdp;
971 if(sockfd == CURL_SOCKET_BAD) {
972 /* eeek, we are supposedly connected and then this cannot be -1 ! */
973 logmsg("socket is -1! on %s:%d", __FILE__, __LINE__);
974 maxfd = 0; /* stdin */
975 }
976 else {
977 /* there is always a socket to wait for */
978 FD_SET(sockfd, &fds_read);
979 maxfd = (int)sockfd;
980 }
981 break;
983 case ACTIVE:
985 sockfd = *sockfdp;
986 /* sockfd turns CURL_SOCKET_BAD when our connection has been closed */
987 if(sockfd != CURL_SOCKET_BAD) {
988 FD_SET(sockfd, &fds_read);
989 maxfd = (int)sockfd;
990 }
991 else {
992 logmsg("No socket to read on");
993 maxfd = 0;
994 }
995 break;
997 case ACTIVE_DISCONNECT:
999 logmsg("disconnected, no socket to read on");
1000 maxfd = 0;
1001 sockfd = CURL_SOCKET_BAD;
1002 break;
1004 } /* switch(*mode) */
1006 do {
1007 /* select() blocking behavior call on blocking descriptors please */
1008 rc = SOCKFILT_select(maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout);
1010 if(got_exit_signal) {
1011 logmsg("signalled to die, exiting...");
1012 return FALSE;
1013 }
1014 } while((rc == -1) && ((sockerr = SOCKERRNO) == SOCKEINTR));
1016 if(rc < 0) {
1017 logmsg("select() failed with error (%d) %s",
1018 sockerr, curlx_strerror(sockerr, errbuf, sizeof(errbuf)));
1019 return FALSE;
1020 }
1022 if(rc == 0)
1023 /* timeout */
1024 return TRUE;
1026 if(FD_ISSET(fileno(stdin), &fds_read)) {
1027 ssize_t buffer_len;
1028 /* read from stdin, commands/data to be dealt with and possibly passed on
1029 to the socket
1031 protocol:
1033 4 letter command + LF [mandatory]
1035 4-digit hexadecimal data length + LF [if the command takes data]
1036 data [the data being as long as set above]
1038 Commands:
1040 DATA - plain pass-through data
1041 */
1043 if(!read_stdin(buffer, 5))
1044 return FALSE;
1046 logmsg("Received %c%c%c%c (on stdin)",
1047 buffer[0], buffer[1], buffer[2], buffer[3]);
1049 if(!memcmp("PING", buffer, 4)) {
1050 /* send reply on stdout, proving we are alive */
1051 if(!write_stdout("PONG\n", 5))
1052 return FALSE;
1053 }
1055 else if(!memcmp("PORT", buffer, 4)) {
1056 /* Question asking us what PORT number we are listening to.
1057 Replies to PORT with "IPv[num]/[port]" */
1058 snprintf((char *)buffer, sizeof(buffer), "%s/%hu\n",
1059 socket_type, server_port);
1060 buffer_len = (ssize_t)strlen((const char *)buffer);
1061 snprintf(data, sizeof(data), "PORT\n%04x\n", (unsigned int)buffer_len);
1062 if(!write_stdout(data, 10))
1063 return FALSE;
1064 if(!write_stdout(buffer, buffer_len))
1065 return FALSE;
1066 }
1067 else if(!memcmp("QUIT", buffer, 4)) {
1068 /* die */
1069 logmsg("quits");
1070 return FALSE;
1071 }
1072 else if(!memcmp("DATA", buffer, 4)) {
1073 /* data IN => data OUT */
1074 if(!read_data_block(buffer, sizeof(buffer), &buffer_len))
1075 return FALSE;
1077 if(buffer_len < 0)
1078 return FALSE;
1080 if(*mode == PASSIVE_LISTEN) {
1081 logmsg("*** We are disconnected!");
1082 if(!disc_handshake())
1083 return FALSE;
1084 }
1085 else {
1086 /* send away on the socket */
1087 ssize_t bytes_written = swrite(sockfd, buffer, buffer_len);
1088 if(bytes_written != buffer_len) {
1089 logmsg("Not all data was sent. Bytes to send: %ld sent: %ld",
1090 (long)buffer_len, (long)bytes_written);
1091 }
1092 }
1093 }
1094 else if(!memcmp("DISC", buffer, 4)) {
1095 /* disconnect! */
1096 if(!write_stdout("ACKD\n", 5))
1097 return FALSE;
1098 if(sockfd != CURL_SOCKET_BAD) {
1099 logmsg("====> Client forcibly disconnected");
1100 sclose(sockfd);
1101 *sockfdp = CURL_SOCKET_BAD;
1102 if(*mode == PASSIVE_CONNECT)
1103 *mode = PASSIVE_LISTEN;
1104 else
1105 *mode = ACTIVE_DISCONNECT;
1106 }
1107 else
1108 logmsg("attempt to close already dead connection");
1109 return TRUE;
1110 }
1111 }
1113 if((sockfd != CURL_SOCKET_BAD) && (FD_ISSET(sockfd, &fds_read))) {
1114 ssize_t nread_socket;
1115 if(*mode == PASSIVE_LISTEN) {
1116 /* there is no stream set up yet, this is an indication that there is a
1117 client connecting. */
1118 curl_socket_t newfd = accept(sockfd, NULL, NULL);
1119 if(newfd == CURL_SOCKET_BAD) {
1120 sockerr = SOCKERRNO;
1121 logmsg("accept() failed with error (%d) %s",
1122 sockerr, curlx_strerror(sockerr, errbuf, sizeof(errbuf)));
1123 }
1124 else {
1125 logmsg("====> Client connect");
1126 if(!write_stdout("CNCT\n", 5))
1127 return FALSE;
1128 *sockfdp = newfd; /* store the new socket */
1129 *mode = PASSIVE_CONNECT; /* we have connected */
1130 }
1131 return TRUE;
1132 }
1134 /* read from socket, pass on data to stdout */
1135 nread_socket = sread(sockfd, buffer, sizeof(buffer));
1137 if(nread_socket > 0) {
1138 snprintf(data, sizeof(data), "DATA\n%04x\n", (unsigned int)nread_socket);
1139 if(!write_stdout(data, 10))
1140 return FALSE;
1141 if(!write_stdout(buffer, nread_socket))
1142 return FALSE;
1144 logmsg("< %ld bytes data, client => server", (long)nread_socket);
1145 lograw(buffer, nread_socket);
1146 }
1148 if(nread_socket <= 0) {
1149 logmsg("====> Client disconnect");
1150 if(!disc_handshake())
1151 return FALSE;
1152 sclose(sockfd);
1153 *sockfdp = CURL_SOCKET_BAD;
1154 if(*mode == PASSIVE_CONNECT)
1155 *mode = PASSIVE_LISTEN;
1156 else
1157 *mode = ACTIVE_DISCONNECT;
1158 return TRUE;
1159 }
1160 }
1162 return TRUE;
1163}
1165static int test_sockfilt(int argc, const char *argv[])
1166{
1167 srvr_sockaddr_union_t me;
1168 curl_socket_t sock = CURL_SOCKET_BAD;
1169 curl_socket_t msgsock = CURL_SOCKET_BAD;
1170 int wrotepidfile = 0;
1171 int wroteportfile = 0;
1172 bool juggle_again;
1173 int rc;
1174 int sockerr;
1175 char errbuf[STRERROR_LEN];
1176 int arg = 1;
1177 enum sockmode mode = PASSIVE_LISTEN; /* default */
1178 const char *addr = NULL;
1180 pidname = ".sockfilt.pid";
1181 serverlogfile = "log/sockfilt.log";
1182 server_port = 8999;
1184 while(argc > arg) {
1185 const char *opt;
1186 curl_off_t num;
1187 if(!strcmp("--version", argv[arg])) {
1188 printf("sockfilt IPv4%s\n",
1189#ifdef USE_IPV6
1190 "/IPv6"
1191#else
1192 ""
1193#endif
1194 );
1195 return 0;
1196 }
1197 else if(!strcmp("--verbose", argv[arg])) {
1198 verbose = TRUE;
1199 arg++;
1200 }
1201 else if(!strcmp("--pidfile", argv[arg])) {
1202 arg++;
1203 if(argc > arg)
1204 pidname = argv[arg++];
1205 }
1206 else if(!strcmp("--portfile", argv[arg])) {
1207 arg++;
1208 if(argc > arg)
1209 portname = argv[arg++];
1210 }
1211 else if(!strcmp("--logfile", argv[arg])) {
1212 arg++;
1213 if(argc > arg)
1214 serverlogfile = argv[arg++];
1215 }
1216 else if(!strcmp("--ipv6", argv[arg])) {
1217#ifdef USE_IPV6
1218 socket_type = "IPv6";
1219 socket_domain = AF_INET6;
1220#endif
1221 arg++;
1222 }
1223 else if(!strcmp("--ipv4", argv[arg])) {
1224 socket_type = "IPv4";
1225 socket_domain = AF_INET;
1226 arg++;
1227 }
1228 else if(!strcmp("--bindonly", argv[arg])) {
1229 s_bind_only = TRUE;
1230 arg++;
1231 }
1232 else if(!strcmp("--port", argv[arg])) {
1233 arg++;
1234 if(argc > arg) {
1235 opt = argv[arg];
1236 if(!curlx_str_number(&opt, &num, 0xffff))
1237 server_port = (uint16_t)num;
1238 arg++;
1239 }
1240 }
1241 else if(!strcmp("--connect", argv[arg])) {
1242 /* Asked to actively connect to the specified local port instead of
1243 doing a passive server-style listening. */
1244 arg++;
1245 if(argc > arg) {
1246 opt = argv[arg];
1247 if(curlx_str_number(&opt, &num, 0xffff)) {
1248 fprintf(stderr, "sockfilt: invalid --connect argument (%s)\n",
1249 argv[arg]);
1250 return 0;
1251 }
1252 server_connectport = (uint16_t)num;
1253 arg++;
1254 }
1255 }
1256 else if(!strcmp("--addr", argv[arg])) {
1257 /* Set an IP address to use with --connect; otherwise use localhost */
1258 arg++;
1259 if(argc > arg) {
1260 addr = argv[arg];
1261 arg++;
1262 }
1263 }
1264 else {
1265 puts("Usage: sockfilt [option]\n"
1266 " --version\n"
1267 " --verbose\n"
1268 " --logfile [file]\n"
1269 " --pidfile [file]\n"
1270 " --portfile [file]\n"
1271 " --ipv4\n"
1272 " --ipv6\n"
1273 " --bindonly\n"
1274 " --port [port]\n"
1275 " --connect [port]\n"
1276 " --addr [address]");
1277 return 0;
1278 }
1279 }
1281 CURL_BINMODE(stdin);
1282 CURL_BINMODE(stdout);
1283 CURL_BINMODE(stderr);
1285 install_signal_handlers(FALSE);
1287 sock = socket(socket_domain, SOCK_STREAM, 0);
1289 if(sock == CURL_SOCKET_BAD) {
1290 sockerr = SOCKERRNO;
1291 logmsg("Error creating socket (%d) %s",
1292 sockerr, curlx_strerror(sockerr, errbuf, sizeof(errbuf)));
1293 write_stdout("FAIL\n", 5);
1294 goto sockfilt_cleanup;
1295 }
1297 if(server_connectport) {
1298 /* Active mode, we should connect to the given port number */
1299 mode = ACTIVE;
1300 switch(socket_domain) {
1301 case AF_INET:
1302 memset(&me.sa4, 0, sizeof(me.sa4));
1303 me.sa4.sin_family = AF_INET;
1304 me.sa4.sin_port = htons(server_connectport);
1305 me.sa4.sin_addr.s_addr = INADDR_ANY;
1306 if(!addr)
1307 addr = "127.0.0.1";
1308 curlx_inet_pton(AF_INET, addr, &me.sa4.sin_addr);
1310 rc = connect(sock, &me.sa, sizeof(me.sa4));
1311 break;
1312#ifdef USE_IPV6
1313 case AF_INET6:
1314 memset(&me.sa6, 0, sizeof(me.sa6));
1315 me.sa6.sin6_family = AF_INET6;
1316 me.sa6.sin6_port = htons(server_connectport);
1317 if(!addr)
1318 addr = "::1";
1319 curlx_inet_pton(AF_INET6, addr, &me.sa6.sin6_addr);
1321 rc = connect(sock, &me.sa, sizeof(me.sa6));
1322 break;
1323#endif /* USE_IPV6 */
1324 default:
1325 rc = 1;
1326 }
1327 if(rc) {
1328 sockerr = SOCKERRNO;
1329 logmsg("Error connecting to port %hu (%d) %s", server_connectport,
1330 sockerr, curlx_strerror(sockerr, errbuf, sizeof(errbuf)));
1331 write_stdout("FAIL\n", 5);
1332 goto sockfilt_cleanup;
1333 }
1334 logmsg("====> Client connect");
1335 msgsock = sock; /* use this as stream */
1336 }
1337 else {
1338 /* passive daemon style */
1339 sock = sockdaemon(sock, &server_port, NULL, s_bind_only);
1340 if(sock == CURL_SOCKET_BAD) {
1341 write_stdout("FAIL\n", 5);
1342 goto sockfilt_cleanup;
1343 }
1344 msgsock = CURL_SOCKET_BAD; /* no stream socket yet */
1345 }
1347 logmsg("Running %s version", socket_type);
1349 if(server_connectport)
1350 logmsg("Connected to port %hu", server_connectport);
1351 else if(s_bind_only)
1352 logmsg("Bound without listening on port %hu", server_port);
1353 else
1354 logmsg("Listening on port %hu", server_port);
1356 wrotepidfile = write_pidfile(pidname);
1357 if(!wrotepidfile) {
1358 write_stdout("FAIL\n", 5);
1359 goto sockfilt_cleanup;
1360 }
1361 if(portname) {
1362 wroteportfile = write_portfile(portname, server_port);
1363 if(!wroteportfile) {
1364 write_stdout("FAIL\n", 5);
1365 goto sockfilt_cleanup;
1366 }
1367 }
1369 do {
1370 juggle_again = juggle(&msgsock, sock, &mode);
1371 } while(juggle_again);
1373sockfilt_cleanup:
1375 if((msgsock != sock) && (msgsock != CURL_SOCKET_BAD))
1376 sclose(msgsock);
1378 if(sock != CURL_SOCKET_BAD)
1379 sclose(sock);
1381 if(wrotepidfile)
1382 unlink(pidname);
1383 if(wroteportfile)
1384 unlink(portname);
1386 restore_signal_handlers(FALSE);
1388 return 0;
1389}
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 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 · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 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 · hit6 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=19 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=6 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
fetch20012 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=12472 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=e2d7947f07eedc91a031415edbd02f0732fe96b0 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=12472 git.pkt.payload.max=12451 git.sideband.band1.bytes=12450 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
- a5e2e46e5fb82947
- Request
- 0764d2f1…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format