aboutsummaryrefslogtreecommitdiff
path: root/src/feature/rend
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2021-02-05 10:58:19 -0500
committerDavid Goulet <dgoulet@torproject.org>2021-02-19 13:19:08 -0500
commita34885bc8035eb29524749582c16ce4ec8fbc715 (patch)
treee9754d86f0165eaabf9dfd50a80d439f759434ce /src/feature/rend
parent2444629c86e3368ebd6c9ee1b54aa5a5959fa398 (diff)
downloadtor-a34885bc8035eb29524749582c16ce4ec8fbc715.tar.gz
tor-a34885bc8035eb29524749582c16ce4ec8fbc715.zip
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@torproject.org>
Diffstat (limited to 'src/feature/rend')
-rw-r--r--src/feature/rend/rendservice.c138
-rw-r--r--src/feature/rend/rendservice.h10
2 files changed, 4 insertions, 144 deletions
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_, \