Browse Source

check local address

pull/1634/head
orignal 4 years ago
parent
commit
a74f685a5d
  1. 3
      daemon/Daemon.cpp
  2. 11
      libi2pd/util.cpp
  3. 1
      libi2pd/util.h

3
daemon/Daemon.cpp

@ -152,7 +152,8 @@ namespace i2p
if (!yggaddress.empty ()) if (!yggaddress.empty ())
{ {
yggaddr = boost::asio::ip::address_v6::from_string (yggaddress); yggaddr = boost::asio::ip::address_v6::from_string (yggaddress);
if (yggaddr.is_unspecified () || i2p::util::net::GetMTU (yggaddr) != 0xFFFF) // ygg's MTU is always 65535 if (yggaddr.is_unspecified () || !i2p::util::net::IsYggdrasilAddress (yggaddr) ||
!i2p::util::net::IsLocalAddress (yggaddr))
{ {
LogPrint(eLogWarning, "Daemon: Can't find Yggdrasil address ", yggaddress); LogPrint(eLogWarning, "Daemon: Can't find Yggdrasil address ", yggaddress);
ygg = false; ygg = false;

11
libi2pd/util.cpp

@ -461,6 +461,17 @@ namespace net
#endif #endif
} }
bool IsLocalAddress (const boost::asio::ip::address& addr)
{
auto mtu = // TODO: implement better
#ifdef _WIN32
GetMTUWindows(addr, 0);
#else
GetMTUUnix(addr, 0);
#endif
return mtu > 0;
}
bool IsInReservedRange (const boost::asio::ip::address& host) bool IsInReservedRange (const boost::asio::ip::address& host)
{ {
// https://en.wikipedia.org/wiki/Reserved_IP_addresses // https://en.wikipedia.org/wiki/Reserved_IP_addresses

1
libi2pd/util.h

@ -189,6 +189,7 @@ namespace util
int GetMTU (const boost::asio::ip::address& localAddress); int GetMTU (const boost::asio::ip::address& localAddress);
const boost::asio::ip::address GetInterfaceAddress (const std::string & ifname, bool ipv6=false); const boost::asio::ip::address GetInterfaceAddress (const std::string & ifname, bool ipv6=false);
boost::asio::ip::address_v6 GetYggdrasilAddress (); boost::asio::ip::address_v6 GetYggdrasilAddress ();
bool IsLocalAddress (const boost::asio::ip::address& addr);
bool IsInReservedRange (const boost::asio::ip::address& host); bool IsInReservedRange (const boost::asio::ip::address& host);
bool IsYggdrasilAddress (const boost::asio::ip::address& addr); bool IsYggdrasilAddress (const boost::asio::ip::address& addr);
} }

Loading…
Cancel
Save