Tor  0.4.3.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-2019, 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 *);
152 
153 #endif /* defined(PT_PRIVATE) */
154 
155 #endif /* !defined(TOR_TRANSPORTS_H) */
void pt_prepare_proxy_list_for_config_read(void)
Definition: transports.c:1558
void pt_free_all(void)
Definition: transports.c:1756
STATIC void free_execve_args(char **arg)
Definition: transports.c:1543
STATIC void managed_proxy_destroy(managed_proxy_t *mp, int also_terminate_process)
Definition: transports.c:695
STATIC void managed_proxy_stdout_callback(process_t *process, const char *line, size_t size)
Definition: transports.c:1820
char * pt_stringify_socks_args(const smartlist_t *socks_args)
Definition: transports.c:1688
STATIC void parse_log_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1154
STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:832
unsigned marked_for_removal
Definition: transports.h:29
const char * name
Definition: config.c:2211
char * name
Definition: transports.h:21
STATIC void parse_proxy_error(const char *line)
Definition: transports.c:1139
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:148
STATIC int parse_version(const char *line, managed_proxy_t *mp)
Definition: transports.c:960
uint16_t port
Definition: transports.h:26
#define STATIC
Definition: testsupport.h:32
STATIC void parse_status_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1220
char * pt_get_extra_info_descriptor_string(void)
Definition: transports.c:1621
void pt_configure_remaining_proxies(void)
Definition: transports.c:566
char * extra_info_args
Definition: transports.h:32
char * tor_escape_str_for_pt_args(const char *string, const char *chars_to_escape)
Definition: transports.c:1782
void mark_transport_list(void)
Definition: transports.c:179
void sweep_transport_list(void)
Definition: transports.c:190
transport_t * transport_get_by_name(const char *name)
Definition: transports.c:235
void sweep_proxy_list(void)
Definition: transports.c:1740
int socks_version
Definition: transports.h:19
STATIC void parse_env_error(const char *line)
Definition: transports.c:944
Header for process.c.
STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1120
tor_addr_t addr
Definition: transports.h:24
STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1130
smartlist_t * get_transport_proxy_ports(void)
Definition: transports.c:1591
int pt_proxies_configuration_pending(void)
Definition: transports.c:373
STATIC int managed_proxy_severity_parse(const char *severity)
Definition: transports.c:1883
STATIC bool managed_proxy_exit_callback(process_t *process, process_exit_code_t exit_code)
Definition: transports.c:1866
static smartlist_t * transport_list
Definition: transports.c:142
STATIC char * get_pt_proxy_uri(void)
Definition: transports.c:733
STATIC void managed_proxy_stderr_callback(process_t *process, const char *line, size_t size)
Definition: transports.c:1844
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
STATIC managed_proxy_t * managed_proxy_create(const smartlist_t *with_transport_list, char **proxy_argv, int is_server)
Definition: transports.c:1461
void transport_free_(transport_t *transport)
Definition: transports.c:166
char * pt_get_socks_args_for_proxy_addrport(const tor_addr_t *addr, uint16_t port)
Definition: transports.c:1724
void pt_kickstart_proxy(const smartlist_t *transport_list, char **proxy_argv, int is_server)
Definition: transports.c:1498
int transport_add_from_config(const tor_addr_t *addr, uint16_t port, const char *name, int socks_ver)
Definition: transports.c:338
STATIC char * get_transport_options_for_server_proxy(const managed_proxy_t *mp)
Definition: transports.c:1271
STATIC int configure_proxy(managed_proxy_t *mp)
Definition: transports.c:623