summaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c310
1 files changed, 222 insertions, 88 deletions
diff --git a/src/or/config.c b/src/or/config.c
index a369297518..8f79c44cc1 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -130,6 +130,7 @@ static config_abbrev_t _option_abbrevs[] = {
{ "HashedControlPassword", "__HashedControlSessionPassword", 1, 0},
{ "StrictEntryNodes", "StrictNodes", 0, 1},
{ "StrictExitNodes", "StrictNodes", 0, 1},
+ { "_UseFilteringSSLBufferevents", "UseFilteringSSLBufferevents", 0, 1},
{ NULL, NULL, 0, 0},
};
@@ -168,6 +169,9 @@ typedef struct config_var_t {
/** An entry for config_vars: "The option <b>name</b> is obsolete." */
#define OBSOLETE(name) { name, CONFIG_TYPE_OBSOLETE, 0, NULL }
+#define VPORT(member,conftype,initvalue) \
+ VAR(#member, conftype, member ## _lines, initvalue)
+
/** Array of configuration options. Until we disallow nonstandard
* abbreviations, order is significant, since the first matching option will
* be chosen first.
@@ -201,12 +205,13 @@ static config_var_t _option_vars[] = {
V(AuthDirListBadExits, BOOL, "0"),
V(AuthDirMaxServersPerAddr, UINT, "2"),
V(AuthDirMaxServersPerAuthAddr,UINT, "5"),
+ V(AuthDirHasIPv6Connectivity, BOOL, "0"),
VAR("AuthoritativeDirectory", BOOL, AuthoritativeDir, "0"),
V(AutomapHostsOnResolve, BOOL, "0"),
V(AutomapHostsSuffixes, CSV, ".onion,.exit"),
V(AvoidDiskWrites, BOOL, "0"),
- V(BandwidthBurst, MEMUNIT, "10 MB"),
- V(BandwidthRate, MEMUNIT, "5 MB"),
+ V(BandwidthBurst, MEMUNIT, "1 GB"),
+ V(BandwidthRate, MEMUNIT, "1 GB"),
V(BridgeAuthoritativeDir, BOOL, "0"),
VAR("Bridge", LINELIST, Bridges, NULL),
V(BridgePassword, STRING, NULL),
@@ -220,8 +225,10 @@ static config_var_t _option_vars[] = {
V(CircuitPriorityHalflife, DOUBLE, "-100.0"), /*negative:'Use default'*/
V(ClientDNSRejectInternalAddresses, BOOL,"1"),
V(ClientOnly, BOOL, "0"),
+ V(ClientPreferIPv6ORPort, BOOL, "0"),
V(ClientRejectInternalAddresses, BOOL, "1"),
V(ClientTransportPlugin, LINELIST, NULL),
+ V(ClientUseIPv6, BOOL, "0"),
V(ConsensusParams, STRING, NULL),
V(ConnLimit, UINT, "1000"),
V(ConnDirectionStatistics, BOOL, "0"),
@@ -229,7 +236,7 @@ static config_var_t _option_vars[] = {
V(ConstrainedSockSize, MEMUNIT, "8192"),
V(ContactInfo, STRING, NULL),
V(ControlListenAddress, LINELIST, NULL),
- V(ControlPort, LINELIST, NULL),
+ VPORT(ControlPort, LINELIST, NULL),
V(ControlPortFileGroupReadable,BOOL, "0"),
V(ControlPortWriteToFile, FILENAME, NULL),
V(ControlSocket, LINELIST, NULL),
@@ -246,7 +253,7 @@ static config_var_t _option_vars[] = {
V(DirListenAddress, LINELIST, NULL),
OBSOLETE("DirFetchPeriod"),
V(DirPolicy, LINELIST, NULL),
- V(DirPort, LINELIST, NULL),
+ VPORT(DirPort, LINELIST, NULL),
V(DirPortFrontPage, FILENAME, NULL),
OBSOLETE("DirPostPeriod"),
OBSOLETE("DirRecordUsageByCountry"),
@@ -259,7 +266,7 @@ static config_var_t _option_vars[] = {
V(DisableDebuggerAttachment, BOOL, "1"),
V(DisableIOCP, BOOL, "1"),
V(DynamicDHGroups, BOOL, "0"),
- V(DNSPort, LINELIST, NULL),
+ VPORT(DNSPort, LINELIST, NULL),
V(DNSListenAddress, LINELIST, NULL),
V(DownloadExtraInfo, BOOL, "0"),
V(EnforceDistinctSubnets, BOOL, "1"),
@@ -273,6 +280,7 @@ static config_var_t _option_vars[] = {
V(ExitPolicy, LINELIST, NULL),
V(ExitPolicyRejectPrivate, BOOL, "1"),
V(ExitPortStatistics, BOOL, "0"),
+ V(ExtendAllowPrivateAddresses, BOOL, "0"),
V(ExtraInfoStatistics, BOOL, "1"),
#if defined (WINCE)
@@ -345,7 +353,7 @@ static config_var_t _option_vars[] = {
V(NewCircuitPeriod, INTERVAL, "30 seconds"),
VAR("NamingAuthoritativeDirectory",BOOL, NamingAuthoritativeDir, "0"),
V(NATDListenAddress, LINELIST, NULL),
- V(NATDPort, LINELIST, NULL),
+ VPORT(NATDPort, LINELIST, NULL),
V(Nickname, STRING, NULL),
V(WarnUnsafeSocks, BOOL, "1"),
OBSOLETE("NoPublish"),
@@ -353,7 +361,7 @@ static config_var_t _option_vars[] = {
V(NumCPUs, UINT, "0"),
V(NumEntryGuards, UINT, "3"),
V(ORListenAddress, LINELIST, NULL),
- V(ORPort, LINELIST, NULL),
+ VPORT(ORPort, LINELIST, NULL),
V(OutboundBindAddress, STRING, NULL),
V(PathBiasCircThreshold, INT, "-1"),
@@ -406,7 +414,7 @@ static config_var_t _option_vars[] = {
V(ShutdownWaitLength, INTERVAL, "30 seconds"),
V(SocksListenAddress, LINELIST, NULL),
V(SocksPolicy, LINELIST, NULL),
- V(SocksPort, LINELIST, NULL),
+ VPORT(SocksPort, LINELIST, NULL),
V(SocksTimeout, INTERVAL, "2 minutes"),
OBSOLETE("StatusFetchPeriod"),
V(StrictNodes, BOOL, "0"),
@@ -419,7 +427,7 @@ static config_var_t _option_vars[] = {
V(TrackHostExitsExpire, INTERVAL, "30 minutes"),
OBSOLETE("TrafficShaping"),
V(TransListenAddress, LINELIST, NULL),
- V(TransPort, LINELIST, NULL),
+ VPORT(TransPort, LINELIST, NULL),
V(TunnelDirConns, BOOL, "1"),
V(UpdateBridgesFromAuthority, BOOL, "0"),
V(UseBridges, BOOL, "0"),
@@ -442,7 +450,7 @@ static config_var_t _option_vars[] = {
VAR("VersioningAuthoritativeDirectory",BOOL,VersioningAuthoritativeDir, "0"),
V(VirtualAddrNetwork, STRING, "127.192.0.0/10"),
V(WarnPlaintextPorts, CSV, "23,109,110,143"),
- V(_UseFilteringSSLBufferevents, BOOL, "0"),
+ V(UseFilteringSSLBufferevents, BOOL, "0"),
VAR("__ReloadTorrcOnSIGHUP", BOOL, ReloadTorrcOnSIGHUP, "1"),
VAR("__AllDirActionsPrivate", BOOL, AllDirActionsPrivate, "0"),
VAR("__DisablePredictedCircuits",BOOL,DisablePredictedCircuits, "0"),
@@ -452,7 +460,7 @@ static config_var_t _option_vars[] = {
VAR("__OwningControllerProcess",STRING,OwningControllerProcess, NULL),
V(MinUptimeHidServDirectoryV2, INTERVAL, "25 hours"),
V(VoteOnHidServDirectoriesV2, BOOL, "1"),
- V(_UsingTestNetworkDefaults, BOOL, "0"),
+ VAR("___UsingTestNetworkDefaults", BOOL, _UsingTestNetworkDefaults, "0"),
{ NULL, CONFIG_TYPE_OBSOLETE, 0, NULL }
};
@@ -460,7 +468,7 @@ static config_var_t _option_vars[] = {
/** Override default values with these if the user sets the TestingTorNetwork
* option. */
static const config_var_t testing_tor_network_defaults[] = {
- V(ServerDNSAllowBrokenConfig, BOOL, "1"),
+ V(ServerDNSAllowBrokenConfig, BOOL, "1"),
V(DirAllowPrivateAddresses, BOOL, "1"),
V(EnforceDistinctSubnets, BOOL, "0"),
V(AssumeReachable, BOOL, "1"),
@@ -470,6 +478,7 @@ static const config_var_t testing_tor_network_defaults[] = {
V(ClientRejectInternalAddresses, BOOL, "0"),
V(CountPrivateBandwidth, BOOL, "1"),
V(ExitPolicyRejectPrivate, BOOL, "0"),
+ V(ExtendAllowPrivateAddresses, BOOL, "1"),
V(V3AuthVotingInterval, INTERVAL, "5 minutes"),
V(V3AuthVoteDelay, INTERVAL, "20 seconds"),
V(V3AuthDistDelay, INTERVAL, "20 seconds"),
@@ -479,7 +488,7 @@ static const config_var_t testing_tor_network_defaults[] = {
V(TestingAuthDirTimeToLearnReachability, INTERVAL, "0 minutes"),
V(TestingEstimatedDescriptorPropagationTime, INTERVAL, "0 minutes"),
V(MinUptimeHidServDirectoryV2, INTERVAL, "0 minutes"),
- V(_UsingTestNetworkDefaults, BOOL, "1"),
+ VAR("___UsingTestNetworkDefaults", BOOL, _UsingTestNetworkDefaults, "1"),
{ NULL, CONFIG_TYPE_OBSOLETE, 0, NULL }
};
@@ -622,7 +631,7 @@ static int parse_dir_server_line(const char *line,
dirinfo_type_t required_type,
int validate_only);
static void port_cfg_free(port_cfg_t *port);
-static int parse_ports(const or_options_t *options, int validate_only,
+static int parse_ports(or_options_t *options, int validate_only,
char **msg_out, int *n_ports_out);
static int check_server_ports(const smartlist_t *ports,
const or_options_t *options);
@@ -710,7 +719,7 @@ get_dirportfrontpage(void)
/** Allocate an empty configuration object of a given format type. */
static void *
-config_alloc(const config_format_t *fmt)
+config_new(const config_format_t *fmt)
{
void *opts = tor_malloc_zero(fmt->size);
*(uint32_t*)STRUCT_VAR_P(opts, fmt->magic_offset) = fmt->magic;
@@ -1167,7 +1176,7 @@ options_act_reversible(const or_options_t *old_options, char **msg)
#if defined(HAVE_NET_IF_H) && defined(HAVE_NET_PFVAR_H)
/* Open /dev/pf before dropping privileges. */
- if (options->TransPort) {
+ if (options->TransPort_set) {
if (get_pf_socket() < 0) {
*msg = tor_strdup("Unable to open /dev/pf for transparent proxy.");
goto rollback;
@@ -1549,7 +1558,7 @@ options_act(const or_options_t *old_options)
monitor_owning_controller_process(options->OwningControllerProcess);
/* reload keys as needed for rendezvous services. */
- if (rend_service_load_keys()<0) {
+ if (rend_service_load_all_keys()<0) {
log_warn(LD_GENERAL,"Error loading rendezvous service keys");
return -1;
}
@@ -1650,7 +1659,7 @@ options_act(const or_options_t *old_options)
int was_relay = 0;
if (options->BridgeRelay) {
time_t int_start = time(NULL);
- if (config_lines_eq(old_options->ORPort, options->ORPort)) {
+ if (config_lines_eq(old_options->ORPort_lines,options->ORPort_lines)) {
int_start += RELAY_BRIDGE_STATS_DELAY;
was_relay = 1;
}
@@ -1734,7 +1743,7 @@ options_act(const or_options_t *old_options)
} else {
options->DirReqStatistics = 0;
/* Don't warn Tor clients, they don't use statistics */
- if (options->ORPort)
+ if (options->ORPort_set)
log_notice(LD_CONFIG, "Configured to measure directory request "
"statistics, but no GeoIP database found. "
"Please specify a GeoIP database using the "
@@ -3110,7 +3119,7 @@ options_dup(const config_format_t *fmt, const or_options_t *old)
int i;
config_line_t *line;
- newopts = config_alloc(fmt);
+ newopts = config_new(fmt);
for (i=0; fmt->vars[i].name; ++i) {
if (fmt->vars[i].type == CONFIG_TYPE_LINELIST_S)
continue;
@@ -3135,7 +3144,7 @@ options_dup(const config_format_t *fmt, const or_options_t *old)
or_options_t *
options_new(void)
{
- return config_alloc(&options_format);
+ return config_new(&options_format);
}
/** Set <b>options</b> to hold reasonable defaults for most options.
@@ -3181,7 +3190,7 @@ config_dump(const config_format_t *fmt, const void *default_options,
char *msg = NULL;
if (defaults == NULL) {
- defaults = defaults_tmp = config_alloc(fmt);
+ defaults = defaults_tmp = config_new(fmt);
config_init(fmt, defaults_tmp);
}
@@ -3448,7 +3457,8 @@ options_validate(or_options_t *old_options, or_options_t *options,
"Tor will still run, but probably won't do anything.");
#ifndef USE_TRANSPARENT
- if (options->TransPort || options->TransListenAddress)
+ /* XXXX024 I think we can remove this TransListenAddress */
+ if (options->TransPort_set || options->TransListenAddress)
REJECT("TransPort and TransListenAddress are disabled in this build.");
#endif
@@ -3518,10 +3528,10 @@ options_validate(or_options_t *old_options, or_options_t *options,
}
}
- if (options->AuthoritativeDir && !options->DirPort)
+ if (options->AuthoritativeDir && !options->DirPort_set)
REJECT("Running as authoritative directory, but no DirPort set.");
- if (options->AuthoritativeDir && !options->ORPort)
+ if (options->AuthoritativeDir && !options->ORPort_set)
REJECT("Running as authoritative directory, but no ORPort set.");
if (options->AuthoritativeDir && options->ClientOnly)
@@ -3708,11 +3718,12 @@ options_validate(or_options_t *old_options, or_options_t *options,
"PublishServerDescriptor line.");
}
- if (options->BridgeRelay && options->DirPort) {
+ if (options->BridgeRelay && options->DirPort_set) {
log_warn(LD_CONFIG, "Can't set a DirPort on a bridge relay; disabling "
"DirPort");
- config_free_lines(options->DirPort);
- options->DirPort = NULL;
+ config_free_lines(options->DirPort_lines);
+ options->DirPort_lines = NULL;
+ options->DirPort_set = 0;
}
if (options->MinUptimeHidServDirectoryV2 < 0) {
@@ -3987,7 +3998,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
}
}
- if (options->ControlPort && !options->HashedControlPassword &&
+ if (options->ControlPort_set && !options->HashedControlPassword &&
!options->HashedControlSessionPassword &&
!options->CookieAuthentication) {
log_warn(LD_CONFIG, "ControlPort is open, but no authentication method "
@@ -4052,7 +4063,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
log_notice(LD_GENERAL, "Tor is not configured as a relay but you specified"
" a ServerTransportPlugin line (%s). The ServerTransportPlugin "
"line will be ignored.",
- esc_for_log(options->ServerTransportPlugin->value));
+ escaped(options->ServerTransportPlugin->value));
}
if (options->ConstrainedSockets) {
@@ -4067,7 +4078,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
MIN_CONSTRAINED_TCP_BUFFER, MAX_CONSTRAINED_TCP_BUFFER);
return -1;
}
- if (options->DirPort) {
+ if (options->DirPort_set) {
/* Providing cached directory entries while system TCP buffers are scarce
* will exacerbate the socket errors. Suggest that this be disabled. */
COMPLAIN("You have requested constrained socket buffers while also "
@@ -4226,7 +4237,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
}
});
- if (options->BridgeRelay == 1 && ! options->ORPort)
+ if (options->BridgeRelay == 1 && ! options->ORPort_set)
REJECT("BridgeRelay is 1, ORPort is not set. This is an invalid "
"combination.");
@@ -4326,7 +4337,7 @@ options_transition_affects_workers(const or_options_t *old_options,
{
if (!opt_streq(old_options->DataDirectory, new_options->DataDirectory) ||
old_options->NumCPUs != new_options->NumCPUs ||
- !config_lines_eq(old_options->ORPort, new_options->ORPort) ||
+ !config_lines_eq(old_options->ORPort_lines, new_options->ORPort_lines) ||
old_options->ServerDNSSearchDomains !=
new_options->ServerDNSSearchDomains ||
old_options->_SafeLogging != new_options->_SafeLogging ||
@@ -4356,8 +4367,10 @@ options_transition_affects_descriptor(const or_options_t *old_options,
!config_lines_eq(old_options->ExitPolicy,new_options->ExitPolicy) ||
old_options->ExitPolicyRejectPrivate !=
new_options->ExitPolicyRejectPrivate ||
- !config_lines_eq(old_options->ORPort, new_options->ORPort) ||
- !config_lines_eq(old_options->DirPort, new_options->DirPort) ||
+ !config_lines_eq(old_options->ORPort_lines,
+ new_options->ORPort_lines) ||
+ !config_lines_eq(old_options->DirPort_lines,
+ new_options->DirPort_lines) ||
old_options->ClientOnly != new_options->ClientOnly ||
old_options->DisableNetwork != new_options->DisableNetwork ||
old_options->_PublishServerDescriptor !=
@@ -4864,12 +4877,11 @@ config_register_addressmaps(const or_options_t *options)
{
smartlist_t *elts;
config_line_t *opt;
- char *from, *to;
+ const char *from, *to, *msg;
addressmap_clear_configured();
elts = smartlist_new();
for (opt = options->AddressMap; opt; opt = opt->next) {
- int from_wildcard = 0, to_wildcard = 0;
smartlist_split_string(elts, opt->value, NULL,
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
if (smartlist_len(elts) < 2) {
@@ -4887,11 +4899,39 @@ config_register_addressmaps(const or_options_t *options)
goto cleanup;
}
- if (!strcmp(to, "*") || !strcmp(from, "*")) {
- log_warn(LD_CONFIG,"MapAddress '%s' is unsupported - can't remap from "
- "or to *. Ignoring.",opt->value);
+ if (addressmap_register_auto(from, to, 0, ADDRMAPSRC_TORRC, &msg) < 0) {
+ log_warn(LD_CONFIG,"MapAddress '%s' failed: %s. Ignoring.", opt->value,
+ msg);
goto cleanup;
}
+
+ if (smartlist_len(elts) > 2)
+ log_warn(LD_CONFIG,"Ignoring extra arguments to MapAddress.");
+
+ cleanup:
+ SMARTLIST_FOREACH(elts, char*, cp, tor_free(cp));
+ smartlist_clear(elts);
+ }
+ smartlist_free(elts);
+}
+
+/** As addressmap_register(), but detect the wildcarded status of "from" and
+ * "to", and do not steal a reference to <b>to</b>. */
+/* XXXX024 move to connection_edge.c */
+int
+addressmap_register_auto(const char *from, const char *to,
+ time_t expires,
+ addressmap_entry_source_t addrmap_source,
+ const char **msg)
+{
+ int from_wildcard = 0, to_wildcard = 0;
+
+ *msg = "whoops, forgot the error message";
+ if (1) {
+ if (!strcmp(to, "*") || !strcmp(from, "*")) {
+ *msg = "can't remap from or to *";
+ return -1;
+ }
/* Detect asterisks in expressions of type: '*.example.com' */
if (!strncmp(from,"*.",2)) {
from += 2;
@@ -4903,30 +4943,20 @@ config_register_addressmaps(const or_options_t *options)
}
if (to_wildcard && !from_wildcard) {
- log_warn(LD_CONFIG,
- "Skipping invalid argument '%s' to MapAddress: "
- "can only use wildcard (i.e. '*.') if 'from' address "
- "uses wildcard also", opt->value);
- goto cleanup;
+ *msg = "can only use wildcard (i.e. '*.') if 'from' address "
+ "uses wildcard also";
+ return -1;
}
if (address_is_invalid_destination(to, 1)) {
- log_warn(LD_CONFIG,
- "Skipping invalid argument '%s' to MapAddress", opt->value);
- goto cleanup;
+ *msg = "destination is invalid";
+ return -1;
}
- addressmap_register(from, tor_strdup(to), 0, ADDRMAPSRC_TORRC,
+ addressmap_register(from, tor_strdup(to), expires, addrmap_source,
from_wildcard, to_wildcard);
-
- if (smartlist_len(elts) > 2)
- log_warn(LD_CONFIG,"Ignoring extra arguments to MapAddress.");
-
- cleanup:
- SMARTLIST_FOREACH(elts, char*, cp, tor_free(cp));
- smartlist_clear(elts);
}
- smartlist_free(elts);
+ return 0;
}
/**
@@ -5485,8 +5515,8 @@ parse_dir_server_line(const char *line, dirinfo_type_t required_type,
fingerprint = smartlist_join_strings(items, "", 0, NULL);
if (strlen(fingerprint) != HEX_DIGEST_LEN) {
- log_warn(LD_CONFIG, "Key digest for DirServer is wrong length %d.",
- (int)strlen(fingerprint));
+ log_warn(LD_CONFIG, "Key digest '%s' for DirServer is wrong length %d.",
+ fingerprint, (int)strlen(fingerprint));
goto err;
}
if (!strcmp(fingerprint, "E623F7625FBE0C87820F11EC5F6D5377ED816294")) {
@@ -5643,13 +5673,13 @@ warn_nonlocal_controller_ports(smartlist_t *ports, unsigned forbid)
*/
static int
parse_port_config(smartlist_t *out,
- const config_line_t *ports,
- const config_line_t *listenaddrs,
- const char *portname,
- int listener_type,
- const char *defaultaddr,
- int defaultport,
- unsigned flags)
+ const config_line_t *ports,
+ const config_line_t *listenaddrs,
+ const char *portname,
+ int listener_type,
+ const char *defaultaddr,
+ int defaultport,
+ unsigned flags)
{
smartlist_t *elts;
int retval = -1;
@@ -5660,6 +5690,7 @@ parse_port_config(smartlist_t *out,
const unsigned forbid_nonlocal = flags & CL_PORT_FORBID_NONLOCAL;
const unsigned allow_spurious_listenaddr =
flags & CL_PORT_ALLOW_EXTRA_LISTENADDR;
+ int got_zero_port=0, got_nonzero_port=0;
/* FooListenAddress is deprecated; let's make it work like it used to work,
* though. */
@@ -5687,7 +5718,7 @@ parse_port_config(smartlist_t *out,
if (mainport == 0) {
if (allow_spurious_listenaddr)
- return 1;
+ return 1; /*DOCDOC*/
log_warn(LD_CONFIG, "%sPort must be defined if %sListenAddress is used",
portname, portname);
return -1;
@@ -5912,6 +5943,11 @@ parse_port_config(smartlist_t *out,
} SMARTLIST_FOREACH_END(elt);
}
+ if (port)
+ got_nonzero_port = 1;
+ else
+ got_zero_port = 1;
+
if (out && port) {
port_cfg_t *cfg = tor_malloc_zero(sizeof(port_cfg_t));
tor_addr_copy(&cfg->addr, &addr);
@@ -5938,6 +5974,13 @@ parse_port_config(smartlist_t *out,
warn_nonlocal_client_ports(out, portname);
}
+ if (got_zero_port && got_nonzero_port) {
+ log_warn(LD_CONFIG, "You specified a nonzero %sPort along with '%sPort 0' "
+ "in the same configuration. Did you mean to disable %sPort or "
+ "not?", portname, portname, portname);
+ goto err;
+ }
+
retval = 0;
err:
SMARTLIST_FOREACH(elts, char *, cp, tor_free(cp));
@@ -5968,16 +6011,34 @@ parse_unix_socket_config(smartlist_t *out, const config_line_t *cfg,
return 0;
}
+/** Return the number of ports which are actually going to listen with type
+ * <b>listenertype</b>. Do not count no_listen ports. Do not count unix
+ * sockets. */
+static int
+count_real_listeners(const smartlist_t *ports, int listenertype)
+{
+ int n = 0;
+ SMARTLIST_FOREACH_BEGIN(ports, port_cfg_t *, port) {
+ if (port->no_listen || port->is_unix_addr)
+ continue;
+ if (port->type != listenertype)
+ continue;
+ ++n;
+ } SMARTLIST_FOREACH_END(port);
+ return n;
+}
+
/** Parse all client port types (Socks, DNS, Trans, NATD) from
- * <b>options</b>. On success, set *<b>n_ports_out</b> to the number of
- * ports that are listed and return 0. On failure, set *<b>msg</b> to a
+ * <b>options</b>. On success, set *<b>n_ports_out</b> to the number
+ * of ports that are listed, update the *Port_set values in
+ * <b>options</b>, and return 0. On failure, set *<b>msg</b> to a
* description of the problem and return -1.
*
* If <b>validate_only</b> is false, set configured_client_ports to the
* new list of ports parsed from <b>options</b>.
**/
static int
-parse_ports(const or_options_t *options, int validate_only,
+parse_ports(or_options_t *options, int validate_only,
char **msg, int *n_ports_out)
{
smartlist_t *ports;
@@ -5988,7 +6049,7 @@ parse_ports(const or_options_t *options, int validate_only,
*n_ports_out = 0;
if (parse_port_config(ports,
- options->SocksPort, options->SocksListenAddress,
+ options->SocksPort_lines, options->SocksListenAddress,
"Socks", CONN_TYPE_AP_LISTENER,
"127.0.0.1", 9050,
CL_PORT_WARN_NONLOCAL|CL_PORT_ALLOW_EXTRA_LISTENADDR) < 0) {
@@ -5996,26 +6057,26 @@ parse_ports(const or_options_t *options, int validate_only,
goto err;
}
if (parse_port_config(ports,
- options->DNSPort, options->DNSListenAddress,
- "DNS", CONN_TYPE_AP_DNS_LISTENER,
- "127.0.0.1", 0,
- CL_PORT_WARN_NONLOCAL) < 0) {
+ options->DNSPort_lines, options->DNSListenAddress,
+ "DNS", CONN_TYPE_AP_DNS_LISTENER,
+ "127.0.0.1", 0,
+ CL_PORT_WARN_NONLOCAL) < 0) {
*msg = tor_strdup("Invalid DNSPort/DNSListenAddress configuration");
goto err;
}
if (parse_port_config(ports,
- options->TransPort, options->TransListenAddress,
- "Trans", CONN_TYPE_AP_TRANS_LISTENER,
- "127.0.0.1", 0,
- CL_PORT_WARN_NONLOCAL) < 0) {
+ options->TransPort_lines, options->TransListenAddress,
+ "Trans", CONN_TYPE_AP_TRANS_LISTENER,
+ "127.0.0.1", 0,
+ CL_PORT_WARN_NONLOCAL) < 0) {
*msg = tor_strdup("Invalid TransPort/TransListenAddress configuration");
goto err;
}
if (parse_port_config(ports,
- options->NATDPort, options->NATDListenAddress,
- "NATD", CONN_TYPE_AP_NATD_LISTENER,
- "127.0.0.1", 0,
- CL_PORT_WARN_NONLOCAL) < 0) {
+ options->NATDPort_lines, options->NATDListenAddress,
+ "NATD", CONN_TYPE_AP_NATD_LISTENER,
+ "127.0.0.1", 0,
+ CL_PORT_WARN_NONLOCAL) < 0) {
*msg = tor_strdup("Invalid NatdPort/NatdListenAddress configuration");
goto err;
}
@@ -6028,7 +6089,8 @@ parse_ports(const or_options_t *options, int validate_only,
control_port_flags |= CL_PORT_FORBID_NONLOCAL;
if (parse_port_config(ports,
- options->ControlPort, options->ControlListenAddress,
+ options->ControlPort_lines,
+ options->ControlListenAddress,
"Control", CONN_TYPE_CONTROL_LISTENER,
"127.0.0.1", 0,
control_port_flags) < 0) {
@@ -6045,7 +6107,7 @@ parse_ports(const or_options_t *options, int validate_only,
}
if (! options->ClientOnly) {
if (parse_port_config(ports,
- options->ORPort, options->ORListenAddress,
+ options->ORPort_lines, options->ORListenAddress,
"OR", CONN_TYPE_OR_LISTENER,
"0.0.0.0", 0,
CL_PORT_SERVER_OPTIONS) < 0) {
@@ -6053,7 +6115,7 @@ parse_ports(const or_options_t *options, int validate_only,
goto err;
}
if (parse_port_config(ports,
- options->DirPort, options->DirListenAddress,
+ options->DirPort_lines, options->DirListenAddress,
"Dir", CONN_TYPE_DIR_LISTENER,
"0.0.0.0", 0,
CL_PORT_SERVER_OPTIONS) < 0) {
@@ -6069,6 +6131,25 @@ parse_ports(const or_options_t *options, int validate_only,
*n_ports_out = smartlist_len(ports);
+ retval = 0;
+
+ /* Update the *Port_set options. The !! here is to force a boolean out of
+ an integer. */
+ options->ORPort_set =
+ !! count_real_listeners(ports, CONN_TYPE_OR_LISTENER);
+ options->SocksPort_set =
+ !! count_real_listeners(ports, CONN_TYPE_AP_LISTENER);
+ options->TransPort_set =
+ !! count_real_listeners(ports, CONN_TYPE_AP_TRANS_LISTENER);
+ options->NATDPort_set =
+ !! count_real_listeners(ports, CONN_TYPE_AP_NATD_LISTENER);
+ options->ControlPort_set =
+ !! count_real_listeners(ports, CONN_TYPE_CONTROL_LISTENER);
+ options->DirPort_set =
+ !! count_real_listeners(ports, CONN_TYPE_DIR_LISTENER);
+ options->DNSPort_set =
+ !! count_real_listeners(ports, CONN_TYPE_AP_DNS_LISTENER);
+
if (!validate_only) {
if (configured_ports) {
SMARTLIST_FOREACH(configured_ports,
@@ -6079,7 +6160,6 @@ parse_ports(const or_options_t *options, int validate_only,
ports = NULL; /* prevent free below. */
}
- retval = 0;
err:
if (ports) {
SMARTLIST_FOREACH(ports, port_cfg_t *, p, port_cfg_free(p));
@@ -6620,7 +6700,7 @@ init_libevent(const or_options_t *options)
suppress_libevent_log_msg(NULL);
tor_check_libevent_version(tor_libevent_get_method(),
- get_options()->ORPort != NULL,
+ server_mode(get_options()),
&badness);
if (badness) {
const char *v = tor_libevent_get_version_str();
@@ -7174,6 +7254,43 @@ remove_file_if_very_old(const char *fname, time_t now)
}
}
+/** Return a smartlist of ports that must be forwarded by
+ * tor-fw-helper. The smartlist contains the ports in a string format
+ * that is understandable by tor-fw-helper. */
+smartlist_t *
+get_list_of_ports_to_forward(void)
+{
+ smartlist_t *ports_to_forward = smartlist_new();
+ int port = 0;
+
+ /** XXX TODO tor-fw-helper does not support forwarding ports to
+ other hosts than the local one. If the user is binding to a
+ different IP address, tor-fw-helper won't work. */
+ port = router_get_advertised_or_port(get_options()); /* Get ORPort */
+ if (port)
+ smartlist_add_asprintf(ports_to_forward, "%d:%d", port, port);
+
+ port = router_get_advertised_dir_port(get_options(), 0); /* Get DirPort */
+ if (port)
+ smartlist_add_asprintf(ports_to_forward, "%d:%d", port, port);
+
+ /* Get ports of transport proxies */
+ {
+ smartlist_t *transport_ports = get_transport_proxy_ports();
+ if (transport_ports) {
+ smartlist_add_all(ports_to_forward, transport_ports);
+ smartlist_free(transport_ports);
+ }
+ }
+
+ if (!smartlist_len(ports_to_forward)) {
+ smartlist_free(ports_to_forward);
+ ports_to_forward = NULL;
+ }
+
+ return ports_to_forward;
+}
+
/** Helper to implement GETINFO functions about configuration variables (not
* their values). Given a "config/names" question, set *<b>answer</b> to a
* new string describing the supported configuration variables and their
@@ -7191,6 +7308,9 @@ getinfo_helper_config(control_connection_t *conn,
for (i = 0; _option_vars[i].name; ++i) {
const config_var_t *var = &_option_vars[i];
const char *type;
+ /* don't tell controller about triple-underscore options */
+ if (!strncmp(_option_vars[i].name, "___", 3))
+ continue;
switch (var->type) {
case CONFIG_TYPE_STRING: type = "String"; break;
case CONFIG_TYPE_FILENAME: type = "Filename"; break;
@@ -7220,6 +7340,20 @@ getinfo_helper_config(control_connection_t *conn,
*answer = smartlist_join_strings(sl, "", 0, NULL);
SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
smartlist_free(sl);
+ } else if (!strcmp(question, "config/defaults")) {
+ smartlist_t *sl = smartlist_new();
+ int i;
+ for (i = 0; _option_vars[i].name; ++i) {
+ const config_var_t *var = &_option_vars[i];
+ if (var->initvalue != NULL) {
+ char *val = esc_for_log(var->initvalue);
+ smartlist_add_asprintf(sl, "%s %s\n",var->name,val);
+ tor_free(val);
+ }
+ }
+ *answer = smartlist_join_strings(sl, "", 0, NULL);
+ SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
+ smartlist_free(sl);
}
return 0;
}