|
@@ -776,10 +776,7 @@ struct cf_socket_ctx {
|
|
|
struct Curl_sockaddr_ex addr; /* address to connect to */
|
|
|
curl_socket_t sock; /* current attempt socket */
|
|
|
struct bufq recvbuf; /* used when `buffer_recv` is set */
|
|
|
- char r_ip[MAX_IPADR_LEN]; /* remote IP as string */
|
|
|
- int r_port; /* remote port number */
|
|
|
- char l_ip[MAX_IPADR_LEN]; /* local IP as string */
|
|
|
- int l_port; /* local port number */
|
|
|
+ struct ip_quadruple ip; /* The IP quadruple 2x(addr+port) */
|
|
|
struct curltime started_at; /* when socket was created */
|
|
|
struct curltime connected_at; /* when socket connected/got first byte */
|
|
|
struct curltime first_byte_at; /* when first byte was recvd */
|
|
@@ -941,7 +938,7 @@ static CURLcode set_local_ip(struct Curl_cfilter *cf,
|
|
|
return CURLE_FAILED_INIT;
|
|
|
}
|
|
|
if(!Curl_addr2string((struct sockaddr*)&ssloc, slen,
|
|
|
- ctx->l_ip, &ctx->l_port)) {
|
|
|
+ ctx->ip.local_ip, &ctx->ip.local_port)) {
|
|
|
failf(data, "ssloc inet_ntop() failed with errno %d: %s",
|
|
|
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
|
|
return CURLE_FAILED_INIT;
|
|
@@ -962,7 +959,7 @@ static CURLcode set_remote_ip(struct Curl_cfilter *cf,
|
|
|
|
|
|
/* store remote address and port used in this connection attempt */
|
|
|
if(!Curl_addr2string(&ctx->addr.sa_addr, ctx->addr.addrlen,
|
|
|
- ctx->r_ip, &ctx->r_port)) {
|
|
|
+ ctx->ip.remote_ip, &ctx->ip.remote_port)) {
|
|
|
char buffer[STRERROR_LEN];
|
|
|
|
|
|
ctx->error = errno;
|
|
@@ -997,11 +994,11 @@ static CURLcode cf_socket_open(struct Curl_cfilter *cf,
|
|
|
#ifdef ENABLE_IPV6
|
|
|
if(ctx->addr.family == AF_INET6) {
|
|
|
set_ipv6_v6only(ctx->sock, 0);
|
|
|
- infof(data, " Trying [%s]:%d...", ctx->r_ip, ctx->r_port);
|
|
|
+ infof(data, " Trying [%s]:%d...", ctx->ip.remote_ip, ctx->ip.remote_port);
|
|
|
}
|
|
|
else
|
|
|
#endif
|
|
|
- infof(data, " Trying %s:%d...", ctx->r_ip, ctx->r_port);
|
|
|
+ infof(data, " Trying %s:%d...", ctx->ip.remote_ip, ctx->ip.remote_port);
|
|
|
|
|
|
#ifdef ENABLE_IPV6
|
|
|
is_tcp = (ctx->addr.family == AF_INET
|
|
@@ -1167,9 +1164,9 @@ static CURLcode cf_tcp_connect(struct Curl_cfilter *cf,
|
|
|
error = SOCKERRNO;
|
|
|
set_local_ip(cf, data);
|
|
|
CURL_TRC_CF(data, cf, "local address %s port %d...",
|
|
|
- ctx->l_ip, ctx->l_port);
|
|
|
+ ctx->ip.local_ip, ctx->ip.local_port);
|
|
|
if(-1 == rc) {
|
|
|
- result = socket_connect_result(data, ctx->r_ip, error);
|
|
|
+ result = socket_connect_result(data, ctx->ip.remote_ip, error);
|
|
|
goto out;
|
|
|
}
|
|
|
}
|
|
@@ -1214,7 +1211,8 @@ out:
|
|
|
{
|
|
|
char buffer[STRERROR_LEN];
|
|
|
infof(data, "connect to %s port %u from %s port %d failed: %s",
|
|
|
- ctx->r_ip, ctx->r_port, ctx->l_ip, ctx->l_port,
|
|
|
+ ctx->ip.remote_ip, ctx->ip.remote_port,
|
|
|
+ ctx->ip.local_ip, ctx->ip.local_port,
|
|
|
Curl_strerror(ctx->error, buffer, sizeof(buffer)));
|
|
|
}
|
|
|
#endif
|
|
@@ -1234,10 +1232,11 @@ static void cf_socket_get_host(struct Curl_cfilter *cf,
|
|
|
const char **pdisplay_host,
|
|
|
int *pport)
|
|
|
{
|
|
|
+ struct cf_socket_ctx *ctx = cf->ctx;
|
|
|
(void)data;
|
|
|
*phost = cf->conn->host.name;
|
|
|
*pdisplay_host = cf->conn->host.dispname;
|
|
|
- *pport = cf->conn->port;
|
|
|
+ *pport = ctx->ip.remote_port;
|
|
|
}
|
|
|
|
|
|
static void cf_socket_adjust_pollset(struct Curl_cfilter *cf,
|
|
@@ -1436,31 +1435,24 @@ out:
|
|
|
return nread;
|
|
|
}
|
|
|
|
|
|
-static void conn_set_primary_ip(struct Curl_cfilter *cf,
|
|
|
- struct Curl_easy *data)
|
|
|
-{
|
|
|
- struct cf_socket_ctx *ctx = cf->ctx;
|
|
|
-
|
|
|
- (void)data;
|
|
|
- DEBUGASSERT(sizeof(ctx->r_ip) == sizeof(cf->conn->primary_ip));
|
|
|
- memcpy(cf->conn->primary_ip, ctx->r_ip, sizeof(cf->conn->primary_ip));
|
|
|
-}
|
|
|
-
|
|
|
static void cf_socket_active(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|
|
{
|
|
|
struct cf_socket_ctx *ctx = cf->ctx;
|
|
|
|
|
|
/* use this socket from now on */
|
|
|
cf->conn->sock[cf->sockindex] = ctx->sock;
|
|
|
- /* the first socket info gets set at conn and data */
|
|
|
+ set_local_ip(cf, data);
|
|
|
+ if(cf->sockindex == SECONDARYSOCKET)
|
|
|
+ cf->conn->secondary = ctx->ip;
|
|
|
+ else
|
|
|
+ cf->conn->primary = ctx->ip;
|
|
|
+ /* the first socket info gets some specials */
|
|
|
if(cf->sockindex == FIRSTSOCKET) {
|
|
|
cf->conn->remote_addr = &ctx->addr;
|
|
|
#ifdef ENABLE_IPV6
|
|
|
cf->conn->bits.ipv6 = (ctx->addr.family == AF_INET6)? TRUE : FALSE;
|
|
|
#endif
|
|
|
- conn_set_primary_ip(cf, data);
|
|
|
- set_local_ip(cf, data);
|
|
|
- Curl_persistconninfo(data, cf->conn, ctx->l_ip, ctx->l_port);
|
|
|
+ Curl_persistconninfo(data, cf->conn, &ctx->ip);
|
|
|
/* buffering is currently disabled by default because we have stalls
|
|
|
* in parallel transfers where not all buffered data is consumed and no
|
|
|
* socket events happen.
|
|
@@ -1483,7 +1475,7 @@ static CURLcode cf_socket_cntrl(struct Curl_cfilter *cf,
|
|
|
cf_socket_active(cf, data);
|
|
|
break;
|
|
|
case CF_CTRL_DATA_SETUP:
|
|
|
- Curl_persistconninfo(data, cf->conn, ctx->l_ip, ctx->l_port);
|
|
|
+ Curl_persistconninfo(data, cf->conn, &ctx->ip);
|
|
|
break;
|
|
|
case CF_CTRL_FORGET_SOCKET:
|
|
|
ctx->sock = CURL_SOCKET_BAD;
|
|
@@ -1640,7 +1632,7 @@ static CURLcode cf_udp_setup_quic(struct Curl_cfilter *cf,
|
|
|
#else
|
|
|
rc = connect(ctx->sock, &ctx->addr.sa_addr, ctx->addr.addrlen);
|
|
|
if(-1 == rc) {
|
|
|
- return socket_connect_result(data, ctx->r_ip, SOCKERRNO);
|
|
|
+ return socket_connect_result(data, ctx->ip.remote_ip, SOCKERRNO);
|
|
|
}
|
|
|
ctx->sock_connected = TRUE;
|
|
|
#endif
|
|
@@ -1648,7 +1640,8 @@ static CURLcode cf_udp_setup_quic(struct Curl_cfilter *cf,
|
|
|
CURL_TRC_CF(data, cf, "%s socket %" CURL_FORMAT_SOCKET_T
|
|
|
" connected: [%s:%d] -> [%s:%d]",
|
|
|
(ctx->transport == TRNSPRT_QUIC)? "QUIC" : "UDP",
|
|
|
- ctx->sock, ctx->l_ip, ctx->l_port, ctx->r_ip, ctx->r_port);
|
|
|
+ ctx->sock, ctx->ip.local_ip, ctx->ip.local_port,
|
|
|
+ ctx->ip.remote_ip, ctx->ip.remote_port);
|
|
|
|
|
|
(void)curlx_nonblock(ctx->sock, TRUE);
|
|
|
switch(ctx->addr.family) {
|
|
@@ -1698,7 +1691,7 @@ static CURLcode cf_udp_connect(struct Curl_cfilter *cf,
|
|
|
goto out;
|
|
|
CURL_TRC_CF(data, cf, "cf_udp_connect(), opened socket=%"
|
|
|
CURL_FORMAT_SOCKET_T " (%s:%d)",
|
|
|
- ctx->sock, ctx->l_ip, ctx->l_port);
|
|
|
+ ctx->sock, ctx->ip.local_ip, ctx->ip.local_port);
|
|
|
}
|
|
|
else {
|
|
|
CURL_TRC_CF(data, cf, "cf_udp_connect(), opened socket=%"
|
|
@@ -1894,8 +1887,8 @@ static void set_accepted_remote_ip(struct Curl_cfilter *cf,
|
|
|
struct Curl_sockaddr_storage ssrem;
|
|
|
curl_socklen_t plen;
|
|
|
|
|
|
- ctx->r_ip[0] = 0;
|
|
|
- ctx->r_port = 0;
|
|
|
+ ctx->ip.remote_ip[0] = 0;
|
|
|
+ ctx->ip.remote_port = 0;
|
|
|
plen = sizeof(ssrem);
|
|
|
memset(&ssrem, 0, plen);
|
|
|
if(getpeername(ctx->sock, (struct sockaddr*) &ssrem, &plen)) {
|
|
@@ -1905,14 +1898,14 @@ static void set_accepted_remote_ip(struct Curl_cfilter *cf,
|
|
|
return;
|
|
|
}
|
|
|
if(!Curl_addr2string((struct sockaddr*)&ssrem, plen,
|
|
|
- ctx->r_ip, &ctx->r_port)) {
|
|
|
+ ctx->ip.remote_ip, &ctx->ip.remote_port)) {
|
|
|
failf(data, "ssrem inet_ntop() failed with errno %d: %s",
|
|
|
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
|
|
return;
|
|
|
}
|
|
|
#else
|
|
|
- ctx->r_ip[0] = 0;
|
|
|
- ctx->r_port = 0;
|
|
|
+ ctx->ip.remote_ip[0] = 0;
|
|
|
+ ctx->ip.remote_port = 0;
|
|
|
(void)data;
|
|
|
#endif
|
|
|
}
|
|
@@ -1941,7 +1934,7 @@ CURLcode Curl_conn_tcp_accepted_set(struct Curl_easy *data,
|
|
|
cf->connected = TRUE;
|
|
|
CURL_TRC_CF(data, cf, "accepted_set(sock=%" CURL_FORMAT_SOCKET_T
|
|
|
", remote=%s port=%d)",
|
|
|
- ctx->sock, ctx->r_ip, ctx->r_port);
|
|
|
+ ctx->sock, ctx->ip.remote_ip, ctx->ip.remote_port);
|
|
|
|
|
|
return CURLE_OK;
|
|
|
}
|
|
@@ -1961,9 +1954,9 @@ CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,
|
|
|
struct Curl_easy *data,
|
|
|
curl_socket_t *psock,
|
|
|
const struct Curl_sockaddr_ex **paddr,
|
|
|
- const char **pr_ip_str, int *pr_port,
|
|
|
- const char **pl_ip_str, int *pl_port)
|
|
|
+ struct ip_quadruple *pip)
|
|
|
{
|
|
|
+ (void)data;
|
|
|
if(cf_is_socket(cf) && cf->ctx) {
|
|
|
struct cf_socket_ctx *ctx = cf->ctx;
|
|
|
|
|
@@ -1971,17 +1964,8 @@ CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,
|
|
|
*psock = ctx->sock;
|
|
|
if(paddr)
|
|
|
*paddr = &ctx->addr;
|
|
|
- if(pr_ip_str)
|
|
|
- *pr_ip_str = ctx->r_ip;
|
|
|
- if(pr_port)
|
|
|
- *pr_port = ctx->r_port;
|
|
|
- if(pl_port ||pl_ip_str) {
|
|
|
- set_local_ip(cf, data);
|
|
|
- if(pl_ip_str)
|
|
|
- *pl_ip_str = ctx->l_ip;
|
|
|
- if(pl_port)
|
|
|
- *pl_port = ctx->l_port;
|
|
|
- }
|
|
|
+ if(pip)
|
|
|
+ *pip = ctx->ip;
|
|
|
return CURLE_OK;
|
|
|
}
|
|
|
return CURLE_FAILED_INIT;
|