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