Tor  0.4.7.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-2021, 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 bool managed_proxy_has_transport(const char *transport_name);
45 
47  (const smartlist_t *transport_list, char **proxy_argv,
48  int is_server));
49 
50 #define pt_kickstart_client_proxy(tl, pa) \
51  pt_kickstart_proxy(tl, pa, 0)
52 #define pt_kickstart_server_proxy(tl, pa) \
53  pt_kickstart_proxy(tl, pa, 1)
54 
56 
58 
60 
61 void pt_free_all(void);
62 
64 void sweep_proxy_list(void);
65 
67 char *pt_stringify_socks_args(const smartlist_t *socks_args);
68 
70  uint16_t port);
71 
72 char *tor_escape_str_for_pt_args(const char *string,
73  const char *chars_to_escape);
74 
75 #ifdef PT_PRIVATE
76 /** State of the managed proxy configuration protocol. */
77 enum pt_proto_state {
78  PT_PROTO_INFANT, /* was just born */
79  PT_PROTO_LAUNCHED, /* was just launched */
80  PT_PROTO_ACCEPTING_METHODS, /* accepting methods */
81  PT_PROTO_CONFIGURED, /* configured successfully */
82  PT_PROTO_COMPLETED, /* configure and registered its transports */
83  PT_PROTO_BROKEN, /* broke during the protocol */
84  PT_PROTO_FAILED_LAUNCH /* failed while launching */
85 };
86 
87 struct process_t;
88 
89 /** Structure containing information of a managed proxy. */
90 typedef struct {
91  enum pt_proto_state conf_state; /* the current configuration state */
92  char **argv; /* the cli arguments of this proxy */
93  int conf_protocol; /* the configuration protocol version used */
94 
95  char *proxy_uri; /* the outgoing proxy in TOR_PT_PROXY URI format */
96  unsigned int proxy_supported : 1; /* the proxy honors TOR_PT_PROXY */
97 
98  int is_server; /* is it a server proxy? */
99 
100  /* A pointer to the process of this managed proxy. */
101  struct process_t *process;
102 
103  /** Boolean: We are re-parsing our config, and we are going to
104  * remove this managed proxy if we don't find it any transport
105  * plugins that use it. */
106  unsigned int marked_for_removal : 1;
107 
108  /** Boolean: We got a SIGHUP while this proxy was running. We use
109  * this flag to signify that this proxy might need to be restarted
110  * so that it can listen for other transports according to the new
111  * torrc. */
112  unsigned int was_around_before_config_read : 1;
113 
114  /* transports to-be-launched by this proxy */
115  smartlist_t *transports_to_launch;
116 
117  /* The 'transports' list contains all the transports this proxy has
118  launched. */
119  smartlist_t *transports;
120 } managed_proxy_t;
121 
122 STATIC transport_t *transport_new(const tor_addr_t *addr, uint16_t port,
123  const char *name, int socks_ver,
124  const char *extra_info_args);
125 STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp);
126 STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp);
127 
128 STATIC int parse_version(const char *line, managed_proxy_t *mp);
129 STATIC void parse_env_error(const char *line);
130 STATIC void parse_proxy_error(const char *line);
131 STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
132 STATIC void parse_log_line(const char *line, managed_proxy_t *mp);
133 STATIC void parse_status_line(const char *line, managed_proxy_t *mp);
134 STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
135 
136 STATIC void managed_proxy_destroy(managed_proxy_t *mp,
137  int also_terminate_process);
138 
139 STATIC managed_proxy_t *managed_proxy_create(const smartlist_t *transport_list,
140  char **proxy_argv, int is_server);
141 
142 STATIC int configure_proxy(managed_proxy_t *mp);
143 
144 STATIC char* get_pt_proxy_uri(void);
145 
146 STATIC void free_execve_args(char **arg);
147 
148 STATIC void managed_proxy_stdout_callback(process_t *, const char *, size_t);
149 STATIC void managed_proxy_stderr_callback(process_t *, const char *, size_t);
150 STATIC bool managed_proxy_exit_callback(process_t *, process_exit_code_t);
151 
152 STATIC int managed_proxy_severity_parse(const char *);
154  sa_family_t);
155 
156 #endif /* defined(PT_PRIVATE) */
157 
158 #endif /* !defined(TOR_TRANSPORTS_H) */
const char * name
Definition: config.c:2434
uint16_t sa_family_t
Definition: inaddr_st.h:77
Header for process.c.
int socks_version
Definition: transports.h:19
char * name
Definition: transports.h:21
uint16_t port
Definition: transports.h:26
unsigned marked_for_removal
Definition: transports.h:29
tor_addr_t addr
Definition: transports.h:24
char * extra_info_args
Definition: transports.h:32
#define STATIC
Definition: testsupport.h:32
#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:1520
STATIC const tor_addr_t * managed_proxy_outbound_address(const or_options_t *options, sa_family_t family)
Definition: transports.c:1980
STATIC void parse_proxy_error(const char *line)
Definition: transports.c:1165
STATIC void managed_proxy_destroy(managed_proxy_t *mp, int also_terminate_process)
Definition: transports.c:718
STATIC void parse_log_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1180
STATIC char * get_pt_proxy_uri(void)
Definition: transports.c:756
STATIC int managed_proxy_severity_parse(const char *severity)
Definition: transports.c:1953
STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1156
STATIC void parse_status_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1246
static smartlist_t * transport_list
Definition: transports.c:143
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
STATIC void managed_proxy_stderr_callback(process_t *process, const char *line, size_t size)
Definition: transports.c:1912
STATIC void managed_proxy_stdout_callback(process_t *process, const char *line, size_t size)
Definition: transports.c:1888
STATIC int parse_version(const char *line, managed_proxy_t *mp)
Definition: transports.c:986
STATIC void parse_env_error(const char *line)
Definition: transports.c:970
STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:1146
STATIC char * get_transport_options_for_server_proxy(const managed_proxy_t *mp)
Definition: transports.c:1297
STATIC int configure_proxy(managed_proxy_t *mp)
Definition: transports.c:646
STATIC void free_execve_args(char **arg)
Definition: transports.c:1602
STATIC bool managed_proxy_exit_callback(process_t *process, process_exit_code_t exit_code)
Definition: transports.c:1936
STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp)
Definition: transports.c:858
char * pt_get_socks_args_for_proxy_addrport(const tor_addr_t *addr, uint16_t port)
Definition: transports.c:1792
int pt_proxies_configuration_pending(void)
Definition: transports.c:396
int transport_add_from_config(const tor_addr_t *addr, uint16_t port, const char *name, int socks_ver)
Definition: transports.c:339
void pt_free_all(void)
Definition: transports.c:1824
bool managed_proxy_has_transport(const char *transport_name)
Definition: transports.c:374
char * pt_stringify_socks_args(const smartlist_t *socks_args)
Definition: transports.c:1756
void pt_configure_remaining_proxies(void)
Definition: transports.c:589
void sweep_proxy_list(void)
Definition: transports.c:1808
smartlist_t * get_transport_proxy_ports(void)
Definition: transports.c:1650
void mark_transport_list(void)
Definition: transports.c:180
char * tor_escape_str_for_pt_args(const char *string, const char *chars_to_escape)
Definition: transports.c:1850
char * pt_get_extra_info_descriptor_string(void)
Definition: transports.c:1680
transport_t * transport_get_by_name(const char *name)
Definition: transports.c:236
void sweep_transport_list(void)
Definition: transports.c:191
void transport_free_(transport_t *transport)
Definition: transports.c:167
void pt_prepare_proxy_list_for_config_read(void)
Definition: transports.c:1617
void pt_kickstart_proxy(const smartlist_t *transport_list, char **proxy_argv, int is_server)
Definition: transports.c:1557