protover: Fix old tor hardcoded version check
[tor.git] / src / or / connection_edge.h
blob5dfc8af901ba0c6fe69884dd5f888369acd108ce
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-2016, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file connection_edge.h
9 * \brief Header file for connection_edge.c.
10 **/
12 #ifndef TOR_CONNECTION_EDGE_H
13 #define TOR_CONNECTION_EDGE_H
15 #include "testsupport.h"
17 #define connection_mark_unattached_ap(conn, endreason) \
18 connection_mark_unattached_ap_((conn), (endreason), __LINE__, SHORT_FILE__)
20 MOCK_DECL(void,connection_mark_unattached_ap_,
21 (entry_connection_t *conn, int endreason,
22 int line, const char *file));
23 int connection_edge_reached_eof(edge_connection_t *conn);
24 int connection_edge_process_inbuf(edge_connection_t *conn,
25 int package_partial);
26 int connection_edge_destroy(circid_t circ_id, edge_connection_t *conn);
27 int connection_edge_end(edge_connection_t *conn, uint8_t reason);
28 int connection_edge_end_errno(edge_connection_t *conn);
29 int connection_edge_flushed_some(edge_connection_t *conn);
30 int connection_edge_finished_flushing(edge_connection_t *conn);
31 int connection_edge_finished_connecting(edge_connection_t *conn);
33 void connection_ap_about_to_close(entry_connection_t *edge_conn);
34 void connection_exit_about_to_close(edge_connection_t *edge_conn);
36 int connection_ap_handshake_send_begin(entry_connection_t *ap_conn);
37 int connection_ap_handshake_send_resolve(entry_connection_t *ap_conn);
39 entry_connection_t *connection_ap_make_link(connection_t *partner,
40 char *address, uint16_t port,
41 const char *digest,
42 int session_group,
43 int isolation_flags,
44 int use_begindir, int want_onehop);
45 void connection_ap_handshake_socks_reply(entry_connection_t *conn, char *reply,
46 size_t replylen,
47 int endreason);
48 MOCK_DECL(void,connection_ap_handshake_socks_resolved,
49 (entry_connection_t *conn,
50 int answer_type,
51 size_t answer_len,
52 const uint8_t *answer,
53 int ttl,
54 time_t expires));
55 void connection_ap_handshake_socks_resolved_addr(entry_connection_t *conn,
56 const tor_addr_t *answer,
57 int ttl,
58 time_t expires);
60 int connection_exit_begin_conn(cell_t *cell, circuit_t *circ);
61 int connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ);
62 void connection_exit_connect(edge_connection_t *conn);
63 int connection_edge_is_rendezvous_stream(edge_connection_t *conn);
64 int connection_ap_can_use_exit(const entry_connection_t *conn,
65 const node_t *exit);
66 void connection_ap_expire_beginning(void);
67 void connection_ap_rescan_and_attach_pending(void);
68 void connection_ap_attach_pending(int retry);
69 void connection_ap_mark_as_pending_circuit_(entry_connection_t *entry_conn,
70 const char *file, int line);
71 #define connection_ap_mark_as_pending_circuit(c) \
72 connection_ap_mark_as_pending_circuit_((c), __FILE__, __LINE__)
73 void connection_ap_mark_as_non_pending_circuit(entry_connection_t *entry_conn);
74 #define CONNECTION_AP_EXPECT_NONPENDING(c) do { \
75 if (ENTRY_TO_CONN(c)->state == AP_CONN_STATE_CIRCUIT_WAIT) { \
76 log_warn(LD_BUG, "At %s:%d: %p was unexpectedly in circuit_wait.", \
77 __FILE__, __LINE__, (c)); \
78 connection_ap_mark_as_non_pending_circuit(c); \
79 } \
80 } while (0)
81 void connection_ap_fail_onehop(const char *failed_digest,
82 cpath_build_state_t *build_state);
83 void circuit_discard_optional_exit_enclaves(extend_info_t *info);
84 int connection_ap_detach_retriable(entry_connection_t *conn,
85 origin_circuit_t *circ,
86 int reason);
87 int connection_ap_process_transparent(entry_connection_t *conn);
89 int address_is_invalid_destination(const char *address, int client);
91 int connection_ap_rewrite_and_attach_if_allowed(entry_connection_t *conn,
92 origin_circuit_t *circ,
93 crypt_path_t *cpath);
94 int connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
95 origin_circuit_t *circ,
96 crypt_path_t *cpath);
98 /** Possible return values for parse_extended_hostname. */
99 typedef enum hostname_type_t {
100 NORMAL_HOSTNAME, ONION_HOSTNAME, EXIT_HOSTNAME, BAD_HOSTNAME
101 } hostname_type_t;
102 hostname_type_t parse_extended_hostname(char *address);
104 #if defined(HAVE_NET_IF_H) && defined(HAVE_NET_PFVAR_H)
105 int get_pf_socket(void);
106 #endif
108 int connection_edge_compatible_with_circuit(const entry_connection_t *conn,
109 const origin_circuit_t *circ);
110 int connection_edge_update_circuit_isolation(const entry_connection_t *conn,
111 origin_circuit_t *circ,
112 int dry_run);
113 void circuit_clear_isolation(origin_circuit_t *circ);
114 streamid_t get_unique_stream_id_by_circ(origin_circuit_t *circ);
116 void connection_edge_free_all(void);
118 void connection_ap_warn_and_unmark_if_pending_circ(
119 entry_connection_t *entry_conn,
120 const char *where);
122 /** @name Begin-cell flags
124 * These flags are used in RELAY_BEGIN cells to change the default behavior
125 * of the cell.
127 * @{
129 /** When this flag is set, the client is willing to get connected to IPv6
130 * addresses */
131 #define BEGIN_FLAG_IPV6_OK (1u<<0)
132 /** When this flag is set, the client DOES NOT support connecting to IPv4
133 * addresses. (The sense of this flag is inverted from IPV6_OK, so that the
134 * old default behavior of Tor is equivalent to having all flags set to 0.)
136 #define BEGIN_FLAG_IPV4_NOT_OK (1u<<1)
137 /** When this flag is set, if we find both an IPv4 and an IPv6 address,
138 * we use the IPv6 address. Otherwise we use the IPv4 address. */
139 #define BEGIN_FLAG_IPV6_PREFERRED (1u<<2)
140 /**@}*/
142 #ifdef CONNECTION_EDGE_PRIVATE
144 /** A parsed BEGIN or BEGIN_DIR cell */
145 typedef struct begin_cell_t {
146 /** The address the client has asked us to connect to, or NULL if this is
147 * a BEGIN_DIR cell*/
148 char *address;
149 /** The flags specified in the BEGIN cell's body. One or more of
150 * BEGIN_FLAG_*. */
151 uint32_t flags;
152 /** The client's requested port. */
153 uint16_t port;
154 /** The client's requested Stream ID */
155 uint16_t stream_id;
156 /** True iff this is a BEGIN_DIR cell. */
157 unsigned is_begindir : 1;
158 } begin_cell_t;
160 STATIC int begin_cell_parse(const cell_t *cell, begin_cell_t *bcell,
161 uint8_t *end_reason_out);
162 STATIC int connected_cell_format_payload(uint8_t *payload_out,
163 const tor_addr_t *addr,
164 uint32_t ttl);
166 typedef struct {
167 /** Original address, after we lowercased it but before we started
168 * mapping it.
170 char orig_address[MAX_SOCKS_ADDR_LEN];
171 /** True iff the address has been automatically remapped to a local
172 * address in VirtualAddrNetwork. (Only set true when we do a resolve
173 * and get a virtual address; not when we connect to the address.) */
174 int automap;
175 /** If this connection has a .exit address, who put it there? */
176 addressmap_entry_source_t exit_source;
177 /** If we've rewritten the address, when does this map expire? */
178 time_t map_expires;
179 /** If we should close the connection, this is the end_reason to pass
180 * to connection_mark_unattached_ap */
181 int end_reason;
182 /** True iff we should close the connection, either because of error or
183 * because of successful early RESOLVED reply. */
184 int should_close;
185 } rewrite_result_t;
187 STATIC void connection_ap_handshake_rewrite(entry_connection_t *conn,
188 rewrite_result_t *out);
189 #endif
191 #endif