Tor  0.4.6.0-alpha-dev
transports.h
Go to the documentation of this file.
1 /* Copyright (c) 2003-2004, Roger Dingledine
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2020, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
6 /**
7  * \file transports.h
8  * \brief Headers for transports.c
9  **/
10 
11 #ifndef TOR_TRANSPORTS_H
12 #define TOR_TRANSPORTS_H
13 
14 #include "lib/process/process.h"
15 
16 /** Represents a pluggable transport used by a bridge. */
17 typedef struct transport_t {
18  /** SOCKS version: One of PROXY_SOCKS4, PROXY_SOCKS5. */
20  /** Name of pluggable transport protocol */
21  char *name;
22  /** The IP address where the transport bound and is waiting for
23  * connections. */
25  /** Port of proxy */
26  uint16_t port;
27  /** Boolean: We are re-parsing our transport list, and we are going to remove
28  * this one if we don't find it in the list of configured transports. */
29  unsigned marked_for_removal : 1;
30  /** Arguments for this transport that must be written to the
31  extra-info descriptor. */
33 } transport_t;
34 
35 void mark_transport_list(void);
36 void sweep_transport_list(void);
38  (const tor_addr_t *addr, uint16_t port,
39  const char *name, int socks_ver));
40 void transport_free_(transport_t *transport);
41 #define transport_free(tr) FREE_AND_NULL(transport_t, transport_free_, (tr))
42 
44 
46  (const smartlist_t *transport_list, char **proxy_argv,
47  int is_server));
48 
49 #define pt_kickstart_client_proxy(tl, pa) \
50  pt_kickstart_proxy(tl, pa, 0)
51 #define pt_kickstart_server_proxy(tl, pa) \
52  pt_kickstart_proxy(tl, pa, 1)
53 
55 
57 
59 
60 void pt_free_all(void);
61 
63 void sweep_proxy_list(void);
64 
66 char *pt_stringify_socks_args(const smartlist_t *socks_args);
67 
69  uint16_t port);
70 
71 char *tor_escape_str_for_pt_args(const char *string,
72  const char *chars_to_escape);
73 
74 #ifdef PT_PRIVATE
75 /** State of the managed proxy configuration protocol. */
76 enum pt_proto_state {
77  PT_PROTO_INFANT, /* was just born */
78  PT_PROTO_LAUNCHED, /* was just launched */
79  PT_PROTO_ACCEPTING_METHODS, /* accepting methods */
80  PT_PROTO_CONFIGURED, /* configured successfully */
81  PT_PROTO_COMPLETED, /* configure and registered its transports */
82  PT_PROTO_BROKEN, /* broke during the protocol */
83  PT_PROTO_FAILED_LAUNCH /* failed while launching */
84 };
85 
86 struct process_t;
87 
88 /** Structure containing information of a managed proxy. */
89 typedef struct {
90  enum pt_proto_state conf_state; /* the current configuration state */
91  char **argv; /* the cli arguments of this proxy */
92  int conf_protocol; /* the configuration protocol version used */
93 
94  char *proxy_uri; /* the outgoing proxy in TOR_PT_PROXY URI format */
95  unsigned int proxy_supported : 1; /* the proxy honors TOR_PT_PROXY */
96 
97  int is_server; /* is it a server proxy? */
98 
99  /* A pointer to the process of this managed proxy. */
100  struct process_t *process;
101 
102  /** Boolean: We are re-parsing our config, and we are going to
103  * remove this managed proxy if we don't find it any transport
104  * plugins that use it. */
105  unsigned int marked_for_removal : 1;
106 
107  /** Boolean: We got a SIGHUP while this proxy was running. We use
108  * this flag to signify that this proxy might need to be restarted
109  * so that it can listen for other transports according to the new
110  * torrc. */
111  unsigned int was_around_before_config_read : 1;
112 
113  /* transports to-be-launched by this proxy */
114  smartlist_t *transports_to_launch;
115 
116  /* The 'transports' list contains all the transports this proxy has
117  launched. */
118  smartlist_t *transports;
119 } managed_proxy_t;
120 
121 STATIC transport_t *transport_new(const tor_addr_t *addr, uint16_t port,
122  const char *name, int socks_ver,
123  const char *extra_info_args);
124 STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp);
125 STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp);
126 
127 STATIC int parse_version(const char *line, managed_proxy_t *mp);
128 STATIC void parse_env_error(const char *line);
129 STATIC void parse_proxy_error(const char *line);
130 STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
131 STATIC void parse_log_line(const char *line, managed_proxy_t *mp);
132 STATIC void parse_status_line(const char *line, managed_proxy_t *mp);
133 STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
134 
135 STATIC void managed_proxy_destroy(managed_proxy_t *mp,
136  int also_terminate_process);
137 
138 STATIC managed_proxy_t *managed_proxy_create(const smartlist_t *transport_list,
139  char **proxy_argv, int is_server);
140 
141 STATIC int configure_proxy(managed_proxy_t *mp);
142 
143 STATIC char* get_pt_proxy_uri(void);
144 
145 STATIC void free_execve_args(char **arg);
146 
147 STATIC void managed_proxy_stdout_callback(process_t *, const char *, size_t);
148 STATIC void managed_proxy_stderr_callback(process_t *, const char *, size_t);
149 STATIC bool managed_proxy_exit_callback(process_t *, process_exit_code_t);
150 
151 STATIC int managed_proxy_severity_parse(const char *);
153  sa_family_t);
154 
155 #endif /* defined(PT_PRIVATE) */
156 
157 #endif /* !defined(TOR_TRANSPORTS_H) */
transport_t::name
char * name
Definition: transports.h:21
name
const char * name
Definition: config.c:2463
transport_t::extra_info_args
char * extra_info_args
Definition: transports.h:32
transport_t
Definition: transports.h:17
tor_addr_t
Definition: address.h:69
transport_t::port
uint16_t port
Definition: transports.h:26
managed_proxy_severity_parse
STATIC int managed_proxy_severity_parse(const char *severity)
Definition: transports.c:1931
parse_proxy_error
STATIC void parse_proxy_error(const char *line)
Definition: transports.c:1143
get_transport_options_for_server_proxy
STATIC char * get_transport_options_for_server_proxy(const managed_proxy_t *mp)
Definition: transports.c:1275
transport_t::socks_version
int socks_version
Definition: transports.h:19
pt_get_extra_info_descriptor_string
char * pt_get_extra_info_descriptor_string(void)
Definition: transports.c:1658
pt_prepare_proxy_list_for_config_read
void pt_prepare_proxy_list_for_config_read(void)
Definition: transports.c:1595
parse_version
STATIC int parse_version(const char *line, managed_proxy_t *mp)
Definition: transports.c:964
transport_get_by_name
transport_t * transport_get_by_name(const char *name)
Definition: transports.c:236
mark_transport_list
void mark_transport_list(void)
Definition: transports.c:180
handle_proxy_line
STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:836
transport_t::addr
tor_addr_t addr
Definition: transports.h:24
pt_kickstart_proxy
void pt_kickstart_proxy(const smartlist_t *transport_list, char **proxy_argv, int is_server)
Definition: transports.c:1535
process.h
Header for process.c.
managed_proxy_stderr_callback
STATIC void managed_proxy_stderr_callback(process_t *process, const char *line, size_t size)
Definition: transports.c:1890
process_t
Definition: process.c:36
transport_add_from_config
int transport_add_from_config(const tor_addr_t *addr, uint16_t port, const char *name, int socks_ver)
Definition: transports.c:339
transport_t::marked_for_removal
unsigned marked_for_removal
Definition: transports.h:29
transport_new
STATIC transport_t * transport_new(const tor_addr_t *addr, uint16_t port, const char *name, int socks_ver, const char *extra_info_args)
Definition: transports.c:149
configure_proxy
STATIC int configure_proxy(managed_proxy_t *mp)
Definition: transports.c:624
parse_log_line
STATIC void parse_log_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1158
pt_get_socks_args_for_proxy_addrport
char * pt_get_socks_args_for_proxy_addrport(const tor_addr_t *addr, uint16_t port)
Definition: transports.c:1770
pt_proxies_configuration_pending
int pt_proxies_configuration_pending(void)
Definition: transports.c:374
pt_stringify_socks_args
char * pt_stringify_socks_args(const smartlist_t *socks_args)
Definition: transports.c:1734
MOCK_DECL
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
sweep_transport_list
void sweep_transport_list(void)
Definition: transports.c:191
tor_escape_str_for_pt_args
char * tor_escape_str_for_pt_args(const char *string, const char *chars_to_escape)
Definition: transports.c:1828
free_execve_args
STATIC void free_execve_args(char **arg)
Definition: transports.c:1580
get_pt_proxy_uri
STATIC char * get_pt_proxy_uri(void)
Definition: transports.c:734
transport_free_
void transport_free_(transport_t *transport)
Definition: transports.c:167
parse_cmethod_line
STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1134
managed_proxy_create
STATIC managed_proxy_t * managed_proxy_create(const smartlist_t *with_transport_list, char **proxy_argv, int is_server)
Definition: transports.c:1498
managed_proxy_stdout_callback
STATIC void managed_proxy_stdout_callback(process_t *process, const char *line, size_t size)
Definition: transports.c:1866
pt_configure_remaining_proxies
void pt_configure_remaining_proxies(void)
Definition: transports.c:567
get_transport_proxy_ports
smartlist_t * get_transport_proxy_ports(void)
Definition: transports.c:1628
managed_proxy_destroy
STATIC void managed_proxy_destroy(managed_proxy_t *mp, int also_terminate_process)
Definition: transports.c:696
transport_list
static smartlist_t * transport_list
Definition: transports.c:143
managed_proxy_outbound_address
STATIC const tor_addr_t * managed_proxy_outbound_address(const or_options_t *options, sa_family_t family)
Definition: transports.c:1958
pt_free_all
void pt_free_all(void)
Definition: transports.c:1802
sa_family_t
uint16_t sa_family_t
Definition: inaddr_st.h:77
or_options_t
Definition: or_options_st.h:64
parse_smethod_line
STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1124
parse_env_error
STATIC void parse_env_error(const char *line)
Definition: transports.c:948
STATIC
#define STATIC
Definition: testsupport.h:32
smartlist_t
Definition: smartlist_core.h:26
sweep_proxy_list
void sweep_proxy_list(void)
Definition: transports.c:1786
managed_proxy_exit_callback
STATIC bool managed_proxy_exit_callback(process_t *process, process_exit_code_t exit_code)
Definition: transports.c:1914
parse_status_line
STATIC void parse_status_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1224