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"
21 #include "nsIDNSService.h"
24 # define DNSQUERY_AVAILABLE 1
26 # undef DNSQUERY_AVAILABLE
32 extern LazyLogModule gGetAddrInfoLog
;
37 * Look up a host by name. Mostly equivalent to getaddrinfo(host, NULL, ...) of
40 * @param aHost[in] Character string defining the host name of interest
41 * @param aAddressFamily[in] May be AF_INET, AF_INET6, or AF_UNSPEC.
42 * @param aFlags[in] See nsIDNSService::DNSFlags
43 * @param aAddrInfo[out] Will point to the results of the host lookup, or be
44 * null if the lookup failed.
45 * @param aGetTtl[in] If true, the TTL will be retrieved if DNS provides the
48 nsresult
GetAddrInfo(const nsACString
& aHost
, uint16_t aAddressFamily
,
49 nsIDNSService::DNSFlags aFlags
, AddrInfo
** aAddrInfo
,
53 * Initialize the GetAddrInfo module.
55 * GetAddrInfoShutdown() should be called for every time this function is
58 nsresult
GetAddrInfoInit();
61 * Shutdown the GetAddrInfo module.
63 * This function should be called for every time GetAddrInfoInit() is called.
64 * An assertion may throw (but is not guarenteed) if this function is called
67 nsresult
GetAddrInfoShutdown();
69 void DNSThreadShutdown();
72 * Resolves a HTTPS record. Will check overrides before calling the
73 * native OS implementation.
75 nsresult
ResolveHTTPSRecord(const nsACString
& aHost
,
76 nsIDNSService::DNSFlags aFlags
,
77 TypeRecordResultType
& aResult
, uint32_t& aTTL
);
80 * The platform specific implementation of HTTPS resolution.
82 nsresult
ResolveHTTPSRecordImpl(const nsACString
& aHost
,
83 nsIDNSService::DNSFlags aFlags
,
84 TypeRecordResultType
& aResult
, uint32_t& aTTL
);
86 nsresult
ParseHTTPSRecord(nsCString
& aHost
, DNSPacket
& aDNSPacket
,
87 TypeRecordResultType
& aResult
, uint32_t& aTTL
);
89 // Use the provided aHost to create a mock HTTPS record.
90 nsresult
CreateAndResolveMockHTTPSRecord(const nsACString
& aHost
,
91 nsIDNSService::DNSFlags aFlags
,
92 TypeRecordResultType
& aResult
,
95 class NativeDNSResolverOverride
: public nsINativeDNSResolverOverride
{
96 NS_DECL_THREADSAFE_ISUPPORTS
97 NS_DECL_NSINATIVEDNSRESOLVEROVERRIDE
99 NativeDNSResolverOverride() = default;
101 static already_AddRefed
<nsINativeDNSResolverOverride
> GetSingleton();
104 virtual ~NativeDNSResolverOverride() = default;
105 mozilla::RWLock mLock
{"NativeDNSResolverOverride"};
107 nsTHashMap
<nsCStringHashKey
, nsTArray
<NetAddr
>> mOverrides
108 MOZ_GUARDED_BY(mLock
);
109 nsTHashMap
<nsCStringHashKey
, nsCString
> mCnames
MOZ_GUARDED_BY(mLock
);
110 nsTHashMap
<nsCStringHashKey
, nsTArray
<uint8_t>> mHTTPSRecordOverrides
111 MOZ_GUARDED_BY(mLock
);
113 friend bool FindAddrOverride(const nsACString
& aHost
, uint16_t aAddressFamily
,
114 nsIDNSService::DNSFlags aFlags
,
115 AddrInfo
** aAddrInfo
);
116 friend bool FindHTTPSRecordOverride(const nsACString
& aHost
,
117 TypeRecordResultType
& aResult
);
121 } // namespace mozilla
123 #endif // netwerk_dns_GetAddrInfo_h