|
|
@ -141,6 +141,20 @@ namespace llarp
|
|
|
|
return Endpoint::SetOption(k, v);
|
|
|
|
return Endpoint::SetOption(k, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
|
|
TunEndpoint::HasLocalIP(const huint32_t &ip) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return m_IPToAddr.find(ip) != m_IPToAddr.end();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
|
|
TunEndpoint::QueueOutboundTraffic(llarp::net::IPv4Packet &&pkt)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return m_NetworkToUserPktQueue.EmplaceIf(
|
|
|
|
|
|
|
|
[](llarp::net::IPv4Packet &) -> bool { return true; },
|
|
|
|
|
|
|
|
std::move(pkt));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
TunEndpoint::MapAddress(const service::Address &addr, huint32_t ip)
|
|
|
|
TunEndpoint::MapAddress(const service::Address &addr, huint32_t ip)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -148,13 +162,14 @@ namespace llarp
|
|
|
|
if(itr != m_IPToAddr.end())
|
|
|
|
if(itr != m_IPToAddr.end())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// XXX is calling inet_ntoa safe in this context? it's MP-unsafe
|
|
|
|
// XXX is calling inet_ntoa safe in this context? it's MP-unsafe
|
|
|
|
llarp::LogWarn(ip, " already mapped to ", itr->second.ToString());
|
|
|
|
llarp::LogWarn(ip, " already mapped to ",
|
|
|
|
|
|
|
|
service::Address(itr->second).ToString());
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
llarp::LogInfo(Name() + " map ", addr.ToString(), " to ", ip);
|
|
|
|
llarp::LogInfo(Name() + " map ", addr.ToString(), " to ", ip);
|
|
|
|
|
|
|
|
|
|
|
|
m_IPToAddr.insert(std::make_pair(ip, addr));
|
|
|
|
m_IPToAddr.insert(std::make_pair(ip, addr.data()));
|
|
|
|
m_AddrToIP.insert(std::make_pair(addr, ip));
|
|
|
|
m_AddrToIP.insert(std::make_pair(addr.data(), ip));
|
|
|
|
MarkIPActiveForever(ip);
|
|
|
|
MarkIPActiveForever(ip);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -331,7 +346,8 @@ namespace llarp
|
|
|
|
// this includes clearing IP addresses, recalculating checksums, etc
|
|
|
|
// this includes clearing IP addresses, recalculating checksums, etc
|
|
|
|
pkt.UpdateIPv4PacketOnSrc();
|
|
|
|
pkt.UpdateIPv4PacketOnSrc();
|
|
|
|
|
|
|
|
|
|
|
|
if(!SendToOrQueue(itr->second, pkt.Buffer(), service::eProtocolTraffic))
|
|
|
|
if(!SendToOrQueue(itr->second.data(), pkt.Buffer(),
|
|
|
|
|
|
|
|
service::eProtocolTraffic))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
llarp::LogWarn(Name(), " did not flush packets");
|
|
|
|
llarp::LogWarn(Name(), " did not flush packets");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -343,7 +359,7 @@ namespace llarp
|
|
|
|
TunEndpoint::ProcessDataMessage(service::ProtocolMessage *msg)
|
|
|
|
TunEndpoint::ProcessDataMessage(service::ProtocolMessage *msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// llarp::LogInfo("got packet from ", msg->sender.Addr());
|
|
|
|
// llarp::LogInfo("got packet from ", msg->sender.Addr());
|
|
|
|
auto themIP = ObtainIPForAddr(msg->sender.Addr());
|
|
|
|
auto themIP = ObtainIPForAddr(msg->sender.Addr().data());
|
|
|
|
// llarp::LogInfo("themIP ", themIP);
|
|
|
|
// llarp::LogInfo("themIP ", themIP);
|
|
|
|
auto usIP = m_OurIP;
|
|
|
|
auto usIP = m_OurIP;
|
|
|
|
auto buf = llarp::Buffer(msg->payload);
|
|
|
|
auto buf = llarp::Buffer(msg->payload);
|
|
|
@ -376,23 +392,14 @@ namespace llarp
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
service::Address
|
|
|
|
huint32_t
|
|
|
|
TunEndpoint::ObtainAddrForIP(huint32_t ip)
|
|
|
|
TunEndpoint::GetIfAddr() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto itr = m_IPToAddr.find(ip);
|
|
|
|
return m_OurIP;
|
|
|
|
if(itr == m_IPToAddr.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// not found
|
|
|
|
|
|
|
|
service::Address addr;
|
|
|
|
|
|
|
|
llarp::LogWarn(ip, " not found in tun map. Sending ", addr.ToString());
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// found
|
|
|
|
|
|
|
|
return itr->second;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
huint32_t
|
|
|
|
huint32_t
|
|
|
|
TunEndpoint::ObtainIPForAddr(const service::Address &addr)
|
|
|
|
TunEndpoint::ObtainIPForAddr(const byte_t *addr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
llarp_time_t now = Now();
|
|
|
|
llarp_time_t now = Now();
|
|
|
|
huint32_t nextIP = {0};
|
|
|
|
huint32_t nextIP = {0};
|
|
|
|