tor  master
connection_edge.h
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_CONNECTION_EDGE_H
13 #define TOR_CONNECTION_EDGE_H
14 
15 #include "testsupport.h"
16 
17 #define connection_mark_unattached_ap(conn, endreason) \
18  connection_mark_unattached_ap_((conn), (endreason), __LINE__, SHORT_FILE__)
19 
20 MOCK_DECL(void,connection_mark_unattached_ap_,
21  (entry_connection_t *conn, int endreason,
22  int line, const char *file));
25  int package_partial);
27 int connection_edge_end(edge_connection_t *conn, uint8_t reason);
32 
35 
36 MOCK_DECL(int,
37  connection_ap_handshake_send_begin,(entry_connection_t *ap_conn));
39 
41  char *address, uint16_t port,
42  const char *digest,
43  int session_group,
44  int isolation_flags,
45  int use_begindir, int want_onehop);
47  size_t replylen,
48  int endreason);
49 MOCK_DECL(void,connection_ap_handshake_socks_resolved,
50  (entry_connection_t *conn,
51  int answer_type,
52  size_t answer_len,
53  const uint8_t *answer,
54  int ttl,
55  time_t expires));
57  const tor_addr_t *answer,
58  int ttl,
59  time_t expires);
60 
66  const node_t *exit);
69 void connection_ap_attach_pending(int retry);
71  const char *file, int line);
72 #define connection_ap_mark_as_pending_circuit(c) \
73  connection_ap_mark_as_pending_circuit_((c), __FILE__, __LINE__)
75 #define CONNECTION_AP_EXPECT_NONPENDING(c) do { \
76  if (ENTRY_TO_CONN(c)->state == AP_CONN_STATE_CIRCUIT_WAIT) { \
77  log_warn(LD_BUG, "At %s:%d: %p was unexpectedly in circuit_wait.", \
78  __FILE__, __LINE__, (c)); \
79  connection_ap_mark_as_non_pending_circuit(c); \
80  } \
81  } while (0)
82 void connection_ap_fail_onehop(const char *failed_digest,
83  cpath_build_state_t *build_state);
86  origin_circuit_t *circ,
87  int reason);
89 
90 int address_is_invalid_destination(const char *address, int client);
91 
92 MOCK_DECL(int, connection_ap_rewrite_and_attach_if_allowed,
93  (entry_connection_t *conn,
94  origin_circuit_t *circ,
95  crypt_path_t *cpath));
97  origin_circuit_t *circ,
98  crypt_path_t *cpath);
99 
101 typedef enum hostname_type_t {
102  NORMAL_HOSTNAME, ONION_V2_HOSTNAME, ONION_V3_HOSTNAME,
103  EXIT_HOSTNAME, BAD_HOSTNAME
105 hostname_type_t parse_extended_hostname(char *address);
106 
107 #if defined(HAVE_NET_IF_H) && defined(HAVE_NET_PFVAR_H)
108 int get_pf_socket(void);
109 #endif
110 
112  const origin_circuit_t *circ);
114  origin_circuit_t *circ,
115  int dry_run);
118 
119 void connection_edge_free_all(void);
120 
121 void connection_ap_warn_and_unmark_if_pending_circ(
122  entry_connection_t *entry_conn,
123  const char *where);
124 
134 #define BEGIN_FLAG_IPV6_OK (1u<<0)
135 
139 #define BEGIN_FLAG_IPV4_NOT_OK (1u<<1)
140 
142 #define BEGIN_FLAG_IPV6_PREFERRED (1u<<2)
143 
145 #ifdef CONNECTION_EDGE_PRIVATE
146 
148 typedef struct begin_cell_t {
151  char *address;
154  uint32_t flags;
156  uint16_t port;
158  uint16_t stream_id;
160  unsigned is_begindir : 1;
161 } begin_cell_t;
162 
163 STATIC int begin_cell_parse(const cell_t *cell, begin_cell_t *bcell,
164  uint8_t *end_reason_out);
165 STATIC int connected_cell_format_payload(uint8_t *payload_out,
166  const tor_addr_t *addr,
167  uint32_t ttl);
168 
169 typedef struct {
173  char orig_address[MAX_SOCKS_ADDR_LEN];
177  int automap;
179  addressmap_entry_source_t exit_source;
181  time_t map_expires;
184  int end_reason;
187  int should_close;
188 } rewrite_result_t;
189 
190 STATIC void connection_ap_handshake_rewrite(entry_connection_t *conn,
191  rewrite_result_t *out);
192 
194 #endif /* defined(CONNECTION_EDGE_PRIVATE) */
195 
196 #endif /* !defined(TOR_CONNECTION_EDGE_H) */
197 
int connection_edge_destroy(circid_t circ_id, edge_connection_t *conn)
Definition: connection_edge.c:300
void connection_ap_handshake_socks_resolved_addr(entry_connection_t *conn, const tor_addr_t *answer, int ttl, time_t expires)
Definition: connection_edge.c:2990
void connection_ap_fail_onehop(const char *failed_digest, cpath_build_state_t *build_state)
Definition: connection_edge.c:1053
void connection_ap_mark_as_pending_circuit_(entry_connection_t *entry_conn, const char *file, int line)
Definition: connection_edge.c:982
Definition: or.h:3476
Definition: or.h:2504
int connection_edge_reached_eof(edge_connection_t *conn)
Definition: connection_edge.c:197
Definition: or.h:2928
Definition: or.h:1177
Definition: address.h:56
hostname_type_t parse_extended_hostname(char *address)
Definition: connection_edge.c:3934
void circuit_clear_isolation(origin_circuit_t *circ)
Definition: connection_edge.c:4148
int connection_edge_end(edge_connection_t *conn, uint8_t reason)
Definition: connection_edge.c:386
void connection_edge_free_all(void)
Definition: connection_edge.c:4183
int connection_edge_end_errno(edge_connection_t *conn)
Definition: connection_edge.c:454
int connection_edge_process_inbuf(edge_connection_t *conn, int package_partial)
Definition: connection_edge.c:231
MOCK_DECL(int, router_have_minimum_dir_info,(void))
addressmap_entry_source_t
Definition: or.h:4974
void connection_exit_about_to_close(edge_connection_t *edge_conn)
Definition: connection_edge.c:688
void connection_ap_expire_beginning(void)
Definition: connection_edge.c:729
void connection_ap_rescan_and_attach_pending(void)
Definition: connection_edge.c:853
STATIC int begin_cell_parse(const cell_t *cell, begin_cell_t *bcell, uint8_t *end_reason_out)
Definition: connection_edge.c:3246
streamid_t get_unique_stream_id_by_circ(origin_circuit_t *circ)
Definition: connection_edge.c:2578
int connection_edge_flushed_some(edge_connection_t *conn)
Definition: connection_edge.c:468
int connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn, origin_circuit_t *circ, crypt_path_t *cpath)
Definition: connection_edge.c:1636
entry_connection_t * connection_ap_make_link(connection_t *partner, char *address, uint16_t port, const char *digest, int session_group, int isolation_flags, int use_begindir, int want_onehop)
Definition: connection_edge.c:2893
int address_is_invalid_destination(const char *address, int client)
Definition: addressmap.c:1075
Definition: or.h:1326
int connection_ap_handshake_send_resolve(entry_connection_t *ap_conn)
Definition: connection_edge.c:2803
uint16_t streamid_t
Definition: or.h:1032
int connection_edge_finished_connecting(edge_connection_t *conn)
Definition: connection_edge.c:562
void connection_ap_handshake_socks_reply(entry_connection_t *conn, char *reply, size_t replylen, int endreason)
Definition: connection_edge.c:3141
int connection_edge_update_circuit_isolation(const entry_connection_t *conn, origin_circuit_t *circ, int dry_run)
Definition: connection_edge.c:4070
void connection_exit_connect(edge_connection_t *conn)
Definition: connection_edge.c:3664
int connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
Definition: connection_edge.c:3402
int connection_ap_detach_retriable(entry_connection_t *conn, origin_circuit_t *circ, int reason)
Definition: connection_edge.c:1145
hostname_type_t
Definition: connection_edge.h:101
int connection_edge_compatible_with_circuit(const entry_connection_t *conn, const origin_circuit_t *circ)
Definition: connection_edge.c:4000
Definition: or.h:3059
void circuit_discard_optional_exit_enclaves(extend_info_t *info)
Definition: connection_edge.c:1094
Definition: or.h:1749
uint32_t circid_t
Definition: or.h:1030
int connection_ap_process_transparent(entry_connection_t *conn)
Definition: connection_edge.c:2367
STATIC int connected_cell_format_payload(uint8_t *payload_out, const tor_addr_t *addr, uint32_t ttl)
Definition: connection_edge.c:528
Definition: or.h:2986
int connection_edge_is_rendezvous_stream(const edge_connection_t *conn)
Definition: connection_edge.c:3836
int connection_ap_can_use_exit(const entry_connection_t *conn, const node_t *exit)
Definition: connection_edge.c:3854
void connection_ap_mark_as_non_pending_circuit(entry_connection_t *entry_conn)
Definition: connection_edge.c:1026
Definition: or.h:2838
Definition: or.h:1687
int connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ)
Definition: connection_edge.c:3594
Definition: or.h:3256
void connection_ap_attach_pending(int retry)
Definition: connection_edge.c:900
int connection_edge_finished_flushing(edge_connection_t *conn)
Definition: connection_edge.c:490
void connection_ap_about_to_close(entry_connection_t *edge_conn)
Definition: connection_edge.c:637
STATIC int connection_ap_process_http_connect(entry_connection_t *conn)
Definition: connection_edge.c:2479