From 1d0ccda5955957c6c09a081502b315ba21c7c62e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 15 Dec 2019 11:46:05 -0500 Subject: [PATCH 1/7] Add torint.h include to confdecl.h. This change allows other modules to include confdecl.h without having first to include integer types they might not even use. --- src/lib/conf/confdecl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/conf/confdecl.h b/src/lib/conf/confdecl.h index 294a1e7173..064ab324f8 100644 --- a/src/lib/conf/confdecl.h +++ b/src/lib/conf/confdecl.h @@ -51,6 +51,7 @@ #undef CONF_CONTEXT #include "lib/cc/tokpaste.h" +#include "lib/cc/torint.h" /** * Begin the definition of a configuration object called `name`. From 5e2318165dba782f6daa6620b17e0fa1e72b4b11 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 15 Dec 2019 18:10:11 -0500 Subject: [PATCH 2/7] Add "stub" files for disabled modules. These modules are only built when the selected modules are disabled. The provide stub implementations of the subsystem blocks. Later, other stub implementations could move here. Having real subsystem blocks here will let us handle disabled configuration options better. --- src/app/main/subsystem_list.c | 4 ---- src/core/include.am | 13 ++++++++++++- src/feature/dirauth/dirauth_stub.c | 19 +++++++++++++++++++ src/feature/dirauth/dirauth_sys.h | 4 ---- src/feature/relay/relay_stub.c | 20 ++++++++++++++++++++ src/feature/relay/relay_sys.h | 4 ---- 6 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 src/feature/dirauth/dirauth_stub.c create mode 100644 src/feature/relay/relay_stub.c diff --git a/src/app/main/subsystem_list.c b/src/app/main/subsystem_list.c index a343207c1c..8b217715a5 100644 --- a/src/app/main/subsystem_list.c +++ b/src/app/main/subsystem_list.c @@ -66,13 +66,9 @@ const subsys_fns_t *tor_subsystems[] = { &sys_mainloop, &sys_or, -#ifdef HAVE_MODULE_RELAY &sys_relay, -#endif -#ifdef HAVE_MODULE_DIRAUTH &sys_dirauth, -#endif }; const unsigned n_tor_subsystems = ARRAY_LENGTH(tor_subsystems); diff --git a/src/core/include.am b/src/core/include.am index 83230fb3ca..ab4adeaf66 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -157,6 +157,11 @@ LIBTOR_APP_A_SOURCES = \ src/feature/stats/rephist.c \ src/feature/stats/predict_ports.c +# +# Sources that we only add for the real libtor_a, and not for testing. +# +LIBTOR_APP_A_STUB_SOURCES = + if BUILD_NT_SERVICES LIBTOR_APP_A_SOURCES += src/app/main/ntmain.c endif @@ -199,13 +204,19 @@ MODULE_DIRAUTH_SOURCES = \ if BUILD_MODULE_RELAY LIBTOR_APP_A_SOURCES += $(MODULE_RELAY_SOURCES) +else +LIBTOR_APP_A_STUB_SOURCES += src/feature/relay/relay_stub.c endif if BUILD_MODULE_DIRAUTH LIBTOR_APP_A_SOURCES += $(MODULE_DIRAUTH_SOURCES) +else +LIBTOR_APP_A_STUB_SOURCES += src/feature/dirauth/dirauth_stub.c endif -src_core_libtor_app_a_SOURCES = $(LIBTOR_APP_A_SOURCES) +src_core_libtor_app_a_SOURCES = \ + $(LIBTOR_APP_A_SOURCES) \ + $(LIBTOR_APP_A_STUB_SOURCES) if UNITTESTS_ENABLED # Add the sources of the modules that are needed for tests to work here. diff --git a/src/feature/dirauth/dirauth_stub.c b/src/feature/dirauth/dirauth_stub.c new file mode 100644 index 0000000000..fac68edd09 --- /dev/null +++ b/src/feature/dirauth/dirauth_stub.c @@ -0,0 +1,19 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * @file dirauth_stub.c + * @brief Stub declarations for use when dirauth module is disabled. + **/ + +#include "orconfig.h" +#include "feature/dirauth/dirauth_sys.h" + +const struct subsys_fns_t sys_dirauth = { + .name = "dirauth", + .supported = false, + .level = 70, +}; diff --git a/src/feature/dirauth/dirauth_sys.h b/src/feature/dirauth/dirauth_sys.h index 86c8d8ba3e..2d5a0cb3e7 100644 --- a/src/feature/dirauth/dirauth_sys.h +++ b/src/feature/dirauth/dirauth_sys.h @@ -12,10 +12,6 @@ #ifndef DIRAUTH_SYS_H #define DIRAUTH_SYS_H -#ifdef HAVE_MODULE_DIRAUTH - extern const struct subsys_fns_t sys_dirauth; -#endif - #endif /* !defined(DIRAUTH_SYS_H) */ diff --git a/src/feature/relay/relay_stub.c b/src/feature/relay/relay_stub.c new file mode 100644 index 0000000000..a23b991862 --- /dev/null +++ b/src/feature/relay/relay_stub.c @@ -0,0 +1,20 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * @file relay_stub.c + * @brief Stub declarations for use when relay module is disabled. + **/ + +#include "orconfig.h" +#include "feature/relay/relay_sys.h" +#include "lib/subsys/subsys.h" + +const struct subsys_fns_t sys_relay = { + .name = "relay", + .supported = false, + .level = 50, +}; diff --git a/src/feature/relay/relay_sys.h b/src/feature/relay/relay_sys.h index aa387369b5..32e21d90d8 100644 --- a/src/feature/relay/relay_sys.h +++ b/src/feature/relay/relay_sys.h @@ -12,10 +12,6 @@ #ifndef TOR_FEATURE_RELAY_RELAY_SYS_H #define TOR_FEATURE_RELAY_RELAY_SYS_H -#ifdef HAVE_MODULE_RELAY - extern const struct subsys_fns_t sys_relay; -#endif - #endif /* !defined(TOR_FEATURE_RELAY_RELAY_SYS_H) */ From 9082a6db3f31c768ba862ed22f0824e99b4e0e22 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 15 Dec 2019 18:40:12 -0500 Subject: [PATCH 3/7] Support a flag to indicate that a config var is disabled Like "obsolete" variables, these variables produce a warning when you try to set them, but the warning says that the relevant module doesn't have support. The confdecl macros now have a CONF_CONTEXT that you can define to make all the modules in a given table disabled. --- src/lib/conf/confdecl.h | 22 ++++++++++++++++++++++ src/lib/conf/conftypes.h | 12 ++++++++++++ src/lib/confmgt/confmgt.c | 3 +++ 3 files changed, 37 insertions(+) diff --git a/src/lib/conf/confdecl.h b/src/lib/conf/confdecl.h index 064ab324f8..723aea1878 100644 --- a/src/lib/conf/confdecl.h +++ b/src/lib/conf/confdecl.h @@ -135,6 +135,28 @@ .initvalue = initval \ }, /**@}*/ + +/* @defgroup STUB_TABLE_MACROS Internal macros: stub table declarations, + * for use when a module is disabled. + * Implementation helpers: the regular confdecl macros expand to these + * when CONF_CONTEXT is defined to LL_TABLE. Don't use them directly. + * @{*/ +#define BEGIN_CONF_STRUCT__STUB_TABLE(structname) \ + static const config_var_t structname##_vars[] = { +#define END_CONF_STRUCT__STUB_TABLE(structname) \ + { .member = { .name = NULL } } \ + }; +#define CONF_VAR__STUB_TABLE(varname, vartype, varflags, initval) \ + { \ + .member = \ + { .name = #varname, \ + .type = CONFIG_TYPE_IGNORE, \ + .offset = -1, \ + }, \ + .flags = CFLG_GROUP_DISABLED, \ + }, +/**@}*/ + #endif /* !defined(COCCI) */ /** Type aliases for the "commonly used" configuration types. diff --git a/src/lib/conf/conftypes.h b/src/lib/conf/conftypes.h index 19ea997316..44171068a1 100644 --- a/src/lib/conf/conftypes.h +++ b/src/lib/conf/conftypes.h @@ -199,6 +199,11 @@ typedef struct struct_magic_decl_t { * whenever the user tries to use it. **/ #define CFLG_WARN_OBSOLETE (1u<<7) +/** + * Flag to indicate that we should warn that an option applies only to + * a disabled module, whenever the user tries to use it. + **/ +#define CFLG_WARN_DISABLED (1u<<8) /** * A group of flags that should be set on all obsolete options and types. @@ -207,6 +212,13 @@ typedef struct struct_magic_decl_t { (CFLG_NOCOPY|CFLG_NOCMP|CFLG_NODUMP|CFLG_NOSET|CFLG_NOLIST|\ CFLG_WARN_OBSOLETE) +/** + * A group of fflags that should be set on all disabled options. + **/ +#define CFLG_GROUP_DISABLED \ + (CFLG_NOCOPY|CFLG_NOCMP|CFLG_NODUMP|CFLG_NOSET|CFLG_NOLIST|\ + CFLG_WARN_DISABLED) + /** A variable allowed in the configuration file or on the command line. */ typedef struct config_var_t { struct_member_t member; /** A struct member corresponding to this diff --git a/src/lib/confmgt/confmgt.c b/src/lib/confmgt/confmgt.c index c72efa847c..eaa4468d55 100644 --- a/src/lib/confmgt/confmgt.c +++ b/src/lib/confmgt/confmgt.c @@ -660,6 +660,9 @@ config_assign_value(const config_mgr_t *mgr, void *options, if (config_var_has_flag(var->cvar, CFLG_WARN_OBSOLETE)) { log_warn(LD_GENERAL, "Skipping obsolete configuration option \"%s\".", var->cvar->member.name); + } else if (config_var_has_flag(var->cvar, CFLG_WARN_DISABLED)) { + log_warn(LD_GENERAL, "This copy of Tor was built without support for " + "the option \"%s\". Skipping.", var->cvar->member.name); } return struct_var_kvassign(object, c, msg, &var->cvar->member); From 419ba97df5bd168bf773478270c0043f20328e15 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 15 Dec 2019 18:42:01 -0500 Subject: [PATCH 4/7] Allow struct_magic to be disabled. When a subsystem is disabled, there will be no corresponding object allocated, and no magic numbers on it. --- src/lib/conf/conftypes.h | 3 +++ src/lib/confmgt/structvar.c | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib/conf/conftypes.h b/src/lib/conf/conftypes.h index 44171068a1..52f9fceb20 100644 --- a/src/lib/conf/conftypes.h +++ b/src/lib/conf/conftypes.h @@ -131,6 +131,9 @@ typedef struct struct_member_t { * * These 'magic numbers' are 32-bit values used to tag objects to make sure * that they have the correct type. + * + * If all fields in this structure are zero or 0, the magic-number check is + * not performed. */ typedef struct struct_magic_decl_t { /** The name of the structure */ diff --git a/src/lib/confmgt/structvar.c b/src/lib/confmgt/structvar.c index de678d18c8..a2411477d6 100644 --- a/src/lib/confmgt/structvar.c +++ b/src/lib/confmgt/structvar.c @@ -29,14 +29,29 @@ #include +/** + * Return true iff all fields on decl are NULL or 0, indicating that + * there is no object or no magic number to check. + **/ +static inline bool +magic_is_null(const struct_magic_decl_t *decl) +{ + return decl->typename == NULL && + decl->magic_offset == 0 && + decl->magic_val == 0; +} + /** * Set the 'magic number' on object to correspond to decl. **/ void struct_set_magic(void *object, const struct_magic_decl_t *decl) { - tor_assert(object); tor_assert(decl); + if (magic_is_null(decl)) + return; + + tor_assert(object); uint32_t *ptr = STRUCT_VAR_P(object, decl->magic_offset); *ptr = decl->magic_val; } @@ -47,8 +62,11 @@ struct_set_magic(void *object, const struct_magic_decl_t *decl) void struct_check_magic(const void *object, const struct_magic_decl_t *decl) { - tor_assert(object); tor_assert(decl); + if (magic_is_null(decl)) + return; + + tor_assert(object); const uint32_t *ptr = STRUCT_VAR_P(object, decl->magic_offset); tor_assertf(*ptr == decl->magic_val, From ffa3499d81823eb21811a479c31b59f1bfb5bc61 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 15 Dec 2019 11:46:55 -0500 Subject: [PATCH 5/7] Add config object for dirauth; move one option there. I've chosen the "AuthDirMaxServersPerAddr" option here for simplicity, since it is used literally nowhere else besides the dirauth module. Once we have all the infrastructure in place for this, we can move more options into this structure. --- src/app/config/config.c | 1 - src/app/config/or_options_st.h | 2 -- src/core/include.am | 2 ++ src/feature/dirauth/.may_include | 1 + src/feature/dirauth/dirauth_config.c | 22 ++++++++++++++++++++++ src/feature/dirauth/dirauth_config.h | 2 ++ src/feature/dirauth/dirauth_options.inc | 18 ++++++++++++++++++ src/feature/dirauth/dirauth_options_st.h | 22 ++++++++++++++++++++++ src/feature/dirauth/dirauth_stub.c | 14 ++++++++++++++ src/feature/dirauth/dirauth_sys.c | 24 ++++++++++++++++++++++++ src/feature/dirauth/dirauth_sys.h | 3 +++ src/feature/dirauth/dirvote.c | 4 +++- 12 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 src/feature/dirauth/dirauth_options.inc create mode 100644 src/feature/dirauth/dirauth_options_st.h diff --git a/src/app/config/config.c b/src/app/config/config.c index 5ea8cec6a6..680a7eeefa 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -337,7 +337,6 @@ static const config_var_t option_vars_[] = { OBSOLETE("AuthDirRejectUnlisted"), OBSOLETE("AuthDirListBadDirs"), V(AuthDirListBadExits, BOOL, "0"), - V(AuthDirMaxServersPerAddr, POSINT, "2"), OBSOLETE("AuthDirMaxServersPerAuthAddr"), V(AuthDirHasIPv6Connectivity, BOOL, "0"), VAR("AuthoritativeDirectory", BOOL, AuthoritativeDir, "0"), diff --git a/src/app/config/or_options_st.h b/src/app/config/or_options_st.h index a3d63d9208..e63ae2510f 100644 --- a/src/app/config/or_options_st.h +++ b/src/app/config/or_options_st.h @@ -467,8 +467,6 @@ struct or_options_t { int AuthDirListBadExits; /**< True iff we should list bad exits, * and vote for all other exits as good. */ - int AuthDirMaxServersPerAddr; /**< Do not permit more than this - * number of servers per IP address. */ int AuthDirHasIPv6Connectivity; /**< Boolean: are we on IPv6? */ int AuthDirPinKeys; /**< Boolean: Do we enforce key-pinning? */ diff --git a/src/core/include.am b/src/core/include.am index ab4adeaf66..911932d46b 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -355,6 +355,8 @@ noinst_HEADERS += \ src/feature/dirauth/bridgeauth.h \ src/feature/dirauth/bwauth.h \ src/feature/dirauth/dirauth_config.h \ + src/feature/dirauth/dirauth_options.inc \ + src/feature/dirauth/dirauth_options_st.h \ src/feature/dirauth/dirauth_periodic.h \ src/feature/dirauth/dirauth_sys.h \ src/feature/dirauth/dircollate.h \ diff --git a/src/feature/dirauth/.may_include b/src/feature/dirauth/.may_include index 424c745c12..a9bb274699 100644 --- a/src/feature/dirauth/.may_include +++ b/src/feature/dirauth/.may_include @@ -1 +1,2 @@ *.h +feature/dirauth/*.inc diff --git a/src/feature/dirauth/dirauth_config.c b/src/feature/dirauth/dirauth_config.c index 552f851461..b7e160c241 100644 --- a/src/feature/dirauth/dirauth_config.c +++ b/src/feature/dirauth/dirauth_config.c @@ -15,6 +15,7 @@ #include "lib/encoding/confline.h" #include "lib/confmgt/confmgt.h" +#include "lib/conf/confdecl.h" /* Required for dirinfo_type_t in or_options_t */ #include "core/or/or.h" @@ -28,6 +29,7 @@ #include "feature/dirauth/dirauth_periodic.h" #include "feature/dirauth/dirvote.h" #include "feature/dirauth/guardfraction.h" +#include "feature/dirauth/dirauth_options_st.h" /* Copied from config.c, we will refactor later in 29211. */ #define REJECT(arg) \ @@ -438,3 +440,23 @@ options_act_dirauth_stats(const or_options_t *old_options, return 0; } + +/* Declare the options field table for dirauth_options */ +#define CONF_CONTEXT TABLE +#include "feature/dirauth/dirauth_options.inc" +#undef CONF_CONTEXT + +/** Magic number for dirauth_options_t. */ +#define DIRAUTH_OPTIONS_MAGIC 0x41757448 + +/** + * Declare the configuration options for the dirauth module. + **/ +const config_format_t dirauth_options_fmt = { + .size = sizeof(dirauth_options_t), + .magic = { "dirauth_options_t", + DIRAUTH_OPTIONS_MAGIC, + offsetof(dirauth_options_t, magic) }, + .vars = dirauth_options_t_vars, +}; + diff --git a/src/feature/dirauth/dirauth_config.h b/src/feature/dirauth/dirauth_config.h index b494ca685e..d21fb69d1e 100644 --- a/src/feature/dirauth/dirauth_config.h +++ b/src/feature/dirauth/dirauth_config.h @@ -39,6 +39,8 @@ int options_act_dirauth_mtbf(const struct or_options_t *old_options); int options_act_dirauth_stats(const struct or_options_t *old_options, bool *print_notice_out); +extern const struct config_format_t dirauth_options_fmt; + #else /* !defined(HAVE_MODULE_DIRAUTH) */ /** When tor is compiled with the dirauth module disabled, it can't be diff --git a/src/feature/dirauth/dirauth_options.inc b/src/feature/dirauth/dirauth_options.inc new file mode 100644 index 0000000000..6b66f1e289 --- /dev/null +++ b/src/feature/dirauth/dirauth_options.inc @@ -0,0 +1,18 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * @file dirauth_options.inc + * @brief Declare configuration options for the crypto_ops module. + **/ + +/** Holds configuration about our directory authority options. */ +BEGIN_CONF_STRUCT(dirauth_options_t) + +/** Do not permit more than this number of servers per IP address. */ +CONF_VAR(AuthDirMaxServersPerAddr, POSINT, 0, "2") + +END_CONF_STRUCT(dirauth_options_t) diff --git a/src/feature/dirauth/dirauth_options_st.h b/src/feature/dirauth/dirauth_options_st.h new file mode 100644 index 0000000000..93b9cb45bc --- /dev/null +++ b/src/feature/dirauth/dirauth_options_st.h @@ -0,0 +1,22 @@ +/* Copyright (c) 2001 Matej Pfajfar. + * Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * @file dirauth_options_st.h + * @brief Structure dirauth_options_t to hold directory authority options. + **/ + +#ifndef TOR_FEATURE_DIRAUTH_DIRAUTH_OPTIONS_ST_H +#define TOR_FEATURE_DIRAUTH_DIRAUTH_OPTIONS_ST_H + +#include "lib/conf/confdecl.h" +#define CONF_CONTEXT STRUCT +#include "feature/dirauth/dirauth_options.inc" +#undef CONF_CONTEXT + +typedef struct dirauth_options_t dirauth_options_t; + +#endif /* !defined(TOR_FEATURE_DIRAUTH_DIRAUTH_OPTIONS_ST_H) */ diff --git a/src/feature/dirauth/dirauth_stub.c b/src/feature/dirauth/dirauth_stub.c index fac68edd09..b0b4f987f2 100644 --- a/src/feature/dirauth/dirauth_stub.c +++ b/src/feature/dirauth/dirauth_stub.c @@ -11,9 +11,23 @@ #include "orconfig.h" #include "feature/dirauth/dirauth_sys.h" +#include "lib/conf/conftypes.h" +#include "lib/conf/confdecl.h" +#include "lib/subsys/subsys.h" + +/* Declare the options field table for dirauth_options */ +#define CONF_CONTEXT STUB_TABLE +#include "feature/dirauth/dirauth_options.inc" +#undef CONF_CONTEXT + +static const config_format_t dirauth_options_stub_fmt = { + .vars = dirauth_options_t_vars, +}; const struct subsys_fns_t sys_dirauth = { .name = "dirauth", .supported = false, .level = 70, + + .options_format = &dirauth_options_stub_fmt }; diff --git a/src/feature/dirauth/dirauth_sys.c b/src/feature/dirauth/dirauth_sys.c index 090e9129f2..8a4b1abaab 100644 --- a/src/feature/dirauth/dirauth_sys.c +++ b/src/feature/dirauth/dirauth_sys.c @@ -17,9 +17,14 @@ #include "feature/dirauth/dirauth_periodic.h" #include "feature/dirauth/keypin.h" #include "feature/dirauth/process_descs.h" +#include "feature/dirauth/dirauth_config.h" + +#include "feature/dirauth/dirauth_options_st.h" #include "lib/subsys/subsys.h" +static const dirauth_options_t *global_dirauth_options; + static int subsys_dirauth_initialize(void) { @@ -34,6 +39,22 @@ subsys_dirauth_shutdown(void) dirvote_free_all(); dirserv_clear_measured_bw_cache(); keypin_close_journal(); + global_dirauth_options = NULL; +} + +const dirauth_options_t * +dirauth_get_options(void) +{ + tor_assert(global_dirauth_options); + return global_dirauth_options; +} + +static int +dirauth_set_options(void *arg) +{ + dirauth_options_t *opts = arg; + global_dirauth_options = opts; + return 0; } const struct subsys_fns_t sys_dirauth = { @@ -42,4 +63,7 @@ const struct subsys_fns_t sys_dirauth = { .level = 70, .initialize = subsys_dirauth_initialize, .shutdown = subsys_dirauth_shutdown, + + .options_format = &dirauth_options_fmt, + .set_options = dirauth_set_options, }; diff --git a/src/feature/dirauth/dirauth_sys.h b/src/feature/dirauth/dirauth_sys.h index 2d5a0cb3e7..4c09ff64f9 100644 --- a/src/feature/dirauth/dirauth_sys.h +++ b/src/feature/dirauth/dirauth_sys.h @@ -12,6 +12,9 @@ #ifndef DIRAUTH_SYS_H #define DIRAUTH_SYS_H +struct dirauth_options_t; +const struct dirauth_options_t *dirauth_get_options(void); + extern const struct subsys_fns_t sys_dirauth; #endif /* !defined(DIRAUTH_SYS_H) */ diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c index 043bbfc227..13003bf639 100644 --- a/src/feature/dirauth/dirvote.c +++ b/src/feature/dirauth/dirvote.c @@ -41,10 +41,12 @@ #include "feature/dirauth/dirvote.h" #include "feature/dirauth/authmode.h" #include "feature/dirauth/shared_random_state.h" +#include "feature/dirauth/dirauth_sys.h" #include "feature/nodelist/authority_cert_st.h" #include "feature/dircache/cached_dir_st.h" #include "feature/dirclient/dir_server_st.h" +#include "feature/dirauth/dirauth_options_st.h" #include "feature/nodelist/document_signature_st.h" #include "feature/nodelist/microdesc_st.h" #include "feature/nodelist/networkstatus_st.h" @@ -4228,7 +4230,7 @@ compare_routerinfo_by_ip_and_bw_(const void **a, const void **b) static digestmap_t * get_possible_sybil_list(const smartlist_t *routers) { - const or_options_t *options = get_options(); + const dirauth_options_t *options = dirauth_get_options(); digestmap_t *omit_as_sybil; smartlist_t *routers_by_ip = smartlist_new(); uint32_t last_addr; From 8d474e4dc5e4088eb26fc0dd665f22d0cfb06abf Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 15 Dec 2019 19:05:17 -0500 Subject: [PATCH 6/7] Add an integration test for options disabled by dirauth subsystem. --- src/test/conf_examples/dirauth_2/expected | 1 + src/test/conf_examples/dirauth_2/expected_log | 1 + src/test/conf_examples/dirauth_2/expected_log_no_dirauth | 1 + .../conf_examples/dirauth_2/expected_log_no_dirauth_relay | 1 + src/test/conf_examples/dirauth_2/expected_no_dirauth | 0 src/test/conf_examples/dirauth_2/expected_no_dirauth_relay | 0 src/test/conf_examples/dirauth_2/torrc | 5 +++++ 7 files changed, 9 insertions(+) create mode 100644 src/test/conf_examples/dirauth_2/expected create mode 100644 src/test/conf_examples/dirauth_2/expected_log create mode 100644 src/test/conf_examples/dirauth_2/expected_log_no_dirauth create mode 100644 src/test/conf_examples/dirauth_2/expected_log_no_dirauth_relay create mode 100644 src/test/conf_examples/dirauth_2/expected_no_dirauth create mode 100644 src/test/conf_examples/dirauth_2/expected_no_dirauth_relay create mode 100644 src/test/conf_examples/dirauth_2/torrc diff --git a/src/test/conf_examples/dirauth_2/expected b/src/test/conf_examples/dirauth_2/expected new file mode 100644 index 0000000000..19ab024ed3 --- /dev/null +++ b/src/test/conf_examples/dirauth_2/expected @@ -0,0 +1 @@ +AuthDirMaxServersPerAddr 8 diff --git a/src/test/conf_examples/dirauth_2/expected_log b/src/test/conf_examples/dirauth_2/expected_log new file mode 100644 index 0000000000..88611fee9d --- /dev/null +++ b/src/test/conf_examples/dirauth_2/expected_log @@ -0,0 +1 @@ +Read configuration file diff --git a/src/test/conf_examples/dirauth_2/expected_log_no_dirauth b/src/test/conf_examples/dirauth_2/expected_log_no_dirauth new file mode 100644 index 0000000000..01110c5d8c --- /dev/null +++ b/src/test/conf_examples/dirauth_2/expected_log_no_dirauth @@ -0,0 +1 @@ +This copy of Tor was built without support for the option "AuthDirMaxServersPerAddr". Skipping. \ No newline at end of file diff --git a/src/test/conf_examples/dirauth_2/expected_log_no_dirauth_relay b/src/test/conf_examples/dirauth_2/expected_log_no_dirauth_relay new file mode 100644 index 0000000000..01110c5d8c --- /dev/null +++ b/src/test/conf_examples/dirauth_2/expected_log_no_dirauth_relay @@ -0,0 +1 @@ +This copy of Tor was built without support for the option "AuthDirMaxServersPerAddr". Skipping. \ No newline at end of file diff --git a/src/test/conf_examples/dirauth_2/expected_no_dirauth b/src/test/conf_examples/dirauth_2/expected_no_dirauth new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/dirauth_2/expected_no_dirauth_relay b/src/test/conf_examples/dirauth_2/expected_no_dirauth_relay new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/conf_examples/dirauth_2/torrc b/src/test/conf_examples/dirauth_2/torrc new file mode 100644 index 0000000000..bd1cdbc8b9 --- /dev/null +++ b/src/test/conf_examples/dirauth_2/torrc @@ -0,0 +1,5 @@ +# +# This will get accepted if the module is enabled, and ignored if the module +# is disabled. +# +AuthDirMaxServersPerAddr 8 From 13df7449217cec5d4a9baf73adec850614b43633 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 18 Dec 2019 11:49:26 -0500 Subject: [PATCH 7/7] Declare relay/dirauth subsystem levels in a header. This way, we can't get out of sync between the two declarations. --- src/feature/dirauth/dirauth_stub.c | 2 +- src/feature/dirauth/dirauth_sys.c | 2 +- src/feature/dirauth/dirauth_sys.h | 8 ++++++++ src/feature/relay/relay_stub.c | 2 +- src/feature/relay/relay_sys.c | 2 +- src/feature/relay/relay_sys.h | 8 ++++++++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/feature/dirauth/dirauth_stub.c b/src/feature/dirauth/dirauth_stub.c index b0b4f987f2..d902d56d2b 100644 --- a/src/feature/dirauth/dirauth_stub.c +++ b/src/feature/dirauth/dirauth_stub.c @@ -27,7 +27,7 @@ static const config_format_t dirauth_options_stub_fmt = { const struct subsys_fns_t sys_dirauth = { .name = "dirauth", .supported = false, - .level = 70, + .level = DIRAUTH_SUBSYS_LEVEL, .options_format = &dirauth_options_stub_fmt }; diff --git a/src/feature/dirauth/dirauth_sys.c b/src/feature/dirauth/dirauth_sys.c index 8a4b1abaab..6ec25681e7 100644 --- a/src/feature/dirauth/dirauth_sys.c +++ b/src/feature/dirauth/dirauth_sys.c @@ -60,7 +60,7 @@ dirauth_set_options(void *arg) const struct subsys_fns_t sys_dirauth = { .name = "dirauth", .supported = true, - .level = 70, + .level = DIRAUTH_SUBSYS_LEVEL, .initialize = subsys_dirauth_initialize, .shutdown = subsys_dirauth_shutdown, diff --git a/src/feature/dirauth/dirauth_sys.h b/src/feature/dirauth/dirauth_sys.h index 4c09ff64f9..6f116855df 100644 --- a/src/feature/dirauth/dirauth_sys.h +++ b/src/feature/dirauth/dirauth_sys.h @@ -17,4 +17,12 @@ const struct dirauth_options_t *dirauth_get_options(void); extern const struct subsys_fns_t sys_dirauth; +/** + * Subsystem level for the directory-authority system. + * + * Defined here so that it can be shared between the real and stub + * definitions. + **/ +#define DIRAUTH_SUBSYS_LEVEL 70 + #endif /* !defined(DIRAUTH_SYS_H) */ diff --git a/src/feature/relay/relay_stub.c b/src/feature/relay/relay_stub.c index a23b991862..36daaa7bd7 100644 --- a/src/feature/relay/relay_stub.c +++ b/src/feature/relay/relay_stub.c @@ -16,5 +16,5 @@ const struct subsys_fns_t sys_relay = { .name = "relay", .supported = false, - .level = 50, + .level = RELAY_SUBSYS_LEVEL, }; diff --git a/src/feature/relay/relay_sys.c b/src/feature/relay/relay_sys.c index 106e88b2a5..dfddff27f2 100644 --- a/src/feature/relay/relay_sys.c +++ b/src/feature/relay/relay_sys.c @@ -42,7 +42,7 @@ subsys_relay_shutdown(void) const struct subsys_fns_t sys_relay = { .name = "relay", .supported = true, - .level = 50, + .level = RELAY_SUBSYS_LEVEL, .initialize = subsys_relay_initialize, .shutdown = subsys_relay_shutdown, }; diff --git a/src/feature/relay/relay_sys.h b/src/feature/relay/relay_sys.h index 32e21d90d8..ba3b5ccf4e 100644 --- a/src/feature/relay/relay_sys.h +++ b/src/feature/relay/relay_sys.h @@ -14,4 +14,12 @@ extern const struct subsys_fns_t sys_relay; +/** + * Subsystem level for the relay system. + * + * Defined here so that it can be shared between the real and stub + * definitions. + **/ +#define RELAY_SUBSYS_LEVEL 50 + #endif /* !defined(TOR_FEATURE_RELAY_RELAY_SYS_H) */