summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2021-01-19 12:24:19 -0500
committerDavid Goulet <dgoulet@torproject.org>2021-01-19 13:07:49 -0500
commit938623004b025c5c85745703d817e33a5308da5a (patch)
treec5acad1c14b8182a23f798e8dfa30ab3141fe017 /src/test
parente3a5482681f9c4625df1e418b42038cded3cb082 (diff)
downloadtor-938623004b025c5c85745703d817e33a5308da5a.tar.gz
tor-938623004b025c5c85745703d817e33a5308da5a.zip
relay: Keep all ORPorts that are on different ports
We used to actually discard ORPorts that were the same port and same family but they could have different address. Instead, we need to keep all different ORPorts so we can bind a listener on each of them. We will publish only one of these in our descriptor though. Related to #40246 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_config.c89
1 files changed, 88 insertions, 1 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 49d7b87410..4eb4ac9cf5 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -6868,8 +6868,95 @@ test_config_duplicate_orports(void *arg)
/* This will remove the [::] and the extra [::1]. */
remove_duplicate_orports(ports);
- // The explicit IPv6 port should have replaced the implicit IPv6 port.
tt_int_op(smartlist_len(ports), OP_EQ, 2);
+ tt_str_op(describe_relay_port(smartlist_get(ports, 0)), OP_EQ,
+ "ORPort 9050");
+ tt_str_op(describe_relay_port(smartlist_get(ports, 1)), OP_EQ,
+ "ORPort [::1]:9050");
+
+ /* Reset. Test different ORPort value. */
+ SMARTLIST_FOREACH(ports, port_cfg_t *, p, port_cfg_free(p));
+ smartlist_free(ports);
+ config_free_lines(config_port);
+ config_port = NULL;
+ ports = smartlist_new();
+
+ /* Implicit port and then specific IPv6 addresses but more than one. */
+ config_line_append(&config_port, "ORPort", "9050"); // two implicit entries.
+ config_line_append(&config_port, "ORPort", "[4242::1]:9051");
+ config_line_append(&config_port, "ORPort", "[4242::2]:9051");
+
+ // Parse IPv4, then IPv6.
+ port_parse_config(ports, config_port, "OR", CONN_TYPE_OR_LISTENER, "0.0.0.0",
+ 0, CL_PORT_SERVER_OPTIONS);
+ port_parse_config(ports, config_port, "OR", CONN_TYPE_OR_LISTENER, "[::]",
+ 0, CL_PORT_SERVER_OPTIONS);
+
+ /* There should be 6 ports at this point that is:
+ * - 0.0.0.0:9050
+ * - [::]:9050
+ * - [4242::1]:9051
+ * - [4242::1]:9051
+ * - [4242::2]:9051
+ * - [4242::2]:9051
+ */
+ tt_int_op(smartlist_len(ports), OP_EQ, 6);
+
+ /* This will remove the [::] and the duplicates. */
+ remove_duplicate_orports(ports);
+
+ /* We have four address here, 1 IPv4 on 9050, IPv6 on 9050, IPv6 on 9051 and
+ * a different IPv6 on 9051. */
+ tt_int_op(smartlist_len(ports), OP_EQ, 3);
+ tt_str_op(describe_relay_port(smartlist_get(ports, 0)), OP_EQ,
+ "ORPort 9050");
+ tt_str_op(describe_relay_port(smartlist_get(ports, 1)), OP_EQ,
+ "ORPort [4242::1]:9051");
+ tt_str_op(describe_relay_port(smartlist_get(ports, 2)), OP_EQ,
+ "ORPort 9050");
+
+ /* Reset. Test different ORPort value. */
+ SMARTLIST_FOREACH(ports, port_cfg_t *, p, port_cfg_free(p));
+ smartlist_free(ports);
+ config_free_lines(config_port);
+ config_port = NULL;
+ ports = smartlist_new();
+
+ /* Three different ports. */
+ config_line_append(&config_port, "ORPort", "9050"); // two implicit entries.
+ config_line_append(&config_port, "ORPort", "[4242::1]:9051");
+ config_line_append(&config_port, "ORPort", "[4242::2]:9052");
+
+ // Parse IPv4, then IPv6.
+ port_parse_config(ports, config_port, "OR", CONN_TYPE_OR_LISTENER, "0.0.0.0",
+ 0, CL_PORT_SERVER_OPTIONS);
+ port_parse_config(ports, config_port, "OR", CONN_TYPE_OR_LISTENER, "[::]",
+ 0, CL_PORT_SERVER_OPTIONS);
+
+ /* There should be 6 ports at this point that is:
+ * - 0.0.0.0:9050
+ * - [::]:9050
+ * - [4242::1]:9051
+ * - [4242::1]:9051
+ * - [4242::2]:9052
+ * - [4242::2]:9052
+ */
+ tt_int_op(smartlist_len(ports), OP_EQ, 6);
+
+ /* This will remove the [::] and the duplicates. */
+ remove_duplicate_orports(ports);
+
+ /* We have four address here, 1 IPv4 on 9050, IPv6 on 9050, IPv6 on 9051 and
+ * IPv6 on 9052. */
+ tt_int_op(smartlist_len(ports), OP_EQ, 4);
+ tt_str_op(describe_relay_port(smartlist_get(ports, 0)), OP_EQ,
+ "ORPort 9050");
+ tt_str_op(describe_relay_port(smartlist_get(ports, 1)), OP_EQ,
+ "ORPort [4242::1]:9051");
+ tt_str_op(describe_relay_port(smartlist_get(ports, 2)), OP_EQ,
+ "ORPort [4242::2]:9052");
+ tt_str_op(describe_relay_port(smartlist_get(ports, 3)), OP_EQ,
+ "ORPort 9050");
done:
SMARTLIST_FOREACH(ports,port_cfg_t *,pf,port_cfg_free(pf));