1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-14 05:30:41 +03:00
SoftEtherVPN/src/Mayaqua/DNS.h
Davide Beatrici 0472f9c286 Rewrite DNS API from scratch into dedicated file(s)
From a functional point of view, the main improvement is that GetIP() now always prioritizes IPv6 over IPv4.
The previous implementation always returned an IPv4 address, unless not available: in such case it failed.
This means that now connections to hostnames should be established via IPv6 if available.

From a programmer point of view, getting rid of the insane wrappers is enough to justify a complete rewrite.

As an extra, several unrelated unused global variables are removed.
2021-04-18 01:46:59 +02:00

79 lines
1.9 KiB
C

#ifndef DNS_H
#define DNS_H
#include "Network.h"
#define DNS_CACHE_EXPIRATION (10 * 60 * 1000)
#ifndef USE_STRATEGY_LOW_MEMORY
#define DNS_THREAD_DEFAULT_NUM_MAX (512)
#else
#define DNS_THREAD_DEFAULT_NUM_MAX (64)
#endif
#define DNS_RESOLVE_DEFAULT_TIMEOUT (2300)
#define DNS_RESOLVE_REVERSE_DEFAULT_TIMEOUT (500)
#define GetIP(ip, hostname) (GetIPEx(ip, hostname, 0, NULL))
#define GetIP4(ip, hostname) (GetIP4Ex(ip, hostname, 0, NULL))
#define GetIP6(ip, hostname) (GetIP6Ex(ip, hostname, 0, NULL))
#define GetIP4Ex(ip, hostname, timeout, cancel_flag) (DnsResolve(NULL, ip, hostname, timeout, cancel_flag))
#define GetIP6Ex(ip, hostname, timeout, cancel_flag) (DnsResolve(ip, NULL, hostname, timeout, cancel_flag))
struct DNS_CACHE
{
const char *Hostname;
IP IPv4;
IP IPv6;
UINT64 Expiration;
};
struct DNS_CACHE_REVERSE
{
IP IP;
char *Hostname;
UINT64 Expiration;
};
struct DNS_RESOLVER
{
const char *Hostname;
IP IPv4;
IP IPv6;
bool OK;
};
struct DNS_RESOLVER_REVERSE
{
IP IP;
char *Hostname;
bool OK;
};
void DnsInit();
void DnsFree();
UINT DnsThreadNum();
UINT DnsThreadNumMax();
void DnsThreadNumMaxSet(const UINT num);
bool DnsCacheIsEnabled();
void DnsCacheToggle(const bool enabled);
DNS_CACHE *DnsCacheFind(const char *hostname);
DNS_CACHE *DnsCacheUpdate(const char *hostname, const IP *ipv6, const IP *ipv4);
DNS_CACHE_REVERSE *DnsCacheReverseFind(const IP *ip);
DNS_CACHE_REVERSE *DnsCacheReverseUpdate(const IP *ip, const char *hostname);
bool DnsResolve(IP *ipv6, IP *ipv4, const char *hostname, UINT timeout, volatile const bool *cancel_flag);
void DnsResolver(THREAD *t, void *param);
bool DnsResolveReverse(char *dst, const UINT size, const IP *ip, UINT timeout, volatile const bool *cancel_flag);
void DnsResolverReverse(THREAD *t, void *param);
bool GetIPEx(IP *ip, const char *hostname, UINT timeout, volatile const bool *cancel_flag);
#endif