connection_edge.h 6 KB
Newer Older
Sebastian Hahn's avatar
Sebastian Hahn committed
1
2
3
/* Copyright (c) 2001 Matej Pfajfar.
 * Copyright (c) 2001-2004, Roger Dingledine.
 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4
 * Copyright (c) 2007-2012, The Tor Project, Inc. */
Sebastian Hahn's avatar
Sebastian Hahn committed
5
6
7
8
9
10
11
/* See LICENSE for licensing information */

/**
 * \file connection_edge.h
 * \brief Header file for connection_edge.c.
 **/

12
13
#ifndef TOR_CONNECTION_EDGE_H
#define TOR_CONNECTION_EDGE_H
Sebastian Hahn's avatar
Sebastian Hahn committed
14
15

#define connection_mark_unattached_ap(conn, endreason) \
16
  connection_mark_unattached_ap_((conn), (endreason), __LINE__, SHORT_FILE__)
Sebastian Hahn's avatar
Sebastian Hahn committed
17

18
void connection_mark_unattached_ap_(entry_connection_t *conn, int endreason,
Sebastian Hahn's avatar
Sebastian Hahn committed
19
20
21
22
23
24
25
                                    int line, const char *file);
int connection_edge_reached_eof(edge_connection_t *conn);
int connection_edge_process_inbuf(edge_connection_t *conn,
                                  int package_partial);
int connection_edge_destroy(circid_t circ_id, edge_connection_t *conn);
int connection_edge_end(edge_connection_t *conn, uint8_t reason);
int connection_edge_end_errno(edge_connection_t *conn);
26
int connection_edge_flushed_some(edge_connection_t *conn);
Sebastian Hahn's avatar
Sebastian Hahn committed
27
28
29
int connection_edge_finished_flushing(edge_connection_t *conn);
int connection_edge_finished_connecting(edge_connection_t *conn);

30
void connection_ap_about_to_close(entry_connection_t *edge_conn);
31
32
void connection_exit_about_to_close(edge_connection_t *edge_conn);

33
34
int connection_ap_handshake_send_begin(entry_connection_t *ap_conn);
int connection_ap_handshake_send_resolve(entry_connection_t *ap_conn);
Sebastian Hahn's avatar
Sebastian Hahn committed
35

36
entry_connection_t  *connection_ap_make_link(connection_t *partner,
37
                                            char *address, uint16_t port,
Sebastian Hahn's avatar
Sebastian Hahn committed
38
                                            const char *digest,
39
40
                                            int session_group,
                                            int isolation_flags,
Sebastian Hahn's avatar
Sebastian Hahn committed
41
                                            int use_begindir, int want_onehop);
42
void connection_ap_handshake_socks_reply(entry_connection_t *conn, char *reply,
Sebastian Hahn's avatar
Sebastian Hahn committed
43
44
                                         size_t replylen,
                                         int endreason);
45
void connection_ap_handshake_socks_resolved(entry_connection_t *conn,
Sebastian Hahn's avatar
Sebastian Hahn committed
46
47
                                            int answer_type,
                                            size_t answer_len,
48
                                            const uint8_t *answer,
Sebastian Hahn's avatar
Sebastian Hahn committed
49
50
51
52
53
54
55
                                            int ttl,
                                            time_t expires);

int connection_exit_begin_conn(cell_t *cell, circuit_t *circ);
int connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ);
void connection_exit_connect(edge_connection_t *conn);
int connection_edge_is_rendezvous_stream(edge_connection_t *conn);
56
int connection_ap_can_use_exit(const entry_connection_t *conn,
57
                               const node_t *exit);
Sebastian Hahn's avatar
Sebastian Hahn committed
58
59
60
61
62
void connection_ap_expire_beginning(void);
void connection_ap_attach_pending(void);
void connection_ap_fail_onehop(const char *failed_digest,
                               cpath_build_state_t *build_state);
void circuit_discard_optional_exit_enclaves(extend_info_t *info);
63
int connection_ap_detach_retriable(entry_connection_t *conn,
Sebastian Hahn's avatar
Sebastian Hahn committed
64
65
                                   origin_circuit_t *circ,
                                   int reason);
66
int connection_ap_process_transparent(entry_connection_t *conn);
Sebastian Hahn's avatar
Sebastian Hahn committed
67
68
69

int address_is_invalid_destination(const char *address, int client);

70
int connection_ap_rewrite_and_attach_if_allowed(entry_connection_t *conn,
71
72
                                                origin_circuit_t *circ,
                                                crypt_path_t *cpath);
73
int connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
Sebastian Hahn's avatar
Sebastian Hahn committed
74
75
76
77
78
79
80
                                               origin_circuit_t *circ,
                                               crypt_path_t *cpath);

/** Possible return values for parse_extended_hostname. */
typedef enum hostname_type_t {
  NORMAL_HOSTNAME, ONION_HOSTNAME, EXIT_HOSTNAME, BAD_HOSTNAME
} hostname_type_t;
81
hostname_type_t parse_extended_hostname(char *address);
Sebastian Hahn's avatar
Sebastian Hahn committed
82
83
84
85
86

#if defined(HAVE_NET_IF_H) && defined(HAVE_NET_PFVAR_H)
int get_pf_socket(void);
#endif

87
int connection_edge_compatible_with_circuit(const entry_connection_t *conn,
88
                                            const origin_circuit_t *circ);
89
int connection_edge_update_circuit_isolation(const entry_connection_t *conn,
90
91
                                             origin_circuit_t *circ,
                                             int dry_run);
92
void circuit_clear_isolation(origin_circuit_t *circ);
93

94
95
96
97
98
99
100
101
102
/** @name Begin-cell flags
 *
 * These flags are used in RELAY_BEGIN cells to change the default behavior
 * of the cell.
 *
 * @{
 **/
/** When this flag is set, the client is willing to get connected to IPv6
 * addresses */
103
#define BEGIN_FLAG_IPV6_OK        (1u<<0)
104
105
106
107
/** When this flag is set, the client DOES NOT support connecting to IPv4
 * addresses.  (The sense of this flag is inverted from IPV6_OK, so that the
 * old default behavior of Tor is equivalent to having all flags set to 0.)
 **/
108
#define BEGIN_FLAG_IPV4_NOT_OK    (1u<<1)
109
110
/** When this flag is set, if we find both an IPv4 and an IPv6 address,
 * we use the IPv6 address.  Otherwise we use the IPv4 address. */
111
#define BEGIN_FLAG_IPV6_PREFERRED (1u<<2)
112
/**@}*/
113

114
115
#ifdef CONNECTION_EDGE_PRIVATE

116
/** A parsed BEGIN or BEGIN_DIR cell */
117
typedef struct begin_cell_t {
118
119
  /** The address the client has asked us to connect to, or NULL if this is
   * a BEGIN_DIR cell*/
120
  char *address;
121
122
  /** The flags specified in the BEGIN cell's body.  One or more of
   * BEGIN_FLAG_*. */
123
  uint32_t flags;
124
  /** The client's requested port. */
125
  uint16_t port;
126
  /** The client's requested Stream ID */
127
  uint16_t stream_id;
128
  /** True iff this is a BEGIN_DIR cell. */
129
130
131
132
133
  unsigned is_begindir : 1;
} begin_cell_t;

int begin_cell_parse(const cell_t *cell, begin_cell_t *bcell,
                     uint8_t *end_reason_out);
134
135
136
int connected_cell_format_payload(uint8_t *payload_out,
                                  const tor_addr_t *addr,
                                  uint32_t ttl);
137
138
#endif

Sebastian Hahn's avatar
Sebastian Hahn committed
139
140
#endif