OpenVPN
Data Structures | Macros | Functions
multi.h File Reference
#include "init.h"
#include "forward.h"
#include "mroute.h"
#include "mbuf.h"
#include "list.h"
#include "schedule.h"
#include "pool.h"
#include "mudp.h"
#include "mtcp.h"
#include "perf.h"
Include dependency graph for multi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  multi_reap
 
struct  deferred_signal_schedule_entry
 
struct  multi_instance
 Server-mode state structure for one single VPN tunnel. More...
 
struct  multi_context
 Main OpenVPN server state structure. More...
 
struct  multi_route
 

Macros

#define MULTI_PREFIX_MAX_LENGTH   256
 
#define MC_UNDEF   0
 
#define MC_SINGLE_THREADED   (1<<0)
 
#define MC_MULTI_THREADED_MASTER   (1<<1)
 
#define MC_MULTI_THREADED_WORKER   (1<<2)
 
#define MC_MULTI_THREADED_SCHEDULER   (1<<3)
 
#define MC_WORK_THREAD   (MC_MULTI_THREADED_WORKER|MC_MULTI_THREADED_SCHEDULER)
 
#define MULTI_ROUTE_CACHE   (1<<0)
 
#define MULTI_ROUTE_AGEABLE   (1<<1)
 
#define MPP_PRE_SELECT   (1<<0)
 
#define MPP_CONDITIONAL_PRE_SELECT   (1<<1)
 
#define MPP_CLOSE_ON_SIGNAL   (1<<2)
 
#define MPP_RECORD_TOUCH   (1<<3)
 
#define REAP_MAX_WAKEUP   10 /* Do reap pass at least once per n seconds */
 
#define REAP_DIVISOR   256 /* How many passes to cover whole hash table */
 
#define REAP_MIN   16 /* Minimum number of buckets per pass */
 
#define REAP_MAX   1024 /* Maximum number of buckets per pass */
 
#define MULTI_CACHE_ROUTE_TTL   60
 
#define MULTI_CHECK_SIG(m)   EVENT_LOOP_CHECK_SIGNAL(&(m)->top, multi_process_signal, (m))
 

Functions

void tunnel_server (struct context *top)
 Main event loop for OpenVPN in server mode. More...
 
const char * multi_instance_string (const struct multi_instance *mi, bool null, struct gc_arena *gc)
 
void multi_init (struct multi_context *m, struct context *t, bool tcp_mode, int thread_mode)
 
void multi_uninit (struct multi_context *m)
 
void multi_top_init (struct multi_context *m, const struct context *top)
 
void multi_top_free (struct multi_context *m)
 
struct multi_instancemulti_create_instance (struct multi_context *m, const struct mroute_addr *real)
 
void multi_close_instance (struct multi_context *m, struct multi_instance *mi, bool shutdown)
 
bool multi_process_timeout (struct multi_context *m, const unsigned int mpp_flags)
 
void multi_process_float (struct multi_context *m, struct multi_instance *mi)
 Handles peer floating. More...
 
bool multi_process_post (struct multi_context *m, struct multi_instance *mi, const unsigned int flags)
 Perform postprocessing of a VPN tunnel instance. More...
 
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. More...
 
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 and then process it accordingly. More...
 
void multi_process_drop_outgoing_tun (struct multi_context *m, const unsigned int mpp_flags)
 
void multi_print_status (struct multi_context *m, struct status_output *so, const int version)
 
struct multi_instancemulti_get_queue (struct mbuf_set *ms)
 
void multi_add_mbuf (struct multi_context *m, struct multi_instance *mi, struct mbuf_buffer *mb)
 
void multi_ifconfig_pool_persist (struct multi_context *m, bool force)
 
bool multi_process_signal (struct multi_context *m)
 
void multi_close_instance_on_signal (struct multi_context *m, struct multi_instance *mi)
 
void init_management_callback_multi (struct multi_context *m)
 
void uninit_management_callback_multi (struct multi_context *m)
 
static bool multi_output_queue_ready (const struct multi_context *m, const struct multi_instance *mi)
 
static struct multi_instancemulti_process_outgoing_link_pre (struct multi_context *m)
 
void route_quota_exceeded (const struct multi_context *m, const struct multi_instance *mi)
 
static void route_quota_inc (struct multi_instance *mi)
 
static void route_quota_dec (struct multi_instance *mi)
 
static bool route_quota_test (const struct multi_context *m, const struct multi_instance *mi)
 
static void multi_instance_inc_refcount (struct multi_instance *mi)
 
static void multi_instance_dec_refcount (struct multi_instance *mi)
 
