OpenVPN
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
socket.h File Reference
#include "buffer.h"
#include "common.h"
#include "error.h"
#include "proto.h"
#include "mtu.h"
#include "win32.h"
#include "event.h"
#include "proxy.h"
#include "socks.h"
#include "misc.h"
Include dependency graph for socket.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  openvpn_sockaddr
 
struct  cached_dns_entry
 
struct  link_socket_actual
 
struct  link_socket_addr
 
struct  link_socket_info
 
struct  stream_buf
 
struct  socket_buffer_size
 
struct  link_socket
 

Macros

#define OPENVPN_PORT   "1194"
 
#define RESOLV_RETRY_INFINITE   1000000000
 
#define htonps(x)   htons(x)
 
#define ntohps(x)   ntohs(x)
 
#define INETD_NONE   0
 
#define INETD_WAIT   1
 
#define INETD_NOWAIT   2
 
#define LS_MODE_DEFAULT   0
 
#define LS_MODE_TCP_LISTEN   1
 
#define LS_MODE_TCP_ACCEPT_FROM   2
 
#define SF_USE_IP_PKTINFO   (1<<0)
 
#define SF_TCP_NODELAY   (1<<1)
 
#define SF_PORT_SHARE   (1<<2)
 
#define SF_HOST_RANDOMIZE   (1<<3)
 
#define SF_GETADDRINFO_DGRAM   (1<<4)
 
#define MSG_NOSIGNAL   0
 
#define openvpn_close_socket(s)   closesocket(s)
 
#define PS_SHOW_PORT_IF_DEFINED   (1<<0)
 
#define PS_SHOW_PORT   (1<<1)
 
#define PS_SHOW_PKTINFO   (1<<2)
 
#define PS_DONT_SHOW_ADDR   (1<<3)
 
#define PS_DONT_SHOW_FAMILY   (1<<4)
 
#define IA_EMPTY_IF_UNDEF   (1<<0)
 
#define IA_NET_ORDER   (1<<1)
 
#define SA_IP_PORT   (1<<0)
 
#define SA_SET_IF_NONZERO   (1<<1)
 
#define IPV4_INVALID_ADDR   0xffffffff
 
#define OIA_HOSTNAME   0
 
#define OIA_IP   1
 
#define OIA_ERROR   -1
 
#define GETADDR_RESOLVE   (1<<0)
 
#define GETADDR_FATAL   (1<<1)
 
#define GETADDR_HOST_ORDER   (1<<2)
 
#define GETADDR_MENTION_RESOLVE_RETRY   (1<<3)
 
#define GETADDR_FATAL_ON_SIGNAL   (1<<4)
 
#define GETADDR_WARN_ON_SIGNAL   (1<<5)
 
#define GETADDR_MSG_VIRT_OUT   (1<<6)
 
#define GETADDR_TRY_ONCE   (1<<7)
 
#define GETADDR_UPDATE_MANAGEMENT_STATE   (1<<8)
 
#define GETADDR_RANDOMIZE   (1<<9)
 
#define GETADDR_PASSIVE   (1<<10)
 
#define GETADDR_DATAGRAM   (1<<11)
 
#define GETADDR_CACHE_MASK   (GETADDR_DATAGRAM|GETADDR_PASSIVE)
 
#define IPv4_UDP_HEADER_SIZE   28
 
#define IPv4_TCP_HEADER_SIZE   40
 
#define IPv6_UDP_HEADER_SIZE   48
 
#define IPv6_TCP_HEADER_SIZE   60
 

Typedefs

typedef uint16_t packet_size_type
 

Enumerations

enum  proto_num {
  PROTO_NONE, PROTO_UDP, PROTO_TCP, PROTO_TCP_SERVER,
  PROTO_TCP_CLIENT, PROTO_N
}
 

Functions

int socket_recv_queue (struct link_socket *sock, int maxsize)
 
int socket_send_queue (struct link_socket *sock, struct buffer *buf, const struct link_socket_actual *to)
 
int socket_finalize (SOCKET s, struct overlapped_io *io, struct buffer *buf, struct link_socket_actual *from)
 
struct link_socketlink_socket_new (void)
 
void socket_bind (socket_descriptor_t sd, struct addrinfo *local, int af_family, const char *prefix, bool ipv6only)
 
int openvpn_connect (socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received)
 
void link_socket_init_phase1 (struct link_socket *sock, const char *local_host, const char *local_port, const char *remote_host, const char *remote_port, struct cached_dns_entry *dns_cache, int proto, sa_family_t af, bool bind_ipv6_only, int mode, const struct link_socket *accept_from, struct http_proxy_info *http_proxy, struct socks_proxy_info *socks_proxy, bool bind_local, bool remote_float, int inetd, struct link_socket_addr *lsa, const char *ipchange_command, const struct plugin_list *plugins, int resolve_retry_seconds, int mtu_discover_type, int rcvbuf, int sndbuf, int mark, struct event_timeout *server_poll_timeout, unsigned int sockflags)
 
void link_socket_init_phase2 (struct link_socket *sock, const struct frame *frame, struct signal_info *sig_info)
 
