mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
4c630e0437
- Previous android java and jni code updated to work, but with much love still needed to make it work nicely, e.g. handling when the VPN is turned off. - DNS handling refactored to allow android to intercept and handle DNS requests as we can't set the system DNS to use a high port (and apparently Chrome ignores system DNS settings anyway) - add packet router structure to allow separate handling of specific intercepted traffic, e.g. UDP traffic to port 53 gets handled by our DNS handler rather than being naively forwarded as exit traffic. - For now, android lokinet is exit-only and hard-coded to use exit.loki as its exit. The exit will be configurable before release, but allowing to not use exit-only mode is more of a challenge. - some old gitignore remnants which were matching to things we don't want them to (and are no longer relevant) removed - some minor changes to CI configuration
85 lines
1.6 KiB
C++
85 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
#include <ev/vpn.hpp>
|
|
#include <vpn/common.hpp>
|
|
#include <llarp.hpp>
|
|
|
|
namespace llarp::vpn
|
|
{
|
|
class AndroidInterface : public NetworkInterface
|
|
{
|
|
const int m_fd;
|
|
const InterfaceInfo m_Info; // likely 100% ignored on android, at least for now
|
|
|
|
public:
|
|
AndroidInterface(InterfaceInfo info, int fd) : m_fd(fd), m_Info(info)
|
|
{
|
|
if (m_fd == -1)
|
|
throw std::runtime_error(
|
|
"Error opening AndroidVPN layer FD: " + std::string{strerror(errno)});
|
|
}
|
|
|
|
virtual ~AndroidInterface()
|
|
{
|
|
if (m_fd != -1)
|
|
::close(m_fd);
|
|
}
|
|
|
|
int
|
|
PollFD() const override
|
|
{
|
|
return m_fd;
|
|
}
|
|
|
|
net::IPPacket
|
|
ReadNextPacket() override
|
|
{
|
|
net::IPPacket pkt;
|
|
const auto sz = read(m_fd, pkt.buf, sizeof(pkt.buf));
|
|
if (sz >= 0)
|
|
pkt.sz = std::min(sz, ssize_t{sizeof(pkt.buf)});
|
|
return pkt;
|
|
}
|
|
|
|
bool
|
|
WritePacket(net::IPPacket pkt) override
|
|
{
|
|
const auto sz = write(m_fd, pkt.buf, pkt.sz);
|
|
if (sz <= 0)
|
|
return false;
|
|
return sz == static_cast<ssize_t>(pkt.sz);
|
|
}
|
|
|
|
bool
|
|
HasNextPacket() override
|
|
{
|
|
return false;
|
|
}
|
|
|
|
std::string
|
|
IfName() const override
|
|
{
|
|
return m_Info.ifname;
|
|
}
|
|
};
|
|
|
|
class AndroidPlatform : public Platform
|
|
{
|
|
const int fd;
|
|
|
|
public:
|
|
AndroidPlatform(llarp::Context* ctx) : fd(ctx->androidFD)
|
|
{}
|
|
|
|
std::shared_ptr<NetworkInterface>
|
|
ObtainInterface(InterfaceInfo info) override
|
|
{
|
|
return std::make_shared<AndroidInterface>(std::move(info), fd);
|
|
}
|
|
};
|
|
|
|
} // namespace llarp::vpn
|