aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-10-31 13:50:36 -0400
committerDavid Goulet <dgoulet@torproject.org>2019-10-31 13:50:36 -0400
commitff8823d03cef50cb3a78f13a35558288e54c2173 (patch)
tree61a4150c243164668cf42f4d83bc961208655495
parentfa0257eda0b985349b3777776a6613ca850132b2 (diff)
downloadtor-ff8823d03cef50cb3a78f13a35558288e54c2173.tar.gz
tor-ff8823d03cef50cb3a78f13a35558288e54c2173.zip
dos: Account rejection in hs_dos_can_send_intro2
This required a small refactoring so we could count properly the INTRO2 sending disallow. Part of #31371 Signed-off-by: David Goulet <dgoulet@torproject.org>
-rw-r--r--src/feature/hs/hs_dos.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/feature/hs/hs_dos.c b/src/feature/hs/hs_dos.c
index 19794e09d3..81041475e8 100644
--- a/src/feature/hs/hs_dos.c
+++ b/src/feature/hs/hs_dos.c
@@ -45,6 +45,9 @@
* introduction DoS defense. Disabled by default. */
#define HS_DOS_INTRODUCE_ENABLED_DEFAULT 0
+/* INTRODUCE2 rejected request counter. */
+static uint64_t intro2_rejected_count = 0;
+
/* Consensus parameters. The ESTABLISH_INTRO DoS cell extension have higher
* priority than these values. If no extension is sent, these are used only by
* the introduction point. */
@@ -163,12 +166,12 @@ hs_dos_can_send_intro2(or_circuit_t *s_intro_circ)
* This can be set by the consensus, the ESTABLISH_INTRO cell extension or
* the hardcoded values in tor code. */
if (!s_intro_circ->introduce2_dos_defense_enabled) {
- return true;
+ goto allow;
}
/* Should not happen but if so, scream loudly. */
if (BUG(TO_CIRCUIT(s_intro_circ)->purpose != CIRCUIT_PURPOSE_INTRO_POINT)) {
- return false;
+ goto disallow;
}
/* This is called just after we got a valid and parsed INTRODUCE1 cell. The
@@ -189,7 +192,18 @@ hs_dos_can_send_intro2(or_circuit_t *s_intro_circ)
}
/* Finally, we can send a new INTRODUCE2 if there are still tokens. */
- return token_bucket_ctr_get(&s_intro_circ->introduce2_bucket) > 0;
+ if (token_bucket_ctr_get(&s_intro_circ->introduce2_bucket) > 0) {
+ goto allow;
+ }
+
+ /* Fallthrough is to disallow since this means the bucket has reached 0. */
+ disallow:
+ /* Increment stats counter, we are rejecting the INTRO2 cell. */
+ intro2_rejected_count++;
+ return false;
+
+ allow:
+ return true;
}
/* Initialize the onion service Denial of Service subsystem. */