From 20c31c80fb7265e8987747b3cdba04f16c352b15 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Sat, 11 Jun 2011 17:08:31 +0200 Subject: [PATCH] ClientTransportPlugin parsing done. --- src/or/config.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++-- src/or/or.h | 2 + 2 files changed, 118 insertions(+), 5 deletions(-) diff --git a/src/or/config.c b/src/or/config.c index d663336796..a1960dd8fc 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -203,8 +203,9 @@ static config_var_t _option_vars[] = { V(CircuitStreamTimeout, INTERVAL, "0"), V(CircuitPriorityHalflife, DOUBLE, "-100.0"), /*negative:'Use default'*/ V(ClientDNSRejectInternalAddresses, BOOL,"1"), - V(ClientRejectInternalAddresses, BOOL, "1"), V(ClientOnly, BOOL, "0"), + V(ClientRejectInternalAddresses, BOOL, "1"), + VAR("ClientTransportPlugin", LINELIST, ClientTransportPlugin, NULL), V(ConsensusParams, STRING, NULL), V(ConnLimit, UINT, "1000"), V(ConnDirectionStatistics, BOOL, "0"), @@ -570,6 +571,7 @@ static int check_nickname_list(const char *lst, const char *name, char **msg); static void config_register_addressmaps(or_options_t *options); static int parse_bridge_line(const char *line, int validate_only); +static int parse_transport_line(const char *line, int validate_only); static int parse_dir_server_line(const char *line, dirinfo_type_t required_type, int validate_only); @@ -1205,6 +1207,17 @@ options_act(or_options_t *old_options) if (consider_adding_dir_authorities(options, old_options) < 0) return -1; + if (options->ClientTransportPlugin) { + for (cl = options->ClientTransportPlugin; cl; cl = cl->next) { + if (parse_transport_line(cl->value, 0)<0) { + log_warn(LD_BUG, + "Previously validated ClientTransportPlugin line " + "could not be added!"); + return -1; + } + } + } + if (options->Bridges) { mark_bridge_list(); for (cl = options->Bridges; cl; cl = cl->next) { @@ -3663,6 +3676,16 @@ options_validate(or_options_t *old_options, or_options_t *options, if (options->UseBridges && !options->TunnelDirConns) REJECT("TunnelDirConns set to 0 only works with UseBridges set to 0"); + + if (options->ClientTransportPlugin) { + if (!options->Bridges) + REJECT("ClientTransportPlugin found without any bridges."); + for (cl = options->ClientTransportPlugin; cl; cl = cl->next) { + if (parse_transport_line(cl->value, 1)<0) + REJECT("Transport line did not parse. See logs for details."); + } + } + if (options->Bridges) { for (cl = options->Bridges; cl; cl = cl->next) { if (parse_bridge_line(cl->value, 1)<0) @@ -4553,6 +4576,8 @@ parse_bridge_line(const char *line, int validate_only) smartlist_t *items = NULL; int r; char *addrport=NULL, *fingerprint=NULL; + char *transport_name=NULL; + char *field1=NULL; tor_addr_t addr; uint16_t port = 0; char digest[DIGEST_LEN]; @@ -4564,8 +4589,18 @@ parse_bridge_line(const char *line, int validate_only) log_warn(LD_CONFIG, "Too few arguments to Bridge line."); goto err; } - addrport = smartlist_get(items, 0); + + /* field1 is either a transport name or addrport */ + field1 = smartlist_get(items, 0); smartlist_del_keeporder(items, 0); + + if (!strstr(field1, ".")) { /* new-style bridge line */ + transport_name = field1; + addrport = smartlist_get(items, 0); + smartlist_del_keeporder(items, 0); + } else + addrport = field1; + if (tor_addr_port_parse(addrport, &addr, &port)<0) { log_warn(LD_CONFIG, "Error parsing Bridge address '%s'", addrport); goto err; @@ -4590,10 +4625,11 @@ parse_bridge_line(const char *line, int validate_only) } if (!validate_only) { - log_debug(LD_DIR, "Bridge at %s:%d (%s)", fmt_addr(&addr), - (int)port, + log_warn(LD_DIR, "Bridge at %s:%d with transport %s (%s)", + fmt_addr(&addr), (int)port, transport_name, fingerprint ? fingerprint : "no key listed"); - bridge_add_from_config(&addr, port, fingerprint ? digest : NULL); + bridge_add_from_config(&addr, port, + fingerprint ? digest : NULL/*, transport_name*/); } r = 0; @@ -4607,9 +4643,84 @@ parse_bridge_line(const char *line, int validate_only) smartlist_free(items); tor_free(addrport); tor_free(fingerprint); + tor_free(transport_name); return r; } +static int +parse_transport_line(const char *line, int validate_only) +{ + smartlist_t *items = NULL; + int r; + char *socks_ver_str=NULL; + char *name=NULL; + char *addrport=NULL; + int socks_ver; + tor_addr_t addr; + uint16_t port = 0; + + items = smartlist_create(); + smartlist_split_string(items, line, NULL, + SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1); + + if (smartlist_len(items) < 3) { + log_warn(LD_CONFIG, "parse_transport_line(): " + "Too few arguments on ClientTransportPlugin line."); + goto err; + } + + name = smartlist_get(items, 0); + smartlist_del_keeporder(items, 0); + + socks_ver_str = smartlist_get(items, 0); + smartlist_del_keeporder(items, 0); + + if (!strcmp(socks_ver_str,"socks4")) + socks_ver = PROXY_SOCKS4; + else if (!strcmp(socks_ver_str,"socks5")) + socks_ver = PROXY_SOCKS5; + else { + log_warn(LD_CONFIG, "Strange transport proxy type."); + goto err; + } + + addrport = smartlist_get(items, 0); + smartlist_del_keeporder(items, 0); + + if (tor_addr_port_parse(addrport, &addr, &port)<0) { + log_warn(LD_CONFIG, "Error parsing transport " + "address '%s'", addrport); + goto err; + } + + if (!port) { + log_warn(LD_CONFIG, + "Transport address '%s' has no port.", addrport); + goto err; + } + + if (!validate_only) { + log_warn(LD_DIR, "Transport %s at %s:%d", name, + fmt_addr(&addr), (int)port); + /* transport_add_from_config(&addr, port, + fingerprint ? digest : NULL, transport); */ + } + + r = 0; + goto done; + + err: + r = -1; + + done: + SMARTLIST_FOREACH(items, char*, s, tor_free(s)); + smartlist_free(items); + tor_free(socks_ver_str); + tor_free(name); + tor_free(addrport); + return r; +} + /** Read the contents of a DirServer line from line. If * validate_only is 0, and the line is well-formed, and it * shares any bits with required_type or required_type diff --git a/src/or/or.h b/src/or/or.h index b4000add81..062352aee3 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -2660,6 +2660,8 @@ typedef struct { config_line_t *Bridges; /**< List of bootstrap bridge addresses. */ + config_line_t *ClientTransportPlugin; /**< List of client transport plugins. */ + int BridgeRelay; /**< Boolean: are we acting as a bridge relay? We make * this explicit so we can change how we behave in the * future. */