aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-06-15 15:02:08 -0400
committerDavid Goulet <dgoulet@torproject.org>2020-06-23 09:25:36 -0400
commit47f9edde699ad687884b6222b557c10dee2592c9 (patch)
tree0c9d84200f85884e5f20ddb1f679684c2f4439c1
parentd3bcbccab9d50fd0dafc682f7ee63902ea344be7 (diff)
downloadtor-47f9edde699ad687884b6222b557c10dee2592c9.tar.gz
tor-47f9edde699ad687884b6222b557c10dee2592c9.zip
config: Change Address to be a LINELIST
With prop312, we want to support IPv4 and IPv6 thus multiple Address statement (up to 2) will be accepted. For this, "Address" option becomes a LINELIST so we can properly process the IPv4 or/and IPv6. Part of #33233 Signed-off-by: David Goulet <dgoulet@torproject.org>
-rw-r--r--src/app/config/config.c4
-rw-r--r--src/app/config/or_options_st.h5
-rw-r--r--src/app/config/resolve_addr.c7
-rw-r--r--src/app/main/main.c3
-rw-r--r--src/feature/relay/relay_config.c2
-rw-r--r--src/test/test_config.c35
6 files changed, 30 insertions, 26 deletions
diff --git a/src/app/config/config.c b/src/app/config/config.c
index 71f8c18ca2..286cd9304a 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -313,7 +313,7 @@ static const config_var_t option_vars_[] = {
V(AccountingMax, MEMUNIT, "0 bytes"),
VAR("AccountingRule", STRING, AccountingRule_option, "max"),
V(AccountingStart, STRING, NULL),
- V(Address, STRING, NULL),
+ V(Address, LINELIST, NULL),
OBSOLETE("AllowDotExit"),
OBSOLETE("AllowInvalidNodes"),
V(AllowNonRFC953Hostnames, BOOL, "0"),
@@ -4028,7 +4028,7 @@ options_check_transition_cb(const void *old_,
if (! CFG_EQ_INT(old, new_val, opt)) \
BAD_CHANGE_TO(opt," with Sandbox active")
- SB_NOCHANGE_STR(Address);
+ SB_NOCHANGE_LINELIST(Address);
SB_NOCHANGE_STR(ServerDNSResolvConfFile);
SB_NOCHANGE_STR(DirPortFrontPage);
SB_NOCHANGE_STR(CookieAuthFile);
diff --git a/src/app/config/or_options_st.h b/src/app/config/or_options_st.h
index bf58205f89..2f375f5d9b 100644
--- a/src/app/config/or_options_st.h
+++ b/src/app/config/or_options_st.h
@@ -71,7 +71,10 @@ struct or_options_t {
int CacheDirectoryGroupReadable; /**< Boolean: Is the CacheDirectory g+r? */
char *Nickname; /**< OR only: nickname of this onion router. */
- char *Address; /**< OR only: configured address for this onion router. */
+ /** OR only: configured address for this onion router. Up to two times this
+ * options is accepted as in IPv4 and IPv6. */
+ struct config_line_t *Address;
+
char *PidFile; /**< Where to store PID of Tor process. */
struct routerset_t *ExitNodes; /**< Structure containing nicknames, digests,
diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c
index 9d1a8e0260..5723a00fa7 100644
--- a/src/app/config/resolve_addr.c
+++ b/src/app/config/resolve_addr.c
@@ -15,6 +15,7 @@
#include "feature/control/control_events.h"
+#include "lib/encoding/confline.h"
#include "lib/net/gethostname.h"
#include "lib/net/resolve.h"
@@ -97,7 +98,6 @@ resolve_my_address(int warn_severity, const or_options_t *options,
int explicit_hostname=1;
int from_interface=0;
char *addr_string = NULL;
- const char *address = options->Address;
int notice_severity = warn_severity <= LOG_NOTICE ?
LOG_NOTICE : warn_severity;
@@ -108,8 +108,9 @@ resolve_my_address(int warn_severity, const or_options_t *options,
* Step one: Fill in 'hostname' to be our best guess.
*/
- if (address && *address) {
- strlcpy(hostname, address, sizeof(hostname));
+ if (options->Address) {
+ /* Only 1 Address is supported even though this is a list. */
+ strlcpy(hostname, options->Address->value, sizeof(hostname));
log_debug(LD_CONFIG, "Trying configured Address '%s' as local hostname",
hostname);
} else { /* then we need to guess our address */
diff --git a/src/app/main/main.c b/src/app/main/main.c
index dc39611f98..32c34ea821 100644
--- a/src/app/main/main.c
+++ b/src/app/main/main.c
@@ -795,8 +795,7 @@ do_dump_config(void)
static void
init_addrinfo(void)
{
- if (! server_mode(get_options()) ||
- (get_options()->Address && strlen(get_options()->Address) > 0)) {
+ if (! server_mode(get_options()) || get_options()->Address) {
/* We don't need to seed our own hostname, because we won't be calling
* resolve_my_address on it.
*/
diff --git a/src/feature/relay/relay_config.c b/src/feature/relay/relay_config.c
index fac6a2f577..7b43b57423 100644
--- a/src/feature/relay/relay_config.c
+++ b/src/feature/relay/relay_config.c
@@ -1029,7 +1029,7 @@ options_transition_affects_descriptor(const or_options_t *old_options,
YES_IF_CHANGED_STRING(DataDirectory);
YES_IF_CHANGED_STRING(Nickname);
- YES_IF_CHANGED_STRING(Address);
+ YES_IF_CHANGED_LINELIST(Address);
YES_IF_CHANGED_LINELIST(ExitPolicy);
YES_IF_CHANGED_BOOL(ExitRelay);
YES_IF_CHANGED_BOOL(ExitPolicyRejectPrivate);
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 095eb24c49..2b44505329 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -1190,6 +1190,7 @@ test_config_resolve_my_address(void *arg)
{
or_options_t *options;
uint32_t resolved_addr;
+ char buf[1024];
const char *method_used;
char *hostname_out = NULL;
int retval;
@@ -1215,8 +1216,8 @@ test_config_resolve_my_address(void *arg)
* If options->Address is a valid IPv4 address string, we want
* the corresponding address to be parsed and returned.
*/
-
- options->Address = tor_strdup("128.52.128.105");
+ strlcpy(buf, "Address 128.52.128.105\n", sizeof(buf));
+ config_get_lines(buf, &(options->Address), 0);
retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr,
&method_used,&hostname_out);
@@ -1226,7 +1227,7 @@ test_config_resolve_my_address(void *arg)
tt_want(hostname_out == NULL);
tt_assert(resolved_addr == 0x80348069);
- tor_free(options->Address);
+ config_free_lines(options->Address);
/*
* CASE 2:
@@ -1237,8 +1238,8 @@ test_config_resolve_my_address(void *arg)
MOCK(tor_lookup_hostname,tor_lookup_hostname_01010101);
- tor_free(options->Address);
- options->Address = tor_strdup("www.torproject.org");
+ strlcpy(buf, "Address www.torproject.org\n", sizeof(buf));
+ config_get_lines(buf, &(options->Address), 0);
prev_n_hostname_01010101 = n_hostname_01010101;
@@ -1253,7 +1254,7 @@ test_config_resolve_my_address(void *arg)
UNMOCK(tor_lookup_hostname);
- tor_free(options->Address);
+ config_free_lines(options->Address);
tor_free(hostname_out);
/*
@@ -1264,7 +1265,6 @@ test_config_resolve_my_address(void *arg)
*/
resolved_addr = 0;
- tor_free(options->Address);
options->Address = NULL;
MOCK(tor_gethostname,tor_gethostname_replacement);
@@ -1295,8 +1295,8 @@ test_config_resolve_my_address(void *arg)
*/
resolved_addr = 0;
- tor_free(options->Address);
- options->Address = tor_strdup("127.0.0.1");
+ strlcpy(buf, "Address 127.0.0.1\n", sizeof(buf));
+ config_get_lines(buf, &(options->Address), 0);
retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr,
&method_used,&hostname_out);
@@ -1304,7 +1304,7 @@ test_config_resolve_my_address(void *arg)
tt_want(resolved_addr == 0);
tt_int_op(retval, OP_EQ, -1);
- tor_free(options->Address);
+ config_free_lines(options->Address);
tor_free(hostname_out);
/*
@@ -1317,8 +1317,8 @@ test_config_resolve_my_address(void *arg)
prev_n_hostname_failure = n_hostname_failure;
- tor_free(options->Address);
- options->Address = tor_strdup("www.tor-project.org");
+ strlcpy(buf, "Address www.tor-project.org\n", sizeof(buf));
+ config_get_lines(buf, &(options->Address), 0);
retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr,
&method_used,&hostname_out);
@@ -1328,7 +1328,8 @@ test_config_resolve_my_address(void *arg)
UNMOCK(tor_lookup_hostname);
- tor_free(options->Address);
+ config_free_lines(options->Address);
+ options->Address = NULL;
tor_free(hostname_out);
/*
@@ -1451,8 +1452,8 @@ test_config_resolve_my_address(void *arg)
prev_n_hostname_failure = n_hostname_failure;
- tor_free(options->Address);
- options->Address = tor_strdup("some_hostname");
+ strlcpy(buf, "Address some_hostname\n", sizeof(buf));
+ config_get_lines(buf, &(options->Address), 0);
retval = resolve_my_address(LOG_NOTICE, options, &resolved_addr,
&method_used,&hostname_out);
@@ -1484,7 +1485,7 @@ test_config_resolve_my_address(void *arg)
* and address from step 6.
*/
- tor_free(options->Address);
+ config_free_lines(options->Address);
options->Address = NULL;
MOCK(tor_gethostname,tor_gethostname_replacement);
@@ -1563,7 +1564,7 @@ test_config_resolve_my_address(void *arg)
UNMOCK(tor_gethostname);
done:
- tor_free(options->Address);
+ config_free_lines(options->Address);
tor_free(options->DirAuthorities);
or_options_free(options);
tor_free(hostname_out);