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:
Daniel Stenberg 2021-01-26 14:14:06 +01:00
Родитель 764c6bd3bf
Коммит d6a37c23a3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5CC908FDB71E12C2
5 изменённых файлов: 34 добавлений и 21 удалений

Просмотреть файл

@ -610,14 +610,18 @@ static CURLcode trynextip(struct Curl_easy *data,
/* Copies connection info into the transfer handle to make it available when /* Copies connection info into the transfer handle to make it available when
the transfer handle is no longer associated with the connection. */ 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_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_scheme = conn->handler->scheme;
data->info.conn_protocol = conn->handler->protocol; data->info.conn_protocol = conn->handler->protocol;
data->info.conn_primary_port = conn->port; 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. /* 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 /* retrieves the start/end point information of a socket of an established
connection */ connection */
void Curl_conninfo_local(struct Curl_easy *data, struct connectdata *conn, void Curl_conninfo_local(struct Curl_easy *data, curl_socket_t sockfd,
curl_socket_t sockfd) char *local_ip, long *local_port)
{ {
#ifdef HAVE_GETSOCKNAME #ifdef HAVE_GETSOCKNAME
char buffer[STRERROR_LEN]; char buffer[STRERROR_LEN];
@ -726,7 +730,7 @@ void Curl_conninfo_local(struct Curl_easy *data, struct connectdata *conn,
return; return;
} }
if(!Curl_addr2string((struct sockaddr*)&ssloc, slen, 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", failf(data, "ssloc inet_ntop() failed with errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer))); errno, Curl_strerror(errno, buffer, sizeof(buffer)));
return; 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, void Curl_updateconninfo(struct Curl_easy *data, struct connectdata *conn,
curl_socket_t sockfd) 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->transport == TRNSPRT_TCP) {
if(!conn->bits.reuse && !conn->bits.tcp_fastopen) { if(!conn->bits.reuse && !conn->bits.tcp_fastopen) {
Curl_conninfo_remote(data, conn, sockfd); 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 */ } /* end of TCP-only section */
/* persist connection info in session handle */ /* 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 /* 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); curl_socket_t sockfd);
void Curl_conninfo_remote(struct Curl_easy *data, struct connectdata *conn, void Curl_conninfo_remote(struct Curl_easy *data, struct connectdata *conn,
curl_socket_t sockfd); curl_socket_t sockfd);
void Curl_conninfo_local(struct Curl_easy *data, struct connectdata *conn, void Curl_conninfo_local(struct Curl_easy *data, curl_socket_t sockfd,
curl_socket_t sockfd); char *local_ip, long *local_port);
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);
int Curl_closesocket(struct Curl_easy *data, struct connectdata *conn, int Curl_closesocket(struct Curl_easy *data, struct connectdata *conn,
curl_socket_t sock); curl_socket_t sock);

Просмотреть файл

@ -3366,6 +3366,11 @@ static void reuse_conn(struct Curl_easy *data,
struct connectdata *old_conn, struct connectdata *old_conn,
struct connectdata *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 #ifndef CURL_DISABLE_PROXY
Curl_free_idnconverted_hostname(&old_conn->http_proxy.host); Curl_free_idnconverted_hostname(&old_conn->http_proxy.host);
Curl_free_idnconverted_hostname(&old_conn->socks_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; old_conn->hostname_resolve = NULL;
/* persist connection info in session handle */ /* 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 */ 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 /* this is supposed to be the connect function so we better at least check
that the file is present here! */ that the file is present here! */
DEBUGASSERT(conn->handler->connect_it); DEBUGASSERT(conn->handler->connect_it);
Curl_persistconninfo(data, conn); Curl_persistconninfo(data, conn, NULL, -1);
result = conn->handler->connect_it(data, &done); result = conn->handler->connect_it(data, &done);
/* Setup a "faked" transfer that'll do nothing */ /* Setup a "faked" transfer that'll do nothing */

Просмотреть файл

@ -977,13 +977,6 @@ struct connectdata {
char primary_ip[MAX_IPADR_LEN]; 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 *user; /* user name string, allocated */
char *passwd; /* password string, allocated */ char *passwd; /* password string, allocated */
char *options; /* options 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))); SOCKERRNO, Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
return CURLE_BAD_FUNCTION_ARGUMENT; return CURLE_BAD_FUNCTION_ARGUMENT;
} }
Curl_persistconninfo(data, conn); Curl_persistconninfo(data, conn, NULL, -1);
/* for connection reuse purposes: */ /* for connection reuse purposes: */
conn->ssl[FIRSTSOCKET].state = ssl_connection_complete; conn->ssl[FIRSTSOCKET].state = ssl_connection_complete;