diff --git a/openvpn/tun/win/client/clientconfig.hpp b/openvpn/tun/win/client/clientconfig.hpp new file mode 100644 index 00000000..9a6eea4b --- /dev/null +++ b/openvpn/tun/win/client/clientconfig.hpp @@ -0,0 +1,105 @@ +// OpenVPN -- An application to securely tunnel IP networks +// over a single port, with support for SSL/TLS-based +// session authentication and key exchange, +// packet encryption, packet authentication, and +// packet compression. +// +// Copyright (C) 2012-2017 OpenVPN Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License Version 3 +// as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program in the COPYING file. +// If not, see . +// + +#pragma once + +#include +#include +#include +#include +#include + +namespace openvpn { + namespace TunWin { + + // These types manage the underlying TAP driver HANDLE + typedef openvpn_io::windows::stream_handle TAPStream; + typedef ScopedAsioStream ScopedTAPStream; + typedef TunPersistTemplate TunPersist; + + class ClientConfig : public TunClientFactory + { + friend class Client; // accesses wfp + + public: + typedef RCPtr Ptr; + + TunProp::Config tun_prop; + int n_parallel = 8; // number of parallel async reads on tun socket + bool wintun = false; // wintun may return multiple packets + + Frame::Ptr frame; + SessionStats::Ptr stats; + + Stop* stop = nullptr; + + TunPersist::Ptr tun_persist; + + TunWin::SetupFactory::Ptr tun_setup_factory; + + TunWin::SetupBase::Ptr new_setup_obj(openvpn_io::io_context& io_context) + { + if (tun_setup_factory) + return tun_setup_factory->new_setup_obj(io_context, wintun); + else + return new TunWin::Setup(io_context, wintun); + } + + static Ptr new_obj() + { + return new ClientConfig; + } + + virtual TunClient::Ptr new_tun_client_obj(openvpn_io::io_context& io_context, + TunClientParent& parent, + TransportClient* transcli) override; + + virtual void finalize(const bool disconnected) override + { + if (disconnected) + tun_persist.reset(); + } + + virtual bool layer_2_supported() const override + { + return true; + } + + void set_wintun(bool wintun_arg) + { + if (wintun_arg) + { + wintun = true; + // we cannot use parallel reads with wintun, since it requires + // the same buffer with the same length for every write() call + n_parallel = 1; + } + else + { + wintun = false; + n_parallel = 8; + } + } + }; + } +} + diff --git a/openvpn/tun/win/client/tuncli.hpp b/openvpn/tun/win/client/tuncli.hpp index 71f3ac92..878b904d 100644 --- a/openvpn/tun/win/client/tuncli.hpp +++ b/openvpn/tun/win/client/tuncli.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -95,77 +96,7 @@ namespace openvpn { } } }; - - // These types manage the underlying TAP driver HANDLE - typedef openvpn_io::windows::stream_handle TAPStream; - typedef ScopedAsioStream ScopedTAPStream; - typedef TunPersistTemplate TunPersist; - - class ClientConfig : public TunClientFactory - { - friend class Client; // accesses wfp - - public: - typedef RCPtr Ptr; - - TunProp::Config tun_prop; - int n_parallel = 8; // number of parallel async reads on tun socket - bool wintun = false; // wintun may return multiple packets - - Frame::Ptr frame; - SessionStats::Ptr stats; - - Stop* stop = nullptr; - - TunPersist::Ptr tun_persist; - - TunWin::SetupFactory::Ptr tun_setup_factory; - - TunWin::SetupBase::Ptr new_setup_obj(openvpn_io::io_context& io_context) - { - if (tun_setup_factory) - return tun_setup_factory->new_setup_obj(io_context, wintun); - else - return new TunWin::Setup(io_context, wintun); - } - - static Ptr new_obj() - { - return new ClientConfig; - } - - virtual TunClient::Ptr new_tun_client_obj(openvpn_io::io_context& io_context, - TunClientParent& parent, - TransportClient* transcli) override; - - virtual void finalize(const bool disconnected) override - { - if (disconnected) - tun_persist.reset(); - } - - virtual bool layer_2_supported() const override - { - return true; - } - - void set_wintun(bool wintun_arg) - { - if (wintun_arg) - { - wintun = true; - // we cannot use parallel reads with wintun, since it requires - // the same buffer with the same length for every write() call - n_parallel = 1; - } - else - { - wintun = false; - n_parallel = 8; - } - } - }; - + class Client : public TunClient { friend class ClientConfig; // calls constructor diff --git a/win/ovpn3-core.vcxproj b/win/ovpn3-core.vcxproj index 5c49c679..609e4691 100644 --- a/win/ovpn3-core.vcxproj +++ b/win/ovpn3-core.vcxproj @@ -420,6 +420,7 @@ + diff --git a/win/ovpn3-core.vcxproj.filters b/win/ovpn3-core.vcxproj.filters index a6ce3b75..c1b829dc 100644 --- a/win/ovpn3-core.vcxproj.filters +++ b/win/ovpn3-core.vcxproj.filters @@ -428,6 +428,7 @@ +