2021-08-25 23:28:58 +00:00
|
|
|
|
|
|
|
#include "vpn_interface.hpp"
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2021-08-25 23:28:58 +00:00
|
|
|
#include "context.hpp"
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
#include <llarp/router/router.hpp>
|
2021-08-25 23:28:58 +00:00
|
|
|
|
|
|
|
namespace llarp::apple
|
|
|
|
{
|
|
|
|
VPNInterface::VPNInterface(
|
2021-12-07 16:17:20 +00:00
|
|
|
Context& ctx,
|
|
|
|
packet_write_callback packet_writer,
|
|
|
|
on_readable_callback on_readable,
|
2023-09-15 14:55:32 +00:00
|
|
|
Router* router)
|
2022-09-15 21:30:33 +00:00
|
|
|
: vpn::NetworkInterface{{}}
|
|
|
|
, m_PacketWriter{std::move(packet_writer)}
|
2021-12-07 16:17:20 +00:00
|
|
|
, m_OnReadable{std::move(on_readable)}
|
|
|
|
, _router{router}
|
2021-08-25 23:28:58 +00:00
|
|
|
{
|
|
|
|
ctx.loop->call_soon([this] { m_OnReadable(*this); });
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VPNInterface::OfferReadPacket(const llarp_buffer_t& buf)
|
|
|
|
{
|
|
|
|
llarp::net::IPPacket pkt;
|
|
|
|
if (!pkt.Load(buf))
|
|
|
|
return false;
|
|
|
|
m_ReadQueue.tryPushBack(std::move(pkt));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-07 16:17:20 +00:00
|
|
|
void
|
|
|
|
VPNInterface::MaybeWakeUpperLayers() const
|
|
|
|
{
|
|
|
|
_router->TriggerPump();
|
|
|
|
}
|
|
|
|
|
2021-08-25 23:28:58 +00:00
|
|
|
int
|
|
|
|
VPNInterface::PollFD() const
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
net::IPPacket
|
|
|
|
VPNInterface::ReadNextPacket()
|
|
|
|
{
|
|
|
|
net::IPPacket pkt{};
|
|
|
|
if (not m_ReadQueue.empty())
|
|
|
|
pkt = m_ReadQueue.popFront();
|
|
|
|
return pkt;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VPNInterface::WritePacket(net::IPPacket pkt)
|
|
|
|
{
|
|
|
|
int af_family = pkt.IsV6() ? AF_INET6 : AF_INET;
|
2022-09-15 21:30:33 +00:00
|
|
|
return m_PacketWriter(af_family, pkt.data(), pkt.size());
|
2021-08-25 23:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace llarp::apple
|