commit 8f085841ef40f00bbc2bb146a2d555aba527738f Author: Alexander Færøy ahf@torproject.org Date: Fri Sep 14 21:37:36 2018 +0200
Encode the 32-bit Global Identifier as 2 x 16-bit in the IPv6 address.
Without this patch we would encode the IPv6 address' last part as ::ffffffff instead of ::ffff:ffff when the GID is UINT32_MAX.
See: https://bugs.torproject.org/4700 --- src/core/or/connection_edge.c | 6 ++++-- src/test/test_hs_service.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c index 891e92217..62d12f498 100644 --- a/src/core/or/connection_edge.c +++ b/src/core/or/connection_edge.c @@ -623,8 +623,10 @@ export_hs_client_circuit_id_haproxy(const edge_connection_t *edge_conn, }
/* Build the string */ - tor_asprintf(&buf, "PROXY TCP6 %s:%x %s %d %d\r\n", - src_ipv6_prefix, gid, dst_ipv6, src_port, dst_port); + tor_asprintf(&buf, "PROXY TCP6 %s:%x:%x %s %d %d\r\n", + src_ipv6_prefix, + gid >> 16, gid & 0x0000ffff, + dst_ipv6, src_port, dst_port);
connection_buf_add(buf, strlen(buf), conn);
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index 0a1c866d6..2b8d6e597 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -2061,6 +2061,32 @@ test_export_client_circuit_id(void *arg) export_hs_client_circuit_id_haproxy(edge_conn, conn); cp2 = buf_get_contents(conn->outbuf, &sz); tt_str_op(cp1, OP_NE, cp2); + tor_free(cp1); + + /* Check that GID with UINT32_MAX works. */ + or_circ->global_identifier = UINT32_MAX; + + export_hs_client_circuit_id_haproxy(edge_conn, conn); + cp1 = buf_get_contents(conn->outbuf, &sz); + tt_str_op(cp1, OP_EQ, + "PROXY TCP6 fc00:dead:beef:4dad::ffff:ffff ::1 65535 42\r\n"); + tor_free(cp1); + + /* Check that GID with UINT16_MAX works. */ + or_circ->global_identifier = UINT16_MAX; + + export_hs_client_circuit_id_haproxy(edge_conn, conn); + cp1 = buf_get_contents(conn->outbuf, &sz); + tt_str_op(cp1, OP_EQ, + "PROXY TCP6 fc00:dead:beef:4dad::0:ffff ::1 65535 42\r\n"); + tor_free(cp1); + + /* Check that GID with UINT16_MAX + 7 works. */ + or_circ->global_identifier = UINT16_MAX + 7; + + export_hs_client_circuit_id_haproxy(edge_conn, conn); + cp1 = buf_get_contents(conn->outbuf, &sz); + tt_str_op(cp1, OP_EQ, "PROXY TCP6 fc00:dead:beef:4dad::1:6 ::1 6 42\r\n");
done: UNMOCK(connection_write_to_buf_impl_);
tor-commits@lists.torproject.org