ip_quadruple/proxy: make port uint16_t

Make `port` member in these struct of type `uint16_t`.

add `uint8_t transport` to `struct ip_quadruple

Define TRNSPRT_NONE as 0. By assigning a valid transport only on a
successful connection, it is clear when the ip_quadruple members are
valid. Also, for transports not involving ports, the getinfos for
`CURLINFO_PRIMARY_PORT` and `CURLINFO_LOCAL_PORT` will now always return
-1.

Make all `transport` members and parameters of type `uint8_t`.

Document the return value of `CURLINFO_LOCAL_PORT` and
`CURLINFO_PRIMARY_PORT` in this regard. Add tests that writeout stats
report ports correctly.

Closes #19708
This commit is contained in:
Stefan Eissing 2025-11-26 14:05:46 +01:00 committed by Daniel Stenberg
parent feea968512
commit c4f29cc508
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
20 changed files with 104 additions and 80 deletions

View file

@ -96,6 +96,9 @@ class TestBasic:
# there are cases where time_connect is reported as 0
assert r.stats[0]['time_connect'] >= 0, f'{r.stats[0]}'
assert r.stats[0]['time_appconnect'] > 0, f'{r.stats[0]}'
# ports are reported correctly
assert r.stats[0]['remote_port'] == env.port_for(proto), f'{r.dump_logs()}'
assert r.stats[0]['local_port'] > 0, f'{r.dump_logs()}'
# simple https: HEAD
@pytest.mark.parametrize("proto", Env.http_protos())

View file

@ -109,6 +109,8 @@ class TestUnix:
'--unix-socket', uds_faker.path,
])
r.check_response(count=1, http_status=200)
assert r.stats[0]['remote_port'] == -1, f'{r.dump_logs()}'
assert r.stats[0]['local_port'] == -1, f'{r.dump_logs()}'
# download https: via Unix socket
@pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
@ -120,6 +122,8 @@ class TestUnix:
'--unix-socket', uds_faker.path,
])
r.check_response(exitcode=35, http_status=None)
assert r.stats[0]['remote_port'] == -1, f'{r.dump_logs()}'
assert r.stats[0]['local_port'] == -1, f'{r.dump_logs()}'
# download HTTP/3 via Unix socket
@pytest.mark.skipif(condition=not Env.have_h3(), reason='h3 not supported')
@ -132,3 +136,5 @@ class TestUnix:
'--unix-socket', uds_faker.path,
])
r.check_response(exitcode=96, http_status=None)
assert r.stats[0]['remote_port'] == -1, f'{r.dump_logs()}'
assert r.stats[0]['local_port'] == -1, f'{r.dump_logs()}'

View file

@ -141,7 +141,7 @@ static CURLcode test_unit1607(const char *arg)
addr = dns ? dns->addr : NULL;
for(j = 0; j < addressnum; ++j) {
int port = 0;
uint16_t port = 0;
char ipaddress[MAX_IPADR_LEN] = {0};
if(!addr && !tests[i].address[j])

View file

@ -143,7 +143,7 @@ static CURLcode test_unit1609(const char *arg)
addr = dns ? dns->addr : NULL;
for(j = 0; j < addressnum; ++j) {
int port = 0;
uint16_t port = 0;
char ipaddress[MAX_IPADR_LEN] = {0};
if(!addr && !tests[i].address[j])

View file

@ -110,7 +110,7 @@ static int test_idx;
struct cf_test_ctx {
int idx;
int ai_family;
int transport;
uint8_t transport;
char id[16];
struct curltime started;
timediff_t fail_delay_ms;
@ -166,7 +166,7 @@ static CURLcode cf_test_create(struct Curl_cfilter **pcf,
struct Curl_easy *data,
struct connectdata *conn,
const struct Curl_addrinfo *ai,
int transport)
uint8_t transport)
{
static const struct Curl_cftype cft_test = {
"TEST",