OpenVPN
multi.h File Reference

Header file for server-mode related structures and functions. More...

#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 "multi_io.h"
#include "vlan.h"
#include "reflect_filter.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  client_connect_defer_state
 Detached client connection state. More...
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 MULTI_ROUTE_CACHE   (1 << 0)
#define MULTI_ROUTE_AGEABLE   (1 << 1)
#define MULTI_ROUTE_PERMANENT   (1 << 2) /* config-derived (iroute / pushed ifconfig); never stale-aged */
#define MPP_PRE_SELECT   (1 << 0)
#define MPP_CLOSE_ON_SIGNAL   (1 << 1)
#define MPP_RECORD_TOUCH   (1 << 2)
#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 CLIENT_CONNECT_OPT_MASK
#define MULTI_CHECK_SIG(m)

Enumerations

enum  client_connect_return { CC_RET_FAILED , CC_RET_SUCCEEDED , CC_RET_DEFERRED , CC_RET_SKIPPED }
 Return values used by the client connect call-back functions. More...

Functions

void tunnel_server (struct context *top)
 Main event loop for OpenVPN in server mode.
const char * multi_instance_string (const struct multi_instance *mi, bool null, struct gc_arena *gc)
struct multi_instance * multi_create_instance (struct multi_context *m, const struct mroute_addr *real, struct link_socket *sock)
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)
bool multi_process_post (struct multi_context *m, struct multi_instance *mi, const unsigned int flags)
 Perform postprocessing of a VPN tunnel instance.
void multi_process_incoming_dco (dco_context_t *dco)
 Process an incoming DCO message (from kernel space).
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.
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.
struct multi_instance * multi_get_queue (struct mbuf_set *ms)
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)
static bool multi_output_queue_ready (const struct multi_context *m, const struct multi_instance *mi)
void route_quota_exceeded (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_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 (const 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_instance (struct multi_context *m, struct timeval *dest)
bool multi_check_push_ifconfig_extra_route (const struct options *o, in_addr_t dest)
 Determines if the ifconfig_push_local address falls into the range of the local IP addresses of the VPN interface (ifconfig_local with ifconfig_remote_netmask).
bool multi_check_push_ifconfig_ipv6_extra_route (const struct options *o, const struct in6_addr *dest)
 Determines if the ifconfig_ipv6_local address falls into the range of the local IP addresses of the VPN interface (ifconfig_local with ifconfig_remote_netmask).
static void multi_set_pending (struct multi_context *m, struct multi_instance *mi)
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 structure.
struct multi_instance * lookup_by_cid (struct multi_context *m, const unsigned long cid)
void update_vhash (struct multi_context *m, struct multi_instance *mi, const char *new_ip, const char *new_ipv6)
 Update the vhash with new IP/IPv6 addresses in the multi_context when a push-update message containing ifconfig/ifconfig-ipv6 options is sent from the server.
void unlearn_ifconfig (struct multi_context *m, struct multi_instance *mi)
void unlearn_ifconfig_ipv6 (struct multi_context *m, struct multi_instance *mi)

Detailed Description

Header file for server-mode related structures and functions.

Definition in file multi.h.

Macro Definition Documentation

◆ CLIENT_CONNECT_OPT_MASK

#define CLIENT_CONNECT_OPT_MASK
Value:
#define OPT_P_PUSH
Definition options.h:749
#define OPT_P_INSTANCE
allowed in ccd, client-connect etc
Definition options.h:750
#define OPT_P_ECHO
Definition options.h:753
#define OPT_P_CONFIG
Definition options.h:751
#define OPT_P_SOCKFLAGS
Definition options.h:759
#define OPT_P_TIMER
Definition options.h:740
#define OPT_P_COMP
Definition options.h:743
#define OPT_P_INHERIT
Definition options.h:754

Definition at line 609 of file multi.h.

Referenced by multi_client_connect_mda(), multi_client_connect_post(), and multi_client_connect_post_plugin().

◆ MPP_CLOSE_ON_SIGNAL

#define MPP_CLOSE_ON_SIGNAL   (1 << 1)

Definition at line 287 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 << 2)

Definition at line 288 of file multi.h.

Referenced by multi_io_dispatch(), multi_io_process_io(), and multi_process_post().

◆ MULTI_CACHE_ROUTE_TTL

#define MULTI_CACHE_ROUTE_TTL   60

Definition at line 549 of file multi.h.

Referenced by multi_init().

◆ MULTI_CHECK_SIG

#define MULTI_CHECK_SIG ( m)
Value:
bool multi_process_signal(struct multi_context *m)
Definition multi.c:3925
#define EVENT_LOOP_CHECK_SIGNAL(c, func, arg)
Definition openvpn.h:522

Definition at line 642 of file multi.h.

Referenced by tunnel_server_loop().

◆ 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 253 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)

