OpenVPN 3 Core Library
Loading...
Searching...
No Matches
tunnull.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// Null tun interface object, intended for testing.
13
14#ifndef OPENVPN_TUN_CLIENT_TUNNULL_H
15#define OPENVPN_TUN_CLIENT_TUNNULL_H
16
18
20
22{
23 public:
25
28
29 static Ptr new_obj()
30 {
31 return new ClientConfig;
32 }
33
34 TunClient::Ptr new_tun_client_obj(openvpn_io::io_context &io_context,
35 TunClientParent &parent,
36 TransportClient *transcli) override;
37
38 bool supports_epoch_data() override
39 {
40 return true;
41 }
42
43 private:
44 ClientConfig() = default;
45};
46
47class Client : public TunClient
48{
49 friend class ClientConfig; // calls constructor
50
51 public:
52 void tun_start(const OptionList &opt, TransportClient &transcli, CryptoDCSettings &) override
53 {
54#ifdef TUN_NULL_EXIT
55 throw ErrorCode(Error::TUN_SETUP_FAILED, true, "TUN_NULL_EXIT");
56#else
57 // signal that we are "connected"
59#endif
60 }
61
62 bool tun_send(BufferAllocated &buf) override
63 {
64 config->stats->inc_stat(SessionStats::TUN_BYTES_OUT, buf.size());
65 config->stats->inc_stat(SessionStats::TUN_PACKETS_OUT, 1);
66 return true;
67 }
68
69 std::string tun_name() const override
70 {
71 return "TUN_NULL";
72 }
73
74 std::string vpn_ip4() const override
75 {
76 return "";
77 }
78
79 std::string vpn_ip6() const override
80 {
81 return "";
82 }
83
84 int vpn_mtu() const override
85 {
86 return 0;
87 }
88
89 void set_disconnect() override
90 {
91 }
92
93 void stop() override
94 {
95 }
96
97 private:
98 Client(openvpn_io::io_context &io_context_arg,
99 ClientConfig *config_arg,
100 TunClientParent &parent_arg)
101 : config(config_arg),
102 parent(parent_arg)
103 {
104 }
105
108};
109
110inline TunClient::Ptr ClientConfig::new_tun_client_obj(openvpn_io::io_context &io_context,
111 TunClientParent &parent,
112 TransportClient *transcli)
113{
114 return TunClient::Ptr(new Client(io_context, this, parent));
115}
116
117} // namespace openvpn::TunNull
118
119#endif // OPENVPN_TUN_CLIENT_TUNNULL_H
size_t size() const
Returns the size of the buffer in T objects.
Definition buffer.hpp:1242
The smart pointer class.
Definition rc.hpp:119
TunClient::Ptr new_tun_client_obj(openvpn_io::io_context &io_context, TunClientParent &parent, TransportClient *transcli) override
Definition tunnull.hpp:110
SessionStats::Ptr stats
Definition tunnull.hpp:27
RCPtr< ClientConfig > Ptr
Definition tunnull.hpp:24
bool supports_epoch_data() override
Definition tunnull.hpp:38
void set_disconnect() override
Definition tunnull.hpp:89
int vpn_mtu() const override
Definition tunnull.hpp:84
std::string tun_name() const override
Definition tunnull.hpp:69
ClientConfig::Ptr config
Definition tunnull.hpp:106
Client(openvpn_io::io_context &io_context_arg, ClientConfig *config_arg, TunClientParent &parent_arg)
Definition tunnull.hpp:98
std::string vpn_ip4() const override
Definition tunnull.hpp:74
TunClientParent & parent
Definition tunnull.hpp:107
bool tun_send(BufferAllocated &buf) override
Definition tunnull.hpp:62
std::string vpn_ip6() const override
Definition tunnull.hpp:79
void tun_start(const OptionList &opt, TransportClient &transcli, CryptoDCSettings &) override
Definition tunnull.hpp:52
void stop() override
Definition tunnull.hpp:93
virtual void tun_connected()=0
RCPtr< TunClient > Ptr
Definition tunbase.hpp:34