OpenVPN
mtu.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2024 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24#ifndef MTU_H
25#define MTU_H
26
27#include "buffer.h"
28
29/*
30 *
31 * Packet manipulation routes such as encrypt, decrypt, compress, decompress
32 * are passed a frame buffer that looks like this:
33 *
34 * [extra_frame bytes] [mtu bytes] [extra_frame_bytes] [compression overflow bytes]
35 * ^
36 * Pointer passed to function points here so that routine
37 * can make use of extra_frame bytes before pointer
38 * to prepend headers, etc.
39 *
40 * extra_frame bytes is large enough for all encryption related overhead.
41 *
42 * mtu bytes will be the MTU size set in the ifconfig statement that configures
43 * the TUN or TAP device such as:
44 *
45 * ifconfig $1 10.1.0.2 pointopoint 10.1.0.1 mtu 1450
46 *
47 * Compression overflow bytes is the worst-case size expansion that would be
48 * expected if we tried to compress mtu + extra_frame bytes of incompressible data.
49 */
50
51/*
52 * Standard ethernet MTU
53 */
54#define ETHERNET_MTU 1500
55
56/*
57 * It is a fatal error if mtu is less than
58 * this value for tun device.
59 */
60#define TUN_MTU_MIN 100
61
62/*
63 * Default MTU of network over which tunnel data will pass by TCP/UDP.
64 */
65#define LINK_MTU_DEFAULT 1500
66
67/*
68 * Default MTU of tunnel device.
69 */
70#define TUN_MTU_DEFAULT 1500
71
72/*
73 * MTU Defaults for TAP devices
74 */
75#define TAP_MTU_EXTRA_DEFAULT 32
76
77/*
78 * Default MSSFIX value, used for reducing TCP MTU size
79 */
80#define MSSFIX_DEFAULT 1492
81
82/*
83 * Default maximum size of control channel packets
84 */
85#define TLS_MTU_DEFAULT 1250
86
87/*
88 * Alignment of payload data such as IP packet or
89 * ethernet frame.
90 */
91#define PAYLOAD_ALIGN 4
92
93
94/**************************************************************************/
98struct frame {
99 struct {
100 /* This struct holds all the information about the buffers that are
101 * allocated to match this frame */
117
118 uint16_t mss_fix;
154};
155
156/* Forward declarations, to prevent includes */
157struct options;
158
159/*
160 * Control buffer headroom allocations to allow for efficient prepending.
161 */
162
163/*
164 * Max size of a buffer used to build a packet for output to
165 * the TCP/UDP port or to read a packet from a tap/tun device.
166 *
167 * Most of our code only prepends headers but compression needs the extra bytes
168 * *after* the data as compressed data might end up larger than the original
169 * data. Also crypto needs an extra block for encryption. Therefore tailroom is
170 * larger than the headroom.
171 */
172#define BUF_SIZE(f) ((f)->buf.headroom + (f)->buf.payload_size + (f)->buf.tailroom)
173
174/*
175 * Function prototypes.
176 */
177
178void frame_print(const struct frame *frame,
179 int level,
180 const char *prefix);
181
182void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af);
183
184int translate_mtu_discover_type_name(const char *name);
185
186/* forward declaration of key_type */
187struct key_type;
188
198size_t
200 const struct options *options,
201 const struct key_type *kt);
202
219size_t
220frame_calculate_payload_overhead(size_t extra_tun,
221 const struct options *options,
222 const struct key_type *kt);
223
224
240size_t
242 const struct options *options,
243 bool occ);
244
252size_t
254 const struct frame *frame);
255
260unsigned int
262 const struct key_type *kt);
263
264/*
265 * allocate a buffer for socket or tun layer
266 */
267void alloc_buf_sock_tun(struct buffer *buf,
268 const struct frame *frame);
269
270/*
271 * EXTENDED_SOCKET_ERROR_CAPABILITY functions -- print extra error info
272 * on socket errors, such as PMTU size. As of 2003.05.11, only works
273 * on Linux 2.4+.
274 */
275
276#if EXTENDED_SOCKET_ERROR_CAPABILITY
277
278void set_sock_extended_error_passing(int sd, sa_family_t proto_af);
279
280const char *format_extended_socket_error(int fd, int *mtu, struct gc_arena *gc);
281
282#endif
283
284#endif /* ifndef MTU_H */
void frame_print(const struct frame *frame, int level, const char *prefix)
Definition mtu.c:195
size_t frame_calculate_payload_size(const struct frame *frame, const struct options *options, const struct key_type *kt)
Calculates the size of the payload according to tun-mtu and tap overhead.
Definition mtu.c:142
int translate_mtu_discover_type_name(const char *name)
Definition mtu.c:261
size_t calc_options_string_link_mtu(const struct options *options, const struct frame *frame)
Calculate the link-mtu to advertise to our peer.
Definition mtu.c:152
size_t frame_calculate_protocol_header_size(const struct key_type *kt, const struct options *options, bool occ)
Calculates the size of the OpenVPN protocol header.
Definition mtu.c:63
unsigned int calc_packet_id_size_dc(const struct options *options, const struct key_type *kt)
Return the size of the packet ID size that is currently in use by cipher and options for the data cha...
Definition mtu.c:53
void alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame)
Definition mtu.c:42
void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proto_af)
Definition mtu.c:225
size_t frame_calculate_payload_overhead(size_t extra_tun, const struct options *options, const struct key_type *kt)
Calculates the size of the payload overhead according to tun-mtu and tap overhead.
Definition mtu.c:101
Wrapper structure for dynamically allocated memory.
Definition buffer.h:61
Packet geometry parameters.
Definition mtu.h:98
int tun_mtu
the (user) configured tun-mtu.
Definition mtu.h:131
int payload_size
the maximum size that a payload that our buffers can hold from either tun device or network link.
Definition mtu.h:102
int tun_max_mtu
the maximum tun-mtu size the buffers are are sized for.
Definition mtu.h:141
int extra_tun
Maximum number of bytes in excess of the tun/tap MTU that might be read from or written to the virtua...
Definition mtu.h:145
int headroom
the headroom in the buffer, this is choosen to allow all potential header to be added before the pack...
Definition mtu.h:108
uint16_t mss_fix
The actual MSS value that should be written to the payload packets.
Definition mtu.h:118
int max_fragment_size
The maximum size of a fragment.
Definition mtu.h:124
struct frame::@8 buf
int tailroom
the tailroom in the buffer.
Definition mtu.h:112
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:117
unsigned short sa_family_t
Definition syshead.h:395
SOCKET socket_descriptor_t
Definition syshead.h:439
struct gc_arena gc
Definition test_ssl.c:155