OpenVPN
Functions
multi.c File Reference
#include "syshead.h"
#include "forward.h"
#include "multi.h"
#include "push.h"
#include "run_command.h"
#include "otime.h"
#include "pf.h"
#include "gremlin.h"
#include "mstats.h"
#include "ssl_verify.h"
#include <inttypes.h>
#include "memdbg.h"
#include "crypto_backend.h"
Include dependency graph for multi.c:

Go to the source code of this file.

Functions

static void update_mstat_n_clients (const int n_clients)
 
static bool learn_address_script (const struct multi_context *m, const struct multi_instance *mi, const char *op, const struct mroute_addr *addr)
 
void multi_ifconfig_pool_persist (struct multi_context *m, bool force)
 
static void multi_reap_range (const struct multi_context *m, int start_bucket, int end_bucket)
 
static void multi_reap_all (const struct multi_context *m)
 
static struct multi_reapmulti_reap_new (int buckets_per_pass)
 
void multi_reap_process_dowork (const struct multi_context *m)
 
static void multi_reap_free (struct multi_reap *mr)
 
static int reap_buckets_per_pass (int n_buckets)
 
void multi_init (struct multi_context *m, struct context *t, bool tcp_mode, int thread_mode)
 
const char * multi_instance_string (const struct multi_instance *mi, bool null, struct gc_arena *gc)
 
static void generate_prefix (struct multi_instance *mi)
 
void ungenerate_prefix (struct multi_instance *mi)
 
static const char * mi_prefix (const struct multi_instance *mi)
 
static void multi_del_iroutes (struct multi_context *m, struct multi_instance *mi)
 
static void setenv_stats (struct context *c)
 
static void multi_client_disconnect_setenv (struct multi_context *m, struct multi_instance *mi)
 
static void multi_client_disconnect_script (struct multi_context *m, struct multi_instance *mi)
 
void multi_close_instance (struct multi_context *m, struct multi_instance *mi, bool shutdown)
 
void multi_uninit (struct multi_context *m)
 
struct multi_instancemulti_create_instance (struct multi_context *m, const struct mroute_addr *real)
 
void multi_print_status (struct multi_context *m, struct status_output *so, const int version)
 
static struct multi_instancemulti_learn_addr (struct multi_context *m, struct multi_instance *mi, const struct mroute_addr *addr, const unsigned int flags)
 
static struct multi_instancemulti_get_instance_by_virtual_addr (struct multi_context *m, const struct mroute_addr *addr, bool cidr_routing)
 
static struct multi_instancemulti_learn_in_addr_t (struct multi_context *m, struct multi_instance *mi, in_addr_t a, int netbits, bool primary)
 
static struct multi_instancemulti_learn_in6_addr (struct multi_context *m, struct multi_instance *mi, struct in6_addr a6, int netbits, bool primary)
 
static void multi_add_iroutes (struct multi_context *m, struct multi_instance *mi)
 
static void multi_delete_dup (struct multi_context *m, struct multi_instance *new_mi)
 
static void check_stale_routes (struct multi_context *m)
 
static bool ifconfig_push_constraint_satisfied (const struct context *c)
 
static void multi_select_virtual_addr (struct multi_context *m, struct multi_instance *mi)
 
static void multi_set_virtual_addr_env (struct multi_context *m, struct multi_instance *mi)
 
static void multi_client_connect_post (struct multi_context *m, struct multi_instance *mi, const char *dc_file, unsigned int option_permissions_mask, unsigned int *option_types_found)
 
static void multi_client_connect_post_plugin (struct multi_context *m, struct multi_instance *mi, const struct plugin_return *pr, unsigned int option_permissions_mask, unsigned int *option_types_found)
 
static void multi_client_connect_setenv (struct multi_context *m, struct multi_instance *mi)
 
static void multi_connection_established (struct multi_context *m, struct multi_instance *mi)
 
void multi_add_mbuf (struct multi_context *m, struct multi_instance *mi, struct mbuf_buffer *mb)
 
static void multi_unicast (struct multi_context *m, const struct buffer *buf, struct multi_instance *mi)
 
