|
|
|
@ -41,7 +41,7 @@ namespace llarp
|
|
|
|
|
llarp::LogError(Name(), " bad exit router key: ", v);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
m_Exit.reset(new llarp::exit::BaseSession(
|
|
|
|
|
m_Exit.reset(new llarp::exit::ExitSession(
|
|
|
|
|
exitRouter,
|
|
|
|
|
std::bind(&TunEndpoint::QueueInboundPacketForExit, this,
|
|
|
|
|
std::placeholders::_1),
|
|
|
|
@ -344,6 +344,7 @@ namespace llarp
|
|
|
|
|
TunEndpoint::FlushSend()
|
|
|
|
|
{
|
|
|
|
|
m_UserToNetworkPktQueue.Process([&](net::IPv4Packet &pkt) {
|
|
|
|
|
std::function<bool(llarp_buffer_t)> sendFunc;
|
|
|
|
|
auto itr = m_IPToAddr.find(pkt.dst());
|
|
|
|
|
if(itr == m_IPToAddr.end())
|
|
|
|
|
{
|
|
|
|
@ -351,21 +352,30 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
pkt.UpdateIPv4PacketOnDst({0}, pkt.dst());
|
|
|
|
|
m_Exit->QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
llarp::LogWarn(Name(), " has no endpoint for ", pkt.dst());
|
|
|
|
|
return true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(m_SNodes.at(itr->second))
|
|
|
|
|
{
|
|
|
|
|
sendFunc = std::bind(&TunEndpoint::SendToSNodeOrQueue, this, itr->second.data(), std::placeholders::_1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendFunc = std::bind(&TunEndpoint::SendToServiceOrQueue, this, itr->second.data(), std::placeholders::_1, service::eProtocolTraffic);
|
|
|
|
|
}
|
|
|
|
|
// prepare packet for insertion into network
|
|
|
|
|
// this includes clearing IP addresses, recalculating checksums, etc
|
|
|
|
|
pkt.UpdateIPv4PacketOnSrc();
|
|
|
|
|
|
|
|
|
|
if(!SendToOrQueue(itr->second.data(), pkt.Buffer(),
|
|
|
|
|
service::eProtocolTraffic))
|
|
|
|
|
{
|
|
|
|
|
llarp::LogWarn(Name(), " did not flush packets");
|
|
|
|
|
}
|
|
|
|
|
if(sendFunc && sendFunc(pkt.Buffer()))
|
|
|
|
|
return true;
|
|
|
|
|
llarp::LogWarn(Name(), " did not flush packets");
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
if(m_Exit)
|
|
|
|
@ -373,14 +383,13 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
TunEndpoint::ProcessDataMessage(service::ProtocolMessage *msg)
|
|
|
|
|
TunEndpoint::HandleWriteIPPacket(llarp_buffer_t buf, std::function<huint32_t(void)> getFromIP)
|
|
|
|
|
{
|
|
|
|
|
// llarp::LogInfo("got packet from ", msg->sender.Addr());
|
|
|
|
|
auto themIP = ObtainIPForAddr(msg->sender.Addr().data());
|
|
|
|
|
auto themIP = getFromIP();
|
|
|
|
|
// llarp::LogInfo("themIP ", themIP);
|
|
|
|
|
auto usIP = m_OurIP;
|
|
|
|
|
auto buf = llarp::Buffer(msg->payload);
|
|
|
|
|
if(m_NetworkToUserPktQueue.EmplaceIf(
|
|
|
|
|
return m_NetworkToUserPktQueue.EmplaceIf(
|
|
|
|
|
[buf, themIP, usIP](net::IPv4Packet &pkt) -> bool {
|
|
|
|
|
// load
|
|
|
|
|
if(!pkt.Load(buf))
|
|
|
|
@ -402,11 +411,7 @@ namespace llarp
|
|
|
|
|
// update packet to use proper addresses, recalc checksums
|
|
|
|
|
pkt.UpdateIPv4PacketOnDst(themIP, usIP);
|
|
|
|
|
return true;
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
llarp::LogDebug(Name(), " handle data message ", msg->payload.size(),
|
|
|
|
|
" bytes from ", themIP);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
huint32_t
|
|
|
|
@ -416,7 +421,7 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
huint32_t
|
|
|
|
|
TunEndpoint::ObtainIPForAddr(const byte_t *a)
|
|
|
|
|
TunEndpoint::ObtainIPForAddr(const byte_t *a, bool snode)
|
|
|
|
|
{
|
|
|
|
|
llarp_time_t now = Now();
|
|
|
|
|
huint32_t nextIP = {0};
|
|
|
|
@ -443,6 +448,7 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
m_AddrToIP[ident] = nextIP;
|
|
|
|
|
m_IPToAddr[nextIP] = ident;
|
|
|
|
|
m_SNodes[ident] = snode;
|
|
|
|
|
llarp::LogInfo(Name(), " mapped ", ident, " to ", nextIP);
|
|
|
|
|
MarkIPActive(nextIP);
|
|
|
|
|
return nextIP;
|
|
|
|
@ -471,6 +477,7 @@ namespace llarp
|
|
|
|
|
// remap address
|
|
|
|
|
m_IPToAddr[oldest.first] = ident;
|
|
|
|
|
m_AddrToIP[ident] = oldest.first;
|
|
|
|
|
m_SNodes[ident] = snode;
|
|
|
|
|
nextIP = oldest.first;
|
|
|
|
|
|
|
|
|
|
// mark ip active
|
|
|
|
|