aboutsummaryrefslogtreecommitdiff
path: root/lib/vquic
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-05-04 17:57:34 +0100
committerDaniel Stenberg <daniel@haxx.se>2020-05-05 14:50:33 +0200
commit80b9db128393eaf457683421bbef40451bb0fd27 (patch)
tree2fd148ba948e1c2e4cd062963f44dda5873e4987 /lib/vquic
parente0af243b6165adc590c78c0b024805fb060b4f56 (diff)
quiche: enable qlog output
quiche has the potential to log qlog files. To enable this, you must build quiche with the qlog feature enabled `cargo build --features qlog`. curl then passes a file descriptor to quiche, which takes ownership of the file. The FD transfer only works on UNIX. The convention is to enable logging when the QLOGDIR environment is set. This should be a path to a folder where files are written with the naming template <SCID>.qlog. Co-authored-by: Lucas Pardue Replaces #5337 Closes #5341
Diffstat (limited to 'lib/vquic')
-rw-r--r--lib/vquic/quiche.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/lib/vquic/quiche.c b/lib/vquic/quiche.c
index c40e5e937..38c0a0a3f 100644
--- a/lib/vquic/quiche.c
+++ b/lib/vquic/quiche.c
@@ -34,6 +34,10 @@
#include "multiif.h"
#include "connect.h"
#include "strerror.h"
+#include "dynbuf.h"
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -64,7 +68,6 @@ static CURLcode http_request(struct connectdata *conn, const void *mem,
static Curl_recv h3_stream_recv;
static Curl_send h3_stream_send;
-
static int quiche_getsock(struct connectdata *conn, curl_socket_t *socks)
{
struct SingleRequest *k = &conn->data->req;
@@ -199,6 +202,44 @@ CURLcode Curl_quic_connect(struct connectdata *conn, curl_socket_t sockfd,
return CURLE_OUT_OF_MEMORY;
}
+ /* Known to not work on Windows */
+#if !defined(WIN32) && defined(HAVE_QUICHE_CONN_SET_QLOG_FD)
+#ifdef O_BINARY
+#define QLOGMODE O_WRONLY|O_CREAT|O_BINARY
+#else
+#define QLOGMODE O_WRONLY|O_CREAT
+#endif
+ {
+ const char *qlog_dir = getenv("QLOGDIR");
+ if(qlog_dir) {
+ struct dynbuf fname;
+ unsigned int i;
+ Curl_dyn_init(&fname, DYN_QLOG_NAME);
+ result = Curl_dyn_add(&fname, qlog_dir);
+ if(!result)
+ result = Curl_dyn_add(&fname, "/");
+ for(i = 0; (i < sizeof(qs->scid)) && !result; i++) {
+ char hex[3];
+ msnprintf(hex, 3, "%02x", qs->scid[i]);
+ result = Curl_dyn_add(&fname, hex);
+ }
+ if(!result)
+ result = Curl_dyn_add(&fname, ".qlog");
+
+ if(!result) {
+ int qlogfd = open(Curl_dyn_ptr(&fname), QLOGMODE,
+ data->set.new_file_perms);
+ if(qlogfd != -1)
+ quiche_conn_set_qlog_fd(qs->conn, qlogfd,
+ "qlog title", "curl qlog");
+ }
+ Curl_dyn_free(&fname);
+ if(result)
+ return result;
+ }
+ }
+#endif
+
result = flush_egress(conn, sockfd, qs);
if(result)
return result;