OpenVPN
Macros | Functions | Variables
forward.c File Reference
#include "syshead.h"
#include "forward.h"
#include "init.h"
#include "push.h"
#include "gremlin.h"
#include "mss.h"
#include "event.h"
#include "occ.h"
#include "ping.h"
#include "ps.h"
#include "dhcp.h"
#include "common.h"
#include "ssl_verify.h"
#include "dco.h"
#include "auth_token.h"
#include "memdbg.h"
#include "mstats.h"
Include dependency graph for forward.c:

Go to the source code of this file.

Macros

#define MAX_ICMPV6LEN   1280
 

Functions

static void check_tls_errors_co (struct context *c)
 
static void check_tls_errors_nco (struct context *c)
 
static void check_tls_errors (struct context *c)
 
static void context_immediate_reschedule (struct context *c)
 
static void context_reschedule_sec (struct context *c, int sec)
 
void check_dco_key_status (struct context *c)
 
static void check_tls (struct context *c)
 
static void check_incoming_control_channel (struct context *c)
 
static void check_push_request (struct context *c)
 
static void check_connection_established (struct context *c)
 
bool send_control_channel_string_dowork (struct tls_session *session, const char *str, int msglevel)
 
void reschedule_multi_process (struct context *c)
 Reschedule tls_multi_process. More...
 
bool send_control_channel_string (struct context *c, const char *str, int msglevel)
 
static void check_add_routes_action (struct context *c, const bool errors)
 
static void check_add_routes (struct context *c)
 
static void check_inactivity_timeout (struct context *c)
 
int get_server_poll_remaining_time (struct event_timeout *server_poll_timeout)
 
static void check_server_poll_timeout (struct context *c)
 
void schedule_exit (struct context *c, const int n_seconds, const int signal)
 
static void check_scheduled_exit (struct context *c)
 
static void check_status_file (struct context *c)
 
static void check_fragment (struct context *c)
 
static void buffer_turnover (const uint8_t *orig_buf, struct buffer *dest_stub, struct buffer *src_stub, struct buffer *storage)
 
void encrypt_sign (struct context *c, bool comp_frag)
 Process a data channel packet that will be sent through a VPN tunnel. More...
 
static void check_session_timeout (struct context *c)
 
static void process_coarse_timers (struct context *c)
 
static void check_coarse_timers (struct context *c)
 
static void check_timeout_random_component_dowork (struct context *c)
 
static void check_timeout_random_component (struct context *c)
 
static void socks_postprocess_incoming_link (struct context *c)
 
static void socks_preprocess_outgoing_link (struct context *c, struct link_socket_actual **to_addr, int *size_delta)
 
static void link_socket_write_post_size_adjust (int *size, int size_delta, struct buffer *buf)
 
void read_incoming_link (struct context *c)
 Read a packet from the external network interface. More...
 
bool process_incoming_link_part1 (struct context *c, struct link_socket_info *lsi, bool floated)
 Starts processing a packet read from the external network interface. More...
 
void process_incoming_link_part2 (struct context *c, struct link_socket_info *lsi, const uint8_t *orig_buf)
 Continues processing a packet read from the external network interface. More...
 
static void process_incoming_link (struct context *c)
 
static void process_incoming_dco (struct context *c)
 
void read_incoming_tun (struct context *c)
 Read a packet from the virtual tun/tap network interface. More...
 
static void drop_if_recursive_routing (struct context *c, struct buffer *buf)
 Drops UDP packets which OS decided to route via tun. More...
 
void process_incoming_tun (struct context *c)
 Process a packet read from the virtual tun/tap network interface. More...
 
void ipv6_send_icmp_unreachable (struct context *c, struct buffer *buf, bool client)
 Forges a IPv6 ICMP packet with a no route to host error code from the IPv6 packet in buf and sends it directly back to the client via the tun device when used on a client and via the link if used on the server. More...
 
void process_ip_header (struct context *c, unsigned int flags, struct buffer *buf)
 
void process_outgoing_link (struct context *c)
 Write a packet to the external network interface. More...
 
void process_outgoing_tun (struct context *c)
 Write a packet to the virtual tun/tap network interface. More...
 
void pre_select (struct context *c)
 
