From 5b705e91769df0a564056f98e79ab3ad72ab2d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 20 Aug 2019 17:56:24 +0200 Subject: [PATCH] Disable Don't Fragment for StreamConnection --- lib/include/chiaki/takion.h | 1 + lib/src/senkusha.c | 1 + lib/src/streamconnection.c | 1 + lib/src/takion.c | 26 +++++++++++++++----------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/include/chiaki/takion.h b/lib/include/chiaki/takion.h index 485d302..1b29bda 100644 --- a/lib/include/chiaki/takion.h +++ b/lib/include/chiaki/takion.h @@ -116,6 +116,7 @@ typedef struct chiaki_takion_connect_info_t ChiakiLog *log; struct sockaddr *sa; size_t sa_len; + bool ip_dontfrag; ChiakiTakionCallback cb; void *cb_user; bool enable_crypt; diff --git a/lib/src/senkusha.c b/lib/src/senkusha.c index 45885f8..2cba4ac 100644 --- a/lib/src/senkusha.c +++ b/lib/src/senkusha.c @@ -151,6 +151,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSenkusha *senkusha, uint memcpy(takion_info.sa, session->connect_info.host_addrinfo_selected->ai_addr, takion_info.sa_len); err = set_port(takion_info.sa, htons(SENKUSHA_PORT)); assert(err == CHIAKI_ERR_SUCCESS); + takion_info.ip_dontfrag = true; takion_info.enable_crypt = false; takion_info.protocol_version = 7; diff --git a/lib/src/streamconnection.c b/lib/src/streamconnection.c index a82bb9c..2bde304 100644 --- a/lib/src/streamconnection.c +++ b/lib/src/streamconnection.c @@ -142,6 +142,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio memcpy(takion_info.sa, session->connect_info.host_addrinfo_selected->ai_addr, takion_info.sa_len); err = set_port(takion_info.sa, htons(STREAM_CONNECTION_PORT)); assert(err == CHIAKI_ERR_SUCCESS); + takion_info.ip_dontfrag = false; takion_info.enable_crypt = true; takion_info.protocol_version = 9; diff --git a/lib/src/takion.c b/lib/src/takion.c index 8494552..dcbf89b 100644 --- a/lib/src/takion.c +++ b/lib/src/takion.c @@ -245,23 +245,27 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki goto error_sock; } + if(info->ip_dontfrag) + { #if __APPLE__ - CHIAKI_LOGW(takion->log, "Don't fragment is not supported on macOS, MTU values may be incorrect."); + CHIAKI_LOGW(takion->log, "Don't fragment is not supported on macOS, MTU values may be incorrect."); #else #if defined(_WIN32) - const DWORD dontfragment_val = 1; - r = setsockopt(takion->sock, IPPROTO_IP, IP_DONTFRAGMENT, (const void *)&dontfragment_val, sizeof(dontfragment_val)); + const DWORD dontfragment_val = 1; + r = setsockopt(takion->sock, IPPROTO_IP, IP_DONTFRAGMENT, (const void *)&dontfragment_val, sizeof(dontfragment_val)); #else - const int mtu_discover_val = IP_PMTUDISC_DO; - r = setsockopt(takion->sock, IPPROTO_IP, IP_MTU_DISCOVER, (const void *)&mtu_discover_val, sizeof(mtu_discover_val)); + const int mtu_discover_val = IP_PMTUDISC_DO; + r = setsockopt(takion->sock, IPPROTO_IP, IP_MTU_DISCOVER, (const void *) &mtu_discover_val, sizeof(mtu_discover_val)); +#endif + if(r < 0) + { + CHIAKI_LOGE(takion->log, "Takion failed to setsockopt IP_MTU_DISCOVER: %s", strerror(errno)); + ret = CHIAKI_ERR_NETWORK; + goto error_sock; + } + CHIAKI_LOGI(takion->log, "Takion enabled Don't Fragment Bit"); #endif - if(r < 0) - { - CHIAKI_LOGE(takion->log, "Takion failed to setsockopt IP_MTU_DISCOVER: %s", strerror(errno)); - ret = CHIAKI_ERR_NETWORK; - goto error_sock; } -#endif r = connect(takion->sock, info->sa, info->sa_len); if(r < 0)