OpenVPN
Functions
dns.c File Reference
#include "syshead.h"
#include "dns.h"
#include "socket.h"
Include dependency graph for dns.c:

Go to the source code of this file.

Functions

static bool dns_server_port_parse (in_port_t *port, char *port_str)
 Parses a string as port and stores it. More...
 
bool dns_server_addr_parse (struct dns_server *server, const char *addr)
 Parses a string IPv4 or IPv6 address and optional colon separated port, into a in_addr or in6_addr respectively plus a in_port_t port. More...
 
void dns_domain_list_append (struct dns_domain **entry, char **domains, struct gc_arena *gc)
 Appends DNS domain parameters to a linked list. More...
 
bool dns_server_priority_parse (long *priority, const char *str, bool pulled)
 Parses a string DNS server priority and validates it. More...
 
struct dns_serverdns_server_get (struct dns_server **entry, long priority, struct gc_arena *gc)
 Find or create DNS server with priority in a linked list. More...
 
bool dns_options_verify (int msglevel, const struct dns_options *o)
 Checks validity of DNS options. More...
 
static struct dns_domainclone_dns_domains (const struct dns_domain *domain, struct gc_arena *gc)
 
static struct dns_serverclone_dns_servers (const struct dns_server *server, struct gc_arena *gc)
 
struct dns_options clone_dns_options (const struct dns_options o, struct gc_arena *gc)
 Makes a deep copy of the passed DNS options. More...
 
void dns_options_preprocess_pull (struct dns_options *o)
 Saves and resets the server options, so that pulled ones don't mix in. More...
 
void dns_options_postprocess_pull (struct dns_options *o)
 Merges pulled DNS servers with static ones into an ordered list. More...
 
static const char * dnssec_value (const enum dns_security dnssec)
 
static const char * transport_value (const enum dns_server_transport transport)
 
static void setenv_dns_option (struct env_set *es, const char *format, int i, int j, const char *value)
 
void setenv_dns_options (const struct dns_options *o, struct env_set *es)
 Puts the DNS options into an environment set. More...
 
void show_dns_options (const struct dns_options *o)
 Prints configured DNS options. More...
 

Function Documentation

◆ clone_dns_domains()

static struct dns_domain* clone_dns_domains ( const struct dns_domain domain,
struct gc_arena gc 
)
static

Definition at line 214 of file dns.c.

References ALLOC_OBJ_CLEAR_GC, and dns_domain::next.

Referenced by clone_dns_options(), and clone_dns_servers().

◆ clone_dns_options()

struct dns_options clone_dns_options ( const struct dns_options  o,
struct gc_arena gc 
)

Makes a deep copy of the passed DNS options.

Parameters
oPointer to the DNS options to clone
gcPointer to the gc_arena to use for the clone
Returns
The dns_options clone

Definition at line 251 of file dns.c.

References clone_dns_domains(), clone_dns_servers(), dns_options::gc, dns_options::search_domains, dns_options::servers, and dns_options::servers_prepull.

Referenced by pre_connect_restore(), and pre_connect_save().

◆ clone_dns_servers()

static struct dns_server* clone_dns_servers ( const struct dns_server server,
struct gc_arena gc 
)
static

Definition at line 232 of file dns.c.

References ALLOC_OBJ_CLEAR_GC, clone_dns_domains(), dns_server::domains, and dns_server::next.

Referenced by clone_dns_options().

◆ dns_domain_list_append()

void dns_domain_list_append ( struct dns_domain **  entry,
char **  domains,
struct gc_arena gc 
)

Appends DNS domain parameters to a linked list.

Parameters
entryAddress of the first list entry pointer
domainsAddress of the first domain parameter
gcThe gc the new list items should be allocated in

Definition at line 141 of file dns.c.

References ALLOC_OBJ_CLEAR_GC, dns_domain::name, and dns_domain::next.

Referenced by add_option().

◆ dns_options_postprocess_pull()

void dns_options_postprocess_pull ( struct dns_options o)

Merges pulled DNS servers with static ones into an ordered list.

Parameters
oPointer to the DNS options to modify

Definition at line 269 of file dns.c.

References dns_server::next, dns_server::priority, dns_options::servers, and dns_options::servers_prepull.

Referenced by options_postprocess_pull().

◆ dns_options_preprocess_pull()

void dns_options_preprocess_pull ( struct dns_options o)

Saves and resets the server options, so that pulled ones don't mix in.

Parameters
oPointer to the DNS options to modify

Definition at line 262 of file dns.c.

References dns_options::servers, and dns_options::servers_prepull.

Referenced by options_postprocess_mutate().

◆ dns_options_verify()

bool dns_options_verify ( int  msglevel,
const struct dns_options o 
)

Checks validity of DNS options.

Parameters
msglevelThe message level to log errors with
oPointer to the DNS options to validate
Returns
True if no error was found

Definition at line 197 of file dns.c.

References dns_server::addr_count, msg, dns_server::next, dns_server::priority, dns_options::servers, and dns_options::servers_prepull.

Referenced by options_postprocess_pull(), and options_postprocess_verify().

◆ dns_server_addr_parse()

bool dns_server_addr_parse ( struct dns_server server,
const char *  addr 
)

Parses a string IPv4 or IPv6 address and optional colon separated port, into a in_addr or in6_addr respectively plus a in_port_t port.

Parameters
serverPointer to DNS server the address is parsed for
addrAddress as string
Returns
True if parsing was successful

Definition at line 55 of file dns.c.

References dns_server_addr::a4, dns_server_addr::a6, dns_server::addr, dns_server::addr_count, dns_server_port_parse(), dns_server_addr::family, dns_server_addr::in, openvpn_getaddrinfo(), dns_server_addr::port, and SIZE.

Referenced by add_option().

◆ dns_server_get()

struct dns_server* dns_server_get ( struct dns_server **  entry,
long  priority,
struct gc_arena gc 
)

Find or create DNS server with priority in a linked list.

The list is ordered by priority.

Parameters
entryAddress of the first list entry pointer
priorityPriority of the DNS server to find / create
gcThe gc new list items should be allocated in

Definition at line 175 of file dns.c.

References ALLOC_OBJ_CLEAR_GC, dns_server::next, and dns_server::priority.

Referenced by add_option().

◆ dns_server_port_parse()

static bool dns_server_port_parse ( in_port_t *  port,
char *  port_str 
)
static

Parses a string as port and stores it.

Parameters
portPointer to in_port_t where the port value is stored
addrPort number as string
Returns
True if parsing was successful

Definition at line 41 of file dns.c.

Referenced by dns_server_addr_parse().

◆ dns_server_priority_parse()

bool dns_server_priority_parse ( long *  priority,
const char *  str,
bool  pulled 
)

Parses a string DNS server priority and validates it.

Parameters
priorityPointer to where the priority should be stored
strPriority string to parse
pulledWhether this was pulled from a server
Returns
True if priority in string is valid

Definition at line 160 of file dns.c.

Referenced by add_option().

◆ dnssec_value()

static const char* dnssec_value ( const enum dns_security  dnssec)
static

◆ setenv_dns_option()

static void setenv_dns_option ( struct env_set es,
const char *  format,
int  i,
int  j,
const char *  value 
)
static

Definition at line 343 of file dns.c.

References es, M_WARN, msg, openvpn_snprintf(), and setenv_str().

Referenced by setenv_dns_options().

◆ setenv_dns_options()

void setenv_dns_options ( const struct dns_options o,
struct env_set es 
)

◆ show_dns_options()

void show_dns_options ( const struct dns_options o)

◆ transport_value()

static const char* transport_value ( const enum dns_server_transport  transport)
static