Tor  0.4.3.0-alpha-dev
origin_circuit_st.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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * @file origin_circuit_st.h
9  * @brief Origin circuit structure.
10  **/
11 
12 #ifndef ORIGIN_CIRCUIT_ST_H
13 #define ORIGIN_CIRCUIT_ST_H
14 
15 #include "core/or/or.h"
16 
17 #include "core/or/circuit_st.h"
18 
19 struct onion_queue_t;
20 
21 /**
22  * Describes the circuit building process in simplified terms based
23  * on the path bias accounting state for a circuit.
24  *
25  * NOTE: These state values are enumerated in the order for which we
26  * expect circuits to transition through them. If you add states,
27  * you need to preserve this overall ordering. The various pathbias
28  * state transition and accounting functions (pathbias_mark_* and
29  * pathbias_count_*) contain ordinal comparisons to enforce proper
30  * state transitions for corrections.
31  *
32  * This state machine and the associated logic was created to prevent
33  * miscounting due to unknown cases of circuit reuse. See also tickets
34  * #6475 and #7802.
35  */
37  /** This circuit is "new". It has not yet completed a first hop
38  * or been counted by the path bias code. */
40  /** This circuit has completed one/two hops, and has been counted by
41  * the path bias logic. */
43  /** This circuit has been completely built */
45  /** Did we try to attach any SOCKS streams or hidserv introductions to
46  * this circuit?
47  *
48  * Note: If we ever implement end-to-end stream timing through test
49  * stream probes (#5707), we must *not* set this for those probes
50  * (or any other automatic streams) because the adversary could
51  * just tag at a later point.
52  */
54  /** Did any SOCKS streams or hidserv introductions actually succeed on
55  * this circuit?
56  *
57  * If any streams detatch/fail from this circuit, the code transitions
58  * the circuit back to PATH_STATE_USE_ATTEMPTED to ensure we probe. See
59  * pathbias_mark_use_rollback() for that.
60  */
62 
63  /**
64  * This is a special state to indicate that we got a corrupted
65  * relay cell on a circuit and we don't intend to probe it.
66  */
68 
69  /**
70  * This is a special state to indicate that we already counted
71  * the circuit. Used to guard against potential state machine
72  * violations.
73  */
75 };
76 
77 /** An origin_circuit_t holds data necessary to build and use a circuit.
78  */
80  circuit_t base_;
81 
82  /** Linked list of AP streams (or EXIT streams if hidden service)
83  * associated with this circuit. */
85 
86  /** Smartlist of half-closed streams (half_edge_t*) that still
87  * have pending activity */
89 
90  /** Bytes read on this circuit since last call to
91  * control_event_circ_bandwidth_used(). Only used if we're configured
92  * to emit CIRC_BW events. */
93  uint32_t n_read_circ_bw;
94 
95  /** Bytes written to on this circuit since last call to
96  * control_event_circ_bandwidth_used(). Only used if we're configured
97  * to emit CIRC_BW events. */
99 
100  /** Total known-valid relay cell bytes since last call to
101  * control_event_circ_bandwidth_used(). Only used if we're configured
102  * to emit CIRC_BW events. */
104 
105  /** Total written relay cell bytes since last call to
106  * control_event_circ_bandwidth_used(). Only used if we're configured
107  * to emit CIRC_BW events. */
109 
110  /** Total overhead data in all known-valid relay data cells since last
111  * call to control_event_circ_bandwidth_used(). Only used if we're
112  * configured to emit CIRC_BW events. */
114 
115  /** Total written overhead data in all relay data cells since last call to
116  * control_event_circ_bandwidth_used(). Only used if we're configured
117  * to emit CIRC_BW events. */
119 
120  /** Build state for this circuit. It includes the intended path
121  * length, the chosen exit router, rendezvous information, etc.
122  */
124  /** The doubly-linked list of crypt_path_t entries, one per hop,
125  * for this circuit. This includes ciphers for each hop,
126  * integrity-checking digests for each hop, and package/delivery
127  * windows for each hop.
128  */
130 
131  /** Holds all rendezvous data on either client or service side. */
133 
134  /** Holds hidden service identifier on either client or service side. This
135  * is for both introduction and rendezvous circuit. */
137 
138  /** Holds the data that the entry guard system uses to track the
139  * status of the guard this circuit is using, and thereby to determine
140  * whether this circuit can be used. */
141  struct circuit_guard_state_t *guard_state;
142 
143  /** Index into global_origin_circuit_list for this circuit. -1 if not
144  * present. */
146 
147  /** How many more relay_early cells can we send on this circuit, according
148  * to the specification? */
149  unsigned int remaining_relay_early_cells : 4;
150 
151  /** Set if this circuit is insanely old and we already informed the user */
152  unsigned int is_ancient : 1;
153 
154  /** Set if this circuit has already been opened. Used to detect
155  * cannibalized circuits. */
156  unsigned int has_opened : 1;
157 
158  /**
159  * Path bias state machine. Used to ensure integrity of our
160  * circuit building and usage accounting. See path_state_t
161  * for more details.
162  */
163  path_state_bitfield_t path_state : 3;
164 
165  /* If this flag is set, we should not consider attaching any more
166  * connections to this circuit. */
167  unsigned int unusable_for_new_conns : 1;
168 
169  /* If this flag is set (due to padding negotiation failure), we should
170  * not try to negotiate further circuit padding. */
171  unsigned padding_negotiation_failed : 1;
172 
173  /**
174  * Tristate variable to guard against pathbias miscounting
175  * due to circuit purpose transitions changing the decision
176  * of pathbias_should_count(). This variable is informational
177  * only. The current results of pathbias_should_count() are
178  * the official decision for pathbias accounting.
179  */
181 #define PATHBIAS_SHOULDCOUNT_UNDECIDED 0
182 #define PATHBIAS_SHOULDCOUNT_IGNORED 1
183 #define PATHBIAS_SHOULDCOUNT_COUNTED 2
184 
185  /** For path probing. Store the temporary probe stream ID
186  * for response comparison */
188 
189  /** For path probing. Store the temporary probe address nonce
190  * (in host byte order) for response comparison. */
192 
193  /** Set iff this is a hidden-service circuit which has timed out
194  * according to our current circuit-build timeout, but which has
195  * been kept around because it might still succeed in connecting to
196  * its destination, and which is not a fully-connected rendezvous
197  * circuit.
198  *
199  * (We clear this flag for client-side rendezvous circuits when they
200  * are 'joined' to the other side's rendezvous circuit, so that
201  * connection_ap_handshake_attach_circuit can put client streams on
202  * the circuit. We also clear this flag for service-side rendezvous
203  * circuits when they are 'joined' to a client's rend circ, but only
204  * for symmetry with the client case. Client-side introduction
205  * circuits are closed when we get a joined rend circ, and
206  * service-side introduction circuits never have this flag set.) */
207  unsigned int hs_circ_has_timed_out : 1;
208 
209  /** Set iff this circuit has been given a relaxed timeout because
210  * no circuits have opened. Used to prevent spamming logs. */
211  unsigned int relaxed_timeout : 1;
212 
213  /** Set iff this is a service-side rendezvous circuit for which a
214  * new connection attempt has been launched. We consider launching
215  * a new service-side rend circ to a client when the previous one
216  * fails; now that we don't necessarily close a service-side rend
217  * circ when we launch a new one to the same client, this flag keeps
218  * us from launching two retries for the same failed rend circ. */
220 
221  /** What commands were sent over this circuit that decremented the
222  * RELAY_EARLY counter? This is for debugging task 878. */
224 
225  /** How many RELAY_EARLY cells have been sent over this circuit? This is
226  * for debugging task 878, too. */
228 
229  /** The next stream_id that will be tried when we're attempting to
230  * construct a new AP stream originating at this circuit. */
232 
233  /* The intro key replaces the hidden service's public key if purpose is
234  * S_ESTABLISH_INTRO or S_INTRO, provided that no unversioned rendezvous
235  * descriptor is used. */
236  crypto_pk_t *intro_key;
237 
238  /** Quasi-global identifier for this circuit; used for control.c */
239  /* XXXX NM This can get re-used after 2**32 circuits. */
241 
242  /** True if we have associated one stream to this circuit, thereby setting
243  * the isolation parameters for this circuit. Note that this doesn't
244  * necessarily mean that we've <em>attached</em> any streams to the circuit:
245  * we may only have marked up this circuit during the launch process.
246  */
247  unsigned int isolation_values_set : 1;
248  /** True iff any stream has <em>ever</em> been attached to this circuit.
249  *
250  * In a better world we could use timestamp_dirty for this, but
251  * timestamp_dirty is far too overloaded at the moment.
252  */
254 
255  /** A bitfield of ISO_* flags for every isolation field such that this
256  * circuit has had streams with more than one value for that field
257  * attached to it. */
259 
260  /** @name Isolation parameters
261  *
262  * If any streams have been associated with this circ (isolation_values_set
263  * == 1), and all streams associated with the circuit have had the same
264  * value for some field ((isolation_flags_mixed & ISO_FOO) == 0), then these
265  * elements hold the value for that field.
266  *
267  * Note again that "associated" is not the same as "attached": we
268  * preliminarily associate streams with a circuit while the circuit is being
269  * launched, so that we can tell whether we need to launch more circuits.
270  *
271  * @{
272  */
273  uint8_t client_proto_type;
274  uint8_t client_proto_socksver;
275  uint16_t dest_port;
276  tor_addr_t client_addr;
277  char *dest_address;
278  int session_group;
279  unsigned nym_epoch;
280  size_t socks_username_len;
281  uint8_t socks_password_len;
282  /* Note that the next two values are NOT NUL-terminated; see
283  socks_username_len and socks_password_len for their lengths. */
284  char *socks_username;
285  char *socks_password;
286  /** Global identifier for the first stream attached here; used by
287  * ISO_STREAM. */
289  /**@}*/
290  /** A list of addr_policy_t for this circuit in particular. Used by
291  * adjust_exit_policy_from_exitpolicy_failure.
292  */
294 
295  /** How long do we wait before closing this circuit if it remains
296  * completely idle after it was built, in seconds? This value
297  * is randomized on a per-circuit basis from CircuitsAvailableTimoeut
298  * to 2*CircuitsAvailableTimoeut. */
300 
301 };
302 
303 #endif /* !defined(ORIGIN_CIRCUIT_ST_H) */
Base circuit structure.
uint32_t pathbias_probe_nonce
uint64_t associated_isolated_stream_global_id
smartlist_t * half_streams
uint32_t n_delivered_read_circ_bw
crypt_path_t * cpath
path_state_t
uint32_t n_overhead_read_circ_bw
unsigned int isolation_any_streams_attached
uint32_t n_overhead_written_circ_bw
uint8_t relay_early_commands[MAX_RELAY_EARLY_CELLS_PER_CIRCUIT]
streamid_t next_stream_id
unsigned int remaining_relay_early_cells
#define MAX_RELAY_EARLY_CELLS_PER_CIRCUIT
Definition: or.h:940
unsigned int isolation_values_set
streamid_t pathbias_probe_id
uint32_t n_delivered_written_circ_bw
Master header file for Tor-specific functionality.
uint16_t streamid_t
Definition: or.h:610
uint32_t n_written_circ_bw
unsigned int relaxed_timeout
unsigned int hs_circ_has_timed_out
path_state_bitfield_t path_state
cpath_build_state_t * build_state
rend_data_t * rend_data
edge_connection_t * p_streams
struct circuit_guard_state_t * guard_state
struct hs_ident_circuit_t * hs_ident
unsigned int is_ancient
smartlist_t * prepend_policy
unsigned int hs_service_side_rend_circ_has_been_relaunched
unsigned int has_opened