diff --git a/openvpn/client/cliopt.hpp b/openvpn/client/cliopt.hpp index 93e8e18c..f743a8d5 100644 --- a/openvpn/client/cliopt.hpp +++ b/openvpn/client/cliopt.hpp @@ -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) diff --git a/openvpn/dco/dcocli.hpp b/openvpn/dco/dcocli.hpp index c026c98e..23f2db78 100644 --- a/openvpn/dco/dcocli.hpp +++ b/openvpn/dco/dcocli.hpp @@ -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); diff --git a/openvpn/kovpn/kodev.hpp b/openvpn/kovpn/kodev.hpp index c2b93c74..7c5cdb58 100644 --- a/openvpn/kovpn/kodev.hpp +++ b/openvpn/kovpn/kodev.hpp @@ -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) { diff --git a/openvpn/transport/dco.hpp b/openvpn/transport/dco.hpp index c554952d..e2b656d4 100644 --- a/openvpn/transport/dco.hpp +++ b/openvpn/transport/dco.hpp @@ -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; }; } diff --git a/openvpn/tun/builder/base.hpp b/openvpn/tun/builder/base.hpp index fc875998..11ca3c8a 100644 --- a/openvpn/tun/builder/base.hpp +++ b/openvpn/tun/builder/base.hpp @@ -23,6 +23,9 @@ #define OPENVPN_TUN_BUILDER_BASE_H #include +#if defined(ENABLE_DCO) +#include +#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 }; }