OpenVPN
resolve.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/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) 2002-2026 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
27#ifndef RESOLVE_H
28#define RESOLVE_H
29
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif
33
34#include "syshead.h"
35
36#include "sig.h"
37
38#define GETADDR_RESOLVE (1u << 0)
39#define GETADDR_FATAL (1u << 1)
40#define GETADDR_HOST_ORDER (1u << 2)
41#define GETADDR_MENTION_RESOLVE_RETRY (1u << 3)
42#define GETADDR_FATAL_ON_SIGNAL (1u << 4)
43#define GETADDR_WARN_ON_SIGNAL (1u << 5)
44#define GETADDR_MSG_VIRT_OUT (1u << 6)
45#define GETADDR_TRY_ONCE (1u << 7)
46#define GETADDR_UPDATE_MANAGEMENT_STATE (1u << 8)
47#define GETADDR_RANDOMIZE (1u << 9)
48#define GETADDR_PASSIVE (1u << 10)
49#define GETADDR_DATAGRAM (1u << 11)
50
51#define GETADDR_CACHE_MASK (GETADDR_DATAGRAM | GETADDR_PASSIVE)
52
56unsigned int sf2gaf(const unsigned int getaddr_flags, const unsigned int sockflags);
57
64in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds,
65 bool *succeeded, struct signal_info *sig_info);
66
67in_addr_t get_ip_addr(const char *ip_string, msglvl_t msglevel, bool *error);
68
72bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits,
73 msglvl_t msglevel);
74
75static inline bool
76ipv6_addr_safe_hexplusbits(const char *ipv6_prefix_spec)
77{
78 return get_ipv6_addr(ipv6_prefix_spec, NULL, NULL, M_WARN);
79}
80
81int openvpn_getaddrinfo(unsigned int flags, const char *hostname, const char *servname,
82 int resolve_retry_seconds, struct signal_info *sig_info, int ai_family,
83 struct addrinfo **res);
84
85void do_preresolve(struct context *c);
86
87/* struct to hold preresolved host names */
89{
90 const char *hostname;
91 const char *servname;
93 unsigned int flags;
94 struct addrinfo *ai;
96};
97
102int get_cached_dns_entry(struct cached_dns_entry *dns_cache, const char *hostname,
103 const char *servname, int ai_family,
104 unsigned int resolve_flags, struct addrinfo **ai);
105
106#endif /* RESOLVE_H */
unsigned int msglvl_t
Definition error.h:77
#define M_WARN
Definition error.h:92
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)
Definition resolve.c:102
in_addr_t get_ip_addr(const char *ip_string, msglvl_t msglevel, bool *error)
Definition resolve.c:469
bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, msglvl_t msglevel)
Translate an IPv6 addr or hostname from string form to in6_addr.
Definition resolve.c:489
int get_cached_dns_entry(struct cached_dns_entry *dns_cache, const char *hostname, const char *servname, int ai_family, unsigned int resolve_flags, struct addrinfo **ai)
get_cached_dns_entry return 0 on success and -1 otherwise.
Definition resolve.c:506
void do_preresolve(struct context *c)
Definition resolve.c:573
static bool ipv6_addr_safe_hexplusbits(const char *ipv6_prefix_spec)
Definition resolve.h:76
unsigned int sf2gaf(const unsigned int getaddr_flags, const unsigned int sockflags)
Convert sockflags/getaddr_flags into getaddr_flags.
Definition resolve.c:42
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, struct signal_info *sig_info)
Translate an IPv4 addr or hostname from string form to in_addr_t.
Definition resolve.c:442
Definition resolve.h:89
const char * hostname
Definition resolve.h:90
int ai_family
Definition resolve.h:92
const char * servname
Definition resolve.h:91
unsigned int flags
Definition resolve.h:93
struct addrinfo * ai
Definition resolve.h:94
struct cached_dns_entry * next
Definition resolve.h:95
Contains all state information for one tunnel.
Definition openvpn.h:471
uint32_t in_addr_t
Definition syshead.h:52