◆ MULTI_ROUTE_PERMANENT

#define MULTI_ROUTE_PERMANENT   (1 << 2) /* config-derived (iroute / pushed ifconfig); never stale-aged */

Definition at line 254 of file multi.h.

Referenced by check_stale_routes(), multi_learn_in6_addr(), and multi_learn_in_addr_t().

◆ REAP_DIVISOR

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

Definition at line 541 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 543 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 540 of file multi.h.

Referenced by multi_get_timeout_instance().

◆ REAP_MIN

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

Definition at line 542 of file multi.h.

Referenced by reap_buckets_per_pass().

Enumeration Type Documentation

◆ client_connect_return

Return values used by the client connect call-back functions.

Enumerator
CC_RET_FAILED 
CC_RET_SUCCEEDED 
CC_RET_DEFERRED 
CC_RET_SKIPPED 

Definition at line 236 of file multi.h.

Function Documentation

◆ clear_prefix()

◆ init_management_callback_multi()

◆ lookup_by_cid()

◆ multi_assign_peer_id()

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 structure.

Parameters
m- The single multi_context structure.
mi- The multi_instance of the VPN tunnel to be postprocessed.

Definition at line 4190 of file multi.c.

References ASSERT, multi_context::assigned_peer_ids, context::c2, multi_instance::context, multi_context::instances, multi_context::max_clients, MAX_PEER_ID, multi_context::max_peerid, tls_multi::rx_peer_id, and context_2::tls_multi.

Referenced by handle_connection_attempt(), and multi_create_instance_tcp().

◆ multi_check_push_ifconfig_extra_route()

bool multi_check_push_ifconfig_extra_route ( const struct options * o,
in_addr_t dest )

Determines if the ifconfig_push_local address falls into the range of the local IP addresses of the VPN interface (ifconfig_local with ifconfig_remote_netmask).

Parameters
oThe instance wide options
destThe destination IP address to check
Returns
Returns true if ifconfig_push is outside that range and requires an extra route to be installed.

Definition at line 4487 of file multi.c.

References options::ifconfig_local, and options::ifconfig_remote_netmask.

Referenced by multi_learn_in_addr_t().

◆ multi_check_push_ifconfig_ipv6_extra_route()

bool multi_check_push_ifconfig_ipv6_extra_route ( const struct options * o,
const struct in6_addr * dest )

Determines if the ifconfig_ipv6_local address falls into the range of the local IP addresses of the VPN interface (ifconfig_local with ifconfig_remote_netmask).

Parameters
oThe instance wide options
destThe destination IPv6 address to check
Returns
Returns true if ifconfig_push is outside that range and requires an extra route to be installed.

Definition at line 4507 of file multi.c.

References options::ifconfig_ipv6_local, options::ifconfig_ipv6_netbits, and ipv6_net_contains_host().

Referenced by multi_learn_in6_addr().

◆ multi_close_instance()

◆ multi_close_instance_on_signal()

void multi_close_instance_on_signal ( struct multi_context * m,
struct multi_instance * mi )

◆ multi_create_instance()

◆ multi_get_queue()

◆ multi_get_timeout_instance()

void multi_get_timeout_instance ( struct multi_context * m,
struct timeval * dest )
inlinestatic

◆ multi_ifconfig_pool_persist()

◆ multi_instance_dec_refcount()

void multi_instance_dec_refcount ( struct multi_instance * mi)
inlinestatic

◆ multi_instance_inc_refcount()

