aboutsummaryrefslogtreecommitdiff
path: root/src/feature/client
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2018-12-20 03:55:02 +0100
committerAlexander Færøy <ahf@torproject.org>2018-12-20 03:55:02 +0100
commit4efe4cc2f918ce45075b010d2cdc09ec7791ac6b (patch)
treecde7a4670aa361d00aa3a6c251ed19b572d018d5 /src/feature/client
parent426c52b377057dc5f4428c664ee56ca77d648c9e (diff)
downloadtor-4efe4cc2f918ce45075b010d2cdc09ec7791ac6b.tar.gz
tor-4efe4cc2f918ce45075b010d2cdc09ec7791ac6b.zip
Add support for STATUS messages from Pluggable Transports.
This patch adds support for the new STATUS message that PT's can emit from their standard out. The STATUS message uses the `config_line_t` K/V format that was recently added in Tor. See: https://bugs.torproject.org/28846
Diffstat (limited to 'src/feature/client')
-rw-r--r--src/feature/client/transports.c60
-rw-r--r--src/feature/client/transports.h1
2 files changed, 58 insertions, 3 deletions
diff --git a/src/feature/client/transports.c b/src/feature/client/transports.c
index 6a3479a470..45dbd0c888 100644
--- a/src/feature/client/transports.c
+++ b/src/feature/client/transports.c
@@ -130,6 +130,7 @@ static void parse_method_error(const char *line, int is_server_method);
#define PROTO_PROXY_DONE "PROXY DONE"
#define PROTO_PROXY_ERROR "PROXY-ERROR"
#define PROTO_LOG "LOG"
+#define PROTO_STATUS "STATUS"
/** The first and only supported - at the moment - configuration
protocol version. */
@@ -912,12 +913,16 @@ handle_proxy_line(const char *line, managed_proxy_t *mp)
parse_proxy_error(line);
goto err;
- /* We check for the additional " " after the PROTO_LOG string to make sure
- * we can later extend this big if/else-if table with something that begins
- * with "LOG" without having to get the order right. */
+ /* We check for the additional " " after the PROTO_LOG * PROTO_STATUS
+ * string to make sure we can later extend this big if/else-if table with
+ * something that begins with "LOG" without having to get the order right.
+ * */
} else if (!strcmpstart(line, PROTO_LOG " ")) {
parse_log_line(line, mp);
return;
+ } else if (!strcmpstart(line, PROTO_STATUS " ")) {
+ parse_status_line(line, mp);
+ return;
}
log_notice(LD_GENERAL, "Unknown line received by managed proxy (%s).", line);
@@ -1205,6 +1210,55 @@ parse_log_line(const char *line, managed_proxy_t *mp)
tor_free(log_message);
}
+/** Parses a STATUS <b>line</b> and emit control events accordingly. */
+STATIC void
+parse_status_line(const char *line, managed_proxy_t *mp)
+{
+ tor_assert(line);
+ tor_assert(mp);
+
+ config_line_t *values = NULL;
+ char *status_message = NULL;
+
+ if (strlen(line) < (strlen(PROTO_STATUS) + 1)) {
+ log_warn(LD_PT, "Managed proxy sent us a %s line "
+ "with missing argument.", PROTO_STATUS);
+ goto done;
+ }
+
+ const char *data = line + strlen(PROTO_STATUS) + 1;
+
+ values = kvline_parse(data, KV_QUOTED);
+
+ if (! values) {
+ log_warn(LD_PT, "Managed proxy \"%s\" wrote an invalid "
+ "STATUS message: %s", mp->argv[0], data);
+ goto done;
+ }
+
+ /* We check if we received the TYPE parameter, which is the only *required*
+ * value. */
+ const config_line_t *type = config_line_find(values, "TYPE");
+
+ if (! type) {
+ log_warn(LD_PT, "Managed proxy \"%s\" wrote a STATUS line without "
+ "TYPE: %s", mp->argv[0], data);
+ goto done;
+ }
+
+ /* Prepend the PT name. */
+ config_line_prepend(&values, "PT", mp->argv[0]);
+ status_message = kvline_encode(values, KV_QUOTED);
+
+ /* We have checked that TYPE is there, we can now emit the STATUS event via
+ * the control port. */
+ control_event_pt_status(status_message);
+
+ done:
+ config_free_lines(values);
+ tor_free(status_message);
+}
+
/** Return a newly allocated string that tor should place in
* TOR_PT_SERVER_TRANSPORT_OPTIONS while configuring the server
* manged proxy in <b>mp</b>. Return NULL if no such options are found. */
diff --git a/src/feature/client/transports.h b/src/feature/client/transports.h
index b8d1bb0081..1a910ae82c 100644
--- a/src/feature/client/transports.h
+++ b/src/feature/client/transports.h
@@ -129,6 +129,7 @@ STATIC void parse_env_error(const char *line);
STATIC void parse_proxy_error(const char *line);
STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
STATIC void parse_log_line(const char *line, managed_proxy_t *mp);
+STATIC void parse_status_line(const char *line, managed_proxy_t *mp);
STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
STATIC void managed_proxy_destroy(managed_proxy_t *mp,