OpenVPN
|
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 "perf.h"
#include "vlan.h"
#include "reflect_filter.h"
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 | 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 | CLIENT_CONNECT_OPT_MASK |
#define | MULTI_CHECK_SIG(m) EVENT_LOOP_CHECK_SIGNAL(&(m)->top, multi_process_signal, (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. | |
bool | multi_process_incoming_dco (struct multi_context *m) |
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. | |
void | multi_process_drop_outgoing_tun (struct multi_context *m, const unsigned int mpp_flags) |
struct multi_instance * | multi_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) |
static bool | multi_output_queue_ready (const struct multi_context *m, const struct multi_instance *mi) |
static struct multi_instance * | multi_process_outgoing_link_pre (struct multi_context *m) |
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 (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. | |
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) |
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 *old_ip, const char *old_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. | |
Header file for server-mode related structures and functions.
Definition in file multi.h.
#define CLIENT_CONNECT_OPT_MASK |
#define MULTI_CHECK_SIG | ( | m | ) | EVENT_LOOP_CHECK_SIGNAL(&(m)->top, multi_process_signal, (m)) |
#define REAP_DIVISOR 256 /* How many passes to cover whole hash table */ |
#define REAP_MAX 1024 /* Maximum number of buckets per pass */ |
#define REAP_MAX_WAKEUP 10 /* Do reap pass at least once per n seconds */ |
#define REAP_MIN 16 /* Minimum number of buckets per pass */ |
|
inlinestatic |
Definition at line 533 of file multi.h.
References msg_set_prefix().
Referenced by multi_close_instance_on_signal(), multi_get_queue(), multi_io_dispatch(), 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(), and multi_tcp_process_outgoing_link().
void init_management_callback_multi | ( | struct multi_context * | m | ) |
Definition at line 4123 of file multi.c.
References management_callback::arg, CLEAR, management_callback::client_auth, management_callback::client_pending_auth, management_callback::delete_event, management_callback::flags, management_callback::get_peer_info, management_callback::kill_by_addr, management_callback::kill_by_cid, management_callback::kill_by_cn, management_callback_kill_by_addr(), management_callback_kill_by_cn(), management_callback_n_clients(), management_callback_send_push_update_broadcast(), management_callback_send_push_update_by_cid(), management_callback_status(), management_client_auth(), management_client_pending_auth(), management_delete_event(), management_get_peer_info(), management_kill_by_cid(), management_set_callback(), management_show_net_callback(), MCF_SERVER, management_callback::n_clients, management_callback::push_update_broadcast, management_callback::push_update_by_cid, management_callback::show_net, and management_callback::status.
Referenced by tunnel_server().
struct multi_instance * lookup_by_cid | ( | struct multi_context * | m, |
const unsigned long | cid | ||
) |
Definition at line 4002 of file multi.c.
References multi_context::cid_hash, multi_instance::halt, hash_lookup(), and multi_context::instances.
Referenced by management_client_auth(), management_client_pending_auth(), management_get_peer_info(), management_kill_by_cid(), and send_push_update().
void multi_add_mbuf | ( | struct multi_context * | m, |
struct multi_instance * | mi, | ||
struct mbuf_buffer * | mb | ||
) |
Definition at line 2865 of file multi.c.
References mbuf_item::buffer, D_MULTI_DROPPED, mbuf_item::instance, multi_context::mbuf, mbuf_add_item(), msg, and multi_output_queue_ready().
Referenced by multi_bcast(), and multi_unicast().
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.
m | - The single multi_context structure. |
mi | - The multi_instance of the VPN tunnel to be postprocessed. |
Definition at line 4150 of file multi.c.
References ASSERT, context::c2, multi_instance::context, i, multi_context::instances, multi_context::max_clients, MAX_PEER_ID, tls_multi::peer_id, and context_2::tls_multi.
Referenced by multi_create_instance_tcp(), and multi_get_create_instance_udp().
void multi_close_instance | ( | struct multi_context * | m, |
struct multi_instance * | mi, | ||
bool | shutdown | ||
) |
Definition at line 582 of file multi.c.
References ASSERT, context::c2, CAS_CONNECT_DONE, CC_GC_FREE, man_def_auth_context::cid, multi_context::cid_hash, close_context(), multi_instance::context, D_MULTI_DEBUG, multi_instance::did_cid_hash, multi_instance::did_iter, multi_instance::did_real_hash, dmsg, multi_context::earliest_wakeup, multi_instance::halt, multi_context::hash, hash_remove(), multi_context::ifconfig_pool, ifconfig_pool_release(), link_socket::info, multi_context::instances, multi_context::iter, context_2::link_sockets, MAX_PEER_ID, multi_context::mbuf, mbuf_dereference_instance(), context_2::mda_context, multi_client_disconnect_script(), multi_del_iroutes(), multi_instance_dec_refcount(), multi_context::multi_io, multi_set_pending(), tls_multi::multi_state, multi_tcp_dereference_instance(), multi_tcp_instance_specific_free(), multi_context::n_clients, multi_instance::n_clients_delta, tls_multi::peer_id, multi_context::pending, PERF_MULTI_CLOSE_INSTANCE, perf_pop(), perf_push(), link_socket_info::proto, proto_is_dgram(), multi_instance::real, multi_context::schedule, schedule_remove_entry(), set_cc_config(), context_2::tls_multi, ungenerate_prefix(), and update_mstat_n_clients().
Referenced by multi_close_instance_on_signal(), multi_create_instance(), multi_create_instance_tcp(), multi_delete_dup(), multi_process_float(), and multi_uninit().
void multi_close_instance_on_signal | ( | struct multi_context * | m, |
struct multi_instance * | mi | ||
) |
Definition at line 3212 of file multi.c.
References clear_prefix(), multi_instance::context, D_MULTI_LOW, multi_close_instance(), print_signal(), remap_signal(), set_prefix(), and context::sig.
Referenced by multi_io_action(), multi_process_post(), and multi_signal_instance().
struct multi_instance * multi_create_instance | ( | struct multi_context * | m, |
const struct mroute_addr * | real, | ||
struct link_socket * | sock | ||
) |
Definition at line 732 of file multi.c.
References ALLOC_OBJ_CLEAR, context::c2, CAS_NOT_CONNECTED, man_def_auth_context::cid, multi_context::cid_counter, multi_context::cid_hash, multi_instance::context, multi_instance::created, D_MULTI_ERRORS, D_MULTI_LOW, D_MULTI_MEDIUM, multi_instance::did_cid_hash, multi_instance::did_iter, multi_instance::ev_arg, EVENT_ARG_MULTI_INSTANCE, multi_instance::gc, gc, gc_free(), gc_new(), generate_prefix(), multi_context::hash, hash_add(), hash_n_elements(), inherit_context_child(), IS_SIG, multi_context::iter, multi_context::max_clients, context_2::mda_context, event_arg::mi, MPP_PRE_SELECT, mroute_addr_init(), mroute_addr_print(), msg, multi_close_instance(), multi_instance_inc_refcount(), multi_process_post(), tls_multi::multi_state, multi_tcp_instance_specific_init(), now, PERF_MULTI_CREATE_INSTANCE, perf_pop(), perf_push(), context_2::push_request_received, multi_instance::real, context_2::tls_multi, multi_context::top, event_arg::type, event_arg::u, and multi_instance::vaddr_handle.
Referenced by multi_create_instance_tcp(), and multi_get_create_instance_udp().
struct multi_instance * multi_get_queue | ( | struct mbuf_set * | ms | ) |
Definition at line 3644 of file multi.c.
References mbuf_buffer::buf, context_2::buf, mbuf_item::buffer, context::c2, clear_prefix(), multi_instance::context, D_MULTI_DEBUG, dmsg, encrypt_sign(), mbuf_buffer::flags, mbuf_item::instance, context_2::link_sockets, mbuf_extract_item(), mbuf_free_buf(), MF_UNICAST, PIP_MSSFIX, PIPV4_PASSTOS, PIPV6_ICMP_NOHOST_SERVER, process_ip_header(), and set_prefix().
Referenced by multi_process_outgoing_link_pre().
|
inlinestatic |
Definition at line 593 of file multi.h.
References ASSERT, CLEAR, multi_context::earliest_wakeup, openvpn_gettimeofday(), REAP_MAX_WAKEUP, multi_context::schedule, schedule_get_earliest_wakeup(), and tv_delta().
Referenced by tunnel_server_loop().
void multi_ifconfig_pool_persist | ( | struct multi_context * | m, |
bool | force | ||
) |
Definition at line 161 of file multi.c.
References context::c1, multi_context::ifconfig_pool, context_1::ifconfig_pool_persist, ifconfig_pool_write(), ifconfig_pool_write_trigger(), and multi_context::top.
Referenced by multi_process_per_second_timers_dowork(), and tunnel_server().
|
inlinestatic |
Definition at line 470 of file multi.h.
References multi_instance::gc, gc_free(), and multi_instance::refcount.
Referenced by multi_close_instance(), and multi_route_del().
|
inlinestatic |
Definition at line 464 of file multi.h.
References multi_instance::refcount.
Referenced by multi_create_instance(), and multi_learn_addr().
const char * multi_instance_string | ( | const struct multi_instance * | mi, |
bool | null, | ||
struct gc_arena * | gc | ||
) |
Definition at line 442 of file multi.c.
References alloc_buf_gc(), BSTR, buf_printf(), context::c2, check_debug_level(), multi_instance::context, D_DCO_DEBUG, dco_enabled(), gc, buffer::len, mroute_addr_print(), MULTI_PREFIX_MAX_LENGTH, context::options, tls_multi::peer_id, multi_instance::real, tls_common_name(), and context_2::tls_multi.
Referenced by generate_prefix(), multi_add_iroutes(), multi_client_connect_late_setup(), multi_client_setup_dco_initial(), multi_get_instance_by_virtual_addr(), multi_io_post(), multi_learn_addr(), multi_process_float(), multi_select_virtual_addr(), and route_quota_exceeded().
|
inlinestatic |
Definition at line 393 of file multi.h.
References mbuf_len(), multi_instance::tcp_link_out_deferred, and multi_context::tcp_queue_limit.
Referenced by multi_add_mbuf(), and multi_process_incoming_tun().
void multi_process_drop_outgoing_tun | ( | struct multi_context * | m, |
const unsigned int | mpp_flags | ||
) |
Definition at line 3712 of file multi.c.
References ASSERT, buf_reset(), context::c2, clear_prefix(), multi_instance::context, D_MULTI_ERRORS, buffer::len, msg, multi_process_post(), multi_context::pending, set_prefix(), and context_2::to_tun.
Referenced by multi_io_dispatch().
bool multi_process_incoming_dco | ( | struct multi_context * | m | ) |
Process an incoming DCO message (from kernel space).
m | - The single multi_context structure. |
Referenced by multi_io_process_io(), and multi_process_io_udp().
|
inlinestatic |
Definition at line 658 of file multi.h.
References context::c2, clear_prefix(), multi_instance::context, context_2::link_sockets, multi_process_post(), process_outgoing_link(), and set_prefix().
Referenced by multi_process_outgoing_link(), multi_tcp_process_outgoing_link(), and multi_tcp_process_outgoing_link_ready().
|
inlinestatic |
Definition at line 411 of file multi.h.
References multi_context::mbuf, mbuf_defined(), multi_get_queue(), and multi_context::pending.
Referenced by multi_process_outgoing_link(), and multi_tcp_process_outgoing_link().
|
inlinestatic |
Definition at line 575 of file multi.h.
References multi_process_per_second_timers_dowork(), now, and multi_context::per_second_trigger.
Referenced by tunnel_server_loop().
void multi_process_per_second_timers_dowork | ( | struct multi_context * | m | ) |
Definition at line 3791 of file multi.c.
References context::c1, check_stale_routes(), management_check_bytecount_server(), multi_ifconfig_pool_persist(), multi_print_status(), multi_reap_process(), context::options, stale_route_check_trigger(), options::stale_routes_check_interval, multi_context::status_file_version, context_1::status_output, status_trigger(), and multi_context::top.
Referenced by multi_process_per_second_timers().
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.
m | - The single multi_context structure. |
mi | - The multi_instance of the VPN tunnel to be postprocessed. |
flags | - Fast I/O optimization flags. |
Definition at line 3013 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_CONDITIONAL_PRE_SELECT, 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_process_drop_outgoing_tun(), multi_process_incoming_link(), multi_process_incoming_tun(), multi_process_outgoing_link_dowork(), multi_process_outgoing_tun(), multi_process_timeout(), and multi_tcp_process_outgoing_link().
bool multi_process_signal | ( | struct multi_context * | m | ) |
Definition at line 3887 of file multi.c.
References options::ce, multi_context::deferred_shutdown_signal, connection_entry::explicit_exit_notification, has_udp_in_local_list(), is_exit_restart(), M_INFO, multi_print_status(), multi_push_restart_schedule_exit(), context::options, context::sig, deferred_signal_schedule_entry::signal_received, signal_info::signal_received, signal_reset(), status_close(), multi_context::status_file_version, status_open(), and multi_context::top.
bool multi_process_timeout | ( | struct multi_context * | m, |
const unsigned int | mpp_flags | ||
) |
Definition at line 3680 of file multi.c.
References clear_prefix(), multi_context::deferred_shutdown_signal, multi_context::earliest_wakeup, multi_process_post(), multi_context::schedule, schedule_remove_entry(), set_prefix(), deferred_signal_schedule_entry::signal_received, and throw_signal().
Referenced by multi_io_dispatch().
|
inlinestatic |
Definition at line 566 of file multi.h.
References multi_reap::last_call, multi_reap_process_dowork(), now, and multi_context::reaper.
Referenced by multi_process_per_second_timers_dowork().
void multi_reap_process_dowork | ( | const struct multi_context * | m | ) |
Definition at line 219 of file multi.c.
References multi_reap::bucket_base, multi_reap::buckets_per_pass, hash_n_buckets(), multi_reap::last_call, multi_reap_range(), now, multi_context::reaper, and multi_context::vhash.
Referenced by multi_reap_process().
|
inlinestatic |
Definition at line 489 of file multi.h.
References mroute_helper::ageable_ttl_secs, mroute_helper::cache_generation, multi_route::cache_generation, multi_route::flags, multi_instance::halt, multi_route::instance, multi_route::last_reference, MULTI_ROUTE_AGEABLE, MULTI_ROUTE_CACHE, now, and multi_context::route_helper.
Referenced by check_stale_routes(), multi_get_instance_by_virtual_addr(), multi_learn_addr(), multi_print_status(), and multi_reap_range().
|
inlinestatic |
Definition at line 480 of file multi.h.
References multi_instance_dec_refcount(), route, and route_quota_dec().
Referenced by check_stale_routes(), multi_learn_addr(), and multi_reap_range().
|
inlinestatic |
Definition at line 675 of file multi.h.
References multi_context::pending.
Referenced by multi_close_instance(), multi_process_incoming_link(), multi_process_incoming_tun(), and multi_process_post().
|
inlinestatic |
Definition at line 439 of file multi.h.
References multi_instance::route_count.
Referenced by multi_route_del().
void route_quota_exceeded | ( | const struct multi_instance * | mi | ) |
Definition at line 3734 of file multi.c.
References multi_instance::context, D_ROUTE_QUOTA, gc, gc_free(), gc_new(), options::max_routes_per_client, msg, multi_instance_string(), and context::options.
Referenced by route_quota_test().
|
inlinestatic |
Definition at line 433 of file multi.h.
References multi_instance::route_count.
Referenced by multi_learn_addr().
|
inlinestatic |
Definition at line 446 of file multi.h.
References multi_instance::context, options::max_routes_per_client, context::options, multi_instance::route_count, and route_quota_exceeded().
Referenced by multi_learn_addr().
|
inlinestatic |
Definition at line 521 of file multi.h.
References multi_instance::msg_prefix, and msg_set_prefix().
Referenced by generate_prefix(), multi_close_instance_on_signal(), multi_get_queue(), multi_io_dispatch(), 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_process_outgoing_link(), and ungenerate_prefix().
void ungenerate_prefix | ( | struct multi_instance * | mi | ) |
Definition at line 489 of file multi.c.
References multi_instance::msg_prefix, and set_prefix().
Referenced by multi_close_instance(), and multi_get_create_instance_udp().
void update_vhash | ( | struct multi_context * | m, |
struct multi_instance * | mi, | ||
const char * | old_ip, | ||
const char * | old_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.
This function should be called after a push-update and old_ip/old_ipv6 are the previous addresses of the client in ctx->options.ifconfig_local and ctx->options.ifconfig_ipv6_local.
Definition at line 4277 of file multi.c.
References multi_instance::context, options::ifconfig_ipv6_local, options::ifconfig_local, multi_learn_in6_addr(), multi_learn_in_addr_t(), and context::options.
Referenced by send_push_update().