copy changelog to releasenotes
[tor.git] / src / or / config.h
blob664553251469cd1baf1d32a570cabfb53c1c5b05
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-2016, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file config.h
9 * \brief Header file for config.c.
10 **/
12 #ifndef TOR_CONFIG_H
13 #define TOR_CONFIG_H
15 #include "testsupport.h"
17 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(DARWIN)
18 #define KERNEL_MAY_SUPPORT_IPFW
19 #endif
21 MOCK_DECL(const char*, get_dirportfrontpage, (void));
22 MOCK_DECL(const or_options_t *, get_options, (void));
23 MOCK_DECL(or_options_t *, get_options_mutable, (void));
24 int set_options(or_options_t *new_val, char **msg);
25 void config_free_all(void);
26 const char *safe_str_client(const char *address);
27 const char *safe_str(const char *address);
28 const char *escaped_safe_str_client(const char *address);
29 const char *escaped_safe_str(const char *address);
30 const char *get_version(void);
31 const char *get_short_version(void);
32 setopt_err_t options_trial_assign(config_line_t *list, unsigned flags,
33 char **msg);
35 uint32_t get_last_resolved_addr(void);
36 void reset_last_resolved_addr(void);
37 int resolve_my_address(int warn_severity, const or_options_t *options,
38 uint32_t *addr_out,
39 const char **method_out, char **hostname_out);
40 MOCK_DECL(int, is_local_addr, (const tor_addr_t *addr));
41 void options_init(or_options_t *options);
43 #define OPTIONS_DUMP_MINIMAL 1
44 #define OPTIONS_DUMP_DEFAULTS 2
45 #define OPTIONS_DUMP_ALL 3
46 char *options_dump(const or_options_t *options, int how_to_dump);
47 int options_init_from_torrc(int argc, char **argv);
48 setopt_err_t options_init_from_string(const char *cf_defaults, const char *cf,
49 int command, const char *command_arg, char **msg);
50 int option_is_recognized(const char *key);
51 const char *option_get_canonical_name(const char *key);
52 config_line_t *option_get_assignment(const or_options_t *options,
53 const char *key);
54 int options_save_current(void);
55 const char *get_torrc_fname(int defaults_fname);
56 MOCK_DECL(char *,
57 options_get_datadir_fname2_suffix,
58 (const or_options_t *options,
59 const char *sub1, const char *sub2,
60 const char *suffix));
61 #define get_datadir_fname2_suffix(sub1, sub2, suffix) \
62 options_get_datadir_fname2_suffix(get_options(), (sub1), (sub2), (suffix))
63 /** Return a newly allocated string containing datadir/sub1. See
64 * get_datadir_fname2_suffix. */
65 #define get_datadir_fname(sub1) get_datadir_fname2_suffix((sub1), NULL, NULL)
66 /** Return a newly allocated string containing datadir/sub1/sub2. See
67 * get_datadir_fname2_suffix. */
68 #define get_datadir_fname2(sub1,sub2) \
69 get_datadir_fname2_suffix((sub1), (sub2), NULL)
70 /** Return a newly allocated string containing datadir/sub1/sub2 relative to
71 * opts. See get_datadir_fname2_suffix. */
72 #define options_get_datadir_fname2(opts,sub1,sub2) \
73 options_get_datadir_fname2_suffix((opts),(sub1), (sub2), NULL)
74 /** Return a newly allocated string containing datadir/sub1suffix. See
75 * get_datadir_fname2_suffix. */
76 #define get_datadir_fname_suffix(sub1, suffix) \
77 get_datadir_fname2_suffix((sub1), NULL, (suffix))
79 int using_default_dir_authorities(const or_options_t *options);
81 int check_or_create_data_subdir(const char *subdir);
82 int write_to_data_subdir(const char* subdir, const char* fname,
83 const char* str, const char* descr);
85 int get_num_cpus(const or_options_t *options);
87 MOCK_DECL(const smartlist_t *,get_configured_ports,(void));
88 int get_first_advertised_port_by_type_af(int listener_type,
89 int address_family);
90 #define get_primary_or_port() \
91 (get_first_advertised_port_by_type_af(CONN_TYPE_OR_LISTENER, AF_INET))
92 #define get_primary_dir_port() \
93 (get_first_advertised_port_by_type_af(CONN_TYPE_DIR_LISTENER, AF_INET))
94 const tor_addr_t *get_first_advertised_addr_by_type_af(int listener_type,
95 int address_family);
96 int port_exists_by_type_addr_port(int listener_type, const tor_addr_t *addr,
97 int port, int check_wildcard);
98 int port_exists_by_type_addr32h_port(int listener_type, uint32_t addr_ipv4h,
99 int port, int check_wildcard);
101 char *get_first_listener_addrport_string(int listener_type);
103 int options_need_geoip_info(const or_options_t *options,
104 const char **reason_out);
106 smartlist_t *get_list_of_ports_to_forward(void);
108 int getinfo_helper_config(control_connection_t *conn,
109 const char *question, char **answer,
110 const char **errmsg);
112 uint32_t get_effective_bwrate(const or_options_t *options);
113 uint32_t get_effective_bwburst(const or_options_t *options);
115 char *get_transport_bindaddr_from_config(const char *transport);
117 int init_cookie_authentication(const char *fname, const char *header,
118 int cookie_len, int group_readable,
119 uint8_t **cookie_out, int *cookie_is_set_out);
121 or_options_t *options_new(void);
123 int config_parse_commandline(int argc, char **argv, int ignore_errors,
124 config_line_t **result,
125 config_line_t **cmdline_result);
127 void config_register_addressmaps(const or_options_t *options);
128 /* XXXX move to connection_edge.h */
129 int addressmap_register_auto(const char *from, const char *to,
130 time_t expires,
131 addressmap_entry_source_t addrmap_source,
132 const char **msg);
134 int port_cfg_line_extract_addrport(const char *line,
135 char **addrport_out,
136 int *is_unix_out,
137 const char **rest_out);
139 /** Represents the information stored in a torrc Bridge line. */
140 typedef struct bridge_line_t {
141 tor_addr_t addr; /* The IP address of the bridge. */
142 uint16_t port; /* The TCP port of the bridge. */
143 char *transport_name; /* The name of the pluggable transport that
144 should be used to connect to the bridge. */
145 char digest[DIGEST_LEN]; /* The bridge's identity key digest. */
146 smartlist_t *socks_args; /* SOCKS arguments for the pluggable
147 transport proxy. */
148 } bridge_line_t;
150 void bridge_line_free(bridge_line_t *bridge_line);
151 bridge_line_t *parse_bridge_line(const char *line);
152 smartlist_t *get_options_from_transport_options_line(const char *line,
153 const char *transport);
154 smartlist_t *get_options_for_server_transport(const char *transport);
156 #ifdef CONFIG_PRIVATE
158 #define CL_PORT_NO_STREAM_OPTIONS (1u<<0)
159 #define CL_PORT_WARN_NONLOCAL (1u<<1)
160 #define CL_PORT_ALLOW_EXTRA_LISTENADDR (1u<<2)
161 #define CL_PORT_SERVER_OPTIONS (1u<<3)
162 #define CL_PORT_FORBID_NONLOCAL (1u<<4)
163 #define CL_PORT_TAKES_HOSTNAMES (1u<<5)
164 #define CL_PORT_IS_UNIXSOCKET (1u<<6)
165 #define CL_PORT_DFLT_GROUP_WRITABLE (1u<<7)
167 STATIC int options_act(const or_options_t *old_options);
168 #ifdef TOR_UNIT_TESTS
169 extern struct config_format_t options_format;
170 #endif
172 STATIC port_cfg_t *port_cfg_new(size_t namelen);
173 STATIC void port_cfg_free(port_cfg_t *port);
174 STATIC void or_options_free(or_options_t *options);
175 STATIC int options_validate_single_onion(or_options_t *options,
176 char **msg);
177 STATIC int options_validate(or_options_t *old_options,
178 or_options_t *options,
179 or_options_t *default_options,
180 int from_setconf, char **msg);
181 STATIC int parse_transport_line(const or_options_t *options,
182 const char *line, int validate_only,
183 int server);
184 STATIC int consider_adding_dir_servers(const or_options_t *options,
185 const or_options_t *old_options);
186 STATIC void add_default_trusted_dir_authorities(dirinfo_type_t type);
187 MOCK_DECL(STATIC void, add_default_fallback_dir_servers, (void));
188 STATIC int parse_dir_authority_line(const char *line,
189 dirinfo_type_t required_type,
190 int validate_only);
191 STATIC int parse_dir_fallback_line(const char *line, int validate_only);
192 STATIC int have_enough_mem_for_dircache(const or_options_t *options,
193 size_t total_mem, char **msg);
194 STATIC int parse_port_config(smartlist_t *out,
195 const config_line_t *ports,
196 const config_line_t *listenaddrs,
197 const char *portname,
198 int listener_type,
199 const char *defaultaddr,
200 int defaultport,
201 const unsigned flags);
202 #endif
204 #endif