mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
Bug 1588219 - Expose DNS suffix list (Linux) r=dragana
Differential Revision: https://phabricator.services.mozilla.com/D49414 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
b41a3493f1
commit
fe3c993ae7
@ -60,7 +60,12 @@ nsNetworkLinkService::GetNetworkID(nsACString& aNetworkID) {
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNetworkLinkService::GetDnsSuffixList(nsTArray<nsCString>& aDnsSuffixList) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
if (!mNetlinkSvc) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
mNetlinkSvc->GetDnsSuffixList(aDnsSuffixList);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -26,6 +26,12 @@
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
|
||||
#if defined(HAVE_RES_NINIT)
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/nameser.h>
|
||||
# include <resolv.h>
|
||||
#endif
|
||||
|
||||
/* a shorter name that better explains what it does */
|
||||
#define EINTR_RETRY(x) MOZ_TEMP_FAILURE_RETRY(x)
|
||||
|
||||
@ -1711,6 +1717,26 @@ bool NetlinkService::CalculateIDForFamily(uint8_t aFamily, SHA1Sum* aSHA1) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
void NetlinkService::ComputeDNSSuffixList() {
|
||||
MOZ_ASSERT(!NS_IsMainThread(), "Must not be called on the main thread");
|
||||
#if defined(HAVE_RES_NINIT)
|
||||
nsTArray<nsCString> suffixList;
|
||||
struct __res_state res;
|
||||
if (res_ninit(&res) == 0) {
|
||||
for (int i = 0; i < MAXDNSRCH; i++) {
|
||||
if (!res.dnsrch[i]) {
|
||||
break;
|
||||
}
|
||||
suffixList.AppendElement(nsCString(res.dnsrch[i]));
|
||||
}
|
||||
res_nclose(&res);
|
||||
}
|
||||
|
||||
MutexAutoLock lock(mMutex);
|
||||
mDNSSuffixList = std::move(suffixList);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Figure out the "network identification".
|
||||
void NetlinkService::CalculateNetworkID() {
|
||||
LOG(("NetlinkService::CalculateNetworkID"));
|
||||
@ -1723,6 +1749,7 @@ void NetlinkService::CalculateNetworkID() {
|
||||
SHA1Sum sha1;
|
||||
|
||||
UpdateLinkStatus();
|
||||
ComputeDNSSuffixList();
|
||||
|
||||
bool idChanged = false;
|
||||
bool found4 = CalculateIDForFamily(AF_INET, &sha1);
|
||||
@ -1793,6 +1820,16 @@ void NetlinkService::GetNetworkID(nsACString& aNetworkID) {
|
||||
aNetworkID = mNetworkId;
|
||||
}
|
||||
|
||||
nsresult NetlinkService::GetDnsSuffixList(nsTArray<nsCString>& aDnsSuffixList) {
|
||||
#if defined(HAVE_RES_NINIT)
|
||||
MutexAutoLock lock(mMutex);
|
||||
aDnsSuffixList = mDNSSuffixList;
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
void NetlinkService::GetIsLinkUp(bool* aIsUp) {
|
||||
MutexAutoLock lock(mMutex);
|
||||
*aIsUp = mLinkUp;
|
||||
|
@ -55,6 +55,7 @@ class NetlinkService : public nsIRunnable {
|
||||
nsresult Shutdown();
|
||||
void GetNetworkID(nsACString& aNetworkID);
|
||||
void GetIsLinkUp(bool* aIsUp);
|
||||
nsresult GetDnsSuffixList(nsTArray<nsCString>& aDnsSuffixList);
|
||||
|
||||
private:
|
||||
void EnqueueGenMsg(uint16_t aMsgType, uint8_t aFamily);
|
||||
@ -76,6 +77,7 @@ class NetlinkService : public nsIRunnable {
|
||||
int GetPollWait();
|
||||
bool CalculateIDForFamily(uint8_t aFamily, mozilla::SHA1Sum* aSHA1);
|
||||
void CalculateNetworkID();
|
||||
void ComputeDNSSuffixList();
|
||||
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
|
||||
@ -108,6 +110,7 @@ class NetlinkService : public nsIRunnable {
|
||||
mozilla::TimeStamp mTriggerTime;
|
||||
|
||||
nsCString mNetworkId;
|
||||
nsTArray<nsCString> mDNSSuffixList;
|
||||
|
||||
class LinkInfo {
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user