mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-09 11:27:53 +00:00
set MTU if local address is specified explicitly. update MTU for ipv6 if not set
This commit is contained in:
parent
09aa96e486
commit
dbb9295063
@ -420,27 +420,30 @@ namespace i2p
|
|||||||
if (address->host != host && address->IsCompatible (host) &&
|
if (address->host != host && address->IsCompatible (host) &&
|
||||||
!i2p::util::net::IsYggdrasilAddress (address->host))
|
!i2p::util::net::IsYggdrasilAddress (address->host))
|
||||||
{
|
{
|
||||||
|
// update host
|
||||||
address->host = host;
|
address->host = host;
|
||||||
if (host.is_v6 () && (address->transportStyle == i2p::data::RouterInfo::eTransportSSU || address->IsSSU2 ()))
|
|
||||||
{
|
|
||||||
// update MTU
|
|
||||||
auto mtu = i2p::util::net::GetMTU (host);
|
|
||||||
if (mtu)
|
|
||||||
{
|
|
||||||
LogPrint (eLogDebug, "Router: Our v6 MTU=", mtu);
|
|
||||||
int maxMTU = i2p::util::net::GetMaxMTU (host.to_v6 ());
|
|
||||||
if (mtu > maxMTU)
|
|
||||||
{
|
|
||||||
mtu = maxMTU;
|
|
||||||
LogPrint(eLogWarning, "Router: MTU dropped to upper limit of ", maxMTU, " bytes");
|
|
||||||
}
|
|
||||||
if (mtu && !address->IsSSU2 ()) // SSU1
|
|
||||||
mtu = (mtu >> 4) << 4; // round to multiple of 16
|
|
||||||
if (address->ssu) address->ssu->mtu = mtu;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
if (host.is_v6 () && address->IsV6 () && address->ssu &&
|
||||||
|
(!address->ssu->mtu || updated))
|
||||||
|
{
|
||||||
|
// update MTU
|
||||||
|
auto mtu = i2p::util::net::GetMTU (host);
|
||||||
|
if (mtu)
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "Router: Our v6 MTU=", mtu);
|
||||||
|
int maxMTU = i2p::util::net::GetMaxMTU (host.to_v6 ());
|
||||||
|
if (mtu > maxMTU)
|
||||||
|
{
|
||||||
|
mtu = maxMTU;
|
||||||
|
LogPrint(eLogWarning, "Router: MTU dropped to upper limit of ", maxMTU, " bytes");
|
||||||
|
}
|
||||||
|
if (mtu && !address->IsSSU2 ()) // SSU1
|
||||||
|
mtu = (mtu >> 4) << 4; // round to multiple of 16
|
||||||
|
address->ssu->mtu = mtu;
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto ts = i2p::util::GetSecondsSinceEpoch ();
|
auto ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
if (updated || ts > m_LastUpdateTime + ROUTER_INFO_UPDATE_INTERVAL)
|
if (updated || ts > m_LastUpdateTime + ROUTER_INFO_UPDATE_INTERVAL)
|
||||||
@ -866,6 +869,43 @@ namespace i2p
|
|||||||
UpdateRouterInfo ();
|
UpdateRouterInfo ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RouterContext::SetMTU (int mtu, bool v4)
|
||||||
|
{
|
||||||
|
if (mtu < 1280 || mtu > 1500) return;
|
||||||
|
auto& addresses = m_RouterInfo.GetAddresses ();
|
||||||
|
for (auto& addr: addresses)
|
||||||
|
{
|
||||||
|
if (addr->ssu && ((v4 && addr->IsV4 ()) || (!v4 && addr->IsV6 ())))
|
||||||
|
{
|
||||||
|
if (!addr->IsSSU2 ()) // SSU1
|
||||||
|
{
|
||||||
|
// round to multiple of 16
|
||||||
|
if (v4)
|
||||||
|
{
|
||||||
|
if (mtu > 1484) mtu = 1484;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mtu -= 12;
|
||||||
|
mtu = (mtu >> 4) << 4;
|
||||||
|
mtu += 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mtu > 1488) mtu = 1488;
|
||||||
|
else
|
||||||
|
mtu = (mtu >> 4) << 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mtu)
|
||||||
|
{
|
||||||
|
addr->ssu->mtu = mtu;
|
||||||
|
LogPrint (eLogDebug, "Router: MTU for ", v4 ? "ipv4" : "ipv6", " address is set to ", mtu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RouterContext::UpdateNTCP2V6Address (const boost::asio::ip::address& host)
|
void RouterContext::UpdateNTCP2V6Address (const boost::asio::ip::address& host)
|
||||||
{
|
{
|
||||||
bool isYgg = i2p::util::net::IsYggdrasilAddress (host);
|
bool isYgg = i2p::util::net::IsYggdrasilAddress (host);
|
||||||
|
@ -144,6 +144,7 @@ namespace garlic
|
|||||||
void SetSupportsV6 (bool supportsV6);
|
void SetSupportsV6 (bool supportsV6);
|
||||||
void SetSupportsV4 (bool supportsV4);
|
void SetSupportsV4 (bool supportsV4);
|
||||||
void SetSupportsMesh (bool supportsmesh, const boost::asio::ip::address_v6& host);
|
void SetSupportsMesh (bool supportsmesh, const boost::asio::ip::address_v6& host);
|
||||||
|
void SetMTU (int mtu, bool v4);
|
||||||
i2p::crypto::NoiseSymmetricState& GetCurrentNoiseState () { return m_CurrentNoiseState; };
|
i2p::crypto::NoiseSymmetricState& GetCurrentNoiseState () { return m_CurrentNoiseState; };
|
||||||
|
|
||||||
void UpdateNTCP2V6Address (const boost::asio::ip::address& host); // called from Daemon. TODO: remove
|
void UpdateNTCP2V6Address (const boost::asio::ip::address& host); // called from Daemon. TODO: remove
|
||||||
|
@ -115,9 +115,22 @@ namespace transport
|
|||||||
{
|
{
|
||||||
if (localAddress.is_unspecified ()) return;
|
if (localAddress.is_unspecified ()) return;
|
||||||
if (localAddress.is_v4 ())
|
if (localAddress.is_v4 ())
|
||||||
|
{
|
||||||
m_AddressV4 = localAddress;
|
m_AddressV4 = localAddress;
|
||||||
|
int mtu = i2p::util::net::GetMTU (localAddress);
|
||||||
|
if (mtu < (int)SSU2_MIN_PACKET_SIZE) mtu = SSU2_MIN_PACKET_SIZE;
|
||||||
|
if (mtu > (int)SSU2_MAX_PACKET_SIZE) mtu = SSU2_MAX_PACKET_SIZE;
|
||||||
|
i2p::context.SetMTU (mtu, true);
|
||||||
|
}
|
||||||
else if (localAddress.is_v6 ())
|
else if (localAddress.is_v6 ())
|
||||||
|
{
|
||||||
m_AddressV6 = localAddress;
|
m_AddressV6 = localAddress;
|
||||||
|
int maxMTU = i2p::util::net::GetMaxMTU (localAddress.to_v6 ());
|
||||||
|
int mtu = i2p::util::net::GetMTU (localAddress);
|
||||||
|
if (mtu > maxMTU) mtu = maxMTU;
|
||||||
|
if (mtu < (int)SSU2_MIN_PACKET_SIZE) mtu = SSU2_MIN_PACKET_SIZE;
|
||||||
|
i2p::context.SetMTU (mtu, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SSU2Server::IsSupported (const boost::asio::ip::address& addr) const
|
bool SSU2Server::IsSupported (const boost::asio::ip::address& addr) const
|
||||||
|
Loading…
Reference in New Issue
Block a user