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

[tor-commits] [tor/master] hs: Rename service config port object



commit a34885bc8035eb29524749582c16ce4ec8fbc715
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Fri Feb 5 10:58:19 2021 -0500

    hs: Rename service config port object
    
    Remove it from rendservice.c and move everything related to hs_common.{c|h}.
    
    Related to #40266
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/feature/control/control_cmd.c |   7 +-
 src/feature/hs/hs_common.c        | 149 ++++++++++++++++++++++++++++++++++++--
 src/feature/hs/hs_common.h        |   9 ++-
 src/feature/hs/hs_config.c        |   4 +-
 src/feature/hs/hs_metrics.c       |   2 +-
 src/feature/hs/hs_service.c       |   4 +-
 src/feature/hs/hs_service.h       |   2 +-
 src/feature/rend/rendservice.c    | 138 +----------------------------------
 src/feature/rend/rendservice.h    |  10 +--
 src/test/test_controller.c        |  46 ++++++------
 src/test/test_hs.c                |   6 +-
 11 files changed, 186 insertions(+), 191 deletions(-)

diff --git a/src/feature/control/control_cmd.c b/src/feature/control/control_cmd.c
index 737a5927e9..e88f17de09 100644
--- a/src/feature/control/control_cmd.c
+++ b/src/feature/control/control_cmd.c
@@ -1727,8 +1727,7 @@ handle_control_add_onion(control_connection_t *conn,
   for (arg = args->kwargs; arg; arg = arg->next) {
     if (!strcasecmp(arg->key, "Port")) {
       /* "Port=VIRTPORT[,TARGET]". */
-      rend_service_port_config_t *cfg =
-          rend_service_parse_port_config(arg->value, ",", NULL);
+      hs_port_config_t *cfg = hs_parse_port_config(arg->value, ",", NULL);
       if (!cfg) {
         control_write_endreply(conn, 512, "Invalid VIRTPORT/TARGET");
         goto out;
@@ -1987,8 +1986,8 @@ handle_control_add_onion(control_connection_t *conn,
 
  out:
   if (port_cfgs) {
-    SMARTLIST_FOREACH(port_cfgs, rend_service_port_config_t*, p,
-                      rend_service_port_config_free(p));
+    SMARTLIST_FOREACH(port_cfgs, hs_port_config_t*, p,
+                      hs_port_config_free(p));
     smartlist_free(port_cfgs);
   }
 
diff --git a/src/feature/hs/hs_common.c b/src/feature/hs/hs_common.c
index 91cb6d529b..55cc4d5518 100644
--- a/src/feature/hs/hs_common.c
+++ b/src/feature/hs/hs_common.c
@@ -37,6 +37,7 @@
 #include "feature/relay/routermode.h"
 #include "lib/crypt_ops/crypto_rand.h"
 #include "lib/crypt_ops/crypto_util.h"
+#include "lib/net/resolve.h"
 
 #include "core/or/edge_connection_st.h"
 #include "feature/nodelist/networkstatus_st.h"
@@ -57,12 +58,12 @@ static const char *str_ed25519_basepoint =
 
 #ifdef HAVE_SYS_UN_H
 
-/** Given <b>ports</b>, a smarlist containing rend_service_port_config_t,
+/** Given <b>ports</b>, a smarlist containing hs_port_config_t,
  * add the given <b>p</b>, a AF_UNIX port to the list. Return 0 on success
  * else return -ENOSYS if AF_UNIX is not supported (see function in the
  * #else statement below). */
 static int
-add_unix_port(smartlist_t *ports, rend_service_port_config_t *p)
+add_unix_port(smartlist_t *ports, hs_port_config_t *p)
 {
   tor_assert(ports);
   tor_assert(p);
@@ -76,7 +77,7 @@ add_unix_port(smartlist_t *ports, rend_service_port_config_t *p)
  * on success else return -ENOSYS if AF_UNIX is not supported (see function
  * in the #else statement below). */
 static int
-set_unix_port(edge_connection_t *conn, rend_service_port_config_t *p)
+set_unix_port(edge_connection_t *conn, hs_port_config_t *p)
 {
   tor_assert(conn);
   tor_assert(p);
@@ -92,7 +93,7 @@ set_unix_port(edge_connection_t *conn, rend_service_port_config_t *p)
 #else /* !defined(HAVE_SYS_UN_H) */
 
 static int
-set_unix_port(edge_connection_t *conn, rend_service_port_config_t *p)
+set_unix_port(edge_connection_t *conn, hs_port_config_t *p)
 {
   (void) conn;
   (void) p;
@@ -100,7 +101,7 @@ set_unix_port(edge_connection_t *conn, rend_service_port_config_t *p)
 }
 
 static int
-add_unix_port(smartlist_t *ports, rend_service_port_config_t *p)
+add_unix_port(smartlist_t *ports, hs_port_config_t *p)
 {
   (void) ports;
   (void) p;
@@ -859,7 +860,7 @@ hs_get_subcredential(const ed25519_public_key_t *identity_pk,
 int
 hs_set_conn_addr_port(const smartlist_t *ports, edge_connection_t *conn)
 {
-  rend_service_port_config_t *chosen_port;
+  hs_port_config_t *chosen_port;
   unsigned int warn_once = 0;
   smartlist_t *matching_ports;
 
@@ -867,7 +868,7 @@ hs_set_conn_addr_port(const smartlist_t *ports, edge_connection_t *conn)
   tor_assert(conn);
 
   matching_ports = smartlist_new();
-  SMARTLIST_FOREACH_BEGIN(ports, rend_service_port_config_t *, p) {
+  SMARTLIST_FOREACH_BEGIN(ports, hs_port_config_t *, p) {
     if (TO_CONN(conn)->port != p->virtual_port) {
       continue;
     }
@@ -912,6 +913,138 @@ hs_set_conn_addr_port(const smartlist_t *ports, edge_connection_t *conn)
   return (chosen_port) ? 0 : -1;
 }
 
+/** Return a new hs_port_config_t with its path set to
+ * <b>socket_path</b> or empty if <b>socket_path</b> is NULL */
+static hs_port_config_t *
+hs_port_config_new(const char *socket_path)
+{
+  if (!socket_path)
+    return tor_malloc_zero(sizeof(hs_port_config_t) + 1);
+
+  const size_t pathlen = strlen(socket_path) + 1;
+  hs_port_config_t *conf =
+    tor_malloc_zero(sizeof(hs_port_config_t) + pathlen);
+  memcpy(conf->unix_addr, socket_path, pathlen);
+  conf->is_unix_addr = 1;
+  return conf;
+}
+
+/** Parses a virtual-port to real-port/socket mapping separated by
+ * the provided separator and returns a new hs_port_config_t,
+ * or NULL and an optional error string on failure.
+ *
+ * The format is: VirtualPort SEP (IP|RealPort|IP:RealPort|'socket':path)?
+ *
+ * IP defaults to 127.0.0.1; RealPort defaults to VirtualPort.
+ */
+hs_port_config_t *
+hs_parse_port_config(const char *string, const char *sep,
+                               char **err_msg_out)
+{
+  smartlist_t *sl;
+  int virtport;
+  int realport = 0;
+  uint16_t p;
+  tor_addr_t addr;
+  hs_port_config_t *result = NULL;
+  unsigned int is_unix_addr = 0;
+  const char *socket_path = NULL;
+  char *err_msg = NULL;
+  char *addrport = NULL;
+
+  sl = smartlist_new();
+  smartlist_split_string(sl, string, sep,
+                         SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
+  if (smartlist_len(sl) < 1 || BUG(smartlist_len(sl) > 2)) {
+    err_msg = tor_strdup("Bad syntax in hidden service port configuration.");
+    goto err;
+  }
+  virtport = (int)tor_parse_long(smartlist_get(sl,0), 10, 1, 65535, NULL,NULL);
+  if (!virtport) {
+    tor_asprintf(&err_msg, "Missing or invalid port %s in hidden service "
+                   "port configuration", escaped(smartlist_get(sl,0)));
+
+    goto err;
+  }
+  if (smartlist_len(sl) == 1) {
+    /* No addr:port part; use default. */
+    realport = virtport;
+    tor_addr_from_ipv4h(&addr, 0x7F000001u); /* 127.0.0.1 */
+  } else {
+    int ret;
+
+    const char *addrport_element = smartlist_get(sl,1);
+    const char *rest = NULL;
+    int is_unix;
+    ret = port_cfg_line_extract_addrport(addrport_element, &addrport,
+                                         &is_unix, &rest);
+
+    if (ret < 0) {
+      tor_asprintf(&err_msg, "Couldn't process address <%s> from hidden "
+                   "service configuration", addrport_element);
+      goto err;
+    }
+
+    if (rest && strlen(rest)) {
+      err_msg = tor_strdup("HiddenServicePort parse error: invalid port "
+                           "mapping");
+      goto err;
+    }
+
+    if (is_unix) {
+      socket_path = addrport;
+      is_unix_addr = 1;
+    } else if (strchr(addrport, ':') || strchr(addrport, '.')) {
+      /* else try it as an IP:port pair if it has a : or . in it */
+      if (tor_addr_port_lookup(addrport, &addr, &p)<0) {
+        err_msg = tor_strdup("Unparseable address in hidden service port "
+                             "configuration.");
+        goto err;
+      }
+      realport = p?p:virtport;
+    } else {
+      /* No addr:port, no addr -- must be port. */
+      realport = (int)tor_parse_long(addrport, 10, 1, 65535, NULL, NULL);
+      if (!realport) {
+        tor_asprintf(&err_msg, "Unparseable or out-of-range port %s in "
+                     "hidden service port configuration.",
+                     escaped(addrport));
+        goto err;
+      }
+      tor_addr_from_ipv4h(&addr, 0x7F000001u); /* Default to 127.0.0.1 */
+    }
+  }
+
+  /* Allow room for unix_addr */
+  result = hs_port_config_new(socket_path);
+  result->virtual_port = virtport;
+  result->is_unix_addr = is_unix_addr;
+  if (!is_unix_addr) {
+    result->real_port = realport;
+    tor_addr_copy(&result->real_addr, &addr);
+    result->unix_addr[0] = '\0';
+  }
+
+ err:
+  tor_free(addrport);
+  if (err_msg_out != NULL) {
+    *err_msg_out = err_msg;
+  } else {
+    tor_free(err_msg);
+  }
+  SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
+  smartlist_free(sl);
+
+  return result;
+}
+
+/** Release all storage held in a hs_port_config_t. */
+void
+hs_port_config_free_(hs_port_config_t *p)
+{
+  tor_free(p);
+}
+
 /** Using a base32 representation of a service address, parse its content into
  * the key_out, checksum_out and version_out. Any out variable can be NULL in
  * case the caller would want only one field. checksum_out MUST at least be 2
@@ -1140,7 +1273,7 @@ hs_service_requires_uptime_circ(const smartlist_t *ports)
 {
   tor_assert(ports);
 
-  SMARTLIST_FOREACH_BEGIN(ports, rend_service_port_config_t *, p) {
+  SMARTLIST_FOREACH_BEGIN(ports, hs_port_config_t *, p) {
     if (smartlist_contains_int_as_string(get_options()->LongLivedPorts,
                                          p->virtual_port)) {
       return 1;
diff --git a/src/feature/hs/hs_common.h b/src/feature/hs/hs_common.h
index 4a9c7a9918..894b0e4844 100644
--- a/src/feature/hs/hs_common.h
+++ b/src/feature/hs/hs_common.h
@@ -150,7 +150,7 @@ typedef enum {
 
 /** Represents the mapping from a virtual port of a rendezvous service to a
  * real port on some IP. */
-typedef struct rend_service_port_config_t {
+typedef struct hs_port_config_t {
   /** The incoming HS virtual port we're mapping */
   uint16_t virtual_port;
   /** Is this an AF_UNIX port? */
@@ -161,7 +161,7 @@ typedef struct rend_service_port_config_t {
   tor_addr_t real_addr;
   /** The socket path to connect to, if is_unix_addr */
   char unix_addr[FLEXIBLE_ARRAY_MEMBER];
-} rend_service_port_config_t;
+} hs_port_config_t;
 
 void hs_init(void);
 void hs_free_all(void);
@@ -260,6 +260,11 @@ void hs_purge_hid_serv_from_last_hid_serv_requests(const char *desc_id);
 void hs_purge_last_hid_serv_requests(void);
 
 int hs_set_conn_addr_port(const smartlist_t *ports, edge_connection_t *conn);
+hs_port_config_t *hs_parse_port_config(const char *string, const char *sep,
+                                       char **err_msg_out);
+void hs_port_config_free_(hs_port_config_t *p);
+#define hs_port_config_free(p) \
+  FREE_AND_NULL(hs_port_config_t, hs_port_config_free_, (p))
 
 void hs_inc_rdv_stream_counter(origin_circuit_t *circ);
 void hs_dec_rdv_stream_counter(origin_circuit_t *circ);
diff --git a/src/feature/hs/hs_config.c b/src/feature/hs/hs_config.c
index 403ea151c4..b100acfcd4 100644
--- a/src/feature/hs/hs_config.c
+++ b/src/feature/hs/hs_config.c
@@ -487,8 +487,8 @@ config_generic_service(const hs_opts_t *hs_opts,
        portline; portline = portline->next) {
     char *err_msg = NULL;
     /* XXX: Can we rename this? */
-    rend_service_port_config_t *portcfg =
-      rend_service_parse_port_config(portline->value, " ", &err_msg);
+    hs_port_config_t *portcfg =
+      hs_parse_port_config(portline->value, " ", &err_msg);
     if (!portcfg) {
       if (err_msg) {
         log_warn(LD_CONFIG, "%s", err_msg);
diff --git a/src/feature/hs/hs_metrics.c b/src/feature/hs/hs_metrics.c
index 67cae8ec0e..9688859d66 100644
--- a/src/feature/hs/hs_metrics.c
+++ b/src/feature/hs/hs_metrics.c
@@ -64,7 +64,7 @@ init_store(hs_service_t *service)
                         format_label("onion", service->onion_address));
     if (base_metrics[i].port_as_label && service->config.ports) {
       SMARTLIST_FOREACH_BEGIN(service->config.ports,
-                              const rend_service_port_config_t *, p) {
+                              const hs_port_config_t *, p) {
         metrics_store_entry_add_label(entry,
                       format_label("port", port_to_str(p->virtual_port)));
       } SMARTLIST_FOREACH_END(p);
diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c
index f0c493d91d..b33013ba1f 100644
--- a/src/feature/hs/hs_service.c
+++ b/src/feature/hs/hs_service.c
@@ -264,8 +264,8 @@ service_clear_config(hs_service_config_t *config)
   }
   tor_free(config->directory_path);
   if (config->ports) {
-    SMARTLIST_FOREACH(config->ports, rend_service_port_config_t *, p,
-                      rend_service_port_config_free(p););
+    SMARTLIST_FOREACH(config->ports, hs_port_config_t *, p,
+                      hs_port_config_free(p););
     smartlist_free(config->ports);
   }
   if (config->clients) {
diff --git a/src/feature/hs/hs_service.h b/src/feature/hs/hs_service.h
index 6a39dee037..54d646d3e4 100644
--- a/src/feature/hs/hs_service.h
+++ b/src/feature/hs/hs_service.h
@@ -210,7 +210,7 @@ typedef struct hs_service_config_t {
   /** Have we explicitly set HiddenServiceVersion? */
   unsigned int hs_version_explicitly_set : 1;
 
-  /** List of rend_service_port_config_t */
+  /** List of hs_port_config_t */
   smartlist_t *ports;
 
   /** Path on the filesystem where the service persistent data is stored. NULL
diff --git a/src/feature/rend/rendservice.c b/src/feature/rend/rendservice.c
index 2be68eadbe..a744f6f93a 100644
--- a/src/feature/rend/rendservice.c
+++ b/src/feature/rend/rendservice.c
@@ -237,8 +237,8 @@ rend_service_free_(rend_service_t *service)
 
   tor_free(service->directory);
   if (service->ports) {
-    SMARTLIST_FOREACH(service->ports, rend_service_port_config_t*, p,
-                      rend_service_port_config_free(p));
+    SMARTLIST_FOREACH(service->ports, hs_port_config_t*, p,
+                      hs_port_config_free(p));
     smartlist_free(service->ports);
   }
   if (service->private_key)
@@ -355,7 +355,7 @@ static int
 rend_add_service(smartlist_t *service_list, rend_service_t *service)
 {
   int i;
-  rend_service_port_config_t *p;
+  hs_port_config_t *p;
 
   tor_assert(service);
 
@@ -408,138 +408,6 @@ rend_add_service(smartlist_t *service_list, rend_service_t *service)
   return 0;
 }
 
-/** Return a new rend_service_port_config_t with its path set to
- * <b>socket_path</b> or empty if <b>socket_path</b> is NULL */
-static rend_service_port_config_t *
-rend_service_port_config_new(const char *socket_path)
-{
-  if (!socket_path)
-    return tor_malloc_zero(sizeof(rend_service_port_config_t) + 1);
-
-  const size_t pathlen = strlen(socket_path) + 1;
-  rend_service_port_config_t *conf =
-    tor_malloc_zero(sizeof(rend_service_port_config_t) + pathlen);
-  memcpy(conf->unix_addr, socket_path, pathlen);
-  conf->is_unix_addr = 1;
-  return conf;
-}
-
-/** Parses a virtual-port to real-port/socket mapping separated by
- * the provided separator and returns a new rend_service_port_config_t,
- * or NULL and an optional error string on failure.
- *
- * The format is: VirtualPort SEP (IP|RealPort|IP:RealPort|'socket':path)?
- *
- * IP defaults to 127.0.0.1; RealPort defaults to VirtualPort.
- */
-rend_service_port_config_t *
-rend_service_parse_port_config(const char *string, const char *sep,
-                               char **err_msg_out)
-{
-  smartlist_t *sl;
-  int virtport;
-  int realport = 0;
-  uint16_t p;
-  tor_addr_t addr;
-  rend_service_port_config_t *result = NULL;
-  unsigned int is_unix_addr = 0;
-  const char *socket_path = NULL;
-  char *err_msg = NULL;
-  char *addrport = NULL;
-
-  sl = smartlist_new();
-  smartlist_split_string(sl, string, sep,
-                         SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
-  if (smartlist_len(sl) < 1 || BUG(smartlist_len(sl) > 2)) {
-    err_msg = tor_strdup("Bad syntax in hidden service port configuration.");
-    goto err;
-  }
-  virtport = (int)tor_parse_long(smartlist_get(sl,0), 10, 1, 65535, NULL,NULL);
-  if (!virtport) {
-    tor_asprintf(&err_msg, "Missing or invalid port %s in hidden service "
-                   "port configuration", escaped(smartlist_get(sl,0)));
-
-    goto err;
-  }
-  if (smartlist_len(sl) == 1) {
-    /* No addr:port part; use default. */
-    realport = virtport;
-    tor_addr_from_ipv4h(&addr, 0x7F000001u); /* 127.0.0.1 */
-  } else {
-    int ret;
-
-    const char *addrport_element = smartlist_get(sl,1);
-    const char *rest = NULL;
-    int is_unix;
-    ret = port_cfg_line_extract_addrport(addrport_element, &addrport,
-                                         &is_unix, &rest);
-
-    if (ret < 0) {
-      tor_asprintf(&err_msg, "Couldn't process address <%s> from hidden "
-                   "service configuration", addrport_element);
-      goto err;
-    }
-
-    if (rest && strlen(rest)) {
-      err_msg = tor_strdup("HiddenServicePort parse error: invalid port "
-                           "mapping");
-      goto err;
-    }
-
-    if (is_unix) {
-      socket_path = addrport;
-      is_unix_addr = 1;
-    } else if (strchr(addrport, ':') || strchr(addrport, '.')) {
-      /* else try it as an IP:port pair if it has a : or . in it */
-      if (tor_addr_port_lookup(addrport, &addr, &p)<0) {
-        err_msg = tor_strdup("Unparseable address in hidden service port "
-                             "configuration.");
-        goto err;
-      }
-      realport = p?p:virtport;
-    } else {
-      /* No addr:port, no addr -- must be port. */
-      realport = (int)tor_parse_long(addrport, 10, 1, 65535, NULL, NULL);
-      if (!realport) {
-        tor_asprintf(&err_msg, "Unparseable or out-of-range port %s in "
-                     "hidden service port configuration.",
-                     escaped(addrport));
-        goto err;
-      }
-      tor_addr_from_ipv4h(&addr, 0x7F000001u); /* Default to 127.0.0.1 */
-    }
-  }
-
-  /* Allow room for unix_addr */
-  result = rend_service_port_config_new(socket_path);
-  result->virtual_port = virtport;
-  result->is_unix_addr = is_unix_addr;
-  if (!is_unix_addr) {
-    result->real_port = realport;
-    tor_addr_copy(&result->real_addr, &addr);
-    result->unix_addr[0] = '\0';
-  }
-
- err:
-  tor_free(addrport);
-  if (err_msg_out != NULL) {
-    *err_msg_out = err_msg;
-  } else {
-    tor_free(err_msg);
-  }
-  SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
-  smartlist_free(sl);
-
-  return result;
-}
-
-/** Release all storage held in a rend_service_port_config_t. */
-void
-rend_service_port_config_free_(rend_service_port_config_t *p)
-{
-  tor_free(p);
-}
-
 /* Copy relevant data from service src to dst while pruning the service lists.
  * This should only be called during the pruning process which takes existing
  * services and copy their data to the newly configured services. The src
diff --git a/src/feature/rend/rendservice.h b/src/feature/rend/rendservice.h
index 012afc0f9f..cd44787ce2 100644
--- a/src/feature/rend/rendservice.h
+++ b/src/feature/rend/rendservice.h
@@ -71,7 +71,7 @@ typedef struct rend_service_t {
                     * this service is ephemeral. */
   int dir_group_readable; /**< if 1, allow group read
                              permissions on directory */
-  smartlist_t *ports; /**< List of rend_service_port_config_t */
+  smartlist_t *ports; /**< List of hs_port_config_t */
   rend_auth_type_t auth_type; /**< Client authorization type or 0 if no client
                                * authorization is performed. */
   smartlist_t *clients; /**< List of rend_authorized_client_t's of
@@ -189,14 +189,6 @@ void rend_service_dump_stats(int severity);
 void rend_service_free_all(void);
 void rend_service_init(void);
 
-rend_service_port_config_t *rend_service_parse_port_config(const char *string,
-                                                           const char *sep,
-                                                           char **err_msg_out);
-void rend_service_port_config_free_(rend_service_port_config_t *p);
-#define rend_service_port_config_free(p) \
-  FREE_AND_NULL(rend_service_port_config_t, rend_service_port_config_free_, \
-                (p))
-
 void rend_authorized_client_free_(rend_authorized_client_t *client);
 #define rend_authorized_client_free(client) \
   FREE_AND_NULL(rend_authorized_client_t, rend_authorized_client_free_, \
diff --git a/src/test/test_controller.c b/src/test/test_controller.c
index 49efeb5f88..0745651aca 100644
--- a/src/test/test_controller.c
+++ b/src/test/test_controller.c
@@ -460,50 +460,50 @@ test_getinfo_helper_onion(void *arg)
 }
 
 static void
-test_rend_service_parse_port_config(void *arg)
+test_hs_parse_port_config(void *arg)
 {
   const char *sep = ",";
-  rend_service_port_config_t *cfg = NULL;
+  hs_port_config_t *cfg = NULL;
   char *err_msg = NULL;
 
   (void)arg;
 
   /* Test "VIRTPORT" only. */
-  cfg = rend_service_parse_port_config("80", sep, &err_msg);
+  cfg = hs_parse_port_config("80", sep, &err_msg);
   tt_assert(cfg);
   tt_ptr_op(err_msg, OP_EQ, NULL);
 
   /* Test "VIRTPORT,TARGET" (Target is port). */
-  rend_service_port_config_free(cfg);
-  cfg = rend_service_parse_port_config("80,8080", sep, &err_msg);
+  hs_port_config_free(cfg);
+  cfg = hs_parse_port_config("80,8080", sep, &err_msg);
   tt_assert(cfg);
   tt_ptr_op(err_msg, OP_EQ, NULL);
 
   /* Test "VIRTPORT,TARGET" (Target is IPv4:port). */
-  rend_service_port_config_free(cfg);
-  cfg = rend_service_parse_port_config("80,192.0.2.1:8080", sep, &err_msg);
+  hs_port_config_free(cfg);
+  cfg = hs_parse_port_config("80,192.0.2.1:8080", sep, &err_msg);
   tt_assert(cfg);
   tt_ptr_op(err_msg, OP_EQ, NULL);
 
   /* Test "VIRTPORT,TARGET" (Target is IPv6:port). */
-  rend_service_port_config_free(cfg);
-  cfg = rend_service_parse_port_config("80,[2001:db8::1]:8080", sep, &err_msg);
+  hs_port_config_free(cfg);
+  cfg = hs_parse_port_config("80,[2001:db8::1]:8080", sep, &err_msg);
   tt_assert(cfg);
   tt_ptr_op(err_msg, OP_EQ, NULL);
-  rend_service_port_config_free(cfg);
+  hs_port_config_free(cfg);
   cfg = NULL;
 
   /* XXX: Someone should add tests for AF_UNIX targets if supported. */
 
   /* Test empty config. */
-  rend_service_port_config_free(cfg);
-  cfg = rend_service_parse_port_config("", sep, &err_msg);
+  hs_port_config_free(cfg);
+  cfg = hs_parse_port_config("", sep, &err_msg);
   tt_ptr_op(cfg, OP_EQ, NULL);
   tt_assert(err_msg);
 
   /* Test invalid port. */
   tor_free(err_msg);
-  cfg = rend_service_parse_port_config("90001", sep, &err_msg);
+  cfg = hs_parse_port_config("90001", sep, &err_msg);
   tt_ptr_op(cfg, OP_EQ, NULL);
   tt_assert(err_msg);
   tor_free(err_msg);
@@ -513,24 +513,24 @@ test_rend_service_parse_port_config(void *arg)
 
   /* quoted unix port */
   tor_free(err_msg);
-  cfg = rend_service_parse_port_config("100 unix:\"/tmp/foo bar\"",
+  cfg = hs_parse_port_config("100 unix:\"/tmp/foo bar\"",
                                        " ", &err_msg);
   tt_assert(cfg);
   tt_ptr_op(err_msg, OP_EQ, NULL);
-  rend_service_port_config_free(cfg);
+  hs_port_config_free(cfg);
   cfg = NULL;
 
   /* quoted unix port */
   tor_free(err_msg);
-  cfg = rend_service_parse_port_config("100 unix:\"/tmp/foo bar\"",
+  cfg = hs_parse_port_config("100 unix:\"/tmp/foo bar\"",
                                        " ", &err_msg);
   tt_assert(cfg);
   tt_ptr_op(err_msg, OP_EQ, NULL);
-  rend_service_port_config_free(cfg);
+  hs_port_config_free(cfg);
   cfg = NULL;
 
   /* quoted unix port, missing end quote */
-  cfg = rend_service_parse_port_config("100 unix:\"/tmp/foo bar",
+  cfg = hs_parse_port_config("100 unix:\"/tmp/foo bar",
                                        " ", &err_msg);
   tt_ptr_op(cfg, OP_EQ, NULL);
   tt_str_op(err_msg, OP_EQ, "Couldn't process address <unix:\"/tmp/foo bar> "
@@ -539,7 +539,7 @@ test_rend_service_parse_port_config(void *arg)
 
   /* bogus IP address */
   MOCK(tor_addr_lookup, mock_tor_addr_lookup__fail_on_bad_addrs);
-  cfg = rend_service_parse_port_config("100 foo!!.example.com:9000",
+  cfg = hs_parse_port_config("100 foo!!.example.com:9000",
                                        " ", &err_msg);
   UNMOCK(tor_addr_lookup);
   tt_ptr_op(cfg, OP_EQ, NULL);
@@ -548,7 +548,7 @@ test_rend_service_parse_port_config(void *arg)
   tor_free(err_msg);
 
   /* bogus port port */
-  cfg = rend_service_parse_port_config("100 99999",
+  cfg = hs_parse_port_config("100 99999",
                                        " ", &err_msg);
   tt_ptr_op(cfg, OP_EQ, NULL);
   tt_str_op(err_msg, OP_EQ, "Unparseable or out-of-range port \"99999\" "
@@ -556,14 +556,14 @@ test_rend_service_parse_port_config(void *arg)
   tor_free(err_msg);
 
   /* Wrong target address and port separation */
-  cfg = rend_service_parse_port_config("80,127.0.0.1 1234", sep,
+  cfg = hs_parse_port_config("80,127.0.0.1 1234", sep,
                                        &err_msg);
   tt_ptr_op(cfg, OP_EQ, NULL);
   tt_assert(err_msg);
   tor_free(err_msg);
 
  done:
-  rend_service_port_config_free(cfg);
+  hs_port_config_free(cfg);
   tor_free(err_msg);
 }
 
@@ -2214,7 +2214,7 @@ struct testcase_t controller_tests[] = {
   { "add_onion_helper_keyarg_v3", test_add_onion_helper_keyarg_v3, 0,
     NULL, NULL },
   { "getinfo_helper_onion", test_getinfo_helper_onion, 0, NULL, NULL },
-  { "rend_service_parse_port_config", test_rend_service_parse_port_config, 0,
+  { "hs_parse_port_config", test_hs_parse_port_config, 0,
     NULL, NULL },
   { "add_onion_helper_clientauth", test_add_onion_helper_clientauth, 0, NULL,
     NULL },
diff --git a/src/test/test_hs.c b/src/test/test_hs.c
index 46b4493a3d..42e663330a 100644
--- a/src/test/test_hs.c
+++ b/src/test/test_hs.c
@@ -646,14 +646,12 @@ test_single_onion_poisoning(void *arg)
   /* Add port to service 1 */
   service_1->ports = smartlist_new();
   service_2->ports = smartlist_new();
-  rend_service_port_config_t *port1 = rend_service_parse_port_config("80", " ",
-                                                                     &err_msg);
+  hs_port_config_t *port1 = hs_parse_port_config("80", " ", &err_msg);
   tt_assert(port1);
   tt_ptr_op(err_msg, OP_EQ, NULL);
   smartlist_add(service_1->ports, port1);
 
-  rend_service_port_config_t *port2 = rend_service_parse_port_config("90", " ",
-                                                                     &err_msg);
+  hs_port_config_t *port2 = hs_parse_port_config("90", " ", &err_msg);
   /* Add port to service 2 */
   tt_assert(port2);
   tt_ptr_op(err_msg, OP_EQ, NULL);



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