aboutsummaryrefslogtreecommitdiff
path: root/src/core/or/circuitlist.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2018-10-12 09:22:30 -0400
committerDavid Goulet <dgoulet@torproject.org>2018-10-18 12:56:51 -0400
commit9ba16c4d03a39bcd369ccd59f6bfa351f4b527d5 (patch)
treea677d211b4bde397322f3eaa21393bea3332a146 /src/core/or/circuitlist.c
parenta5599fb71c51ddec47282164f71cfb06933096cc (diff)
downloadtor-9ba16c4d03a39bcd369ccd59f6bfa351f4b527d5.tar.gz
tor-9ba16c4d03a39bcd369ccd59f6bfa351f4b527d5.zip
hs-v3: Close client intro circuits if the descriptor is replaced
When storing a descriptor in the client cache, if we are about to replace an existing descriptor, make sure to close every introduction circuits of the old descriptor so we don't have leftovers lying around. Ticket 27471 describes a situation where tor is sending an INTRODUCE1 cell on an introduction circuit for which it doesn't have a matching intro point object (taken from the descriptor). The main theory is that, after a new descriptor showed up, the introduction points changed which led to selecting an introduction circuit not used by the service anymore thus for which we are unable to find the corresponding introduction point within the descriptor we just fetched. Closes #27471. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/core/or/circuitlist.c')
-rw-r--r--src/core/or/circuitlist.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/core/or/circuitlist.c b/src/core/or/circuitlist.c
index 5ff142c15c..35efc6541f 100644
--- a/src/core/or/circuitlist.c
+++ b/src/core/or/circuitlist.c
@@ -1644,15 +1644,24 @@ circuit_get_ready_rend_circ_by_rend_data(const rend_data_t *rend_data)
return NULL;
}
-/** Return the first service introduction circuit originating from the global
- * circuit list after <b>start</b> or at the start of the list if <b>start</b>
- * is NULL. Return NULL if no circuit is found.
+/** Return the first introduction circuit originating from the global circuit
+ * list after <b>start</b> or at the start of the list if <b>start</b> is
+ * NULL. Return NULL if no circuit is found.
+ *
+ * If <b>want_client_circ</b> is true, then we are looking for client-side
+ * introduction circuits: A client introduction point circuit has a purpose of
+ * either CIRCUIT_PURPOSE_C_INTRODUCING, CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT
+ * or CIRCUIT_PURPOSE_C_INTRODUCE_ACKED. This does not return a circuit marked
+ * for close, but it returns circuits regardless of their circuit state.
*
- * A service introduction point circuit has a purpose of either
- * CIRCUIT_PURPOSE_S_ESTABLISH_INTRO or CIRCUIT_PURPOSE_S_INTRO. This does not
- * return a circuit marked for close and its state must be open. */
+ * If <b>want_client_circ</b> is false, then we are looking for service-side
+ * introduction circuits: A service introduction point circuit has a purpose of
+ * either CIRCUIT_PURPOSE_S_ESTABLISH_INTRO or CIRCUIT_PURPOSE_S_INTRO. This
+ * does not return circuits marked for close, or in any state other than open.
+ */
origin_circuit_t *
-circuit_get_next_service_intro_circ(origin_circuit_t *start)
+circuit_get_next_intro_circ(const origin_circuit_t *start,
+ bool want_client_circ)
{
int idx = 0;
smartlist_t *lst = circuit_get_global_list();
@@ -1664,13 +1673,29 @@ circuit_get_next_service_intro_circ(origin_circuit_t *start)
for ( ; idx < smartlist_len(lst); ++idx) {
circuit_t *circ = smartlist_get(lst, idx);
- /* Ignore a marked for close circuit or purpose not matching a service
- * intro point or if the state is not open. */
- if (circ->marked_for_close || circ->state != CIRCUIT_STATE_OPEN ||
- (circ->purpose != CIRCUIT_PURPOSE_S_ESTABLISH_INTRO &&
- circ->purpose != CIRCUIT_PURPOSE_S_INTRO)) {
+ /* Ignore a marked for close circuit or if the state is not open. */
+ if (circ->marked_for_close) {
continue;
}
+
+ /* Depending on whether we are looking for client or service circs, skip
+ * circuits with other purposes. */
+ if (want_client_circ) {
+ if (circ->purpose != CIRCUIT_PURPOSE_C_INTRODUCING &&
+ circ->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT &&
+ circ->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACKED) {
+ continue;
+ }
+ } else { /* we are looking for service-side circs */
+ if (circ->state != CIRCUIT_STATE_OPEN) {
+ continue;
+ }
+ if (circ->purpose != CIRCUIT_PURPOSE_S_ESTABLISH_INTRO &&
+ circ->purpose != CIRCUIT_PURPOSE_S_INTRO) {
+ continue;
+ }
+ }
+
/* The purposes we are looking for are only for origin circuits so the
* following is valid. */
return TO_ORIGIN_CIRCUIT(circ);