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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef DNS_H
24#define DNS_H
25
26#include "buffer.h"
27#include "env_set.h"
28#include "tun.h"
29
37
45
52
54{
56 const char *name;
57};
58
60{
61 union
62 {
63 struct in_addr a4;
64 struct in6_addr a6;
65 } in;
67 in_port_t port;
68};
69
81
83{
85 int fds[2];
86#if !defined(_WIN32)
87 pid_t pid;
88#endif
89};
90
91#ifndef N_DHCP_ADDR
92#define N_DHCP_ADDR 4
93#endif
94
95#ifndef N_SEARCH_LIST_LEN
96#define N_SEARCH_LIST_LEN 10
97#endif
98
100{
101 in_addr_t dns[N_DHCP_ADDR];
103
104 struct in6_addr dns6[N_DHCP_ADDR];
106
107 const char *domain;
110};
111
122
131bool dns_server_priority_parse(long *priority, const char *str, bool pulled);
132
141struct dns_server *dns_server_get(struct dns_server **entry, long priority, struct gc_arena *gc);
142
150void dns_domain_list_append(struct dns_domain **entry, char **domains, struct gc_arena *gc);
151
160bool dns_server_addr_parse(struct dns_server *server, const char *addr);
161
169bool dns_options_verify(int msglevel, const struct dns_options *o);
170
178struct dns_options clone_dns_options(const struct dns_options *o, struct gc_arena *gc);
179
186
193
201void run_dns_up_down(bool up, struct options *o, const struct tuntap *tt,
202 struct dns_updown_runner_info *duri);
203
209void show_dns_options(const struct dns_options *o);
210
216static inline bool
218{
220}
221
227static inline bool
229{
230 return o->updown_flags == DNS_UPDOWN_FORCED;
231}
232
233#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:217
bool dns_options_verify(int msglevel, const struct dns_options *o)
Checks validity of DNS options.
Definition dns.c:203
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:147
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:848
void dns_options_postprocess_pull(struct dns_options *o)
Merges pulled DNS servers with static ones into an ordered list.
Definition dns.c:279
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:61
dns_updown_flags
Definition dns.h:47
@ DNS_UPDOWN_FORCED
Definition dns.h:50
@ DNS_UPDOWN_NO_FLAGS
Definition dns.h:48
@ DNS_UPDOWN_USER_SET
Definition dns.h:49
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:181
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:166
static bool dns_updown_forced(const struct dns_options *o)
Returns whether dns-updown is forced to run.
Definition dns.h:228
dns_server_transport
Definition dns.h:39
@ DNS_TRANSPORT_PLAIN
Definition dns.h:41
@ DNS_TRANSPORT_UNSET
Definition dns.h:40
@ DNS_TRANSPORT_TLS
Definition dns.h:43
@ DNS_TRANSPORT_HTTPS
Definition dns.h:42
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:257
void show_dns_options(const struct dns_options *o)
Prints configured DNS options.
Definition dns.c:769
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:272
int dns6_len
Definition dns.h:105
const char * domain_search_list[N_SEARCH_LIST_LEN]
Definition dns.h:108
const char * domain
Definition dns.h:107
struct in6_addr dns6[N_DHCP_ADDR]
Definition dns.h:104
int dns_len
Definition dns.h:102
in_addr_t dns[N_DHCP_ADDR]
Definition dns.h:101
int domain_search_list_len
Definition dns.h:109
struct dns_domain * next
Definition dns.h:55
const char * name
Definition dns.h:56
struct dns_server * servers
Definition dns.h:117
const char * updown
Definition dns.h:119
struct dhcp_options from_dhcp
Definition dns.h:114
struct dns_server * servers_prepull
Definition dns.h:116
struct gc_arena gc
Definition dns.h:118
enum dns_updown_flags updown_flags
Definition dns.h:120
struct dns_domain * search_domains
Definition dns.h:115
struct in_addr a4
Definition dns.h:63
union dns_server_addr::@0 in
sa_family_t family
Definition dns.h:66
struct in6_addr a6
Definition dns.h:64
in_port_t port
Definition dns.h:67
struct dns_server_addr addr[8]
Definition dns.h:75
enum dns_security dnssec
Definition dns.h:77
struct dns_server * next
Definition dns.h:72
long priority
Definition dns.h:73
size_t addr_count
Definition dns.h:74
struct dns_domain * domains
Definition dns.h:76
enum dns_server_transport transport
Definition dns.h:78
const char * sni
Definition dns.h:79
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:116
Definition tun.h:183
unsigned short sa_family_t
Definition syshead.h:396
struct gc_arena gc
Definition test_ssl.c:154
#define N_SEARCH_LIST_LEN
Definition tun.h:128
#define N_DHCP_ADDR
Definition tun.h:109