static void multi_bcast (struct multi_context *m, const struct buffer *buf, const struct multi_instance *sender_instance, const struct mroute_addr *sender_addr)
 
static unsigned int compute_wakeup_sigma (const struct timeval *delta)
 
static void multi_schedule_context_wakeup (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. More...
 
void multi_process_float (struct multi_context *m, struct multi_instance *mi)
 Handles peer floating. 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...
 
struct multi_instancemulti_get_queue (struct mbuf_set *ms)
 
bool multi_process_timeout (struct multi_context *m, const unsigned int mpp_flags)
 
void multi_process_drop_outgoing_tun (struct multi_context *m, const unsigned int mpp_flags)
 
void route_quota_exceeded (const struct multi_context *m, const struct multi_instance *mi)
 
static bool stale_route_check_trigger (struct multi_context *m)
 
void multi_process_per_second_timers_dowork (struct multi_context *m)
 
void multi_top_init (struct multi_context *m, const struct context *top)
 
void multi_top_free (struct multi_context *m)
 
static bool is_exit_restart (int sig)
 
static void multi_push_restart_schedule_exit (struct multi_context *m, bool next_server)
 
bool multi_process_signal (struct multi_context *m)
 
void multi_close_instance_on_signal (struct multi_context *m, struct multi_instance *mi)
 
static void multi_signal_instance (struct multi_context *m, struct multi_instance *mi, const int sig)
 
static void management_callback_status (void *arg, const int version, struct status_output *so)
 
static int management_callback_n_clients (void *arg)
 
static int management_callback_kill_by_cn (void *arg, const char *del_cn)
 
static int management_callback_kill_by_addr (void *arg, const in_addr_t addr, const int port)
 
static void management_delete_event (void *arg, event_t event)
 
void init_management_callback_multi (struct multi_context *m)
 
void uninit_management_callback_multi (struct multi_context *m)
 
void tunnel_server (struct context *top)
 Main event loop for OpenVPN in server mode. More...
 

Function Documentation

◆ check_stale_routes()

static void check_stale_routes ( struct multi_context m)
static

◆ compute_wakeup_sigma()

static unsigned int compute_wakeup_sigma ( const struct timeval *  delta)
inlinestatic

Definition at line 2285 of file multi.c.

Referenced by multi_push_restart_schedule_exit(), and multi_schedule_context_wakeup().

◆ generate_prefix()

static void generate_prefix ( struct multi_instance mi)
static

◆ ifconfig_push_constraint_satisfied()

static bool ifconfig_push_constraint_satisfied ( const struct context c)
static

◆ init_management_callback_multi()

void init_management_callback_multi ( struct multi_context m)

◆ is_exit_restart()

static bool is_exit_restart ( int  sig)
static

Definition at line 3040 of file multi.c.

References SIGHUP, SIGINT, SIGTERM, and SIGUSR1.

Referenced by multi_process_signal().

◆ learn_address_script()

static bool learn_address_script ( const struct multi_context m,
const struct multi_instance mi,
const char *  op,
const struct mroute_addr addr 
)
static

◆ management_callback_kill_by_addr()

static int management_callback_kill_by_addr ( void *  arg,
const in_addr_t  addr,
const int  port 
)
static

◆ management_callback_kill_by_cn()

static int management_callback_kill_by_cn ( void *  arg,
const char *  del_cn 
)
static

◆ management_callback_n_clients()

static int management_callback_n_clients ( void *  arg)
static

Definition at line 3150 of file multi.c.

References multi_context::n_clients.

Referenced by init_management_callback_multi().

◆ management_callback_status()

static void management_callback_status ( void *  arg,
const int  version,
struct status_output so 
)
static

Definition at line 3135 of file multi.c.

References multi_print_status(), and multi_context::status_file_version.

Referenced by init_management_callback_multi().

◆ management_delete_event()

static void management_delete_event ( void *  arg,
event_t  event 
)
static

◆ mi_prefix()

static const char* mi_prefix ( const struct multi_instance mi)
static

Definition at line 515 of file multi.c.

References multi_instance::msg_prefix.

Referenced by multi_bcast(), and multi_process_incoming_link().

◆ multi_add_iroutes()

static void multi_add_iroutes ( struct multi_context m,
struct multi_instance mi 
)
static

◆ multi_add_mbuf()

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

◆ multi_bcast()

static void multi_bcast ( struct multi_context m,
const struct buffer buf,
const struct multi_instance sender_instance,
const struct mroute_addr sender_addr 
)
static

◆ multi_client_connect_post()

static void multi_client_connect_post ( struct multi_context m,
struct multi_instance mi,
const char *  dc_file,
unsigned int  option_permissions_mask,
unsigned int *  option_types_found 
)
static

◆ multi_client_connect_post_plugin()

static void multi_client_connect_post_plugin ( struct multi_context m,
struct multi_instance mi,
const struct plugin_return pr,
unsigned int  option_permissions_mask,
unsigned int *  option_types_found 
)
static

◆ multi_client_connect_setenv()

static void multi_client_connect_setenv ( struct multi_context m,
struct multi_instance mi 
)
static

◆ multi_client_disconnect_script()

static void multi_client_disconnect_script ( struct multi_context m,
struct multi_instance mi 
)
static

◆ multi_client_disconnect_setenv()

static void multi_client_disconnect_setenv ( struct multi_context m,
struct multi_instance mi 
)
static

◆ 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_connection_established()

static void multi_connection_established ( struct multi_context m,
struct multi_instance mi 
)
static

Definition at line 1786 of file multi.c.

References argv_new(), argv_parse_cmd(), argv_printf(), argv_printf_cat(), argv_reset(), ASSERT, context::c1, context::c2, CAS_FAILED, CAS_PARTIAL, CAS_SUCCEEDED, CCD_DEFAULT, options::client_config_dir, options::client_connect_script, multi_instance::connection_established_flag, multi_instance::context, context_2::context_auth, D_IMPORT_ERRORS, D_MULTI_DEBUG, D_MULTI_ERRORS, D_MULTI_LOW, DEV_TYPE_TUN, options::disable, do_deferred_options(), options::duplicate_cn, context_2::es, gc_free(), gc_new(), generate_prefix(), hash_lookup(), hash_remove(), ifconfig_push_constraint_satisfied(), options::iroutes, M_OPTERR, M_WARN, msg, multi_add_iroutes(), multi_client_connect_post(), multi_client_connect_post_plugin(), multi_client_connect_setenv(), multi_delete_dup(), multi_instance_string(), multi_learn_in6_addr(), multi_learn_in_addr_t(), multi_process_post(), multi_select_virtual_addr(), multi_context::n_clients, multi_instance::n_clients_delta, OPENVPN_PLUGIN_CLIENT_CONNECT, OPENVPN_PLUGIN_CLIENT_CONNECT_V2, OPENVPN_PLUGIN_FUNC_SUCCESS, openvpn_run_script(), OPT_P_COMP, OPT_P_CONFIG, OPT_P_ECHO, OPT_P_INHERIT, OPT_P_INSTANCE, OPT_P_PUSH, OPT_P_SOCKFLAGS, OPT_P_TIMER, context::options, options_server_import(), platform_create_temp_file(), platform_gen_path(), platform_test_file(), platform_unlink(), plugin_call(), plugin_defined(), plugin_return_free(), plugin_return_init(), context::plugins, print_in6_addr(), print_in_addr_t(), process_incoming_push_request(), options::push_ifconfig_constraint_netmask, options::push_ifconfig_constraint_network, context_2::push_ifconfig_defined, context_2::push_ifconfig_ipv6_defined, context_2::push_ifconfig_ipv6_local, context_2::push_ifconfig_local, context_2::push_reply_deferred, read, remove_iroutes_from_push_route_list(), multi_instance::reporting_addr, multi_instance::reporting_addr_ipv6, setenv_str(), tls_authentication_status(), TLS_AUTHENTICATION_SUCCEEDED, tls_common_name(), tls_lock_cert_hash_set(), tls_lock_common_name(), context_2::tls_multi, options::tmp_dir, multi_context::top, TUNNEL_TYPE, context_1::tuntap, update_mstat_n_clients(), and multi_instance::vaddr_handle.

Referenced by multi_process_post().

◆ multi_create_instance()

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

◆ multi_del_iroutes()

static void multi_del_iroutes ( struct multi_context m,
struct multi_instance mi 
)
static

◆ multi_delete_dup()

static void multi_delete_dup ( struct multi_context m,
struct multi_instance new_mi 
)
static

◆ multi_get_instance_by_virtual_addr()

static struct multi_instance* multi_get_instance_by_virtual_addr ( struct multi_context m,
const struct mroute_addr addr,
bool  cidr_routing 
)
static

◆ multi_get_queue()

struct multi_instance* multi_get_queue ( struct mbuf_set ms)

◆ 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_string()

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

◆ multi_learn_addr()

static struct multi_instance* multi_learn_addr ( struct multi_context m,
struct multi_instance mi,
const struct mroute_addr addr,
const unsigned int  flags 
)
static

◆ multi_learn_in6_addr()

static struct multi_instance* multi_learn_in6_addr ( struct multi_context m,
struct multi_instance mi,
struct in6_addr  a6,
int  netbits,
bool  primary 
)
static

◆ multi_learn_in_addr_t()

static struct multi_instance* multi_learn_in_addr_t ( struct multi_context m,
struct multi_instance mi,
in_addr_t  a,
int  netbits,
bool  primary 
)
static

◆ 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_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_push_restart_schedule_exit()

static void multi_push_restart_schedule_exit ( struct multi_context m,
bool  next_server 
)
static

◆ multi_reap_all()

static void multi_reap_all ( const struct multi_context m)
static

Definition at line 211 of file multi.c.

References multi_reap_range().

Referenced by multi_uninit().

◆ multi_reap_free()

static void multi_reap_free ( struct multi_reap mr)
static

Definition at line 241 of file multi.c.

References free.

Referenced by multi_uninit().

◆ multi_reap_new()

static struct multi_reap* multi_reap_new ( int  buckets_per_pass)
static

Definition at line 217 of file multi.c.

References ALLOC_OBJ, multi_reap::bucket_base, multi_reap::buckets_per_pass, multi_reap::last_call, and now.

Referenced by multi_init().

◆ multi_reap_process_dowork()

void multi_reap_process_dowork ( const struct multi_context m)

◆ multi_reap_range()

static void multi_reap_range ( const struct multi_context m,
int  start_bucket,
int  end_bucket 
)
static

◆ multi_schedule_context_wakeup()

static void multi_schedule_context_wakeup ( struct multi_context m,
struct multi_instance mi 
)
static

◆ multi_select_virtual_addr()

static void multi_select_virtual_addr ( struct multi_context m,
struct multi_instance mi 
)
static

◆ multi_set_virtual_addr_env()

static void multi_set_virtual_addr_env ( struct multi_context m,
struct multi_instance mi 
)
static

◆ multi_signal_instance()

static void multi_signal_instance ( struct multi_context m,
struct multi_instance mi,
const int  sig 
)
static

◆ 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_unicast()

static void multi_unicast ( struct multi_context m,
const struct buffer buf,
struct multi_instance mi 
)
inlinestatic

◆ multi_uninit()

void multi_uninit ( struct multi_context m)

◆ reap_buckets_per_pass()

static int reap_buckets_per_pass ( int  n_buckets)
static

Definition at line 250 of file multi.c.

References constrain_int(), REAP_DIVISOR, REAP_MAX, and REAP_MIN.

Referenced by multi_init().

◆ route_quota_exceeded()

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

◆ setenv_stats()

static void setenv_stats ( struct context c)
static

◆ stale_route_check_trigger()

static bool stale_route_check_trigger ( struct multi_context m)
static

◆ 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().

◆ update_mstat_n_clients()

static void update_mstat_n_clients ( const int  n_clients)
inlinestatic

Definition at line 85 of file multi.c.

Referenced by multi_close_instance(), and multi_connection_established().