[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] config: Change Address to be a LINELIST



commit 47f9edde699ad687884b6222b557c10dee2592c9
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Mon Jun 15 15:02:08 2020 -0400

    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@xxxxxxxxxxxxxx>
---
 src/app/config/config.c          |  4 ++--
 src/app/config/or_options_st.h   |  5 ++++-
 src/app/config/resolve_addr.c    |  7 ++++---
 src/app/main/main.c              |  3 +--
 src/feature/relay/relay_config.c |  2 +-
 src/test/test_config.c           | 35 ++++++++++++++++++-----------------
 6 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 71f8c18ca..286cd9304 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 bf58205f8..2f375f5d9 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 9d1a8e026..5723a00fa 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 dc39611f9..32c34ea82 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 fac6a2f57..7b43b5742 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 095eb24c4..2b4450532 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);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits