vtls: localization of state data in filters

- almost all backend calls pass the Curl_cfilter intance instead of
   connectdata+sockindex
 - ssl_connect_data is remove from struct connectdata and made internal
   to vtls
 - ssl_connect_data is allocated in the added filter, kept at cf->ctx

 - added function to let a ssl filter access its ssl_primary_config and
   ssl_config_data this selects the propert subfields in conn and data,
   for filters added as plain or proxy
 - adjusted all backends to use the changed api
 - adjusted all backends to access config data via the exposed
   functions, no longer using conn or data directly

cfilter renames for clear purpose:

 - methods `Curl_conn_*(data, conn, sockindex)` work on the complete
   filter chain at `sockindex` and connection `conn`.
 - methods `Curl_cf_*(cf, ...)` work on a specific Curl_cfilter
   instance.
 - methods `Curl_conn_cf()` work on/with filter instances at a
   connection.
 - rebased and resolved some naming conflicts
 - hostname validation (und session lookup) on SECONDARY use the same
   name as on FIRST (again).

new debug macros and removing connectdata from function signatures where not
needed.

adapting schannel for new Curl_read_plain paramter.

Closes #9919
This commit is contained in:
Stefan Eissing 2022-11-22 09:55:41 +01:00 committed by Daniel Stenberg
parent a28a80d59e
commit af22c2a546
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
48 changed files with 2230 additions and 2117 deletions

View file

