Squashed 'OpenVPN Adapter/Vendors/openvpn/' changes from da99df6..4095565

4095565 OpenVPN 3 client: added tun abstraction layer.
4bfaafc AsioTimer: use expires_after() method when possible.
782e8eb Apple: moved some source files.
f89da96 OpenVPN 3 client: added single-thread mode:
233dfde OpenVPN 3 client: fixed state->session typos.
d689b6d Added new Apple Core Foundation wrappers:
3838a62 i/o layer: added OPENVPN_IO_REQUIRES_STOP compile flag.
138ec96 asiopolysock.hpp: don't call SockOpt::set_cloexec(fd) if fd is undefined (i.e. fd == -1).
10eb723 Apple CF wrapper: renamed OWN/BORROW.
962fe87 Apple CF wrapper: simplify cf.hpp dependency profile.
4fcc99c Objective C++: fix symbol conflicts.
8f63cbb tunwrapasio.hpp: make generic with respect to i/o layer.
67e0013 AsioTimer: added expires_after() method.
fc7eaaf Apple CF wrappers: moved CFRunLoop/CFRunLoopSource wrapper to applecrypto/cf, where all other CF wrappers currently reside.
1215912 Revamped Function (our own functor object) to be more flexible.
10fa276 process.hpp: added compile option to avoid async pipe usage.
9e09451 gwv4.hpp: added missing includes
916856d build script: updated Objective-C support when OBJC=1.

