Tor  0.4.7.0-alpha-dev
relay_config.h
Go to the documentation of this file.
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 */
6 
7 /**
8  * @file relay_config.h
9  * @brief Header for feature/relay/relay_config.c
10  **/
11 
12 #ifndef TOR_FEATURE_RELAY_RELAY_CONFIG_H
13 #define TOR_FEATURE_RELAY_RELAY_CONFIG_H
14 
15 struct or_options_t;
16 
17 #ifdef HAVE_MODULE_RELAY
18 
19 #include "lib/cc/torint.h"
21 
22 struct smartlist_t;
23 
24 int options_validate_relay_mode(const struct or_options_t *old_options,
25  struct or_options_t *options,
26  char **msg);
27 
28 MOCK_DECL(const char*, relay_get_dirportfrontpage, (void));
29 void relay_config_free_all(void);
30 
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);
33 
34 void port_warn_nonlocal_ext_orports(const struct smartlist_t *ports,
35  const char *portname);
36 
37 int port_parse_ports_relay(struct or_options_t *options,
38  char **msg,
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);
43 
44 int options_validate_relay_os(const struct or_options_t *old_options,
45  struct or_options_t *options,
46  char **msg);
47 
48 int options_validate_relay_info(const struct or_options_t *old_options,
49  struct or_options_t *options,
50  char **msg);
51 
52 int options_validate_publish_server(const struct or_options_t *old_options,
53  struct or_options_t *options,
54  char **msg);
55 
56 int options_validate_relay_padding(const struct or_options_t *old_options,
57  struct or_options_t *options,
58  char **msg);
59 
60 int options_validate_relay_bandwidth(const struct or_options_t *old_options,
61  struct or_options_t *options,
62  char **msg);
63 
64 int options_validate_relay_accounting(const struct or_options_t *old_options,
65  struct or_options_t *options,
66  char **msg);
67 
68 int options_validate_relay_testing(const struct or_options_t *old_options,
69  struct or_options_t *options,
70  char **msg);
71 
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);
76 
77 int options_act_relay_stats(const struct or_options_t *old_options,
78  bool *print_notice_out);
80 
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);
84 
85 #ifdef RELAY_CONFIG_PRIVATE
86 
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);
91 #ifdef TOR_UNIT_TESTS
92 
93 struct port_cfg_t;
94 STATIC const char *describe_relay_port(const struct port_cfg_t *port);
95 
96 #endif /* defined(TOR_UNIT_TESTS) */
97 
98 #endif /* defined(RELAY_CONFIG_PRIVATE) */
99 
100 #else /* !defined(HAVE_MODULE_RELAY) */
101 
102 #include "lib/cc/compat_compiler.h"
103 
104 /** When tor is compiled with the relay module disabled, it can't be
105  * configured as a relay or bridge.
106  *
107  * Always sets ClientOnly to 1.
108  *
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. */
111 static inline int
112 options_validate_relay_mode(const struct or_options_t *old_options,
113  struct or_options_t *options,
114  char **msg)
115 {
116  (void)old_options;
117 
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.");
129  return -1;
130  }
131 
132  return 0;
133 }
134 
135 static inline int
137  char **msg,
138  smartlist_t *ports_out,
139  int *have_low_ports_out)
140 {
141  (void)options;
142  (void)msg;
143  (void)ports_out;
144  if (*have_low_ports_out < 0)
145  *have_low_ports_out = 0;
146  return 0;
147 }
148 
149 #define relay_get_dirportfrontpage() \
150  (NULL)
151 #define relay_config_free_all() \
152  STMT_BEGIN STMT_END
153 
154 #define relay_get_effective_bwrate(options) \
155  (((void)(options)),0)
156 #define relay_get_effective_bwburst(options) \
157  (((void)(options)),0)
158 
159 #define port_warn_nonlocal_ext_orports(ports, portname) \
160  (((void)(ports)),((void)(portname)))
161 
162 #define port_update_port_set_relay(options, ports) \
163  (((void)(options)),((void)(ports)))
164 
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)
179 
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)
188 
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() \
192  STMT_BEGIN STMT_END
193 
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)
200 
201 #endif /* defined(HAVE_MODULE_RELAY) */
202 
203 #endif /* !defined(TOR_FEATURE_RELAY_RELAY_CONFIG_H) */
Utility macros to handle different features and behavior in different compilers.
STATIC void remove_duplicate_orports(smartlist_t *ports)
Definition: relay_config.c:249
STATIC int check_bridge_distribution_setting(const char *bd)
Definition: relay_config.c:690
int options_act_relay_bandwidth(const or_options_t *old_options)
int options_validate_relay_padding(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:783
int options_act_relay_stats(const or_options_t *old_options, bool *print_notice_out)
void port_update_port_set_relay(or_options_t *options, const smartlist_t *ports)
Definition: relay_config.c:519
int options_act_relay(const or_options_t *old_options)
int options_validate_relay_accounting(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:917
const char * relay_get_dirportfrontpage(void)
Definition: relay_config.c:75
void relay_config_free_all(void)
Definition: relay_config.c:84
int options_validate_relay_bandwidth(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:825
int options_validate_relay_os(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:549
int options_act_relay_dir(const or_options_t *old_options)
void port_warn_nonlocal_ext_orports(const smartlist_t *ports, const char *portname)
Definition: relay_config.c:118
int port_parse_ports_relay(or_options_t *options, char **msg, smartlist_t *ports_out, int *have_low_ports_out)
Definition: relay_config.c:438
int options_act_relay_accounting(const or_options_t *old_options)
void options_act_relay_stats_msg(void)
uint32_t relay_get_effective_bwrate(const or_options_t *options)
Definition: relay_config.c:92
uint32_t relay_get_effective_bwburst(const or_options_t *options)
Definition: relay_config.c:106
int options_validate_relay_info(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:586
int options_validate_publish_server(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:726
int options_act_relay_dos(const or_options_t *old_options)
STATIC const char * describe_relay_port(const port_cfg_t *port)
Definition: relay_config.c:155
int options_act_relay_desc(const or_options_t *old_options)
int options_act_bridge_stats(const or_options_t *old_options)
int options_validate_relay_testing(const or_options_t *old_options, or_options_t *options, char **msg)
STATIC int have_enough_mem_for_dircache(const or_options_t *options, size_t total_mem, char **msg)
static int options_validate_relay_mode(const struct or_options_t *old_options, struct or_options_t *options, char **msg)
Definition: relay_config.h:112
struct config_line_t * ORPort_lines
struct config_line_t * DirPort_lines
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
Integer definitions used throughout Tor.