static void multi_route_del (struct multi_route *route)
 
static bool multi_route_defined (const struct multi_context *m, const struct multi_route *r)
 
void ungenerate_prefix (struct multi_instance *mi)
 
static void set_prefix (struct multi_instance *mi)
 
static void clear_prefix (void)
 
void multi_reap_process_dowork (const struct multi_context *m)
 
void multi_process_per_second_timers_dowork (struct multi_context *m)
 
static void multi_reap_process (const struct multi_context *m)
 
static void multi_process_per_second_timers (struct multi_context *m)
 
static void multi_get_timeout (struct multi_context *m, struct timeval *dest)
 
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. More...
 
static bool multi_process_outgoing_link_dowork (struct multi_context *m, struct multi_instance *mi, const unsigned int mpp_flags)
 
static void multi_set_pending (struct multi_context *m, struct multi_instance *mi)
 

Macro Definition Documentation

◆ MC_MULTI_THREADED_MASTER

#define MC_MULTI_THREADED_MASTER   (1<<1)

Definition at line 134 of file multi.h.

◆ MC_MULTI_THREADED_SCHEDULER

#define MC_MULTI_THREADED_SCHEDULER   (1<<3)

Definition at line 136 of file multi.h.

◆ MC_MULTI_THREADED_WORKER

#define MC_MULTI_THREADED_WORKER   (1<<2)

Definition at line 135 of file multi.h.

◆ MC_SINGLE_THREADED

#define MC_SINGLE_THREADED   (1<<0)

Definition at line 133 of file multi.h.

Referenced by tunnel_server_tcp(), and tunnel_server_udp_single_threaded().

◆ MC_UNDEF

#define MC_UNDEF   0

Definition at line 132 of file multi.h.

Referenced by multi_uninit().

◆ MC_WORK_THREAD

Definition at line 137 of file multi.h.

Referenced by multi_uninit().

◆ MPP_CLOSE_ON_SIGNAL

#define MPP_CLOSE_ON_SIGNAL   (1<<2)

◆ MPP_CONDITIONAL_PRE_SELECT

#define MPP_CONDITIONAL_PRE_SELECT   (1<<1)

Definition at line 257 of file multi.h.

Referenced by multi_process_io_udp(), and multi_process_post().

◆ MPP_PRE_SELECT

#define MPP_PRE_SELECT   (1<<0)

◆ MPP_RECORD_TOUCH

#define MPP_RECORD_TOUCH   (1<<3)

Definition at line 259 of file multi.h.

Referenced by multi_process_post(), multi_tcp_dispatch(), and multi_tcp_process_io().

◆ MULTI_CACHE_ROUTE_TTL

#define MULTI_CACHE_ROUTE_TTL   60

Definition at line 537 of file multi.h.

Referenced by multi_init().

◆ MULTI_CHECK_SIG

#define MULTI_CHECK_SIG (   m)    EVENT_LOOP_CHECK_SIGNAL(&(m)->top, multi_process_signal, (m))

Definition at line 648 of file multi.h.

Referenced by tunnel_server_tcp(), and tunnel_server_udp_single_threaded().

◆ MULTI_PREFIX_MAX_LENGTH

#define MULTI_PREFIX_MAX_LENGTH   256

Definition at line 44 of file multi.h.

Referenced by multi_instance_string().

◆ MULTI_ROUTE_AGEABLE

#define MULTI_ROUTE_AGEABLE   (1<<1)

Definition at line 203 of file multi.h.

Referenced by multi_get_instance_by_virtual_addr(), and multi_route_defined().

◆ MULTI_ROUTE_CACHE

#define MULTI_ROUTE_CACHE   (1<<0)

◆ REAP_DIVISOR

#define REAP_DIVISOR   256 /* How many passes to cover whole hash table */

Definition at line 529 of file multi.h.

Referenced by reap_buckets_per_pass().

◆ REAP_MAX

#define REAP_MAX   1024 /* Maximum number of buckets per pass */

Definition at line 531 of file multi.h.

Referenced by reap_buckets_per_pass().

◆ REAP_MAX_WAKEUP

#define REAP_MAX_WAKEUP   10 /* Do reap pass at least once per n seconds */

Definition at line 528 of file multi.h.

Referenced by multi_get_timeout().

◆ REAP_MIN

#define REAP_MIN   16 /* Minimum number of buckets per pass */

Definition at line 530 of file multi.h.

Referenced by reap_buckets_per_pass().

Function Documentation

◆ clear_prefix()

static void clear_prefix ( void  )
inlinestatic

◆ init_management_callback_multi()

void init_management_callback_multi ( struct multi_context m)