void do_preresolve (struct context *c)
 
void socket_adjust_frame_parameters (struct frame *frame, int proto)
 
void frame_adjust_path_mtu (struct frame *frame, int pmtu, int proto)
 
void link_socket_close (struct link_socket *sock)
 
void sd_close (socket_descriptor_t *sd)
 
const char * print_sockaddr_ex (const struct sockaddr *addr, const char *separator, const unsigned int flags, struct gc_arena *gc)
 
static const char * print_openvpn_sockaddr_ex (const struct openvpn_sockaddr *addr, const char *separator, const unsigned int flags, struct gc_arena *gc)
 
static const char * print_openvpn_sockaddr (const struct openvpn_sockaddr *addr, struct gc_arena *gc)
 
static const char * print_sockaddr (const struct sockaddr *addr, struct gc_arena *gc)
 
const char * print_link_socket_actual_ex (const struct link_socket_actual *act, const char *separator, const unsigned int flags, struct gc_arena *gc)
 
const char * print_link_socket_actual (const struct link_socket_actual *act, struct gc_arena *gc)
 
const char * print_in_addr_t (in_addr_t addr, unsigned int flags, struct gc_arena *gc)
 
const char * print_in6_addr (struct in6_addr addr6, unsigned int flags, struct gc_arena *gc)
 
struct in6_addr add_in6_addr (struct in6_addr base, uint32_t add)
 
void setenv_sockaddr (struct env_set *es, const char *name_prefix, const struct openvpn_sockaddr *addr, const unsigned int flags)
 
void setenv_in_addr_t (struct env_set *es, const char *name_prefix, in_addr_t addr, const unsigned int flags)
 
void setenv_in6_addr (struct env_set *es, const char *name_prefix, const struct in6_addr *addr, const unsigned int flags)
 
void setenv_link_socket_actual (struct env_set *es, const char *name_prefix, const struct link_socket_actual *act, const unsigned int flags)
 
void bad_address_length (int actual, int expected)
 
in_addr_t link_socket_current_remote (const struct link_socket_info *info)
 
const struct in6_addr * link_socket_current_remote_ipv6 (const struct link_socket_info *info)
 
void link_socket_connection_initiated (const struct buffer *buf, struct link_socket_info *info, const struct link_socket_actual *addr, const char *common_name, struct env_set *es)
 
