OpenVPN 3 Core Library
Loading...
Searching...
No Matches
tunbase.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 client tun interface objects.
13
14#ifndef OPENVPN_TUN_CLIENT_TUNBASE_H
15#define OPENVPN_TUN_CLIENT_TUNBASE_H
16
17#include <string>
18
19#include <openvpn/io/io.hpp>
20
21#include <openvpn/common/rc.hpp>
26
27namespace openvpn {
28
29constexpr std::uint32_t INVALID_ADAPTER_INDEX = static_cast<std::uint32_t>(-1);
30
31// Base class for objects that implement a client tun interface.
32struct TunClient : public virtual RC<thread_unsafe_refcount>
33{
35
36 virtual void tun_start(const OptionList &, TransportClient &, CryptoDCSettings &) = 0;
37 virtual void stop() = 0;
38 virtual void set_disconnect() = 0;
39 virtual bool tun_send(BufferAllocated &buf) = 0; // return true if send succeeded
40
41 virtual std::string tun_name() const = 0;
42
43 virtual std::string vpn_ip4() const = 0; // VPN IP addresses
44 virtual std::string vpn_ip6() const = 0;
45
46 virtual std::string vpn_gw4() const
47 {
48 return std::string();
49 } // VPN gateways
50 virtual std::string vpn_gw6() const
51 {
52 return std::string();
53 }
54
55 virtual int vpn_mtu() const = 0;
56
57 virtual void adjust_mss(int mss) {};
58
70 virtual void apply_push_update(const OptionList &opt, TransportClient &cli) {};
71
72 virtual std::uint32_t vpn_interface_index() const
73 {
75 }
76};
77
78// Base class for parent of tun interface object, used to
79// communicate received data packets, exceptions,
80// special events, and progress notifications.
82{
83 virtual ~TunClientParent() = default;
84
85 virtual void tun_recv(BufferAllocated &buf) = 0;
86 virtual void tun_error(const Error::Type fatal_err, const std::string &err_text) = 0;
87
88 // progress notifications
89 virtual void tun_pre_tun_config() = 0;
90 virtual void tun_pre_route_config() = 0;
91 virtual void tun_connected() = 0;
92
93 // allow tunclient to generate events
95 {
96 }
97};
98
99// Factory for tun interface objects.
100struct TunClientFactory : public virtual RC<thread_unsafe_refcount>
101{
103
104 virtual TunClient::Ptr new_tun_client_obj(openvpn_io::io_context &io_context, TunClientParent &parent, TransportClient *transcli) = 0;
105
106 // return true if layer 2 tunnels are supported
107 virtual bool layer_2_supported() const
108 {
109 return false;
110 }
111
120 virtual bool supports_epoch_data() = 0;
121
122 // Called on TunClient close, after TunClient::stop has been called.
123 // disconnected ->
124 // true: this is the final disconnect, or
125 // false: we are in a pause/reconnecting state.
126 virtual void finalize(const bool disconnected)
127 {
128 }
129};
130
131} // namespace openvpn
132
133#endif // OPENVPN_TUN_CLIENT_TUNBASE_H
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
constexpr std::uint32_t INVALID_ADAPTER_INDEX
Definition tunbase.hpp:29
virtual bool layer_2_supported() const
Definition tunbase.hpp:107
virtual void finalize(const bool disconnected)
Definition tunbase.hpp:126
virtual TunClient::Ptr new_tun_client_obj(openvpn_io::io_context &io_context, TunClientParent &parent, TransportClient *transcli)=0
RCPtr< TunClientFactory > Ptr
Definition tunbase.hpp:102
virtual bool supports_epoch_data()=0
virtual ~TunClientParent()=default
virtual void tun_error(const Error::Type fatal_err, const std::string &err_text)=0
virtual void tun_event(ClientEvent::Base::Ptr ev)
Definition tunbase.hpp:94
virtual void tun_pre_route_config()=0
virtual void tun_connected()=0
virtual void tun_pre_tun_config()=0
virtual void tun_recv(BufferAllocated &buf)=0
virtual std::string vpn_gw6() const
Definition tunbase.hpp:50
virtual std::string vpn_ip4() const =0
virtual std::string tun_name() const =0
virtual void stop()=0
virtual int vpn_mtu() const =0
virtual void adjust_mss(int mss)
Definition tunbase.hpp:57
virtual void apply_push_update(const OptionList &opt, TransportClient &cli)
Notifies tun client about received PUSH_UPDATE control channel message.
Definition tunbase.hpp:70
RCPtr< TunClient > Ptr
Definition tunbase.hpp:34
virtual std::uint32_t vpn_interface_index() const
Definition tunbase.hpp:72
virtual void set_disconnect()=0
virtual void tun_start(const OptionList &, TransportClient &, CryptoDCSettings &)=0
virtual std::string vpn_gw4() const
Definition tunbase.hpp:46
virtual bool tun_send(BufferAllocated &buf)=0
virtual std::string vpn_ip6() const =0