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