Improve export_hs_client_circuit_id() function.

- Change default values.
- Beautify.
- Documentation.
This commit is contained in:
George Kadianakis 2018-09-12 14:43:23 +03:00
parent 27d7491f5a
commit 5d34a8cbbb
2 changed files with 20 additions and 14 deletions

View File

@ -597,31 +597,34 @@ connected_cell_format_payload(uint8_t *payload_out,
return connected_payload_len;
}
/* DOCDOCDOC */
static void
send_ha_proxy_header(const edge_connection_t *edge_conn,
connection_t *conn)
/* This is an onion service client connection: Export the client circuit ID
* according to the HAProxy proxy protocol. */
STATIC void
export_hs_client_circuit_id_haproxy(const edge_connection_t *edge_conn,
connection_t *conn)
{
char buf[512];
char dst_ipv6[39] = "::1";
char *buf;
const char dst_ipv6[] = "::1";
/* See RFC4193 regarding fc00::/7 */
char src_ipv6_prefix[34] = "fc00:dead:beef:4dad:";
const char src_ipv6_prefix[] = "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;
uint16_t src_port = 1; /* default value */
uint32_t gid = 0; /* default value */
/* Generate a GID and source port for this client */
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;
/* 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_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);
tor_free(buf);
}
/** Connected handler for exit connections: start writing pending
@ -649,7 +652,7 @@ connection_edge_finished_connecting(edge_connection_t *edge_conn)
* protocol header */
if (edge_conn->hs_ident &&
hs_service_exports_circuit_id(&edge_conn->hs_ident->identity_pk)) {
send_ha_proxy_header(edge_conn, conn);
export_hs_client_circuit_id_haproxy(edge_conn, conn);
}
connection_watch_events(conn, READ_EVENT); /* stop writing, keep reading */

View File

@ -243,6 +243,9 @@ STATIC void connection_ap_handshake_rewrite(entry_connection_t *conn,
rewrite_result_t *out);
STATIC int connection_ap_process_http_connect(entry_connection_t *conn);
STATIC void
export_hs_client_circuit_id_haproxy(const edge_connection_t *edge_conn,
connection_t *conn);
#endif /* defined(CONNECTION_EDGE_PRIVATE) */
#endif /* !defined(TOR_CONNECTION_EDGE_H) */