◆ multi_add_mbuf()

void multi_add_mbuf ( struct multi_context m,
struct multi_instance mi,
struct mbuf_buffer mb 
)

◆ multi_close_instance()

void multi_close_instance ( struct multi_context m,
struct multi_instance mi,
bool  shutdown 
)

◆ multi_close_instance_on_signal()

void multi_close_instance_on_signal ( struct multi_context m,
struct multi_instance mi 
)

◆ multi_create_instance()

struct multi_instance* multi_create_instance ( struct multi_context m,
const struct mroute_addr real 
)

◆ multi_get_queue()

struct multi_instance* multi_get_queue ( struct mbuf_set ms)

◆ multi_get_timeout()

static void multi_get_timeout ( struct multi_context m,
struct timeval *  dest 
)
inlinestatic

◆ multi_ifconfig_pool_persist()

void multi_ifconfig_pool_persist ( struct multi_context m,
bool  force 
)

◆ multi_init()

void multi_init ( struct multi_context m,
struct context t,
bool  tcp_mode,
int  thread_mode 
)

Definition at line 295 of file multi.c.

References ASSERT, context::c1, options::cf_max, options::cf_per, CLEAR, D_MULTI_LOW, multi_context::deferred_shutdown_signal, options::dev, options::dev_type, dev_type_enum(), DEV_TYPE_TUN, DEV_TYPE_UNDEF, options::duplicate_cn, multi_context::enable_c2c, options::enable_c2c, event_timeout_init(), frequency_limit_init(), get_random(), multi_context::hash, hash_init(), options::ifconfig_ipv6_pool_base, options::ifconfig_ipv6_pool_defined, options::ifconfig_ipv6_pool_netbits, multi_context::ifconfig_pool, IFCONFIG_POOL_30NET, options::ifconfig_pool_defined, options::ifconfig_pool_end, IFCONFIG_POOL_INDIV, ifconfig_pool_init(), context_1::ifconfig_pool_persist, ifconfig_pool_read(), options::ifconfig_pool_start, multi_context::instances, multi_context::iter, tuntap::local, multi_context::local, M_INFO, multi_context::max_clients, options::max_clients, multi_context::mbuf, mbuf_init(), mroute_addr_compare_function(), mroute_addr_hash_function(), mroute_extract_in_addr_t(), mroute_helper_init(), msg, multi_context::mtcp, MULTI_CACHE_ROUTE_TTL, multi_reap_new(), multi_tcp_init(), options::n_bcast_buf, multi_context::new_connection_limiter, context::options, options::real_hash_size, reap_buckets_per_pass(), multi_context::reaper, multi_context::route_helper, multi_context::schedule, schedule_init(), deferred_signal_schedule_entry::signal_received, options::stale_routes_ageing_time, multi_context::stale_routes_check_et, options::stale_routes_check_interval, multi_context::status_file_version, options::status_file_version, multi_context::tcp_queue_limit, options::tcp_queue_limit, multi_context::thread_mode, TOP_NET30, options::topology, context_1::tuntap, multi_context::vhash, and options::virtual_hash_size.

Referenced by tunnel_server_tcp(), and tunnel_server_udp_single_threaded().

◆ multi_instance_dec_refcount()

static void multi_instance_dec_refcount ( struct multi_instance mi)
inlinestatic

Definition at line 446 of file multi.h.

References free, multi_instance::gc, gc_free(), and multi_instance::refcount.

Referenced by multi_close_instance(), and multi_route_del().

◆ multi_instance_inc_refcount()

static void multi_instance_inc_refcount ( struct multi_instance mi)
inlinestatic

Definition at line 440 of file multi.h.

References multi_instance::refcount.

Referenced by multi_create_instance(), and multi_learn_addr().

◆ multi_instance_string()

const char* multi_instance_string ( const struct multi_instance mi,
bool  null,
struct gc_arena gc 
)

◆ multi_output_queue_ready()

static bool multi_output_queue_ready ( const struct multi_context m,
const struct multi_instance mi 
)
inlinestatic

◆ multi_print_status()

void multi_print_status ( struct multi_context m,
struct status_output so,
const int  version 
)

◆ multi_process_drop_outgoing_tun()

void multi_process_drop_outgoing_tun ( struct multi_context m,
const unsigned int  mpp_flags 
)

◆ multi_process_float()

void multi_process_float ( struct multi_context m,
struct multi_instance mi 
)

◆ multi_process_outgoing_link_dowork()

static bool multi_process_outgoing_link_dowork ( struct multi_context m,
struct multi_instance mi,
const unsigned int  mpp_flags 
)
inlinestatic

