tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

transports.h (6537B)


      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. */
     19  int socks_version;
     20  /** Name of pluggable transport protocol */
     21  char *name;
     22  /** The IP address where the transport bound and is waiting for
     23   * connections. */
     24  tor_addr_t addr;
     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. */
     32  char *extra_info_args;
     33 } transport_t;
     34 
     35 void mark_transport_list(void);
     36 void sweep_transport_list(void);
     37 MOCK_DECL(int, transport_add_from_config,
     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 
     43 MOCK_DECL(transport_t*, transport_get_by_name, (const char *name));
     44 bool managed_proxy_has_transport(const char *transport_name);
     45 
     46 MOCK_DECL(void, pt_kickstart_proxy,
     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 
     55 void pt_configure_remaining_proxies(void);
     56 
     57 int pt_proxies_configuration_pending(void);
     58 
     59 char *pt_get_extra_info_descriptor_string(void);
     60 void pt_update_bridge_lines(void);
     61 
     62 void pt_free_all(void);
     63 
     64 void pt_prepare_proxy_list_for_config_read(void);
     65 void sweep_proxy_list(void);
     66 
     67 smartlist_t *get_transport_proxy_ports(void);
     68 char *pt_stringify_socks_args(const smartlist_t *socks_args);
     69 
     70 char *pt_get_socks_args_for_proxy_addrport(const tor_addr_t *addr,
     71                                            uint16_t port);
     72 
     73 char *tor_escape_str_for_pt_args(const char *string,
     74                                 const char *chars_to_escape);
     75 
     76 #ifdef PT_PRIVATE
     77 /** State of the managed proxy configuration protocol. */
     78 enum pt_proto_state {
     79  PT_PROTO_INFANT, /* was just born */
     80  PT_PROTO_WAITING, /* waiting to be launched */
     81  PT_PROTO_LAUNCHED, /* was just launched */
     82  PT_PROTO_ACCEPTING_METHODS, /* accepting methods */
     83  PT_PROTO_CONFIGURED, /* configured successfully */
     84  PT_PROTO_COMPLETED, /* configure and registered its transports */
     85  PT_PROTO_BROKEN, /* broke during the protocol */
     86  PT_PROTO_FAILED_LAUNCH /* failed while launching */
     87 };
     88 
     89 struct process_t;
     90 
     91 /** Structure containing information of a managed proxy. */
     92 typedef struct {
     93  enum pt_proto_state conf_state; /* the current configuration state */
     94  char **argv; /* the cli arguments of this proxy */
     95  int conf_protocol; /* the configuration protocol version used */
     96 
     97  char *proxy_uri;  /* the outgoing proxy in TOR_PT_PROXY URI format */
     98  unsigned int proxy_supported : 1; /* the proxy honors TOR_PT_PROXY */
     99 
    100  int is_server; /* is it a server proxy? */
    101 
    102  /* A pointer to the process of this managed proxy. */
    103  struct process_t *process;
    104 
    105  /* timer event to launch proxy */
    106  struct mainloop_event_t *process_launch_ev;
    107 
    108  /** Boolean: We are re-parsing our config, and we are going to
    109   * remove this managed proxy if we don't find it any transport
    110   * plugins that use it. */
    111  unsigned int marked_for_removal : 1;
    112 
    113  /** Boolean: We got a SIGHUP while this proxy was running. We use
    114   * this flag to signify that this proxy might need to be restarted
    115   * so that it can listen for other transports according to the new
    116   * torrc. */
    117  unsigned int was_around_before_config_read : 1;
    118 
    119  /* transports to-be-launched by this proxy */
    120  smartlist_t *transports_to_launch;
    121 
    122  /** Version as set by STATUS TYPE=version messages. */
    123  char *version;
    124 
    125  /** Implementation as set by the STATUS TYPE=version messages. */
    126  char *implementation;
    127 
    128  /* The 'transports' list contains all the transports this proxy has
    129     launched. */
    130  smartlist_t *transports;
    131 } managed_proxy_t;
    132 
    133 struct config_line_t;
    134 
    135 STATIC transport_t *transport_new(const tor_addr_t *addr, uint16_t port,
    136                                  const char *name, int socks_ver,
    137                                  const char *extra_info_args);
    138 STATIC int parse_cmethod_line(const char *line, managed_proxy_t *mp);
    139 STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp);
    140 
    141 STATIC int parse_version(const char *line, managed_proxy_t *mp);
    142 STATIC void parse_env_error(const char *line);
    143 STATIC void parse_proxy_error(const char *line);
    144 STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
    145 STATIC void parse_log_line(const char *line, managed_proxy_t *mp);
    146 STATIC void parse_status_line(const char *line, managed_proxy_t *mp);
    147 STATIC void handle_status_message(const struct config_line_t *values,
    148                                  managed_proxy_t *mp);
    149 STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
    150 
    151 STATIC void managed_proxy_destroy(managed_proxy_t *mp,
    152                                  int also_terminate_process);
    153 
    154 STATIC managed_proxy_t *managed_proxy_create(const smartlist_t *transport_list,
    155                                             char **proxy_argv, int is_server);
    156 
    157 STATIC void launch_proxy_ev(struct mainloop_event_t *event, void *v);
    158 STATIC int configure_proxy(managed_proxy_t *mp);
    159 
    160 STATIC char* get_pt_proxy_uri(void);
    161 
    162 STATIC void free_execve_args(char **arg);
    163 
    164 STATIC void managed_proxy_stdout_callback(process_t *, const char *, size_t);
    165 STATIC void managed_proxy_stderr_callback(process_t *, const char *, size_t);
    166 STATIC bool managed_proxy_exit_callback(process_t *, process_exit_code_t);
    167 
    168 STATIC int managed_proxy_severity_parse(const char *);
    169 STATIC const tor_addr_t *managed_proxy_outbound_address(const or_options_t *,
    170                                                        sa_family_t);
    171 
    172 STATIC const char *managed_proxy_state_to_string(enum pt_proto_state);
    173 STATIC void managed_proxy_set_state(managed_proxy_t *, enum pt_proto_state);
    174 #endif /* defined(PT_PRIVATE) */
    175 
    176 #endif /* !defined(TOR_TRANSPORTS_H) */