-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fall back to null vpn platform when we have no implementation for the…
… current target
- Loading branch information
1 parent
e338597
commit 4c16a37
Showing
2 changed files
with
105 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#pragma once | ||
#include <llarp/ev/vpn.hpp> | ||
#include <unistd.h> | ||
|
||
namespace llarp::vpn | ||
{ | ||
class NullInterface : public NetworkInterface | ||
{ | ||
/// we use a pipe because it isnt going to poll itself | ||
int m_pipe[2]; | ||
|
||
public: | ||
NullInterface() | ||
{ | ||
::pipe(m_pipe); | ||
} | ||
|
||
virtual ~NullInterface() | ||
{ | ||
::close(m_pipe[1]); | ||
::close(m_pipe[0]); | ||
} | ||
|
||
int | ||
PollFD() const override | ||
{ | ||
return m_pipe[0]; | ||
} | ||
|
||
/// the interface's name | ||
std::string | ||
IfName() const override | ||
{ | ||
return ""; | ||
} | ||
|
||
net::IPPacket | ||
ReadNextPacket() override | ||
{ | ||
return net::IPPacket{}; | ||
} | ||
|
||
/// write a packet to the interface | ||
/// returns false if we dropped it | ||
bool WritePacket(net::IPPacket) override | ||
{ | ||
return true; | ||
} | ||
}; | ||
|
||
class NopRouteManager : public IRouteManager | ||
{ | ||
public: | ||
void AddRoute(IPVariant_t, IPVariant_t) override{}; | ||
|
||
void DelRoute(IPVariant_t, IPVariant_t) override{}; | ||
|
||
void AddDefaultRouteViaInterface(std::string) override{}; | ||
|
||
void DelDefaultRouteViaInterface(std::string) override{}; | ||
|
||
void | ||
AddRouteViaInterface(NetworkInterface&, IPRange) override{}; | ||
|
||
void | ||
DelRouteViaInterface(NetworkInterface&, IPRange) override{}; | ||
|
||
std::vector<IPVariant_t> GetGatewaysNotOnInterface(std::string) override | ||
{ | ||
return {}; | ||
} | ||
}; | ||
|
||
class NullPlatform : public Platform | ||
{ | ||
NopRouteManager _routes; | ||
|
||
public: | ||
NullPlatform() : Platform{}, _routes{} | ||
{} | ||
|
||
virtual ~NullPlatform() = default; | ||
|
||
std::shared_ptr<NetworkInterface> | ||
ObtainInterface(InterfaceInfo, AbstractRouter*) | ||
{ | ||
return std::static_pointer_cast<NetworkInterface>(std::make_shared<NullInterface>()); | ||
} | ||
|
||
IRouteManager& | ||
RouteManager() override | ||
{ | ||
return _routes; | ||
} | ||
}; | ||
} // namespace llarp::vpn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters