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 {
193 }
194 else
195 {
197 }
198 }
199 }
200
201 const time_t delay = socket_accept_paused();
202 if (delay && m->top.c2.timeval.tv_sec >= delay)
203 {
204 m->top.c2.timeval.tv_sec = (tv_sec_t)delay;
205 m->top.c2.timeval.tv_usec = 0;
206 m->earliest_wakeup = NULL;
207 }
208
209 tun_set(m->top.c1.tuntap, m->multi_io->es, EVENT_READ, MULTI_IO_TUN, persistent);
210#if defined(ENABLE_DCO)
212#endif
213
214#ifdef ENABLE_MANAGEMENT
215 if (management)
216 {
219 }
220#endif
221
222#ifdef ENABLE_ASYNC_PUSH
223 /* arm inotify watcher */
225#endif
226
227 status =
229 update_time();
230 m->multi_io->n_esr = 0;
231 if (status > 0)
232 {
233 m->multi_io->n_esr = status;
234 }
235 return status;
236}
237
238static int
239multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, const int action,
240 bool *tun_input_pending)
241{
242 struct context *c = multi_get_context(m, mi);
243 unsigned int looking_for = 0;
244
245 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_wait_lite a=%s mi=" ptr_format, pract(action),
246 (ptr_type)mi);
247
248 tv_clear(&c->c2.timeval); /* ZERO-TIMEOUT */
249
250 switch (action)
251 {
252 case TA_TUN_WRITE:
253 looking_for = TUN_WRITE;
254 tun_input_pending = NULL;
255 /* For some reason, the Linux 2.2 TUN/TAP driver hits this timeout */
256 c->c2.timeval.tv_sec = 1;
258 break;
259
260 case TA_SOCKET_WRITE:
261 looking_for = SOCKET_WRITE;
263 break;
264
265 default:
266 msg(M_FATAL, "MULTI IO: multi_io_wait_lite, unhandled action=%d", action);
267 }
268
269 if (tun_input_pending && (c->c2.event_set_status & TUN_READ))
270 {
271 *tun_input_pending = true;
272 }
273
274 if (c->c2.event_set_status & looking_for)
275 {
276 return action;
277 }
278 else
279 {
280 switch (action)
281 {
282 /* MULTI PROTOCOL socket output buffer is full */
283 case TA_SOCKET_WRITE:
285
286 /* TUN device timed out on accepting write */
287 case TA_TUN_WRITE:
289 }
290
291 return TA_UNDEF;
292 }
293}
294
312static bool
313multi_io_write_tun(struct multi_context *m, const unsigned int mpp_flags)
314{
315 struct multi_instance *mi = m->pending;
316 bool ret = true;
317
318 ASSERT(mi);
319#ifdef MULTI_DEBUG_EVENT_LOOP
320 printf("%s -> TUN len=%d\n", id(mi), mi->context.c2.to_tun.len);
321#endif
322 set_prefix(mi);
325 ret = multi_process_post(m, mi, mpp_flags);
326 clear_prefix();
327 return ret;
328}
329
330/*
331 * Drop a TUN/TAP outgoing packet..
332 */
333static void
334multi_io_drop_tun(struct multi_context *m, const unsigned int mpp_flags)
335{
336 struct multi_instance *mi = m->pending;
337
338 ASSERT(mi);
339
340 set_prefix(mi);
341
342 msg(D_MULTI_ERRORS, "MULTI: Outgoing TUN queue full, dropped packet len=%d",
343 mi->context.c2.to_tun.len);
344
346
347 multi_process_post(m, mi, mpp_flags);
348 clear_prefix();
349}
350
351/*
352 * Determine which instance has pending output
353 * and prepare the output for sending in
354 * the to_link buffer.
355 */
356static struct multi_instance *
358{
359 struct multi_instance *mi = NULL;
360
361 if (m->pending)
362 {
363 mi = m->pending;
364 }
365 else if (mbuf_defined(m->mbuf))
366 {
367 mi = multi_get_queue(m->mbuf);
368 }
369 return mi;
370}
371
372bool
373multi_io_send_link(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
374{
375 bool ret = true;
376 set_prefix(mi);
378 ret = multi_process_post(m, mi, mpp_flags);
379 clear_prefix();
380 return ret;
381}
382
383static bool
385 const unsigned int mpp_flags)
386{
387 struct mbuf_item item;
388 bool ret = true;
389 ASSERT(mi);
390
391 /* extract from queue */
392 if (mbuf_extract_item(mi->tcp_link_out_deferred, &item)) /* ciphertext IP packet */
393 {
394 dmsg(D_MULTI_TCP, "MULTI TCP: transmitting previously deferred packet");
395
396 ASSERT(mi == item.instance);
397 mi->context.c2.to_link = item.buffer->buf;
398 ret = multi_io_send_link(m, mi, mpp_flags);
399 mbuf_free_buf(item.buffer);
400 }
401 return ret;
402}
403
404static bool
405multi_io_write_link(struct multi_context *m, bool defer, const unsigned int mpp_flags)
406{
408 bool ret = true;
409
410 if (mi)
411 {
412 if ((defer && !proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto))
414 {
415 /* save to queue */
416 struct buffer *buf = &mi->context.c2.to_link;
417 if (BLEN(buf) > 0)
418 {
419 struct mbuf_buffer *mb = mbuf_alloc_buf(buf);
420 struct mbuf_item item;
421
422 set_prefix(mi);
423 dmsg(D_MULTI_TCP, "MULTI TCP: queuing deferred packet");
424 item.buffer = mb;
425 item.instance = mi;
427 mbuf_free_buf(mb);
428 buf_reset(buf);
429 ret = multi_process_post(m, mi, mpp_flags);
430 if (!ret)
431 {
432 mi = NULL;
433 }
434 clear_prefix();
435 }
436 }
437 else
438 {
439 ret = multi_io_send_link(m, mi, mpp_flags);
440 if (!ret)
441 {
442 mi = NULL;
443 }
444 }
445 }
446 return ret;
447}
448
449static struct multi_instance *
450multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
451{
452 const unsigned int mpp_flags = MPP_PRE_SELECT | MPP_RECORD_TOUCH;
453 struct multi_instance *touched = mi;
454 // cppcheck-suppress autoVariables ; yes, we know this is dangerous
455 m->mpp_touched = &touched;
456
457 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_dispatch a=%s mi=" ptr_format, pract(action),
458 (ptr_type)mi);
459
460 switch (action)
461 {
462 case TA_TUN_READ:
464 if (!IS_SIG(&m->top))
465 {
466 multi_process_incoming_tun(m, mpp_flags);
467 }
468 break;
469
470 case TA_SOCKET_READ:
472 ASSERT(mi);
475 set_prefix(mi);
477 clear_prefix();
478 if (!IS_SIG(&mi->context))
479 {
480 multi_process_incoming_link(m, mi, mpp_flags, mi->context.c2.link_sockets[0]);
481 if (!IS_SIG(&mi->context))
482 {
484 }
485 }
486 break;
487
488 case TA_TIMEOUT:
489 multi_process_timeout(m, mpp_flags);
490 break;
491
492 case TA_TUN_WRITE:
493 multi_io_write_tun(m, mpp_flags);
494 break;
495
497 multi_io_drop_tun(m, mpp_flags);
498 break;
499
501 ASSERT(mi);
502 multi_io_write_link_deferred(m, mi, mpp_flags);
503 break;
504
505 case TA_SOCKET_WRITE:
506 multi_io_write_link(m, false, mpp_flags);
507 break;
508
510 multi_io_write_link(m, true, mpp_flags);
511 break;
512
513 case TA_INITIAL:
514 ASSERT(mi);
516 multi_process_post(m, mi, mpp_flags);
517 break;
518
519 default:
520 msg(M_FATAL, "MULTI IO: multi_io_dispatch, unhandled action=%d", action);
521 }
522
523 m->mpp_touched = NULL;
524 return touched;
525}
526
527static int
528multi_io_post(struct multi_context *m, struct multi_instance *mi, const int action)
529{
530 struct context *c = multi_get_context(m, mi);
531 int newaction = TA_UNDEF;
532
533#define MTP_NONE 0
534#define MTP_TUN_OUT (1 << 0)
535#define MTP_LINK_OUT (1 << 1)
536 unsigned int flags = MTP_NONE;
537
538 if (TUN_OUT(c))
539 {
540 flags |= MTP_TUN_OUT;
541 }
542 if (LINK_OUT(c))
543 {
544 flags |= MTP_LINK_OUT;
545 }
546
547 switch (flags)
548 {
550 case MTP_TUN_OUT:
551 newaction = TA_TUN_WRITE;
552 break;
553
554 case MTP_LINK_OUT:
555 newaction = TA_SOCKET_WRITE;
556 break;
557
558 case MTP_NONE:
559 if (mi && sockets_read_residual(c))
560 {
561 newaction = TA_SOCKET_READ_RESIDUAL;
562 }
563 else
564 {
566 }
567 break;
568
569 default:
570 {
571 struct gc_arena gc = gc_new();
572 msg(M_FATAL, "MULTI IO: multi_io_post bad state, mi=%s flags=%u",
573 multi_instance_string(mi, false, &gc), flags);
574 gc_free(&gc);
575 break;
576 }
577 }
578
579 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_post %s -> %s", pract(action), pract(newaction));
580
581 return newaction;
582}
583
584void
586{
587 struct multi_io *multi_io = m->multi_io;
588 int i;
589
590 for (i = 0; i < multi_io->n_esr; ++i)
591 {
592 struct event_set_return *e = &multi_io->esr[i];
593 struct event_arg *ev_arg = (struct event_arg *)e->arg;
594
595 /* incoming data for instance or listening socket? */
596 if (e->arg >= MULTI_N)
597 {
598 switch (ev_arg->type)
599 {
600 struct multi_instance *mi;
601
602 /* react to event on child instance */
604 if (!ev_arg->u.mi)
605 {
606 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null minstance");
607 break;
608 }
609
610 mi = ev_arg->u.mi;
611 if (e->rwflags & EVENT_WRITE)
612 {
614 }
615 else if (e->rwflags & EVENT_READ)
616 {
617 multi_io_action(m, mi, TA_SOCKET_READ, false);
618 }
619 break;
620
622 if (!ev_arg->u.sock)
623 {
624 msg(D_MULTI_ERRORS, "MULTI IO: multi_io_proc_io: null socket");
625 break;
626 }
627 /* new incoming TCP client attempting to connect? */
629 {
632 }
633 else
634 {
636 mi = m->pending;
637 }
638 /* monitor and/or handle events that are
639 * triggered in succession by the first one
640 * before returning to the main loop. */
641 if (mi)
642 {
643 multi_io_action(m, mi, TA_INITIAL, false);
644 }
645 break;
646 }
647 }
648 else
649 {
650#ifdef ENABLE_MANAGEMENT
651 if (e->arg == MULTI_IO_MANAGEMENT)
652 {
655 }
656 else
657#endif
658 /* incoming data on TUN? */
659 if (e->arg == MULTI_IO_TUN)
660 {
661 if (e->rwflags & EVENT_WRITE)
662 {
663 multi_io_action(m, NULL, TA_TUN_WRITE, false);
664 }
665 else if (e->rwflags & EVENT_READ)
666 {
667 multi_io_action(m, NULL, TA_TUN_READ, false);
668 }
669 }
670
671#if defined(ENABLE_DCO)
672 /* incoming data on DCO? */
673 else if (e->arg == MULTI_IO_DCO)
674 {
676 }
677#endif
678 /* signal received? */
679 else if (e->arg == MULTI_IO_SIG)
680 {
682 }
683#ifdef ENABLE_ASYNC_PUSH
684 else if (e->arg == MULTI_IO_FILE_CLOSE_WRITE)
685 {
686 multi_process_file_closed(m, MPP_PRE_SELECT | MPP_RECORD_TOUCH);
687 }
688#endif
689 }
690 if (IS_SIG(&m->top))
691 {
692 break;
693 }
694 }
695 multi_io->n_esr = 0;
696
697 /*
698 * Drain the queued mbuf packets, datagram and TCP instances alike
699 */
700 {
701 struct multi_instance *mi;
702 while (!IS_SIG(&m->top) && (mi = mbuf_peek(m->mbuf)) != NULL)
703 {
704 multi_io_action(m, mi, TA_SOCKET_WRITE, true);
705 }
706 }
707}
708
709void
710multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
711{
712 bool tun_input_pending = false;
713
714 do
715 {
716 dmsg(D_MULTI_DEBUG, "MULTI IO: multi_io_action a=%s p=%d", pract(action), poll);
717
718 /*
719 * If TA_SOCKET_READ_RESIDUAL, it means we still have pending
720 * input packets which were read by a prior recv.
721 *
722 * Otherwise do a "lite" wait, which means we wait with 0 timeout
723 * on I/O events only related to the current instance, not
724 * the big list of events.
725 *
726 * On our first pass, poll will be false because we already know
727 * that input is available, and to call io_wait would be redundant.
728 */
729 if (poll && action != TA_SOCKET_READ_RESIDUAL)
730 {
731 const int orig_action = action;
732 action = multi_io_wait_lite(m, mi, action, &tun_input_pending);
733 if (action == TA_UNDEF)
734 {
735 msg(M_FATAL, "MULTI IO: I/O wait required blocking in multi_io_action, action=%d",
736 orig_action);
737 }
738 }
739
740 /*
741 * Dispatch the action
742 */
743 struct multi_instance *touched = multi_io_dispatch(m, mi, action);
744
745 /*
746 * Signal received or connection
747 * reset by peer?
748 */
749 if (touched && IS_SIG(&touched->context))
750 {
751 if (mi == touched)
752 {
753 mi = NULL;
754 }
756 }
757
758
759 /*
760 * If dispatch produced any pending output
761 * for a particular instance, point to
762 * that instance.
763 */
764 if (m->pending)
765 {
766 mi = m->pending;
767 }
768
769 /*
770 * Based on the effects of the action,
771 * such as generating pending output,
772 * possibly transition to a new action state.
773 */
774 action = multi_io_post(m, mi, action);
775
776 /*
777 * If we are finished processing the original action,
778 * check if we have any TUN input. If so, transition
779 * our action state to processing this input.
780 */
781 if (tun_input_pending && action == TA_UNDEF)
782 {
783 action = TA_TUN_READ;
784 mi = NULL;
785 tun_input_pending = false;
786 poll = false;
787 }
788 else
789 {
790 poll = true;
791 }
792
793 } while (action != TA_UNDEF);
794}
795
796void
798{
799 if (multi_io && multi_io->es)
800 {
801 event_del(multi_io->es, event);
802 }
803}
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:327
static int dco_read_and_process(dco_context_t *dco)
Definition dco.h:320
#define D_MULTI_ERRORS
Definition errlevel.h:64
#define D_MULTI_DEBUG
Definition errlevel.h:124
#define D_MULTI_TCP
Definition errlevel.h:158
#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
const struct rw_handle * event_t
Definition event.h:89
#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:2141
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:2047
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:3598
void process_outgoing_link(struct context *c, struct link_socket *sock)
Write a packet to the external network interface.
Definition forward.c:1763
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:1326
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:1896
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:313
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:3661
#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:3358
void management_io(struct management *man)
Definition manage.c:3399
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:3320
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:3079
struct multi_instance * multi_get_queue(struct mbuf_set *ms)
Definition multi.c:3752
bool multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
Definition multi.c:3802
const char * multi_instance_string(const struct multi_instance *mi, bool null, struct gc_arena *gc)
Definition multi.c:495
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:585
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:239
bool multi_io_send_link(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
Definition multi_io.c:373
#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:357
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:450
static bool multi_io_write_link(struct multi_context *m, bool defer, const unsigned int mpp_flags)
Definition multi_io.c:405
static bool multi_io_write_link_deferred(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
Definition multi_io.c:384
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:334
void multi_io_delete_event(struct multi_io *multi_io, event_t event)
Definition multi_io.c:797
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:528
void multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
Definition multi_io.c:710
#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
long tv_sec_t
Definition otime.h:31
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
time_t socket_accept_paused(void)
Definition socket.c:455
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:849
static void socket_unset_listen_persistent(struct link_socket *sock, struct event_set *es)
Definition socket.h:859
static bool stream_buf_read_setup(struct link_socket *sock)
Definition socket.h:591
static void socket_reset_listen_persistent(struct link_socket *sock)
Definition socket.h:869
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:455
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:476
struct context_2 c2
Level 2 context.
Definition openvpn.h:492
struct context_1 c1
Level 1 context.
Definition openvpn.h:491
union event_arg::@352313260244035237115140212234220346176163201310 u
struct link_socket * sock
Definition event.h:145
struct multi_instance * mi
Definition event.h:144
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
struct multi_instance * earliest_wakeup
Definition multi.h:212
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:574
static bool tuntap_is_dco_win(const struct tuntap *tt)
Definition tun.h:505
void vlan_process_outgoing_tun(const struct multi_context *m, struct multi_instance *mi)
Definition vlan.c:291