Browse Source

handle 'reservedrange' param properly

pull/2007/head
orignal 11 months ago
parent
commit
ca9782dd0d
  1. 4
      daemon/Daemon.cpp
  2. 4
      libi2pd/NTCP2.cpp
  3. 24
      libi2pd/Reseed.cpp
  4. 5
      libi2pd/RouterInfo.cpp
  5. 8
      libi2pd/SSU2.cpp
  6. 4
      libi2pd/SSU2Session.cpp
  7. 13
      libi2pd/Transports.cpp
  8. 5
      libi2pd/Transports.h

4
daemon/Daemon.cpp

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2023, The PurpleI2P Project * Copyright (c) 2013-2024, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -298,12 +298,10 @@ namespace util
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2); bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
bool ssu2; i2p::config::GetOption("ssu2.enabled", ssu2); bool ssu2; i2p::config::GetOption("ssu2.enabled", ssu2);
bool checkInReserved; i2p::config::GetOption("reservedrange", checkInReserved);
LogPrint(eLogInfo, "Daemon: Starting Transports"); LogPrint(eLogInfo, "Daemon: Starting Transports");
if(!ssu2) LogPrint(eLogInfo, "Daemon: SSU2 disabled"); if(!ssu2) LogPrint(eLogInfo, "Daemon: SSU2 disabled");
if(!ntcp2) LogPrint(eLogInfo, "Daemon: NTCP2 disabled"); if(!ntcp2) LogPrint(eLogInfo, "Daemon: NTCP2 disabled");
i2p::transport::transports.SetCheckReserved(checkInReserved);
i2p::transport::transports.Start(ntcp2, ssu2); i2p::transport::transports.Start(ntcp2, ssu2);
if (i2p::transport::transports.IsBoundSSU2() || i2p::transport::transports.IsBoundNTCP2()) if (i2p::transport::transports.IsBoundSSU2() || i2p::transport::transports.IsBoundNTCP2())
LogPrint(eLogInfo, "Daemon: Transports started"); LogPrint(eLogInfo, "Daemon: Transports started");

4
libi2pd/NTCP2.cpp

