aboutsummaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-09-28 11:57:36 -0400
committerNick Mathewson <nickm@torproject.org>2012-09-28 11:57:36 -0400
commit5f494a363a725951af884882a472ff4ab2b0a6db (patch)
tree0c97d1149f5464c8e5cdd11b4d1c69f1124825be /src/or/config.c
parent95d9f7e9cce96d684a1f0279aa82c68d0b6182be (diff)
parent1cbf45bed1451997e0815bedca8e816d87e081ce (diff)
downloadtor-5f494a363a725951af884882a472ff4ab2b0a6db.tar
tor-5f494a363a725951af884882a472ff4ab2b0a6db.tar.gz
Merge remote-tracking branch 'linus/enh6876_2'
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 00ca427f4..8e5108584 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -302,7 +302,7 @@ static config_var_t _option_vars[] = {
V(NumEntryGuards, UINT, "3"),
V(ORListenAddress, LINELIST, NULL),
VPORT(ORPort, LINELIST, NULL),
- V(OutboundBindAddress, STRING, NULL),
+ V(OutboundBindAddress, LINELIST, NULL),
V(PathBiasCircThreshold, INT, "-1"),
V(PathBiasNoticeRate, DOUBLE, "-1"),
@@ -474,6 +474,8 @@ static int options_init_logs(or_options_t *options, int validate_only);
static void init_libevent(const or_options_t *options);
static int opt_streq(const char *s1, const char *s2);
+static int parse_outbound_addresses(or_options_t *options, int validate_only,
+ char **msg);
/** Magic value for or_options_t. */
#define OR_OPTIONS_MAGIC 9090909
@@ -1392,6 +1394,12 @@ options_act(const or_options_t *old_options)
tor_free(http_authenticator);
}
+ if (parse_outbound_addresses(options, 0, &msg) < 0) {
+ log_warn(LD_BUG, "Failed parsing oubound bind addresses: %s", msg);
+ tor_free(msg);
+ return -1;
+ }
+
/* Check for transitions that need action. */
if (old_options) {
int revise_trackexithosts = 0;
@@ -2166,6 +2174,9 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (parse_ports(options, 1, msg, &n_ports) < 0)
return -1;
+ if (parse_outbound_addresses(options, 1, msg) < 0)
+ return -1;
+
if (validate_data_directory(options)<0)
REJECT("Invalid DataDirectory");
@@ -5495,3 +5506,57 @@ getinfo_helper_config(control_connection_t *conn,
return 0;
}
+/** Parse outbound bind address option lines. If <b>validate_only</b>
+ * is not 0 update _OutboundBindAddressIPv4 and
+ * _OutboundBindAddressIPv6 in <b>options</b>. On failure, set
+ * <b>msg</b> (if provided) to a newly allocated string containing a
+ * description of the problem and return -1. */
+static int
+parse_outbound_addresses(or_options_t *options, int validate_only, char **msg)
+{
+ const config_line_t *lines = options->OutboundBindAddress;
+ int found_v4 = 0, found_v6 = 0;
+
+ if (!validate_only) {
+ memset(&options->_OutboundBindAddressIPv4, 0,
+ sizeof(options->_OutboundBindAddressIPv4));
+ memset(&options->_OutboundBindAddressIPv6, 0,
+ sizeof(options->_OutboundBindAddressIPv6));
+ }
+ while (lines) {
+ tor_addr_t addr, *dst_addr = NULL;
+ int af = tor_addr_parse(&addr, lines->value);
+ switch (af) {
+ case AF_INET:
+ if (found_v4) {
+ if (msg)
+ tor_asprintf(msg, "Multiple IPv4 outbound bind addresses "
+ "configured: %s", lines->value);
+ return -1;
+ }
+ found_v4 = 1;
+ dst_addr = &options->_OutboundBindAddressIPv4;
+ break;
+ case AF_INET6:
+ if (found_v6) {
+ if (msg)
+ tor_asprintf(msg, "Multiple IPv6 outbound bind addresses "
+ "configured: %s", lines->value);
+ return -1;
+ }
+ found_v6 = 1;
+ dst_addr = &options->_OutboundBindAddressIPv6;
+ break;
+ default:
+ if (msg)
+ tor_asprintf(msg, "Outbound bind address '%s' didn't parse.",
+ lines->value);
+ return -1;
+ }
+ if (!validate_only)
+ tor_addr_copy(dst_addr, &addr);
+ lines = lines->next;
+ }
+ return 0;
+}
+