#endif
#include "urldata.h"
+#include "cfilters.h"
#include "sendf.h"
#include "hostip.h"
#include "hash.h"
(pf == PF_UNSPEC) ? "A+AAAA" :
((pf == PF_INET) ? "A" : "AAAA"));
hints.ai_family = pf;
- hints.ai_socktype = (data->conn->transport == TRNSPRT_TCP) ?
+ hints.ai_socktype =
+ (Curl_conn_get_transport(data, data->conn) == TRNSPRT_TCP) ?
SOCK_STREAM : SOCK_DGRAM;
/* Since the service is a numerical one, set the hint flags
* accordingly to save a call to getservbyname in inside C-Ares
#endif
#include "urldata.h"
+#include "cfilters.h"
#include "sendf.h"
#include "hostip.h"
#include "hash.h"
memset(&hints, 0, sizeof(hints));
hints.ai_family = pf;
- hints.ai_socktype = (data->conn->transport == TRNSPRT_TCP) ?
+ hints.ai_socktype =
+ (Curl_conn_get_transport(data, data->conn) == TRNSPRT_TCP) ?
SOCK_STREAM : SOCK_DGRAM;
/* fire up a new resolver thread! */
CURLcode result;
struct curltime started;
int reply_ms;
+ unsigned char transport;
enum alpnid alpn_id;
BIT(shutdown);
};
};
static void cf_hc_baller_assign(struct cf_hc_baller *b,
- enum alpnid alpn_id)
+ enum alpnid alpn_id,
+ unsigned char def_transport)
{
b->alpn_id = alpn_id;
+ b->transport = def_transport;
switch(b->alpn_id) {
case ALPN_h3:
b->name = "h3";
+ b->transport = TRNSPRT_QUIC;
break;
case ALPN_h2:
b->name = "h2";
winner->name, (int)curlx_timediff(curlx_now(),
winner->started));
+ /* install the winning filter below this one. */
cf->next = winner->cf;
winner->cf = NULL;
DEBUGASSERT(!ctx->ballers[i].cf);
CURL_TRC_CF(data, cf, "connect, init");
ctx->started = now;
- cf_hc_baller_init(&ctx->ballers[0], cf, data, cf->conn->transport);
+ cf_hc_baller_init(&ctx->ballers[0], cf, data, ctx->ballers[0].transport);
if(ctx->baller_count > 1) {
Curl_expire(data, ctx->soft_eyeballs_timeout_ms, EXPIRE_ALPN_EYEBALLS);
CURL_TRC_CF(data, cf, "set next attempt to start in %" FMT_TIMEDIFF_T
}
if(time_to_start_next(cf, data, 1, now)) {
- cf_hc_baller_init(&ctx->ballers[1], cf, data, cf->conn->transport);
+ cf_hc_baller_init(&ctx->ballers[1], cf, data, ctx->ballers[1].transport);
}
if((ctx->baller_count > 1) && cf_hc_baller_is_active(&ctx->ballers[1])) {
static CURLcode cf_hc_create(struct Curl_cfilter **pcf,
struct Curl_easy *data,
- enum alpnid *alpnids, size_t alpn_count)
+ enum alpnid *alpnids, size_t alpn_count,
+ unsigned char def_transport)
{
struct Curl_cfilter *cf = NULL;
struct cf_hc_ctx *ctx;
goto out;
}
for(i = 0; i < alpn_count; ++i)
- cf_hc_baller_assign(&ctx->ballers[i], alpnids[i]);
+ cf_hc_baller_assign(&ctx->ballers[i], alpnids[i], def_transport);
for(; i < CURL_ARRAYSIZE(ctx->ballers); ++i)
ctx->ballers[i].alpn_id = ALPN_none;
ctx->baller_count = alpn_count;
static CURLcode cf_http_connect_add(struct Curl_easy *data,
struct connectdata *conn,
int sockindex,
- enum alpnid *alpn_ids, size_t alpn_count)
+ enum alpnid *alpn_ids, size_t alpn_count,
+ unsigned char def_transport)
{
struct Curl_cfilter *cf;
CURLcode result = CURLE_OK;
DEBUGASSERT(data);
- result = cf_hc_create(&cf, data, alpn_ids, alpn_count);
+ result = cf_hc_create(&cf, data, alpn_ids, alpn_count, def_transport);
if(result)
goto out;
Curl_conn_cf_add(data, conn, sockindex, cf);
continue;
switch(alpn) {
case ALPN_h3:
- if(Curl_conn_may_http3(data, conn))
+ if(Curl_conn_may_http3(data, conn, conn->transport_wanted))
break; /* not possible */
if(data->state.http_neg.allowed & CURL_HTTP_V3x) {
CURL_TRC_CF(data, cf, "adding h3 via HTTPS-RR");
if((alpn_count < CURL_ARRAYSIZE(alpn_ids)) &&
(data->state.http_neg.wanted & CURL_HTTP_V3x) &&
!cf_https_alpns_contain(ALPN_h3, alpn_ids, alpn_count)) {
- result = Curl_conn_may_http3(data, conn);
+ result = Curl_conn_may_http3(data, conn, conn->transport_wanted);
if(!result) {
CURL_TRC_CF(data, cf, "adding wanted h3");
alpn_ids[alpn_count++] = ALPN_h3;
/* If we identified ALPNs to use, install our filter. Otherwise,
* install nothing, so our call will use a default connect setup. */
if(alpn_count) {
- result = cf_http_connect_add(data, conn, sockindex, alpn_ids, alpn_count);
+ result = cf_http_connect_add(data, conn, sockindex,
+ alpn_ids, alpn_count,
+ conn->transport_wanted);
}
out:
DEBUGASSERT(pres2);
*((curl_socket_t *)pres2) = ctx->sock;
return CURLE_OK;
+ case CF_QUERY_TRANSPORT:
+ DEBUGASSERT(pres1);
+ *pres1 = ctx->transport;
+ return CURLE_OK;
case CF_QUERY_REMOTE_ADDR:
DEBUGASSERT(pres2);
*((const struct Curl_sockaddr_ex **)pres2) = cf->connected ?
result = CURLE_OUT_OF_MEMORY;
goto out;
}
- ctx->transport = conn->transport;
+ ctx->transport = TRNSPRT_TCP;
ctx->sock = *s;
ctx->listening = TRUE;
ctx->accepted = FALSE;
return FALSE;
}
+unsigned char Curl_conn_get_transport(struct Curl_easy *data,
+ struct connectdata *conn)
+{
+ struct Curl_cfilter *cf = conn->cfilter[FIRSTSOCKET];
+ return Curl_conn_cf_get_transport(cf, data);
+}
+
unsigned char Curl_conn_http_version(struct Curl_easy *data,
struct connectdata *conn)
{
return CURL_SOCKET_BAD;
}
+unsigned char Curl_conn_cf_get_transport(struct Curl_cfilter *cf,
+ struct Curl_easy *data)
+{
+ int transport = 0;
+ if(cf && !cf->cft->query(cf, data, CF_QUERY_TRANSPORT, &transport, NULL))
+ return (unsigned char)transport;
+ return (unsigned char)(data->conn ? data->conn->transport_wanted : 0);
+}
+
static const struct Curl_sockaddr_ex *
cf_get_remote_addr(struct Curl_cfilter *cf, struct Curl_easy *data)
{
#define CF_QUERY_HOST_PORT 11 /* port const char * */
#define CF_QUERY_SSL_INFO 12 /* - struct curl_tlssessioninfo * */
#define CF_QUERY_SSL_CTX_INFO 13 /* - struct curl_tlssessioninfo * */
+#define CF_QUERY_TRANSPORT 14 /* TRNSPRT_* - * */
/**
* Query the cfilter for properties. Filters ignorant of a query will
bool Curl_conn_cf_needs_flush(struct Curl_cfilter *cf,
struct Curl_easy *data);
+unsigned char Curl_conn_cf_get_transport(struct Curl_cfilter *cf,
+ struct Curl_easy *data);
+
#define CURL_CF_SSL_DEFAULT -1
#define CURL_CF_SSL_DISABLE 0
#define CURL_CF_SSL_ENABLE 1
unsigned char Curl_conn_http_version(struct Curl_easy *data,
struct connectdata *conn);
+/* Get the TRNSPRT_* the connection is using */
+unsigned char Curl_conn_get_transport(struct Curl_easy *data,
+ struct connectdata *conn);
+
/**
* Close the filter chain at `sockindex` for connection `data->conn`.
* Filters remain in place and may be connected again afterwards.
/* Still no cfilter set, apply default. */
if(!conn->cfilter[sockindex]) {
- result = cf_setup_add(data, conn, sockindex, conn->transport, ssl_mode);
+ result = cf_setup_add(data, conn, sockindex,
+ conn->transport_wanted, ssl_mode);
if(result)
goto out;
}
/* step 2, create a socket for the requested address */
error = 0;
for(ai = res; ai; ai = ai->ai_next) {
- if(Curl_socket_open(data, ai, NULL, conn->transport, &portsock)) {
+ if(Curl_socket_open(data, ai, NULL,
+ Curl_conn_get_transport(data, conn), &portsock)) {
error = SOCKERRNO;
continue;
}
#endif
#include "urldata.h"
+#include "cfilters.h"
#include "sendf.h"
#include "hostip.h"
#include "hash.h"
memset(&hints, 0, sizeof(hints));
hints.ai_family = pf;
- hints.ai_socktype = (data->conn->transport == TRNSPRT_TCP) ?
+ hints.ai_socktype =
+ (Curl_conn_get_transport(data, data->conn) == TRNSPRT_TCP) ?
SOCK_STREAM : SOCK_DGRAM;
#ifndef USE_RESOLVE_ON_IPS
connkeep(conn, "HTTP default");
if(data->state.http_neg.wanted == CURL_HTTP_V3x) {
/* only HTTP/3, needs to work */
- CURLcode result = Curl_conn_may_http3(data, conn);
+ CURLcode result = Curl_conn_may_http3(data, conn, conn->transport_wanted);
if(result)
return result;
}
{
char *type;
- conn->transport = TRNSPRT_UDP;
+ conn->transport_wanted = TRNSPRT_UDP;
/* TFTP URLs support an extension like ";mode=<typecode>" that
* we will try to get now! */
#endif
conn->ip_version = data->set.ipver;
conn->connect_only = data->set.connect_only;
- conn->transport = TRNSPRT_TCP; /* most of them are TCP streams */
+ conn->transport_wanted = TRNSPRT_TCP; /* most of them are TCP streams */
/* Initialize the attached xfers bitset */
Curl_uint_spbset_init(&conn->xfers_attached);
neg->wanted = neg->allowed = CURL_HTTP_V2x;
break;
case ALPN_h3:
- conn->transport = TRNSPRT_QUIC;
+ conn->transport_wanted = TRNSPRT_QUIC;
neg->wanted = neg->allowed = CURL_HTTP_V3x;
break;
default: /* should not be possible */
if(unix_path) {
/* This only works if previous transport is TRNSPRT_TCP. Check it? */
- conn->transport = TRNSPRT_UNIX;
+ conn->transport_wanted = TRNSPRT_UNIX;
return resolve_unix(data, conn, unix_path, pdns);
}
}
#ifndef CURL_DISABLE_PROXY
unsigned char proxy_alpn; /* APLN of proxy tunnel, CURL_HTTP_VERSION* */
#endif
- unsigned char transport; /* one of the TRNSPRT_* defines */
+ unsigned char transport_wanted; /* one of the TRNSPRT_* defines. Not
+ necessarily the transport the connection ends using due to Alt-Svc
+ and happy eyeballing. Use `Curl_conn_get_transport() for actual value
+ once the connection is set up. */
unsigned char ip_version; /* copied from the Curl_easy at creation time */
/* HTTP version last responded with by the server.
* 0 at start, then one of 09, 10, 11, etc. */
}
CURLcode Curl_conn_may_http3(struct Curl_easy *data,
- const struct connectdata *conn)
+ const struct connectdata *conn,
+ unsigned char transport)
{
- if(conn->transport == TRNSPRT_UNIX) {
+ if(transport == TRNSPRT_UNIX) {
/* cannot do QUIC over a Unix domain socket */
return CURLE_QUIC_CONNECT_ERROR;
}
#else /* USE_HTTP3 */
CURLcode Curl_conn_may_http3(struct Curl_easy *data,
- const struct connectdata *conn)
+ const struct connectdata *conn,
+ unsigned char transport)
{
(void)conn;
(void)data;
+ (void)transport;
DEBUGF(infof(data, "QUIC is not supported in this build"));
return CURLE_NOT_BUILT_IN;
}
#endif /* !USE_HTTP3 */
CURLcode Curl_conn_may_http3(struct Curl_easy *data,
- const struct connectdata *conn);
+ const struct connectdata *conn,
+ unsigned char transport);
#endif /* HEADER_CURL_VQUIC_QUIC_H */
size_t idx = 0;
#endif
CURLcode result = CURLE_FAILED_INIT;
+ unsigned char transport;
DEBUGASSERT(!wctx->ssl_ctx);
DEBUGASSERT(!wctx->ssl);
goto out;
}
Curl_alpn_copy(&alpns, alpns_requested);
+ DEBUGASSERT(cf->next);
+ transport = Curl_conn_cf_get_transport(cf->next, data);
#if LIBWOLFSSL_VERSION_HEX < 0x04002000 /* 4.2.0 (2019) */
req_method = wolfSSLv23_client_method();
#endif
curves = conn_config->curves;
- if(!curves && cf->conn->transport == TRNSPRT_QUIC)
+ if(!curves && (transport == TRNSPRT_QUIC))
curves = (char *)CURL_UNCONST(QUIC_GROUPS);
if(curves) {
}
#endif
- if(ssl_config->primary.cache_session &&
- cf->conn->transport != TRNSPRT_QUIC) {
+ if(ssl_config->primary.cache_session && (transport != TRNSPRT_QUIC)) {
/* Register to get notified when a new session is received */
wolfSSL_CTX_sess_set_new_cb(wctx->ssl_ctx, wssl_vtls_new_session_cb);
}
wolfSSL_set_app_data(wctx->ssl, ssl_user_data);
#ifdef WOLFSSL_QUIC
- if(cf->conn->transport == TRNSPRT_QUIC)
+ if(transport == TRNSPRT_QUIC)
wolfSSL_set_quic_use_legacy_codepoint(wctx->ssl, 0);
#endif