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#ifdef ENABLE_DEBUG
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 /* ENABLE_DEBUG */
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 if (mbuf_defined(m->mbuf))
181 {
182 flags |= IOW_MBUF;
183 }
184 else
185 {
186 flags |= IOW_READ;
187 }
188 return flags;
189}
190
191int
193{
194 int status, i;
195 unsigned int *persistent = &m->multi_io->tun_rwflags;
196
198 {
199 for (i = 0; i < m->top.c1.link_sockets_num; i++)
200 {
202 &m->top.c2.link_sockets[i]->ev_arg);
203 }
204 }
205
207 {
208 for (int i = 0; i < m->top.c1.link_sockets_num; i++)
209 {
210 struct link_socket *sock = m->top.c2.link_sockets[i];
211
212 if ((m->top.options.mode == MODE_SERVER) && proto_is_dgram(sock->info.proto))
213 {
214 unsigned int flags = p2mp_iow_flags(m, sock);
215
216 multi_io_process_flags(&m->top, m->multi_io->es, sock, flags);
217 }
218 }
219 }
220
221 tun_set(m->top.c1.tuntap, m->multi_io->es, EVENT_READ, MULTI_IO_TUN, persistent);
222#if defined(ENABLE_DCO)
224#endif
225
226#ifdef ENABLE_MANAGEMENT
227 if (management)
228 {
231 }
232#endif
233
234#ifdef ENABLE_ASYNC_PUSH
235 /* arm inotify watcher */
237#endif
238
239 status =
241 update_time();
242 m->multi_io->n_esr = 0;
243 if (status > 0)
244 {
245 m->multi_io->n_esr = status;
246 }
247 return status;
248}
249
250static int
251multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, const int action,
252 bool *tun_input_pending)
253{
254 struct context *c = multi_get_context(m, mi);
255 unsigned int looking_for = 0;
256
257 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=%s mi=" ptr_format, pract(action),
258 (ptr_type)mi);
259
260 tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */
261
262 switch (action)
263 {
264 case TA_TUN_READ:
265 looking_for = TUN_READ;
266 tun_input_pending = NULL;
268 break;
269
270 case TA_SOCKET_READ:
271 looking_for = SOCKET_READ;
272 tun_input_pending = NULL;
274 break;
275
276 case TA_TUN_WRITE:
277 looking_for = TUN_WRITE;
278 tun_input_pending = NULL;
279 /* For some reason, the Linux 2.2 TUN/TAP driver hits this timeout */
280 c->c2.timeval.tv_sec = 1;
282 break;
283
284 case TA_SOCKET_WRITE:
285 looking_for = SOCKET_WRITE;
287 break;
288
289 default:
290 msg(M_FATAL, "MULTI IO: multi_io_wait_lite, unhandled action=%d", action);
291 }
292
293 if (tun_input_pending && (c->c2.event_set_status & TUN_READ))
294 {
295 *tun_input_pending = true;
296 }
297
298 if (c->c2.event_set_status & looking_for)
299 {
300 return action;
301 }
302 else
303 {
304 switch (action)
305 {
306 /* MULTI PROTOCOL socket output buffer is full */
307 case TA_SOCKET_WRITE:
309
310 /* TUN device timed out on accepting write */
311 case TA_TUN_WRITE:
313 }
314
315 return TA_UNDEF;
316 }
317}
318
319static struct multi_instance *
320multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
321{
322 const unsigned int mpp_flags = MPP_PRE_SELECT | MPP_RECORD_TOUCH;
323 struct multi_instance *touched = mi;
324 m->mpp_touched = &touched;
325
326 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=%s mi=" ptr_format, pract(action),
327 (ptr_type)mi);
328
329 switch (action)
330 {
331 case TA_TUN_READ:
333 if (!IS_SIG(&m->top))
334 {
335 multi_process_incoming_tun(m, mpp_flags);
336 }
337 break;
338
339 case TA_SOCKET_READ:
341 ASSERT(mi);
344 set_prefix(mi);
346 clear_prefix();
347 if (!IS_SIG(&mi->context))
348 {
349 multi_process_incoming_link(m, mi, mpp_flags, mi->context.c2.link_sockets[0]);
350 if (!IS_SIG(&mi->context))
351 {
353 }
354 }
355 break;
356
357 case TA_TIMEOUT:
358 multi_process_timeout(m, mpp_flags);
359 break;
360
361 case TA_TUN_WRITE:
362 multi_process_outgoing_tun(m, mpp_flags);
363 break;
364
367 break;
368
370 ASSERT(mi);
372 break;
373
374 case TA_SOCKET_WRITE:
375 multi_tcp_process_outgoing_link(m, false, mpp_flags);
376 break;
377
379 multi_tcp_process_outgoing_link(m, true, mpp_flags);
380 break;
381
382 case TA_INITIAL:
383 ASSERT(mi);
385 multi_process_post(m, mi, mpp_flags);
386 break;
387
388 default:
389 msg(M_FATAL, "MULTI IO: multi_io_dispatch, unhandled action=%d", action);
390 }
391
392 m->mpp_touched = NULL;
393 return touched;
394}
395
396static int
397multi_io_post(struct multi_context *m, struct multi_instance *mi, const int action)
398{
399 struct context *c = multi_get_context(m, mi);
400 int newaction = TA_UNDEF;
401
402#define MTP_NONE 0
403#define MTP_TUN_OUT (1 << 0)
404#define MTP_LINK_OUT (1 << 1)
405 unsigned int flags = MTP_NONE;
406
407 if (TUN_OUT(c))
408 {
409 flags |= MTP_TUN_OUT;
410 }
411 if (LINK_OUT(c))
412 {
413 flags |= MTP_LINK_OUT;
414 }
415
416 switch (flags)
417 {
419 case MTP_TUN_OUT:
420 newaction = TA_TUN_WRITE;
421 break;
422
423 case MTP_LINK_OUT:
424 newaction = TA_SOCKET_WRITE;
425 break;
426
427 case MTP_NONE:
428 if (mi && sockets_read_residual(c))
429 {
430 newaction = TA_SOCKET_READ_RESIDUAL;
431 }
432 else
433 {
435 }
436 break;
437
438 default:
439 {
440 struct gc_arena gc = gc_new();
441 msg(M_FATAL, "MULTI IO: multi_io_post bad state, mi=%s flags=%d",
442 multi_instance_string(mi, false, &gc), flags);
443 gc_free(&gc);
444 break;
445 }
446 }
447
448 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_post %s -> %s", pract(action), pract(newaction));
449
450 return newaction;
451}
452
453void
455{
456 struct multi_io *multi_io = m->multi_io;
457 int i;
458
459 for (i = 0; i < multi_io->n_esr; ++i)
460 {
461 struct event_set_return *e = &multi_io->esr[i];
462 struct event_arg *ev_arg = (struct event_arg *)e->arg;
463
464 /* incoming data for instance or listening socket? */
465 if (e->arg >= MULTI_N)
466 {
467 switch (ev_arg->type)
468 {
469 struct multi_instance *mi;
470
471 /* react to event on child instance */
473 if (!ev_arg->u.mi)
474 {
475 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null minstance");
476 break;
477 }
478
479 mi = ev_arg->u.mi;
480 if (e->rwflags & EVENT_WRITE)
481 {
483 }
484 else if (e->rwflags & EVENT_READ)
485 {
486 multi_io_action(m, mi, TA_SOCKET_READ, false);
487 }
488 break;
489
491 if (!ev_arg->u.sock)
492 {
493 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null socket");
494 break;
495 }
496 /* new incoming TCP client attempting to connect? */
498 {
501 }
502 else
503 {
505 mi = m->pending;
506 }
507 /* monitor and/or handle events that are
508 * triggered in succession by the first one
509 * before returning to the main loop. */
510 if (mi)
511 {
512 multi_io_action(m, mi, TA_INITIAL, false);
513 }
514 break;
515 }
516 }
517 else
518 {
519#ifdef ENABLE_MANAGEMENT
520 if (e->arg == MULTI_IO_MANAGEMENT)
521 {
524 }
525 else
526#endif
527 /* incoming data on TUN? */
528 if (e->arg == MULTI_IO_TUN)
529 {
530 if (e->rwflags & EVENT_WRITE)
531 {
532 multi_io_action(m, NULL, TA_TUN_WRITE, false);
533 }
534 else if (e->rwflags & EVENT_READ)
535 {
536 multi_io_action(m, NULL, TA_TUN_READ, false);
537 }
538 }
539
540#if defined(ENABLE_DCO)
541 /* incoming data on DCO? */
542 else if (e->arg == MULTI_IO_DCO)
543 {
545 }
546#endif
547 /* signal received? */
548 else if (e->arg == MULTI_IO_SIG)
549 {
551 }
552#ifdef ENABLE_ASYNC_PUSH
553 else if (e->arg == MULTI_IO_FILE_CLOSE_WRITE)
554 {
555 multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_TOUCH);
556 }
557#endif
558 }
559 if (IS_SIG(&m->top))
560 {
561 break;
562 }
563 }
564 multi_io->n_esr = 0;
565
566 /*
567 * Process queued mbuf packets destined for TCP socket
568 */
569 {
570 struct multi_instance *mi;
571 while (!IS_SIG(&m->top) && (mi = mbuf_peek(m->mbuf)) != NULL)
572 {
573 multi_io_action(m, mi, TA_SOCKET_WRITE, true);
574 }
575 }
576}
577
578void
579multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
580{
581 bool tun_input_pending = false;
582
583 do
584 {
585 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_action a=%s p=%d", pract(action), poll);
586
587 /*
588 * If TA_SOCKET_READ_RESIDUAL, it means we still have pending
589 * input packets which were read by a prior recv.
590 *
591 * Otherwise do a "lite" wait, which means we wait with 0 timeout
592 * on I/O events only related to the current instance, not
593 * the big list of events.
594 *
595 * On our first pass, poll will be false because we already know
596 * that input is available, and to call io_wait would be redundant.
597 */
598 if (poll && action != TA_SOCKET_READ_RESIDUAL)
599 {
600 const int orig_action = action;
601 action = multi_io_wait_lite(m, mi, action, &tun_input_pending);
602 if (action == TA_UNDEF)
603 {
604 msg(M_FATAL, "MULTI IO: I/O wait required blocking in multi_io_action, action=%d",
605 orig_action);
606 }
607 }
608
609 /*
610 * Dispatch the action
611 */
612 struct multi_instance *touched = multi_io_dispatch(m, mi, action);
613
614 /*
615 * Signal received or connection
616 * reset by peer?
617 */
618 if (touched && IS_SIG(&touched->context))
619 {
620 if (mi == touched)
621 {
622 mi = NULL;
623 }
625 }
626
627
628 /*
629 * If dispatch produced any pending output
630 * for a particular instance, point to
631 * that instance.
632 */
633 if (m->pending)
634 {
635 mi = m->pending;
636 }
637
638 /*
639 * Based on the effects of the action,
640 * such as generating pending output,
641 * possibly transition to a new action state.
642 */
643 action = multi_io_post(m, mi, action);
644
645 /*
646 * If we are finished processing the original action,
647 * check if we have any TUN input. If so, transition
648 * our action state to processing this input.
649 */
650 if (tun_input_pending && action == TA_UNDEF)
651 {
652 action = TA_TUN_READ;
653 mi = NULL;
654 tun_input_pending = false;
655 poll = false;
656 }
657 else
658 {
659 poll = true;
660 }
661
662 } while (action != TA_UNDEF);
663}
664
665void
667{
668 if (multi_io && multi_io->es)
669 {
670 event_del(multi_io->es, event);
671 }
672}
static void gc_free(struct gc_arena *a)
Definition buffer.h:1049
#define ALLOC_OBJ_CLEAR(dptr, type)
Definition buffer.h:1088
#define ALLOC_ARRAY(dptr, type, n)
Definition buffer.h:1094
static struct gc_arena gc_new(void)
Definition buffer.h:1041
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:203
@ 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:2136
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:2034
Interface functions to the internal and external multiplexers.
#define IOW_WAIT_SIGNAL
Definition forward.h:63
#define IOW_READ_TUN
Definition forward.h:56
#define IOW_MBUF
Definition forward.h:61
#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:62
#define IOW_READ
Definition forward.h:65
#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:3306
void read_incoming_link(struct context *c, struct link_socket *sock)
Read a packet from the external network interface.
Definition forward.c:926
void read_incoming_tun(struct context *c)
Read a packet from the virtual tun/tap network interface.
Definition forward.c:1300
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:635
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:3506
#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:3247
void management_io(struct management *man)
Definition manage.c:3285
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:365
void multi_close_instance_on_signal(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:3177
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:2981
bool multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
Definition multi.c:3633
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:3665
Header file for server-mode related structures and functions.
static void set_prefix(struct multi_instance *mi)
Definition multi.h:519
static void clear_prefix(void)
Definition multi.h:531
#define MPP_RECORD_TOUCH
Definition multi.h:271
#define MPP_PRE_SELECT
Definition multi.h:269
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:454
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:251
#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:192
#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:320
void multi_io_delete_event(struct multi_io *multi_io, event_t event)
Definition multi_io.c:666
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:397
void multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
Definition multi_io.c:579
#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:172
#define msg(flags,...)
Definition error.h:152
#define ASSERT(x)
Definition error.h:219
bool has_udp_in_local_list(const struct options *options)
Definition options.c:9329
#define MODE_SERVER
Definition options.h:263
static void update_time(void)
Definition otime.h:84
static void tv_clear(struct timeval *tv)
Definition otime.h:108
#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:2939
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:811
static bool stream_buf_read_setup(struct link_socket *sock)
Definition socket.h:562
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition socket.h:821
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
int link_sockets_num
Definition openvpn.h:158
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:172
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:471
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:472
struct context_1 c1
Level 1 context.
Definition openvpn.h:513
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:116
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:264
volatile int signal_received
Definition sig.h:42
dco_context_t dco
Definition tun.h:247
struct gc_arena gc
Definition test_ssl.c:133
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