Always set bridge-distribution-request on bridges' descriptors.

Also, warn the user if the BridgeDistribution option is
unrecognized, and reject the value if it is invalid.
This commit is contained in:
Nick Mathewson 2017-10-23 10:52:42 -04:00
parent 3581f93d27
commit 613b18f0af
2 changed files with 47 additions and 6 deletions

View File

@ -654,7 +654,7 @@ static int parse_ports(or_options_t *options, int validate_only,
static int check_server_ports(const smartlist_t *ports, static int check_server_ports(const smartlist_t *ports,
const or_options_t *options, const or_options_t *options,
int *num_low_ports_out); int *num_low_ports_out);
static int check_bridge_distribution_setting(const char *bd);
static int validate_data_directory(or_options_t *options); static int validate_data_directory(or_options_t *options);
static int write_configuration_file(const char *fname, static int write_configuration_file(const char *fname,
const or_options_t *options); const or_options_t *options);
@ -3347,9 +3347,15 @@ options_validate(or_options_t *old_options, or_options_t *options,
options->DirPort_set = 0; options->DirPort_set = 0;
} }
if (options->BridgeDistribution && !options->BridgeRelay) { if (options->BridgeDistribution) {
REJECT("You have set BridgeDistribution, yet you didn't set BridgeRelay!"); if (!options->BridgeRelay) {
REJECT("You set BridgeDistribution, but you didn't set BridgeRelay!");
} }
if (check_bridge_distribution_setting(options->BridgeDistribution) < 0) {
REJECT("Invalid BridgeDistribution value.");
}
}
if (options->MinUptimeHidServDirectoryV2 < 0) { if (options->MinUptimeHidServDirectoryV2 < 0) {
log_warn(LD_CONFIG, "MinUptimeHidServDirectoryV2 option must be at " log_warn(LD_CONFIG, "MinUptimeHidServDirectoryV2 option must be at "
@ -6344,6 +6350,37 @@ warn_client_dns_cache(const char *option, int disabling)
"to your destination."); "to your destination.");
} }
/** Warn if <b>bd</b> is an unrecognized bridge distribution setting;
* return -1 if it is invalid. */
static int
check_bridge_distribution_setting(const char *bd)
{
if (bd == NULL)
return 0;
const char *RECOGNIZED[] = {
"none", "any", "https", "email", "moat", "hyphae"
};
unsigned i;
for (i = 0; i < ARRAY_LENGTH(RECOGNIZED); ++i) {
if (!strcmp(bd, RECOGNIZED[i]))
return 0;
}
const char *cp = bd;
// Method = (KeywordChar | "_") +
while (TOR_ISALNUM(*cp) || *cp == '-' || *cp == '_')
++cp;
if (*cp == 0) {
log_warn(LD_CONFIG, "Unrecognized BridgeDistribution value %s. I'll "
"assume you know what you are doing...", escaped(bd));
return 0; // we reached the end of the string; all is well
} else {
return -1; // we found a bad character in the string.
}
}
/** /**
* Parse port configuration for a single port type. * Parse port configuration for a single port type.
* *

View File

@ -2867,9 +2867,13 @@ router_dump_router_to_string(routerinfo_t *router,
smartlist_add_asprintf(chunks, "contact %s\n", ci); smartlist_add_asprintf(chunks, "contact %s\n", ci);
} }
if (options->BridgeRelay && options->BridgeDistribution && if (options->BridgeRelay) {
strlen(options->BridgeDistribution)) { const char *bd;
const char *bd = options->BridgeDistribution; if (options->BridgeDistribution && strlen(options->BridgeDistribution)) {
bd = options->BridgeDistribution;
} else {
bd = "any";
}
if (strchr(bd, '\n') || strchr(bd, '\r')) if (strchr(bd, '\n') || strchr(bd, '\r'))
bd = escaped(bd); bd = escaped(bd);
smartlist_add_asprintf(chunks, "bridge-distribution-request %s\n", bd); smartlist_add_asprintf(chunks, "bridge-distribution-request %s\n", bd);