OpenVPN
dns.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2022-2025 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24#ifndef DNS_H
25#define DNS_H
26
27#include "buffer.h"
28#include "env_set.h"
29#include "tun.h"
30
37
44
50
51struct dns_domain {
53 const char *name;
54};
55
57 union {
58 struct in_addr a4;
59 struct in6_addr a6;
60 } in;
62 in_port_t port;
63};
64
75
78 int fds[2];
79#if !defined(_WIN32)
80 pid_t pid;
81#endif
82};
83
84#ifndef N_DHCP_ADDR
85#define N_DHCP_ADDR 4
86#endif
87
88#ifndef N_SEARCH_LIST_LEN
89#define N_SEARCH_LIST_LEN 10
90#endif
91
93 in_addr_t dns[N_DHCP_ADDR];
95
96 struct in6_addr dns6[N_DHCP_ADDR];
98
99 const char *domain;
102};
103
113
122bool dns_server_priority_parse(long *priority, const char *str, bool pulled);
123
132struct dns_server *dns_server_get(struct dns_server **entry, long priority, struct gc_arena *gc);
133
141void dns_domain_list_append(struct dns_domain **entry, char **domains, struct gc_arena *gc);
142
151bool dns_server_addr_parse(struct dns_server *server, const char *addr);
152
160bool dns_options_verify(int msglevel, const struct dns_options *o);
161
169struct dns_options clone_dns_options(const struct dns_options *o,
170 struct gc_arena *gc);
171
178
185
193void run_dns_up_down(bool up, struct options *o, const struct tuntap *tt,
194 struct dns_updown_runner_info *duri);
195
201void show_dns_options(const struct dns_options *o);
202
208static inline bool
210{
212}
213
219static inline bool
221{
222 return o->updown_flags == DNS_UPDOWN_FORCED;
223}
224
225#endif /* ifndef DNS_H */
static bool dns_updown_user_set(const struct dns_options *o)
Returns whether dns-updown is user defined.
Definition dns.h:209
bool dns_options_verify(int msglevel, const struct dns_options *o)
Checks validity of DNS options.
Definition dns.c:204
void dns_domain_list_append(struct dns_domain **entry, char **domains, struct gc_arena *gc)
Appends DNS domain parameters to a linked list.
Definition dns.c:148
void run_dns_up_down(bool up, struct options *o, const struct tuntap *tt, struct dns_updown_runner_info *duri)
Invokes the action associated with bringing DNS up or down.
Definition dns.c:850
void dns_options_postprocess_pull(struct dns_options *o)
Merges pulled DNS servers with static ones into an ordered list.
Definition dns.c:280
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 re...
Definition dns.c:62
dns_updown_flags
Definition dns.h:45
@ DNS_UPDOWN_FORCED
Definition dns.h:48
@ DNS_UPDOWN_NO_FLAGS
Definition dns.h:46
@ DNS_UPDOWN_USER_SET
Definition dns.h:47
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.
Definition dns.c:182
dns_security
Definition dns.h:31
@ DNS_SECURITY_UNSET
Definition dns.h:32
@ DNS_SECURITY_NO
Definition dns.h:33
@ DNS_SECURITY_YES
Definition dns.h:34
@ DNS_SECURITY_OPTIONAL
Definition dns.h:35
bool dns_server_priority_parse(long *priority, const char *str, bool pulled)
Parses a string DNS server priority and validates it.
Definition dns.c:167
static bool dns_updown_forced(const struct dns_options *o)
Returns whether dns-updown is forced to run.
Definition dns.h:220
dns_server_transport
Definition dns.h:38
@ DNS_TRANSPORT_PLAIN
Definition dns.h:40
@ DNS_TRANSPORT_UNSET
Definition dns.h:39
@ DNS_TRANSPORT_TLS
Definition dns.h:42
@ DNS_TRANSPORT_HTTPS
Definition dns.h:41
struct dns_options clone_dns_options(const struct dns_options *o, struct gc_arena *gc)
Makes a deep copy of the passed DNS options.
Definition dns.c:258
void show_dns_options(const struct dns_options *o)
Prints configured DNS options.
Definition dns.c:771
void dns_options_preprocess_pull(struct dns_options *o)
Saves and resets the server options, so that pulled ones don't mix in.
Definition dns.c:273
int dns6_len
Definition dns.h:97
const char * domain_search_list[N_SEARCH_LIST_LEN]
Definition dns.h:100
const char * domain
Definition dns.h:99
struct in6_addr dns6[N_DHCP_ADDR]
Definition dns.h:96
int dns_len
Definition dns.h:94
in_addr_t dns[N_DHCP_ADDR]
Definition dns.h:93
int domain_search_list_len
Definition dns.h:101
struct dns_domain * next
Definition dns.h:52
const char * name
Definition dns.h:53
struct dns_server * servers
Definition dns.h:108
const char * updown
Definition dns.h:110
struct dhcp_options from_dhcp
Definition dns.h:105
struct dns_server * servers_prepull
Definition dns.h:107
struct gc_arena gc
Definition dns.h:109
enum dns_updown_flags updown_flags
Definition dns.h:111
struct dns_domain * search_domains
Definition dns.h:106
struct in_addr a4
Definition dns.h:58
union dns_server_addr::@0 in
sa_family_t family
Definition dns.h:61
struct in6_addr a6
Definition dns.h:59
in_port_t port
Definition dns.h:62
struct dns_server_addr addr[8]
Definition dns.h:69
enum dns_security dnssec
Definition dns.h:71
struct dns_server * next
Definition dns.h:66
long priority
Definition dns.h:67
size_t addr_count
Definition dns.h:68
struct dns_domain * domains
Definition dns.h:70
enum dns_server_transport transport
Definition dns.h:72
const char * sni
Definition dns.h:73
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:117
Definition tun.h:178
unsigned short sa_family_t
Definition syshead.h:395
struct gc_arena gc
Definition test_ssl.c:155
#define N_SEARCH_LIST_LEN
Definition tun.h:126
#define N_DHCP_ADDR
Definition tun.h:108