aboutsummaryrefslogtreecommitdiff
path: root/src/or/ext_orport.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2013-02-11 20:45:17 +0100
committerNick Mathewson <nickm@torproject.org>2013-07-18 14:59:56 -0400
commit210210f219a1773530dd117d7a48d6edc3a5e714 (patch)
tree907d6f679fd4b1820ff4c690a7cb1525258eed03 /src/or/ext_orport.c
parent895709db07c75c9a3bf8f2ef4e507fd410495dff (diff)
downloadtor-210210f219a1773530dd117d7a48d6edc3a5e714.tar
tor-210210f219a1773530dd117d7a48d6edc3a5e714.tar.gz
Make the Extended ORPort understand the TRANSPORT command.
Diffstat (limited to 'src/or/ext_orport.c')
-rw-r--r--src/or/ext_orport.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/or/ext_orport.c b/src/or/ext_orport.c
index db95843c7..ff752f486 100644
--- a/src/or/ext_orport.c
+++ b/src/or/ext_orport.c
@@ -12,6 +12,7 @@
#include "ext_orport.h"
#include "control.h"
#include "config.h"
+#include "util.h"
#include "main.h"
/** Allocate and return a structure capable of holding an Extended
@@ -381,6 +382,7 @@ connection_ext_or_auth_process_inbuf(or_connection_t *or_conn)
/** Extended ORPort commands (Transport-to-Bridge) */
#define EXT_OR_CMD_TB_DONE 0x0000
#define EXT_OR_CMD_TB_USERADDR 0x0001
+#define EXT_OR_CMD_TB_TRANSPORT 0x0002
/** Extended ORPort commands (Bridge-to-Transport) */
#define EXT_OR_CMD_BT_OKAY 0x1000
@@ -395,8 +397,8 @@ connection_ext_or_auth_process_inbuf(or_connection_t *or_conn)
*
* Return 0 on success and -1 on error. */
static int
-connection_ext_or_handle_useraddr(connection_t *conn,
- const char *payload, uint16_t len)
+connection_ext_or_handle_cmd_useraddr(connection_t *conn,
+ const char *payload, uint16_t len)
{
/* Copy address string. */
tor_addr_t addr;
@@ -437,6 +439,32 @@ connection_ext_or_handle_useraddr(connection_t *conn,
return 0;
}
+/** Process a TRANSPORT command from the Extended
+ * ORPort. <b>payload</b> is a payload of size <b>len</b>.
+ *
+ * If the TRANSPORT command was well formed, register the name of the
+ * transport on <b>conn</b>.
+ *
+ * Return 0 on success and -1 on error. */
+static int
+connection_ext_or_handle_cmd_transport(or_connection_t *conn,
+ const char *payload, uint16_t len)
+{
+ char *transport_str = tor_malloc(len + 1); /* NUL-terminate the string */
+ memcpy(transport_str, payload, len);
+ transport_str[len] = 0;
+
+ /* Transport names MUST be C-identifiers. */
+ if (!string_is_C_identifier(transport_str)) {
+ tor_free(transport_str);
+ return -1;
+ }
+
+ conn->ext_or_transport = transport_str;
+ return 0;
+}
+
+
/** Process Extended ORPort messages from <b>or_conn</b>. */
int
connection_ext_or_process_inbuf(or_connection_t *or_conn)
@@ -480,15 +508,24 @@ connection_ext_or_process_inbuf(or_connection_t *or_conn)
log_debug(LD_NET, "Received DONE.");
+ /* If the transport proxy did not use the TRANSPORT command to
+ * specify the transport name, mark this as unknown transport. */
+ if (!or_conn->ext_or_transport)
+ or_conn->ext_or_transport = tor_strdup("<?\?>");
+
connection_write_ext_or_command(conn, EXT_OR_CMD_BT_OKAY, NULL, 0);
/* can't transition immediately; need to flush first. */
conn->state = EXT_OR_CONN_STATE_FLUSHING;
connection_stop_reading(conn);
} else if (command->cmd == EXT_OR_CMD_TB_USERADDR) {
- if (connection_ext_or_handle_useraddr(conn,
+ if (connection_ext_or_handle_cmd_useraddr(conn,
command->body, command->len) < 0)
goto err;
+ } else if (command->cmd == EXT_OR_CMD_TB_TRANSPORT) {
+ if (connection_ext_or_handle_cmd_transport(or_conn,
+ command->body, command->len) < 0)
+ goto err;
} else {
log_notice(LD_NET,"Got Extended ORPort command we don't regognize (%u).",
command->cmd);