mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 12:12:15 +02:00
tun/win: factor out ClientConfig into separate header
Signed-off-by: Lev Stipakov <lev@openvpn.net>
This commit is contained in:
parent
aeb5ce0ad7
commit
98bfd037e3
105
openvpn/tun/win/client/clientconfig.hpp
Normal file
105
openvpn/tun/win/client/clientconfig.hpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <openvpn/asio/scoped_asio_stream.hpp>
|
||||||
|
#include <openvpn/tun/client/tunbase.hpp>
|
||||||
|
#include <openvpn/tun/client/tunprop.hpp>
|
||||||
|
#include <openvpn/tun/persist/tunpersist.hpp>
|
||||||
|
#include <openvpn/tun/win/client/tunsetup.hpp>
|
||||||
|
|
||||||
|
namespace openvpn {
|
||||||
|
namespace TunWin {
|
||||||
|
|
||||||
|
// These types manage the underlying TAP driver HANDLE
|
||||||
|
typedef openvpn_io::windows::stream_handle TAPStream;
|
||||||
|
typedef ScopedAsioStream<TAPStream> ScopedTAPStream;
|
||||||
|
typedef TunPersistTemplate<ScopedTAPStream> TunPersist;
|
||||||
|
|
||||||
|
class ClientConfig : public TunClientFactory
|
||||||
|
{
|
||||||
|
friend class Client; // accesses wfp
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef RCPtr<ClientConfig> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -38,6 +38,7 @@
|
|||||||
#include <openvpn/tun/persist/tunpersist.hpp>
|
#include <openvpn/tun/persist/tunpersist.hpp>
|
||||||
#include <openvpn/tun/persist/tunwrapasio.hpp>
|
#include <openvpn/tun/persist/tunwrapasio.hpp>
|
||||||
#include <openvpn/tun/tunio.hpp>
|
#include <openvpn/tun/tunio.hpp>
|
||||||
|
#include <openvpn/tun/win/client/clientconfig.hpp>
|
||||||
#include <openvpn/tun/win/client/tunsetup.hpp>
|
#include <openvpn/tun/win/client/tunsetup.hpp>
|
||||||
#include <openvpn/win/modname.hpp>
|
#include <openvpn/win/modname.hpp>
|
||||||
|
|
||||||
@ -95,77 +96,7 @@ namespace openvpn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// These types manage the underlying TAP driver HANDLE
|
|
||||||
typedef openvpn_io::windows::stream_handle TAPStream;
|
|
||||||
typedef ScopedAsioStream<TAPStream> ScopedTAPStream;
|
|
||||||
typedef TunPersistTemplate<ScopedTAPStream> TunPersist;
|
|
||||||
|
|
||||||
class ClientConfig : public TunClientFactory
|
|
||||||
{
|
|
||||||
friend class Client; // accesses wfp
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef RCPtr<ClientConfig> 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
|
class Client : public TunClient
|
||||||
{
|
{
|
||||||
friend class ClientConfig; // calls constructor
|
friend class ClientConfig; // calls constructor
|
||||||
|
@ -420,6 +420,7 @@
|
|||||||
<ClInclude Include="..\openvpn\tun\tunlog.hpp" />
|
<ClInclude Include="..\openvpn\tun\tunlog.hpp" />
|
||||||
<ClInclude Include="..\openvpn\tun\tunmtu.hpp" />
|
<ClInclude Include="..\openvpn\tun\tunmtu.hpp" />
|
||||||
<ClInclude Include="..\openvpn\tun\tunspec.hpp" />
|
<ClInclude Include="..\openvpn\tun\tunspec.hpp" />
|
||||||
|
<ClInclude Include="..\openvpn\tun\win\client\clientconfig.hpp" />
|
||||||
<ClInclude Include="..\openvpn\tun\win\client\setupbase.hpp" />
|
<ClInclude Include="..\openvpn\tun\win\client\setupbase.hpp" />
|
||||||
<ClInclude Include="..\openvpn\tun\win\client\tuncli.hpp" />
|
<ClInclude Include="..\openvpn\tun\win\client\tuncli.hpp" />
|
||||||
<ClInclude Include="..\openvpn\tun\win\client\tunsetup.hpp" />
|
<ClInclude Include="..\openvpn\tun\win\client\tunsetup.hpp" />
|
||||||
|
@ -428,6 +428,7 @@
|
|||||||
<ClInclude Include="..\openvpn\ip\ping4.hpp" />
|
<ClInclude Include="..\openvpn\ip\ping4.hpp" />
|
||||||
<ClInclude Include="..\openvpn\ip\ping6.hpp" />
|
<ClInclude Include="..\openvpn\ip\ping6.hpp" />
|
||||||
<ClInclude Include="..\openvpn\ip\csum.hpp" />
|
<ClInclude Include="..\openvpn\ip\csum.hpp" />
|
||||||
|
<ClInclude Include="..\openvpn\tun\win\client\clientconfig.hpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\test\ovpncli\cli.cpp" />
|
<ClCompile Include="..\test\ovpncli\cli.cpp" />
|
||||||
|
Loading…
Reference in New Issue
Block a user