mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1361099 - provide a way to map all dns to constant r=valentin
// When non empty all non-localhost DNS queries (including IP addresses) // resolve to this value. The value can be a name or an IP address. // domains mapped to localhost with localDomains stay localhost. pref("network.dns.forceResolve", ""); Testing is the primary use case here - replay captive data on a 'fake server' by directing all traffic to it at the DNS level. Chrome has something similar. MozReview-Commit-ID: 7AOgQZpZKec --HG-- extra : rebase_source : ad2648a701fffecaae47cbfae17e7aa6badd50ee
This commit is contained in:
parent
87b3c001bf
commit
d1c557fcfe
@ -1918,6 +1918,11 @@ pref("network.dns.blockDotOnion", true);
|
||||
// These domains are treated as localhost equivalent
|
||||
pref("network.dns.localDomains", "");
|
||||
|
||||
// When non empty all non-localhost DNS queries (including IP addresses)
|
||||
// resolve to this value. The value can be a name or an IP address.
|
||||
// domains mapped to localhost with localDomains stay localhost.
|
||||
pref("network.dns.forceResolve", "");
|
||||
|
||||
// Contols whether or not "localhost" should resolve when offline
|
||||
pref("network.dns.offline-localhost", true);
|
||||
|
||||
|
@ -50,6 +50,7 @@ static const char kPrefDisableIPv6[] = "network.dns.disableIPv6";
|
||||
static const char kPrefDisablePrefetch[] = "network.dns.disablePrefetch";
|
||||
static const char kPrefBlockDotOnion[] = "network.dns.blockDotOnion";
|
||||
static const char kPrefDnsLocalDomains[] = "network.dns.localDomains";
|
||||
static const char kPrefDnsForceResolve[] = "network.dns.forceResolve";
|
||||
static const char kPrefDnsOfflineLocalhost[] = "network.dns.offline-localhost";
|
||||
static const char kPrefDnsNotifyResolution[] = "network.dns.notifyResolution";
|
||||
|
||||
@ -482,6 +483,7 @@ nsDNSService::nsDNSService()
|
||||
, mFirstTime(true)
|
||||
, mNotifyResolution(false)
|
||||
, mOfflineLocalhost(false)
|
||||
, mForceResolveOn(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -546,6 +548,7 @@ nsDNSService::Init()
|
||||
|
||||
nsAdoptingCString ipv4OnlyDomains;
|
||||
nsAdoptingCString localDomains;
|
||||
nsAdoptingCString forceResolve;
|
||||
|
||||
// read prefs
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
@ -562,6 +565,7 @@ nsDNSService::Init()
|
||||
prefs->GetBoolPref(kPrefDisableIPv6, &disableIPv6);
|
||||
prefs->GetCharPref(kPrefIPv4OnlyDomains, getter_Copies(ipv4OnlyDomains));
|
||||
prefs->GetCharPref(kPrefDnsLocalDomains, getter_Copies(localDomains));
|
||||
prefs->GetCharPref(kPrefDnsForceResolve, getter_Copies(forceResolve));
|
||||
prefs->GetBoolPref(kPrefDnsOfflineLocalhost, &offlineLocalhost);
|
||||
prefs->GetBoolPref(kPrefDisablePrefetch, &disablePrefetch);
|
||||
prefs->GetBoolPref(kPrefBlockDotOnion, &blockDotOnion);
|
||||
@ -579,6 +583,7 @@ nsDNSService::Init()
|
||||
prefs->AddObserver(kPrefDnsCacheGrace, this, false);
|
||||
prefs->AddObserver(kPrefIPv4OnlyDomains, this, false);
|
||||
prefs->AddObserver(kPrefDnsLocalDomains, this, false);
|
||||
prefs->AddObserver(kPrefDnsForceResolve, this, false);
|
||||
prefs->AddObserver(kPrefDisableIPv6, this, false);
|
||||
prefs->AddObserver(kPrefDnsOfflineLocalhost, this, false);
|
||||
prefs->AddObserver(kPrefDisablePrefetch, this, false);
|
||||
@ -616,6 +621,8 @@ nsDNSService::Init()
|
||||
mOfflineLocalhost = offlineLocalhost;
|
||||
mDisableIPv6 = disableIPv6;
|
||||
mBlockDotOnion = blockDotOnion;
|
||||
mForceResolve = forceResolve;
|
||||
mForceResolveOn = !mForceResolve.IsEmpty();
|
||||
|
||||
// Disable prefetching either by explicit preference or if a manual proxy is configured
|
||||
mDisablePrefetch = disablePrefetch || (proxyType == nsIProtocolProxyService::PROXYCONFIG_MANUAL);
|
||||
@ -706,6 +713,15 @@ nsDNSService::PreprocessHostname(bool aLocalDomain,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mForceResolveOn) {
|
||||
MutexAutoLock lock(mLock);
|
||||
if (!aInput.LowerCaseEqualsASCII("localhost") &&
|
||||
!aInput.LowerCaseEqualsASCII("127.0.0.1")) {
|
||||
aACE.Assign(mForceResolve);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (!aIDN || IsASCII(aInput)) {
|
||||
aACE = aInput;
|
||||
return NS_OK;
|
||||
|
@ -60,12 +60,14 @@ private:
|
||||
// IPv4 DNS lookups are performed. This allows the user to disable IPv6 on
|
||||
// a per-domain basis and work around broken DNS servers. See bug 68796.
|
||||
nsAdoptingCString mIPv4OnlyDomains;
|
||||
nsAdoptingCString mForceResolve;
|
||||
bool mDisableIPv6;
|
||||
bool mDisablePrefetch;
|
||||
bool mBlockDotOnion;
|
||||
bool mFirstTime;
|
||||
bool mNotifyResolution;
|
||||
bool mOfflineLocalhost;
|
||||
bool mForceResolveOn;
|
||||
nsTHashtable<nsCStringHashKey> mLocalDomains;
|
||||
};
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
|
||||
var nextTest;
|
||||
|
||||
var listener = {
|
||||
onLookupComplete: function(inRequest, inRecord, inStatus) {
|
||||
var answer = inRecord.getNextAddrAsString();
|
||||
do_check_true(answer == "127.0.0.1" || answer == "::1");
|
||||
|
||||
prefs.clearUserPref("network.dns.localDomains");
|
||||
|
||||
nextTest();
|
||||
do_test_finished();
|
||||
},
|
||||
QueryInterface: function(aIID) {
|
||||
@ -26,9 +27,25 @@ function run_test() {
|
||||
|
||||
var threadManager = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
var mainThread = threadManager.currentThread;
|
||||
nextTest = do_test_2;
|
||||
dns.asyncResolve("local.vingtetun.org", 0, listener,
|
||||
mainThread, defaultOriginAttributes);
|
||||
|
||||
do_test_pending();
|
||||
}
|
||||
|
||||
function do_test_2() {
|
||||
var threadManager = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
||||
var mainThread = threadManager.currentThread;
|
||||
nextTest = testsDone;
|
||||
prefs.setCharPref("network.dns.forceResolve", "localhost");
|
||||
dns.asyncResolve("www.example.com", 0, listener, mainThread, defaultOriginAttributes);
|
||||
|
||||
do_test_pending();
|
||||
}
|
||||
|
||||
function testsDone() {
|
||||
prefs.clearUserPref("network.dns.localDomains");
|
||||
prefs.clearUserPref("network.dns.forceResolve");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user