void link_socket_bad_incoming_addr (struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
 
void set_actual_address (struct link_socket_actual *actual, struct addrinfo *ai)
 
void link_socket_bad_outgoing_addr (void)
 
void setenv_trusted (struct env_set *es, const struct link_socket_info *info)
 
bool link_socket_update_flags (struct link_socket *ls, unsigned int sockflags)
 
void link_socket_update_buffer_sizes (struct link_socket *ls, int rcvbuf, int sndbuf)
 
int openvpn_inet_aton (const char *dotted_quad, struct in_addr *addr)
 
bool ip_addr_dotted_quad_safe (const char *dotted_quad)
 
bool ip_or_dns_addr_safe (const char *addr, const bool allow_fqdn)
 
bool mac_addr_safe (const char *mac_addr)
 
bool ipv6_addr_safe (const char *ipv6_text_addr)
 
socket_descriptor_t create_socket_tcp (struct addrinfo *)
 
socket_descriptor_t socket_do_accept (socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait)
 
bool proto_is_net (int proto)
 
bool proto_is_dgram (int proto)
 
bool proto_is_udp (int proto)
 
bool proto_is_tcp (int proto)
 
in_addr_t getaddr (unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, volatile int *signal_received)
 Translate an IPv4 addr or hostname from string form to in_addr_t. More...
 
bool get_ipv6_addr (const char *hostname, struct in6_addr *network, unsigned int *netbits, int msglevel)
 Translate an IPv6 addr or hostname from string form to in6_addr. More...
 
int openvpn_getaddrinfo (unsigned int flags, const char *hostname, const char *servname, int resolve_retry_seconds, volatile int *signal_received, int ai_family, struct addrinfo **res)
 
int ascii2proto (const char *proto_name)
 
sa_family_t ascii2af (const char *proto_name)
 
const char * proto2ascii (int proto, sa_family_t af, bool display_form)
 
const char * proto2ascii_all (struct gc_arena *gc)
 
const char * proto_remote (int proto, bool remote)
 
const char * addr_family_name (int af)
 
static int datagram_overhead (int proto)
 
static bool link_socket_proto_connection_oriented (int proto)
 
static bool link_socket_connection_oriented (const struct link_socket *sock)
 
static bool addr_defined (const struct openvpn_sockaddr *addr)
 
static bool addr_local (const struct sockaddr *addr)
 
static bool addr_defined_ipi (const struct link_socket_actual *lsa)
 
static bool link_socket_actual_defined (const struct link_socket_actual *act)
 
static bool addr_match (const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
 
static bool addrlist_match (const struct openvpn_sockaddr *a1, const struct addrinfo *addrlist)
 
static in_addr_t addr_host (const struct openvpn_sockaddr *addr)
 
static bool addrlist_port_match (const struct openvpn_sockaddr *a1, const struct addrinfo *a2)
 
static bool addr_port_match (const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2)
 
static bool addr_match_proto (const struct openvpn_sockaddr *a1, const struct openvpn_sockaddr *a2, const int proto)
 
static bool addrlist_match_proto (const struct openvpn_sockaddr *a1, struct addrinfo *addr_list, const int proto)
 
static void addr_zero_host (struct openvpn_sockaddr *addr)
 
static void addr_copy_sa (struct openvpn_sockaddr *dst, const struct openvpn_sockaddr *src)
 
static bool addr_inet4or6 (struct sockaddr *addr)
 
int addr_guess_family (sa_family_t af, const char *name)
 
static int af_addr_size (sa_family_t af)
 
static bool link_socket_actual_match (const struct link_socket_actual *a1, const struct link_socket_actual *a2)
 
static bool socket_connection_reset (const struct link_socket *sock, int status)
 
static bool link_socket_verify_incoming_addr (struct buffer *buf, const struct link_socket_info *info, const struct link_socket_actual *from_addr)
 
static void link_socket_get_outgoing_addr (struct buffer *buf, const struct link_socket_info *info, struct link_socket_actual **act)
 
static void link_socket_set_outgoing_addr (const struct buffer *buf, struct link_socket_info *info, const struct link_socket_actual *act, const char *common_name, struct env_set *es)
 
bool stream_buf_read_setup_dowork (struct link_socket *sock)
 
static bool stream_buf_read_setup (struct link_socket *sock)
 
int link_socket_read_tcp (struct link_socket *sock, struct buffer *buf)
 
static int link_socket_read_udp_win32 (struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
 
static int link_socket_read (struct link_socket *sock, struct buffer *buf, struct link_socket_actual *from)
 
int link_socket_write_tcp (struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
 
static int link_socket_write_win32 (struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
 
static size_t link_socket_write_udp (struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
 
static int link_socket_write (struct link_socket *sock, struct buffer *buf, struct link_socket_actual *to)
 
static bool socket_read_residual (const struct link_socket *s)
 
static event_t socket_event_handle (const struct link_socket *s)
 
event_t socket_listen_event_handle (struct link_socket *s)
 
unsigned int socket_set (struct link_socket *s, struct event_set *es, unsigned int rwflags, void *arg, unsigned int *persistent)
 
static void socket_set_listen_persistent (struct link_socket *s, struct event_set *es, void *arg)
 
static void socket_reset_listen_persistent (struct link_socket *s)
 
const char * socket_stat (const struct link_socket *s, unsigned int rwflags, struct gc_arena *gc)
 

Variables

const int proto_overhead []
 

Macro Definition Documentation

◆ GETADDR_CACHE_MASK

#define GETADDR_CACHE_MASK   (GETADDR_DATAGRAM|GETADDR_PASSIVE)

Definition at line 533 of file socket.h.

Referenced by do_preresolve_host(), and get_cached_dns_entry().

◆ GETADDR_DATAGRAM

#define GETADDR_DATAGRAM   (1<<11)

Definition at line 531 of file socket.h.

Referenced by do_preresolve(), openvpn_getaddrinfo(), resolve_bind_local(), and resolve_remote().

◆ GETADDR_FATAL

#define GETADDR_FATAL   (1<<1)

◆ GETADDR_FATAL_ON_SIGNAL

#define GETADDR_FATAL_ON_SIGNAL   (1<<4)

Definition at line 524 of file socket.h.

Referenced by init_tun(), and openvpn_getaddrinfo().

◆ GETADDR_HOST_ORDER

#define GETADDR_HOST_ORDER   (1<<2)

◆ GETADDR_MENTION_RESOLVE_RETRY

#define GETADDR_MENTION_RESOLVE_RETRY   (1<<3)

Definition at line 523 of file socket.h.

Referenced by do_preresolve(), openvpn_getaddrinfo(), and resolve_remote().

◆ GETADDR_MSG_VIRT_OUT

#define GETADDR_MSG_VIRT_OUT   (1<<6)

Definition at line 526 of file socket.h.

Referenced by man_kill(), and openvpn_getaddrinfo().

◆ GETADDR_PASSIVE

#define GETADDR_PASSIVE   (1<<10)

◆ GETADDR_RANDOMIZE

#define GETADDR_RANDOMIZE   (1<<9)

Definition at line 529 of file socket.h.

Referenced by do_preresolve(), openvpn_getaddrinfo(), and sf2gaf().

◆ GETADDR_RESOLVE

#define GETADDR_RESOLVE   (1<<0)

◆ GETADDR_TRY_ONCE

#define GETADDR_TRY_ONCE   (1<<7)

Definition at line 527 of file socket.h.

Referenced by openvpn_getaddrinfo(), and resolve_remote().

◆ GETADDR_UPDATE_MANAGEMENT_STATE

#define GETADDR_UPDATE_MANAGEMENT_STATE   (1<<8)

Definition at line 528 of file socket.h.

Referenced by do_preresolve(), openvpn_getaddrinfo(), and resolve_remote().

◆ GETADDR_WARN_ON_SIGNAL

#define GETADDR_WARN_ON_SIGNAL   (1<<5)

◆ htonps

#define htonps (   x)    htons(x)

Definition at line 58 of file socket.h.

Referenced by link_socket_write_tcp().

◆ IA_EMPTY_IF_UNDEF

#define IA_EMPTY_IF_UNDEF   (1<<0)

◆ IA_NET_ORDER

#define IA_NET_ORDER   (1<<1)

◆ INETD_NONE

#define INETD_NONE   0

Definition at line 191 of file socket.h.

◆ INETD_NOWAIT

#define INETD_NOWAIT   2

◆ INETD_WAIT

#define INETD_WAIT   1

Definition at line 192 of file socket.h.

Referenced by add_option().

◆ IPV4_INVALID_ADDR

#define IPV4_INVALID_ADDR   0xffffffff

Definition at line 428 of file socket.h.

Referenced by link_socket_current_remote(), and redirect_default_route_to_vpn().

◆ IPv4_TCP_HEADER_SIZE

#define IPv4_TCP_HEADER_SIZE   40

Definition at line 594 of file socket.h.

◆ IPv4_UDP_HEADER_SIZE

#define IPv4_UDP_HEADER_SIZE   28

Definition at line 593 of file socket.h.

◆ IPv6_TCP_HEADER_SIZE

#define IPv6_TCP_HEADER_SIZE   60

Definition at line 596 of file socket.h.

◆ IPv6_UDP_HEADER_SIZE

#define IPv6_UDP_HEADER_SIZE   48

Definition at line 595 of file socket.h.

◆ LS_MODE_DEFAULT

#define LS_MODE_DEFAULT   0

Definition at line 196 of file socket.h.

Referenced by init_instance(), and phase2_tcp_server().

◆ LS_MODE_TCP_ACCEPT_FROM

#define LS_MODE_TCP_ACCEPT_FROM   2

◆ LS_MODE_TCP_LISTEN

#define LS_MODE_TCP_LISTEN   1

Definition at line 197 of file socket.h.

Referenced by init_instance(), and phase2_tcp_server().

◆ MSG_NOSIGNAL

#define MSG_NOSIGNAL   0

◆ ntohps

#define ntohps (   x)    ntohs(x)

Definition at line 61 of file socket.h.

Referenced by stream_buf_added().

◆ OIA_ERROR

#define OIA_ERROR   -1

Definition at line 462 of file socket.h.

Referenced by openvpn_inet_aton().

◆ OIA_HOSTNAME

#define OIA_HOSTNAME   0

Definition at line 460 of file socket.h.

Referenced by openvpn_inet_aton().

◆ OIA_IP

#define OIA_IP   1

Definition at line 461 of file socket.h.

Referenced by ip_addr_dotted_quad_safe(), and openvpn_inet_aton().

◆ openvpn_close_socket

#define openvpn_close_socket (   s)    closesocket(s)

◆ OPENVPN_PORT

#define OPENVPN_PORT   "1194"

Definition at line 41 of file socket.h.

Referenced by init_options().

◆ PS_DONT_SHOW_ADDR

#define PS_DONT_SHOW_ADDR   (1<<3)

Definition at line 348 of file socket.h.

Referenced by print_sockaddr_ex().

◆ PS_DONT_SHOW_FAMILY

#define PS_DONT_SHOW_FAMILY   (1<<4)

Definition at line 349 of file socket.h.

Referenced by log_entry_print(), and print_sockaddr_ex().

◆ PS_SHOW_PKTINFO

#define PS_SHOW_PKTINFO   (1<<2)

Definition at line 347 of file socket.h.

Referenced by print_link_socket_actual(), and print_link_socket_actual_ex().

◆ PS_SHOW_PORT

#define PS_SHOW_PORT   (1<<1)

◆ PS_SHOW_PORT_IF_DEFINED

#define PS_SHOW_PORT_IF_DEFINED   (1<<0)

Definition at line 345 of file socket.h.

Referenced by linksock_print_addr(), and print_sockaddr_ex().

◆ RESOLV_RETRY_INFINITE

#define RESOLV_RETRY_INFINITE   1000000000

Definition at line 47 of file socket.h.

Referenced by add_option(), init_options(), and resolve_remote().

◆ SA_IP_PORT

#define SA_IP_PORT   (1<<0)

Definition at line 401 of file socket.h.

Referenced by setenv_sockaddr(), setenv_trusted(), and setenv_untrusted().

◆ SA_SET_IF_NONZERO

#define SA_SET_IF_NONZERO   (1<<1)

Definition at line 402 of file socket.h.

Referenced by multi_set_virtual_addr_env(), setenv_in6_addr(), and setenv_in_addr_t().

◆ SF_GETADDRINFO_DGRAM

#define SF_GETADDRINFO_DGRAM   (1<<4)

Definition at line 212 of file socket.h.

Referenced by create_socket().

◆ SF_HOST_RANDOMIZE

#define SF_HOST_RANDOMIZE   (1<<3)

Definition at line 211 of file socket.h.

Referenced by add_option(), do_preresolve(), and sf2gaf().

◆ SF_PORT_SHARE

#define SF_PORT_SHARE   (1<<2)

Definition at line 210 of file socket.h.

Referenced by do_init_socket_1(), and stream_buf_init().

◆ SF_TCP_NODELAY

#define SF_TCP_NODELAY   (1<<1)

Definition at line 209 of file socket.h.

Referenced by add_option(), helper_tcp_nodelay(), and socket_set_flags().

◆ SF_USE_IP_PKTINFO

#define SF_USE_IP_PKTINFO   (1<<0)

Typedef Documentation

◆ packet_size_type

Definition at line 55 of file socket.h.

Enumeration Type Documentation

◆ proto_num

enum proto_num
Enumerator
PROTO_NONE 
PROTO_UDP 
PROTO_TCP 
PROTO_TCP_SERVER 
PROTO_TCP_CLIENT 
PROTO_N 

Definition at line 569 of file socket.h.

Function Documentation

◆ add_in6_addr()

struct in6_addr add_in6_addr ( struct in6_addr  base,
uint32_t  add 
)

Definition at line 3010 of file socket.c.

References add(), and UINT8_MAX.

Referenced by helper_client_server(), ifconfig_pool_acquire(), and ifconfig_pool_handle_to_ipv6_base().

◆ addr_copy_sa()

static void addr_copy_sa ( struct openvpn_sockaddr dst,
const struct openvpn_sockaddr src 
)
inlinestatic

Definition at line 850 of file socket.h.

References openvpn_sockaddr::addr.

Referenced by link_socket_read().

◆ addr_defined()

static bool addr_defined ( const struct openvpn_sockaddr addr)
inlinestatic

◆ addr_defined_ipi()

static bool addr_defined_ipi ( const struct link_socket_actual lsa)
inlinestatic

◆ addr_family_name()

const char* addr_family_name ( int  af)

Definition at line 3257 of file socket.c.

Referenced by link_socket_init_phase2(), and socket_bind().

◆ addr_guess_family()

int addr_guess_family ( sa_family_t  af,
const char *  name 
)

Referenced by addr_inet4or6().

◆ addr_host()

static in_addr_t addr_host ( const struct openvpn_sockaddr addr)
inlinestatic

Definition at line 746 of file socket.h.

References openvpn_sockaddr::addr, openvpn_sockaddr::in4, and openvpn_sockaddr::sa.

◆ addr_inet4or6()

static bool addr_inet4or6 ( struct sockaddr *  addr)
inlinestatic

Definition at line 856 of file socket.h.

References addr_guess_family().

◆ addr_local()

static bool addr_local ( const struct sockaddr *  addr)
inlinestatic

Definition at line 648 of file socket.h.

Referenced by create_socket().

◆ addr_match()

static bool addr_match ( const struct openvpn_sockaddr a1,
const struct openvpn_sockaddr a2 
)
inlinestatic

◆ addr_match_proto()

static bool addr_match_proto ( const struct openvpn_sockaddr a1,
const struct openvpn_sockaddr a2,
const int  proto 
)
inlinestatic

◆ addr_port_match()

static bool addr_port_match ( const struct openvpn_sockaddr a1,
const struct openvpn_sockaddr a2 
)
inlinestatic

◆ addr_zero_host()

static void addr_zero_host ( struct openvpn_sockaddr addr)
inlinestatic

◆ addrlist_match()

static bool addrlist_match ( const struct openvpn_sockaddr a1,
const struct addrinfo *  addrlist 
)
inlinestatic

◆ addrlist_match_proto()

static bool addrlist_match_proto ( const struct openvpn_sockaddr a1,
struct addrinfo *  addr_list,
const int  proto 
)
inlinestatic

◆ addrlist_port_match()

static bool addrlist_port_match ( const struct openvpn_sockaddr a1,
const struct addrinfo *  a2 
)
inlinestatic

◆ af_addr_size()

static int af_addr_size ( sa_family_t  af)
inlinestatic

◆ ascii2af()

sa_family_t ascii2af ( const char *  proto_name)

Definition at line 3204 of file socket.c.

References proto_names::proto_af, proto_names::short_form, and SIZE.

Referenced by add_option().

◆ ascii2proto()

int ascii2proto ( const char *  proto_name)

Definition at line 3190 of file socket.c.

References proto_names::proto, proto_names::short_form, and SIZE.

Referenced by add_option().

◆ bad_address_length()

void bad_address_length ( int  actual,
int  expected 
)

Definition at line 3309 of file socket.c.

References M_FATAL, and msg.

Referenced by link_socket_read_tcp(), socket_finalize(), and socket_recv_queue().

◆ create_socket_tcp()

socket_descriptor_t create_socket_tcp ( struct addrinfo *  )

Definition at line 996 of file socket.c.

References ASSERT, M_ERR, msg, and set_cloexec().

Referenced by create_socket(), man_connect(), man_listen(), and phase2_tcp_client().

◆ datagram_overhead()

static int datagram_overhead ( int  proto)
inlinestatic

Definition at line 601 of file socket.h.

References ASSERT, PROTO_N, and proto_overhead.

Referenced by frame_adjust_path_mtu(), and process_outgoing_link().

◆ do_preresolve()

void do_preresolve ( struct context c)

◆ frame_adjust_path_mtu()

void frame_adjust_path_mtu ( struct frame frame,
int  pmtu,
int  proto 
)

Definition at line 1666 of file socket.c.

References datagram_overhead(), frame_set_mtu_dynamic(), and SET_MTU_UPPER_BOUND.

Referenced by check_fragment_dowork().

◆ get_ipv6_addr()

bool get_ipv6_addr ( const char *  hostname,
struct in6_addr *  network,
unsigned int *  netbits,
int  msglevel 
)

Translate an IPv6 addr or hostname from string form to in6_addr.

Definition at line 220 of file socket.c.

References get_addr_generic(), and GETADDR_RESOLVE.

Referenced by add_option(), dhcp_option_dns6_parse(), init_route_ipv6(), ipv6_addr_safe_hexplusbits(), and option_iroute_ipv6().

◆ getaddr()

in_addr_t getaddr ( unsigned int  flags,
const char *  hostname,
int  resolve_retry_seconds,
bool succeeded,
volatile int *  signal_received 
)

Translate an IPv4 addr or hostname from string form to in_addr_t.

In case of resolve error, it will try again for resolve_retry_seconds seconds.

Definition at line 189 of file socket.c.

References get_addr_generic(), in_addr_t, M_WARN, and status.

Referenced by add_client_nat_to_option_list(), add_host_route_array(), add_option(), get_adapter_ip_netmask(), get_ip_addr(), ifconfig_pool_read(), init_route(), init_route_list(), init_tun(), ip_addr_string_to_array(), man_kill(), option_iroute(), and remove_iroutes_from_push_route_list().

◆ ip_addr_dotted_quad_safe()

bool ip_addr_dotted_quad_safe ( const char *  dotted_quad)

Definition at line 685 of file socket.c.

References OIA_IP, and openvpn_inet_aton().

Referenced by add_option(), dhcp_option_address_parse(), and ip_or_dns_addr_safe().

◆ ip_or_dns_addr_safe()

bool ip_or_dns_addr_safe ( const char *  addr,
const bool  allow_fqdn 
)

Definition at line 771 of file socket.c.

References dns_addr_safe(), and ip_addr_dotted_quad_safe().

Referenced by add_option().

◆ ipv6_addr_safe()

bool ipv6_addr_safe ( const char *  ipv6_text_addr)

Definition at line 735 of file socket.c.

References inet_pton().

Referenced by add_option().

◆ link_socket_actual_defined()

static bool link_socket_actual_defined ( const struct link_socket_actual act)
inlinestatic

◆ link_socket_actual_match()

static bool link_socket_actual_match ( const struct link_socket_actual a1,
const struct link_socket_actual a2 
)
inlinestatic

◆ link_socket_bad_incoming_addr()

void link_socket_bad_incoming_addr ( struct buffer buf,
const struct link_socket_info info,
const struct link_socket_actual from_addr 
)

◆ link_socket_bad_outgoing_addr()

void link_socket_bad_outgoing_addr ( void  )

Definition at line 2516 of file socket.c.

References D_READ_WRITE, dmsg, and in_addr_t.

Referenced by link_socket_get_outgoing_addr().

◆ link_socket_close()

void link_socket_close ( struct link_socket sock)

◆ link_socket_connection_initiated()

void link_socket_connection_initiated ( const struct buffer buf,
struct link_socket_info info,
const struct link_socket_actual addr,
const char *  common_name,
struct env_set es 
)

◆ link_socket_connection_oriented()

static bool link_socket_connection_oriented ( const struct link_socket sock)
inlinestatic

◆ link_socket_current_remote()

in_addr_t link_socket_current_remote ( const struct link_socket_info info)

◆ link_socket_current_remote_ipv6()

const struct in6_addr* link_socket_current_remote_ipv6 ( const struct link_socket_info info)

◆ link_socket_get_outgoing_addr()

static void link_socket_get_outgoing_addr ( struct buffer buf,
const struct link_socket_info info,
struct link_socket_actual **  act 
)
inlinestatic

◆ link_socket_init_phase1()

void link_socket_init_phase1 ( struct link_socket sock,
const char *  local_host,
const char *  local_port,
const char *  remote_host,
const char *  remote_port,
struct cached_dns_entry dns_cache,
int  proto,
sa_family_t  af,
bool  bind_ipv6_only,
int  mode,
const struct link_socket accept_from,
struct http_proxy_info http_proxy,
struct socks_proxy_info socks_proxy,
bool  bind_local,
bool  remote_float,
int  inetd,
struct link_socket_addr lsa,
const char *  ipchange_command,
const struct plugin_list plugins,
int  resolve_retry_seconds,
int  mtu_discover_type,
int  rcvbuf,
int  sndbuf,
int  mark,
struct event_timeout server_poll_timeout,
unsigned int  sockflags 
)

◆ link_socket_init_phase2()

void link_socket_init_phase2 ( struct link_socket sock,
const struct frame frame,
struct signal_info sig_info 
)

◆ link_socket_new()

struct link_socket* link_socket_new ( void  )

Definition at line 1841 of file socket.c.

References ALLOC_OBJ_CLEAR, link_socket::ctrl_sd, link_socket::sd, and SOCKET_UNDEFINED.

Referenced by do_link_socket_new().

◆ link_socket_proto_connection_oriented()

static bool link_socket_proto_connection_oriented ( int  proto)
inlinestatic

◆ link_socket_read()

static int link_socket_read ( struct link_socket sock,
struct buffer buf,
struct link_socket_actual from 
)
inlinestatic

◆ link_socket_read_tcp()

int link_socket_read_tcp ( struct link_socket sock,
struct buffer buf 
)

◆ link_socket_read_udp_win32()

static int link_socket_read_udp_win32 ( struct link_socket sock,
struct buffer buf,
struct link_socket_actual from 
)
inlinestatic

Definition at line 1034 of file socket.h.

References link_socket::reads, link_socket::sd, and socket_finalize().

Referenced by link_socket_read().

◆ link_socket_set_outgoing_addr()

static void link_socket_set_outgoing_addr ( const struct buffer buf,
struct link_socket_info info,
const struct link_socket_actual act,
const char *  common_name,
struct env_set es 
)
inlinestatic

◆ link_socket_update_buffer_sizes()

void link_socket_update_buffer_sizes ( struct link_socket ls,
int  rcvbuf,
int  sndbuf 
)

◆ link_socket_update_flags()

bool link_socket_update_flags ( struct link_socket ls,
unsigned int  sockflags 
)

Definition at line 967 of file socket.c.

References link_socket::sd, socket_defined(), socket_set_flags(), and link_socket::sockflags.

Referenced by do_deferred_options().

◆ link_socket_verify_incoming_addr()

static bool link_socket_verify_incoming_addr ( struct buffer buf,
const struct link_socket_info info,
const struct link_socket_actual from_addr 
)
inlinestatic

◆ link_socket_write()

static int link_socket_write ( struct link_socket sock,
struct buffer buf,
struct link_socket_actual to 
)
inlinestatic

◆ link_socket_write_tcp()

int link_socket_write_tcp ( struct link_socket sock,
struct buffer buf,
struct link_socket_actual to 
)

◆ link_socket_write_udp()

static size_t link_socket_write_udp ( struct link_socket sock,
struct buffer buf,
struct link_socket_actual to 
)
inlinestatic

Definition at line 1152 of file socket.h.

References link_socket_write_win32().

Referenced by link_socket_write().

◆ link_socket_write_win32()

static int link_socket_write_win32 ( struct link_socket sock,
struct buffer buf,
struct link_socket_actual to 
)
inlinestatic

◆ mac_addr_safe()

bool mac_addr_safe ( const char *  mac_addr)

Definition at line 788 of file socket.c.

Referenced by add_option().

◆ openvpn_connect()

int openvpn_connect ( socket_descriptor_t  sd,
const struct sockaddr *  remote,
int  connect_timeout,
volatile int *  signal_received 
)

◆ openvpn_getaddrinfo()

int openvpn_getaddrinfo ( unsigned int  flags,
const char *  hostname,
const char *  servname,
int  resolve_retry_seconds,
volatile int *  signal_received,
int  ai_family,
struct addrinfo **  res 
)

◆ openvpn_inet_aton()

int openvpn_inet_aton ( const char *  dotted_quad,
struct in_addr *  addr 
)

Definition at line 661 of file socket.c.

References CC_DIGIT, CC_DOT, CLEAR, OIA_ERROR, OIA_HOSTNAME, OIA_IP, and string_class().

Referenced by ip_addr_dotted_quad_safe().

◆ print_in6_addr()

const char* print_in6_addr ( struct in6_addr  addr6,
unsigned int  flags,
struct gc_arena gc 
)

◆ print_in_addr_t()

const char* print_in_addr_t ( in_addr_t  addr,
unsigned int  flags,
struct gc_arena gc 
)

◆ print_link_socket_actual()

const char* print_link_socket_actual ( const struct link_socket_actual act,
struct gc_arena gc 
)

◆ print_link_socket_actual_ex()

const char* print_link_socket_actual_ex ( const struct link_socket_actual act,
const char *  separator,
const unsigned int  flags,
struct gc_arena gc 
)

◆ print_openvpn_sockaddr()

static const char* print_openvpn_sockaddr ( const struct openvpn_sockaddr addr,
struct gc_arena gc 
)
inlinestatic

◆ print_openvpn_sockaddr_ex()

static const char* print_openvpn_sockaddr_ex ( const struct openvpn_sockaddr addr,
const char *  separator,
const unsigned int  flags,
struct gc_arena gc 
)
inlinestatic

Definition at line 358 of file socket.h.

References openvpn_sockaddr::addr, print_sockaddr_ex(), and openvpn_sockaddr::sa.

◆ print_sockaddr()

static const char* print_sockaddr ( const struct sockaddr *  addr,
struct gc_arena gc 
)
inlinestatic

◆ print_sockaddr_ex()

const char* print_sockaddr_ex ( const struct sockaddr *  addr,
const char *  separator,
const unsigned int  flags,
struct gc_arena gc 
)

◆ proto2ascii()

const char* proto2ascii ( int  proto,
sa_family_t  af,
bool  display_form 
)

◆ proto2ascii_all()

const char* proto2ascii_all ( struct gc_arena gc)

Definition at line 3240 of file socket.c.

References alloc_buf_gc(), BSTR, buf_printf(), and SIZE.

Referenced by add_option().

◆ proto_is_dgram()

bool proto_is_dgram ( int  proto)

◆ proto_is_net()

bool proto_is_net ( int  proto)

Definition at line 3155 of file socket.c.

References ASSERT, PROTO_N, and PROTO_NONE.

Referenced by options_postprocess_verify_ce().

◆ proto_is_tcp()

bool proto_is_tcp ( int  proto)

◆ proto_is_udp()

bool proto_is_udp ( int  proto)

◆ proto_remote()

const char* proto_remote ( int  proto,
bool  remote 
)

Definition at line 3281 of file socket.c.

References ASSERT, PROTO_N, PROTO_TCP_CLIENT, PROTO_TCP_SERVER, and PROTO_UDP.

Referenced by options_string().

◆ sd_close()

void sd_close ( socket_descriptor_t sd)

◆ set_actual_address()

void set_actual_address ( struct link_socket_actual actual,
struct addrinfo *  ai 
)

◆ setenv_in6_addr()

void setenv_in6_addr ( struct env_set es,
const char *  name_prefix,
const struct in6_addr *  addr,
const unsigned int  flags 
)

◆ setenv_in_addr_t()

void setenv_in_addr_t ( struct env_set es,
const char *  name_prefix,
in_addr_t  addr,
const unsigned int  flags 
)

◆ setenv_link_socket_actual()

void setenv_link_socket_actual ( struct env_set es,
const char *  name_prefix,
const struct link_socket_actual act,
const unsigned int  flags 
)

Definition at line 3115 of file socket.c.

References link_socket_actual::dest, and setenv_sockaddr().

Referenced by setenv_trusted(), and setenv_untrusted().

◆ setenv_sockaddr()

void setenv_sockaddr ( struct env_set es,
const char *  name_prefix,
const struct openvpn_sockaddr addr,
const unsigned int  flags 
)

◆ setenv_trusted()

void setenv_trusted ( struct env_set es,
const struct link_socket_info info 
)

◆ socket_adjust_frame_parameters()

void socket_adjust_frame_parameters ( struct frame frame,
int  proto 
)

◆ socket_bind()

void socket_bind ( socket_descriptor_t  sd,
struct addrinfo *  local,
int  af_family,
const char *  prefix,
bool  ipv6only 
)

◆ socket_connection_reset()

static bool socket_connection_reset ( const struct link_socket sock,
int  status 
)
inlinestatic

◆ socket_do_accept()

socket_descriptor_t socket_do_accept ( socket_descriptor_t  sd,
struct link_socket_actual act,
const bool  nowait 
)

◆ socket_event_handle()

static event_t socket_event_handle ( const struct link_socket s)
inlinestatic

◆ socket_finalize()

int socket_finalize ( SOCKET  s,
struct overlapped_io io,
struct buffer buf,
struct link_socket_actual from 
)

◆ socket_listen_event_handle()

event_t socket_listen_event_handle ( struct link_socket s)

◆ socket_read_residual()

static bool socket_read_residual ( const struct link_socket s)
inlinestatic

Definition at line 1220 of file socket.h.

References stream_buf::residual_fully_formed, and link_socket::stream_buf.

Referenced by io_wait_dowork(), and multi_tcp_post().

◆ socket_recv_queue()

int socket_recv_queue ( struct link_socket sock,
int  maxsize 
)

◆ socket_reset_listen_persistent()

static void socket_reset_listen_persistent ( struct link_socket s)
inlinestatic

◆ socket_send_queue()

int socket_send_queue ( struct link_socket sock,
struct buffer buf,
const struct link_socket_actual to 
)

◆ socket_set()

unsigned int socket_set ( struct link_socket s,
struct event_set es,
unsigned int  rwflags,
void *  arg,
unsigned int *  persistent 
)

◆ socket_set_listen_persistent()

static void socket_set_listen_persistent ( struct link_socket s,
struct event_set es,
void *  arg 
)
inlinestatic

◆ socket_stat()

const char* socket_stat ( const struct link_socket s,
unsigned int  rwflags,
struct gc_arena gc 
)

◆ stream_buf_read_setup()

static bool stream_buf_read_setup ( struct link_socket sock)
inlinestatic

◆ stream_buf_read_setup_dowork()

bool stream_buf_read_setup_dowork ( struct link_socket sock)

Variable Documentation

◆ proto_overhead

const int proto_overhead[]

Definition at line 47 of file socket.c.

Referenced by datagram_overhead().