◆ multi_process_outgoing_link_pre()

static struct multi_instance* multi_process_outgoing_link_pre ( struct multi_context m)
static

◆ multi_process_per_second_timers()

static void multi_process_per_second_timers ( struct multi_context m)
inlinestatic

◆ multi_process_per_second_timers_dowork()

void multi_process_per_second_timers_dowork ( struct multi_context m)

◆ multi_process_post()

bool multi_process_post ( struct multi_context m,
struct multi_instance mi,
const unsigned int  flags 
)

Perform postprocessing of a VPN tunnel instance.

After some VPN tunnel activity has taken place, the VPN tunnel's state may need updating and some follow-up action may be required. This function controls the necessary postprocessing. It is called by many other functions that handle VPN tunnel related activity, such as multi_process_incoming_link(), multi_process_outgoing_link(), multi_process_incoming_tun(), multi_process_outgoing_tun(), and multi_process_timeout(), among others.

Parameters
m- The single multi_context structure.
mi- The multi_instance of the VPN tunnel to be postprocessed.
flags- Fast I/O optimization flags.
Returns
  • True, if the VPN tunnel instance mi was not closed due to a signal during processing.
  • False, if the VPN tunnel instance mi was closed.

Definition at line 2328 of file multi.c.

References ANY_OUT, key_state::authenticated, context::c2, CONNECTION_ESTABLISHED, multi_instance::connection_established_flag, multi_instance::context, context_2::fragment, hash_add(), hash_remove(), IS_SIG, tls_session::key, KS_PRIMARY, buffer::len, M_ERRNO, M_NONFATAL, MPP_CLOSE_ON_SIGNAL, MPP_CONDITIONAL_PRE_SELECT, MPP_PRE_SELECT, MPP_RECORD_TOUCH, multi_context::mpp_touched, msg, multi_close_instance_on_signal(), multi_connection_established(), multi_schedule_context_wakeup(), multi_set_pending(), fragment_master::outgoing, multi_context::pending, pre_select(), tls_multi::session, context_2::timeval, context_2::tls_multi, TM_ACTIVE, context_2::to_link, context_2::to_tun, and multi_context::top.

Referenced by multi_connection_established(), multi_create_instance(), multi_process_drop_outgoing_tun(), multi_process_incoming_link(), multi_process_incoming_tun(), multi_process_outgoing_link_dowork(), multi_process_outgoing_tun(), multi_process_timeout(), multi_tcp_dispatch(), and multi_tcp_process_outgoing_link().

◆ multi_process_signal()

bool multi_process_signal ( struct multi_context m)

◆ multi_process_timeout()

bool multi_process_timeout ( struct multi_context m,
const unsigned int  mpp_flags 
)

◆ multi_reap_process()

static void multi_reap_process ( const struct multi_context m)
inlinestatic

◆ multi_reap_process_dowork()

void multi_reap_process_dowork ( const struct multi_context m)

◆ multi_route_defined()

static bool multi_route_defined ( const struct multi_context m,
const struct multi_route r 
)
inlinestatic

◆ multi_route_del()

static void multi_route_del ( struct multi_route route)
inlinestatic

◆ multi_set_pending()

static void multi_set_pending ( struct multi_context m,
struct multi_instance mi 
)
inlinestatic

◆ multi_top_free()

void multi_top_free ( struct multi_context m)

◆ multi_top_init()

void multi_top_init ( struct multi_context m,
const struct context top 
)

◆ multi_uninit()

void multi_uninit ( struct multi_context m)

◆ route_quota_dec()

static void route_quota_dec ( struct multi_instance mi)
inlinestatic

Definition at line 415 of file multi.h.

References multi_instance::route_count.

Referenced by multi_route_del().

◆ route_quota_exceeded()

void route_quota_exceeded ( const struct multi_context m,
const struct multi_instance mi 
)

◆ route_quota_inc()

static void route_quota_inc ( struct multi_instance mi)
inlinestatic

Definition at line 409 of file multi.h.

References multi_instance::route_count.

Referenced by multi_learn_addr().

◆ route_quota_test()

static bool route_quota_test ( const struct multi_context m,
const struct multi_instance mi 
)
inlinestatic

◆ set_prefix()

static void set_prefix ( struct multi_instance mi)
inlinestatic

◆ ungenerate_prefix()

void ungenerate_prefix ( struct multi_instance mi)

◆ uninit_management_callback_multi()

void uninit_management_callback_multi ( struct multi_context m)

Definition at line 3376 of file multi.c.

References uninit_management_callback().

Referenced by tunnel_server_tcp(), and tunnel_server_udp_single_threaded().