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
107#if defined(__GNUC__) || defined(__clang__)
108#pragma GCC diagnostic push
109#pragma GCC diagnostic ignored "-Wsign-conversion"
110#endif
111
112struct multi_io *
113multi_io_init(const int maxclients)
114{
115 struct multi_io *multi_io;
116
117 ASSERT(maxclients >= 1);
118
120 multi_io->maxevents = maxclients + BASE_N_EVENTS;
124 msg(D_MULTI_LOW, "MULTI IO: MULTI_IO INIT maxclients=%d maxevents=%d", maxclients,
126 return multi_io;
127}
128
129#if defined(__GNUC__) || defined(__clang__)
130#pragma GCC diagnostic pop
131#endif
132
133void
135{
136 if (multi_io)
137 {
139 free(multi_io->esr);
140 free(multi_io);
141 }
142}
143
144/*
145 * Return the io flags appropriate for
146 * a point-to-multipoint tunnel.
147 */
148static unsigned int
149p2mp_iow_flags(const struct multi_context *m, const struct link_socket *sock)
150{
151 unsigned int flags = IOW_WAIT_SIGNAL;
152
153 if (m->pending)
154 {
155 if (TUN_OUT(&m->pending->context))
156 {
157 flags |= IOW_TO_TUN;
158 }
159
160 /* If the to be processed socket happens to be the same one on the pending
161 * UDP client instance, we set that socket ready for write */
162 if (LINK_OUT(&m->pending->context) && m->pending->context.c2.link_sockets[0] == sock)
163 {
164 flags |= IOW_TO_LINK;
165 }
166 }
167 else
168 {
169 flags |= IOW_READ;
170 }
171 return flags;
172}
173
174int
176{
177 int status;
178 unsigned int *persistent = &m->multi_io->tun_rwflags;
179
180 for (int i = 0; i < m->top.c1.link_sockets_num; i++)
181 {
182 struct link_socket *sock = m->top.c2.link_sockets[i];
183
184 if (proto_is_dgram(sock->info.proto))
185 {
186 multi_io_process_flags(&m->top, m->multi_io->es, sock, p2mp_iow_flags(m, sock));
187 }
188 else if (!tuntap_is_dco_win(m->top.c1.tuntap))
189 {
191 }
192 }
193
194 tun_set(m->top.c1.tuntap, m->multi_io->es, EVENT_READ, MULTI_IO_TUN, persistent);
195#if defined(ENABLE_DCO)
197#endif
198
199#ifdef ENABLE_MANAGEMENT
200 if (management)
201 {
204 }
205#endif
206
207#ifdef ENABLE_ASYNC_PUSH
208 /* arm inotify watcher */
210#endif
211
212 status =
214 update_time();
215 m->multi_io->n_esr = 0;
216 if (status > 0)
217 {
218 m->multi_io->n_esr = status;
219 }
220 return status;
221}
222
223static int
224multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, const int action,
225 bool *tun_input_pending)
226{
227 struct context *c = multi_get_context(m, mi);
228 unsigned int looking_for = 0;
229
230 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=%s mi=" ptr_format, pract(action),
231 (ptr_type)mi);
232
233 tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */
234
235 switch (action)
236 {
237 case TA_TUN_WRITE:
238 looking_for = TUN_WRITE;
239 tun_input_pending = NULL;
240 /* For some reason, the Linux 2.2 TUN/TAP driver hits this timeout */
241 c->c2.timeval.tv_sec = 1;
243 break;
244
245 case TA_SOCKET_WRITE:
246 looking_for = SOCKET_WRITE;
248 break;
249
250 default:
251 msg(M_FATAL, "MULTI IO: multi_io_wait_lite, unhandled action=%d", action);
252 }
253
254 if (tun_input_pending && (c->c2.event_set_status & TUN_READ))
255 {
256 *tun_input_pending = true;
257 }
258
259 if (c->c2.event_set_status & looking_for)
260 {
261 return action;
262 }
263 else
264 {
265 switch (action)
266 {
267 /* MULTI PROTOCOL socket output buffer is full */
268 case TA_SOCKET_WRITE:
270
271 /* TUN device timed out on accepting write */
272 case TA_TUN_WRITE:
274 }
275
276 return TA_UNDEF;
277 }
278}
279
297static bool
298multi_io_write_tun(struct multi_context *m, const unsigned int mpp_flags)
299{
300 struct multi_instance *mi = m->pending;
301 bool ret = true;
302
303 ASSERT(mi);
304#ifdef MULTI_DEBUG_EVENT_LOOP
305 printf("%s -> TUN len=%d\n", id(mi), mi->context.c2.to_tun.len);
306#endif
307 set_prefix(mi);
310 ret = multi_process_post(m, mi, mpp_flags);
311 clear_prefix();
312 return ret;
313}
314
315/*
316 * Drop a TUN/TAP outgoing packet..
317 */
318static void
319multi_io_drop_tun(struct multi_context *m, const unsigned int mpp_flags)
320{
321 struct multi_instance *mi = m->pending;
322
323 ASSERT(mi);
324
325 set_prefix(mi);
326
327 msg(D_MULTI_ERRORS, "MULTI: Outgoing TUN queue full, dropped packet len=%d",
328 mi->context.c2.to_tun.len);
329
331
332 multi_process_post(m, mi, mpp_flags);
333 clear_prefix();
334}
335
336/*
337 * Determine which instance has pending output
338 * and prepare the output for sending in
339 * the to_link buffer.
340 */
341static struct multi_instance *
343{
344 struct multi_instance *mi = NULL;
345
346 if (m->pending)
347 {
348 mi = m->pending;
349 }
350 else if (mbuf_defined(m->mbuf))
351 {
352 mi = multi_get_queue(m->mbuf);
353 }
354 return mi;
355}
356
357bool
358multi_io_send_link(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
359{
360 bool ret = true;
361 set_prefix(mi);
363 ret = multi_process_post(m, mi, mpp_flags);
364 clear_prefix();
365 return ret;
366}
367
368static bool
370 const unsigned int mpp_flags)
371{
372 struct mbuf_item item;
373 bool ret = true;
374 ASSERT(mi);
375
376 /* extract from queue */
377 if (mbuf_extract_item(mi->tcp_link_out_deferred, &item)) /* ciphertext IP packet */
378 {
379 dmsg(D_MULTI_TCP, "MULTI TCP: transmitting previously deferred packet");
380
381 ASSERT(mi == item.instance);
382 mi->context.c2.to_link = item.buffer->buf;
383 ret = multi_io_send_link(m, mi, mpp_flags);
384 mbuf_free_buf(item.buffer);
385 }
386 return ret;
387}
388
389static bool
390multi_io_write_link(struct multi_context *m, bool defer, const unsigned int mpp_flags)
391{
393 bool ret = true;
394
395 if (mi)
396 {
397 if ((defer && !proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto))
399 {
400 /* save to queue */
401 struct buffer *buf = &mi->context.c2.to_link;
402 if (BLEN(buf) > 0)
403 {
404 struct mbuf_buffer *mb = mbuf_alloc_buf(buf);
405 struct mbuf_item item;
406
407 set_prefix(mi);
408 dmsg(D_MULTI_TCP, "MULTI TCP: queuing deferred packet");
409 item.buffer = mb;
410 item.instance = mi;
412 mbuf_free_buf(mb);
413 buf_reset(buf);
414 ret = multi_process_post(m, mi, mpp_flags);
415 if (!ret)
416 {
417 mi = NULL;
418 }
419 clear_prefix();
420 }
421 }
422 else
423 {
424 ret = multi_io_send_link(m, mi, mpp_flags);
425 if (!ret)
426 {
427 mi = NULL;
428 }
429 }
430 }
431 return ret;
432}
433
434static struct multi_instance *
435multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
436{
437 const unsigned int mpp_flags = MPP_PRE_SELECT | MPP_RECORD_TOUCH;
438 struct multi_instance *touched = mi;
439 // cppcheck-suppress autoVariables ; yes, we know this is dangerous
440 m->mpp_touched = &touched;
441
442 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=%s mi=" ptr_format, pract(action),
443 (ptr_type)mi);
444
445 switch (action)
446 {
447 case TA_TUN_READ:
449 if (!IS_SIG(&m->top))
450 {
451 multi_process_incoming_tun(m, mpp_flags);
452 }
453 break;
454
455 case TA_SOCKET_READ:
457 ASSERT(mi);
460 set_prefix(mi);
462 clear_prefix();
463 if (!IS_SIG(&mi->context))
464 {
465 multi_process_incoming_link(m, mi, mpp_flags, mi->context.c2.link_sockets[0]);
466 if (!IS_SIG(&mi->context))
467 {
469 }
470 }
471 break;
472
473 case TA_TIMEOUT:
474 multi_process_timeout(m, mpp_flags);
475 break;
476
477 case TA_TUN_WRITE:
478 multi_io_write_tun(m, mpp_flags);
479 break;
480
482 multi_io_drop_tun(m, mpp_flags);
483 break;
484
486 ASSERT(mi);
487 multi_io_write_link_deferred(m, mi, mpp_flags);
488 break;
489
490 case TA_SOCKET_WRITE:
491 multi_io_write_link(m, false, mpp_flags);
492 break;
493
495 multi_io_write_link(m, true, mpp_flags);
496 break;
497
498 case TA_INITIAL:
499 ASSERT(mi);
501 multi_process_post(m, mi, mpp_flags);
502 break;
503
504 default:
505 msg(M_FATAL, "MULTI IO: multi_io_dispatch, unhandled action=%d", action);
506 }
507
508 m->mpp_touched = NULL;
509 return touched;
510}
511
512static int
513multi_io_post(struct multi_context *m, struct multi_instance *mi, const int action)
514{
515 struct context *c = multi_get_context(m, mi);
516 int newaction = TA_UNDEF;
517
518#define MTP_NONE 0
519#define MTP_TUN_OUT (1 << 0)
520#define MTP_LINK_OUT (1 << 1)
521 unsigned int flags = MTP_NONE;
522
523 if (TUN_OUT(c))
524 {
525 flags |= MTP_TUN_OUT;
526 }
527 if (LINK_OUT(c))
528 {
529 flags |= MTP_LINK_OUT;
530 }
531
532 switch (flags)
533 {
535 case MTP_TUN_OUT:
536 newaction = TA_TUN_WRITE;
537 break;
538
539 case MTP_LINK_OUT:
540 newaction = TA_SOCKET_WRITE;
541 break;
542
543 case MTP_NONE:
544 if (mi && sockets_read_residual(c))
545 {
546 newaction = TA_SOCKET_READ_RESIDUAL;
547 }
548 else
549 {
551 }
552 break;
553
554 default:
555 {
556 struct gc_arena gc = gc_new();
557 msg(M_FATAL, "MULTI IO: multi_io_post bad state, mi=%s flags=%u",
558 multi_instance_string(mi, false, &gc), flags);
559 gc_free(&gc);
560 break;
561 }
562 }
563
564 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_post %s -> %s", pract(action), pract(newaction));
565
566 return newaction;
567}
568
569void
571{
572 struct multi_io *multi_io = m->multi_io;
573 int i;
574
575 for (i = 0; i < multi_io->n_esr; ++i)
576 {
577 struct event_set_return *e = &multi_io->esr[i];
578 struct event_arg *ev_arg = (struct event_arg *)e->arg;
579
580 /* incoming data for instance or listening socket? */
581 if (e->arg >= MULTI_N)
582 {
583 switch (ev_arg->type)
584 {
585 struct multi_instance *mi;
586
587 /* react to event on child instance */
589 if (!ev_arg->u.mi)
590 {
591 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null minstance");
592 break;
593 }
594
595 mi = ev_arg->u.mi;
596 if (e->rwflags & EVENT_WRITE)
597 {
599 }
600 else if (e->rwflags & EVENT_READ)
601 {
602 multi_io_action(m, mi, TA_SOCKET_READ, false);
603 }
604 break;
605
607 if (!ev_arg->u.sock)
608 {
609 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null socket");
610 break;
611 }
612 /* new incoming TCP client attempting to connect? */
614 {
617 }
618 else
619 {
621 mi = m->pending;
622 }
623 /* monitor and/or handle events that are
624 * triggered in succession by the first one
625 * before returning to the main loop. */
626 if (mi)
627 {
628 multi_io_action(m, mi, TA_INITIAL, false);
629 }
630 break;
631 }
632 }
633 else
634 {
635#ifdef ENABLE_MANAGEMENT
636 if (e->arg == MULTI_IO_MANAGEMENT)
637 {
640 }
641 else
642#endif
643 /* incoming data on TUN? */
644 if (e->arg == MULTI_IO_TUN)
645 {
646 if (e->rwflags & EVENT_WRITE)
647 {
648 multi_io_action(m, NULL, TA_TUN_WRITE, false);
649 }
650 else if (e->rwflags & EVENT_READ)
651 {
652 multi_io_action(m, NULL, TA_TUN_READ, false);
653 }
654 }
655
656#if defined(ENABLE_DCO)
657 /* incoming data on DCO? */
658 else if (e->arg == MULTI_IO_DCO)
659 {
661 }
662#endif
663 /* signal received? */
664 else if (e->arg == MULTI_IO_SIG)
665 {
667 }
668#ifdef ENABLE_ASYNC_PUSH
669 else if (e->arg == MULTI_IO_FILE_CLOSE_WRITE)
670 {
671 multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_TOUCH);
672 }
673#endif
674 }
675 if (IS_SIG(&m->top))
676 {
677 break;
678 }
679 }
680 multi_io->n_esr = 0;
681
682 /*
683 * Drain the queued mbuf packets, datagram and TCP instances alike
684 */
685 {
686 struct multi_instance *mi;
687 while (!IS_SIG(&m->top) && (mi = mbuf_peek(m->mbuf)) != NULL)
688 {
689 multi_io_action(m, mi, TA_SOCKET_WRITE, true);
690 }
691 }
692}
693
694void
695multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
696{
697 bool tun_input_pending = false;
698
699 do
700 {
701 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_action a=%s p=%d", pract(action), poll);
702
703 /*
704 * If TA_SOCKET_READ_RESIDUAL, it means we still have pending
705 * input packets which were read by a prior recv.
706 *
707 * Otherwise do a "lite" wait, which means we wait with 0 timeout
708 * on I/O events only related to the current instance, not
709 * the big list of events.
710 *
711 * On our first pass, poll will be false because we already know
712 * that input is available, and to call io_wait would be redundant.
713 */
714 if (poll && action != TA_SOCKET_READ_RESIDUAL)
715 {
716 const int orig_action = action;
717 action = multi_io_wait_lite(m, mi, action, &tun_input_pending);
718 if (action == TA_UNDEF)
719 {
720 msg(M_FATAL, "MULTI IO: I/O wait required blocking in multi_io_action, action=%d",
721 orig_action);
722 }
723 }
724
725 /*
726 * Dispatch the action
727 */
728 struct multi_instance *touched = multi_io_dispatch(m, mi, action);
729
730 /*
731 * Signal received or connection
732 * reset by peer?
733 */
734 if (touched && IS_SIG(&touched->context))
735 {
736 if (mi == touched)
737 {
738 mi = NULL;
739 }
741 }
742
743
744 /*
745 * If dispatch produced any pending output
746 * for a particular instance, point to
747 * that instance.
748 */
749 if (m->pending)
750 {
751 mi = m->pending;
752 }
753
754 /*
755 * Based on the effects of the action,
756 * such as generating pending output,
757 * possibly transition to a new action state.
758 */
759 action = multi_io_post(m, mi, action);
760
761 /*
762 * If we are finished processing the original action,
763 * check if we have any TUN input. If so, transition
764 * our action state to processing this input.
765 */
766 if (tun_input_pending && action == TA_UNDEF)
767 {
768 action = TA_TUN_READ;
769 mi = NULL;
770 tun_input_pending = false;
771 poll = false;
772 }
773 else
774 {
775 poll = true;
776 }
777
778 } while (action != TA_UNDEF);
779}
780
781void
783{
784 if (multi_io && multi_io->es)
785 {
786 event_del(multi_io->es, event);
787 }
788}
static void buf_reset(struct buffer *buf)
Reset a buffer to an undefined (unallocated) state.
Definition buffer.h:599
#define BLEN(buf)
Return the length of the buffer content in bytes.
Definition buffer.h:151
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given type.
Definition buffer.h:2036
#define ALLOC_ARRAY(dptr, type, n)
Allocate memory for an array of n elements of the given type.
Definition buffer.h:2052
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
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:124
#define D_MULTI_TCP
Definition errlevel.h:159
#define D_MULTI_LOW
Definition errlevel.h:84
struct event_set * event_set_init(int *maxevents, unsigned int flags)
Definition event.c:1205
#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
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:2132
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:2038
Interface functions to the internal and external multiplexers.
#define IOW_WAIT_SIGNAL
Definition forward.h:62
#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:3535
void process_outgoing_link(struct context *c, struct link_socket *sock)
Write a packet to the external network interface.
Definition forward.c:1754
void read_incoming_link(struct context *c, struct link_socket *sock)
Read a packet from the external network interface.
Definition forward.c:951
void read_incoming_tun(struct context *c)
Read a packet from the virtual tun/tap network interface.
Definition forward.c:1317
void process_outgoing_tun(struct context *c, struct link_socket *in_sock)
Write a packet to the virtual tun/tap network interface.
Definition forward.c:1887
static bool multi_io_write_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_io.c:298
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:3598
#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:3312
void management_io(struct management *man)
Definition manage.c:3350
void mbuf_add_item(struct mbuf_set *ms, const struct mbuf_item *item)
Definition mbuf.c:104
struct mbuf_buffer * mbuf_alloc_buf(const struct buffer *buf)
Definition mbuf.c:65
void mbuf_free_buf(struct mbuf_buffer *mb)
Definition mbuf.c:76
bool mbuf_extract_item(struct mbuf_set *ms, struct mbuf_item *item)
Definition mbuf.c:126
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
void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi)
Definition mtcp.c:119
struct multi_instance * multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock)
Definition mtcp.c:46
void multi_process_io_udp(struct multi_context *m, struct link_socket *sock, unsigned int rwflags)
Definition mudp.c:482
void multi_close_instance_on_signal(struct multi_context *m, struct multi_instance *mi)
Definition multi.c:3257
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:3016
struct multi_instance * multi_get_queue(struct mbuf_set *ms)
Definition multi.c:3689
bool multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
Definition multi.c:3725
const char * multi_instance_string(const struct multi_instance *mi, bool null, struct gc_arena *gc)
Definition multi.c:432
Header file for server-mode related structures and functions.
static void clear_prefix(void)
Definition multi.h:523
static void set_prefix(const struct multi_instance *mi)
Definition multi.h:511
#define MPP_RECORD_TOUCH
Definition multi.h:288
#define MPP_PRE_SELECT
Definition multi.h:286
struct multi_io * multi_io_init(const int maxclients)
Definition multi_io.c:113
#define MULTI_IO_SIG
Definition multi_io.c:44
void multi_io_process_io(struct multi_context *m)
Definition multi_io.c:570
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:224
bool multi_io_send_link(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
Definition multi_io.c:358
#define MULTI_IO_TUN
Definition multi_io.c:43
void multi_io_free(struct multi_io *multi_io)
Definition multi_io.c:134
#define MTP_NONE
static unsigned int p2mp_iow_flags(const struct multi_context *m, const struct link_socket *sock)
Definition multi_io.c:149
#define MTP_TUN_OUT
#define MULTI_IO_DCO
Definition multi_io.c:47
#define MTP_LINK_OUT
static struct multi_instance * multi_io_write_link_pre(struct multi_context *m)
Definition multi_io.c:342
int multi_io_wait(struct multi_context *m)
Definition multi_io.c:175
#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:435
static bool multi_io_write_link(struct multi_context *m, bool defer, const unsigned int mpp_flags)
Definition multi_io.c:390
static bool multi_io_write_link_deferred(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
Definition multi_io.c:369
static const char * pract(int action)
Definition multi_io.c:51
static void multi_io_drop_tun(struct multi_context *m, const unsigned int mpp_flags)
Definition multi_io.c:319
void multi_io_delete_event(struct multi_io *multi_io, event_t event)
Definition multi_io.c:782
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:513
void multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
Definition multi_io.c:695
#define MULTI_IO_MANAGEMENT
Definition multi_io.c:45
#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
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
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:839
static bool stream_buf_read_setup(struct link_socket *sock)
Definition socket.h:581
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition socket.h:849
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
int link_sockets_num
Definition openvpn.h:144
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:155
unsigned int event_set_status
Definition openvpn.h:218
struct buffer to_link
Definition openvpn.h:351
struct buffer to_tun
Definition openvpn.h:350
struct link_socket ** link_sockets
Definition openvpn.h:220
struct timeval timeval
Time to next event of timers and similar.
Definition openvpn.h:370
Contains all state information for one tunnel.
Definition openvpn.h:445
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:474
struct context_2 c2
Level 2 context.
Definition openvpn.h:490
struct context_1 c1
Level 1 context.
Definition openvpn.h:489
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
struct buffer buf
Definition mbuf.h:44
struct mbuf_buffer * buffer
Definition mbuf.h:53
struct multi_instance * instance
Definition mbuf.h:54
Main OpenVPN server state structure.
Definition multi.h:170
struct mbuf_set * mbuf
Set of buffers for passing data channel packets between VPN tunnel instances.
Definition multi.h:190
struct multi_io * multi_io
I/O state and events tracker.
Definition multi.h:193
struct context top
Storage structure for process-wide configuration.
Definition multi.h:217
struct multi_instance * pending
Definition multi.h:211
struct multi_instance ** mpp_touched
Definition multi.h:213
Server-mode state structure for one single VPN tunnel.
Definition multi.h:102
struct mbuf_set * tcp_link_out_deferred
Definition multi.h:128
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:150
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
volatile int signal_received
Definition sig.h:42
dco_context_t dco
Definition tun.h:247
struct gc_arena gc
Definition test_ssl.c:138
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
Definition tun.h:601
static bool tuntap_is_dco_win(const struct tuntap *tt)
Definition tun.h:532
void vlan_process_outgoing_tun(const struct multi_context *m, struct multi_instance *mi)
Definition vlan.c:300