OpenVPN
occ.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-2018 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 OCC_H
25 #define OCC_H
26 
27 #ifdef ENABLE_OCC
28 
29 #include "forward.h"
30 
31 /* OCC_STRING_SIZE must be set to sizeof (occ_magic) */
32 #define OCC_STRING_SIZE 16
33 
34 /*
35  * OCC (OpenVPN Configuration Control) protocol opcodes.
36  */
37 
38 #define OCC_REQUEST 0 /* request options string from peer */
39 #define OCC_REPLY 1 /* deliver options string to peer */
40 
41 /*
42  * Send an OCC_REQUEST once every OCC_INTERVAL
43  * seconds until a reply is received.
44  *
45  * If we haven't received a reply after
46  * OCC_N_TRIES, give up.
47  */
48 #define OCC_INTERVAL_SECONDS 10
49 #define OCC_N_TRIES 12
50 
51 /*
52  * Other OCC protocol opcodes used to estimate the MTU empirically.
53  */
54 #define OCC_MTU_LOAD_REQUEST 2 /* Ask peer to send a big packet to us */
55 #define OCC_MTU_LOAD 3 /* Send a big packet to peer */
56 #define OCC_MTU_REQUEST 4 /* Ask peer to tell us the largest
57  * packet it has received from us so far */
58 #define OCC_MTU_REPLY 5 /* Send largest packet size to peer */
59 
60 /*
61  * Process one command from mtu_load_test_sequence
62  * once every n seconds, if --mtu-test is specified.
63  */
64 #define OCC_MTU_LOAD_INTERVAL_SECONDS 3
65 
66 /*
67  * Send an exit message to remote.
68  */
69 #define OCC_EXIT 6
70 
71 /*
72  * Used to conduct a load test command sequence
73  * of UDP connection for empirical MTU measurement.
74  */
76 {
77  int op; /* OCC opcode to send to peer */
78  int delta; /* determine packet size to send by using
79  * this delta against currently
80  * configured MTU */
81 };
82 
83 extern const uint8_t occ_magic[];
84 
85 static inline bool
86 is_occ_msg(const struct buffer *buf)
87 {
89 }
90 
91 void process_received_occ_msg(struct context *c);
92 
93 void check_send_occ_req_dowork(struct context *c);
94 
96 
97 void check_send_occ_msg_dowork(struct context *c);
98 
99 /*
100  * Inline functions
101  */
102 
103 static inline int
105 {
106  return -1;
107 }
108 
109 /*
110  * Should we send an OCC_REQUEST message?
111  */
112 static inline void
114 {
117  &c->c2.timeval,
118  (!TO_LINK_DEF(c) && c->c2.occ_op < 0) ? ETT_DEFAULT : 0))
119  {
121  }
122 }
123 
124 /*
125  * Should we send an MTU load test?
126  */
127 static inline void
129 {
132  &c->c2.timeval,
133  (!TO_LINK_DEF(c) && c->c2.occ_op < 0) ? ETT_DEFAULT : 0))
134  {
136  }
137 }
138 
139 /*
140  * Should we send an OCC message?
141  */
142 static inline void
144 {
145  if (c->c2.occ_op >= 0)
146  {
147  if (!TO_LINK_DEF(c))
148  {
150  }
151  else
152  {
153  tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */
154  }
155  }
156 }
157 
158 #endif /* ifdef ENABLE_OCC */
159 #endif /* ifndef OCC_H */
#define ETT_DEFAULT
Definition: interval.h:213
Contains all state information for one tunnel.
Definition: openvpn.h:500
const uint8_t occ_magic[]
Definition: occ.c:59
static bool is_occ_msg(const struct buffer *buf)
Definition: occ.h:86
void process_received_occ_msg(struct context *c)
Definition: occ.c:353
static void tv_clear(struct timeval *tv)
Definition: otime.h:134
static void check_send_occ_load_test(struct context *c)
Definition: occ.h:128
void check_send_occ_load_test_dowork(struct context *c)
Definition: occ.c:188
bool event_timeout_trigger(struct event_timeout *et, struct timeval *tv, const int et_const_retry)
Definition: interval.c:45
struct event_timeout occ_interval
Definition: openvpn.h:312
static int occ_reset_op(void)
Definition: occ.h:104
static bool event_timeout_defined(const struct event_timeout *et)
Definition: interval.h:144
void check_send_occ_req_dowork(struct context *c)
Definition: occ.c:151
struct timeval timeval
Definition: openvpn.h:401
#define TO_LINK_DEF(c)
Definition: forward.h:48
Interface functions to the internal and external multiplexers.
int delta
Definition: occ.h:78
struct context_2 c2
Level 2 context.
Definition: openvpn.h:539
#define OCC_STRING_SIZE
Definition: occ.h:32
static void check_send_occ_req(struct context *c)
Definition: occ.h:113
unsigned __int8 uint8_t
Definition: config-msvc.h:123
static void check_send_occ_msg(struct context *c)
Definition: occ.h:143
struct event_timeout occ_mtu_load_test_interval
Definition: openvpn.h:329
void check_send_occ_msg_dowork(struct context *c)
Definition: occ.c:218
static bool buf_string_match_head(const struct buffer *src, const void *match, int size)
Compare first size bytes of src buffer contents with match.
Definition: buffer.h:883
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
int op
Definition: occ.h:77
int occ_op
Definition: openvpn.h:310