[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Improve export_hs_client_circuit_id() function.
commit 5d34a8cbbb8ac4b6edd6800e10b5cb6dba1dcbcb
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date: Wed Sep 12 14:43:23 2018 +0300
Improve export_hs_client_circuit_id() function.
- Change default values.
- Beautify.
- Documentation.
---
src/core/or/connection_edge.c | 31 +++++++++++++++++--------------
src/core/or/connection_edge.h | 3 +++
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
index 8b333a6f4..9af03f7f2 100644
--- a/src/core/or/connection_edge.c
+++ b/src/core/or/connection_edge.c
@@ -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 */
diff --git a/src/core/or/connection_edge.h b/src/core/or/connection_edge.h
index 24968b277..adec4998e 100644
--- a/src/core/or/connection_edge.h
+++ b/src/core/or/connection_edge.h
@@ -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) */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits