2011-07-13 19:00:28 +02:00
|
|
|
/* Copyright (c) 2003-2004, Roger Dingledine
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2020-01-09 00:39:17 +01:00
|
|
|
* Copyright (c) 2007-2020, The Tor Project, Inc. */
|
2011-07-13 19:00:28 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
2011-07-18 02:33:31 +02:00
|
|
|
* \file transports.h
|
|
|
|
* \brief Headers for transports.c
|
2011-07-13 19:00:28 +02:00
|
|
|
**/
|
|
|
|
|
2011-07-18 02:33:31 +02:00
|
|
|
#ifndef TOR_TRANSPORTS_H
|
|
|
|
#define TOR_TRANSPORTS_H
|
2011-07-13 19:00:28 +02:00
|
|
|
|
2018-11-23 05:56:41 +01:00
|
|
|
#include "lib/process/process.h"
|
|
|
|
|
2012-01-25 17:51:38 +01:00
|
|
|
/** Represents a pluggable transport used by a bridge. */
|
2012-07-12 15:28:43 +02:00
|
|
|
typedef struct transport_t {
|
2012-01-25 17:51:38 +01:00
|
|
|
/** SOCKS version: One of PROXY_SOCKS4, PROXY_SOCKS5. */
|
|
|
|
int socks_version;
|
|
|
|
/** Name of pluggable transport protocol */
|
|
|
|
char *name;
|
2012-07-12 15:28:43 +02:00
|
|
|
/** The IP address where the transport bound and is waiting for
|
|
|
|
* connections. */
|
2012-01-25 17:51:38 +01:00
|
|
|
tor_addr_t addr;
|
|
|
|
/** Port of proxy */
|
|
|
|
uint16_t port;
|
|
|
|
/** Boolean: We are re-parsing our transport list, and we are going to remove
|
|
|
|
* this one if we don't find it in the list of configured transports. */
|
|
|
|
unsigned marked_for_removal : 1;
|
2013-07-01 15:45:21 +02:00
|
|
|
/** Arguments for this transport that must be written to the
|
|
|
|
extra-info descriptor. */
|
|
|
|
char *extra_info_args;
|
2012-01-25 17:51:38 +01:00
|
|
|
} transport_t;
|
|
|
|
|
|
|
|
void mark_transport_list(void);
|
|
|
|
void sweep_transport_list(void);
|
2014-07-26 06:41:03 +02:00
|
|
|
MOCK_DECL(int, transport_add_from_config,
|
|
|
|
(const tor_addr_t *addr, uint16_t port,
|
|
|
|
const char *name, int socks_ver));
|
2017-11-21 15:37:47 +01:00
|
|
|
void transport_free_(transport_t *transport);
|
2017-12-07 16:44:04 +01:00
|
|
|
#define transport_free(tr) FREE_AND_NULL(transport_t, transport_free_, (tr))
|
2012-01-25 17:51:38 +01:00
|
|
|
|
2018-03-05 21:43:26 +01:00
|
|
|
MOCK_DECL(transport_t*, transport_get_by_name, (const char *name));
|
2012-01-25 17:51:38 +01:00
|
|
|
|
2014-07-26 06:41:03 +02:00
|
|
|
MOCK_DECL(void, pt_kickstart_proxy,
|
|
|
|
(const smartlist_t *transport_list, char **proxy_argv,
|
|
|
|
int is_server));
|
2011-07-13 19:00:28 +02:00
|
|
|
|
2011-10-07 14:13:41 +02:00
|
|
|
#define pt_kickstart_client_proxy(tl, pa) \
|
|
|
|
pt_kickstart_proxy(tl, pa, 0)
|
|
|
|
#define pt_kickstart_server_proxy(tl, pa) \
|
|
|
|
pt_kickstart_proxy(tl, pa, 1)
|
2011-07-13 19:00:28 +02:00
|
|
|
|
|
|
|
void pt_configure_remaining_proxies(void);
|
|
|
|
|
|
|
|
int pt_proxies_configuration_pending(void);
|
|
|
|
|
2012-02-24 02:51:48 +01:00
|
|
|
char *pt_get_extra_info_descriptor_string(void);
|
|
|
|
|
2011-07-13 19:00:28 +02:00
|
|
|
void pt_free_all(void);
|
|
|
|
|
2011-09-11 20:29:12 +02:00
|
|
|
void pt_prepare_proxy_list_for_config_read(void);
|
|
|
|
void sweep_proxy_list(void);
|
|
|
|
|
2012-06-07 18:20:36 +02:00
|
|
|
smartlist_t *get_transport_proxy_ports(void);
|
2012-12-17 13:39:24 +01:00
|
|
|
char *pt_stringify_socks_args(const smartlist_t *socks_args);
|
2012-06-07 18:20:36 +02:00
|
|
|
|
2012-12-17 14:01:31 +01:00
|
|
|
char *pt_get_socks_args_for_proxy_addrport(const tor_addr_t *addr,
|
|
|
|
uint16_t port);
|
|
|
|
|
2018-06-28 17:49:27 +02:00
|
|
|
char *tor_escape_str_for_pt_args(const char *string,
|
|
|
|
const char *chars_to_escape);
|
|
|
|
|
2011-07-13 19:00:28 +02:00
|
|
|
#ifdef PT_PRIVATE
|
|
|
|
/** State of the managed proxy configuration protocol. */
|
|
|
|
enum pt_proto_state {
|
|
|
|
PT_PROTO_INFANT, /* was just born */
|
2011-08-12 21:33:05 +02:00
|
|
|
PT_PROTO_LAUNCHED, /* was just launched */
|
2011-07-13 19:00:28 +02:00
|
|
|
PT_PROTO_ACCEPTING_METHODS, /* accepting methods */
|
|
|
|
PT_PROTO_CONFIGURED, /* configured successfully */
|
|
|
|
PT_PROTO_COMPLETED, /* configure and registered its transports */
|
2011-10-24 15:59:11 +02:00
|
|
|
PT_PROTO_BROKEN, /* broke during the protocol */
|
|
|
|
PT_PROTO_FAILED_LAUNCH /* failed while launching */
|
2011-07-13 19:00:28 +02:00
|
|
|
};
|
|
|
|
|
2018-11-23 05:56:41 +01:00
|
|
|
struct process_t;
|
2018-06-28 16:53:34 +02:00
|
|
|
|
2011-07-13 19:00:28 +02:00
|
|
|
/** Structure containing information of a managed proxy. */
|
|
|
|
typedef struct {
|
|
|
|
enum pt_proto_state conf_state; /* the current configuration state */
|
2011-08-12 21:33:05 +02:00
|
|
|
char **argv; /* the cli arguments of this proxy */
|
2011-07-13 19:00:28 +02:00
|
|
|
int conf_protocol; /* the configuration protocol version used */
|
|
|
|
|
2014-03-25 08:21:22 +01:00
|
|
|
char *proxy_uri; /* the outgoing proxy in TOR_PT_PROXY URI format */
|
2014-09-09 20:21:19 +02:00
|
|
|
unsigned int proxy_supported : 1; /* the proxy honors TOR_PT_PROXY */
|
2014-03-25 08:21:22 +01:00
|
|
|
|
2011-08-07 18:05:40 +02:00
|
|
|
int is_server; /* is it a server proxy? */
|
|
|
|
|
2018-11-23 05:56:41 +01:00
|
|
|
/* A pointer to the process of this managed proxy. */
|
|
|
|
struct process_t *process;
|
2011-07-13 19:00:28 +02:00
|
|
|
|
2011-09-11 20:29:12 +02:00
|
|
|
/** Boolean: We are re-parsing our config, and we are going to
|
|
|
|
* remove this managed proxy if we don't find it any transport
|
|
|
|
* plugins that use it. */
|
|
|
|
unsigned int marked_for_removal : 1;
|
|
|
|
|
|
|
|
/** Boolean: We got a SIGHUP while this proxy was running. We use
|
|
|
|
* this flag to signify that this proxy might need to be restarted
|
|
|
|
* so that it can listen for other transports according to the new
|
|
|
|
* torrc. */
|
2014-04-08 18:22:36 +02:00
|
|
|
unsigned int was_around_before_config_read : 1;
|
2011-09-11 20:29:12 +02:00
|
|
|
|
2011-09-11 23:34:36 +02:00
|
|
|
/* transports to-be-launched by this proxy */
|
|
|
|
smartlist_t *transports_to_launch;
|
2011-09-11 20:29:12 +02:00
|
|
|
|
|
|
|
/* The 'transports' list contains all the transports this proxy has
|
2012-01-25 23:29:15 +01:00
|
|
|
launched. */
|
2011-09-11 20:29:12 +02:00
|
|
|
smartlist_t *transports;
|
2011-07-13 19:00:28 +02:00
|
|
|
} managed_proxy_t;
|
|
|
|
|
2018-03-05 21:43:26 +01:00
|
|
|
STATIC transport_t *transport_new(const tor_addr_t *addr, uint16_t port,
|
|
|
|
const char *name, int socks_ver,
|
|
|
|
const char *extra_info_args);
|
2013-06-06 23:58:28 +02:00
|
|
|
STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp);
|
|
|
|
STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp);
|
2011-07-13 19:00:28 +02:00
|
|
|
|
2013-06-06 23:58:28 +02:00
|
|
|
STATIC int parse_version(const char *line, managed_proxy_t *mp);
|
|
|
|
STATIC void parse_env_error(const char *line);
|
2014-03-25 08:21:22 +01:00
|
|
|
STATIC void parse_proxy_error(const char *line);
|
2013-06-06 23:58:28 +02:00
|
|
|
STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
|
2018-11-29 16:42:56 +01:00
|
|
|
STATIC void parse_log_line(const char *line, managed_proxy_t *mp);
|
2018-12-20 03:55:02 +01:00
|
|
|
STATIC void parse_status_line(const char *line, managed_proxy_t *mp);
|
2013-07-15 23:32:08 +02:00
|
|
|
STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
|
|
|
|
|
|
|
|
STATIC void managed_proxy_destroy(managed_proxy_t *mp,
|
|
|
|
int also_terminate_process);
|
2011-07-13 19:00:28 +02:00
|
|
|
|
2013-07-16 17:53:36 +02:00
|
|
|
STATIC managed_proxy_t *managed_proxy_create(const smartlist_t *transport_list,
|
|
|
|
char **proxy_argv, int is_server);
|
|
|
|
|
2013-07-29 15:59:59 +02:00
|
|
|
STATIC int configure_proxy(managed_proxy_t *mp);
|
|
|
|
|
2014-03-25 08:21:22 +01:00
|
|
|
STATIC char* get_pt_proxy_uri(void);
|
|
|
|
|
2014-12-22 18:27:26 +01:00
|
|
|
STATIC void free_execve_args(char **arg);
|
|
|
|
|
2018-12-07 02:09:22 +01:00
|
|
|
STATIC void managed_proxy_stdout_callback(process_t *, const char *, size_t);
|
|
|
|
STATIC void managed_proxy_stderr_callback(process_t *, const char *, size_t);
|
2018-11-28 21:55:04 +01:00
|
|
|
STATIC bool managed_proxy_exit_callback(process_t *, process_exit_code_t);
|
2018-11-23 05:56:41 +01:00
|
|
|
|
2018-12-20 02:10:42 +01:00
|
|
|
STATIC int managed_proxy_severity_parse(const char *);
|
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(PT_PRIVATE) */
|
2011-07-13 19:00:28 +02:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_TRANSPORTS_H) */
|