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