mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 04:02:15 +02:00
Implement opening /dev/net/ovpn via tun builder interface
Signed-off-by: Arne Schwabe <arne@openvpn.net>
This commit is contained in:
parent
913adc6807
commit
1e2d7b1c81
@ -325,6 +325,9 @@ namespace openvpn {
|
||||
if (dco)
|
||||
{
|
||||
DCO::TunConfig tunconf;
|
||||
#if defined(USE_TUN_BUILDER)
|
||||
dco->builder = config.builder;
|
||||
#endif
|
||||
tunconf.tun_prop.layer = layer;
|
||||
tunconf.tun_prop.session_name = session_name;
|
||||
if (tun_mtu)
|
||||
|
@ -197,14 +197,25 @@ namespace openvpn {
|
||||
devconf.dc.peer_lookup = OVPN_PEER_LOOKUP_NONE;
|
||||
devconf.dc.cpu_id = -1;
|
||||
|
||||
// create kovpn tun socket (implementation in kodevtun.hpp)
|
||||
impl.reset(new TunImpl(io_context,
|
||||
devconf,
|
||||
this,
|
||||
config->transport.frame,
|
||||
nullptr,
|
||||
nullptr));
|
||||
|
||||
/* We have a tun builder, we get the device from the
|
||||
* tun builder
|
||||
*/
|
||||
if (config->builder)
|
||||
{
|
||||
int fd = config->builder->tun_builder_open_kovpn(devconf);
|
||||
impl.reset (new TunImpl(io_context, fd, devconf.dc.dev_name,
|
||||
this, config->transport.frame));
|
||||
}
|
||||
else
|
||||
{
|
||||
// create kovpn tun socket (implementation in kodevtun.hpp)
|
||||
impl.reset (new TunImpl (io_context,
|
||||
devconf,
|
||||
this,
|
||||
config->transport.frame,
|
||||
nullptr,
|
||||
nullptr));
|
||||
}
|
||||
// set kovpn stats hook
|
||||
config->transport.stats->dco_configure(this);
|
||||
|
||||
|
@ -313,6 +313,18 @@ namespace openvpn {
|
||||
Base::stream = new openvpn_io::posix::stream_descriptor(io_context, fd.release());
|
||||
}
|
||||
|
||||
// variant that is used when tun builder is in use
|
||||
TunClient(openvpn_io::io_context& io_context,
|
||||
const int kovpnfd,
|
||||
std::string dev_name,
|
||||
ReadHandler read_handler,
|
||||
const Frame::Ptr& frame)
|
||||
: Base(read_handler, frame, SessionStats::Ptr())
|
||||
{
|
||||
Base::name_ = dev_name;
|
||||
Base::stream = new openvpn_io::posix::stream_descriptor(io_context, kovpnfd);
|
||||
}
|
||||
|
||||
// Attach UDP socket to ovpn instance
|
||||
void socket_attach_udp(const int sock_fd)
|
||||
{
|
||||
|
@ -65,8 +65,11 @@ namespace openvpn {
|
||||
Stop* stop = nullptr;
|
||||
};
|
||||
|
||||
|
||||
virtual TunClientFactory::Ptr new_tun_factory(const TunConfig& conf, const OptionList& opt) = 0;
|
||||
virtual TransportClientFactory::Ptr new_transport_factory(const TransportConfig& conf) = 0;
|
||||
|
||||
TunBuilderBase* builder = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,9 @@
|
||||
#define OPENVPN_TUN_BUILDER_BASE_H
|
||||
|
||||
#include <string>
|
||||
#if defined(ENABLE_DCO)
|
||||
#include <openvpn/kovpn/kovpn_devconf.hpp>
|
||||
#endif
|
||||
|
||||
namespace openvpn {
|
||||
class TunBuilderBase
|
||||
@ -248,6 +251,17 @@ namespace openvpn {
|
||||
virtual void tun_builder_teardown(bool disconnect) {}
|
||||
|
||||
virtual ~TunBuilderBase() {}
|
||||
#if defined(ENABLE_DCO)
|
||||
/**
|
||||
* Opens the kovpn device to use for the DCOTransport
|
||||
* @param devconf Parameters for opening device, will be overwritten with the return values
|
||||
* @return file descriptor of the opened device (/dev/net/ovpn)
|
||||
*/
|
||||
virtual int tun_builder_open_kovpn(KoTun::DevConf& devconf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user