diff options
author | Mahrud Sayrafi <mahrud@cloudflare.com> | 2018-07-30 16:10:23 -0700 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2018-09-12 15:20:26 +0300 |
commit | be142194cd447a5e31836128c9166f8a592a1649 (patch) | |
tree | f8e128dfd944f78d41059c96befad013486e6bea /src | |
parent | 0dbd4fe30961bb56539d3e2853244bd2e19f19b8 (diff) | |
download | tor-be142194cd447a5e31836128c9166f8a592a1649.tar.gz tor-be142194cd447a5e31836128c9166f8a592a1649.zip |
Encode Circuit ID as src IP in Proxy Protocol for Opportunistic Onions
Diffstat (limited to 'src')
-rw-r--r-- | src/core/or/connection_edge.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c index ab3c14d2c3..a85419376f 100644 --- a/src/core/or/connection_edge.c +++ b/src/core/or/connection_edge.c @@ -617,6 +617,29 @@ connection_edge_finished_connecting(edge_connection_t *edge_conn) rep_hist_note_exit_stream_opened(conn->port); conn->state = EXIT_CONN_STATE_OPEN; + + /* Include Proxy Protocol header. */ + char buf[512]; + char dst_ipv6[39] = "::1"; + /* See RFC4193 regarding fc00::/7 */ + char src_ipv6_prefix[34] = "fc00:dead:beef:4dad:"; + /* TODO: retain virtual port and use as destination port */ + uint16_t dst_port = 443; + uint16_t src_port = 0; + uint32_t gid = 0; + + if (edge_conn->on_circuit != NULL) { + gid = TO_ORIGIN_CIRCUIT(edge_conn->on_circuit)->global_identifier; + src_port = gid & 0x0000ffff; + } + + gid = (gid == 0) ? 1 : gid; + src_port = (src_port == 0) ? 1 : src_port; + + tor_snprintf(buf, sizeof(buf), "PROXY TCP6 %s:%x %s %d %d\r\n", + src_ipv6_prefix, gid, dst_ipv6, src_port, dst_port); + connection_buf_add(buf, strlen(buf), conn); + connection_watch_events(conn, READ_EVENT); /* stop writing, keep reading */ if (connection_get_outbuf_len(conn)) /* in case there are any queued relay * cells */ |