1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef netwerk_dns_GetAddrInfo_h
8 #define netwerk_dns_GetAddrInfo_h
12 #include "nsINativeDNSResolverOverride.h"
13 #include "nsHashKeys.h"
14 #include "nsTHashMap.h"
15 #include "mozilla/RWLock.h"
18 #include "mozilla/net/DNS.h"
19 #include "nsIDNSByTypeRecord.h"
20 #include "mozilla/Logging.h"
23 # define DNSQUERY_AVAILABLE 1
25 # undef DNSQUERY_AVAILABLE
31 extern LazyLogModule gGetAddrInfoLog
;
36 * Look up a host by name. Mostly equivalent to getaddrinfo(host, NULL, ...) of
39 * @param aHost[in] Character string defining the host name of interest
40 * @param aAddressFamily[in] May be AF_INET, AF_INET6, or AF_UNSPEC.
41 * @param aFlags[in] May be either PR_AI_ADDRCONFIG or
42 * PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME. Include PR_AI_NOCANONNAME to
43 * suppress the determination of the canonical name corresponding to
44 * hostname (PR_AI_NOCANONNAME will be ignored if the TTL is retrieved).
45 * @param aAddrInfo[out] Will point to the results of the host lookup, or be
46 * null if the lookup failed.
47 * @param aGetTtl[in] If true, the TTL will be retrieved if DNS provides the
50 nsresult
GetAddrInfo(const nsACString
& aHost
, uint16_t aAddressFamily
,
51 uint16_t aFlags
, AddrInfo
** aAddrInfo
, bool aGetTtl
);
54 * Initialize the GetAddrInfo module.
56 * GetAddrInfoShutdown() should be called for every time this function is
59 nsresult
GetAddrInfoInit();
62 * Shutdown the GetAddrInfo module.
64 * This function should be called for every time GetAddrInfoInit() is called.
65 * An assertion may throw (but is not guarenteed) if this function is called
68 nsresult
GetAddrInfoShutdown();
70 void DNSThreadShutdown();
73 * Resolves a HTTPS record. Will check overrides before calling the
74 * native OS implementation.
76 nsresult
ResolveHTTPSRecord(const nsACString
& aHost
, uint16_t aFlags
,
77 TypeRecordResultType
& aResult
, uint32_t& aTTL
);
80 * The platform specific implementation of HTTPS resolution.
82 nsresult
ResolveHTTPSRecordImpl(const nsACString
& aHost
, uint16_t aFlags
,
83 TypeRecordResultType
& aResult
, uint32_t& aTTL
);
85 nsresult
ParseHTTPSRecord(nsCString
& aHost
, DNSPacket
& aDNSPacket
,
86 TypeRecordResultType
& aResult
, uint32_t& aTTL
);
88 class NativeDNSResolverOverride
: public nsINativeDNSResolverOverride
{
89 NS_DECL_THREADSAFE_ISUPPORTS
90 NS_DECL_NSINATIVEDNSRESOLVEROVERRIDE
92 NativeDNSResolverOverride() = default;
94 static already_AddRefed
<nsINativeDNSResolverOverride
> GetSingleton();
97 virtual ~NativeDNSResolverOverride() = default;
98 mozilla::RWLock mLock MOZ_UNANNOTATED
{"NativeDNSResolverOverride"};
100 nsTHashMap
<nsCStringHashKey
, nsTArray
<NetAddr
>> mOverrides
;
101 nsTHashMap
<nsCStringHashKey
, nsCString
> mCnames
;
102 nsTHashMap
<nsCStringHashKey
, nsTArray
<uint8_t>> mHTTPSRecordOverrides
;
104 friend bool FindAddrOverride(const nsACString
& aHost
, uint16_t aAddressFamily
,
105 uint16_t aFlags
, AddrInfo
** aAddrInfo
);
106 friend bool FindHTTPSRecordOverride(const nsACString
& aHost
,
107 TypeRecordResultType
& aResult
);
111 } // namespace mozilla
113 #endif // netwerk_dns_GetAddrInfo_h