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-2023 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#ifdef _WIN32
195 {
197 {
198 /* there is data in wintun ring buffer, read it immediately */
199 m->multi_io->esr[0].arg = MULTI_IO_TUN;
201 m->multi_io->n_esr = 1;
202 return 1;
203 }
204 persistent = NULL;
205 }
206#endif
207 tun_set(m->top.c1.tuntap, m->multi_io->es, EVENT_READ, MULTI_IO_TUN, persistent);
208#if defined(ENABLE_DCO) \
209 && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(TARGET_WIN32))
211#endif
212
213#ifdef ENABLE_MANAGEMENT
214 if (management)
215 {
217 }
218#endif
219
220#ifdef ENABLE_ASYNC_PUSH
221 /* arm inotify watcher */
223#endif
224
226 update_time();
227 m->multi_io->n_esr = 0;
228 if (status > 0)
229 {
230 m->multi_io->n_esr = status;
231 }
232 return status;
233}
234
235static int
236multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, const int action, bool *tun_input_pending)
237{
238 struct context *c = multi_get_context(m, mi);
239 unsigned int looking_for = 0;
240
241 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=%s mi=" ptr_format,
242 pract(action),
243 (ptr_type)mi);
244
245 tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */
246
247 switch (action)
248 {
249 case TA_TUN_READ:
250 looking_for = TUN_READ;
251 tun_input_pending = NULL;
253 break;
254
255 case TA_SOCKET_READ:
256 looking_for = SOCKET_READ;
257 tun_input_pending = NULL;
259 break;
260
261 case TA_TUN_WRITE:
262 looking_for = TUN_WRITE;
263 tun_input_pending = NULL;
264 c->c2.timeval.tv_sec = 1; /* For some reason, the Linux 2.2 TUN/TAP driver hits this timeout */
267 perf_pop();
268 break;
269
270 case TA_SOCKET_WRITE:
271 looking_for = SOCKET_WRITE;
273 break;
274
275 default:
276 msg(M_FATAL, "MULTI IO: multi_io_wait_lite, unhandled action=%d", action);
277 }
278
279 if (tun_input_pending && (c->c2.event_set_status & TUN_READ))
280 {
281 *tun_input_pending = true;
282 }
283
284 if (c->c2.event_set_status & looking_for)
285 {
286 return action;
287 }
288 else
289 {
290 switch (action)
291 {
292 /* MULTI PROTOCOL socket output buffer is full */
293 case TA_SOCKET_WRITE:
295
296 /* TUN device timed out on accepting write */
297 case TA_TUN_WRITE:
299 }
300
301 return TA_UNDEF;
302 }
303}
304
305static struct multi_instance *
306multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
307{
308 const unsigned int mpp_flags = MPP_PRE_SELECT|MPP_RECORD_TOUCH;
309 struct multi_instance *touched = mi;
310 m->mpp_touched = &touched;
311
312 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=%s mi=" ptr_format,
313 pract(action),
314 (ptr_type)mi);
315
316 switch (action)
317 {
318 case TA_TUN_READ:
320 if (!IS_SIG(&m->top))
321 {
322 multi_process_incoming_tun(m, mpp_flags);
323 }
324 break;
325
326 case TA_SOCKET_READ:
328 ASSERT(mi);
331 set_prefix(mi);
333 clear_prefix();
334 if (!IS_SIG(&mi->context))
335 {
336 multi_process_incoming_link(m, mi, mpp_flags,
337 mi->context.c2.link_sockets[0]);
338 if (!IS_SIG(&mi->context))
339 {
341 }
342 }
343 break;
344
345 case TA_TIMEOUT:
346 multi_process_timeout(m, mpp_flags);
347 break;
348
349 case TA_TUN_WRITE:
350 multi_process_outgoing_tun(m, mpp_flags);
351 break;
352
355 break;
356
358 ASSERT(mi);
360 break;
361
362 case TA_SOCKET_WRITE:
363 multi_tcp_process_outgoing_link(m, false, mpp_flags);
364 break;
365
367 multi_tcp_process_outgoing_link(m, true, mpp_flags);
368 break;
369
370 case TA_INITIAL:
371 ASSERT(mi);
373 multi_process_post(m, mi, mpp_flags);
374 break;
375
376 default:
377 msg(M_FATAL, "MULTI IO: multi_io_dispatch, unhandled action=%d", action);
378 }
379
380 m->mpp_touched = NULL;
381 return touched;
382}
383
384static int
385multi_io_post(struct multi_context *m, struct multi_instance *mi, const int action)
386{
387 struct context *c = multi_get_context(m, mi);
388 int newaction = TA_UNDEF;
389
390#define MTP_NONE 0
391#define MTP_TUN_OUT (1<<0)
392#define MTP_LINK_OUT (1<<1)
393 unsigned int flags = MTP_NONE;
394
395 if (TUN_OUT(c))
396 {
397 flags |= MTP_TUN_OUT;
398 }
399 if (LINK_OUT(c))
400 {
401 flags |= MTP_LINK_OUT;
402 }
403
404 switch (flags)
405 {
407 case MTP_TUN_OUT:
408 newaction = TA_TUN_WRITE;
409 break;
410
411 case MTP_LINK_OUT:
412 newaction = TA_SOCKET_WRITE;
413 break;
414
415 case MTP_NONE:
416 if (mi && sockets_read_residual(c))
417 {
418 newaction = TA_SOCKET_READ_RESIDUAL;
419 }
420 else
421 {
423 }
424 break;
425
426 default:
427 {
428 struct gc_arena gc = gc_new();
429 msg(M_FATAL, "MULTI IO: multi_io_post bad state, mi=%s flags=%d",
430 multi_instance_string(mi, false, &gc),
431 flags);
432 gc_free(&gc);
433 break;
434 }
435 }
436
437 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_post %s -> %s",
438 pract(action),
439 pract(newaction));
440
441 return newaction;
442}
443
444void
446{
447 struct multi_io *multi_io = m->multi_io;
448 int i;
449
450 for (i = 0; i < multi_io->n_esr; ++i)
451 {
452 struct event_set_return *e = &multi_io->esr[i];
453 struct event_arg *ev_arg = (struct event_arg *)e->arg;
454
455 /* incoming data for instance or listening socket? */
456 if (e->arg >= MULTI_N)
457 {
458 switch (ev_arg->type)
459 {
460 struct multi_instance *mi;
461
462 /* react to event on child instance */
464 if (!ev_arg->u.mi)
465 {
466 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null minstance");
467 break;
468 }
469
470 mi = ev_arg->u.mi;
471 if (e->rwflags & EVENT_WRITE)
472 {
474 }
475 else if (e->rwflags & EVENT_READ)
476 {
477 multi_io_action(m, mi, TA_SOCKET_READ, false);
478 }
479 break;
480
482 if (!ev_arg->u.sock)
483 {
484 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null socket");
485 break;
486 }
487 /* new incoming TCP client attempting to connect? */
489 {
492 }
493 else
494 {
496 mi = m->pending;
497 }
498 /* monitor and/or handle events that are
499 * triggered in succession by the first one
500 * before returning to the main loop. */
501 if (mi)
502 {
503 multi_io_action(m, mi, TA_INITIAL, false);
504 }
505 break;
506 }
507 }
508 else
509 {
510#ifdef ENABLE_MANAGEMENT
511 if (e->arg == MULTI_IO_MANAGEMENT)
512 {
515 }
516 else
517#endif
518 /* incoming data on TUN? */
519 if (e->arg == MULTI_IO_TUN)
520 {
521 if (e->rwflags & EVENT_WRITE)
522 {
523 multi_io_action(m, NULL, TA_TUN_WRITE, false);
524 }
525 else if (e->rwflags & EVENT_READ)
526 {
527 multi_io_action(m, NULL, TA_TUN_READ, false);
528 }
529 }
530 /* new incoming TCP client attempting to connect? */
531 else if (e->arg == MULTI_IO_SOCKET)
532 {
533 struct multi_instance *mi;
534 ASSERT(m->top.c2.link_sockets[0]);
537 if (mi)
538 {
539 multi_io_action(m, mi, TA_INITIAL, false);
540 }
541 }
542#if defined(ENABLE_DCO) \
543 && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(TARGET_WIN32))
544 /* incoming data on DCO? */
545 else if (e->arg == MULTI_IO_DCO)
546 {
548 }
549#endif
550 /* signal received? */
551 else if (e->arg == MULTI_IO_SIG)
552 {
554 }
555#ifdef ENABLE_ASYNC_PUSH
556 else if (e->arg == MULTI_IO_FILE_CLOSE_WRITE)
557 {
558 multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_TOUCH);
559 }
560#endif
561 }
562 if (IS_SIG(&m->top))
563 {
564 break;
565 }
566 }
567 multi_io->n_esr = 0;
568
569 /*
570 * Process queued mbuf packets destined for TCP socket
571 */
572 {
573 struct multi_instance *mi;
574 while (!IS_SIG(&m->top) && (mi = mbuf_peek(m->mbuf)) != NULL)
575 {
576 multi_io_action(m, mi, TA_SOCKET_WRITE, true);
577 }
578 }
579}
580
581void
582multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
583{
584 bool tun_input_pending = false;
585
586 do
587 {
588 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_action a=%s p=%d",
589 pract(action),
590 poll);
591
592 /*
593 * If TA_SOCKET_READ_RESIDUAL, it means we still have pending
594 * input packets which were read by a prior recv.
595 *
596 * Otherwise do a "lite" wait, which means we wait with 0 timeout
597 * on I/O events only related to the current instance, not
598 * the big list of events.
599 *
600 * On our first pass, poll will be false because we already know
601 * that input is available, and to call io_wait would be redundant.
602 */
603 if (poll && action != TA_SOCKET_READ_RESIDUAL)
604 {
605 const int orig_action = action;
606 action = multi_io_wait_lite(m, mi, action, &tun_input_pending);
607 if (action == TA_UNDEF)
608 {
609 msg(M_FATAL, "MULTI IO: I/O wait required blocking in multi_io_action, action=%d", orig_action);
610 }
611 }
612
613 /*
614 * Dispatch the action
615 */
616 struct multi_instance *touched = multi_io_dispatch(m, mi, action);
617
618 /*
619 * Signal received or connection
620 * reset by peer?
621 */
622 if (touched && IS_SIG(&touched->context))
623 {
624 if (mi == touched)
625 {
626 mi = NULL;
627 }
629 }
630
631
632 /*
633 * If dispatch produced any pending output
634 * for a particular instance, point to
635 * that instance.
636 */
637 if (m->pending)
638 {
639 mi = m->pending;
640 }
641
642 /*
643 * Based on the effects of the action,
644 * such as generating pending output,
645 * possibly transition to a new action state.
646 */
647 action = multi_io_post(m, mi, action);
648
649 /*
650 * If we are finished processing the original action,
651 * check if we have any TUN input. If so, transition
652 * our action state to processing this input.
653 */
654 if (tun_input_pending && action == TA_UNDEF)
655 {
656 action = TA_TUN_READ;
657 mi = NULL;
658 tun_input_pending = false;
659 poll = false;
660 }
661 else
662 {
663 poll = true;
664 }
665
666 } while (action != TA_UNDEF);
667}
668
669void
671{
672 if (multi_io && multi_io->es)
673 {
674 event_del(multi_io->es, event);
675 }
676}
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:2201
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:377
#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:3422
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:1299
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:3626
#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:53
void management_socket_set(struct management *man, struct event_set *es, void *arg, unsigned int *persistent)
Definition manage.c:3127
void management_io(struct management *man)
Definition manage.c:3167
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:3293
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:3118
bool multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
Definition multi.c:3755
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:3786
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:445
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:236
#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:306
void multi_io_delete_event(struct multi_io *multi_io, event_t event)
Definition multi_io.c:670
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:385
void multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
Definition multi_io.c:582
#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:9566
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:4019
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:157
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:171
unsigned int event_set_status
Definition openvpn.h:235
struct link_socket ** link_sockets
Definition openvpn.h:237
struct timeval timeval
Time to next event of timers and similar.
Definition openvpn.h:396
Contains all state information for one tunnel.
Definition openvpn.h:474
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:500
struct context_2 c2
Level 2 context.
Definition openvpn.h:514
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:475
struct context_1 c1
Level 1 context.
Definition openvpn.h:513
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:250
struct gc_arena gc
Definition test_ssl.c:155
static bool tuntap_is_wintun(struct tuntap *tt)
Definition tun.h:266
static bool tuntap_ring_empty(struct tuntap *tt)
Definition tun.h:272
static bool tuntap_is_dco_win(struct tuntap *tt)
Definition tun.h:683
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition tun.h:749