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 server tun objects
13
14#ifndef OPENVPN_TUN_SERVER_TUNBASE_H
15#define OPENVPN_TUN_SERVER_TUNBASE_H
16
17#include <string>
18
20#include <openvpn/common/rc.hpp>
23#include <openvpn/addr/ip.hpp>
25
27
28using PostCloseFunc = Function<void(int fd)>;
29
30// A native reference to a client instance
32{
33 NativeHandle() = default;
34
35 NativeHandle(const int fd_arg, const int peer_id_arg)
36 : fd(fd_arg),
37 peer_id(peer_id_arg)
38 {
39 }
40
41 bool fd_defined() const
42 {
43 return fd >= 0;
44 }
45
46 bool defined() const
47 {
48 return fd >= 0 && peer_id >= 0;
49 }
50
51 int fd = -1;
52 int peer_id = -1;
53};
54
55// Base class for the client instance receiver. Note that all
56// client instance receivers (transport, routing, management,
57// etc.) must inherit virtually from RC because the client instance
58// object will inherit from multiple receivers.
59struct Recv : public virtual RC<thread_unsafe_refcount>
60{
62
63 // virtual bool defined() const = 0;
64 virtual void stop() = 0;
65
66 // Called with IP packets from tun layer.
67 virtual void tun_recv(BufferAllocated &buf) = 0;
68
69 // clang-format off
70 // push a halt or restart message to client
72 const std::string &reason,
73 const std::string &client_reason) = 0;
74 // clang-format on
75};
76
77// Base class for the per-client-instance state of the TunServer.
78// Each client instance uses this class to send data to the tun layer.
79struct Send : public virtual RC<thread_unsafe_refcount>
80{
82
83 // virtual bool defined() const = 0;
84 virtual void stop() = 0;
85
86 virtual bool tun_send_const(const Buffer &buf) = 0;
87 virtual bool tun_send(BufferAllocated &buf) = 0;
88
89 // get the native handle for tun/peer
91
92 // set up relay to target
93 virtual void relay(const IP::Addr &target, const int port) = 0;
94
95 virtual const std::string &tun_info() const = 0;
96};
97
98// Factory for server tun object.
99struct Factory : public RC<thread_unsafe_refcount>
100{
102
103 virtual Send::Ptr new_tun_obj(Recv *parent) = 0;
104};
105
106} // namespace openvpn::TunClientInstance
107
108#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:908
virtual Send::Ptr new_tun_obj(Recv *parent)=0
NativeHandle(const int fd_arg, const int peer_id_arg)
Definition tunbase.hpp:35
virtual void tun_recv(BufferAllocated &buf)=0
virtual void push_halt_restart_msg(const HaltRestart::Type type, const std::string &reason, const std::string &client_reason)=0
virtual bool tun_send_const(const Buffer &buf)=0
virtual void relay(const IP::Addr &target, const int port)=0
virtual bool tun_send(BufferAllocated &buf)=0
virtual NativeHandle tun_native_handle()=0
virtual const std::string & tun_info() const =0
proxy_host_port port