vquic.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. /* WIP, experimental: use recvmmsg() on linux
  25. * we have no configure check, yet
  26. * and also it is only available for _GNU_SOURCE, which
  27. * we do not use otherwise.
  28. #define HAVE_SENDMMSG
  29. */
  30. #if defined(HAVE_SENDMMSG)
  31. #define _GNU_SOURCE
  32. #include <sys/socket.h>
  33. #undef _GNU_SOURCE
  34. #endif
  35. #include "curl_setup.h"
  36. #ifdef HAVE_FCNTL_H
  37. #include <fcntl.h>
  38. #endif
  39. #include "urldata.h"
  40. #include "bufq.h"
  41. #include "dynbuf.h"
  42. #include "cfilters.h"
  43. #include "curl_trc.h"
  44. #include "curl_msh3.h"
  45. #include "curl_ngtcp2.h"
  46. #include "curl_quiche.h"
  47. #include "rand.h"
  48. #include "vquic.h"
  49. #include "vquic_int.h"
  50. #include "strerror.h"
  51. /* The last 3 #include files should be in this order */
  52. #include "curl_printf.h"
  53. #include "curl_memory.h"
  54. #include "memdebug.h"
  55. #ifdef ENABLE_QUIC
  56. #ifdef O_BINARY
  57. #define QLOGMODE O_WRONLY|O_CREAT|O_BINARY
  58. #else
  59. #define QLOGMODE O_WRONLY|O_CREAT
  60. #endif
  61. #define NW_CHUNK_SIZE (64 * 1024)
  62. #define NW_SEND_CHUNKS 2
  63. void Curl_quic_ver(char *p, size_t len)
  64. {
  65. #if defined(USE_NGTCP2) && defined(USE_NGHTTP3)
  66. Curl_ngtcp2_ver(p, len);
  67. #elif defined(USE_QUICHE)
  68. Curl_quiche_ver(p, len);
  69. #elif defined(USE_MSH3)
  70. Curl_msh3_ver(p, len);
  71. #endif
  72. }
  73. CURLcode vquic_ctx_init(struct cf_quic_ctx *qctx)
  74. {
  75. Curl_bufq_init2(&qctx->sendbuf, NW_CHUNK_SIZE, NW_SEND_CHUNKS,
  76. BUFQ_OPT_SOFT_LIMIT);
  77. #if defined(__linux__) && defined(UDP_SEGMENT) && defined(HAVE_SENDMSG)
  78. qctx->no_gso = FALSE;
  79. #else
  80. qctx->no_gso = TRUE;
  81. #endif
  82. #ifdef DEBUGBUILD
  83. {
  84. char *p = getenv("CURL_DBG_QUIC_WBLOCK");
  85. if(p) {
  86. long l = strtol(p, NULL, 10);
  87. if(l >= 0 && l <= 100)
  88. qctx->wblock_percent = (int)l;
  89. }
  90. }
  91. #endif
  92. return CURLE_OK;
  93. }
  94. void vquic_ctx_free(struct cf_quic_ctx *qctx)
  95. {
  96. Curl_bufq_free(&qctx->sendbuf);
  97. }
  98. static CURLcode send_packet_no_gso(struct Curl_cfilter *cf,
  99. struct Curl_easy *data,
  100. struct cf_quic_ctx *qctx,
  101. const uint8_t *pkt, size_t pktlen,
  102. size_t gsolen, size_t *psent);
  103. static CURLcode do_sendmsg(struct Curl_cfilter *cf,
  104. struct Curl_easy *data,
  105. struct cf_quic_ctx *qctx,
  106. const uint8_t *pkt, size_t pktlen, size_t gsolen,
  107. size_t *psent)
  108. {
  109. #ifdef HAVE_SENDMSG
  110. struct iovec msg_iov;
  111. struct msghdr msg = {0};
  112. ssize_t sent;
  113. #if defined(__linux__) && defined(UDP_SEGMENT)
  114. uint8_t msg_ctrl[32];
  115. struct cmsghdr *cm;
  116. #endif
  117. *psent = 0;
  118. msg_iov.iov_base = (uint8_t *)pkt;
  119. msg_iov.iov_len = pktlen;
  120. msg.msg_iov = &msg_iov;
  121. msg.msg_iovlen = 1;
  122. #if defined(__linux__) && defined(UDP_SEGMENT)
  123. if(pktlen > gsolen) {
  124. /* Only set this, when we need it. macOS, for example,
  125. * does not seem to like a msg_control of length 0. */
  126. msg.msg_control = msg_ctrl;
  127. assert(sizeof(msg_ctrl) >= CMSG_SPACE(sizeof(uint16_t)));
  128. msg.msg_controllen = CMSG_SPACE(sizeof(uint16_t));
  129. cm = CMSG_FIRSTHDR(&msg);
  130. cm->cmsg_level = SOL_UDP;
  131. cm->cmsg_type = UDP_SEGMENT;
  132. cm->cmsg_len = CMSG_LEN(sizeof(uint16_t));
  133. *(uint16_t *)(void *)CMSG_DATA(cm) = gsolen & 0xffff;
  134. }
  135. #endif
  136. while((sent = sendmsg(qctx->sockfd, &msg, 0)) == -1 && SOCKERRNO == EINTR)
  137. ;
  138. if(sent == -1) {
  139. switch(SOCKERRNO) {
  140. case EAGAIN:
  141. #if EAGAIN != EWOULDBLOCK
  142. case EWOULDBLOCK:
  143. #endif
  144. return CURLE_AGAIN;
  145. case EMSGSIZE:
  146. /* UDP datagram is too large; caused by PMTUD. Just let it be lost. */
  147. break;
  148. case EIO:
  149. if(pktlen > gsolen) {
  150. /* GSO failure */
  151. failf(data, "sendmsg() returned %zd (errno %d); disable GSO", sent,
  152. SOCKERRNO);
  153. qctx->no_gso = TRUE;
  154. return send_packet_no_gso(cf, data, qctx, pkt, pktlen, gsolen, psent);
  155. }
  156. /* FALLTHROUGH */
  157. default:
  158. failf(data, "sendmsg() returned %zd (errno %d)", sent, SOCKERRNO);
  159. return CURLE_SEND_ERROR;
  160. }
  161. }
  162. else {
  163. assert(pktlen == (size_t)sent);
  164. }
  165. #else
  166. ssize_t sent;
  167. (void)gsolen;
  168. *psent = 0;
  169. while((sent = send(qctx->sockfd,
  170. (const char *)pkt, (SEND_TYPE_ARG3)pktlen, 0)) == -1 &&
  171. SOCKERRNO == EINTR)
  172. ;
  173. if(sent == -1) {
  174. if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
  175. return CURLE_AGAIN;
  176. }
  177. else {
  178. failf(data, "send() returned %zd (errno %d)", sent, SOCKERRNO);
  179. if(SOCKERRNO != EMSGSIZE) {
  180. return CURLE_SEND_ERROR;
  181. }
  182. /* UDP datagram is too large; caused by PMTUD. Just let it be
  183. lost. */
  184. }
  185. }
  186. #endif
  187. (void)cf;
  188. *psent = pktlen;
  189. return CURLE_OK;
  190. }
  191. static CURLcode send_packet_no_gso(struct Curl_cfilter *cf,
  192. struct Curl_easy *data,
  193. struct cf_quic_ctx *qctx,
  194. const uint8_t *pkt, size_t pktlen,
  195. size_t gsolen, size_t *psent)
  196. {
  197. const uint8_t *p, *end = pkt + pktlen;
  198. size_t sent;
  199. *psent = 0;
  200. for(p = pkt; p < end; p += gsolen) {
  201. size_t len = CURLMIN(gsolen, (size_t)(end - p));
  202. CURLcode curlcode = do_sendmsg(cf, data, qctx, p, len, len, &sent);
  203. if(curlcode != CURLE_OK) {
  204. return curlcode;
  205. }
  206. *psent += sent;
  207. }
  208. return CURLE_OK;
  209. }
  210. static CURLcode vquic_send_packets(struct Curl_cfilter *cf,
  211. struct Curl_easy *data,
  212. struct cf_quic_ctx *qctx,
  213. const uint8_t *pkt, size_t pktlen,
  214. size_t gsolen, size_t *psent)
  215. {
  216. #ifdef DEBUGBUILD
  217. /* simulate network blocking/partial writes */
  218. if(qctx->wblock_percent > 0) {
  219. unsigned char c;
  220. Curl_rand(data, &c, 1);
  221. if(c >= ((100-qctx->wblock_percent)*256/100)) {
  222. CURL_TRC_CF(data, cf, "vquic_flush() simulate EWOULDBLOCK");
  223. return CURLE_AGAIN;
  224. }
  225. }
  226. #endif
  227. if(qctx->no_gso && pktlen > gsolen) {
  228. return send_packet_no_gso(cf, data, qctx, pkt, pktlen, gsolen, psent);
  229. }
  230. return do_sendmsg(cf, data, qctx, pkt, pktlen, gsolen, psent);
  231. }
  232. CURLcode vquic_flush(struct Curl_cfilter *cf, struct Curl_easy *data,
  233. struct cf_quic_ctx *qctx)
  234. {
  235. const unsigned char *buf;
  236. size_t blen, sent;
  237. CURLcode result;
  238. size_t gsolen;
  239. while(Curl_bufq_peek(&qctx->sendbuf, &buf, &blen)) {
  240. gsolen = qctx->gsolen;
  241. if(qctx->split_len) {
  242. gsolen = qctx->split_gsolen;
  243. if(blen > qctx->split_len)
  244. blen = qctx->split_len;
  245. }
  246. result = vquic_send_packets(cf, data, qctx, buf, blen, gsolen, &sent);
  247. CURL_TRC_CF(data, cf, "vquic_send(len=%zu, gso=%zu) -> %d, sent=%zu",
  248. blen, gsolen, result, sent);
  249. if(result) {
  250. if(result == CURLE_AGAIN) {
  251. Curl_bufq_skip(&qctx->sendbuf, sent);
  252. if(qctx->split_len)
  253. qctx->split_len -= sent;
  254. }
  255. return result;
  256. }
  257. Curl_bufq_skip(&qctx->sendbuf, sent);
  258. if(qctx->split_len)
  259. qctx->split_len -= sent;
  260. }
  261. return CURLE_OK;
  262. }
  263. CURLcode vquic_send(struct Curl_cfilter *cf, struct Curl_easy *data,
  264. struct cf_quic_ctx *qctx, size_t gsolen)
  265. {
  266. qctx->gsolen = gsolen;
  267. return vquic_flush(cf, data, qctx);
  268. }
  269. CURLcode vquic_send_tail_split(struct Curl_cfilter *cf, struct Curl_easy *data,
  270. struct cf_quic_ctx *qctx, size_t gsolen,
  271. size_t tail_len, size_t tail_gsolen)
  272. {
  273. DEBUGASSERT(Curl_bufq_len(&qctx->sendbuf) > tail_len);
  274. qctx->split_len = Curl_bufq_len(&qctx->sendbuf) - tail_len;
  275. qctx->split_gsolen = gsolen;
  276. qctx->gsolen = tail_gsolen;
  277. CURL_TRC_CF(data, cf, "vquic_send_tail_split: [%zu gso=%zu][%zu gso=%zu]",
  278. qctx->split_len, qctx->split_gsolen,
  279. tail_len, qctx->gsolen);
  280. return vquic_flush(cf, data, qctx);
  281. }
  282. #ifdef HAVE_SENDMMSG
  283. static CURLcode recvmmsg_packets(struct Curl_cfilter *cf,
  284. struct Curl_easy *data,
  285. struct cf_quic_ctx *qctx,
  286. size_t max_pkts,
  287. vquic_recv_pkt_cb *recv_cb, void *userp)
  288. {
  289. #define MMSG_NUM 64
  290. struct iovec msg_iov[MMSG_NUM];
  291. struct mmsghdr mmsg[MMSG_NUM];
  292. uint8_t bufs[MMSG_NUM][2*1024];
  293. struct sockaddr_storage remote_addr[MMSG_NUM];
  294. size_t total_nread, pkts;
  295. int mcount, i, n;
  296. char errstr[STRERROR_LEN];
  297. CURLcode result = CURLE_OK;
  298. DEBUGASSERT(max_pkts > 0);
  299. pkts = 0;
  300. total_nread = 0;
  301. while(pkts < max_pkts) {
  302. n = (int)CURLMIN(MMSG_NUM, max_pkts);
  303. memset(&mmsg, 0, sizeof(mmsg));
  304. for(i = 0; i < n; ++i) {
  305. msg_iov[i].iov_base = bufs[i];
  306. msg_iov[i].iov_len = (int)sizeof(bufs[i]);
  307. mmsg[i].msg_hdr.msg_iov = &msg_iov[i];
  308. mmsg[i].msg_hdr.msg_iovlen = 1;
  309. mmsg[i].msg_hdr.msg_name = &remote_addr[i];
  310. mmsg[i].msg_hdr.msg_namelen = sizeof(remote_addr[i]);
  311. }
  312. while((mcount = recvmmsg(qctx->sockfd, mmsg, n, 0, NULL)) == -1 &&
  313. SOCKERRNO == EINTR)
  314. ;
  315. if(mcount == -1) {
  316. if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
  317. CURL_TRC_CF(data, cf, "ingress, recvmmsg -> EAGAIN");
  318. goto out;
  319. }
  320. if(!cf->connected && SOCKERRNO == ECONNREFUSED) {
  321. const char *r_ip = NULL;
  322. int r_port = 0;
  323. Curl_cf_socket_peek(cf->next, data, NULL, NULL,
  324. &r_ip, &r_port, NULL, NULL);
  325. failf(data, "QUIC: connection to %s port %u refused",
  326. r_ip, r_port);
  327. result = CURLE_COULDNT_CONNECT;
  328. goto out;
  329. }
  330. Curl_strerror(SOCKERRNO, errstr, sizeof(errstr));
  331. failf(data, "QUIC: recvmsg() unexpectedly returned %d (errno=%d; %s)",
  332. mcount, SOCKERRNO, errstr);
  333. result = CURLE_RECV_ERROR;
  334. goto out;
  335. }
  336. CURL_TRC_CF(data, cf, "recvmmsg() -> %d packets", mcount);
  337. pkts += mcount;
  338. for(i = 0; i < mcount; ++i) {
  339. total_nread += mmsg[i].msg_len;
  340. result = recv_cb(bufs[i], mmsg[i].msg_len,
  341. mmsg[i].msg_hdr.msg_name, mmsg[i].msg_hdr.msg_namelen,
  342. 0, userp);
  343. if(result)
  344. goto out;
  345. }
  346. }
  347. out:
  348. if(total_nread || result)
  349. CURL_TRC_CF(data, cf, "recvd %zu packets with %zu bytes -> %d",
  350. pkts, total_nread, result);
  351. return result;
  352. }
  353. #elif defined(HAVE_SENDMSG)
  354. static CURLcode recvmsg_packets(struct Curl_cfilter *cf,
  355. struct Curl_easy *data,
  356. struct cf_quic_ctx *qctx,
  357. size_t max_pkts,
  358. vquic_recv_pkt_cb *recv_cb, void *userp)
  359. {
  360. struct iovec msg_iov;
  361. struct msghdr msg;
  362. uint8_t buf[64*1024];
  363. struct sockaddr_storage remote_addr;
  364. size_t total_nread, pkts;
  365. ssize_t nread;
  366. char errstr[STRERROR_LEN];
  367. CURLcode result = CURLE_OK;
  368. msg_iov.iov_base = buf;
  369. msg_iov.iov_len = (int)sizeof(buf);
  370. memset(&msg, 0, sizeof(msg));
  371. msg.msg_iov = &msg_iov;
  372. msg.msg_iovlen = 1;
  373. DEBUGASSERT(max_pkts > 0);
  374. for(pkts = 0, total_nread = 0; pkts < max_pkts;) {
  375. msg.msg_name = &remote_addr;
  376. msg.msg_namelen = sizeof(remote_addr);
  377. while((nread = recvmsg(qctx->sockfd, &msg, 0)) == -1 &&
  378. SOCKERRNO == EINTR)
  379. ;
  380. if(nread == -1) {
  381. if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
  382. goto out;
  383. }
  384. if(!cf->connected && SOCKERRNO == ECONNREFUSED) {
  385. const char *r_ip = NULL;
  386. int r_port = 0;
  387. Curl_cf_socket_peek(cf->next, data, NULL, NULL,
  388. &r_ip, &r_port, NULL, NULL);
  389. failf(data, "QUIC: connection to %s port %u refused",
  390. r_ip, r_port);
  391. result = CURLE_COULDNT_CONNECT;
  392. goto out;
  393. }
  394. Curl_strerror(SOCKERRNO, errstr, sizeof(errstr));
  395. failf(data, "QUIC: recvmsg() unexpectedly returned %zd (errno=%d; %s)",
  396. nread, SOCKERRNO, errstr);
  397. result = CURLE_RECV_ERROR;
  398. goto out;
  399. }
  400. ++pkts;
  401. total_nread += (size_t)nread;
  402. result = recv_cb(buf, (size_t)nread, msg.msg_name, msg.msg_namelen,
  403. 0, userp);
  404. if(result)
  405. goto out;
  406. }
  407. out:
  408. if(total_nread || result)
  409. CURL_TRC_CF(data, cf, "recvd %zu packets with %zu bytes -> %d",
  410. pkts, total_nread, result);
  411. return result;
  412. }
  413. #else /* HAVE_SENDMMSG || HAVE_SENDMSG */
  414. static CURLcode recvfrom_packets(struct Curl_cfilter *cf,
  415. struct Curl_easy *data,
  416. struct cf_quic_ctx *qctx,
  417. size_t max_pkts,
  418. vquic_recv_pkt_cb *recv_cb, void *userp)
  419. {
  420. uint8_t buf[64*1024];
  421. int bufsize = (int)sizeof(buf);
  422. struct sockaddr_storage remote_addr;
  423. socklen_t remote_addrlen = sizeof(remote_addr);
  424. size_t total_nread, pkts;
  425. ssize_t nread;
  426. char errstr[STRERROR_LEN];
  427. CURLcode result = CURLE_OK;
  428. DEBUGASSERT(max_pkts > 0);
  429. for(pkts = 0, total_nread = 0; pkts < max_pkts;) {
  430. while((nread = recvfrom(qctx->sockfd, (char *)buf, bufsize, 0,
  431. (struct sockaddr *)&remote_addr,
  432. &remote_addrlen)) == -1 &&
  433. SOCKERRNO == EINTR)
  434. ;
  435. if(nread == -1) {
  436. if(SOCKERRNO == EAGAIN || SOCKERRNO == EWOULDBLOCK) {
  437. CURL_TRC_CF(data, cf, "ingress, recvfrom -> EAGAIN");
  438. goto out;
  439. }
  440. if(!cf->connected && SOCKERRNO == ECONNREFUSED) {
  441. const char *r_ip = NULL;
  442. int r_port = 0;
  443. Curl_cf_socket_peek(cf->next, data, NULL, NULL,
  444. &r_ip, &r_port, NULL, NULL);
  445. failf(data, "QUIC: connection to %s port %u refused",
  446. r_ip, r_port);
  447. result = CURLE_COULDNT_CONNECT;
  448. goto out;
  449. }
  450. Curl_strerror(SOCKERRNO, errstr, sizeof(errstr));
  451. failf(data, "QUIC: recvfrom() unexpectedly returned %zd (errno=%d; %s)",
  452. nread, SOCKERRNO, errstr);
  453. result = CURLE_RECV_ERROR;
  454. goto out;
  455. }
  456. ++pkts;
  457. total_nread += (size_t)nread;
  458. result = recv_cb(buf, (size_t)nread, &remote_addr, remote_addrlen,
  459. 0, userp);
  460. if(result)
  461. goto out;
  462. }
  463. out:
  464. if(total_nread || result)
  465. CURL_TRC_CF(data, cf, "recvd %zu packets with %zu bytes -> %d",
  466. pkts, total_nread, result);
  467. return result;
  468. }
  469. #endif /* !HAVE_SENDMMSG && !HAVE_SENDMSG */
  470. CURLcode vquic_recv_packets(struct Curl_cfilter *cf,
  471. struct Curl_easy *data,
  472. struct cf_quic_ctx *qctx,
  473. size_t max_pkts,
  474. vquic_recv_pkt_cb *recv_cb, void *userp)
  475. {
  476. #if defined(HAVE_SENDMMSG)
  477. return recvmmsg_packets(cf, data, qctx, max_pkts, recv_cb, userp);
  478. #elif defined(HAVE_SENDMSG)
  479. return recvmsg_packets(cf, data, qctx, max_pkts, recv_cb, userp);
  480. #else
  481. return recvfrom_packets(cf, data, qctx, max_pkts, recv_cb, userp);
  482. #endif
  483. }
  484. /*
  485. * If the QLOGDIR environment variable is set, open and return a file
  486. * descriptor to write the log to.
  487. *
  488. * This function returns error if something failed outside of failing to
  489. * create the file. Open file success is deemed by seeing if the returned fd
  490. * is != -1.
  491. */
  492. CURLcode Curl_qlogdir(struct Curl_easy *data,
  493. unsigned char *scid,
  494. size_t scidlen,
  495. int *qlogfdp)
  496. {
  497. const char *qlog_dir = getenv("QLOGDIR");
  498. *qlogfdp = -1;
  499. if(qlog_dir) {
  500. struct dynbuf fname;
  501. CURLcode result;
  502. unsigned int i;
  503. Curl_dyn_init(&fname, DYN_QLOG_NAME);
  504. result = Curl_dyn_add(&fname, qlog_dir);
  505. if(!result)
  506. result = Curl_dyn_add(&fname, "/");
  507. for(i = 0; (i < scidlen) && !result; i++) {
  508. char hex[3];
  509. msnprintf(hex, 3, "%02x", scid[i]);
  510. result = Curl_dyn_add(&fname, hex);
  511. }
  512. if(!result)
  513. result = Curl_dyn_add(&fname, ".sqlog");
  514. if(!result) {
  515. int qlogfd = open(Curl_dyn_ptr(&fname), QLOGMODE,
  516. data->set.new_file_perms);
  517. if(qlogfd != -1)
  518. *qlogfdp = qlogfd;
  519. }
  520. Curl_dyn_free(&fname);
  521. if(result)
  522. return result;
  523. }
  524. return CURLE_OK;
  525. }
  526. CURLcode Curl_cf_quic_create(struct Curl_cfilter **pcf,
  527. struct Curl_easy *data,
  528. struct connectdata *conn,
  529. const struct Curl_addrinfo *ai,
  530. int transport)
  531. {
  532. (void)transport;
  533. DEBUGASSERT(transport == TRNSPRT_QUIC);
  534. #if defined(USE_NGTCP2) && defined(USE_NGHTTP3)
  535. return Curl_cf_ngtcp2_create(pcf, data, conn, ai);
  536. #elif defined(USE_QUICHE)
  537. return Curl_cf_quiche_create(pcf, data, conn, ai);
  538. #elif defined(USE_MSH3)
  539. return Curl_cf_msh3_create(pcf, data, conn, ai);
  540. #else
  541. *pcf = NULL;
  542. (void)data;
  543. (void)conn;
  544. (void)ai;
  545. return CURLE_NOT_BUILT_IN;
  546. #endif
  547. }
  548. bool Curl_conn_is_http3(const struct Curl_easy *data,
  549. const struct connectdata *conn,
  550. int sockindex)
  551. {
  552. #if defined(USE_NGTCP2) && defined(USE_NGHTTP3)
  553. return Curl_conn_is_ngtcp2(data, conn, sockindex);
  554. #elif defined(USE_QUICHE)
  555. return Curl_conn_is_quiche(data, conn, sockindex);
  556. #elif defined(USE_MSH3)
  557. return Curl_conn_is_msh3(data, conn, sockindex);
  558. #else
  559. return ((conn->handler->protocol & PROTO_FAMILY_HTTP) &&
  560. (conn->httpversion == 30));
  561. #endif
  562. }
  563. CURLcode Curl_conn_may_http3(struct Curl_easy *data,
  564. const struct connectdata *conn)
  565. {
  566. if(conn->transport == TRNSPRT_UNIX) {
  567. /* cannot do QUIC over a unix domain socket */
  568. return CURLE_QUIC_CONNECT_ERROR;
  569. }
  570. if(!(conn->handler->flags & PROTOPT_SSL)) {
  571. failf(data, "HTTP/3 requested for non-HTTPS URL");
  572. return CURLE_URL_MALFORMAT;
  573. }
  574. #ifndef CURL_DISABLE_PROXY
  575. if(conn->bits.socksproxy) {
  576. failf(data, "HTTP/3 is not supported over a SOCKS proxy");
  577. return CURLE_URL_MALFORMAT;
  578. }
  579. if(conn->bits.httpproxy && conn->bits.tunnel_proxy) {
  580. failf(data, "HTTP/3 is not supported over a HTTP proxy");
  581. return CURLE_URL_MALFORMAT;
  582. }
  583. #endif
  584. return CURLE_OK;
  585. }
  586. #else /* ENABLE_QUIC */
  587. CURLcode Curl_conn_may_http3(struct Curl_easy *data,
  588. const struct connectdata *conn)
  589. {
  590. (void)conn;
  591. (void)data;
  592. DEBUGF(infof(data, "QUIC is not supported in this build"));
  593. return CURLE_NOT_BUILT_IN;
  594. }
  595. #endif /* !ENABLE_QUIC */