connect: set socktype/protocol correctly

So that an address used from the DNS cache that was previously used for
QUIC can be reused for TCP and vice versa.

To make this possible, set conn->transport to "unix" for unix domain
connections ... and store the transport struct field in an unsigned char
to use less space.

Reported-by: ウさん
Fixes #9274
Closes #9276
This commit is contained in:
Daniel Stenberg 2022-08-08 12:36:41 +02:00
parent a041ed8cde
commit 0f23341953
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 21 additions and 9 deletions

View File

@ -1604,9 +1604,20 @@ CURLcode Curl_socket(struct Curl_easy *data,
*/
addr->family = ai->ai_family;
addr->socktype = (conn->transport == TRNSPRT_TCP) ? SOCK_STREAM : SOCK_DGRAM;
addr->protocol = conn->transport != TRNSPRT_TCP ? IPPROTO_UDP :
ai->ai_protocol;
switch(conn->transport) {
case TRNSPRT_TCP:
addr->socktype = SOCK_STREAM;
addr->protocol = IPPROTO_TCP;
break;
case TRNSPRT_UNIX:
addr->socktype = SOCK_STREAM;
addr->protocol = IPPROTO_IP;
break;
default: /* UDP and QUIC */
addr->socktype = SOCK_DGRAM;
addr->protocol = IPPROTO_UDP;
break;
}
addr->addrlen = ai->ai_addrlen;
if(addr->addrlen > sizeof(struct Curl_sockaddr_storage))

View File

@ -3477,6 +3477,7 @@ static CURLcode resolve_server(struct Curl_easy *data,
free(hostaddr);
hostaddr = NULL;
}
conn->transport = TRNSPRT_UNIX;
}
}
else

View File

@ -879,6 +879,11 @@ struct connstate {
unsigned char *outp; /* send from this pointer */
};
#define TRNSPRT_TCP 3
#define TRNSPRT_UDP 4
#define TRNSPRT_QUIC 5
#define TRNSPRT_UNIX 6
/*
* The connectdata struct contains all fields and variables that should be
* unique for an entire connection.
@ -919,12 +924,7 @@ struct connectdata {
#ifdef ENABLE_IPV6
unsigned int scope_id; /* Scope id for IPv6 */
#endif
enum {
TRNSPRT_TCP = 3,
TRNSPRT_UDP = 4,
TRNSPRT_QUIC = 5
} transport;
unsigned char transport; /* one of the TRNSPRT_* defines */
#ifdef ENABLE_QUIC
struct quicsocket hequic[2]; /* two, for happy eyeballs! */