OpenVPN 3 Core Library
Loading...
Searching...
No Matches
transbase.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12// Abstract base classes for server transport objects that implement UDP, TCP,
13// HTTP Proxy, etc.
14
15#ifndef OPENVPN_TRANSPORT_SERVER_TRANSBASE_H
16#define OPENVPN_TRANSPORT_SERVER_TRANSBASE_H
17
18#include <string>
19#include <vector>
20
21#include <openvpn/io/io.hpp>
22
24#include <openvpn/common/rc.hpp>
32#include <openvpn/ssl/psid.hpp>
33
34// TunClientInstance fwd decl replaces
35// #include <openvpn/tun/server/tunbase.hpp>
36namespace openvpn {
37class PsidCookie;
38namespace TunClientInstance {
39struct Recv;
40struct Send;
41} // namespace TunClientInstance
42} // namespace openvpn
43
44// used by ipma_notify()
45struct ovpn_tun_head_ipma;
46
47namespace openvpn {
48
49// Base class for server transport object.
50struct TransportServer : public RC<thread_unsafe_refcount>
51{
53
54 virtual void start() = 0;
55 virtual void stop() = 0;
56 virtual std::string local_endpoint_info() const = 0;
57 virtual IP::Addr local_endpoint_addr() const = 0;
58};
59
60// Factory for server transport object.
61struct TransportServerFactory : public RC<thread_unsafe_refcount>
62{
64
65 virtual TransportServer::Ptr new_server_obj(openvpn_io::io_context &io_context) = 0;
66};
67
68namespace TransportClientInstance {
69
70// Base class for the per-client-instance state of the TransportServer.
71// Each client instance uses this class to send data to the transport layer.
72struct Send : public virtual RC<thread_unsafe_refcount>
73{
75
76 virtual bool defined() const = 0;
77 virtual void stop() = 0;
78
79 virtual bool transport_send_const(const Buffer &buf) = 0;
80 virtual bool transport_send(BufferAllocated &buf) = 0;
81
82 virtual const std::string &transport_info() const = 0;
83
84 // bandwidth stats polling
85 virtual bool stats_pending() const = 0;
86 virtual PeerStats stats_poll() = 0;
87};
88
89// Base class for the client instance receiver. Note that all
90// client instance receivers (transport, routing, management,
91// etc.) must inherit virtually from RC because the client instance
92// object will inherit from multiple receivers.
93struct Recv : public virtual RC<thread_unsafe_refcount>
94{
95 // clang-format off
97
98 virtual bool defined() const = 0;
99 virtual void stop() = 0;
100
101 virtual void start(const Send::Ptr &parent,
102 const PeerAddr::Ptr &addr,
103 const int local_peer_id,
104 const ProtoSessionID cookie_psid = ProtoSessionID()) = 0;
105
106 // Called with OpenVPN-encapsulated packets from transport layer.
107 // Returns true if packet successfully validated.
108 virtual bool transport_recv(BufferAllocated &buf) = 0;
109
110 // Return true if keepalive parameter(s) are enabled.
111 virtual bool is_keepalive_enabled() const = 0;
112
113 // Disable keepalive for rest of session, but fetch
114 // the keepalive parameters (in seconds).
115 virtual void disable_keepalive(unsigned int &keepalive_ping,
116 unsigned int &keepalive_timeout) = 0;
117
118 // override the data channel factory
119 virtual void override_dc_factory(const CryptoDCFactory::Ptr &dc_factory) = 0;
120
121 // override the tun provider
123
124 // bandwidth stats notification
125 virtual void stats_notify(const PeerStats &ps, const bool final) = 0;
126
127 // client float notification
128 virtual void float_notify(const PeerAddr::Ptr &addr) = 0;
129
130 // IP-mapped ACL (IPMA) notification
131 virtual void ipma_notify(const struct ovpn_tun_head_ipma &ipma) = 0;
132
133 // Data limit notification -- trigger a renegotiation
134 // when cdl_status == DataLimit::Red.
135 virtual void data_limit_notify(const int key_id,
136 const DataLimit::Mode cdl_mode,
137 const DataLimit::State cdl_status) = 0;
138
139 // push a halt or restart message to client
141 const std::string &reason,
142 const std::string &client_reason) = 0;
143 // clang-format on
144};
145
146// Base class for factory used to create Recv objects.
147struct Factory : public RC<thread_unsafe_refcount>
148{
150
152 virtual bool validate_initial_packet(const BufferAllocated &net_buf) = 0;
153};
154
155} // namespace TransportClientInstance
156} // namespace openvpn
157
158#endif
The smart pointer class.
Definition rc.hpp:119
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
Definition rc.hpp:912
virtual bool validate_initial_packet(const BufferAllocated &net_buf)=0
virtual void start(const Send::Ptr &parent, const PeerAddr::Ptr &addr, const int local_peer_id, const ProtoSessionID cookie_psid=ProtoSessionID())=0
virtual void push_halt_restart_msg(const HaltRestart::Type type, const std::string &reason, const std::string &client_reason)=0
virtual bool transport_recv(BufferAllocated &buf)=0
virtual void override_dc_factory(const CryptoDCFactory::Ptr &dc_factory)=0
virtual void ipma_notify(const struct ovpn_tun_head_ipma &ipma)=0
virtual void data_limit_notify(const int key_id, const DataLimit::Mode cdl_mode, const DataLimit::State cdl_status)=0
virtual void disable_keepalive(unsigned int &keepalive_ping, unsigned int &keepalive_timeout)=0
virtual void float_notify(const PeerAddr::Ptr &addr)=0
virtual TunClientInstance::Recv * override_tun(TunClientInstance::Send *tun)=0
virtual bool is_keepalive_enabled() const =0
virtual void stats_notify(const PeerStats &ps, const bool final)=0
virtual bool transport_send_const(const Buffer &buf)=0
virtual bool stats_pending() const =0
virtual bool transport_send(BufferAllocated &buf)=0
virtual const std::string & transport_info() const =0
RCPtr< TransportServerFactory > Ptr
Definition transbase.hpp:63
virtual TransportServer::Ptr new_server_obj(openvpn_io::io_context &io_context)=0
virtual IP::Addr local_endpoint_addr() const =0
virtual void stop()=0
RCPtr< TransportServer > Ptr
Definition transbase.hpp:52
virtual void start()=0
virtual std::string local_endpoint_info() const =0