36#ifdef HAVE_SYS_INOTIFY_H
37#include <sys/inotify.h>
43#define MULTI_IO_SOCKET ((void *)1)
44#define MULTI_IO_TUN ((void *)2)
45#define MULTI_IO_SIG ((void *)3)
46#define MULTI_IO_MANAGEMENT ((void *)4)
47#define MULTI_IO_FILE_CLOSE_WRITE ((void *)5)
48#define MULTI_IO_DCO ((void *)6)
68 return "TA_SOCKET_READ";
71 return "TA_SOCKET_READ_RESIDUAL";
74 return "TA_SOCKET_WRITE";
77 return "TA_SOCKET_WRITE_READY";
80 return "TA_SOCKET_WRITE_DEFERRED";
86 return "TA_TUN_WRITE";
95 return "TA_TUN_WRITE_TIMEOUT";
205#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
209#ifdef ENABLE_MANAGEMENT
216#ifdef ENABLE_ASYNC_PUSH
235 unsigned int looking_for = 0;
247 tun_input_pending = NULL;
253 tun_input_pending = NULL;
259 tun_input_pending = NULL;
272 msg(
M_FATAL,
"MULTI IO: multi_io_wait_lite, unhandled action=%d", action);
277 *tun_input_pending =
true;
373 msg(
M_FATAL,
"MULTI IO: multi_io_dispatch, unhandled action=%d", action);
387#define MTP_TUN_OUT (1<<0)
388#define MTP_LINK_OUT (1<<1)
425 msg(
M_FATAL,
"MULTI IO: multi_io_post bad state, mi=%s flags=%d",
454 switch (ev_arg->
type)
506#ifdef ENABLE_MANAGEMENT
538#if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))
550#ifdef ENABLE_ASYNC_PUSH
579 bool tun_input_pending =
false;
600 const int orig_action = action;
604 msg(
M_FATAL,
"MULTI IO: I/O wait required blocking in multi_io_action, action=%d", orig_action);
649 if (tun_input_pending && action ==
TA_UNDEF)
653 tun_input_pending =
false;
static void gc_free(struct gc_arena *a)
#define ALLOC_OBJ_CLEAR(dptr, type)
#define ALLOC_ARRAY(dptr, type, n)
static struct gc_arena gc_new(void)
static void dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
struct event_set * event_set_init(int *maxevents, unsigned int flags)
static void event_free(struct event_set *es)
static void event_del(struct event_set *es, event_t event)
static int event_wait(struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen)
static void wait_signal(struct event_set *es, void *arg)
@ EVENT_ARG_MULTI_INSTANCE
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
void get_io_flags_udp(struct context *c, struct multi_io *multi_io, const unsigned int flags)
Interface functions to the internal and external multiplexers.
static void io_wait(struct context *c, const unsigned int flags)
#define IOW_READ_TUN_FORCE
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.
void read_incoming_link(struct context *c, struct link_socket *sock)
Read a packet from the external network interface.
void read_incoming_tun(struct context *c)
Read a packet from the virtual tun/tap network interface.
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.
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 ...
static int min_int(int x, int y)
static int max_int(int x, int y)
static SERVICE_STATUS status
void management_socket_set(struct management *man, struct event_set *es, void *arg, unsigned int *persistent)
void management_io(struct management *man)
static struct multi_instance * mbuf_peek(struct mbuf_set *ms)
static bool mbuf_defined(const struct mbuf_set *ms)
struct multi_instance * multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock)
bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags)
bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
unsigned int p2mp_iow_flags(const struct multi_context *m)
void multi_process_io_udp(struct multi_context *m, struct link_socket *sock)
void multi_close_instance_on_signal(struct multi_context *m, struct multi_instance *mi)
bool multi_process_post(struct multi_context *m, struct multi_instance *mi, const unsigned int flags)
Perform postprocessing of a VPN tunnel instance.
bool multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
const char * multi_instance_string(const struct multi_instance *mi, bool null, struct gc_arena *gc)
void multi_process_drop_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags)
Header file for server-mode related structures and functions.
bool multi_process_incoming_dco(struct multi_context *m)
Process an incoming DCO message (from kernel space).
static void set_prefix(struct multi_instance *mi)
static void clear_prefix(void)
void multi_io_process_io(struct multi_context *m)
static int multi_io_wait_lite(struct multi_context *m, struct multi_instance *mi, const int action, bool *tun_input_pending)
struct multi_io * multi_io_init(int maxevents, int *maxclients)
void multi_io_free(struct multi_io *multi_io)
void multi_io_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi)
int multi_io_wait(struct multi_context *m)
#define MULTI_IO_FILE_CLOSE_WRITE
static struct multi_instance * multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
void multi_io_delete_event(struct multi_io *multi_io, event_t event)
static struct context * multi_get_context(struct multi_context *m, struct multi_instance *mi)
static int multi_io_post(struct multi_context *m, struct multi_instance *mi, const int action)
void multi_io_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
#define MULTI_IO_MANAGEMENT
#define TA_SOCKET_WRITE_READY
#define TA_SOCKET_READ_RESIDUAL
#define TA_SOCKET_WRITE_DEFERRED
#define TA_TUN_WRITE_TIMEOUT
bool has_udp_in_local_list(const struct options *options)
static void update_time(void)
static void tv_clear(struct timeval *tv)
static void perf_push(int type)
#define PERF_PROC_OUT_TUN_MTCP
static void perf_pop(void)
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
unsigned int socket_set(struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
bool sockets_read_residual(const struct context *c)
static void socket_set_listen_persistent(struct link_socket *sock, struct event_set *es, void *arg)
static bool stream_buf_read_setup(struct link_socket *sock)
static void socket_reset_listen_persistent(struct link_socket *sock)
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
struct tuntap * tuntap
Tun/tap virtual network interface.
unsigned int event_set_status
struct link_socket ** link_sockets
struct timeval timeval
Time to next event of timers and similar.
Contains all state information for one tunnel.
struct signal_info * sig
Internal error signaling object.
struct context_2 c2
Level 2 context.
struct options options
Options loaded from command line or configuration file.
struct context_1 c1
Level 1 context.
struct link_socket * sock
struct multi_instance * mi
Garbage collection arena used to keep track of dynamically allocated memory.
struct link_socket_info info
struct event_arg ev_arg
this struct will store a pointer to either mi or link_socket, depending on the event type,...
Main OpenVPN server state structure.
struct mbuf_set * mbuf
Set of buffers for passing data channel packets between VPN tunnel instances.
struct multi_io * multi_io
I/O state and events tracker.
struct context top
Storage structure for process-wide configuration.
struct multi_instance * pending
struct multi_instance ** mpp_touched
Server-mode state structure for one single VPN tunnel.
struct mbuf_set * tcp_link_out_deferred
struct event_arg ev_arg
this struct will store a pointer to either mi or link_socket, depending on the event type,...
struct context context
The context structure storing state for this VPN tunnel.
struct event_set_return * esr
unsigned int management_persist_flags
volatile int signal_received
static bool tuntap_is_wintun(struct tuntap *tt)
static bool tuntap_ring_empty(struct tuntap *tt)
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)