@ -753,17 +753,16 @@ static void conn_reset_all_postponed_data(struct connectdata *conn)
#endif /* ! USE_RECV_BEFORE_SEND_WORKAROUND */
static void conn_shutdown(struct Curl_easy *data, struct connectdata *conn)
static void conn_shutdown(struct Curl_easy *data)
{
DEBUGASSERT(conn);
DEBUGASSERT(data);
infof(data, "Closing connection %ld", conn->connection_id);
infof(data, "Closing connection %ld", data->conn->connection_id);
/* possible left-overs from the async name resolvers */
Curl_resolver_cancel(data);
Curl_cfilter_close(data, conn, SECONDARYSOCKET);
Curl_cfilter_close(data, conn, FIRSTSOCKET);
Curl_conn_close(data, SECONDARYSOCKET);
Curl_conn_close(data, FIRSTSOCKET);
}
static void conn_free(struct Curl_easy *data, struct connectdata *conn)
@ -773,7 +772,7 @@ static void conn_free(struct Curl_easy *data, struct connectdata *conn)
DEBUGASSERT(conn);
for(i = 0; i < ARRAYSIZE(conn->cfilter); ++i) {
Curl_cfilter_destroy(data, conn, (int)i);
Curl_conn_cf_discard_all(data, conn, (int)i);
}
Curl_free_idnconverted_hostname(&conn->host);
@ -809,9 +808,6 @@ static void conn_free(struct Curl_easy *data, struct connectdata *conn)
Curl_safefree(conn->unix_domain_socket);
#endif
#ifdef USE_SSL
Curl_safefree(conn->ssl_extra);
#endif
free(conn); /* free all the connection oriented data */
}
@ -878,7 +874,7 @@ void Curl_disconnect(struct Curl_easy *data,
/* This is set if protocol-specific cleanups should be made */
conn->handler->disconnect(data, conn, dead_connection);
conn_shutdown(data, conn);
conn_shutdown(data);
/* detach it again */
Curl_detach_connection(data);
@ -1241,7 +1237,7 @@ ConnectionExists(struct Curl_easy *data,
}
}
if(check->sock[FIRSTSOCKET] == CURL_SOCKET_BAD) {
if(!Curl_conn_is_connected(check, FIRSTSOCKET)) {
foundPendingCandidate = TRUE;
/* Don't pick a connection that hasn't connected yet */
infof(data, "Connection #%ld isn't open enough, can't reuse",
@ -1307,15 +1303,11 @@ ConnectionExists(struct Curl_easy *data,
if(!Curl_ssl_config_matches(&needle->proxy_ssl_config,
&check->proxy_ssl_config))
continue;
if(check->proxy_ssl[FIRSTSOCKET].state != ssl_connection_complete)
continue;
}
if(!Curl_ssl_config_matches(&needle->ssl_config,
&check->ssl_config))
continue;
if(check->ssl[FIRSTSOCKET].state != ssl_connection_complete)
continue;
}
}
#endif
@ -1409,14 +1401,6 @@ ConnectionExists(struct Curl_easy *data,
check->connection_id));
continue;
}
if(check->ssl[FIRSTSOCKET].state != ssl_connection_complete) {
foundPendingCandidate = TRUE;
DEBUGF(infof(data,
"Connection #%ld has not started SSL connect, "
"can't reuse",
check->connection_id));
continue;
}
}
match = TRUE;
}
@ -1680,45 +1664,6 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
if(!conn)
return NULL;
#ifdef USE_SSL
/* The SSL backend-specific data (ssl_backend_data) objects are allocated as
a separate array to ensure suitable alignment.
Note that these backend pointers can be swapped by vtls (eg ssl backend
data becomes proxy backend data). */
{
size_t onesize = Curl_ssl_get_backend_data_size(data);
size_t totalsize = onesize;
char *ssl;
#ifndef CURL_DISABLE_FTP
totalsize *= 2;
#endif
#ifndef CURL_DISABLE_PROXY
totalsize *= 2;
#endif
ssl = calloc(1, totalsize);
if(!ssl) {
free(conn);
return NULL;
}
conn->ssl_extra = ssl;
conn->ssl[FIRSTSOCKET].backend = (void *)ssl;
#ifndef CURL_DISABLE_FTP
ssl += onesize;
conn->ssl[SECONDARYSOCKET].backend = (void *)ssl;
#endif
#ifndef CURL_DISABLE_PROXY
ssl += onesize;
conn->proxy_ssl[FIRSTSOCKET].backend = (void *)ssl;
#ifndef CURL_DISABLE_FTP
ssl += onesize;
conn->proxy_ssl[SECONDARYSOCKET].backend = (void *)ssl;
#endif
#endif
}
#endif
conn->handler = &Curl_handler_dummy; /* Be sure we have a handler defined
already from start to avoid NULL
situations and checks */
@ -1826,9 +1771,6 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
Curl_llist_destroy(&conn->easyq, NULL);
free(conn->localdev);
#ifdef USE_SSL
free(conn->ssl_extra);
#endif
free(conn);
return NULL;
}
@ -3810,10 +3752,10 @@ static CURLcode create_conn(struct Curl_easy *data,
#endif
/* Setup filter for network connections */
conn->recv[FIRSTSOCKET] = Curl_cfilter_recv;
conn->send[FIRSTSOCKET] = Curl_cfilter_send;
conn->recv[SECONDARYSOCKET] = Curl_cfilter_recv;
conn->send[SECONDARYSOCKET] = Curl_cfilter_send;
conn->recv[FIRSTSOCKET] = Curl_conn_recv;
conn->send[FIRSTSOCKET] = Curl_conn_send;
conn->recv[SECONDARYSOCKET] = Curl_conn_recv;
conn->send[SECONDARYSOCKET] = Curl_conn_send;
conn->bits.tcp_fastopen = data->set.tcp_fastopen;
/* Get a cloned copy of the SSL config situation stored in the
@ -4099,8 +4041,8 @@ CURLcode Curl_setup_conn(struct Curl_easy *data,
is later set again for the progress meter purpose */
conn->now = Curl_now();
if(!conn->bits.reuse)
result = Curl_cfilter_setup(data, conn, FIRSTSOCKET, conn->dns_entry,
CURL_CF_SSL_DEFAULT);
result = Curl_conn_setup(data, FIRSTSOCKET, conn->dns_entry,
CURL_CF_SSL_DEFAULT);
/* not sure we need this flag to be passed around any more */
*protocol_done = FALSE;
return result;