OpenVPN 3 Core Library
Loading...
Searching...
No Matches
compstub.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// This is a "stub" compression object. It acts like a compressor
13// in the sense that it plays along with compression framing in
14// the OpenVPN protocol, but it always sends packets with NO_COMPRESS
15// or NO_COMPRESS_SWAP compression status. While it's not designed
16// to receive compressed packets, it will try to handle received LZO
17// packets, but it will never send compressed packets.
18
19#ifndef OPENVPN_COMPRESS_COMPSTUB_H
20#define OPENVPN_COMPRESS_COMPSTUB_H
21
22#ifndef NO_LZO
24#endif
25
26namespace openvpn {
27
28class CompressStub : public Compress
29{
30 public:
31 CompressStub(const Frame::Ptr &frame, const SessionStats::Ptr &stats, const bool support_swap_arg)
33 support_swap(support_swap_arg)
34#ifndef NO_LZO
35 ,
36 lzo(frame, stats, false, true)
37#endif
38 {
39 OVPN_LOG_INFO("Comp-stub init swap=" << support_swap_arg);
40 }
41
42 const char *name() const override
43 {
44 return "stub";
45 }
46
47 void compress(BufferAllocated &buf, const bool hint) override
48 {
49 // skip null packets
50 if (!buf.size())
51 return;
52
53 // indicate that we didn't compress
54 if (support_swap)
56 else
58 }
59
60 void decompress(BufferAllocated &buf) override
61 {
62 // skip null packets
63 if (!buf.size())
64 return;
65
66 const unsigned char c = buf.pop_front();
67 switch (c)
68 {
70 do_unswap(buf);
71 case NO_COMPRESS:
72 break;
73#ifndef NO_LZO
74 // special mode to support older servers that ignore
75 // compression handshake -- this will handle receiving
76 // compressed packets even if we didn't ask for them
78 OVPN_LOG_VERBOSE("CompressStub: handled unsolicited LZO packet");
80 break;
81#endif
82 default:
83 OVPN_LOG_VERBOSE("CompressStub: unable to handle op=" << int(c));
84 error(buf);
85 }
86 }
87
88 private:
89 const bool support_swap;
90#ifndef NO_LZO
92#endif
93};
94
95// Compression stub using V2 protocol
97{
98 public:
101 {
102 OVPN_LOG_INFO("Comp-stubV2 init");
103 }
104
105 const char *name() const override
106 {
107 return "stubv2";
108 }
109
110 void compress(BufferAllocated &buf, const bool hint) override
111 {
112 // skip null packets
113 if (!buf.size())
114 return;
115
116 // indicate that we didn't compress
118 }
119
120 void decompress(BufferAllocated &buf) override
121 {
122 // skip null packets
123 if (!buf.size())
124 return;
125
126 const int cop = v2_pull(buf);
127 if (cop)
128 {
129 OVPN_LOG_VERBOSE("CompressStubV2: unable to handle op=" << cop);
130 error(buf);
131 }
132 }
133};
134
135} // namespace openvpn
136
137#endif // OPENVPN_COMPRESS_COMPSTUB_H
void decompress_work(BufferAllocated &buf)
Definition lzo.hpp:58
const char * name() const override
Definition compstub.hpp:105
CompressStubV2(const Frame::Ptr &frame, const SessionStats::Ptr &stats)
Definition compstub.hpp:99
void compress(BufferAllocated &buf, const bool hint) override
Definition compstub.hpp:110
void decompress(BufferAllocated &buf) override
Definition compstub.hpp:120
void decompress(BufferAllocated &buf) override
Definition compstub.hpp:60
CompressStub(const Frame::Ptr &frame, const SessionStats::Ptr &stats, const bool support_swap_arg)
Definition compstub.hpp:31
const char * name() const override
Definition compstub.hpp:42
void compress(BufferAllocated &buf, const bool hint) override
Definition compstub.hpp:47
const bool support_swap
Definition compstub.hpp:89
void do_swap(Buffer &buf, unsigned char op)
Definition compress.hpp:82
void error(BufferAllocated &buf)
Definition compress.hpp:76
void do_unswap(Buffer &buf)
Definition compress.hpp:93
void v2_push(Buffer &buf, unsigned char value)
Definition compress.hpp:104
Frame::Ptr frame
Definition compress.hpp:127
SessionStats::Ptr stats
Definition compress.hpp:128
int v2_pull(Buffer &buf)
Definition compress.hpp:117
size_t size() const
Returns the size of the buffer in T objects.
Definition buffer.hpp:1242
T pop_front()
Removes and returns the first element from the buffer.
Definition buffer.hpp:1256
void push_front(const T &value)
Append a T object to the array, with possible resize.
Definition buffer.hpp:1490
#define OVPN_LOG_INFO(args)
Definition logger.hpp:224
#define OVPN_LOG_VERBOSE(args)
Definition logger.hpp:225