summaryrefslogtreecommitdiff
path: root/src/or/connection_edge.c
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2015-01-24 17:31:12 +0000
committerNick Mathewson <nickm@torproject.org>2015-01-28 14:30:23 -0500
commitca5ba2956bcd4b5ee1e526ccf5914f52fe6e6d51 (patch)
treea064fa582c6081c7a9e25a944b5cb85b7b3d3373 /src/or/connection_edge.c
parent6564291601540bf61c1ca3294b6c22f0c5021a20 (diff)
downloadtor-ca5ba2956bcd4b5ee1e526ccf5914f52fe6e6d51.tar.gz
tor-ca5ba2956bcd4b5ee1e526ccf5914f52fe6e6d51.zip
Support connection_exit_connect() to AF_UNIX sockets
Diffstat (limited to 'src/or/connection_edge.c')
-rw-r--r--src/or/connection_edge.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index f541249992..9690653d59 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -2940,7 +2940,7 @@ connection_exit_connect(edge_connection_t *edge_conn)
const tor_addr_t *addr;
uint16_t port;
connection_t *conn = TO_CONN(edge_conn);
- int socket_error = 0;
+ int socket_error = 0, result;
if ( (!connection_edge_is_rendezvous_stream(edge_conn) &&
router_compare_to_my_exit_policy(&edge_conn->base_.addr,
@@ -2955,14 +2955,36 @@ connection_exit_connect(edge_connection_t *edge_conn)
return;
}
- addr = &conn->addr;
- port = conn->port;
+#ifdef HAVE_SYS_UN_H
+ if (conn->socket_family != AF_UNIX) {
+#else
+ {
+#endif /* defined(HAVE_SYS_UN_H) */
+ addr = &conn->addr;
+ port = conn->port;
+
+ if (tor_addr_family(addr) == AF_INET6)
+ conn->socket_family = AF_INET6;
+
+ log_debug(LD_EXIT, "about to try connecting");
+ result = connection_connect(conn, conn->address,
+ addr, port, &socket_error);
+#ifdef HAVE_SYS_UN_H
+ } else {
+ /*
+ * In the AF_UNIX case, we expect to have already had conn->port = 1,
+ * tor_addr_make_unspec(conn->addr) (cf. the way we mark in the incoming
+ * case in connection_handle_listener_read()), and conn->address should
+ * have the socket path to connect to.
+ */
+ tor_assert(conn->address && strlen(conn->address) > 0);
- if (tor_addr_family(addr) == AF_INET6)
- conn->socket_family = AF_INET6;
+ log_debug(LD_EXIT, "about to try connecting");
+ result = connection_connect_unix(conn, conn->address, &socket_error);
+#endif /* defined(HAVE_SYS_UN_H) */
+ }
- log_debug(LD_EXIT,"about to try connecting");
- switch (connection_connect(conn, conn->address, addr, port, &socket_error)) {
+ switch (result) {
case -1: {
int reason = errno_to_stream_end_reason(socket_error);
connection_edge_end(edge_conn, reason);