mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Refactor config free logic to use a single path.
The right way to free a config object is now to wrap config_free(), always. Instead of creating an alternative free function, objects should provide an alternative clear callback to free any fields that the configuration manager doesn't manage. This lets us simplify our code a little, and lets us extend the confparse.c code to manage additional fields in config_free.
This commit is contained in:
parent
3d1f9f583a
commit
47654d3249
@ -843,9 +843,9 @@ static void config_maybe_load_geoip_files_(const or_options_t *options,
|
|||||||
static int options_validate_cb(void *old_options, void *options,
|
static int options_validate_cb(void *old_options, void *options,
|
||||||
void *default_options,
|
void *default_options,
|
||||||
int from_setconf, char **msg);
|
int from_setconf, char **msg);
|
||||||
static void options_free_cb(const config_mgr_t *, void *options);
|
|
||||||
static void cleanup_protocol_warning_severity_level(void);
|
static void cleanup_protocol_warning_severity_level(void);
|
||||||
static void set_protocol_warning_severity_level(int warning_severity);
|
static void set_protocol_warning_severity_level(int warning_severity);
|
||||||
|
static void options_clear_cb(const config_mgr_t *mgr, void *opts);
|
||||||
|
|
||||||
/** Magic value for or_options_t. */
|
/** Magic value for or_options_t. */
|
||||||
#define OR_OPTIONS_MAGIC 9090909
|
#define OR_OPTIONS_MAGIC 9090909
|
||||||
@ -862,8 +862,8 @@ static const config_format_t options_format = {
|
|||||||
option_deprecation_notes_,
|
option_deprecation_notes_,
|
||||||
option_vars_,
|
option_vars_,
|
||||||
options_validate_cb,
|
options_validate_cb,
|
||||||
options_free_cb,
|
options_clear_cb,
|
||||||
NULL
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1011,11 +1011,11 @@ set_options(or_options_t *new_val, char **msg)
|
|||||||
|
|
||||||
/** Release additional memory allocated in options
|
/** Release additional memory allocated in options
|
||||||
*/
|
*/
|
||||||
STATIC void
|
static void
|
||||||
or_options_free_(or_options_t *options)
|
options_clear_cb(const config_mgr_t *mgr, void *opts)
|
||||||
{
|
{
|
||||||
if (!options)
|
(void)mgr;
|
||||||
return;
|
or_options_t *options = opts;
|
||||||
|
|
||||||
routerset_free(options->ExcludeExitNodesUnion_);
|
routerset_free(options->ExcludeExitNodesUnion_);
|
||||||
if (options->NodeFamilySets) {
|
if (options->NodeFamilySets) {
|
||||||
@ -1038,6 +1038,13 @@ or_options_free_(or_options_t *options)
|
|||||||
tor_free(options->command_arg);
|
tor_free(options->command_arg);
|
||||||
tor_free(options->master_key_fname);
|
tor_free(options->master_key_fname);
|
||||||
config_free_lines(options->MyFamily);
|
config_free_lines(options->MyFamily);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Release all memory allocated in options
|
||||||
|
*/
|
||||||
|
STATIC void
|
||||||
|
or_options_free_(or_options_t *options)
|
||||||
|
{
|
||||||
config_free(get_options_mgr(), options);
|
config_free(get_options_mgr(), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3164,14 +3171,6 @@ options_validate_cb(void *old_options, void *options, void *default_options,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Callback to free an or_options_t */
|
|
||||||
static void
|
|
||||||
options_free_cb(const config_mgr_t *mgr, void *options)
|
|
||||||
{
|
|
||||||
(void)mgr;
|
|
||||||
or_options_free_(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define REJECT(arg) \
|
#define REJECT(arg) \
|
||||||
STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END
|
STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END
|
||||||
#if defined(__GNUC__) && __GNUC__ <= 3
|
#if defined(__GNUC__) && __GNUC__ <= 3
|
||||||
|
@ -789,6 +789,10 @@ config_free_(const config_mgr_t *mgr, void *options)
|
|||||||
|
|
||||||
tor_assert(fmt);
|
tor_assert(fmt);
|
||||||
|
|
||||||
|
if (mgr->toplevel->clear_fn) {
|
||||||
|
mgr->toplevel->clear_fn(mgr, options);
|
||||||
|
}
|
||||||
|
|
||||||
SMARTLIST_FOREACH_BEGIN(mgr->all_vars, const managed_var_t *, mv) {
|
SMARTLIST_FOREACH_BEGIN(mgr->all_vars, const managed_var_t *, mv) {
|
||||||
config_clear(mgr, options, mv);
|
config_clear(mgr, options, mv);
|
||||||
} SMARTLIST_FOREACH_END(mv);
|
} SMARTLIST_FOREACH_END(mv);
|
||||||
@ -977,9 +981,7 @@ config_dump(const config_mgr_t *mgr, const void *default_options,
|
|||||||
result = smartlist_join_strings(elements, "", 0, NULL);
|
result = smartlist_join_strings(elements, "", 0, NULL);
|
||||||
SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp));
|
SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp));
|
||||||
smartlist_free(elements);
|
smartlist_free(elements);
|
||||||
if (defaults_tmp) {
|
config_free(mgr, defaults_tmp);
|
||||||
fmt->free_fn(mgr, defaults_tmp);
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ typedef int (*validate_fn_t)(void*,void*,void*,int,char**);
|
|||||||
|
|
||||||
struct config_mgr_t;
|
struct config_mgr_t;
|
||||||
|
|
||||||
/** Callback to free a configuration object. */
|
/** Callback to clear all non-managed fields of a configuration object. */
|
||||||
typedef void (*free_cfg_fn_t)(const struct config_mgr_t *mgr, void*);
|
typedef void (*clear_cfg_fn_t)(const struct config_mgr_t *mgr, void*);
|
||||||
|
|
||||||
/** Information on the keys, value types, key-to-struct-member mappings,
|
/** Information on the keys, value types, key-to-struct-member mappings,
|
||||||
* variable descriptions, validation functions, and abbreviations for a
|
* variable descriptions, validation functions, and abbreviations for a
|
||||||
@ -57,7 +57,7 @@ typedef struct config_format_t {
|
|||||||
* values, and where we stick them in the
|
* values, and where we stick them in the
|
||||||
* structure. */
|
* structure. */
|
||||||
validate_fn_t validate_fn; /**< Function to validate config. */
|
validate_fn_t validate_fn; /**< Function to validate config. */
|
||||||
free_cfg_fn_t free_fn; /**< Function to free the configuration. */
|
clear_cfg_fn_t clear_fn; /**< Function to clear the configuration. */
|
||||||
/** If present, extra denotes a LINELIST variable for unrecognized
|
/** If present, extra denotes a LINELIST variable for unrecognized
|
||||||
* lines. Otherwise, unrecognized lines are an error. */
|
* lines. Otherwise, unrecognized lines are an error. */
|
||||||
const struct_member_t *extra;
|
const struct_member_t *extra;
|
||||||
|
@ -145,8 +145,6 @@ static int or_state_validate_cb(void *old_options, void *options,
|
|||||||
void *default_options,
|
void *default_options,
|
||||||
int from_setconf, char **msg);
|
int from_setconf, char **msg);
|
||||||
|
|
||||||
static void or_state_free_cb(const config_mgr_t *mgr, void *state);
|
|
||||||
|
|
||||||
/** Magic value for or_state_t. */
|
/** Magic value for or_state_t. */
|
||||||
#define OR_STATE_MAGIC 0x57A73f57
|
#define OR_STATE_MAGIC 0x57A73f57
|
||||||
|
|
||||||
@ -170,7 +168,7 @@ static const config_format_t state_format = {
|
|||||||
NULL,
|
NULL,
|
||||||
state_vars_,
|
state_vars_,
|
||||||
or_state_validate_cb,
|
or_state_validate_cb,
|
||||||
or_state_free_cb,
|
NULL,
|
||||||
&state_extra_var,
|
&state_extra_var,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -282,13 +280,6 @@ or_state_validate_cb(void *old_state, void *state, void *default_state,
|
|||||||
return or_state_validate(state, msg);
|
return or_state_validate(state, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
or_state_free_cb(const config_mgr_t *mgr, void *state)
|
|
||||||
{
|
|
||||||
(void)mgr;
|
|
||||||
or_state_free_(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return 0 if every setting in <b>state</b> is reasonable, and a
|
/** Return 0 if every setting in <b>state</b> is reasonable, and a
|
||||||
* permissible transition from <b>old_state</b>. Else warn and return -1.
|
* permissible transition from <b>old_state</b>. Else warn and return -1.
|
||||||
* Should have no side effects, except for normalizing the contents of
|
* Should have no side effects, except for normalizing the contents of
|
||||||
|
@ -62,7 +62,6 @@ DUMMY_TYPECHECK_INSTANCE(sr_disk_state_t);
|
|||||||
static int
|
static int
|
||||||
disk_state_validate_cb(void *old_state, void *state, void *default_state,
|
disk_state_validate_cb(void *old_state, void *state, void *default_state,
|
||||||
int from_setconf, char **msg);
|
int from_setconf, char **msg);
|
||||||
static void disk_state_free_cb(const config_mgr_t *mgr, void *);
|
|
||||||
|
|
||||||
/* Array of variables that are saved to disk as a persistent state. */
|
/* Array of variables that are saved to disk as a persistent state. */
|
||||||
static const config_var_t state_vars[] = {
|
static const config_var_t state_vars[] = {
|
||||||
@ -99,7 +98,7 @@ static const config_format_t state_format = {
|
|||||||
NULL,
|
NULL,
|
||||||
state_vars,
|
state_vars,
|
||||||
disk_state_validate_cb,
|
disk_state_validate_cb,
|
||||||
disk_state_free_cb,
|
NULL,
|
||||||
&state_extra_var,
|
&state_extra_var,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -361,13 +360,6 @@ disk_state_validate_cb(void *old_state, void *state, void *default_state,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
disk_state_free_cb(const config_mgr_t *mgr, void *state)
|
|
||||||
{
|
|
||||||
(void)mgr;
|
|
||||||
disk_state_free_(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse the Commit line(s) in the disk state and translate them to the
|
/* Parse the Commit line(s) in the disk state and translate them to the
|
||||||
* the memory state. Return 0 on success else -1 on error. */
|
* the memory state. Return 0 on success else -1 on error. */
|
||||||
static int
|
static int
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* Copyright (c) 2016-2019, The Tor Project, Inc. */
|
/* Copyright (c) 2016-2019, The Tor Project, Inc. */
|
||||||
/* See LICENSE for licensing information */
|
/* See LICENSE for licensing information */
|
||||||
#define CRYPTO_ED25519_PRIVATE
|
#define CRYPTO_ED25519_PRIVATE
|
||||||
|
#define CONFIG_PRIVATE
|
||||||
#include "orconfig.h"
|
#include "orconfig.h"
|
||||||
#include "core/or/or.h"
|
#include "core/or/or.h"
|
||||||
#include "app/main/subsysmgr.h"
|
#include "app/main/subsysmgr.h"
|
||||||
@ -189,7 +190,7 @@ main(int argc, char **argv)
|
|||||||
if (fuzz_cleanup() < 0)
|
if (fuzz_cleanup() < 0)
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
tor_free(mock_options);
|
or_options_free(mock_options);
|
||||||
UNMOCK(get_options);
|
UNMOCK(get_options);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1755,6 +1755,18 @@ add_default_fallback_dir_servers_known_default(void)
|
|||||||
n_add_default_fallback_dir_servers_known_default++;
|
n_add_default_fallback_dir_servers_known_default++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper for test_config_adding_dir_servers(), which should be
|
||||||
|
* refactored: clear the fields in the options which the options object
|
||||||
|
* does not really own. */
|
||||||
|
static void
|
||||||
|
ads_clear_helper(or_options_t *options)
|
||||||
|
{
|
||||||
|
options->DirAuthorities = NULL;
|
||||||
|
options->AlternateBridgeAuthority = NULL;
|
||||||
|
options->AlternateDirAuthority = NULL;
|
||||||
|
options->FallbackDir = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Test all the different combinations of adding dir servers */
|
/* Test all the different combinations of adding dir servers */
|
||||||
static void
|
static void
|
||||||
test_config_adding_dir_servers(void *arg)
|
test_config_adding_dir_servers(void *arg)
|
||||||
@ -1885,7 +1897,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -1967,7 +1981,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -2108,7 +2124,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -2249,7 +2267,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -2391,7 +2411,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -2543,7 +2565,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -2697,7 +2721,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -2860,7 +2886,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -3017,7 +3045,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -3183,7 +3213,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -3346,7 +3378,9 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
n_add_default_fallback_dir_servers_known_default = 0;
|
n_add_default_fallback_dir_servers_known_default = 0;
|
||||||
|
|
||||||
/* clear options*/
|
/* clear options*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
ads_clear_helper(options);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* clear any previous dir servers:
|
/* clear any previous dir servers:
|
||||||
consider_adding_dir_servers() should do this anyway */
|
consider_adding_dir_servers() should do this anyway */
|
||||||
@ -3515,10 +3549,7 @@ test_config_adding_dir_servers(void *arg)
|
|||||||
tor_free(test_fallback_directory->value);
|
tor_free(test_fallback_directory->value);
|
||||||
tor_free(test_fallback_directory);
|
tor_free(test_fallback_directory);
|
||||||
|
|
||||||
options->DirAuthorities = NULL;
|
ads_clear_helper(options);
|
||||||
options->AlternateBridgeAuthority = NULL;
|
|
||||||
options->AlternateDirAuthority = NULL;
|
|
||||||
options->FallbackDir = NULL;
|
|
||||||
or_options_free(options);
|
or_options_free(options);
|
||||||
|
|
||||||
UNMOCK(add_default_fallback_dir_servers);
|
UNMOCK(add_default_fallback_dir_servers);
|
||||||
@ -3619,9 +3650,10 @@ test_config_directory_fetch(void *arg)
|
|||||||
mock_router_my_exit_policy_is_reject_star);
|
mock_router_my_exit_policy_is_reject_star);
|
||||||
MOCK(advertised_server_mode, mock_advertised_server_mode);
|
MOCK(advertised_server_mode, mock_advertised_server_mode);
|
||||||
MOCK(router_get_my_routerinfo, mock_router_get_my_routerinfo);
|
MOCK(router_get_my_routerinfo, mock_router_get_my_routerinfo);
|
||||||
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
|
|
||||||
/* Clients can use multiple directory mirrors for bootstrap */
|
/* Clients can use multiple directory mirrors for bootstrap */
|
||||||
memset(options, 0, sizeof(or_options_t));
|
|
||||||
options->ClientOnly = 1;
|
options->ClientOnly = 1;
|
||||||
tt_assert(server_mode(options) == 0);
|
tt_assert(server_mode(options) == 0);
|
||||||
tt_assert(public_server_mode(options) == 0);
|
tt_assert(public_server_mode(options) == 0);
|
||||||
@ -3630,7 +3662,8 @@ test_config_directory_fetch(void *arg)
|
|||||||
OP_EQ, 1);
|
OP_EQ, 1);
|
||||||
|
|
||||||
/* Bridge Clients can use multiple directory mirrors for bootstrap */
|
/* Bridge Clients can use multiple directory mirrors for bootstrap */
|
||||||
memset(options, 0, sizeof(or_options_t));
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
options->UseBridges = 1;
|
options->UseBridges = 1;
|
||||||
tt_assert(server_mode(options) == 0);
|
tt_assert(server_mode(options) == 0);
|
||||||
tt_assert(public_server_mode(options) == 0);
|
tt_assert(public_server_mode(options) == 0);
|
||||||
@ -3640,7 +3673,8 @@ test_config_directory_fetch(void *arg)
|
|||||||
|
|
||||||
/* Bridge Relays (Bridges) must act like clients, and use multiple
|
/* Bridge Relays (Bridges) must act like clients, and use multiple
|
||||||
* directory mirrors for bootstrap */
|
* directory mirrors for bootstrap */
|
||||||
memset(options, 0, sizeof(or_options_t));
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
options->BridgeRelay = 1;
|
options->BridgeRelay = 1;
|
||||||
options->ORPort_set = 1;
|
options->ORPort_set = 1;
|
||||||
tt_assert(server_mode(options) == 1);
|
tt_assert(server_mode(options) == 1);
|
||||||
@ -3651,7 +3685,8 @@ test_config_directory_fetch(void *arg)
|
|||||||
|
|
||||||
/* Clients set to FetchDirInfoEarly must fetch it from the authorities,
|
/* Clients set to FetchDirInfoEarly must fetch it from the authorities,
|
||||||
* but can use multiple authorities for bootstrap */
|
* but can use multiple authorities for bootstrap */
|
||||||
memset(options, 0, sizeof(or_options_t));
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
options->FetchDirInfoEarly = 1;
|
options->FetchDirInfoEarly = 1;
|
||||||
tt_assert(server_mode(options) == 0);
|
tt_assert(server_mode(options) == 0);
|
||||||
tt_assert(public_server_mode(options) == 0);
|
tt_assert(public_server_mode(options) == 0);
|
||||||
@ -3662,7 +3697,8 @@ test_config_directory_fetch(void *arg)
|
|||||||
/* OR servers only fetch the consensus from the authorities when they don't
|
/* OR servers only fetch the consensus from the authorities when they don't
|
||||||
* know their own address, but never use multiple directories for bootstrap
|
* know their own address, but never use multiple directories for bootstrap
|
||||||
*/
|
*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
options->ORPort_set = 1;
|
options->ORPort_set = 1;
|
||||||
|
|
||||||
mock_router_pick_published_address_result = -1;
|
mock_router_pick_published_address_result = -1;
|
||||||
@ -3682,7 +3718,8 @@ test_config_directory_fetch(void *arg)
|
|||||||
/* Exit OR servers only fetch the consensus from the authorities when they
|
/* Exit OR servers only fetch the consensus from the authorities when they
|
||||||
* refuse unknown exits, but never use multiple directories for bootstrap
|
* refuse unknown exits, but never use multiple directories for bootstrap
|
||||||
*/
|
*/
|
||||||
memset(options, 0, sizeof(or_options_t));
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
options->ORPort_set = 1;
|
options->ORPort_set = 1;
|
||||||
options->ExitRelay = 1;
|
options->ExitRelay = 1;
|
||||||
mock_router_pick_published_address_result = 0;
|
mock_router_pick_published_address_result = 0;
|
||||||
@ -3712,7 +3749,8 @@ test_config_directory_fetch(void *arg)
|
|||||||
* advertising their dirport, and never use multiple directories for
|
* advertising their dirport, and never use multiple directories for
|
||||||
* bootstrap. This only applies if they are also OR servers.
|
* bootstrap. This only applies if they are also OR servers.
|
||||||
* (We don't care much about the behaviour of non-OR directory servers.) */
|
* (We don't care much about the behaviour of non-OR directory servers.) */
|
||||||
memset(options, 0, sizeof(or_options_t));
|
or_options_free(options);
|
||||||
|
options = options_new();
|
||||||
options->DirPort_set = 1;
|
options->DirPort_set = 1;
|
||||||
options->ORPort_set = 1;
|
options->ORPort_set = 1;
|
||||||
options->DirCache = 1;
|
options->DirCache = 1;
|
||||||
@ -3766,7 +3804,7 @@ test_config_directory_fetch(void *arg)
|
|||||||
OP_EQ, 0);
|
OP_EQ, 0);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
tor_free(options);
|
or_options_free(options);
|
||||||
UNMOCK(router_pick_published_address);
|
UNMOCK(router_pick_published_address);
|
||||||
UNMOCK(router_get_my_routerinfo);
|
UNMOCK(router_get_my_routerinfo);
|
||||||
UNMOCK(advertised_server_mode);
|
UNMOCK(advertised_server_mode);
|
||||||
|
@ -119,8 +119,6 @@ test_validate_cb(void *old_options, void *options, void *default_options,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_free_cb(const config_mgr_t *mgr, void *options);
|
|
||||||
|
|
||||||
#define TEST_MAGIC 0x1337
|
#define TEST_MAGIC 0x1337
|
||||||
|
|
||||||
static const config_format_t test_fmt = {
|
static const config_format_t test_fmt = {
|
||||||
@ -134,19 +132,10 @@ static const config_format_t test_fmt = {
|
|||||||
test_deprecation_notes,
|
test_deprecation_notes,
|
||||||
test_vars,
|
test_vars,
|
||||||
test_validate_cb,
|
test_validate_cb,
|
||||||
test_free_cb,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
test_free_cb(const config_mgr_t *mgr, void *options)
|
|
||||||
{
|
|
||||||
if (!options)
|
|
||||||
return;
|
|
||||||
|
|
||||||
config_free(mgr, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure that config_init sets everything to the right defaults. */
|
/* Make sure that config_init sets everything to the right defaults. */
|
||||||
static void
|
static void
|
||||||
test_confparse_init(void *arg)
|
test_confparse_init(void *arg)
|
||||||
@ -824,7 +813,7 @@ static config_format_t etest_fmt = {
|
|||||||
test_deprecation_notes,
|
test_deprecation_notes,
|
||||||
test_vars,
|
test_vars,
|
||||||
test_validate_cb,
|
test_validate_cb,
|
||||||
test_free_cb,
|
NULL,
|
||||||
&extra,
|
&extra,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -479,8 +479,7 @@ static or_options_t *mock_options = NULL;
|
|||||||
static void
|
static void
|
||||||
init_mock_options(void)
|
init_mock_options(void)
|
||||||
{
|
{
|
||||||
mock_options = tor_malloc(sizeof(or_options_t));
|
mock_options = options_new();
|
||||||
memset(mock_options, 0, sizeof(or_options_t));
|
|
||||||
mock_options->TestingTorNetwork = 1;
|
mock_options->TestingTorNetwork = 1;
|
||||||
mock_options->DataDirectory = tor_strdup(get_fname_rnd("datadir_tmp"));
|
mock_options->DataDirectory = tor_strdup(get_fname_rnd("datadir_tmp"));
|
||||||
mock_options->CacheDirectory = tor_strdup(mock_options->DataDirectory);
|
mock_options->CacheDirectory = tor_strdup(mock_options->DataDirectory);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#define CIRCUITLIST_PRIVATE
|
#define CIRCUITLIST_PRIVATE
|
||||||
#define CIRCUITBUILD_PRIVATE
|
#define CIRCUITBUILD_PRIVATE
|
||||||
|
#define CONFIG_PRIVATE
|
||||||
#define STATEFILE_PRIVATE
|
#define STATEFILE_PRIVATE
|
||||||
#define ENTRYNODES_PRIVATE
|
#define ENTRYNODES_PRIVATE
|
||||||
#define ROUTERLIST_PRIVATE
|
#define ROUTERLIST_PRIVATE
|
||||||
@ -201,7 +202,7 @@ big_fake_network_setup(const struct testcase_t *testcase)
|
|||||||
smartlist_add(big_fake_net_nodes, n);
|
smartlist_add(big_fake_net_nodes, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
dummy_state = or_state_new();
|
||||||
dummy_consensus = tor_malloc_zero(sizeof(networkstatus_t));
|
dummy_consensus = tor_malloc_zero(sizeof(networkstatus_t));
|
||||||
if (reasonably_future_consensus) {
|
if (reasonably_future_consensus) {
|
||||||
/* Make the dummy consensus valid in 6 hours, and expiring in 7 hours. */
|
/* Make the dummy consensus valid in 6 hours, and expiring in 7 hours. */
|
||||||
@ -235,12 +236,12 @@ mock_randomize_time_no_randomization(time_t a, time_t b)
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static or_options_t mocked_options;
|
static or_options_t *mocked_options;
|
||||||
|
|
||||||
static const or_options_t *
|
static const or_options_t *
|
||||||
mock_get_options(void)
|
mock_get_options(void)
|
||||||
{
|
{
|
||||||
return &mocked_options;
|
return mocked_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_IPV4_ADDR "123.45.67.89"
|
#define TEST_IPV4_ADDR "123.45.67.89"
|
||||||
@ -259,7 +260,7 @@ test_node_preferred_orport(void *arg)
|
|||||||
tor_addr_port_t ap;
|
tor_addr_port_t ap;
|
||||||
|
|
||||||
/* Setup options */
|
/* Setup options */
|
||||||
memset(&mocked_options, 0, sizeof(mocked_options));
|
mocked_options = options_new();
|
||||||
/* We don't test ClientPreferIPv6ORPort here, because it's used in
|
/* We don't test ClientPreferIPv6ORPort here, because it's used in
|
||||||
* nodelist_set_consensus to setup node.ipv6_preferred, which we set
|
* nodelist_set_consensus to setup node.ipv6_preferred, which we set
|
||||||
* directly. */
|
* directly. */
|
||||||
@ -282,8 +283,8 @@ test_node_preferred_orport(void *arg)
|
|||||||
|
|
||||||
/* Check the preferred address is IPv4 if we're only using IPv4, regardless
|
/* Check the preferred address is IPv4 if we're only using IPv4, regardless
|
||||||
* of whether we prefer it or not */
|
* of whether we prefer it or not */
|
||||||
mocked_options.ClientUseIPv4 = 1;
|
mocked_options->ClientUseIPv4 = 1;
|
||||||
mocked_options.ClientUseIPv6 = 0;
|
mocked_options->ClientUseIPv6 = 0;
|
||||||
node.ipv6_preferred = 0;
|
node.ipv6_preferred = 0;
|
||||||
node_get_pref_orport(&node, &ap);
|
node_get_pref_orport(&node, &ap);
|
||||||
tt_assert(tor_addr_eq(&ap.addr, &ipv4_addr));
|
tt_assert(tor_addr_eq(&ap.addr, &ipv4_addr));
|
||||||
@ -296,8 +297,8 @@ test_node_preferred_orport(void *arg)
|
|||||||
|
|
||||||
/* Check the preferred address is IPv4 if we're using IPv4 and IPv6, but
|
/* Check the preferred address is IPv4 if we're using IPv4 and IPv6, but
|
||||||
* don't prefer the IPv6 address */
|
* don't prefer the IPv6 address */
|
||||||
mocked_options.ClientUseIPv4 = 1;
|
mocked_options->ClientUseIPv4 = 1;
|
||||||
mocked_options.ClientUseIPv6 = 1;
|
mocked_options->ClientUseIPv6 = 1;
|
||||||
node.ipv6_preferred = 0;
|
node.ipv6_preferred = 0;
|
||||||
node_get_pref_orport(&node, &ap);
|
node_get_pref_orport(&node, &ap);
|
||||||
tt_assert(tor_addr_eq(&ap.addr, &ipv4_addr));
|
tt_assert(tor_addr_eq(&ap.addr, &ipv4_addr));
|
||||||
@ -305,28 +306,29 @@ test_node_preferred_orport(void *arg)
|
|||||||
|
|
||||||
/* Check the preferred address is IPv6 if we prefer it and
|
/* Check the preferred address is IPv6 if we prefer it and
|
||||||
* ClientUseIPv6 is 1, regardless of ClientUseIPv4 */
|
* ClientUseIPv6 is 1, regardless of ClientUseIPv4 */
|
||||||
mocked_options.ClientUseIPv4 = 1;
|
mocked_options->ClientUseIPv4 = 1;
|
||||||
mocked_options.ClientUseIPv6 = 1;
|
mocked_options->ClientUseIPv6 = 1;
|
||||||
node.ipv6_preferred = 1;
|
node.ipv6_preferred = 1;
|
||||||
node_get_pref_orport(&node, &ap);
|
node_get_pref_orport(&node, &ap);
|
||||||
tt_assert(tor_addr_eq(&ap.addr, &ipv6_addr));
|
tt_assert(tor_addr_eq(&ap.addr, &ipv6_addr));
|
||||||
tt_assert(ap.port == ipv6_port);
|
tt_assert(ap.port == ipv6_port);
|
||||||
|
|
||||||
mocked_options.ClientUseIPv4 = 0;
|
mocked_options->ClientUseIPv4 = 0;
|
||||||
node_get_pref_orport(&node, &ap);
|
node_get_pref_orport(&node, &ap);
|
||||||
tt_assert(tor_addr_eq(&ap.addr, &ipv6_addr));
|
tt_assert(tor_addr_eq(&ap.addr, &ipv6_addr));
|
||||||
tt_assert(ap.port == ipv6_port);
|
tt_assert(ap.port == ipv6_port);
|
||||||
|
|
||||||
/* Check the preferred address is IPv6 if we don't prefer it, but
|
/* Check the preferred address is IPv6 if we don't prefer it, but
|
||||||
* ClientUseIPv4 is 0 */
|
* ClientUseIPv4 is 0 */
|
||||||
mocked_options.ClientUseIPv4 = 0;
|
mocked_options->ClientUseIPv4 = 0;
|
||||||
mocked_options.ClientUseIPv6 = 1;
|
mocked_options->ClientUseIPv6 = 1;
|
||||||
node.ipv6_preferred = fascist_firewall_prefer_ipv6_orport(&mocked_options);
|
node.ipv6_preferred = fascist_firewall_prefer_ipv6_orport(mocked_options);
|
||||||
node_get_pref_orport(&node, &ap);
|
node_get_pref_orport(&node, &ap);
|
||||||
tt_assert(tor_addr_eq(&ap.addr, &ipv6_addr));
|
tt_assert(tor_addr_eq(&ap.addr, &ipv6_addr));
|
||||||
tt_assert(ap.port == ipv6_port);
|
tt_assert(ap.port == ipv6_port);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
or_options_free(mocked_options);
|
||||||
UNMOCK(get_options);
|
UNMOCK(get_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1181,7 +1181,7 @@ test_introduce2(void *arg)
|
|||||||
MOCK(get_or_state,
|
MOCK(get_or_state,
|
||||||
get_or_state_replacement);
|
get_or_state_replacement);
|
||||||
|
|
||||||
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
dummy_state = or_state_new();
|
||||||
|
|
||||||
circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_INTRO, flags);
|
circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_INTRO, flags);
|
||||||
tt_assert(circ);
|
tt_assert(circ);
|
||||||
@ -1345,7 +1345,7 @@ test_rotate_descriptors(void *arg)
|
|||||||
|
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
dummy_state = or_state_new();
|
||||||
|
|
||||||
hs_init();
|
hs_init();
|
||||||
MOCK(get_or_state, get_or_state_replacement);
|
MOCK(get_or_state, get_or_state_replacement);
|
||||||
@ -1462,7 +1462,7 @@ test_build_update_descriptors(void *arg)
|
|||||||
MOCK(networkstatus_get_live_consensus,
|
MOCK(networkstatus_get_live_consensus,
|
||||||
mock_networkstatus_get_live_consensus);
|
mock_networkstatus_get_live_consensus);
|
||||||
|
|
||||||
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
dummy_state = or_state_new();
|
||||||
|
|
||||||
ret = parse_rfc1123_time("Sat, 26 Oct 1985 03:00:00 UTC",
|
ret = parse_rfc1123_time("Sat, 26 Oct 1985 03:00:00 UTC",
|
||||||
&mock_ns.valid_after);
|
&mock_ns.valid_after);
|
||||||
@ -1693,7 +1693,7 @@ test_build_descriptors(void *arg)
|
|||||||
MOCK(networkstatus_get_live_consensus,
|
MOCK(networkstatus_get_live_consensus,
|
||||||
mock_networkstatus_get_live_consensus);
|
mock_networkstatus_get_live_consensus);
|
||||||
|
|
||||||
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
dummy_state = or_state_new();
|
||||||
|
|
||||||
ret = parse_rfc1123_time("Sat, 26 Oct 1985 03:00:00 UTC",
|
ret = parse_rfc1123_time("Sat, 26 Oct 1985 03:00:00 UTC",
|
||||||
&mock_ns.valid_after);
|
&mock_ns.valid_after);
|
||||||
@ -1794,7 +1794,7 @@ test_upload_descriptors(void *arg)
|
|||||||
MOCK(networkstatus_get_live_consensus,
|
MOCK(networkstatus_get_live_consensus,
|
||||||
mock_networkstatus_get_live_consensus);
|
mock_networkstatus_get_live_consensus);
|
||||||
|
|
||||||
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
dummy_state = or_state_new();
|
||||||
|
|
||||||
ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC",
|
ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC",
|
||||||
&mock_ns.valid_after);
|
&mock_ns.valid_after);
|
||||||
|
@ -352,7 +352,7 @@ test_pt_configure_proxy(void *arg)
|
|||||||
managed_proxy_t *mp = NULL;
|
managed_proxy_t *mp = NULL;
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
dummy_state = or_state_new();
|
||||||
|
|
||||||
MOCK(process_read_stdout, process_read_stdout_replacement);
|
MOCK(process_read_stdout, process_read_stdout_replacement);
|
||||||
MOCK(get_or_state,
|
MOCK(get_or_state,
|
||||||
|
Loading…
Reference in New Issue
Block a user