1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * @brief Header for feature/relay/relay_config.c
12 #ifndef TOR_FEATURE_RELAY_RELAY_CONFIG_H
13 #define TOR_FEATURE_RELAY_RELAY_CONFIG_H
17 #ifdef HAVE_MODULE_RELAY
19 #include "lib/cc/torint.h"
20 #include "lib/testsupport/testsupport.h"
24 int options_validate_relay_mode(const struct or_options_t
*old_options
,
25 struct or_options_t
*options
,
28 MOCK_DECL(const char*, relay_get_dirportfrontpage
, (void));
29 void relay_config_free_all(void);
31 uint32_t relay_get_effective_bwrate(const struct or_options_t
*options
);
32 uint32_t relay_get_effective_bwburst(const struct or_options_t
*options
);
34 void port_warn_nonlocal_ext_orports(const struct smartlist_t
*ports
,
35 const char *portname
);
37 int port_parse_ports_relay(struct or_options_t
*options
,
39 struct smartlist_t
*ports_out
,
40 int *have_low_ports_out
);
41 void port_update_port_set_relay(struct or_options_t
*options
,
42 const struct smartlist_t
*ports
);
44 int options_validate_relay_os(const struct or_options_t
*old_options
,
45 struct or_options_t
*options
,
48 int options_validate_relay_info(const struct or_options_t
*old_options
,
49 struct or_options_t
*options
,
52 int options_validate_publish_server(const struct or_options_t
*old_options
,
53 struct or_options_t
*options
,
56 int options_validate_relay_padding(const struct or_options_t
*old_options
,
57 struct or_options_t
*options
,
60 int options_validate_relay_bandwidth(const struct or_options_t
*old_options
,
61 struct or_options_t
*options
,
64 int options_validate_relay_accounting(const struct or_options_t
*old_options
,
65 struct or_options_t
*options
,
68 int options_validate_relay_testing(const struct or_options_t
*old_options
,
69 struct or_options_t
*options
,
72 int options_act_relay(const struct or_options_t
*old_options
);
73 int options_act_relay_accounting(const struct or_options_t
*old_options
);
74 int options_act_relay_bandwidth(const struct or_options_t
*old_options
);
75 int options_act_bridge_stats(const struct or_options_t
*old_options
);
77 int options_act_relay_stats(const struct or_options_t
*old_options
,
78 bool *print_notice_out
);
79 void options_act_relay_stats_msg(void);
81 int options_act_relay_desc(const struct or_options_t
*old_options
);
82 int options_act_relay_dos(const struct or_options_t
*old_options
);
83 int options_act_relay_dir(const struct or_options_t
*old_options
);
85 #ifdef RELAY_CONFIG_PRIVATE
87 STATIC
void remove_duplicate_orports(struct smartlist_t
*ports
);
88 STATIC
int check_bridge_distribution_setting(const char *bd
);
89 STATIC
int have_enough_mem_for_dircache(const struct or_options_t
*options
,
90 size_t total_mem
, char **msg
);
94 STATIC
const char *describe_relay_port(const struct port_cfg_t
*port
);
96 #endif /* defined(TOR_UNIT_TESTS) */
98 #endif /* defined(RELAY_CONFIG_PRIVATE) */
100 #else /* !defined(HAVE_MODULE_RELAY) */
102 #include "lib/cc/compat_compiler.h"
104 /** When tor is compiled with the relay module disabled, it can't be
105 * configured as a relay or bridge.
107 * Always sets ClientOnly to 1.
109 * Returns -1 and sets msg to a newly allocated string, if ORPort, DirPort,
110 * DirCache, or BridgeRelay are set in options. Otherwise returns 0. */
112 options_validate_relay_mode(const struct or_options_t
*old_options
,
113 struct or_options_t
*options
,
118 /* Only check the primary options for now, #29211 will disable more
119 * options. These ORPort and DirPort checks are too strict, and will
120 * reject valid configs that disable ports, like "ORPort 0". */
121 if (options
->DirCache
||
122 options
->BridgeRelay
||
123 options
->ORPort_lines
||
124 options
->DirPort_lines
) {
125 /* REJECT() this configuration */
126 *msg
= tor_strdup("This tor was built with relay mode disabled. "
127 "It can not be configured with an ORPort, a DirPort, "
128 "DirCache 1, or BridgeRelay 1.");
136 port_parse_ports_relay(or_options_t
*options
,
138 smartlist_t
*ports_out
,
139 int *have_low_ports_out
)
144 if (*have_low_ports_out
< 0)
145 *have_low_ports_out
= 0;
149 #define relay_get_dirportfrontpage() \
151 #define relay_config_free_all() \
154 #define relay_get_effective_bwrate(options) \
155 (((void)(options)),0)
156 #define relay_get_effective_bwburst(options) \
157 (((void)(options)),0)
159 #define port_warn_nonlocal_ext_orports(ports, portname) \
160 (((void)(ports)),((void)(portname)))
162 #define port_update_port_set_relay(options, ports) \
163 (((void)(options)),((void)(ports)))
165 #define options_validate_relay_os(old_options, options, msg) \
166 (((void)(old_options)),((void)(options)),((void)(msg)),0)
167 #define options_validate_relay_info(old_options, options, msg) \
168 (((void)(old_options)),((void)(options)),((void)(msg)),0)
169 #define options_validate_publish_server(old_options, options, msg) \
170 (((void)(old_options)),((void)(options)),((void)(msg)),0)
171 #define options_validate_relay_padding(old_options, options, msg) \
172 (((void)(old_options)),((void)(options)),((void)(msg)),0)
173 #define options_validate_relay_bandwidth(old_options, options, msg) \
174 (((void)(old_options)),((void)(options)),((void)(msg)),0)
175 #define options_validate_relay_accounting(old_options, options, msg) \
176 (((void)(old_options)),((void)(options)),((void)(msg)),0)
177 #define options_validate_relay_testing(old_options, options, msg) \
178 (((void)(old_options)),((void)(options)),((void)(msg)),0)
180 #define options_act_relay(old_options) \
181 (((void)(old_options)),0)
182 #define options_act_relay_accounting(old_options) \
183 (((void)(old_options)),0)
184 #define options_act_relay_bandwidth(old_options) \
185 (((void)(old_options)),0)
186 #define options_act_bridge_stats(old_options) \
187 (((void)(old_options)),0)
189 #define options_act_relay_stats(old_options, print_notice_out) \
190 (((void)(old_options)),((void)(print_notice_out)),0)
191 #define options_act_relay_stats_msg() \
194 #define options_act_relay_desc(old_options) \
195 (((void)(old_options)),0)
196 #define options_act_relay_dos(old_options) \
197 (((void)(old_options)),0)
198 #define options_act_relay_dir(old_options) \
199 (((void)(old_options)),0)
201 #endif /* defined(HAVE_MODULE_RELAY) */
203 #endif /* !defined(TOR_FEATURE_RELAY_RELAY_CONFIG_H) */