mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
addr: Refactor is_local_addr() to support IPv6
Series of changes:
1. Rename function to reflect the namespace of the file.
2. Use the new last resolved cache instead of the unused
last_resolved_addr_v4 (which is also removed in this commit).
3. Make the entire code base use the new resolved_addr_is_local() function.
You will notice that this function uses /24 to differentiate subnets where the
rest of tor uses /16 (including documentation of EnforceDistinctSubnets).
Ticket #40009 has been opened for that.
But that the moment, the function keeps looking at /24.
Part of #33233
Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
+16
-16
@@ -38,13 +38,13 @@ static or_connection_t * tlschan_connection_or_connect_mock(
|
||||
const char *digest,
|
||||
const ed25519_public_key_t *ed_id,
|
||||
channel_tls_t *tlschan);
|
||||
static int tlschan_is_local_addr_mock(const tor_addr_t *addr);
|
||||
static bool tlschan_resolved_addr_is_local_mock(const tor_addr_t *addr);
|
||||
|
||||
/* Fake close method */
|
||||
static void tlschan_fake_close_method(channel_t *chan);
|
||||
|
||||
/* Flags controlling behavior of channeltls unit test mocks */
|
||||
static int tlschan_local = 0;
|
||||
static bool tlschan_local = false;
|
||||
static const buf_t * tlschan_buf_datalen_mock_target = NULL;
|
||||
static size_t tlschan_buf_datalen_mock_size = 0;
|
||||
|
||||
@@ -67,9 +67,9 @@ test_channeltls_create(void *arg)
|
||||
test_addr.addr.in_addr.s_addr = htonl(0x01020304);
|
||||
|
||||
/* For this test we always want the address to be treated as non-local */
|
||||
tlschan_local = 0;
|
||||
/* Install is_local_addr() mock */
|
||||
MOCK(is_local_addr, tlschan_is_local_addr_mock);
|
||||
tlschan_local = false;
|
||||
/* Install resolved_addr_is_local() mock */
|
||||
MOCK(resolved_addr_is_local, tlschan_resolved_addr_is_local_mock);
|
||||
|
||||
/* Install mock for connection_or_connect() */
|
||||
MOCK(connection_or_connect, tlschan_connection_or_connect_mock);
|
||||
@@ -92,7 +92,7 @@ test_channeltls_create(void *arg)
|
||||
}
|
||||
|
||||
UNMOCK(connection_or_connect);
|
||||
UNMOCK(is_local_addr);
|
||||
UNMOCK(resolved_addr_is_local);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -116,9 +116,9 @@ test_channeltls_num_bytes_queued(void *arg)
|
||||
test_addr.addr.in_addr.s_addr = htonl(0x01020304);
|
||||
|
||||
/* For this test we always want the address to be treated as non-local */
|
||||
tlschan_local = 0;
|
||||
/* Install is_local_addr() mock */
|
||||
MOCK(is_local_addr, tlschan_is_local_addr_mock);
|
||||
tlschan_local = false;
|
||||
/* Install resolved_addr_is_local() mock */
|
||||
MOCK(resolved_addr_is_local, tlschan_resolved_addr_is_local_mock);
|
||||
|
||||
/* Install mock for connection_or_connect() */
|
||||
MOCK(connection_or_connect, tlschan_connection_or_connect_mock);
|
||||
@@ -178,7 +178,7 @@ test_channeltls_num_bytes_queued(void *arg)
|
||||
}
|
||||
|
||||
UNMOCK(connection_or_connect);
|
||||
UNMOCK(is_local_addr);
|
||||
UNMOCK(resolved_addr_is_local);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -201,9 +201,9 @@ test_channeltls_overhead_estimate(void *arg)
|
||||
test_addr.addr.in_addr.s_addr = htonl(0x01020304);
|
||||
|
||||
/* For this test we always want the address to be treated as non-local */
|
||||
tlschan_local = 0;
|
||||
/* Install is_local_addr() mock */
|
||||
MOCK(is_local_addr, tlschan_is_local_addr_mock);
|
||||
tlschan_local = false;
|
||||
/* Install resolved_addr_is_local() mock */
|
||||
MOCK(resolved_addr_is_local, tlschan_resolved_addr_is_local_mock);
|
||||
|
||||
/* Install mock for connection_or_connect() */
|
||||
MOCK(connection_or_connect, tlschan_connection_or_connect_mock);
|
||||
@@ -252,7 +252,7 @@ test_channeltls_overhead_estimate(void *arg)
|
||||
}
|
||||
|
||||
UNMOCK(connection_or_connect);
|
||||
UNMOCK(is_local_addr);
|
||||
UNMOCK(resolved_addr_is_local);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -321,8 +321,8 @@ tlschan_fake_close_method(channel_t *chan)
|
||||
return;
|
||||
}
|
||||
|
||||
static int
|
||||
tlschan_is_local_addr_mock(const tor_addr_t *addr)
|
||||
static bool
|
||||
tlschan_resolved_addr_is_local_mock(const tor_addr_t *addr)
|
||||
{
|
||||
tt_ptr_op(addr, OP_NE, NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user