Go to the documentation of this file.
35 #ifdef HAVE_SYS_INOTIFY_H
36 #include <sys/inotify.h>
43 #define TA_SOCKET_READ 1
44 #define TA_SOCKET_READ_RESIDUAL 2
45 #define TA_SOCKET_WRITE 3
46 #define TA_SOCKET_WRITE_READY 4
47 #define TA_SOCKET_WRITE_DEFERRED 5
49 #define TA_TUN_WRITE 7
52 #define TA_TUN_WRITE_TIMEOUT 10
57 #define MTCP_SOCKET ((void *)1)
58 #define MTCP_TUN ((void *)2)
59 #define MTCP_SIG ((void *)3)
60 #define MTCP_MANAGEMENT ((void *)4)
61 #define MTCP_FILE_CLOSE_WRITE ((void *)5)
62 #define MTCP_DCO ((void *)6)
64 #define MTCP_N ((void *)16)
84 return "TA_SOCKET_READ";
87 return "TA_SOCKET_READ_RESIDUAL";
90 return "TA_SOCKET_WRITE";
93 return "TA_SOCKET_WRITE_READY";
96 return "TA_SOCKET_WRITE_DEFERRED";
102 return "TA_TUN_WRITE";
111 return "TA_TUN_WRITE_TIMEOUT";
140 msg(
D_MULTI_LOW,
"MULTI TCP: new incoming client address matches existing client address -- new client takes precedence");
218 if (mtcp && mtcp->
es)
284 #if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
288 #ifdef ENABLE_MANAGEMENT
295 #ifdef ENABLE_ASYNC_PUSH
333 dmsg(
D_MULTI_TCP,
"MULTI TCP: transmitting previously deferred packet");
395 unsigned int looking_for = 0;
407 tun_input_pending = NULL;
413 tun_input_pending = NULL;
419 tun_input_pending = NULL;
432 msg(
M_FATAL,
"MULTI TCP: multi_tcp_wait_lite, unhandled action=%d", action);
437 *tun_input_pending =
true;
485 ASSERT(mi->context.c2.link_socket);
489 if (!
IS_SIG(&mi->context))
492 if (!
IS_SIG(&mi->context))
531 msg(
M_FATAL,
"MULTI TCP: multi_tcp_dispatch, unhandled action=%d", action);
545 #define MTP_TUN_OUT (1<<0)
546 #define MTP_LINK_OUT (1<<1)
583 msg(
M_FATAL,
"MULTI TCP: multi_tcp_post bad state, mi=%s flags=%d",
601 bool tun_input_pending =
false;
622 const int orig_action = action;
626 msg(
M_FATAL,
"MULTI TCP: I/O wait required blocking in multi_tcp_action, action=%d", orig_action);
671 if (tun_input_pending && action ==
TA_UNDEF)
675 tun_input_pending =
false;
692 for (i = 0; i < mtcp->
n_esr; ++i)
714 #ifdef ENABLE_MANAGEMENT
746 #if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD))
758 #ifdef ENABLE_ASYNC_PUSH
816 #ifdef ENABLE_ASYNC_PUSH
817 multi.
top.
c2.inotify_fd = inotify_init();
818 if (multi.
top.
c2.inotify_fd < 0)
852 #ifdef ENABLE_ASYNC_PUSH
853 close(
top->
c2.inotify_fd);
static int multi_tcp_wait(const struct context *c, struct multi_tcp *mtcp)
unsigned int event_set_status
bool mbuf_extract_item(struct mbuf_set *ms, struct mbuf_item *item)
volatile int signal_received
Server-mode state structure for one single VPN tunnel.
union openvpn_sockaddr::@14 addr
bool multi_process_incoming_dco(struct multi_context *m)
Process an incoming DCO message (from kernel space).
static bool mbuf_defined(const struct mbuf_set *ms)
#define PERF_PROC_OUT_TUN_MTCP
static struct hash_bucket * hash_bucket(struct hash *hash, uint32_t hv)
static struct gc_arena gc_new(void)
static bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
void management_socket_set(struct management *man, struct event_set *es, void *arg, unsigned int *persistent)
static void buf_reset(struct buffer *buf)
static void multi_tcp_set_global_rw_flags(struct multi_context *m, struct multi_instance *mi)
struct tuntap * tuntap
Tun/tap virtual network interface.
static bool tuntap_is_wintun(struct tuntap *tt)
Contains all state information for one tunnel.
struct link_socket_addr * lsa
struct mbuf_set * mbuf
Set of buffers for passing data channel packets between VPN tunnel instances.
static int multi_tcp_wait_lite(struct multi_context *m, struct multi_instance *mi, const int action, bool *tun_input_pending)
struct mroute_addr real
External network address of the remote peer.
static void set_prefix(struct multi_instance *mi)
static struct multi_instance * mbuf_peek(struct mbuf_set *ms)
void multi_tcp_dereference_instance(struct multi_tcp *mtcp, struct multi_instance *mi)
void multi_uninit(struct multi_context *m)
#define TA_SOCKET_WRITE_READY
static bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags)
void multi_close_instance_on_signal(struct multi_context *m, struct multi_instance *mi)
void multi_ifconfig_pool_persist(struct multi_context *m, bool force)
int mode
Role of this context within the OpenVPN process.
static void event_ctl(struct event_set *es, event_t event, unsigned int rwflags, void *arg)
static void clear_prefix(void)
struct context_2 c2
Level 2 context.
static void event_del(struct event_set *es, event_t event)
static event_t socket_event_handle(const struct link_socket *s)
void multi_init(struct multi_context *m, struct context *t, bool tcp_mode)
struct context top
Storage structure for process-wide configuration.
void mbuf_add_item(struct mbuf_set *ms, const struct mbuf_item *item)
static void hash_add_fast(struct hash *hash, struct hash_bucket *bucket, const void *key, uint32_t hv, void *value)
void multi_assign_peer_id(struct multi_context *m, struct multi_instance *mi)
Assigns a peer-id to a a client and adds the instance to the the instances array of the multi_context...
static void io_wait(struct context *c, const unsigned int flags)
void tunnel_server_tcp(struct context *top)
Main event loop for OpenVPN in TCP server mode.
bool multi_process_timeout(struct multi_context *m, const unsigned int mpp_flags)
void multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool shutdown)
static void update_time(void)
bool multi_tcp_instance_specific_init(struct multi_context *m, struct multi_instance *mi)
static bool multi_process_outgoing_link_dowork(struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
void mbuf_free(struct mbuf_set *ms)
void close_instance(struct context *c)
static void perf_pop(void)
#define MTCP_FILE_CLOSE_WRITE
#define LS_MODE_TCP_ACCEPT_FROM
struct hash_element * hash_lookup_fast(struct hash *hash, struct hash_bucket *bucket, const void *key, uint32_t hv)
struct options options
Options loaded from command line or configuration file.
struct multi_instance ** mpp_touched
void dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
void read_incoming_tun(struct context *c)
Read a packet from the virtual tun/tap network interface.
struct hash * hash
VPN tunnel instances indexed by real address of the remote peer.
static void multi_process_per_second_timers(struct multi_context *m)
struct multi_instance * instance
#define MULTI_CHECK_SIG(m)
static bool tuntap_ring_empty(struct tuntap *tt)
struct multi_instance * pending
bool multi_process_post(struct multi_context *m, struct multi_instance *mi, const unsigned int flags)
Perform postprocessing of a VPN tunnel instance.
bool mroute_extract_openvpn_sockaddr(struct mroute_addr *addr, const struct openvpn_sockaddr *osaddr, bool use_port)
Wrapper structure for dynamically allocated memory.
struct multi_instance * multi_create_instance(struct multi_context *m, const struct mroute_addr *real)
static struct multi_instance * multi_create_instance_tcp(struct multi_context *m)
#define IOW_READ_TUN_FORCE
static int multi_tcp_post(struct multi_context *m, struct multi_instance *mi, const int action)
struct link_socket_info info
struct link_socket_actual actual
static struct context * multi_tcp_context(struct multi_context *m, struct multi_instance *mi)
struct timeval timeval
Time to next event of timers and similar.
struct link_socket * link_socket
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 ...
struct mbuf_buffer * mbuf_alloc_buf(const struct buffer *buf)
static void socket_reset_listen_persistent(struct link_socket *s)
Garbage collection arena used to keep track of dynamically allocated memory.
struct signal_info * sig
Internal error signaling object.
void context_clear_2(struct context *c)
#define TA_SOCKET_WRITE_DEFERRED
const char * mroute_addr_print(const struct mroute_addr *ma, struct gc_arena *gc)
void uninit_management_callback(void)
void multi_tcp_free(struct multi_tcp *mtcp)
static void multi_tcp_process_io(struct multi_context *m)
Main OpenVPN server state structure.
void init_management_callback_multi(struct multi_context *m)
void multi_top_init(struct multi_context *m, struct context *top)
struct env_set * es
Set of environment variables.
#define CC_HARD_USR1_TO_HUP
static void event_free(struct event_set *es)
static struct multi_instance * multi_tcp_dispatch(struct multi_context *m, struct multi_instance *mi, const int action)
struct multi_tcp * multi_tcp_init(int maxevents, int *maxclients)
void init_instance_handle_signals(struct context *c, const struct env_set *env, const unsigned int flags)
static int max_int(int x, int y)
void mbuf_free_buf(struct mbuf_buffer *mb)
unsigned int socket_set(struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
static void multi_tcp_action(struct multi_context *m, struct multi_instance *mi, int action, bool poll)
#define TA_TUN_WRITE_TIMEOUT
static bool stream_buf_read_setup(struct link_socket *sock)
static SERVICE_STATUS status
void read_incoming_link(struct context *c)
Read a packet from the external network interface.
void multi_process_drop_outgoing_tun(struct multi_context *m, const unsigned int mpp_flags)
static int min_int(int x, int y)
static void gc_free(struct gc_arena *a)
struct event_set * event_set_init(int *maxevents, unsigned int flags)
const char * multi_instance_string(const struct multi_instance *mi, bool null, struct gc_arena *gc)
#define ALLOC_OBJ_CLEAR(dptr, type)
static void wait_signal(struct event_set *es, void *arg)
static void socket_set_listen_persistent(struct link_socket *s, struct event_set *es, void *arg)
static bool socket_read_residual(const struct link_socket *s)
bool multi_process_incoming_link(struct multi_context *m, struct multi_instance *instance, const unsigned int mpp_flags)
Demultiplex and process a packet received over the external network interface.
struct mbuf_buffer * buffer
#define TA_SOCKET_READ_RESIDUAL
struct multi_tcp * mtcp
State specific to OpenVPN using TCP as external transport.
static void get_signal(volatile int *sig)
Copy the global signal_received (if non-zero) to the passed-in argument sig.
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.
struct mbuf_set * tcp_link_out_deferred
struct openvpn_sockaddr dest
#define ALLOC_ARRAY(dptr, type, n)
struct mbuf_set * mbuf_init(unsigned int size)
unsigned int management_persist_flags
void multi_top_free(struct multi_context *m)
static void tun_set(struct tuntap *tt, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
void multi_tcp_instance_specific_free(struct multi_instance *mi)
void multi_tcp_delete_event(struct multi_tcp *mtcp, event_t event)
static void tv_clear(struct timeval *tv)
static void perf_push(int type)
void management_io(struct management *man)
struct context context
The context structure storing state for this VPN tunnel.
struct event_set_return * esr
static void multi_get_timeout(struct multi_context *m, struct timeval *dest)
void initialization_sequence_completed(struct context *c, const unsigned int flags)
static struct multi_instance * multi_process_outgoing_link_pre(struct multi_context *m)
static uint32_t hash_value(const struct hash *hash, const void *key)
static int event_wait(struct event_set *es, const struct timeval *tv, struct event_set_return *out, int outlen)
struct context_1 c1
Level 1 context.