void io_wait_dowork (struct context *c, const unsigned int flags)
 
void process_io (struct context *c)
 

Variables

counter_type link_read_bytes_global
 
counter_type link_write_bytes_global
 

Macro Definition Documentation

◆ MAX_ICMPV6LEN

#define MAX_ICMPV6LEN   1280

Function Documentation

◆ buffer_turnover()

static void buffer_turnover ( const uint8_t *  orig_buf,
struct buffer dest_stub,
struct buffer src_stub,
struct buffer storage 
)
inlinestatic

Definition at line 585 of file forward.c.

References buf_assign(), and buffer::data.

Referenced by encrypt_sign(), and process_incoming_link_part2().

◆ check_add_routes()

static void check_add_routes ( struct context c)
static

◆ check_add_routes_action()

static void check_add_routes_action ( struct context c,
const bool  errors 
)
static

◆ check_coarse_timers()

static void check_coarse_timers ( struct context c)
static

◆ check_connection_established()

static void check_connection_established ( struct context c)
static

◆ check_dco_key_status()

void check_dco_key_status ( struct context c)

◆ check_fragment()

static void check_fragment ( struct context c)
static

◆ check_inactivity_timeout()

static void check_inactivity_timeout ( struct context c)
static

◆ check_incoming_control_channel()

static void check_incoming_control_channel ( struct context c)
static

◆ check_push_request()

static void check_push_request ( struct context c)
static

◆ check_scheduled_exit()

static void check_scheduled_exit ( struct context c)
static

◆ check_server_poll_timeout()

static void check_server_poll_timeout ( struct context c)
static

◆ check_session_timeout()

static void check_session_timeout ( struct context c)
static

◆ check_status_file()

static void check_status_file ( struct context c)
static

Definition at line 543 of file forward.c.

References context::c1, print_status(), and context_1::status_output.

Referenced by process_coarse_timers().

◆ check_timeout_random_component()

static void check_timeout_random_component ( struct context c)
inlinestatic

◆ check_timeout_random_component_dowork()

static void check_timeout_random_component_dowork ( struct context c)
static

◆ check_tls()

static void check_tls ( struct context c)
static

◆ check_tls_errors()

static void check_tls_errors ( struct context c)
inlinestatic

◆ check_tls_errors_co()

static void check_tls_errors_co ( struct context c)
static

◆ check_tls_errors_nco()

static void check_tls_errors_nco ( struct context c)
static

Definition at line 87 of file forward.c.

References context::c2, register_signal(), context::sig, and context_2::tls_exit_signal.

Referenced by check_tls_errors().

◆ context_immediate_reschedule()

static void context_immediate_reschedule ( struct context c)
inlinestatic

Definition at line 123 of file forward.c.

References context::c2, and context_2::timeval.

Referenced by reschedule_multi_process().

◆ context_reschedule_sec()

static void context_reschedule_sec ( struct context c,
int  sec 
)
inlinestatic

Definition at line 130 of file forward.c.

References context::c2, and context_2::timeval.

Referenced by check_coarse_timers(), and check_tls().

◆ drop_if_recursive_routing()

static void drop_if_recursive_routing ( struct context c,
struct buffer buf 
)
static

Drops UDP packets which OS decided to route via tun.

On Windows and OS X when netwotk adapter is disabled or disconnected, platform starts to use tun as external interface. When packet is sent to tun, it comes to openvpn, encapsulated and sent to routing table, which sends it again to tun.

Definition at line 1350 of file forward.c.

References openvpn_sockaddr::addr, BLEN, BPTR, context_2::buf, context::c1, context::c2, D_LOW, openvpn_iphdr::daddr, openvpn_ipv6hdr::daddr, link_socket_actual::dest, gc_free(), gc_new(), get_tun_ip_ver(), openvpn_sockaddr::in4, openvpn_sockaddr::in6, IN6_ARE_ADDR_EQUAL, buffer::len, msg, print_link_socket_actual(), openvpn_sockaddr::sa, context_2::to_link_addr, TUNNEL_TYPE, and context_1::tuntap.

Referenced by process_incoming_tun().

◆ get_server_poll_remaining_time()

int get_server_poll_remaining_time ( struct event_timeout server_poll_timeout)

