aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_config.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-11-12 11:22:02 -0500
committerDavid Goulet <dgoulet@torproject.org>2020-11-13 08:38:22 -0500
commitd425dbf04a6bbac7eae832bf51c2bfe061e2c426 (patch)
tree3f598f329955ff14d40e9dcb7d11ee39997d2e05 /src/test/test_config.c
parent46ccde66a97d7985388eb54bc74a025402fb0a19 (diff)
downloadtor-d425dbf04a6bbac7eae832bf51c2bfe061e2c426.tar.gz
tor-d425dbf04a6bbac7eae832bf51c2bfe061e2c426.zip
port: Don't ignore ports of a different family
Commit c3a0f757964de0e8a24911d72abff5df20bb323c added this feature for ORPort that we ignore any port that is not the family of our default address when parsing the port. So if port_parse_config() was called with an IPv4 default address, all IPv6 address would be ignored. That makes sense for ORPort since we call twice port_parse_config() for 0.0.0.0 and [::] but for the rest of the ports, it is not good since a perfectly valid configuration can be: SocksPort 9050 SocksPort [::1]:9050 Any non-ORPort only binds by default to an IPv4 except the ORPort that binds to both IPv4 and IPv6 by default. The fix here is to always parse all ports within port_parse_config() and then, specifically for ORPort, remove the duplicates or superseding ones. The warning is only emitted when a port supersedes another. A unit tests is added to make sure SocksPort of different family always exists together. Fixes #40183 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_config.c')
-rw-r--r--src/test/test_config.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c
index a0278f9422..d680ab31ef 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -6855,9 +6855,15 @@ test_config_duplicate_orports(void *arg)
port_parse_config(ports, config_port, "OR", CONN_TYPE_OR_LISTENER, "[::]",
0, CL_PORT_SERVER_OPTIONS);
- // There should be three ports at this point.
- tt_int_op(smartlist_len(ports), OP_EQ, 3);
+ /* There should be 4 ports at this point that is:
+ * - 0.0.0.0:9050
+ * - [::]:9050
+ * - [::1]:9050
+ * - [::1]:9050
+ */
+ tt_int_op(smartlist_len(ports), OP_EQ, 4);
+ /* This will remove the [::] and the extra [::1]. */
remove_duplicate_orports(ports);
// The explicit IPv6 port should have replaced the implicit IPv6 port.
@@ -6869,6 +6875,33 @@ test_config_duplicate_orports(void *arg)
config_free_lines(config_port);
}
+static void
+test_config_multifamily_port(void *arg)
+{
+ (void) arg;
+
+ config_line_t *config_port = NULL;
+ smartlist_t *ports = smartlist_new();
+
+ config_line_append(&config_port, "SocksPort", "9050");
+ config_line_append(&config_port, "SocksPort", "[::1]:9050");
+
+ // Parse IPv4, then IPv6.
+ port_parse_config(ports, config_port, "SOCKS", CONN_TYPE_AP_LISTENER,
+ "0.0.0.0", 9050, 0);
+
+ /* There should be 2 ports at this point that is:
+ * - 0.0.0.0:9050
+ * - [::1]:9050
+ */
+ tt_int_op(smartlist_len(ports), OP_EQ, 2);
+
+ done:
+ SMARTLIST_FOREACH(ports, port_cfg_t *, cfg, port_cfg_free(cfg));
+ smartlist_free(ports);
+ config_free_lines(config_port);
+}
+
#ifndef COCCI
#define CONFIG_TEST(name, flags) \
{ #name, test_config_ ## name, flags, NULL, NULL }
@@ -6937,5 +6970,6 @@ struct testcase_t config_tests[] = {
CONFIG_TEST(kvline_parse, 0),
CONFIG_TEST(getinfo_config_names, 0),
CONFIG_TEST(duplicate_orports, 0),
+ CONFIG_TEST(multifamily_port, 0),
END_OF_TESTCASES
};