config: Move server transport actions into the relay module

This commit:
* moves server transport config checks into transport_config.c,
* adds thin wrappers to make the moved code compile.

No functional changes: the moved code is still enabled,
even if the relay module is disabled. (Some of the checks
are re-ordered, so the order of some warnings may change.)

Part of 32213.
This commit is contained in:
teor 2019-10-30 13:55:49 +10:00
parent 0a511778eb
commit 6d03c05665
3 changed files with 64 additions and 33 deletions

View File

@ -1865,19 +1865,6 @@ options_act,(const or_options_t *old_options))
"in a non-anonymous mode. It will provide NO ANONYMITY.");
}
/* If we are a bridge with a pluggable transport proxy but no
Extended ORPort, inform the user that they are missing out. */
if (server_mode(options) && options->ServerTransportPlugin &&
!options->ExtORPort_lines) {
log_notice(LD_CONFIG, "We use pluggable transports but the Extended "
"ORPort is disabled. Tor and your pluggable transports proxy "
"communicate with each other via the Extended ORPort so it "
"is suggested you enable it: it will also allow your Bridge "
"to collect statistics about its clients that use pluggable "
"transports. Please enable it using the ExtORPort torrc option "
"(e.g. set 'ExtORPort auto').");
}
if (options->Bridges) {
mark_bridge_list();
for (cl = options->Bridges; cl; cl = cl->next) {
@ -1930,13 +1917,7 @@ options_act,(const or_options_t *old_options))
rep_hist_load_mtbf_data(time(NULL));
}
/* If we have an ExtORPort, initialize its auth cookie. */
if (running_tor &&
init_ext_or_cookie_authentication(!!options->ExtORPort_lines) < 0) {
log_warn(LD_CONFIG,"Error creating Extended ORPort cookie file.");
return -1;
}
/* 31851: some of the code in these functions is relay-only */
mark_transport_list();
pt_prepare_proxy_list_for_config_read();
if (!options->DisableNetwork) {
@ -1952,20 +1933,11 @@ options_act,(const or_options_t *old_options))
}
}
}
if (options->ServerTransportPlugin && server_mode(options)) {
for (cl = options->ServerTransportPlugin; cl; cl = cl->next) {
if (parse_transport_line(options, cl->value, 0, 1) < 0) {
// LCOV_EXCL_START
log_warn(LD_BUG,
"Previously validated ServerTransportPlugin line "
"could not be added!");
return -1;
// LCOV_EXCL_STOP
}
}
}
}
if (options_act_server_transport(old_options) < 0)
return -1;
sweep_transport_list();
sweep_proxy_list();

View File

@ -245,3 +245,60 @@ options_validate_server_transport(const or_options_t *old_options,
return 0;
}
/** Fetch the active option list, and take server pluggable transport actions
* based on it. All of the things we do should survive being done repeatedly.
* If present, <b>old_options</b> contains the previous value of the options.
*
* Return 0 if all goes well, return -1 if it's time to die.
*
* Note: We haven't moved all the "act on new configuration" logic
* into the options_act* functions yet. Some is still in do_hup() and other
* places.
*/
int
options_act_server_transport(const or_options_t *old_options)
{
(void)old_options;
config_line_t *cl;
const or_options_t *options = get_options();
int running_tor = options->command == CMD_RUN_TOR;
/* If we are a bridge with a pluggable transport proxy but no
Extended ORPort, inform the user that they are missing out. */
if (server_mode(options) && options->ServerTransportPlugin &&
!options->ExtORPort_lines) {
log_notice(LD_CONFIG, "We use pluggable transports but the Extended "
"ORPort is disabled. Tor and your pluggable transports proxy "
"communicate with each other via the Extended ORPort so it "
"is suggested you enable it: it will also allow your Bridge "
"to collect statistics about its clients that use pluggable "
"transports. Please enable it using the ExtORPort torrc option "
"(e.g. set 'ExtORPort auto').");
}
/* If we have an ExtORPort, initialize its auth cookie. */
if (running_tor &&
init_ext_or_cookie_authentication(!!options->ExtORPort_lines) < 0) {
log_warn(LD_CONFIG,"Error creating Extended ORPort cookie file.");
return -1;
}
if (!options->DisableNetwork) {
if (options->ServerTransportPlugin && server_mode(options)) {
for (cl = options->ServerTransportPlugin; cl; cl = cl->next) {
if (parse_transport_line(options, cl->value, 0, 1) < 0) {
// LCOV_EXCL_START
log_warn(LD_BUG,
"Previously validated ServerTransportPlugin line "
"could not be added!");
return -1;
// LCOV_EXCL_STOP
}
}
}
}
return 0;
}

View File

@ -24,4 +24,6 @@ int options_validate_server_transport(const or_options_t *old_options,
or_options_t *options,
char **msg);
int options_act_server_transport(const or_options_t *old_options);
#endif /* !defined(TOR_FEATURE_RELAY_TRANSPORT_CONFIG_H) */