From 0a511778eb6f3ca00d0e3da99327cce2cf179830 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 29 Oct 2019 17:57:04 +1000 Subject: config: Move bw & other configs into the dirauth module This commit: * moves bandwidth checks into dirauth_config, and * moves some other minor checks into dirauth_config. The moved code is disabled when the dirauth module is disabled. (And some of the checks are re-ordered, so the order of some warnings may change.) Part of 32213. --- src/feature/dirauth/dirauth_config.c | 45 ++++++++++++++++++++++++++++++++++++ src/feature/dirauth/dirauth_config.h | 7 ++++++ 2 files changed, 52 insertions(+) (limited to 'src/feature/dirauth') diff --git a/src/feature/dirauth/dirauth_config.c b/src/feature/dirauth/dirauth_config.c index 56a71e950d..6574edb540 100644 --- a/src/feature/dirauth/dirauth_config.c +++ b/src/feature/dirauth/dirauth_config.c @@ -61,6 +61,11 @@ options_validate_dirauth_mode(const or_options_t *old_options, return -1; if (options->AuthoritativeDir) { + /* confirm that our address isn't broken, so we can complain now */ + uint32_t tmp; + if (resolve_my_address(LOG_WARN, options, &tmp, NULL, NULL) < 0) + REJECT("Failed to resolve/guess local address. See logs for details."); + if (!options->ContactInfo && !options->TestingTorNetwork) REJECT("Authoritative directory servers must set ContactInfo"); if (!options->RecommendedClientVersions) @@ -117,6 +122,46 @@ options_validate_dirauth_mode(const or_options_t *old_options, REJECT("Running as authoritative directory, but ClientOnly also set."); } + /* 31851: the tests expect us to validate these options, even when we are + * not in authority mode. */ + if (options->MinUptimeHidServDirectoryV2 < 0) { + log_warn(LD_CONFIG, "MinUptimeHidServDirectoryV2 option must be at " + "least 0 seconds. Changing to 0."); + options->MinUptimeHidServDirectoryV2 = 0; + } + + return 0; +} + +/** + * Legacy validation/normalization function for the dirauth bandwidth options + * in options. Uses old_options as the previous options. + * + * Returns 0 on success, returns -1 and sets *msg to a newly allocated string + * on error. + */ +int +options_validate_dirauth_bandwidth(const or_options_t *old_options, + or_options_t *options, + char **msg) +{ + (void)old_options; + + if (BUG(!options)) + return -1; + + if (BUG(!msg)) + return -1; + + /* 31851: the tests expect us to validate these options, even when we are + * not in authority mode. */ + if (ensure_bandwidth_cap(&options->AuthDirFastGuarantee, + "AuthDirFastGuarantee", msg) < 0) + return -1; + if (ensure_bandwidth_cap(&options->AuthDirGuardBWGuarantee, + "AuthDirGuardBWGuarantee", msg) < 0) + return -1; + return 0; } diff --git a/src/feature/dirauth/dirauth_config.h b/src/feature/dirauth/dirauth_config.h index 95aef3de95..2c67c62ecb 100644 --- a/src/feature/dirauth/dirauth_config.h +++ b/src/feature/dirauth/dirauth_config.h @@ -20,6 +20,10 @@ int options_validate_dirauth_mode(const or_options_t *old_options, or_options_t *options, char **msg); +int options_validate_dirauth_bandwidth(const or_options_t *old_options, + or_options_t *options, + char **msg); + int options_validate_dirauth_schedule(const or_options_t *old_options, or_options_t *options, char **msg); @@ -56,6 +60,9 @@ options_validate_dirauth_mode(const or_options_t *old_options, return 0; } +#define options_validate_dirauth_bandwidth(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) + #define options_validate_dirauth_schedule(old_options, options, msg) \ (((void)(old_options)),((void)(options)),((void)(msg)),0) -- cgit v1.2.3-54-g00ecf