◆ io_wait_dowork()

void io_wait_dowork ( struct context c,
const unsigned int  flags 
)

◆ ipv6_send_icmp_unreachable()

void ipv6_send_icmp_unreachable ( struct context c,
struct buffer buf,
bool  client 
)

Forges a IPv6 ICMP packet with a no route to host error code from the IPv6 packet in buf and sends it directly back to the client via the tun device when used on a client and via the link if used on the server.

Parameters
buf- The buf containing the packet for which the icmp6 unreachable should be constructed.
client- determines whether to the send packet back via tun or link

Definition at line 1499 of file forward.c.

References ASSERT, context_buffers::aux_buf, BLEN, BPTR, buf_copy_n(), buf_init, buf_safe(), buf_write_prepend(), context_2::buffers, context::c1, context::c2, CLEAR, openvpn_ipv6hdr::daddr, openvpn_ethhdr::dest, DEV_TYPE_TAP, context_2::frame, openvpn_icmp6hdr::icmp6_cksum, openvpn_icmp6hdr::icmp6_code, openvpn_icmp6hdr::icmp6_type, options::ifconfig_ipv6_remote, ip_checksum(), is_ipv6(), MAX_ICMPV6LEN, min_int(), openvpn_ipv6hdr::nexthdr, OPENVPN_ETH_ALEN, OPENVPN_ETH_P_IPV6, OPENVPN_ICMP6_DESTINATION_UNREACHABLE, OPENVPN_ICMP6_DU_NOROUTE, OPENVPN_IPPROTO_ICMPV6, context::options, openvpn_ipv6hdr::payload_len, openvpn_ethhdr::proto, openvpn_ipv6hdr::saddr, openvpn_ethhdr::source, context_2::to_link, context_2::to_tun, frame::tun_mtu, TUNNEL_TYPE, context_1::tuntap, and openvpn_ipv6hdr::version_prio.

Referenced by process_ip_header().

◆ link_socket_write_post_size_adjust()

static void link_socket_write_post_size_adjust ( int *  size,
int  size_delta,
struct buffer buf 
)
inlinestatic

Definition at line 893 of file forward.c.

References buf_advance().

Referenced by process_outgoing_link().

◆ pre_select()

void pre_select ( struct context c)

◆ process_coarse_timers()

static void process_coarse_timers ( struct context c)
static

◆ process_incoming_dco()

static void process_incoming_dco ( struct context c)
static

◆ process_incoming_link()

static void process_incoming_link ( struct context c)
static

◆ process_io()

void process_io ( struct context c)

◆ process_ip_header()

void process_ip_header ( struct context c,
unsigned int  flags,
struct buffer buf 
)

◆ reschedule_multi_process()

void reschedule_multi_process ( struct context c)

Reschedule tls_multi_process.

NOTE: in multi-client mode, usually calling the function is insufficient to reschedule the client instance object unless multi_schedule_context_wakeup(m, mi) is also called.

Definition at line 389 of file forward.c.

References context::c2, context_immediate_reschedule(), interval_action(), and context_2::tmp_int.

Referenced by management_client_pending_auth(), send_auth_failed(), and send_control_channel_string().

◆ schedule_exit()

void schedule_exit ( struct context c,
const int  n_seconds,
const int  signal 
)

◆ send_control_channel_string()

bool send_control_channel_string ( struct context c,
const char *  str,
int  msglevel 
)

◆ send_control_channel_string_dowork()

bool send_control_channel_string_dowork ( struct tls_session session,
const char *  str,
int  msglevel 
)

◆ socks_postprocess_incoming_link()

static void socks_postprocess_incoming_link ( struct context c)
inlinestatic

◆ socks_preprocess_outgoing_link()

static void socks_preprocess_outgoing_link ( struct context c,
struct link_socket_actual **  to_addr,
int *  size_delta 
)
inlinestatic

Variable Documentation

◆ link_read_bytes_global

counter_type link_read_bytes_global

Definition at line 49 of file forward.c.

Referenced by man_load_stats(), and process_incoming_link_part1().

◆ link_write_bytes_global

counter_type link_write_bytes_global

Definition at line 50 of file forward.c.

Referenced by man_load_stats(), and process_outgoing_link().