git-subtree-dir: OpenVPN Adapter/Vendors/openvpn
git-subtree-split: 4095565b4de2c7d738e728cae989f632100a8ce8
This commit is contained in:
Sergey Abramchuk
2017-04-15 11:59:39 +03:00
parent f65d76170b
commit 9b95600d06
39 changed files with 773 additions and 223 deletions
+85 -5
View File
@@ -83,7 +83,7 @@
// on Android and iOS, use TunBuilderBase abstraction
#include <openvpn/common/platform.hpp>
#if (defined(OPENVPN_PLATFORM_ANDROID) || defined(OPENVPN_PLATFORM_IPHONE)) && !defined(OPENVPN_FORCE_TUN_NULL) && !defined(OPENVPN_CUSTOM_TUN_FACTORY)
#if (defined(OPENVPN_PLATFORM_ANDROID) || defined(OPENVPN_PLATFORM_IPHONE)) && !defined(OPENVPN_FORCE_TUN_NULL) && !defined(OPENVPN_EXTERNAL_TUN_FACTORY)
#define USE_TUN_BUILDER
#endif
@@ -92,6 +92,7 @@
#include <openvpn/common/platform_string.hpp>
#include <openvpn/common/count.hpp>
#include <openvpn/asio/asiostop.hpp>
#include <openvpn/time/asiotimer.hpp>
#include <openvpn/client/cliconnect.hpp>
#include <openvpn/client/cliopthelper.hpp>
#include <openvpn/options/merge.hpp>
@@ -205,7 +206,8 @@ namespace openvpn {
// save connected event
if (event->id() == ClientEvent::CONNECTED)
last_connected = std::move(event);
else if (event->id() == ClientEvent::DISCONNECTED)
parent->on_disconnect();
parent->event(ev);
}
}
@@ -341,6 +343,51 @@ namespace openvpn {
OpenVPNClient* parent = nullptr;
};
class MyClockTick
{
public:
MyClockTick(openvpn_io::io_context& io_context,
OpenVPNClient* parent_arg,
const unsigned int ms)
: timer(io_context),
parent(parent_arg),
period(Time::Duration::milliseconds(ms))
{
}
void cancel()
{
timer.cancel();
}
void detach_from_parent()
{
parent = nullptr;
}
void schedule()
{
timer.expires_after(period);
timer.async_wait([this](const openvpn_io::error_code& error)
{
if (!parent || error)
return;
try {
parent->clock_tick();
}
catch (...)
{
}
schedule();
});
}
private:
AsioTimer timer;
OpenVPNClient* parent;
const Time::Duration period;
};
namespace Private {
class ClientState
{
@@ -355,6 +402,7 @@ namespace openvpn {
MySessionStats::Ptr stats;
MyClientEvents::Ptr events;
ClientConnect::Ptr session;
std::unique_ptr<MyClockTick> clock_tick;
// extra settings submitted by API client
std::string server_override;
@@ -376,6 +424,7 @@ namespace openvpn {
ProtoContextOptions::Ptr proto_context_options;
PeerInfo::Set::Ptr extra_peer_info;
HTTPProxyTransport::Options::Ptr http_proxy_options;
unsigned int clock_tick_ms = 0;
#ifdef OPENVPN_GREMLIN
Gremlin::Config::Ptr gremlin_config;
#endif
@@ -429,6 +478,8 @@ namespace openvpn {
socket_protect.detach_from_parent();
reconnect_notify.detach_from_parent();
remote_override.detach_from_parent();
if (clock_tick)
clock_tick->detach_from_parent();
if (stats)
stats->detach_from_parent();
if (events)
@@ -474,6 +525,13 @@ namespace openvpn {
async_stop_local_.stop();
}
// disconnect
void on_disconnect()
{
if (clock_tick)
clock_tick->cancel();
}
private:
ClientState(const ClientState&) = delete;
ClientState& operator=(const ClientState&) = delete;
@@ -596,6 +654,7 @@ namespace openvpn {
state->dco = config.dco;
state->echo = config.echo;
state->info = config.info;
state->clock_tick_ms = config.clockTickMS;
if (!config.gremlinConfig.empty())
{
#ifdef OPENVPN_GREMLIN
@@ -755,7 +814,9 @@ namespace openvpn {
OPENVPN_CLIENT_EXPORT Status OpenVPNClient::connect()
{
#if !defined(OPENVPN_OVPNCLI_SINGLE_THREAD)
openvpn_io::detail::signal_blocker signal_blocker; // signals should be handled by parent thread
#endif
#if defined(OPENVPN_LOG_LOGTHREAD_H) && !defined(OPENVPN_LOG_LOGBASE_H)
#ifdef OPENVPN_LOG_GLOBAL
#error ovpn3 core logging object only supports thread-local scope
@@ -815,6 +876,9 @@ namespace openvpn {
cc.socket_protect = &state->socket_protect;
cc.builder = this;
#endif
#if defined(OPENVPN_EXTERNAL_TUN_FACTORY)
cc.extern_tun_factory = this;
#endif
// force Session ID use and disable password cache if static challenge is enabled
if (state->creds
@@ -864,6 +928,13 @@ namespace openvpn {
// instantiate top-level client session
state->session.reset(new ClientConnect(*state->io_context(), client_options));
// convenience clock tick
if (state->clock_tick_ms)
{
state->clock_tick.reset(new MyClockTick(*state->io_context(), this, state->clock_tick_ms));
state->clock_tick->schedule();
}
// raise an exception if app has expired
check_app_expired();
@@ -1142,7 +1213,7 @@ namespace openvpn {
{
ClientConnect* session = state->session.get();
if (session)
state->session->thread_safe_resume();
session->thread_safe_resume();
}
}
@@ -1152,7 +1223,7 @@ namespace openvpn {
{
ClientConnect* session = state->session.get();
if (session)
state->session->thread_safe_reconnect(seconds);
session->thread_safe_reconnect(seconds);
}
}
@@ -1162,10 +1233,19 @@ namespace openvpn {
{
ClientConnect* session = state->session.get();
if (session)
state->session->thread_safe_post_cc_msg(msg);
session->thread_safe_post_cc_msg(msg);
}
}
OPENVPN_CLIENT_EXPORT void OpenVPNClient::clock_tick()
{
}
OPENVPN_CLIENT_EXPORT void OpenVPNClient::on_disconnect()
{
state->on_disconnect();
}
OPENVPN_CLIENT_EXPORT std::string OpenVPNClient::crypto_self_test()
{
return SelfTest::crypto_self_test();