From 8511a74c1049015901ac5dd405c7465380fca5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20M=C3=BCller?= Date: Sun, 6 Sep 2020 15:17:33 +0200 Subject: [PATCH] Fix MTU detection (Fix #303) (#304) --- lib/src/senkusha.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/src/senkusha.c b/lib/src/senkusha.c index e45d39f5..d1049fdf 100644 --- a/lib/src/senkusha.c +++ b/lib/src/senkusha.c @@ -363,7 +363,7 @@ static ChiakiErrorCode senkusha_run_mtu_in_test(ChiakiSenkusha *senkusha, uint32 uint32_t cur = max; uint32_t request_id = 0; - while(max > min) + while((max - min) > 1) { bool success = false; for(uint32_t attempt=0; attemptlog, "Senkusha determined inbound MTU %u", (unsigned int)max); - *mtu = max; + CHIAKI_LOGI(senkusha->log, "Senkusha determined inbound MTU %u", (unsigned int)min); + *mtu = min; return CHIAKI_ERR_SUCCESS; } @@ -481,7 +481,7 @@ static ChiakiErrorCode senkusha_run_mtu_out_test(ChiakiSenkusha *senkusha, uint3 err = CHIAKI_ERR_SUCCESS; uint32_t cur = mtu_in; - while(max > min) + while((max - min) > 1) { bool success = false; for(uint32_t attempt=0; attemptlog, "Senkusha failed to send ping"); - goto beach; + err = CHIAKI_ERR_TIMEOUT; + } + else + { + err = chiaki_cond_timedwait_pred(&senkusha->state_cond, &senkusha->state_mutex, timeout_ms, state_finished_cond_check, senkusha); } - err = chiaki_cond_timedwait_pred(&senkusha->state_cond, &senkusha->state_mutex, timeout_ms, state_finished_cond_check, senkusha); assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT); if(!senkusha->state_finished) @@ -549,14 +552,14 @@ static ChiakiErrorCode senkusha_run_mtu_out_test(ChiakiSenkusha *senkusha, uint3 } if(success) - min = cur + 1; + min = cur; else - max = cur - 1; + max = cur; cur = min + (max - min) / 2; } - CHIAKI_LOGI(senkusha->log, "Senkusha determined outbound MTU %u", (unsigned int)max); - *mtu = max; + CHIAKI_LOGI(senkusha->log, "Senkusha determined outbound MTU %u", (unsigned int)min); + *mtu = min; CHIAKI_LOGI(senkusha->log, "Senkusha sending final Client MTU Command"); client_mtu_cmd.id = 2;