OpenVPN
Data Structures | Macros | Enumerations | Functions
socket_util.h File Reference
#include "buffer.h"
#include "env_set.h"
#include "sig.h"
Include dependency graph for socket_util.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  link_socket_actual
 

Macros

#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 OIA_HOSTNAME   0
 
#define OIA_IP   1
 
#define OIA_ERROR   -1
 

Enumerations

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

Functions

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 (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)
 
const char * print_in_port_t (in_port_t port, 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)
 
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)
 
static bool proto_is_net (int proto)
 
static bool proto_is_udp (int proto)
 Returns if the protocol being used is UDP.
 
static bool proto_is_dgram (int proto)
 Return if the protocol is datagram (UDP)
 
static bool proto_is_tcp (int proto)
 returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
 
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 bool addr_defined (const struct openvpn_sockaddr *addr)
 
static int datagram_overhead (sa_family_t af, int proto)
 Overhead added to packets by various protocols.
 
static bool link_socket_proto_connection_oriented (int proto)
 
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 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, const struct addrinfo *addr_list, const int proto)
 
static void addr_zero_host (struct openvpn_sockaddr *addr)
 
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)
 

Macro Definition Documentation

◆ IA_EMPTY_IF_UNDEF

#define IA_EMPTY_IF_UNDEF   (1 << 0)

Definition at line 89 of file socket_util.h.

◆ IA_NET_ORDER

#define IA_NET_ORDER   (1 << 1)

Definition at line 90 of file socket_util.h.

◆ OIA_ERROR

#define OIA_ERROR   -1

Definition at line 116 of file socket_util.h.

◆ OIA_HOSTNAME

#define OIA_HOSTNAME   0

Definition at line 114 of file socket_util.h.

◆ OIA_IP

#define OIA_IP   1

Definition at line 115 of file socket_util.h.

◆ PS_DONT_SHOW_ADDR

#define PS_DONT_SHOW_ADDR   (1 << 3)

Definition at line 33 of file socket_util.h.

◆ PS_DONT_SHOW_FAMILY

#define PS_DONT_SHOW_FAMILY   (1 << 4)

Definition at line 34 of file socket_util.h.

◆ PS_SHOW_PKTINFO

#define PS_SHOW_PKTINFO   (1 << 2)

Definition at line 32 of file socket_util.h.

◆ PS_SHOW_PORT

#define PS_SHOW_PORT   (1 << 1)

Definition at line 31 of file socket_util.h.

◆ PS_SHOW_PORT_IF_DEFINED

#define PS_SHOW_PORT_IF_DEFINED   (1 << 0)

Definition at line 30 of file socket_util.h.

◆ SA_IP_PORT

#define SA_IP_PORT   (1 << 0)

Definition at line 99 of file socket_util.h.

◆ SA_SET_IF_NONZERO

#define SA_SET_IF_NONZERO   (1 << 1)

Definition at line 100 of file socket_util.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 136 of file socket_util.h.

Function Documentation

◆ add_in6_addr()

struct in6_addr add_in6_addr ( struct in6_addr  base,
uint32_t  add 
)

◆ addr_defined()

static bool addr_defined ( const struct openvpn_sockaddr *  addr)
inlinestatic

◆ addr_family_name()

const char * addr_family_name ( int  af)

Definition at line 446 of file socket_util.c.

References buffer::len.

Referenced by dco_mp_start_vpn(), dco_p2p_new_peer(), link_socket_init_phase2(), and socket_bind().

◆ 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,
const 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

Definition at line 426 of file socket_util.h.

References ASSERT, M_ERR, and msg.

Referenced by openvpn_connect(), read_sockaddr_from_overlapped(), socket_do_accept(), and socket_recv_queue().

◆ ascii2af()

sa_family_t ascii2af ( const char *  proto_name)

Definition at line 396 of file socket_util.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 383 of file socket_util.c.

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

Referenced by add_option().

◆ datagram_overhead()

static int datagram_overhead ( sa_family_t  af,
int  proto 
)
inlinestatic

Overhead added to packets by various protocols.

Definition at line 270 of file socket_util.h.

References PROTO_UDP.

Referenced by calc_control_channel_frame_overhead(), frame_adjust_path_mtu(), get_ip_encap_overhead(), and process_outgoing_link().

◆ ip_addr_dotted_quad_safe()

bool ip_addr_dotted_quad_safe ( const char *  dotted_quad)

◆ ip_or_dns_addr_safe()

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

Definition at line 608 of file socket_util.c.

References dns_addr_safe(), and ip_addr_dotted_quad_safe().

Referenced by add_option(), and check_route_option().

◆ ipv6_addr_safe()

bool ipv6_addr_safe ( const char *  ipv6_text_addr)

Definition at line 572 of file socket_util.c.

Referenced by add_option(), and check_route6_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_proto_connection_oriented()

static bool link_socket_proto_connection_oriented ( int  proto)
inlinestatic

◆ mac_addr_safe()

bool mac_addr_safe ( const char *  mac_addr)

Definition at line 625 of file socket_util.c.

Referenced by add_option().

◆ openvpn_inet_aton()

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

Definition at line 498 of file socket_util.c.

References CC_DIGIT, CC_DOT, CLEAR, buffer::len, 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_in_port_t()

const char * print_in_port_t ( in_port_t  port,
struct gc_arena *  gc 
)

Definition at line 231 of file socket_util.c.

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

Referenced by show_dns_options().

◆ 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

Definition at line 71 of file socket_util.h.

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

Referenced by recv_socks_reply().

◆ 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 430 of file socket_util.c.

References alloc_buf_gc(), BSTR, buf_printf(), gc, buffer::len, and SIZE.

Referenced by add_option().

◆ proto_is_dgram()

static bool proto_is_dgram ( int  proto)
inlinestatic

◆ proto_is_net()

static bool proto_is_net ( int  proto)
inlinestatic

Definition at line 147 of file socket_util.h.

References ASSERT, PROTO_N, and PROTO_NONE.

Referenced by options_postprocess_verify_ce().

◆ proto_is_tcp()

static bool proto_is_tcp ( int  proto)
inlinestatic

returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)

Definition at line 177 of file socket_util.h.

References ASSERT, PROTO_N, PROTO_TCP_CLIENT, and PROTO_TCP_SERVER.

Referenced by frame_calculate_protocol_header_size(), link_socket_read(), link_socket_write(), multi_client_connect_real_addr(), phase2_set_socket_flags(), socket_recv_queue(), and socket_send_queue().

◆ proto_is_udp()

static bool proto_is_udp ( int  proto)
inlinestatic

◆ proto_remote()

const char * proto_remote ( int  proto,
bool  remote 
)

Definition at line 472 of file socket_util.c.

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

Referenced by options_string().

◆ 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 344 of file socket_util.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 
)