OpenVPN
Functions
dns.c File Reference
#include "syshead.h"
#include "dns.h"
#include "socket.h"
#include "options.h"
#include "win32.h"
#include "openvpn-msg.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.
 
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.
 
void dns_domain_list_append (struct dns_domain **entry, char **domains, struct gc_arena *gc)
 Appends DNS domain parameters to a linked list.
 
bool dns_server_priority_parse (long *priority, const char *str, bool pulled)
 Parses a string DNS server priority and validates it.
 
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.
 
bool dns_options_verify (int msglevel, const struct dns_options *o)
 Checks validity of DNS options.
 
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.
 
void dns_options_preprocess_pull (struct dns_options *o)
 Saves and resets the server options, so that pulled ones don't mix in.
 
void dns_options_postprocess_pull (struct dns_options *o)
 Merges pulled DNS servers with static ones into an ordered list.
 
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.
 
static void make_domain_list (const char *what, const struct dns_domain *src, bool nrpt_domains, char *dst, size_t dst_size)
 
static void run_up_down_service (bool add, const struct options *o, const struct tuntap *tt)
 
void show_dns_options (const struct dns_options *o)
 Prints configured DNS options.
 
void run_dns_up_down (bool up, struct options *o, const struct tuntap *tt)
 Invokes the action associated with bringing DNS up or down.
 

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 220 of file dns.c.

References ALLOC_OBJ_CLEAR_GC, 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 257 of file dns.c.

References clone_dns_domains(), clone_dns_servers(), 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 238 of file dns.c.

References ALLOC_OBJ_CLEAR_GC, clone_dns_domains(), dns_server::domains, gc, 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 147 of file dns.c.

References ALLOC_OBJ_CLEAR_GC, 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 277 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 270 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 203 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 61 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 181 of file dns.c.

References ALLOC_OBJ_CLEAR_GC, 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
port_strPort number as string
Returns
True if parsing was successful

Definition at line 47 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 166 of file dns.c.

Referenced by add_option().

◆ dnssec_value()

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

◆ make_domain_list()

static void make_domain_list ( const char *  what,
const struct dns_domain src,
bool  nrpt_domains,
char *  dst,
size_t  dst_size 
)
static

Definition at line 440 of file dns.c.

References M_WARN, msg, dns_domain::name, and dns_domain::next.

Referenced by run_up_down_service().

◆ run_dns_up_down()

void run_dns_up_down ( bool  up,
struct options o,
const struct tuntap tt 
)

Invokes the action associated with bringing DNS up or down.

Parameters
upBoolean to set this call to "up" when true
oPointer to the program options
ttPointer to the connection's tuntap struct

Definition at line 633 of file dns.c.

References dns_server::addr, dns_server::addr_count, tuntap::did_ifconfig_ipv6_setup, tuntap::did_ifconfig_setup, options::dns_options, dns_server_addr::family, M_WARN, msg, dns_server::next, dns_server::priority, run_up_down_service(), and dns_options::servers.

Referenced by do_close_tun(), and do_open_tun().

◆ run_up_down_service()

static void run_up_down_service ( bool  add,
const struct options o,
const struct tuntap tt 
)
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 351 of file dns.c.

References es, M_WARN, msg, 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