OpenVPN
multi_io.c
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-2025 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#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include "syshead.h"
29
30#include "memdbg.h"
31
32#include "multi.h"
33#include "forward.h"
34#include "multi_io.h"
35
36#ifdef HAVE_SYS_INOTIFY_H
37#include <sys/inotify.h>
38#endif
39
40/*
41 * Special tags passed to event.[ch] functions
42 */
43#define MULTI_IO_SOCKET ((void *)1)
44#define MULTI_IO_TUN ((void *)2)
45#define MULTI_IO_SIG ((void *)3) /* Only on Windows */
46#define MULTI_IO_MANAGEMENT ((void *)4)
47#define MULTI_IO_FILE_CLOSE_WRITE ((void *)5)
48#define MULTI_IO_DCO ((void *)6)
49
50struct ta_iow_flags
51{
52 unsigned int flags;
53 unsigned int ret;
54 unsigned int tun;
55 unsigned int sock;
56};
57
58#ifdef ENABLE_DEBUG
59static const char *
60pract(int action)
61{
62 switch (action)
63 {
64 case TA_UNDEF:
65 return "TA_UNDEF";
66
67 case TA_SOCKET_READ:
68 return "TA_SOCKET_READ";
69
71 return "TA_SOCKET_READ_RESIDUAL";
72
73 case TA_SOCKET_WRITE:
74 return "TA_SOCKET_WRITE";
75
77 return "TA_SOCKET_WRITE_READY";
78
80 return "TA_SOCKET_WRITE_DEFERRED";
81
82 case TA_TUN_READ:
83 return "TA_TUN_READ";
84
85 case TA_TUN_WRITE:
86 return "TA_TUN_WRITE";
87
88 case TA_INITIAL:
89 return "TA_INITIAL";
90
91 case TA_TIMEOUT:
92 return "TA_TIMEOUT";
93
95 return "TA_TUN_WRITE_TIMEOUT";
96
97 default:
98 return "?";
99 }
100}
101#endif /* ENABLE_DEBUG */
102
103static inline struct context *
105{
106 if (mi)
107 {
108 return &mi->context;
109 }
110 else
111 {
112 return &m->top;
113 }
114}
115
116struct multi_io *
117multi_io_init(int maxevents, int *maxclients)
118{
119 struct multi_io *multi_io;
120 const int extra_events = BASE_N_EVENTS;
121
122 ASSERT(maxevents >= 1);
123 ASSERT(maxclients);
124
126 multi_io->maxevents = maxevents + extra_events;
130 *maxclients = max_int(min_int(multi_io->maxevents - extra_events, *maxclients), 1);
131 msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", *maxclients, multi_io->maxevents);
132 return multi_io;
133}
134
135void
137{
138 if (!mi)
139 {
140 return;
141 }
142
143 mi->socket_set_called = true;
145 {
147 m->multi_io->es,
149 &mi->context.c2.link_sockets[0]->ev_arg,
150 NULL);
151 }
152 else
153 {
155 m->multi_io->es,
157 &mi->ev_arg,
158 &mi->tcp_rwflags);
159 }
160}
161
162void
164{
165 if (multi_io)
166 {
168 free(multi_io->esr);
169 free(multi_io);
170 }
171}
172
173int
175{
176 int status, i;
177 unsigned int *persistent = &m->multi_io->tun_rwflags;
178
180 {
181 for (i = 0; i < m->top.c1.link_sockets_num; i++)
182 {
184 &m->top.c2.link_sockets[i]->ev_arg);
185 }
186 }
187
189 {
191 }
192
193 tun_set(m->top.c1.tuntap, m->multi_io->es, EVENT_READ, MULTI_IO_TUN, persistent);
194#if defined(ENABLE_DCO) \
195 && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(TARGET_WIN32))
197#endif
198
199#ifdef ENABLE_MANAGEMENT
200 if (management)
201 {
203 }
204#endif
205
206#ifdef ENABLE_ASYNC_PUSH
207 /* arm inotify watcher */
209#endif
210
212 update_time();
213 m->multi_io->n_esr = 0;
214 if (status > 0)
215 {
216 m->multi_io->n_esr = status;
217 }
218 return status;
219}
220
221static int
222multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, const int action, bool *tun_input_pending)
223{
224 struct context *c = multi_get_context(m, mi);
225 unsigned int looking_for = 0;
226
227 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=%s mi=" ptr_format,
228 pract(action),
229 (ptr_type)mi);
230
231 tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */
232
233 switch (action)
234 {
235 case TA_TUN_READ:
236 looking_for = TUN_READ;
237 tun_input_pending = NULL;
239 break;
240
241 case TA_SOCKET_READ:
242 looking_for = SOCKET_READ;
243 tun_input_pending = NULL;
245 break;
246
247 case TA_TUN_WRITE:
248 looking_for = TUN_WRITE;
249 tun_input_pending = NULL;
250 /* For some reason, the Linux 2.2 TUN/TAP driver hits this timeout */
251 c->c2.timeval.tv_sec = 1;
254 perf_pop();
255 break;
256
257 case TA_SOCKET_WRITE:
258 looking_for = SOCKET_WRITE;
260 break;
261
262 default:
263 msg(M_FATAL, "MULTI IO: multi_io_wait_lite, unhandled action=%d", action);
264 }
265
266 if (tun_input_pending && (c->c2.event_set_status & TUN_READ))
267 {
268 *tun_input_pending = true;
269 }
270
271 if (c->c2.event_set_status & looking_for)
272 {
273 return action;
274 }
275 else
276 {
277 switch (action)
278 {
279 /* MULTI PROTOCOL socket output buffer is full */
280 case TA_SOCKET_WRITE:
282
283 /* TUN device timed out on accepting write */
284 case TA_TUN_WRITE:
286 }
287
288 return TA_UNDEF;
289 }
290}
291
292static struct multi_instance *
293multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
294{
295 const unsigned int mpp_flags = MPP_PRE_SELECT|MPP_RECORD_TOUCH;
296 struct multi_instance *touched = mi;
297 m->mpp_touched = &touched;
298
299 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=%s mi=" ptr_format,
300 pract(action),
301 (ptr_type)mi);
302
303 switch (action)
304 {
305 case TA_TUN_READ:
307 if (!IS_SIG(&m->top))
308 {
309 multi_process_incoming_tun(m, mpp_flags);
310 }
311 break;
312
313 case TA_SOCKET_READ:
315 ASSERT(mi);
318 set_prefix(mi);
320 clear_prefix();
321 if (!IS_SIG(&mi->context))
322 {
323 multi_process_incoming_link(m, mi, mpp_flags,
324 mi->context.c2.link_sockets[0]);
325 if (!IS_SIG(&mi->context))
326 {
328 }
329 }
330 break;
331
332 case TA_TIMEOUT:
333 multi_process_timeout(m, mpp_flags);
334 break;
335
336 case TA_TUN_WRITE:
337 multi_process_outgoing_tun(m, mpp_flags);
338 break;
339
342 break;
343
345 ASSERT(mi);
347 break;
348
349 case TA_SOCKET_WRITE:
350 multi_tcp_process_outgoing_link(m, false, mpp_flags);
351 break;
352
354 multi_tcp_process_outgoing_link(m, true, mpp_flags);
355 break;
356
357 case TA_INITIAL:
358 ASSERT(mi);
360 multi_process_post(m, mi, mpp_flags);
361 break;
362
363 default:
364 msg(M_FATAL, "MULTI IO: multi_io_dispatch, unhandled action=%d", action);
365 }
366
367 m->mpp_touched = NULL;
368 return touched;
369}
370
371static int
372multi_io_post(struct multi_context *m, struct multi_instance *mi, const int action)
373{
374 struct context *c = multi_get_context(m, mi);
375 int newaction = TA_UNDEF;
376
377#define MTP_NONE 0
378#define MTP_TUN_OUT (1<<0)
379#define MTP_LINK_OUT (1<<1)
380 unsigned int flags = MTP_NONE;
381
382 if (TUN_OUT(c))
383 {
384 flags |= MTP_TUN_OUT;
385 }
386 if (LINK_OUT(c))
387 {
388 flags |= MTP_LINK_OUT;
389 }
390
391 switch (flags)
392 {
394 case MTP_TUN_OUT:
395 newaction = TA_TUN_WRITE;
396 break;
397
398 case MTP_LINK_OUT:
399 newaction = TA_SOCKET_WRITE;
400 break;
401
402 case MTP_NONE:
403 if (mi && sockets_read_residual(c))
404 {
405 newaction = TA_SOCKET_READ_RESIDUAL;
406 }
407 else
408 {
410 }
411 break;
412
413 default:
414 {
415 struct gc_arena gc = gc_new();
416 msg(M_FATAL, "MULTI IO: multi_io_post bad state, mi=%s flags=%d",
417 multi_instance_string(mi, false, &gc),
418 flags);
419 gc_free(&gc);
420 break;
421 }
422 }
423
424 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_post %s -> %s",
425 pract(action),
426 pract(newaction));
427
428 return newaction;
429}
430
431void
433{
434 struct multi_io *multi_io = m->multi_io;
435 int i;
436
437 for (i = 0; i < multi_io->n_esr; ++i)
438 {
439 struct event_set_return *e = &multi_io->esr[i];
440 struct event_arg *ev_arg = (struct event_arg *)e->arg;
441
442 /* incoming data for instance or listening socket? */
443 if (e->arg >= MULTI_N)
444 {
445 switch (ev_arg->type)
446 {
447 struct multi_instance *mi;
448
449 /* react to event on child instance */
451 if (!ev_arg->u.mi)
452 {
453 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null minstance");
454 break;
455 }
456
457 mi = ev_arg->u.mi;
458 if (e->rwflags & EVENT_WRITE)
459 {
461 }
462 else if (e->rwflags & EVENT_READ)
463 {
464 multi_io_action(m, mi, TA_SOCKET_READ, false);
465 }
466 break;
467
469 if (!ev_arg->u.sock)
470 {
471 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null socket");
472 break;
473 }
474 /* new incoming TCP client attempting to connect? */
476 {
479 }
480 else
481 {
483 mi = m->pending;
484 }
485 /* monitor and/or handle events that are
486 * triggered in succession by the first one
487 * before returning to the main loop. */
488 if (mi)
489 {
490 multi_io_action(m, mi, TA_INITIAL, false);
491 }
492 break;
493 }
494 }
495 else
496 {
497#ifdef ENABLE_MANAGEMENT
498 if (e->arg == MULTI_IO_MANAGEMENT)
499 {
502 }
503 else
504#endif
505 /* incoming data on TUN? */
506 if (e->arg == MULTI_IO_TUN)
507 {
508 if (e->rwflags & EVENT_WRITE)
509 {
510 multi_io_action(m, NULL, TA_TUN_WRITE, false);
511 }
512 else if (e->rwflags & EVENT_READ)
513 {
514 multi_io_action(m, NULL, TA_TUN_READ, false);
515 }
516 }
517 /* new incoming TCP client attempting to connect? */
518 else if (e->arg == MULTI_IO_SOCKET)
519 {
520 struct multi_instance *mi;
521 ASSERT(m->top.c2.link_sockets[0]);
524 if (mi)
525 {
526 multi_io_action(m, mi, TA_INITIAL, false);
527 }
528 }
529#if defined(ENABLE_DCO) \
530 && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(TARGET_WIN32))
531 /* incoming data on DCO? */
532 else if (e->arg == MULTI_IO_DCO)
533 {
535 }
536#endif
537 /* signal received? */
538 else if (e->arg == MULTI_IO_SIG)
539 {
541 }
542#ifdef ENABLE_ASYNC_PUSH
543 else if (e->arg == MULTI_IO_FILE_CLOSE_WRITE)
544 {
545 multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_TOUCH);
546 }
547#endif
548 }
549 if (IS_SIG(&m->top))
550 {
551 break;
552 }
553 }
554 multi_io->n_esr = 0;
555
556 /*
557 * Process queued mbuf packets destined for TCP socket
558 */
559 {
560 struct multi_instance *mi;
561 while (!IS_SIG(&m->top) && (mi = mbuf_peek(m->mbuf)) != NULL)
562 {
563 multi_io_action(m, mi, TA_SOCKET_WRITE, true);
564 }
565 }
566}
567
568void
569multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
570{
571 bool tun_input_pending = false;
572
573 do
574 {
575 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_action a=%s p=%d",
576 pract(action),
577 poll);
578
579 /*
580 * If TA_SOCKET_READ_RESIDUAL, it means we still have pending
581 * input packets which were read by a prior recv.
582 *
583 * Otherwise do a "lite" wait, which means we wait with 0 timeout
584 * on I/O events only related to the current instance, not
585 * the big list of events.
586 *
587 * On our first pass, poll will be false because we already know
588 * that input is available, and to call io_wait would be redundant.
589 */
590 if (poll && action != TA_SOCKET_READ_RESIDUAL)
591 {
592 const int orig_action = action;
593 action = multi_io_wait_lite(m, mi, action, &tun_input_pending);
594 if (action == TA_UNDEF)
595 {
596 msg(M_FATAL, "MULTI IO: I/O wait required blocking in multi_io_action, action=%d", orig_action);
597 }
598 }
599
600 /*
601 * Dispatch the action
602 */
603 struct multi_instance *touched = multi_io_dispatch(m, mi, action);
604
605 /*
606 * Signal received or connection
607 * reset by peer?
608 */
609 if (touched && IS_SIG(&touched->context))
610 {
611 if (mi == touched)
612 {
613 mi = NULL;
614 }
616 }
617
618
619 /*
620 * If dispatch produced any pending output
621 * for a particular instance, point to
622 * that instance.
623 */
624 if (m->pending)
625 {
626 mi = m->pending;
627 }
628
629 /*
630 * Based on the effects of the action,
631 * such as generating pending output,
632 * possibly transition to a new action state.
633 */
634 action = multi_io_post(m, mi, action);
635
636 /*
637 * If we are finished processing the original action,
638 * check if we have any TUN input. If so, transition
639 * our action state to processing this input.
640 */
641 if (tun_input_pending && action == TA_UNDEF)
642 {
643 action = TA_TUN_READ;
644 mi = NULL;
645 tun_input_pending = false;
646 poll = false;
647 }
648 else
649 {
650 poll = true;
651 }
652
653 } while (action != TA_UNDEF);
654}
655
656void
658{
659 if (multi_io && multi_io->es)
660 {
661 event_del(multi_io->es, event);
662 }
663}
static void gc_free(struct gc_arena *a)
Definition buffer.h:1033
#define ALLOC_OBJ_CLEAR(dptr, type)
Definition buffer.h:1060
#define ALLOC_ARRAY(dptr, type, n)
Definition buffer.h:1066
static struct gc_arena gc_new(void)
Definition buffer.h:1025
unsigned long ptr_type
Definition common.h:58
#define ptr_format
Definition common.h:49
static void dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
Definition dco.h:324
#define D_MULTI_ERRORS
Definition errlevel.h:65
#define D_MULTI_DEBUG
Definition errlevel.h:127
#define D_MULTI_LOW
Definition errlevel.h:86
struct event_set * event_set_init(int *maxevents, unsigned int flags)
Definition event.c:1186
#define TUN_WRITE
Definition event.h:66
static void event_free(struct event_set *es)
Definition event.h:160
static void event_del(struct event_set *es, event_t event)
Definition event.h:175
#define SOCKET_READ
Definition event.h:62
static int event_wait(struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen)
Definition event.h:187
#define SOCKET_WRITE
Definition event.h:63
#define EVENT_WRITE
Definition event.h:40
#define MULTI_N
Definition event.h:89
#define EVENT_READ
Definition event.h:39
#define TUN_READ
Definition event.h:65
static void wait_signal(struct event_set *es, void *arg)
Definition event.h:206
@ EVENT_ARG_LINK_SOCKET
Definition event.h:137
@ EVENT_ARG_MULTI_INSTANCE
Definition event.h:136
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
Definition event.h:181
void get_io_flags_udp(struct context *c, struct multi_io *multi_io, const unsigned int flags)
Definition forward.c:2181
Interface functions to the internal and external multiplexers.
#define IOW_READ_TUN
Definition forward.h:57
static void io_wait(struct context *c, const unsigned int flags)
Definition forward.h:371
#define IOW_READ_LINK
Definition forward.h:58
#define LINK_OUT(c)
Definition forward.h:39
#define TUN_OUT(c)
Definition forward.h:38
#define IOW_TO_TUN
Definition forward.h:55
#define IOW_READ_TUN_FORCE
Definition forward.h:63
#define IOW_TO_LINK
Definition forward.h:56
bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags, struct link_socket *sock)
Demultiplex and process a packet received over the external network interface.
Definition multi.c:3426
void read_incoming_link(struct context *c, struct link_socket *sock)
Read a packet from the external network interface.
Definition forward.c:934
void read_incoming_tun(struct context *c)
Read a packet from the virtual tun/tap network interface.
Definition forward.c:1305
static bool multi_process_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags)
Send a packet over the virtual tun/tap network interface to its locally reachable destination.
Definition multi.h:659
bool multi_process_incoming_tun(struct multi_context *m, const unsigned int mpp_flags)
Determine the destination VPN tunnel of a packet received over the virtual tun/tap network interface ...
Definition multi.c:3630
#define BASE_N_EVENTS
Definition init.h:33
static int min_int(int x, int y)
Definition integer.h:102
static int max_int(int x, int y)
Definition integer.h:89
static SERVICE_STATUS status
Definition interactive.c:52
void management_socket_set(struct management *man, struct event_set *es, void *arg, unsigned int *persistent)
Definition manage.c:3128
void management_io(struct management *man)
Definition manage.c:3168
static struct multi_instance * mbuf_peek(struct mbuf_set *ms)
Definition mbuf.h:100
static bool mbuf_defined(const struct mbuf_set *ms)
Definition mbuf.h:80
struct multi_instance * multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock)
Definition mtcp.c:50
bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags)
Definition mtcp.c:177
bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
Definition mtcp.c:153
unsigned int p2mp_iow_flags(const struct multi_context *m)
Definition mudp.c:434
void multi_process_io_udp(struct multi_context *m, struct link_socket *sock)
Definition mudp.c:335
void multi_close_instance_on_signal(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:3297
bool multi_process_post(struct multi_context *m, struct multi_instance *mi, const unsigned int flags)
Perform postprocessing of a VPN tunnel instance.
Definition multi.c:3116
bool multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
Definition multi.c:3759
const char * multi_instance_string(const struct multi_instance *mi, bool null, struct gc_arena *gc)
Definition multi.c:466
void multi_process_drop_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags)
Definition multi.c:3790
Header file for server-mode related structures and functions.
bool multi_process_incoming_dco(struct multi_context *m)
Process an incoming DCO message (from kernel space).
static void set_prefix(struct multi_instance *mi)
Definition multi.h:544
static void clear_prefix(void)
Definition multi.h:556
#define MPP_RECORD_TOUCH
Definition multi.h:295
#define MPP_PRE_SELECT
Definition multi.h:292
#define MULTI_IO_SIG
Definition multi_io.c:45
void multi_io_process_io(struct multi_context *m)
Definition multi_io.c:432
static int multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, const int action, bool *tun_input_pending)
Definition multi_io.c:222
#define MULTI_IO_TUN
Definition multi_io.c:44
struct multi_io * multi_io_init(int maxevents, int *maxclients)
Definition multi_io.c:117
void multi_io_free(struct multi_io *multi_io)
Definition multi_io.c:163
#define MTP_NONE
#define MTP_TUN_OUT
#define MULTI_IO_DCO
Definition multi_io.c:48
#define MTP_LINK_OUT
void multi_io_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi)
Definition multi_io.c:136
int multi_io_wait(struct multi_context *m)
Definition multi_io.c:174
#define MULTI_IO_FILE_CLOSE_WRITE
Definition multi_io.c:47
static struct multi_instance * multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
Definition multi_io.c:293
void multi_io_delete_event(struct multi_io *multi_io, event_t event)
Definition multi_io.c:657
static struct context * multi_get_context(struct multi_context *m, struct multi_instance *mi)
Definition multi_io.c:104
static int multi_io_post(struct multi_context *m, struct multi_instance *mi, const int action)
Definition multi_io.c:372
void multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
Definition multi_io.c:569
#define MULTI_IO_MANAGEMENT
Definition multi_io.c:46
#define MULTI_IO_SOCKET
Definition multi_io.c:43
#define TA_UNDEF
Definition multi_io.h:37
#define TA_SOCKET_WRITE_READY
Definition multi_io.h:41
#define TA_SOCKET_READ_RESIDUAL
Definition multi_io.h:39
#define TA_SOCKET_READ
Definition multi_io.h:38
#define TA_INITIAL
Definition multi_io.h:45
#define TA_TUN_WRITE
Definition multi_io.h:44
#define TA_TIMEOUT
Definition multi_io.h:46
#define TA_SOCKET_WRITE_DEFERRED
Definition multi_io.h:42
#define TA_TUN_WRITE_TIMEOUT
Definition multi_io.h:47
#define TA_TUN_READ
Definition multi_io.h:43
#define TA_SOCKET_WRITE
Definition multi_io.h:40
#define M_FATAL
Definition error.h:89
#define dmsg(flags,...)
Definition error.h:148
#define msg(flags,...)
Definition error.h:144
#define ASSERT(x)
Definition error.h:195
bool has_udp_in_local_list(const struct options *options)
Definition options.c:9677
static void update_time(void)
Definition otime.h:77
static void tv_clear(struct timeval *tv)
Definition otime.h:101
static void perf_push(int type)
Definition perf.h:78
#define PERF_PROC_OUT_TUN_MTCP
Definition perf.h:57
static void perf_pop(void)
Definition perf.h:82
#define IS_SIG(c)
Definition sig.h:48
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
Definition sig.h:110
unsigned int socket_set(struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition socket.c:4029
bool sockets_read_residual(const struct context *c)
Definition socket.c:46
static void socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
Definition socket.h:1278
static bool stream_buf_read_setup(struct link_socket *sock)
Definition socket.h:1009
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition socket.h:1290
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
Definition socket.h:597
int link_sockets_num
Definition openvpn.h:159
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:173
unsigned int event_set_status
Definition openvpn.h:237
struct link_socket ** link_sockets
Definition openvpn.h:239
struct timeval timeval
Time to next event of timers and similar.
Definition openvpn.h:398
Contains all state information for one tunnel.
Definition openvpn.h:476
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:502
struct context_2 c2
Level 2 context.
Definition openvpn.h:516
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:477
struct context_1 c1
Level 1 context.
Definition openvpn.h:515
struct link_socket * sock
Definition event.h:146
struct multi_instance * mi
Definition event.h:145
union event_arg::@1 u
event_arg_t type
Definition event.h:143
unsigned int rwflags
Definition event.h:126
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:117
Main OpenVPN server state structure.
Definition multi.h:163
struct mbuf_set * mbuf
Set of buffers for passing data channel packets between VPN tunnel instances.
Definition multi.h:175
struct multi_io * multi_io
I/O state and events tracker.
Definition multi.h:178
struct context top
Storage structure for process-wide configuration.
Definition multi.h:202
struct multi_instance * pending
Definition multi.h:196
struct multi_instance ** mpp_touched
Definition multi.h:198
Server-mode state structure for one single VPN tunnel.
Definition multi.h:103
struct mbuf_set * tcp_link_out_deferred
Definition multi.h:129
unsigned int tcp_rwflags
Definition multi.h:128
bool socket_set_called
Definition multi.h:130
struct event_arg ev_arg
this struct will store a pointer to either mi or link_socket, depending on the event type,...
Definition multi.h:108
struct context context
The context structure storing state for this VPN tunnel.
Definition multi.h:144
struct event_set * es
Definition multi_io.h:54
int n_esr
Definition multi_io.h:56
struct event_set_return * esr
Definition multi_io.h:55
unsigned int tun_rwflags
Definition multi_io.h:58
int maxevents
Definition multi_io.h:57
unsigned int management_persist_flags
Definition multi_io.h:61
volatile int signal_received
Definition sig.h:43
unsigned int flags
Definition mtcp.c:43
unsigned int ret
Definition mtcp.c:44
unsigned int tun
Definition mtcp.c:45
unsigned int sock
Definition mtcp.c:46
dco_context_t dco
Definition tun.h:244
struct gc_arena gc
Definition test_ssl.c:155
static bool tuntap_is_dco_win(struct tuntap *tt)
Definition tun.h:536
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition tun.h:602