@ -1490,7 +1490,7 @@ namespace transport
if (!ec) if (!ec)
{ {
LogPrint (eLogDebug, "NTCP2: Connected from ", ep); LogPrint (eLogDebug, "NTCP2: Connected from ", ep);
if (!i2p::util::net::IsInReservedRange(ep.address ())) if (!i2p::transport::transports.IsInReservedRange(ep.address ()))
{ {
if (m_PendingIncomingSessions.emplace (ep.address (), conn).second) if (m_PendingIncomingSessions.emplace (ep.address (), conn).second)
{ {
@ -1537,7 +1537,7 @@ namespace transport
if (!ec) if (!ec)
{ {
LogPrint (eLogDebug, "NTCP2: Connected from ", ep); LogPrint (eLogDebug, "NTCP2: Connected from ", ep);
if (!i2p::util::net::IsInReservedRange(ep.address ()) || if (!i2p::transport::transports.IsInReservedRange(ep.address ()) ||
i2p::util::net::IsYggdrasilAddress (ep.address ())) i2p::util::net::IsYggdrasilAddress (ep.address ()))
{ {
if (m_PendingIncomingSessions.emplace (ep.address (), conn).second) if (m_PendingIncomingSessions.emplace (ep.address (), conn).second)

24
libi2pd/Reseed.cpp

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2023, The PurpleI2P Project * Copyright (c) 2013-2024, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -687,18 +687,16 @@ namespace data
while (it != end) while (it != end)
{ {
boost::asio::ip::tcp::endpoint ep = *it; boost::asio::ip::tcp::endpoint ep = *it;
if ( bool supported = false;
( if (!ep.address ().is_unspecified ())
!i2p::util::net::IsInReservedRange(ep.address ()) && ( {
(ep.address ().is_v4 () && i2p::context.SupportsV4 ()) || if (ep.address ().is_v4 ())
(ep.address ().is_v6 () && i2p::context.SupportsV6 ()) supported = i2p::context.SupportsV4 ();
) else if (ep.address ().is_v6 ())
) || supported = i2p::util::net::IsYggdrasilAddress (ep.address ()) ?
( i2p::context.SupportsMesh () : i2p::context.SupportsV6 ();
i2p::util::net::IsYggdrasilAddress (ep.address ()) && }
i2p::context.SupportsMesh () if (supported)
)
)
{ {
s.lowest_layer().connect (ep, ecode); s.lowest_layer().connect (ep, ecode);
if (!ecode) if (!ecode)

5
libi2pd/RouterInfo.cpp

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2023, The PurpleI2P Project * Copyright (c) 2013-2024, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -21,6 +21,7 @@
#include "Base.h" #include "Base.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "Log.h" #include "Log.h"
#include "Transports.h"
#include "NetDb.hpp" #include "NetDb.hpp"
#include "RouterContext.h" #include "RouterContext.h"
#include "RouterInfo.h" #include "RouterInfo.h"
@ -253,7 +254,7 @@ namespace data
address->host = boost::asio::ip::address::from_string (value, ecode); address->host = boost::asio::ip::address::from_string (value, ecode);
if (!ecode && !address->host.is_unspecified ()) if (!ecode && !address->host.is_unspecified ())
{ {
if (!i2p::util::net::IsInReservedRange (address->host) || if (!i2p::transport::transports.IsInReservedRange (address->host) ||
i2p::util::net::IsYggdrasilAddress (address->host)) i2p::util::net::IsYggdrasilAddress (address->host))
isHost = true; isHost = true;
else else

8
libi2pd/SSU2.cpp

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022-2023, The PurpleI2P Project * Copyright (c) 2022-2024, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -566,7 +566,7 @@ namespace transport
else else
it1->second->ProcessRetry (buf, len); it1->second->ProcessRetry (buf, len);
} }
else if (!i2p::util::net::IsInReservedRange(senderEndpoint.address ()) && senderEndpoint.port ()) else if (!i2p::transport::transports.IsInReservedRange(senderEndpoint.address ()) && senderEndpoint.port ())
{ {
// assume new incoming session // assume new incoming session
auto session = std::make_shared<SSU2Session> (*this); auto session = std::make_shared<SSU2Session> (*this);
@ -666,7 +666,7 @@ namespace transport
bool isValidEndpoint = !address->host.is_unspecified () && address->port; bool isValidEndpoint = !address->host.is_unspecified () && address->port;
if (isValidEndpoint) if (isValidEndpoint)
{ {
if (i2p::util::net::IsInReservedRange(address->host)) return false; if (i2p::transport::transports.IsInReservedRange(address->host)) return false;
auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (address->host, address->port)); auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (address->host, address->port));
if (s) if (s)
{ {
@ -753,7 +753,7 @@ namespace transport
if (addr) if (addr)
{ {
bool isValidEndpoint = !addr->host.is_unspecified () && addr->port && bool isValidEndpoint = !addr->host.is_unspecified () && addr->port &&
!i2p::util::net::IsInReservedRange(addr->host); !i2p::transport::transports.IsInReservedRange(addr->host);
if (isValidEndpoint) if (isValidEndpoint)
{ {
auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (addr->host, addr->port)); auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (addr->host, addr->port));

4
libi2pd/SSU2Session.cpp

@ -1471,7 +1471,7 @@ namespace transport
ResendHandshakePacket (); // assume we receive ResendHandshakePacket (); // assume we receive
return; return;
} }
if (from != m_RemoteEndpoint && !i2p::util::net::IsInReservedRange (from.address ())) if (from != m_RemoteEndpoint && !i2p::transport::transports.IsInReservedRange (from.address ()))
{ {
LogPrint (eLogInfo, "SSU2: Remote endpoint update ", m_RemoteEndpoint, "->", from); LogPrint (eLogInfo, "SSU2: Remote endpoint update ", m_RemoteEndpoint, "->", from);
m_RemoteEndpoint = from; m_RemoteEndpoint = from;
@ -1753,7 +1753,7 @@ namespace transport
if (ExtractEndpoint (buf, len, ep)) if (ExtractEndpoint (buf, len, ep))
{ {
LogPrint (eLogInfo, "SSU2: Our external address is ", ep); LogPrint (eLogInfo, "SSU2: Our external address is ", ep);
if (!i2p::util::net::IsInReservedRange (ep.address ())) if (!i2p::transport::transports.IsInReservedRange (ep.address ()))
{ {
i2p::context.UpdateAddress (ep.address ()); i2p::context.UpdateAddress (ep.address ());
// check our port // check our port

13
libi2pd/Transports.cpp

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2023, The PurpleI2P Project * Copyright (c) 2013-2024, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -505,7 +505,7 @@ namespace transport
if (!m_NTCP2Server) continue; if (!m_NTCP2Server) continue;
std::shared_ptr<const RouterInfo::Address> address = (tr == i2p::data::RouterInfo::eNTCP2V6) ? std::shared_ptr<const RouterInfo::Address> address = (tr == i2p::data::RouterInfo::eNTCP2V6) ?
peer.router->GetPublishedNTCP2V6Address () : peer.router->GetPublishedNTCP2V4Address (); peer.router->GetPublishedNTCP2V6Address () : peer.router->GetPublishedNTCP2V4Address ();
if (address && m_CheckReserved && i2p::util::net::IsInReservedRange(address->host)) if (address && IsInReservedRange(address->host))
address = nullptr; address = nullptr;
if (address) if (address)
{ {
@ -524,7 +524,7 @@ namespace transport
if (!m_SSU2Server) continue; if (!m_SSU2Server) continue;
std::shared_ptr<const RouterInfo::Address> address = (tr == i2p::data::RouterInfo::eSSU2V6) ? std::shared_ptr<const RouterInfo::Address> address = (tr == i2p::data::RouterInfo::eSSU2V6) ?
peer.router->GetSSU2V6Address () : peer.router->GetSSU2V4Address (); peer.router->GetSSU2V6Address () : peer.router->GetSSU2V4Address ();
if (address && m_CheckReserved && i2p::util::net::IsInReservedRange(address->host)) if (address && IsInReservedRange(address->host))
address = nullptr; address = nullptr;
if (address && address->IsReachableSSU ()) if (address && address->IsReachableSSU ())
{ {
@ -1084,6 +1084,11 @@ namespace transport
} }
} }
bool Transports::IsInReservedRange (const boost::asio::ip::address& host) const
{
return IsCheckReserved () && i2p::util::net::IsInReservedRange (host);
}
void InitAddressFromIface () void InitAddressFromIface ()
{ {
bool ipv6; i2p::config::GetOption("ipv6", ipv6); bool ipv6; i2p::config::GetOption("ipv6", ipv6);
@ -1196,6 +1201,8 @@ namespace transport
i2p::context.PublishSSU2Address (ssu2port, false, ipv4, ipv6); // unpublish i2p::context.PublishSSU2Address (ssu2port, false, ipv4, ipv6); // unpublish
} }
bool checkReserved; i2p::config::GetOption("reservedrange", checkReserved);
transports.SetCheckReserved (checkReserved);
} }
} }
} }

5
libi2pd/Transports.h

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013-2023, The PurpleI2P Project * Copyright (c) 2013-2024, The PurpleI2P Project
* *
* This file is part of Purple i2pd project and licensed under BSD3 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -167,7 +167,8 @@ namespace transport
void PeerTest (bool ipv4 = true, bool ipv6 = true); void PeerTest (bool ipv4 = true, bool ipv6 = true);
void SetCheckReserved (bool check) { m_CheckReserved = check; }; void SetCheckReserved (bool check) { m_CheckReserved = check; };
bool IsCheckReserved () { return m_CheckReserved; }; bool IsCheckReserved () const { return m_CheckReserved; };
bool IsInReservedRange (const boost::asio::ip::address& host) const;
private: private:

Loading…
Cancel
Save