From 1ddc710be11452e4bf5b8bd55399b4e3dfd2f7e8 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 7 Sep 2017 09:49:57 +0200 Subject: [PATCH] fix uTP path MTU discovery issue on windows (DF bit was not set correctly) --- ChangeLog | 1 + include/libtorrent/socket.hpp | 44 ++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 467dfa512..2a86cad09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 1.1.5 release + * fix uTP path MTU discovery issue on windows (DF bit was not set correctly) * fix python binding for torrent_handle, to be hashable * fix IPv6 tracker support by performing the second announce in more cases * fix utf-8 encoding check in torrent parser diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index 1f1067778..7df7af763 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -163,26 +163,24 @@ namespace libtorrent #endif #ifdef TORRENT_HAS_DONT_FRAGMENT + + // the order of these preprocessor tests matters. Windows defines both + // IP_DONTFRAGMENT and IP_MTU_DISCOVER, but the latter is not supported + // in general, the simple option of just setting the DF bit is preferred, if + // it's available +#if defined IP_DONTFRAG || defined IP_DONTFRAGMENT + struct dont_fragment { - dont_fragment(bool val) -#ifdef IP_PMTUDISCOVER_DO - : m_value(val ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT) {} -#else - : m_value(val) {} -#endif + dont_fragment(bool val) : m_value(val) {} template int level(Protocol const&) const { return IPPROTO_IP; } template int name(Protocol const&) const #if defined IP_DONTFRAG { return IP_DONTFRAG; } -#elif defined IP_MTU_DISCOVER - { return IP_MTU_DISCOVER; } -#elif defined IP_DONTFRAGMENT +#else // defined IP_DONTFRAGMENT { return IP_DONTFRAGMENT; } -#else - {} #endif template int const* data(Protocol const&) const { return &m_value; } @@ -190,6 +188,30 @@ namespace libtorrent size_t size(Protocol const&) const { return sizeof(m_value); } int m_value; }; + +#else + + // this is the fallback mechanism using the IP_MTU_DISCOVER option, which + // does a little bit more than we want, it makes the kernel track an estimate + // of the MTU and rejects packets immediately if they are believed to exceed + // it. + struct dont_fragment + { + dont_fragment(bool val) + : m_value(val ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT) {} + template + int level(Protocol const&) const { return IPPROTO_IP; } + template + int name(Protocol const&) const { return IP_MTU_DISCOVER; } + template + int const* data(Protocol const&) const { return &m_value; } + template + size_t size(Protocol const&) const { return sizeof(m_value); } + int m_value; + }; + +#endif // IP_DONTFRAG vs. IP_MTU_DISCOVER + #endif // TORRENT_HAS_DONT_FRAGMENT }