urldata: remove 'local_ip' from the connectdata struct
As the info is already stored in the transfer handle anyway, there's no need to carry around a duplicate buffer for the life-time of the handle. Closes #6534
This commit is contained in:
Родитель
764c6bd3bf
Коммит
d6a37c23a3
|
@ -610,14 +610,18 @@ static CURLcode trynextip(struct Curl_easy *data,
|
|||
|
||||
/* Copies connection info into the transfer handle to make it available when
|
||||
the transfer handle is no longer associated with the connection. */
|
||||
void Curl_persistconninfo(struct Curl_easy *data, struct connectdata *conn)
|
||||
void Curl_persistconninfo(struct Curl_easy *data, struct connectdata *conn,
|
||||
char *local_ip, long local_port)
|
||||
{
|
||||
memcpy(data->info.conn_primary_ip, conn->primary_ip, MAX_IPADR_LEN);
|
||||
memcpy(data->info.conn_local_ip, conn->local_ip, MAX_IPADR_LEN);
|
||||
if(local_ip && local_ip[0])
|
||||
memcpy(data->info.conn_local_ip, local_ip, MAX_IPADR_LEN);
|
||||
else
|
||||
data->info.conn_local_ip[0] = 0;
|
||||
data->info.conn_scheme = conn->handler->scheme;
|
||||
data->info.conn_protocol = conn->handler->protocol;
|
||||
data->info.conn_primary_port = conn->port;
|
||||
data->info.conn_local_port = conn->local_port;
|
||||
data->info.conn_local_port = local_port;
|
||||
}
|
||||
|
||||
/* retrieves ip address and port from a sockaddr structure.
|
||||
|
@ -710,8 +714,8 @@ void Curl_conninfo_remote(struct Curl_easy *data,
|
|||
|
||||
/* retrieves the start/end point information of a socket of an established
|
||||
connection */
|
||||
void Curl_conninfo_local(struct Curl_easy *data, struct connectdata *conn,
|
||||
curl_socket_t sockfd)
|
||||
void Curl_conninfo_local(struct Curl_easy *data, curl_socket_t sockfd,
|
||||
char *local_ip, long *local_port)
|
||||
{
|
||||
#ifdef HAVE_GETSOCKNAME
|
||||
char buffer[STRERROR_LEN];
|
||||
|
@ -726,7 +730,7 @@ void Curl_conninfo_local(struct Curl_easy *data, struct connectdata *conn,
|
|||
return;
|
||||
}
|
||||
if(!Curl_addr2string((struct sockaddr*)&ssloc, slen,
|
||||
conn->local_ip, &conn->local_port)) {
|
||||
local_ip, local_port)) {
|
||||
failf(data, "ssloc inet_ntop() failed with errno %d: %s",
|
||||
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
|
||||
return;
|
||||
|
@ -743,15 +747,21 @@ void Curl_conninfo_local(struct Curl_easy *data, struct connectdata *conn,
|
|||
void Curl_updateconninfo(struct Curl_easy *data, struct connectdata *conn,
|
||||
curl_socket_t sockfd)
|
||||
{
|
||||
/* 'local_ip' and 'local_port' get filled with local's numerical
|
||||
ip address and port number whenever an outgoing connection is
|
||||
**established** from the primary socket to a remote address. */
|
||||
char local_ip[MAX_IPADR_LEN] = "";
|
||||
long local_port = -1;
|
||||
|
||||
if(conn->transport == TRNSPRT_TCP) {
|
||||
if(!conn->bits.reuse && !conn->bits.tcp_fastopen) {
|
||||
Curl_conninfo_remote(data, conn, sockfd);
|
||||
Curl_conninfo_local(data, conn, sockfd);
|
||||
Curl_conninfo_local(data, sockfd, local_ip, &local_port);
|
||||
}
|
||||
} /* end of TCP-only section */
|
||||
|
||||
/* persist connection info in session handle */
|
||||
Curl_persistconninfo(data, conn);
|
||||
Curl_persistconninfo(data, conn, local_ip, local_port);
|
||||
}
|
||||
|
||||
/* After a TCP connection to the proxy has been verified, this function does
|
||||
|
|
|
@ -80,9 +80,10 @@ void Curl_updateconninfo(struct Curl_easy *data, struct connectdata *conn,
|
|||
curl_socket_t sockfd);
|
||||
void Curl_conninfo_remote(struct Curl_easy *data, struct connectdata *conn,
|
||||
curl_socket_t sockfd);
|
||||
void Curl_conninfo_local(struct Curl_easy *data, struct connectdata *conn,
|
||||
curl_socket_t sockfd);
|
||||
void Curl_persistconninfo(struct Curl_easy *data, struct connectdata *conn);
|
||||
void Curl_conninfo_local(struct Curl_easy *data, curl_socket_t sockfd,
|
||||
char *local_ip, long *local_port);
|
||||
void Curl_persistconninfo(struct Curl_easy *data, struct connectdata *conn,
|
||||
char *local_ip, long local_port);
|
||||
int Curl_closesocket(struct Curl_easy *data, struct connectdata *conn,
|
||||
curl_socket_t sock);
|
||||
|
||||
|
|
13
lib/url.c
13
lib/url.c
|
@ -3366,6 +3366,11 @@ static void reuse_conn(struct Curl_easy *data,
|
|||
struct connectdata *old_conn,
|
||||
struct connectdata *conn)
|
||||
{
|
||||
/* 'local_ip' and 'local_port' get filled with local's numerical
|
||||
ip address and port number whenever an outgoing connection is
|
||||
**established** from the primary socket to a remote address. */
|
||||
char local_ip[MAX_IPADR_LEN] = "";
|
||||
long local_port = -1;
|
||||
#ifndef CURL_DISABLE_PROXY
|
||||
Curl_free_idnconverted_hostname(&old_conn->http_proxy.host);
|
||||
Curl_free_idnconverted_hostname(&old_conn->socks_proxy.host);
|
||||
|
@ -3432,7 +3437,11 @@ static void reuse_conn(struct Curl_easy *data,
|
|||
old_conn->hostname_resolve = NULL;
|
||||
|
||||
/* persist connection info in session handle */
|
||||
Curl_persistconninfo(data, conn);
|
||||
if(conn->transport == TRNSPRT_TCP) {
|
||||
Curl_conninfo_local(data, conn->sock[FIRSTSOCKET],
|
||||
local_ip, &local_port);
|
||||
}
|
||||
Curl_persistconninfo(data, conn, local_ip, local_port);
|
||||
|
||||
conn_reset_all_postponed_data(old_conn); /* free buffers */
|
||||
|
||||
|
@ -3646,7 +3655,7 @@ static CURLcode create_conn(struct Curl_easy *data,
|
|||
/* this is supposed to be the connect function so we better at least check
|
||||
that the file is present here! */
|
||||
DEBUGASSERT(conn->handler->connect_it);
|
||||
Curl_persistconninfo(data, conn);
|
||||
Curl_persistconninfo(data, conn, NULL, -1);
|
||||
result = conn->handler->connect_it(data, &done);
|
||||
|
||||
/* Setup a "faked" transfer that'll do nothing */
|
||||
|
|
|
@ -977,13 +977,6 @@ struct connectdata {
|
|||
|
||||
char primary_ip[MAX_IPADR_LEN];
|
||||
|
||||
/* 'local_ip' and 'local_port' get filled with local's numerical
|
||||
ip address and port number whenever an outgoing connection is
|
||||
**established** from the primary socket to a remote address. */
|
||||
|
||||
char local_ip[MAX_IPADR_LEN];
|
||||
long local_port;
|
||||
|
||||
char *user; /* user name string, allocated */
|
||||
char *passwd; /* password string, allocated */
|
||||
char *options; /* options string, allocated */
|
||||
|
|
|
@ -255,7 +255,7 @@ CURLcode Curl_quic_connect(struct Curl_easy *data,
|
|||
SOCKERRNO, Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
}
|
||||
Curl_persistconninfo(data, conn);
|
||||
Curl_persistconninfo(data, conn, NULL, -1);
|
||||
|
||||
/* for connection reuse purposes: */
|
||||
conn->ssl[FIRSTSOCKET].state = ssl_connection_complete;
|
||||
|
|
Загрузка…
Ссылка в новой задаче