diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-11-14 10:48:58 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-11-14 23:16:41 -0500 |
commit | 882b389668067a29bb539d0f5bd5cb2f83b93012 (patch) | |
tree | 867e692b6b15922a361633106e48aa46ebd9937d /src/test/test_cell_formats.c | |
parent | 6b36142bcc6f268a5312e197c4c3397065b3414e (diff) | |
download | tor-882b389668067a29bb539d0f5bd5cb2f83b93012.tar.gz tor-882b389668067a29bb539d0f5bd5cb2f83b93012.zip |
Actually send back correctly-formed IPv6 CONNECTED cells
We had some old code to send back connected cells for IPv6 addresses,
but it was wrong. Fortunately, it was also unreachable.
Diffstat (limited to 'src/test/test_cell_formats.c')
-rw-r--r-- | src/test/test_cell_formats.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/test/test_cell_formats.c b/src/test/test_cell_formats.c index 3fac74519f..4222c79d92 100644 --- a/src/test/test_cell_formats.c +++ b/src/test/test_cell_formats.c @@ -231,6 +231,7 @@ test_cfmt_connected_cells(void *arg) cell_t cell; tor_addr_t addr; int ttl, r; + char *mem_op_hex_tmp = NULL; (void)arg; /* Let's try an oldschool one with nothing in it. */ @@ -332,8 +333,45 @@ test_cfmt_connected_cells(void *arg) r = connected_cell_parse(&rh, &cell, &addr, &ttl); tt_int_op(r, ==, -1); + /* Now make sure we can generate connected cells correctly. */ + /* Try an IPv4 address */ + memset(&rh, 0, sizeof(rh)); + memset(&cell, 0, sizeof(cell)); + tor_addr_parse(&addr, "30.40.50.60"); + rh.length = connected_cell_format_payload(cell.payload+RELAY_HEADER_SIZE, + &addr, 128); + tt_int_op(rh.length, ==, 8); + test_memeq_hex(cell.payload+RELAY_HEADER_SIZE, "1e28323c" "00000080"); + + /* Try parsing it. */ + tor_addr_make_unspec(&addr); + r = connected_cell_parse(&rh, &cell, &addr, &ttl); + tt_int_op(r, ==, 0); + tt_int_op(tor_addr_family(&addr), ==, AF_INET); + tt_str_op(fmt_addr(&addr), ==, "30.40.50.60"); + tt_int_op(ttl, ==, 128); + + /* Try an IPv6 address */ + memset(&rh, 0, sizeof(rh)); + memset(&cell, 0, sizeof(cell)); + tor_addr_parse(&addr, "2620::6b0:b:1a1a:0:26e5:480e"); + rh.length = connected_cell_format_payload(cell.payload+RELAY_HEADER_SIZE, + &addr, 3600); + tt_int_op(rh.length, ==, 25); + test_memeq_hex(cell.payload + RELAY_HEADER_SIZE, + "00000000" "06" + "2620000006b0000b1a1a000026e5480e" "00000e10"); + + /* Try parsing it. */ + tor_addr_make_unspec(&addr); + r = connected_cell_parse(&rh, &cell, &addr, &ttl); + tt_int_op(r, ==, 0); + tt_int_op(tor_addr_family(&addr), ==, AF_INET6); + tt_str_op(fmt_addr(&addr), ==, "2620:0:6b0:b:1a1a:0:26e5:480e"); + tt_int_op(ttl, ==, 3600); + done: - ; + tor_free(mem_op_hex_tmp); } #define TEST(name, flags) \ |