Browse Source

detect MTU for some known ipv6 tunnel brokers

pull/1776/head
orignal 2 years ago
parent
commit
014e4b0e1d
  1. 4
      libi2pd/RouterContext.cpp
  2. 20
      libi2pd/util.cpp
  3. 3
      libi2pd/util.h

4
libi2pd/RouterContext.cpp

@ -428,13 +428,13 @@ namespace i2p @@ -428,13 +428,13 @@ namespace i2p
if (mtu)
{
LogPrint (eLogDebug, "Router: Our v6 MTU=", mtu);
int maxMTU = address->IsSSU2 () ? 1500 : 1488; // must be multiple of 16 for SSU1
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");
}
else if (mtu && !address->IsSSU2 ()) // SSU1
if (mtu && !address->IsSSU2 ()) // SSU1
mtu = (mtu >> 4) << 4; // round to multiple of 16
if (address->ssu) address->ssu->mtu = mtu;
}

20
libi2pd/util.cpp

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
#include "util.h"
#include "Log.h"
#include "I2PEndian.h"
#if not defined (__FreeBSD__)
#include <pthread.h>
@ -423,6 +424,25 @@ namespace net @@ -423,6 +424,25 @@ namespace net
#endif
}
int GetMaxMTU (const boost::asio::ip::address_v6& localAddress)
{
uint32_t prefix = bufbe32toh (localAddress.to_bytes ().data ());
switch (prefix)
{
case 0x20010470:
case 0x260070ff:
// Hurricane Electric
return 1480;
break;
case 0x2a06a004:
// route48
return 1420;
break;
default: ;
}
return 1500;
}
static bool IsYggdrasilAddress (const uint8_t addr[16])
{
return addr[0] == 0x02 || addr[0] == 0x03;

3
libi2pd/util.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2021, The PurpleI2P Project
* Copyright (c) 2013-2022, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -218,6 +218,7 @@ namespace util @@ -218,6 +218,7 @@ namespace util
namespace net
{
int GetMTU (const boost::asio::ip::address& localAddress);
int GetMaxMTU (const boost::asio::ip::address_v6& localAddress); // check tunnel broker for ipv6 address
const boost::asio::ip::address GetInterfaceAddress (const std::string & ifname, bool ipv6=false);
boost::asio::ip::address_v6 GetYggdrasilAddress ();
bool IsLocalAddress (const boost::asio::ip::address& addr);

Loading…
Cancel
Save