OpenVPN
forward-inline.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 FORWARD_INLINE_H
25 #define FORWARD_INLINE_H
26 
27 /*
28  * Inline functions
29  */
30 
31 /*
32  * Does TLS session need service?
33  */
34 static inline void
35 check_tls(struct context *c)
36 {
37  void check_tls_dowork(struct context *c);
38 
39  if (c->c2.tls_multi)
40  {
42  }
43 }
44 
45 /*
46  * TLS errors are fatal in TCP mode.
47  * Also check for --tls-exit trigger.
48  */
49 static inline void
51 {
52  void check_tls_errors_co(struct context *c);
53 
54  void check_tls_errors_nco(struct context *c);
55 
56  if (c->c2.tls_multi && c->c2.tls_exit_signal)
57  {
59  {
60  if (c->c2.tls_multi->n_soft_errors)
61  {
63  }
64  }
65  else
66  {
67  if (c->c2.tls_multi->n_hard_errors)
68  {
70  }
71  }
72  }
73 }
74 
75 /*
76  * Check for possible incoming configuration
77  * messages on the control channel.
78  */
79 static inline void
81 {
82 #if P2MP
84 
85  if (tls_test_payload_len(c->c2.tls_multi) > 0)
86  {
88  }
89 #endif
90 }
91 
92 /*
93  * Options like --up-delay need to be triggered by this function which
94  * checks for connection establishment.
95  */
96 static inline void
98 {
100 
102  {
104  }
105 }
106 
107 /*
108  * Should we add routes?
109  */
110 static inline void
112 {
113  void check_add_routes_dowork(struct context *c);
114 
116  {
118  }
119 }
120 
121 /*
122  * Should we exit due to inactivity timeout?
123  */
124 static inline void
126 {
128 
131  {
133  }
134 }
135 
136 #if P2MP
137 
138 static inline void
140 {
142 
143  if (c->options.ce.connect_timeout
145  {
147  }
148 }
149 
150 /*
151  * Scheduled exit?
152  */
153 static inline void
155 {
156  void check_scheduled_exit_dowork(struct context *c);
157 
159  {
161  {
163  }
164  }
165 }
166 #endif /* if P2MP */
167 
168 /*
169  * Should we write timer-triggered status file.
170  */
171 static inline void
173 {
174  void check_status_file_dowork(struct context *c);
175 
176  if (c->c1.status_output)
177  {
179  {
181  }
182  }
183 }
184 
185 #ifdef ENABLE_FRAGMENT
186 /*
187  * Should we deliver a datagram fragment to remote?
188  */
189 static inline void
191 {
192  void check_fragment_dowork(struct context *c);
193 
194  if (c->c2.fragment)
195  {
197  }
198 }
199 #endif
200 
201 #if P2MP
202 
203 /*
204  * see if we should send a push_request in response to --pull
205  */
206 static inline void
208 {
209  void check_push_request_dowork(struct context *c);
210 
212  {
214  }
215 }
216 
217 #endif
218 
219 /*
220  * Should we persist our anti-replay packet ID state to disk?
221  */
222 static inline void
224 {
227  {
229  }
230 }
231 
232 /*
233  * Set our wakeup to 0 seconds, so we will be rescheduled
234  * immediately.
235  */
236 static inline void
238 {
239  c->c2.timeval.tv_sec = 0; /* ZERO-TIMEOUT */
240  c->c2.timeval.tv_usec = 0;
241 }
242 
243 static inline void
244 context_reschedule_sec(struct context *c, int sec)
245 {
246  if (sec < 0)
247  {
248  sec = 0;
249  }
250  if (sec < c->c2.timeval.tv_sec)
251  {
252  c->c2.timeval.tv_sec = sec;
253  c->c2.timeval.tv_usec = 0;
254  }
255 }
256 
257 static inline struct link_socket_info *
259 {
260  if (c->c2.link_socket_info)
261  {
262  return c->c2.link_socket_info;
263  }
264  else
265  {
266  return &c->c2.link_socket->info;
267  }
268 }
269 
270 static inline void
271 register_activity(struct context *c, const int size)
272 {
274  {
275  c->c2.inactivity_bytes += size;
277  {
278  c->c2.inactivity_bytes = 0;
280  }
281  }
282 }
283 
284 /*
285  * Return the io_wait() flags appropriate for
286  * a point-to-point tunnel.
287  */
288 static inline unsigned int
289 p2p_iow_flags(const struct context *c)
290 {
292  if (c->c2.to_link.len > 0)
293  {
294  flags |= IOW_TO_LINK;
295  }
296  if (c->c2.to_tun.len > 0)
297  {
298  flags |= IOW_TO_TUN;
299  }
300  return flags;
301 }
302 
303 /*
304  * This is the core I/O wait function, used for all I/O waits except
305  * for TCP in server mode.
306  */
307 static inline void
308 io_wait(struct context *c, const unsigned int flags)
309 {
310  void io_wait_dowork(struct context *c, const unsigned int flags);
311 
312  if (c->c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF)))
313  {
314  /* fast path -- only for TUN/TAP/UDP writes */
315  unsigned int ret = 0;
316  if (flags & IOW_TO_TUN)
317  {
318  ret |= TUN_WRITE;
319  }
320  if (flags & (IOW_TO_LINK|IOW_MBUF))
321  {
322  ret |= SOCKET_WRITE;
323  }
324  c->c2.event_set_status = ret;
325  }
326  else
327  {
328  /* slow path */
329  io_wait_dowork(c, flags);
330  }
331 }
332 
333 #define CONNECTION_ESTABLISHED(c) (get_link_socket_info(c)->connection_established)
334 
335 #endif /* EVENT_INLINE_H */
void io_wait_dowork(struct context *c, const unsigned int flags)
Definition: forward.c:1602
void check_server_poll_timeout_dowork(struct context *c)
Definition: forward.c:347
struct buffer to_link
Definition: openvpn.h:382
#define ETT_DEFAULT
Definition: interval.h:213
struct event_timeout route_wakeup
Definition: openvpn.h:388
void check_tls_dowork(struct context *c)
Definition: forward.c:91
struct options options
Options loaded from command line or configuration file.
Definition: openvpn.h:500
Contains all state information for one tunnel.
Definition: openvpn.h:498
static void context_reschedule_sec(struct context *c, int sec)
bool status_trigger_tv(struct status_output *so, struct timeval *tv)
Definition: status.c:150
static int tls_test_payload_len(const struct tls_multi *multi)
Definition: ssl.h:545
struct event_timeout wait_for_connect
Definition: openvpn.h:295
int inactivity_minimum_bytes
Definition: options.h:257
struct link_socket_info * link_socket_info
Definition: openvpn.h:252
#define IOW_SHAPER
Definition: forward.h:54
static void check_packet_id_persist_flush(struct context *c)
void check_status_file_dowork(struct context *c)
Definition: forward.c:388
static void check_scheduled_exit(struct context *c)
#define IOW_TO_LINK
Definition: forward.h:51
static bool link_socket_connection_oriented(const struct link_socket *sock)
Definition: socket.h:606
static void check_incoming_control_channel(struct context *c)
list flags
int len
Length in bytes of the actual content within the allocated memory.
Definition: buffer.h:66
struct context_1 c1
Level 1 context.
Definition: openvpn.h:536
#define IOW_TO_TUN
Definition: forward.h:50
struct event_timeout inactivity_interval
Definition: openvpn.h:300
static void event_timeout_reset(struct event_timeout *et)
Definition: interval.h:174
bool event_timeout_trigger(struct event_timeout *et, struct timeval *tv, const int et_const_retry)
Definition: interval.c:45
int inactivity_bytes
Definition: openvpn.h:301
#define IOW_MBUF
Definition: forward.h:57
void check_add_routes_dowork(struct context *c)
Definition: forward.c:293
static bool event_timeout_defined(const struct event_timeout *et)
Definition: interval.h:144
int n_hard_errors
Definition: ssl_common.h:525
struct timeval timeval
Definition: openvpn.h:399
static void check_add_routes(struct context *c)
static void check_inactivity_timeout(struct context *c)
#define IOW_FRAG
Definition: forward.h:56
static void register_activity(struct context *c, const int size)
struct event_timeout scheduled_exit
Definition: openvpn.h:468
int n_soft_errors
Definition: ssl_common.h:526
struct link_socket * link_socket
Definition: openvpn.h:250
void check_fragment_dowork(struct context *c)
Definition: forward.c:401
static void check_status_file(struct context *c)
struct connection_entry ce
Definition: options.h:208
struct context_2 c2
Level 2 context.
Definition: openvpn.h:537
void check_push_request_dowork(struct context *c)
Definition: forward.c:190
#define IOW_WAIT_SIGNAL
Definition: forward.h:59
int inactivity_timeout
Definition: options.h:256
struct event_timeout packet_id_persist_interval
Definition: openvpn.h:360
struct event_timeout push_request_interval
Definition: openvpn.h:459
static void check_tls_errors(struct context *c)
void check_scheduled_exit_dowork(struct context *c)
Definition: forward.c:377
void check_incoming_control_channel_dowork(struct context *c)
Definition: forward.c:141
int connect_timeout
Definition: options.h:101
static void check_push_request(struct context *c)
static void check_fragment(struct context *c)
struct fragment_master * fragment
Definition: openvpn.h:264
#define IOW_CHECK_RESIDUAL
Definition: forward.h:55
void check_tls_errors_co(struct context *c)
Definition: forward.c:122
struct status_output * status_output
Definition: openvpn.h:178
struct packet_id_persist pid_persist
Definition: openvpn.h:163
struct event_timeout server_poll_interval
Definition: openvpn.h:411
static void context_immediate_reschedule(struct context *c)
#define TUN_WRITE
Definition: openvpn.h:237
static unsigned int p2p_iow_flags(const struct context *c)
bool fast_io
Definition: openvpn.h:429
#define SOCKET_WRITE
Definition: openvpn.h:235
void check_connection_established_dowork(struct context *c)
Definition: forward.c:204
static bool packet_id_persist_enabled(const struct packet_id_persist *p)
Definition: packet_id.h:281
static void check_connection_established(struct context *c)
void check_inactivity_timeout_dowork(struct context *c)
Definition: forward.c:331
void packet_id_persist_save(struct packet_id_persist *p)
Definition: packet_id.c:482
struct buffer to_tun
Definition: openvpn.h:381
void check_tls_errors_nco(struct context *c)
Definition: forward.c:129
static void check_tls(struct context *c)
static void io_wait(struct context *c, const unsigned int flags)
unsigned int event_set_status
Definition: openvpn.h:248
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition: openvpn.h:334
static void check_server_poll_timeout(struct context *c)
static struct link_socket_info * get_link_socket_info(struct context *c)
int tls_exit_signal
Definition: openvpn.h:352
#define IOW_READ
Definition: forward.h:61