From 80b9db128393eaf457683421bbef40451bb0fd27 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 4 May 2020 17:57:34 +0100 Subject: 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 .qlog. Co-authored-by: Lucas Pardue Replaces #5337 Closes #5341 --- configure.ac | 1 + lib/dynbuf.h | 2 +- lib/vquic/quiche.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 768f52f4c..aa79cfa42 100755 --- a/configure.ac +++ b/configure.ac @@ -3814,6 +3814,7 @@ if test X"$want_quiche" != Xno; then QUICHE_ENABLED=1 AC_DEFINE(USE_QUICHE, 1, [if quiche is in use]) AC_SUBST(USE_QUICHE, [1]) + AC_CHECK_FUNCS([quiche_conn_set_qlog_fd]) CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$DIR_QUICHE" export CURL_LIBRARY_PATH AC_MSG_NOTICE([Added $DIR_QUICHE to CURL_LIBRARY_PATH]), diff --git a/lib/dynbuf.h b/lib/dynbuf.h index 427269c68..b4932b535 100644 --- a/lib/dynbuf.h +++ b/lib/dynbuf.h @@ -58,5 +58,5 @@ size_t Curl_dyn_len(const struct dynbuf *s); #define DYN_RTSP_REQ_HEADER (64*1024) #define DYN_TRAILERS (64*1024) #define DYN_PROXY_CONNECT_HEADERS 16384 - +#define DYN_QLOG_NAME 1024 #endif 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 +#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; -- cgit v1.2.3