mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-08-27 10:40:23 +01:00
create unique loopback address for ipv6
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / trixie (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / trixie (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
This commit is contained in:
parent
a2073a8751
commit
310ee78d24
1 changed files with 27 additions and 8 deletions
|
@ -81,14 +81,26 @@ namespace client
|
||||||
return ourIP;
|
return ourIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::asio::ip::address GetLoopbackAddress6For(const i2p::data::IdentHash & addr)
|
||||||
|
{
|
||||||
|
boost::asio::ip::address_v6::bytes_type bytes;
|
||||||
|
const uint8_t * ident = addr;
|
||||||
|
bytes[0] = 0xfd;
|
||||||
|
memcpy (bytes.data ()+1, ident, 15);
|
||||||
|
boost::asio::ip::address ourIP = boost::asio::ip::address_v6 (bytes);
|
||||||
|
return ourIP;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
static void MapToLoopback(std::shared_ptr<boost::asio::ip::tcp::socket> sock, const i2p::data::IdentHash & addr)
|
static void MapToLoopback(std::shared_ptr<boost::asio::ip::tcp::socket> sock, const i2p::data::IdentHash & addr, bool isV4)
|
||||||
{
|
{
|
||||||
if (sock)
|
if (sock)
|
||||||
{
|
{
|
||||||
// bind to 127.x.x.x address
|
// bind to 127.x.x.x address for ipv4
|
||||||
// where x.x.x are first three bytes from ident
|
// where x.x.x are first three bytes from ident
|
||||||
auto ourIP = GetLoopbackAddressFor(addr);
|
// bind to fdxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx address for ipv6
|
||||||
|
// where xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx are first 15 bytes from ident
|
||||||
|
auto ourIP = isV4 ? GetLoopbackAddressFor(addr) : GetLoopbackAddress6For(addr);
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
sock->bind (boost::asio::ip::tcp::endpoint (ourIP, 0), ec);
|
sock->bind (boost::asio::ip::tcp::endpoint (ourIP, 0), ec);
|
||||||
if (ec)
|
if (ec)
|
||||||
|
@ -103,12 +115,19 @@ namespace client
|
||||||
{
|
{
|
||||||
I2PTunnelSetSocketOptions (m_Socket);
|
I2PTunnelSetSocketOptions (m_Socket);
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (isUniqueLocal && m_RemoteEndpoint.address ().is_v4 () &&
|
if (isUniqueLocal && m_RemoteEndpoint.address ().is_loopback ())
|
||||||
m_RemoteEndpoint.address ().to_v4 ().to_bytes ()[0] == 127)
|
{
|
||||||
|
auto ident = m_Stream->GetRemoteIdentity()->GetIdentHash();
|
||||||
|
if (m_RemoteEndpoint.address ().is_v4 ())
|
||||||
{
|
{
|
||||||
m_Socket->open (boost::asio::ip::tcp::v4 ());
|
m_Socket->open (boost::asio::ip::tcp::v4 ());
|
||||||
auto ident = m_Stream->GetRemoteIdentity()->GetIdentHash();
|
MapToLoopback(m_Socket, ident, true);
|
||||||
MapToLoopback(m_Socket, ident);
|
}
|
||||||
|
else if (m_RemoteEndpoint.address ().is_v6 ())
|
||||||
|
{
|
||||||
|
m_Socket->open (boost::asio::ip::tcp::v6 ());
|
||||||
|
MapToLoopback(m_Socket, ident, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
m_Socket->async_connect (m_RemoteEndpoint, std::bind (&I2PTunnelConnection::HandleConnect,
|
m_Socket->async_connect (m_RemoteEndpoint, std::bind (&I2PTunnelConnection::HandleConnect,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue