]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
quiche: enable qlog output
authorDaniel Stenberg <daniel@haxx.se>
Mon, 4 May 2020 16:57:34 +0000 (17:57 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 5 May 2020 12:50:33 +0000 (14:50 +0200)
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

configure.ac
lib/dynbuf.h
lib/vquic/quiche.c

index 768f52f4c513b0e88e25a15708cc92170951972c..aa79cfa423ee59ba51851e34a305e13207862050 100755 (executable)
@@ -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]),
index 427269c68decf2d2b4fbe630f1708ea7db44587f..b4932b5351c877f636110a5f158da9304f0ee5af 100644 (file)
@@ -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
index c40e5e937ca6cdb88e1e543362e2fcdc0b2a3af5..38c0a0a3f4cae63410d08edcea6c94e112234005 100644 (file)
 #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;