39#ifndef OPENVPN_CLIENT_CLICONNECT_H
40#define OPENVPN_CLIENT_CLICONNECT_H
45using namespace std::chrono_literals;
64 public RC<thread_unsafe_refcount>
101 if (bulkres->work_available())
116 client->send_explicit_exit_notify();
135 client->tun_set_disconnect();
152#ifdef OPENVPN_IO_REQUIRES_STOP
170 self->graceful_stop(); });
173 void pause(
const std::string &reason)
180 client->send_explicit_exit_notify();
210 OPENVPN_LOG(
"Client terminated, reconnecting in " << seconds <<
"...");
216 self->restart_wait_callback(gen, error); });
226 self->pause(reason); });
244 self->reconnect(seconds); });
264 self->post_cc_msg(
msg); });
270 client->post_app_control_message(std::move(protocol), std::move(
msg));
279 template <
typename... ArgsT>
283 client->start_acc_certcheck(std::forward<ArgsT>(args)...);
290 openvpn_io::post(
io_context, [self =
Ptr(
this), protocol = std::move(protocol),
msg = std::move(
msg)]()
293 self->send_app_control_channel_msg(protocol,
msg); });
335 client->send_explicit_exit_notify();
345 OPENVPN_LOG(
"Server poll timeout, trying next remote entry...");
377 self->conn_timer_callback(gen, error); });
424 OPENVPN_LOG(
"Client terminated, restarting in " << delay.count() <<
" ms...");
431 self->restart_wait_callback(gen, error); });
438 auto timer_left = std::chrono::duration_cast<std::chrono::seconds>(
conn_timer.expiry() - AsioTimer::clock_type::now()).count();
439 if (timer_left < timeout)
441 OPENVPN_LOG(
"Extending connection timeout from " << timer_left <<
" to " << timeout <<
" for pending authentication");
450 template <
typename ErrorClass>
453 add_error_and_stop<ErrorClass>(
client->fatal(),
client->fatal_reason());
457 template <
typename ErrorClass>
466 template <
typename ErrorClass>
475 template <
typename ErrorClass>
484 template <
typename ErrorClass>
503 auto fatal_code =
client->fatal();
504 auto fatal_reason =
client->fatal_reason();
510 std::chrono::duration client_delay =
client->reconnect_delay();
523 add_error_and_stop<ClientEvent::TunSetupFailed>(
client.
get());
526 add_error_and_stop<ClientEvent::TunSetupFailed>(
client.
get());
529 add_error_and_stop<ClientEvent::TunIfaceCreate>(
client.
get());
532 add_error_and_restart<ClientEvent::TunIfaceDisabled>(5000ms, fatal_reason);
535 add_error_and_stop<ClientEvent::ProxyError>(
client.
get());
538 add_error_and_stop<ClientEvent::ProxyNeedCreds>(
client.
get());
541 add_error_and_stop<ClientEvent::CertVerifyFail>(
client.
get());
544 add_error_and_stop<ClientEvent::TLSVersionMinFail>(fatal_code);
547 add_error_and_stop<ClientEvent::ClientHalt>(
client.
get());
550 add_error_and_restart<ClientEvent::ClientRestart>(5000ms, fatal_reason);
555 add_error_and_stop<ClientEvent::InactiveTimeout>(fatal_code);
558 add_error_and_restart<ClientEvent::TransportError>(5000ms, fatal_reason);
561 add_error_and_restart<ClientEvent::TunError>(5000ms, fatal_reason);
564 add_error_and_stop<ClientEvent::TunHalt>(
client.
get());
568 add_error_and_restart<ClientEvent::Relay>(0ms);
571 add_error_and_stop<ClientEvent::RelayError>(
client.
get());
574 add_error_and_stop<ClientEvent::CompressError>(
client.
get());
577 add_error_and_stop<ClientEvent::NtlmMissingCryptoError>(
client.
get());
580 add_error_and_stop<ClientEvent::TLSAlertProtocolVersion>(fatal_code);
583 add_error_and_stop<ClientEvent::TLSSigAlgDisallowedOrUnsupported>(fatal_code);
586 add_error_and_stop<ClientEvent::TLSAlertProtocolUnknownCA>(fatal_code);
589 add_error_and_stop<ClientEvent::TLSAlertMisc>(fatal_code, fatal_reason);
592 add_error_and_stop<ClientEvent::TLSAlertHandshakeFailure>(fatal_code);
595 add_error_and_stop<ClientEvent::TLSAlertCertificateExpire>(fatal_code);
598 add_error_and_stop<ClientEvent::TLSAlertCertificateRevoked>(fatal_code);
601 add_error_and_stop<ClientEvent::TLSAlertBadCertificate>(fatal_code);
604 add_error_and_stop<ClientEvent::TLSAlertUnsupportedCertificate>(fatal_code);
615 throw client_connect_unhandled_exception();
659 advance_type =
client->advance_type();
693 self->server_poll_callback(gen, error); });
706 virtual void cln_pause(
const std::string &reason)
override
#define OPENVPN_ASYNC_HANDLER
std::size_t expires_after(const Time::Duration &d)
static bool is_dynamic(const std::string &s)
void thread_safe_resume()
virtual void client_proto_auth_pending_timeout(int timeout) override
virtual void cln_stop() override
void thread_safe_post_cc_msg(std::string msg)
TransportClientFactory::Ptr transport_factory_relay
ClientOptions::Client Client
void post_cc_msg(const std::string &msg)
virtual void client_proto_terminate() override
virtual void cln_pause(const std::string &reason) override
bool test_network() const
virtual void cln_reconnect(int seconds) override
virtual void client_proto_connected() override
void stop_on_signal(const openvpn_io::error_code &error, int signal_number)
RCPtr< ClientConnect > Ptr
void add_error_and_stop(const int error_code, const std::string &fatal_reason)
void client_proto_renegotiated() override
void restart_wait_callback(unsigned int gen, const openvpn_io::error_code &e)
RemoteList::BulkResolve::Ptr bulk_resolve
AsioTimer restart_wait_timer
void queue_restart(std::chrono::milliseconds delay=default_delay_)
void handle_auth_failed(const int error_code, const std::string &reason)
OPENVPN_SIMPLE_EXCEPTION(client_connect_unhandled_exception)
void send_explicit_exit_notify()
void add_error_and_stop(const Client *client)
AsioTimer server_poll_timer
void server_poll_callback(unsigned int gen, const openvpn_io::error_code &e)
void thread_safe_reconnect(int seconds)
openvpn_io::io_context & io_context
void send_app_control_channel_msg(std::string protocol, std::string msg)
virtual void cln_resume() override
void start_acc_certcheck(ArgsT &&...args)
Passes the given arguments through to start_acc_certcheck.
virtual void bulk_resolve_done() override
void thread_safe_pause(const std::string &reason)
void pause(const std::string &reason)
void thread_safe_send_app_control_channel_msg(std::string protocol, std::string msg)
void conn_timer_callback(unsigned int gen, const openvpn_io::error_code &e)
void add_error_and_stop(const int error_code)
ClientOptions::Ptr client_options
static constexpr std::chrono::milliseconds default_delay_
void add_error_and_restart(std::chrono::milliseconds delay, const std::string &fatal_reason)
std::unique_ptr< AsioWork > asio_work
ClientConnect(openvpn_io::io_context &io_context_arg, const ClientOptions::Ptr &client_options_arg)
void reconnect(int seconds)
void conn_timer_start(int timeout)
void add_error_and_restart(std::chrono::milliseconds delay)
virtual void add_event(Base::Ptr event)=0
virtual void start(NotifyCallback *)=0
virtual bool network_available()=0
const SessionStats::Ptr & stats_ptr() const
void finalize(const bool disconnected)
bool server_poll_timeout_enabled() const
bool asio_work_always_on() const
bool pause_on_connection_timeout()
void next(RemoteList::Advance type)
ClientEvent::Queue & events()
ClientLifeCycle * lifecycle()
Time::Duration server_poll_timeout() const
bool retry_on_auth_failed() const
RemoteList::Ptr remote_list_precache() const
Client::Config::Ptr client_config(const bool relay_mode)
void remote_reset_cache_item()
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
T * get() const noexcept
Returns the raw pointer to the object T, or nullptr.
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
virtual void error(const size_t type, const std::string *text=nullptr)
#define OPENVPN_LOG(args)
@ TLS_ALERT_CERTIFICATE_REVOKED
@ TLS_ALERT_BAD_CERTIFICATE
@ TLS_ALERT_CERTIFICATE_EXPIRED
@ TLS_ALERT_UNSUPPORTED_CERTIFICATE
@ TUN_REGISTER_RINGS_ERROR
@ TLS_ALERT_PROTOCOL_VERSION
@ TLS_ALERT_HANDSHAKE_FAILURE
@ TLS_SIGALG_DISALLOWED_OR_UNSUPPORTED
Support deferred server-side state creation when client connects.