void multi_instance_inc_refcount ( struct multi_instance * mi)
inlinestatic

Definition at line 454 of file multi.h.

References multi_instance::refcount.

Referenced by multi_create_instance(), multi_hash_sid_add(), and multi_learn_addr().

◆ multi_instance_string()

◆ multi_output_queue_ready()

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

◆ multi_process_incoming_dco()

void multi_process_incoming_dco ( dco_context_t * dco)

Process an incoming DCO message (from kernel space).

Parameters
dco- Pointer to the structure representing the DCO context.

Referenced by dco_read_and_process().

◆ multi_process_per_second_timers()

void multi_process_per_second_timers ( struct multi_context * m)
inlinestatic

◆ multi_process_per_second_timers_dowork()

◆ 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_io_write_link(), multi_process_incoming_tun(), multi_io_write_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 3044 of file multi.c.

References ANY_OUT, auth_deferred_status::auth_control_file, key_state::authenticated, context::c2, multi_instance::client_connect_defer_state, multi_instance::context, client_connect_defer_state::deferred_ret_file, context_2::fragment, is_cas_pending(), IS_SIG, tls_session::key, KS_AUTH_DEFERRED, KS_AUTH_FALSE, KS_PRIMARY, buffer::len, MPP_CLOSE_ON_SIGNAL, MPP_PRE_SELECT, MPP_RECORD_TOUCH, multi_context::mpp_touched, multi_close_instance_on_signal(), multi_connection_established(), multi_schedule_context_wakeup(), multi_set_pending(), tls_multi::multi_state, fragment_master::outgoing, multi_context::pending, key_state::plugin_auth, pre_select(), key_state::script_auth, 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_create_instance(), multi_io_dispatch(), multi_io_drop_tun(), multi_io_send_link(), multi_io_write_link(), multi_io_write_tun(), multi_process_incoming_link(), multi_process_incoming_tun(), and multi_process_timeout().

◆ multi_process_signal()

◆ multi_process_timeout()

◆ multi_reap_process()

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

◆ multi_route_del()

void multi_route_del ( struct multi_route * route)
inlinestatic

◆ multi_set_pending()

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

◆ route_quota_dec()

void route_quota_dec ( struct multi_instance * mi)
inlinestatic

Definition at line 429 of file multi.h.

References multi_instance::route_count.

Referenced by multi_route_del().

◆ route_quota_exceeded()

void route_quota_exceeded ( const struct multi_instance * mi)

◆ route_quota_inc()

void route_quota_inc ( struct multi_instance * mi)
inlinestatic

Definition at line 423 of file multi.h.

References multi_instance::route_count.

Referenced by multi_learn_addr().

◆ route_quota_test()

bool route_quota_test ( const struct multi_instance * mi)
inlinestatic

◆ set_prefix()

◆ ungenerate_prefix()

void ungenerate_prefix ( struct multi_instance * mi)

Definition at line 475 of file multi.c.

References multi_instance::msg_prefix, and set_prefix().

Referenced by multi_close_instance(), and multi_get_instance_udp_data().

◆ unlearn_ifconfig()

◆ unlearn_ifconfig_ipv6()

◆ update_vhash()

void update_vhash ( struct multi_context * m,
struct multi_instance * mi,
const char * new_ip,
const char * new_ipv6 )

Update the vhash with new IP/IPv6 addresses in the multi_context when a push-update message containing ifconfig/ifconfig-ipv6 options is sent from the server.

Parameters
mThe multi_context
miThe multi_instance of the client we are updating
new_ipThe new IPv4 address or NULL if no change
new_ipv6The new IPv6 address or NULL if no change

Definition at line 4441 of file multi.c.

References context::c2, CLEAR, multi_instance::context, multi_learn_in6_addr(), multi_learn_in_addr_t(), context_2::push_ifconfig_defined, context_2::push_ifconfig_ipv6_defined, context_2::push_ifconfig_ipv6_local, context_2::push_ifconfig_local, multi_instance::reporting_addr, multi_instance::reporting_addr_ipv6, unlearn_ifconfig(), and unlearn_ifconfig_ipv6().

Referenced by send_single_push_update().