Skip to content

Commit

Permalink
cfiler: filter types have flags indicating what they do
Browse files Browse the repository at this point in the history
- Adding Curl_conn_is_ip_connected() to check if network connectivity
  has been reached

- having ftp wait for network connectivity before proceeding with
  transfers.

Fixes test failures 1631 and 1632 with hyper.

Closes curl#9952
  • Loading branch information
icing authored and bagder committed Nov 22, 2022
1 parent b7413a6 commit 4a8b4a1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
15 changes: 15 additions & 0 deletions lib/cfilters.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,21 @@ bool Curl_cfilter_is_connected(struct Curl_easy *data,
return cf && cf->connected;
}

bool Curl_conn_is_ip_connected(struct Curl_easy *data, int sockindex)
{
struct Curl_cfilter *cf;

cf = data->conn->cfilter[sockindex];
while(cf) {
if(cf->connected)
return TRUE;
if(cf->cft->flags & CF_TYPE_IP_CONNECT)
return FALSE;
cf = cf->next;
}
return FALSE;
}

bool Curl_cfilter_data_pending(const struct Curl_easy *data,
struct connectdata *conn, int sockindex)
{
Expand Down
10 changes: 10 additions & 0 deletions lib/cfilters.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ typedef void Curl_cf_detach_data(struct Curl_cfilter *cf,
*/
void Curl_cfilter_detach(struct connectdata *conn, struct Curl_easy *data);

#define CF_TYPE_IP_CONNECT (1 << 0)
#define CF_TYPE_SSL (1 << 1)

/* A connection filter type, e.g. specific implementation. */
struct Curl_cftype {
const char *name; /* name of the filter type */
long flags; /* flags of filter type */
Curl_cf_destroy *destroy; /* destroy resources held */
Curl_cf_attach_data *attach_data; /* data is being handled here */
Curl_cf_detach_data *detach_data; /* data is no longer handled here */
Expand Down Expand Up @@ -164,6 +168,12 @@ CURLcode Curl_cfilter_connect(struct Curl_easy *data,
bool blocking, bool *done);
bool Curl_cfilter_is_connected(struct Curl_easy *data,
struct connectdata *conn, int sockindex);
/**
* Determine if we have reached the remote host on IP level, e.g.
* have a TCP connection. This turns TRUE before a possible SSL
* handshake has been started/done.
*/
bool Curl_conn_is_ip_connected(struct Curl_easy *data, int sockindex);

void Curl_cfilter_close(struct Curl_easy *data,
struct connectdata *conn, int index);
Expand Down
2 changes: 2 additions & 0 deletions lib/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ static void socket_cf_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)

static const struct Curl_cftype cft_socket = {
"SOCKET",
CF_TYPE_IP_CONNECT,
socket_cf_destroy,
Curl_cf_def_attach_data,
Curl_cf_def_detach_data,
Expand Down Expand Up @@ -1892,6 +1893,7 @@ static CURLcode socket_accept_cf_setup(struct Curl_cfilter *cf,

static const struct Curl_cftype cft_socket_accept = {
"SOCKET-ACCEPT",
CF_TYPE_IP_CONNECT,
socket_cf_destroy,
Curl_cf_def_attach_data,
Curl_cf_def_detach_data,
Expand Down
10 changes: 7 additions & 3 deletions lib/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3560,12 +3560,16 @@ static CURLcode ftp_do_more(struct Curl_easy *data, int *completep)
* complete */
struct FTP *ftp = NULL;

/* if the second connection isn't done yet, wait for it */
/* if the second connection isn't done yet, wait for it to have
* connected to the remote host. When using proxy tunneling, this
* means the tunnel needs to have been establish. However, we
* can not expect the remote host to talk to us in any way yet.
* So, when using ftps: the SSL handshake will not start until we
* tell the remote server that we are there. */
if(conn->cfilter[SECONDARYSOCKET]) {
result = Curl_cfilter_connect(data, conn, SECONDARYSOCKET,
FALSE, &connected);
if(result ||
(!connected && conn->sock[SECONDARYSOCKET] == CURL_SOCKET_BAD)) {
if(result || !Curl_conn_is_ip_connected(data, SECONDARYSOCKET)) {
if(result && (ftpc->count1 == 0)) {
*completep = -1; /* go back to DOING please */
/* this is a EPSV connect failing, try PASV instead */
Expand Down
2 changes: 2 additions & 0 deletions lib/http_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ static void http_proxy_cf_close(struct Curl_cfilter *cf,

static const struct Curl_cftype cft_http_proxy = {
"HTTP-PROXY",
CF_TYPE_IP_CONNECT,
http_proxy_cf_destroy,
Curl_cf_def_attach_data,
http_proxy_cf_detach_data,
Expand Down Expand Up @@ -1246,6 +1247,7 @@ static CURLcode haproxy_cf_connect(struct Curl_cfilter *cf,

static const struct Curl_cftype cft_haproxy = {
"HAPROXY",
0,
Curl_cf_def_destroy,
Curl_cf_def_attach_data,
Curl_cf_def_detach_data,
Expand Down
1 change: 1 addition & 0 deletions lib/socks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,7 @@ static void socks_proxy_cf_detach_data(struct Curl_cfilter *cf,

static const struct Curl_cftype cft_socks_proxy = {
"SOCKS-PROXYY",
CF_TYPE_IP_CONNECT,
socks_proxy_cf_destroy,
Curl_cf_def_attach_data,
socks_proxy_cf_detach_data,
Expand Down
2 changes: 2 additions & 0 deletions lib/vtls/vtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,7 @@ static void ssl_cf_def_detach_data(struct Curl_cfilter *cf,

static const struct Curl_cftype cft_ssl = {
"SSL",
CF_TYPE_SSL,
ssl_cf_destroy,
ssl_cf_def_attach_data,
ssl_cf_def_detach_data,
Expand All @@ -1670,6 +1671,7 @@ static const struct Curl_cftype cft_ssl = {
#ifndef CURL_DISABLE_PROXY
static const struct Curl_cftype cft_ssl_proxy = {
"SSL-PROXY",
CF_TYPE_SSL,
ssl_cf_destroy,
ssl_cf_def_attach_data,
ssl_cf_def_detach_data,
Expand Down

0 comments on commit 4a8b4a1

Please sign in to comment.