2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2018-12-12 02:15:08 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/service/endpoint.hpp>
|
2021-03-27 18:54:09 +00:00
|
|
|
#include <llarp/service/protocol_type.hpp>
|
|
|
|
#include <llarp/quic/tunnel.hpp>
|
|
|
|
#include <llarp/router/abstractrouter.hpp>
|
|
|
|
#include <llarp/ev/ev.hpp>
|
2021-09-23 18:01:04 +00:00
|
|
|
#include <llarp/vpn/egres_packet_router.hpp>
|
2018-11-29 13:12:35 +00:00
|
|
|
|
2021-09-23 18:01:04 +00:00
|
|
|
namespace llarp::handlers
|
2018-11-29 13:12:35 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
struct NullEndpoint final : public llarp::service::Endpoint,
|
|
|
|
public std::enable_shared_from_this<NullEndpoint>
|
2018-11-29 13:12:35 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
NullEndpoint(AbstractRouter* r, llarp::service::Context* parent)
|
|
|
|
: llarp::service::Endpoint{r, parent}
|
2021-09-30 17:17:06 +00:00
|
|
|
, m_PacketRouter{new vpn::EgresPacketRouter{[](auto from, auto pkt) {
|
|
|
|
var::visit(
|
|
|
|
[&pkt](auto&& from) {
|
|
|
|
LogError("unhandled traffic from: ", from, " of ", pkt.sz, " bytes");
|
|
|
|
},
|
|
|
|
from);
|
|
|
|
}}}
|
2018-11-29 13:12:35 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
r->loop()->add_ticker([this] { Pump(Now()); });
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
HandleInboundPacket(
|
|
|
|
const service::ConvoTag tag,
|
|
|
|
const llarp_buffer_t& buf,
|
|
|
|
service::ProtocolType t,
|
|
|
|
uint64_t) override
|
|
|
|
{
|
|
|
|
LogTrace("Inbound ", t, " packet (", buf.sz, "B) on convo ", tag);
|
|
|
|
if (t == service::ProtocolType::Control)
|
2021-03-27 18:54:09 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
return true;
|
2021-03-27 18:54:09 +00:00
|
|
|
}
|
2021-09-23 18:01:04 +00:00
|
|
|
if (t == service::ProtocolType::TrafficV4 or t == service::ProtocolType::TrafficV6)
|
2018-11-29 13:12:35 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
if (auto from = GetEndpointWithConvoTag(tag))
|
2021-03-31 17:09:34 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
net::IPPacket pkt{};
|
|
|
|
if (not pkt.Load(buf))
|
|
|
|
{
|
|
|
|
LogWarn("invalid ip packet from remote T=", tag);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_PacketRouter->HandleIPPacketFrom(std::move(*from), std::move(pkt));
|
2021-03-29 16:31:55 +00:00
|
|
|
return true;
|
2021-03-31 17:09:34 +00:00
|
|
|
}
|
2021-09-23 18:01:04 +00:00
|
|
|
else
|
2021-03-27 18:54:09 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
LogWarn("did not handle packet, no endpoint with convotag T=", tag);
|
2021-03-27 18:54:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-11-29 13:12:35 +00:00
|
|
|
}
|
2021-09-23 18:01:04 +00:00
|
|
|
if (t != service::ProtocolType::QUIC)
|
|
|
|
return false;
|
2018-11-29 13:12:35 +00:00
|
|
|
|
2021-09-23 18:01:04 +00:00
|
|
|
auto* quic = GetQUICTunnel();
|
|
|
|
if (!quic)
|
2020-08-21 15:07:37 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
LogWarn("incoming quic packet but this endpoint is not quic capable; dropping");
|
|
|
|
return false;
|
2020-08-21 15:07:37 +00:00
|
|
|
}
|
2021-09-23 18:01:04 +00:00
|
|
|
if (buf.sz < 4)
|
2019-04-23 16:13:22 +00:00
|
|
|
{
|
2021-09-23 18:01:04 +00:00
|
|
|
LogWarn("invalid incoming quic packet, dropping");
|
|
|
|
return false;
|
2019-04-23 16:13:22 +00:00
|
|
|
}
|
2021-09-23 18:01:04 +00:00
|
|
|
quic->receive_packet(tag, buf);
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-23 16:13:22 +00:00
|
|
|
|
2021-09-23 18:01:04 +00:00
|
|
|
std::string
|
|
|
|
GetIfName() const override
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
2021-06-04 12:34:41 +00:00
|
|
|
|
2021-09-23 18:01:04 +00:00
|
|
|
path::PathSet_ptr
|
|
|
|
GetSelf() override
|
|
|
|
{
|
|
|
|
return shared_from_this();
|
|
|
|
}
|
2020-05-21 14:18:23 +00:00
|
|
|
|
2021-09-23 18:01:04 +00:00
|
|
|
std::weak_ptr<path::PathSet>
|
|
|
|
GetWeak() override
|
|
|
|
{
|
|
|
|
return weak_from_this();
|
|
|
|
}
|
2020-08-20 12:59:01 +00:00
|
|
|
|
2021-09-23 18:01:04 +00:00
|
|
|
bool
|
|
|
|
SupportsV6() const override
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-15 16:01:19 +00:00
|
|
|
|
2021-09-23 18:01:04 +00:00
|
|
|
void
|
|
|
|
SendPacketToRemote(const llarp_buffer_t&, service::ProtocolType) override{};
|
|
|
|
|
|
|
|
huint128_t ObtainIPForAddr(std::variant<service::Address, RouterID>) override
|
|
|
|
{
|
|
|
|
return {0};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<std::variant<service::Address, RouterID>> ObtainAddrForIP(
|
|
|
|
huint128_t) const override
|
|
|
|
{
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
vpn::EgresPacketRouter*
|
|
|
|
EgresPacketRouter() override
|
|
|
|
{
|
|
|
|
return m_PacketRouter.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<vpn::EgresPacketRouter> m_PacketRouter;
|
|
|
|
};
|
|
|
|
} // namespace llarp::handlers
|