OpenVPN
Data Structures | Macros | Functions | Variables
socket_util.c File Reference
#include "syshead.h"
#include "socket_util.h"
#include "crypto.h"
#include "manage.h"
Include dependency graph for socket_util.c:

Go to the source code of this file.

Data Structures

struct  proto_names
 

Macros

#define IF_NAMESIZE   16
 
#define n_rnd_bytes   6
 

Functions

const char * print_sockaddr_ex (const struct sockaddr *sa, 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_link_socket_actual_ex (const struct link_socket_actual *act, const char *separator, const unsigned int flags, 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 a6, 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 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 * addr_family_name (int af)
 
const char * proto_remote (int proto, bool remote)
 
static const char * getaddrinfo_addr_family_name (int af)
 Small helper function for openvpn_getaddrinfo to print the address family when resolving fails.
 
static const char * hostname_randomize (const char *hostname, struct gc_arena *gc)
 
int openvpn_getaddrinfo (unsigned int flags, const char *hostname, const char *servname, int resolve_retry_seconds, struct signal_info *sig_info, int ai_family, struct addrinfo **res)
 
int openvpn_inet_aton (const char *dotted_quad, struct in_addr *addr)
 
bool ip_addr_dotted_quad_safe (const char *dotted_quad)
 
bool ipv6_addr_safe (const char *ipv6_text_addr)
 
static bool dns_addr_safe (const char *addr)
 
bool ip_or_dns_addr_safe (const char *addr, const bool allow_fqdn)
 
bool mac_addr_safe (const char *mac_addr)
 

Variables

static const struct proto_names proto_names []
 

Macro Definition Documentation

◆ IF_NAMESIZE

#define IF_NAMESIZE   16

Definition at line 123 of file socket_util.c.

◆ n_rnd_bytes

#define n_rnd_bytes   6

Function Documentation

◆ add_in6_addr()

struct in6_addr add_in6_addr ( struct in6_addr  base,
uint32_t  add 
)

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

◆ ascii2af()

sa_family_t ascii2af ( const char *  proto_name)

Definition at line 396 of file socket_util.c.

References i, 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 i, proto_names::proto, proto_names::short_form, and SIZE.

Referenced by add_option().

◆ dns_addr_safe()

static bool dns_addr_safe ( const char *  addr)
static

Definition at line 859 of file socket_util.c.

References CC_ALNUM, CC_DASH, CC_DOT, and string_class().

Referenced by ip_or_dns_addr_safe().

◆ getaddrinfo_addr_family_name()

static const char * getaddrinfo_addr_family_name ( int  af)
static

Small helper function for openvpn_getaddrinfo to print the address family when resolving fails.

Definition at line 498 of file socket_util.c.

References buffer::len.

Referenced by openvpn_getaddrinfo().

◆ hostname_randomize()

static const char * hostname_randomize ( const char *  hostname,
struct gc_arena gc 
)
static

◆ ip_addr_dotted_quad_safe()

bool ip_addr_dotted_quad_safe ( const char *  dotted_quad)

Definition at line 787 of file socket_util.c.

References OIA_IP, and openvpn_inet_aton().

Referenced by check_route_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 873 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 837 of file socket_util.c.

Referenced by add_option(), and check_route6_option().

◆ mac_addr_safe()

bool mac_addr_safe ( const char *  mac_addr)

Definition at line 890 of file socket_util.c.

Referenced by add_option().

◆ openvpn_getaddrinfo()

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

◆ openvpn_inet_aton()

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

Definition at line 763 of file socket_util.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  a6,
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_sockaddr_ex()

const char * print_sockaddr_ex ( const struct sockaddr *  sa,
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, i, and SIZE.

Referenced by add_option().

◆ 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, es, 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 
)

Variable Documentation

◆ proto_names

const struct proto_names proto_names[]
static
Initial value:
= {
{ "proto-uninitialized", "proto-NONE", AF_UNSPEC, PROTO_NONE },
{ "udp", "UDP", AF_UNSPEC, PROTO_UDP },
{ "tcp-server", "TCP_SERVER", AF_UNSPEC, PROTO_TCP_SERVER },
{ "tcp-client", "TCP_CLIENT", AF_UNSPEC, PROTO_TCP_CLIENT },
{ "tcp", "TCP", AF_UNSPEC, PROTO_TCP },
{ "udp4", "UDPv4", AF_INET, PROTO_UDP },
{ "tcp4-server", "TCPv4_SERVER", AF_INET, PROTO_TCP_SERVER },
{ "tcp4-client", "TCPv4_CLIENT", AF_INET, PROTO_TCP_CLIENT },
{ "tcp4", "TCPv4", AF_INET, PROTO_TCP },
{ "udp6", "UDPv6", AF_INET6, PROTO_UDP },
{ "tcp6-server", "TCPv6_SERVER", AF_INET6, PROTO_TCP_SERVER },
{ "tcp6-client", "TCPv6_CLIENT", AF_INET6, PROTO_TCP_CLIENT },
{ "tcp6", "TCPv6", AF_INET6, PROTO_TCP },
}
@ PROTO_NONE
@ PROTO_UDP
@ PROTO_TCP
@ PROTO_TCP_CLIENT
@ PROTO_TCP_SERVER

Definition at line 363 of file socket_util.c.