Tor  0.4.7.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-2021, 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 detach/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 hidden service identifier on either client or service side. This
132  * is for both introduction and rendezvous circuit. */
134 
135  /** Holds the data that the entry guard system uses to track the
136  * status of the guard this circuit is using, and thereby to determine
137  * whether this circuit can be used. */
138  struct circuit_guard_state_t *guard_state;
139 
140  /** Index into global_origin_circuit_list for this circuit. -1 if not
141  * present. */
143 
144  /** How many more relay_early cells can we send on this circuit, according
145  * to the specification? */
146  unsigned int remaining_relay_early_cells : 4;
147 
148  /** Set if this circuit is insanely old and we already informed the user */
149  unsigned int is_ancient : 1;
150 
151  /** Set if this circuit has already been opened. Used to detect
152  * cannibalized circuits. */
153  unsigned int has_opened : 1;
154 
155  /**
156  * Path bias state machine. Used to ensure integrity of our
157  * circuit building and usage accounting. See path_state_t
158  * for more details.
159  */
160  path_state_bitfield_t path_state : 3;
161 
162  /* If this flag is set, we should not consider attaching any more
163  * connections to this circuit. */
164  unsigned int unusable_for_new_conns : 1;
165 
166  /* If this flag is set (due to padding negotiation failure), we should
167  * not try to negotiate further circuit padding. */
168  unsigned padding_negotiation_failed : 1;
169 
170  /**
171  * If this flag is set, then a controller chose the first hop of this
172  * circuit's path, and it's okay to ignore checks that we'd usually do
173  * on this circuit's first hop.
174  *
175  * This flag is distinct from the CIRCUIT_PURPOSE_CONTROLLER purpose: the
176  * purpose indicates _what tor can use the circuit for_. Controller-created
177  * circuits can still have the CIRCUIT_PURPOSE_GENERAL purpose if Tor is
178  * allowed to attach streams to them.
179  */
181 
182  /**
183  * Tristate variable to guard against pathbias miscounting
184  * due to circuit purpose transitions changing the decision
185  * of pathbias_should_count(). This variable is informational
186  * only. The current results of pathbias_should_count() are
187  * the official decision for pathbias accounting.
188  */
190 #define PATHBIAS_SHOULDCOUNT_UNDECIDED 0
191 #define PATHBIAS_SHOULDCOUNT_IGNORED 1
192 #define PATHBIAS_SHOULDCOUNT_COUNTED 2
193 
194  /** For path probing. Store the temporary probe stream ID
195  * for response comparison */
197 
198  /** For path probing. Store the temporary probe address nonce
199  * (in host byte order) for response comparison. */
201 
202  /** Set iff this is a hidden-service circuit which has timed out
203  * according to our current circuit-build timeout, but which has
204  * been kept around because it might still succeed in connecting to
205  * its destination, and which is not a fully-connected rendezvous
206  * circuit.
207  *
208  * (We clear this flag for client-side rendezvous circuits when they
209  * are 'joined' to the other side's rendezvous circuit, so that
210  * connection_ap_handshake_attach_circuit can put client streams on
211  * the circuit. We also clear this flag for service-side rendezvous
212  * circuits when they are 'joined' to a client's rend circ, but only
213  * for symmetry with the client case. Client-side introduction
214  * circuits are closed when we get a joined rend circ, and
215  * service-side introduction circuits never have this flag set.) */
216  unsigned int hs_circ_has_timed_out : 1;
217 
218  /** Set iff this circuit has been given a relaxed timeout because
219  * no circuits have opened. Used to prevent spamming logs. */
220  unsigned int relaxed_timeout : 1;
221 
222  /** Set iff this is a service-side rendezvous circuit for which a
223  * new connection attempt has been launched. We consider launching
224  * a new service-side rend circ to a client when the previous one
225  * fails; now that we don't necessarily close a service-side rend
226  * circ when we launch a new one to the same client, this flag keeps
227  * us from launching two retries for the same failed rend circ. */
229 
230  /** What commands were sent over this circuit that decremented the
231  * RELAY_EARLY counter? This is for debugging task 878. */
233 
234  /** How many RELAY_EARLY cells have been sent over this circuit? This is
235  * for debugging task 878, too. */
237 
238  /** The next stream_id that will be tried when we're attempting to
239  * construct a new AP stream originating at this circuit. */
241 
242  /* The intro key replaces the hidden service's public key if purpose is
243  * S_ESTABLISH_INTRO or S_INTRO, provided that no unversioned rendezvous
244  * descriptor is used. */
245  crypto_pk_t *intro_key;
246 
247  /** Quasi-global identifier for this circuit; used for control.c */
248  /* XXXX NM This can get re-used after 2**32 circuits. */
250 
251  /** True if we have associated one stream to this circuit, thereby setting
252  * the isolation parameters for this circuit. Note that this doesn't
253  * necessarily mean that we've <em>attached</em> any streams to the circuit:
254  * we may only have marked up this circuit during the launch process.
255  */
256  unsigned int isolation_values_set : 1;
257  /** True iff any stream has <em>ever</em> been attached to this circuit.
258  *
259  * In a better world we could use timestamp_dirty for this, but
260  * timestamp_dirty is far too overloaded at the moment.
261  */
263 
264  /** A bitfield of ISO_* flags for every isolation field such that this
265  * circuit has had streams with more than one value for that field
266  * attached to it. */
268 
269  /** @name Isolation parameters
270  *
271  * If any streams have been associated with this circ (isolation_values_set
272  * == 1), and all streams associated with the circuit have had the same
273  * value for some field ((isolation_flags_mixed & ISO_FOO) == 0), then these
274  * elements hold the value for that field.
275  *
276  * Note again that "associated" is not the same as "attached": we
277  * preliminarily associate streams with a circuit while the circuit is being
278  * launched, so that we can tell whether we need to launch more circuits.
279  *
280  * @{
281  */
282  uint8_t client_proto_type;
283  uint8_t client_proto_socksver;
284  uint16_t dest_port;
285  tor_addr_t client_addr;
286  char *dest_address;
287  int session_group;
288  unsigned nym_epoch;
289  size_t socks_username_len;
290  uint8_t socks_password_len;
291  /* Note that the next two values are NOT NUL-terminated; see
292  socks_username_len and socks_password_len for their lengths. */
293  char *socks_username;
294  char *socks_password;
295  /** Global identifier for the first stream attached here; used by
296  * ISO_STREAM. */
298  /**@}*/
299  /** A list of addr_policy_t for this circuit in particular. Used by
300  * adjust_exit_policy_from_exitpolicy_failure.
301  */
303 
304  /** How long do we wait before closing this circuit if it remains
305  * completely idle after it was built, in seconds? This value
306  * is randomized on a per-circuit basis from CircuitsAvailableTimoeut
307  * to 2*CircuitsAvailableTimoeut. */
309 
310 };
311 
312 #endif /* !defined(ORIGIN_CIRCUIT_ST_H) */
Base circuit structure.
Master header file for Tor-specific functionality.
#define MAX_RELAY_EARLY_CELLS_PER_CIRCUIT
Definition: or.h:834
uint16_t streamid_t
Definition: or.h:491
path_state_t
@ PATH_STATE_ALREADY_COUNTED
@ PATH_STATE_USE_FAILED
@ PATH_STATE_BUILD_ATTEMPTED
@ PATH_STATE_BUILD_SUCCEEDED
@ PATH_STATE_USE_SUCCEEDED
@ PATH_STATE_NEW_CIRC
@ PATH_STATE_USE_ATTEMPTED
uint64_t associated_isolated_stream_global_id
uint32_t n_written_circ_bw
unsigned int hs_service_side_rend_circ_has_been_relaunched
unsigned int relaxed_timeout
struct hs_ident_circuit_t * hs_ident
edge_connection_t * p_streams
uint8_t relay_early_commands[MAX_RELAY_EARLY_CELLS_PER_CIRCUIT]
unsigned int isolation_values_set
unsigned int remaining_relay_early_cells
uint32_t n_overhead_written_circ_bw
unsigned int has_opened
path_state_bitfield_t path_state
unsigned int is_ancient
uint32_t pathbias_probe_nonce
uint32_t n_delivered_read_circ_bw
uint32_t n_delivered_written_circ_bw
uint32_t n_overhead_read_circ_bw
smartlist_t * prepend_policy
crypt_path_t * cpath
streamid_t pathbias_probe_id
cpath_build_state_t * build_state
unsigned int isolation_any_streams_attached
struct circuit_guard_state_t * guard_state
streamid_t next_stream_id
unsigned int hs_circ_has_timed_out
smartlist_t * half_streams
unsigned first_hop_from_controller