Tor  0.4.6.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-2020, 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 
92 #endif /* defined(RELAY_CONFIG_PRIVATE) */
93 
94 #else /* !defined(HAVE_MODULE_RELAY) */
95 
96 #include "lib/cc/compat_compiler.h"
97 
98 /** When tor is compiled with the relay module disabled, it can't be
99  * configured as a relay or bridge.
100  *
101  * Always sets ClientOnly to 1.
102  *
103  * Returns -1 and sets msg to a newly allocated string, if ORPort, DirPort,
104  * DirCache, or BridgeRelay are set in options. Otherwise returns 0. */
105 static inline int
106 options_validate_relay_mode(const struct or_options_t *old_options,
107  struct or_options_t *options,
108  char **msg)
109 {
110  (void)old_options;
111 
112  /* Only check the primary options for now, #29211 will disable more
113  * options. These ORPort and DirPort checks are too strict, and will
114  * reject valid configs that disable ports, like "ORPort 0". */
115  if (options->DirCache ||
116  options->BridgeRelay ||
117  options->ORPort_lines ||
118  options->DirPort_lines) {
119  /* REJECT() this configuration */
120  *msg = tor_strdup("This tor was built with relay mode disabled. "
121  "It can not be configured with an ORPort, a DirPort, "
122  "DirCache 1, or BridgeRelay 1.");
123  return -1;
124  }
125 
126  return 0;
127 }
128 
129 static inline int
131  char **msg,
132  smartlist_t *ports_out,
133  int *have_low_ports_out)
134 {
135  (void)options;
136  (void)msg;
137  (void)ports_out;
138  if (*have_low_ports_out < 0)
139  *have_low_ports_out = 0;
140  return 0;
141 }
142 
143 #define relay_get_dirportfrontpage() \
144  (NULL)
145 #define relay_config_free_all() \
146  STMT_BEGIN STMT_END
147 
148 #define relay_get_effective_bwrate(options) \
149  (((void)(options)),0)
150 #define relay_get_effective_bwburst(options) \
151  (((void)(options)),0)
152 
153 #define port_warn_nonlocal_ext_orports(ports, portname) \
154  (((void)(ports)),((void)(portname)))
155 
156 #define port_update_port_set_relay(options, ports) \
157  (((void)(options)),((void)(ports)))
158 
159 #define options_validate_relay_os(old_options, options, msg) \
160  (((void)(old_options)),((void)(options)),((void)(msg)),0)
161 #define options_validate_relay_info(old_options, options, msg) \
162  (((void)(old_options)),((void)(options)),((void)(msg)),0)
163 #define options_validate_publish_server(old_options, options, msg) \
164  (((void)(old_options)),((void)(options)),((void)(msg)),0)
165 #define options_validate_relay_padding(old_options, options, msg) \
166  (((void)(old_options)),((void)(options)),((void)(msg)),0)
167 #define options_validate_relay_bandwidth(old_options, options, msg) \
168  (((void)(old_options)),((void)(options)),((void)(msg)),0)
169 #define options_validate_relay_accounting(old_options, options, msg) \
170  (((void)(old_options)),((void)(options)),((void)(msg)),0)
171 #define options_validate_relay_testing(old_options, options, msg) \
172  (((void)(old_options)),((void)(options)),((void)(msg)),0)
173 
174 #define options_act_relay(old_options) \
175  (((void)(old_options)),0)
176 #define options_act_relay_accounting(old_options) \
177  (((void)(old_options)),0)
178 #define options_act_relay_bandwidth(old_options) \
179  (((void)(old_options)),0)
180 #define options_act_bridge_stats(old_options) \
181  (((void)(old_options)),0)
182 
183 #define options_act_relay_stats(old_options, print_notice_out) \
184  (((void)(old_options)),((void)(print_notice_out)),0)
185 #define options_act_relay_stats_msg() \
186  STMT_BEGIN STMT_END
187 
188 #define options_act_relay_desc(old_options) \
189  (((void)(old_options)),0)
190 #define options_act_relay_dos(old_options) \
191  (((void)(old_options)),0)
192 #define options_act_relay_dir(old_options) \
193  (((void)(old_options)),0)
194 
195 #endif /* defined(HAVE_MODULE_RELAY) */
196 
197 #endif /* !defined(TOR_FEATURE_RELAY_RELAY_CONFIG_H) */
or_options_t::ORPort_lines
struct config_line_t * ORPort_lines
Definition: or_options_st.h:164
options_validate_relay_bandwidth
int options_validate_relay_bandwidth(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:755
options_act_relay_bandwidth
int options_act_relay_bandwidth(const or_options_t *old_options)
Definition: relay_config.c:1304
or_options_t::BridgeRelay
int BridgeRelay
Definition: or_options_st.h:271
torint.h
Integer definitions used throughout Tor.
options_validate_publish_server
int options_validate_publish_server(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:656
options_validate_relay_padding
int options_validate_relay_padding(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:713
options_validate_relay_info
int options_validate_relay_info(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:516
check_bridge_distribution_setting
STATIC int check_bridge_distribution_setting(const char *bd)
Definition: relay_config.c:620
options_validate_relay_os
int options_validate_relay_os(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:479
relay_config_free_all
void relay_config_free_all(void)
Definition: relay_config.c:84
remove_duplicate_orports
STATIC void remove_duplicate_orports(smartlist_t *ports)
Definition: relay_config.c:204
relay_get_effective_bwburst
uint32_t relay_get_effective_bwburst(const or_options_t *options)
Definition: relay_config.c:106
options_act_relay_stats_msg
void options_act_relay_stats_msg(void)
Definition: relay_config.c:1485
options_act_relay_dir
int options_act_relay_dir(const or_options_t *old_options)
Definition: relay_config.c:1557
options_act_bridge_stats
int options_act_bridge_stats(const or_options_t *old_options)
Definition: relay_config.c:1333
options_validate_relay_mode
static int options_validate_relay_mode(const struct or_options_t *old_options, struct or_options_t *options, char **msg)
Definition: relay_config.h:106
options_act_relay_desc
int options_act_relay_desc(const or_options_t *old_options)
Definition: relay_config.c:1503
options_act_relay_dos
int options_act_relay_dos(const or_options_t *old_options)
Definition: relay_config.c:1528
MOCK_DECL
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
options_act_relay
int options_act_relay(const or_options_t *old_options)
Definition: relay_config.c:1212
port_parse_ports_relay
int port_parse_ports_relay(or_options_t *options, char **msg, smartlist_t *ports_out, int *have_low_ports_out)
Definition: relay_config.c:368
port_warn_nonlocal_ext_orports
void port_warn_nonlocal_ext_orports(const smartlist_t *ports, const char *portname)
Definition: relay_config.c:118
testsupport.h
Macros to implement mocking and selective exposure for the test code.
options_validate_relay_accounting
int options_validate_relay_accounting(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:847
options_validate_relay_testing
int options_validate_relay_testing(const or_options_t *old_options, or_options_t *options, char **msg)
Definition: relay_config.c:1113
relay_get_dirportfrontpage
const char * relay_get_dirportfrontpage(void)
Definition: relay_config.c:75
relay_get_effective_bwrate
uint32_t relay_get_effective_bwrate(const or_options_t *options)
Definition: relay_config.c:92
or_options_t
Definition: or_options_st.h:64
or_options_t::DirPort_lines
struct config_line_t * DirPort_lines
Definition: or_options_st.h:194
port_update_port_set_relay
void port_update_port_set_relay(or_options_t *options, const smartlist_t *ports)
Definition: relay_config.c:449
or_options_t::DirCache
int DirCache
Definition: or_options_st.h:601
STATIC
#define STATIC
Definition: testsupport.h:32
options_act_relay_accounting
int options_act_relay_accounting(const or_options_t *old_options)
Definition: relay_config.c:1274
have_enough_mem_for_dircache
STATIC int have_enough_mem_for_dircache(const or_options_t *options, size_t total_mem, char **msg)
Definition: relay_config.c:985
smartlist_t
Definition: smartlist_core.h:26
compat_compiler.h
Utility macros to handle different features and behavior in different compilers.
options_act_relay_stats
int options_act_relay_stats(const or_options_t *old_options, bool *print_notice_out)
Definition: relay_config.c:1387