Backed out 2 changesets (bug 1937522) for causing build bustages @MockNetworkLayerController.h. CLOSED TREE
Backed out changeset 5e14601b04cc (bug 1937522) Backed out changeset 897b51f29229 (bug 1937522)
This commit is contained in:
@@ -14413,6 +14413,13 @@
|
||||
value: ""
|
||||
mirror: never
|
||||
|
||||
# This is only used for testing. When true, nsHttpChannel::mPeerAddr will be
|
||||
# overridden with the address provided by DNS prefetch.
|
||||
- name: network.dns.use_override_as_peer_address
|
||||
type: RelaxedAtomicBool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Whether to add additional record IPs to the cache
|
||||
- name: network.trr.add_additional_records
|
||||
type: RelaxedAtomicBool
|
||||
@@ -14630,13 +14637,6 @@
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Used for testing purposes only. When true, it attaches an extra networking
|
||||
# layer to simulate different network scenarios.
|
||||
- name: network.socket.attach_mock_network_layer
|
||||
type: RelaxedAtomicBool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Prefs starting with "nglayout."
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "MockNetworkLayer.h"
|
||||
#include "MockNetworkLayerController.h"
|
||||
#include "nsSocketTransportService2.h"
|
||||
#include "prmem.h"
|
||||
#include "prio.h"
|
||||
|
||||
namespace mozilla::net {
|
||||
|
||||
static PRDescIdentity sMockNetworkLayerIdentity;
|
||||
static PRIOMethods sMockNetworkLayeyMethods;
|
||||
static PRIOMethods* sMockNetworkLayeyMethodsPtr = nullptr;
|
||||
|
||||
// Not used for now.
|
||||
class MockNetworkSecret {
|
||||
public:
|
||||
MockNetworkSecret() = default;
|
||||
};
|
||||
|
||||
static PRStatus MockNetworkConnect(PRFileDesc* fd, const PRNetAddr* addr,
|
||||
PRIntervalTime to) {
|
||||
PRStatus status;
|
||||
mozilla::net::NetAddr netAddr(addr);
|
||||
MockNetworkSecret* secret = reinterpret_cast<MockNetworkSecret*>(fd->secret);
|
||||
nsAutoCString addrPort;
|
||||
netAddr.ToAddrPortString(addrPort);
|
||||
SOCKET_LOG(
|
||||
("MockNetworkConnect %p connect to [%s]\n", secret, addrPort.get()));
|
||||
mozilla::net::NetAddr redirected;
|
||||
if (FindNetAddrOverride(netAddr, redirected)) {
|
||||
redirected.ToAddrPortString(addrPort);
|
||||
SOCKET_LOG(
|
||||
("MockNetworkConnect %p redirect to [%s]\n", secret, addrPort.get()));
|
||||
PRNetAddr prAddr;
|
||||
NetAddrToPRNetAddr(&redirected, &prAddr);
|
||||
status = fd->lower->methods->connect(fd->lower, &prAddr, to);
|
||||
} else {
|
||||
status = fd->lower->methods->connect(fd->lower, addr, to);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static PRInt32 MockNetworkSend(PRFileDesc* fd, const void* buf, PRInt32 amount,
|
||||
PRIntn flags, PRIntervalTime timeout) {
|
||||
MOZ_RELEASE_ASSERT(fd->identity == sMockNetworkLayerIdentity);
|
||||
|
||||
MockNetworkSecret* secret = reinterpret_cast<MockNetworkSecret*>(fd->secret);
|
||||
SOCKET_LOG(("MockNetworkSend %p\n", secret));
|
||||
|
||||
PRInt32 rv =
|
||||
(fd->lower->methods->send)(fd->lower, buf, amount, flags, timeout);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static PRInt32 MockNetworkWrite(PRFileDesc* fd, const void* buf,
|
||||
PRInt32 amount) {
|
||||
return MockNetworkSend(fd, buf, amount, 0, PR_INTERVAL_NO_WAIT);
|
||||
}
|
||||
|
||||
static PRInt32 MockNetworkRecv(PRFileDesc* fd, void* buf, PRInt32 amount,
|
||||
PRIntn flags, PRIntervalTime timeout) {
|
||||
MOZ_RELEASE_ASSERT(fd->identity == sMockNetworkLayerIdentity);
|
||||
|
||||
MockNetworkSecret* secret = reinterpret_cast<MockNetworkSecret*>(fd->secret);
|
||||
SOCKET_LOG(("MockNetworkRecv %p\n", secret));
|
||||
|
||||
PRInt32 rv =
|
||||
(fd->lower->methods->recv)(fd->lower, buf, amount, flags, timeout);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static PRInt32 MockNetworkRead(PRFileDesc* fd, void* buf, PRInt32 amount) {
|
||||
return MockNetworkRecv(fd, buf, amount, 0, PR_INTERVAL_NO_WAIT);
|
||||
}
|
||||
|
||||
static PRStatus MockNetworkClose(PRFileDesc* fd) {
|
||||
if (!fd) {
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
PRFileDesc* layer = PR_PopIOLayer(fd, PR_TOP_IO_LAYER);
|
||||
|
||||
MOZ_RELEASE_ASSERT(layer && layer->identity == sMockNetworkLayerIdentity,
|
||||
"MockNetwork Layer not on top of stack");
|
||||
|
||||
MockNetworkSecret* secret =
|
||||
reinterpret_cast<MockNetworkSecret*>(layer->secret);
|
||||
SOCKET_LOG(("MockNetworkClose %p\n", secret));
|
||||
layer->secret = nullptr;
|
||||
layer->dtor(layer);
|
||||
delete secret;
|
||||
return fd->methods->close(fd);
|
||||
}
|
||||
|
||||
nsresult AttachMockNetworkLayer(PRFileDesc* fd) {
|
||||
if (!sMockNetworkLayeyMethodsPtr) {
|
||||
sMockNetworkLayerIdentity = PR_GetUniqueIdentity("MockNetwork Layer");
|
||||
sMockNetworkLayeyMethods = *PR_GetDefaultIOMethods();
|
||||
sMockNetworkLayeyMethods.connect = MockNetworkConnect;
|
||||
sMockNetworkLayeyMethods.send = MockNetworkSend;
|
||||
sMockNetworkLayeyMethods.write = MockNetworkWrite;
|
||||
sMockNetworkLayeyMethods.recv = MockNetworkRecv;
|
||||
sMockNetworkLayeyMethods.read = MockNetworkRead;
|
||||
sMockNetworkLayeyMethods.close = MockNetworkClose;
|
||||
sMockNetworkLayeyMethodsPtr = &sMockNetworkLayeyMethods;
|
||||
}
|
||||
|
||||
PRFileDesc* layer = PR_CreateIOLayerStub(sMockNetworkLayerIdentity,
|
||||
sMockNetworkLayeyMethodsPtr);
|
||||
|
||||
if (!layer) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
MockNetworkSecret* secret = new MockNetworkSecret();
|
||||
|
||||
layer->secret = reinterpret_cast<PRFilePrivate*>(secret);
|
||||
|
||||
PRStatus status = PR_PushIOLayer(fd, PR_NSPR_IO_LAYER, layer);
|
||||
|
||||
if (status == PR_FAILURE) {
|
||||
delete secret;
|
||||
PR_Free(layer); // PR_CreateIOLayerStub() uses PR_Malloc().
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::net
|
||||
@@ -1,20 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef MockNetworkLayer_h__
|
||||
#define MockNetworkLayer_h__
|
||||
|
||||
#include "prerror.h"
|
||||
#include "prio.h"
|
||||
#include "ErrorList.h"
|
||||
|
||||
namespace mozilla::net {
|
||||
|
||||
nsresult AttachMockNetworkLayer(PRFileDesc* fd);
|
||||
|
||||
} // namespace mozilla::net
|
||||
|
||||
#endif // MockNetworkLayer_h__
|
||||
@@ -1,96 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "MockNetworkLayerController.h"
|
||||
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/net/SocketProcessParent.h"
|
||||
#include "nsIOService.h"
|
||||
#include "nsNetAddr.h"
|
||||
|
||||
namespace mozilla::net {
|
||||
|
||||
static StaticRefPtr<MockNetworkLayerController> gController;
|
||||
|
||||
bool FindNetAddrOverride(const NetAddr& aInput, NetAddr& aOutput) {
|
||||
RefPtr<MockNetworkLayerController> controller = gController;
|
||||
if (!controller) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsAutoCString addrPort;
|
||||
aInput.ToAddrPortString(addrPort);
|
||||
AutoReadLock lock(controller->mLock);
|
||||
return controller->mNetAddrOverrides.Get(addrPort, &aOutput);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIMockNetworkLayerController>
|
||||
MockNetworkLayerController::GetSingleton() {
|
||||
if (gController) {
|
||||
return do_AddRef(gController);
|
||||
}
|
||||
|
||||
gController = new MockNetworkLayerController();
|
||||
ClearOnShutdown(&gController);
|
||||
return do_AddRef(gController);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(MockNetworkLayerController, nsIMockNetworkLayerController)
|
||||
|
||||
NS_IMETHODIMP MockNetworkLayerController::CreateScriptableNetAddr(
|
||||
const nsACString& aIP, uint16_t aPort, nsINetAddr** aResult) {
|
||||
NetAddr rawAddr;
|
||||
if (NS_FAILED(rawAddr.InitFromString(aIP))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
rawAddr.inet.port = PR_htons(aPort);
|
||||
|
||||
RefPtr<nsNetAddr> netaddr = new nsNetAddr(&rawAddr);
|
||||
netaddr.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MockNetworkLayerController::AddNetAddrOverride(nsINetAddr* aFrom,
|
||||
nsINetAddr* aTo) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
NetAddr fromAddr;
|
||||
aFrom->GetNetAddr(&fromAddr);
|
||||
NetAddr toAddr;
|
||||
aTo->GetNetAddr(&toAddr);
|
||||
nsAutoCString addrPort;
|
||||
fromAddr.ToAddrPortString(addrPort);
|
||||
{
|
||||
AutoWriteLock lock(mLock);
|
||||
mNetAddrOverrides.InsertOrUpdate(addrPort, toAddr);
|
||||
}
|
||||
if (nsIOService::UseSocketProcess()) {
|
||||
RefPtr<SocketProcessParent> parent = SocketProcessParent::GetSingleton();
|
||||
if (parent) {
|
||||
Unused << parent->SendAddNetAddrOverride(fromAddr, toAddr);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP MockNetworkLayerController::ClearNetAddrOverrides() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
{
|
||||
AutoWriteLock lock(mLock);
|
||||
mNetAddrOverrides.Clear();
|
||||
}
|
||||
if (nsIOService::UseSocketProcess()) {
|
||||
RefPtr<SocketProcessParent> parent = SocketProcessParent::GetSingleton();
|
||||
if (parent) {
|
||||
Unused << parent->SendClearNetAddrOverrides();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::net
|
||||
@@ -1,37 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef MockNetworkLayerController_h__
|
||||
#define MockNetworkLayerController_h__
|
||||
|
||||
#include "mozilla/RWLock.h"
|
||||
#include "nsIMockNetworkLayerController.h"
|
||||
|
||||
namespace mozilla::net {
|
||||
|
||||
bool FindNetAddrOverride(const NetAddr& aInput, NetAddr& aOutput);
|
||||
|
||||
class MockNetworkLayerController : public nsIMockNetworkLayerController {
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIMOCKNETWORKLAYERCONTROLLER
|
||||
|
||||
MockNetworkLayerController() = default;
|
||||
|
||||
static already_AddRefed<nsIMockNetworkLayerController> GetSingleton();
|
||||
|
||||
private:
|
||||
virtual ~MockNetworkLayerController() = default;
|
||||
mozilla::RWLock mLock{"MockNetworkLayerController::mLock"};
|
||||
|
||||
nsTHashMap<nsCStringHashKey, NetAddr> mNetAddrOverrides MOZ_GUARDED_BY(mLock);
|
||||
|
||||
friend bool FindNetAddrOverride(const NetAddr& aInput, NetAddr& aOutput);
|
||||
};
|
||||
|
||||
} // namespace mozilla::net
|
||||
|
||||
#endif // MockNetworkLayerController_h__
|
||||
@@ -54,7 +54,6 @@ XPIDL_SOURCES += [
|
||||
"nsILoadGroupChild.idl",
|
||||
"nsILoadInfo.idl",
|
||||
"nsIMIMEInputStream.idl",
|
||||
"nsIMockNetworkLayerController.idl",
|
||||
"nsIMultiPartChannel.idl",
|
||||
"nsINestedURI.idl",
|
||||
"nsINetAddr.idl",
|
||||
@@ -191,8 +190,6 @@ UNIFIED_SOURCES += [
|
||||
"LoadContextInfo.cpp",
|
||||
"LoadInfo.cpp",
|
||||
"MemoryDownloader.cpp",
|
||||
"MockNetworkLayer.cpp",
|
||||
"MockNetworkLayerController.cpp",
|
||||
"NetworkConnectivityService.cpp",
|
||||
"NetworkDataCountLayer.cpp",
|
||||
"nsAsyncRedirectVerifyHelper.cpp",
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsINetAddr;
|
||||
|
||||
[scriptable, builtinclass, uuid(8ef68853-dbea-4113-9dce-273b45d431c5)]
|
||||
interface nsIMockNetworkLayerController : nsISupports
|
||||
{
|
||||
|
||||
nsINetAddr createScriptableNetAddr(in AUTF8String aIP, in uint16_t aPort);
|
||||
|
||||
/**
|
||||
* Adds an override for this specific NetAddr.
|
||||
*/
|
||||
void addNetAddrOverride(in nsINetAddr aFrom, in nsINetAddr aTo);
|
||||
|
||||
/**
|
||||
* Clears all the NetAddr overrides that were previously set.
|
||||
*/
|
||||
void clearNetAddrOverrides();
|
||||
};
|
||||
@@ -242,7 +242,6 @@ static const char* gCallbackPrefsForSocketProcess[] = {
|
||||
"network.connectivity-service.",
|
||||
"network.captive-portal-service.testMode",
|
||||
"network.socket.ip_addr_any.disabled",
|
||||
"network.socket.attach_mock_network_layer",
|
||||
nullptr,
|
||||
};
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#include "nsSocketTransport2.h"
|
||||
|
||||
#include "MockNetworkLayer.h"
|
||||
#include "MockNetworkLayerController.h"
|
||||
#include "NSSErrorsService.h"
|
||||
#include "NetworkDataCountLayer.h"
|
||||
#include "QuicSocketControl.h"
|
||||
@@ -1233,19 +1231,6 @@ nsresult nsSocketTransport::BuildSocket(PRFileDesc*& fd, bool& proxyTransparent,
|
||||
return rv;
|
||||
}
|
||||
|
||||
static bool ShouldBlockAddress(const NetAddr& aAddr) {
|
||||
if (!xpc::AreNonLocalConnectionsDisabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NetAddr overrideAddr;
|
||||
bool hasOverride = FindNetAddrOverride(aAddr, overrideAddr);
|
||||
const NetAddr& addrToCheck = hasOverride ? overrideAddr : aAddr;
|
||||
|
||||
return !(addrToCheck.IsIPAddrAny() || addrToCheck.IsIPAddrLocal() ||
|
||||
addrToCheck.IsIPAddrShared() || addrToCheck.IsLoopbackAddr());
|
||||
}
|
||||
|
||||
nsresult nsSocketTransport::InitiateSocket() {
|
||||
SOCKET_LOG(("nsSocketTransport::InitiateSocket [this=%p]\n", this));
|
||||
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
|
||||
@@ -1287,7 +1272,9 @@ nsresult nsSocketTransport::InitiateSocket() {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NS_SUCCEEDED(mCondition) && ShouldBlockAddress(mNetAddr)) {
|
||||
if (NS_SUCCEEDED(mCondition) && xpc::AreNonLocalConnectionsDisabled() &&
|
||||
!(mNetAddr.IsIPAddrAny() || mNetAddr.IsIPAddrLocal() ||
|
||||
mNetAddr.IsIPAddrShared())) {
|
||||
nsAutoCString ipaddr;
|
||||
RefPtr<nsNetAddr> netaddr = new nsNetAddr(&mNetAddr);
|
||||
netaddr->GetAddress(ipaddr);
|
||||
@@ -1554,15 +1541,6 @@ nsresult nsSocketTransport::InitiateSocket() {
|
||||
this));
|
||||
}
|
||||
}
|
||||
if (StaticPrefs::network_socket_attach_mock_network_layer() &&
|
||||
xpc::AreNonLocalConnectionsDisabled()) {
|
||||
if (NS_FAILED(AttachMockNetworkLayer(fd))) {
|
||||
SOCKET_LOG(
|
||||
("nsSocketTransport::InitiateSocket "
|
||||
"AttachMockNetworkLayer failed [this=%p]\n",
|
||||
this));
|
||||
}
|
||||
}
|
||||
|
||||
bool connectCalled = true; // This is only needed for telemetry.
|
||||
status = PR_Connect(fd, &prAddr, NS_SOCKET_CONNECT_TIMEOUT);
|
||||
|
||||
@@ -768,15 +768,6 @@ Classes = [
|
||||
'categories': {'profile-after-change': 'SimpleURIUnknownSchemesRemoteObserver'},
|
||||
'processes': ProcessSelector.MAIN_PROCESS_ONLY,
|
||||
},
|
||||
{
|
||||
'cid': '{82b09188-8809-44c5-b41e-d8b85b8c2743}',
|
||||
'contract_ids': ['@mozilla.org/network/mock-network-controller;1'],
|
||||
'singleton': True,
|
||||
'type': 'nsIMockNetworkLayerController',
|
||||
'constructor': 'mozilla::net::MockNetworkLayerController::GetSingleton',
|
||||
'headers': ['/netwerk/base/MockNetworkLayerController.h'],
|
||||
'processes': ProcessSelector.ALLOW_IN_SOCKET_PROCESS,
|
||||
},
|
||||
]
|
||||
|
||||
if defined('NECKO_WIFI'):
|
||||
|
||||
@@ -148,12 +148,6 @@ nsCString NetAddr::ToString() const {
|
||||
return ""_ns;
|
||||
}
|
||||
|
||||
void NetAddr::ToAddrPortString(nsACString& aOutput) const {
|
||||
uint16_t port = 0;
|
||||
GetPort(&port);
|
||||
aOutput.Assign(nsPrintfCString("%s:%d", ToString().get(), port));
|
||||
}
|
||||
|
||||
bool NetAddr::IsLoopbackAddr() const {
|
||||
if (IsLoopBackAddressWithoutIPv6Mapping()) {
|
||||
return true;
|
||||
|
||||
@@ -154,7 +154,6 @@ union NetAddr {
|
||||
nsresult GetPort(uint16_t* aResult) const;
|
||||
bool ToStringBuffer(char* buf, uint32_t bufSize) const;
|
||||
nsCString ToString() const;
|
||||
void ToAddrPortString(nsACString& aOutput) const;
|
||||
};
|
||||
|
||||
enum class DNSResolverType : uint32_t { Native = 0, TRR };
|
||||
|
||||
@@ -44,7 +44,6 @@ using struct nsID from "nsID.h";
|
||||
using mozilla::net::SocketInfo from "mozilla/net/DashboardTypes.h";
|
||||
using mozilla::net::DNSCacheEntries from "mozilla/net/DashboardTypes.h";
|
||||
using mozilla::net::HttpRetParams from "mozilla/net/DashboardTypes.h";
|
||||
using mozilla::net::NetAddr from "mozilla/net/DNS.h";
|
||||
using nsIDNSService::DNSFlags from "nsIDNSService.h";
|
||||
|
||||
#if defined(XP_WIN)
|
||||
@@ -213,9 +212,6 @@ child:
|
||||
async UnblockUntrustedModulesThread();
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
async AddNetAddrOverride(NetAddr aFrom, NetAddr aTo);
|
||||
async ClearNetAddrOverrides();
|
||||
|
||||
both:
|
||||
async PDNSRequest(nsCString hostName, nsCString trrServer, int32_t port,
|
||||
uint16_t type, OriginAttributes originAttributes,
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "mozilla/StaticPrefs_javascript.h"
|
||||
#include "mozilla/StaticPrefs_network.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "MockNetworkLayerController.h"
|
||||
#include "NetworkConnectivityService.h"
|
||||
#include "nsDebugImpl.h"
|
||||
#include "nsHttpConnectionInfo.h"
|
||||
@@ -41,7 +40,6 @@
|
||||
#include "nsIDNSService.h"
|
||||
#include "nsIHttpActivityObserver.h"
|
||||
#include "nsIXULRuntime.h"
|
||||
#include "nsNetAddr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsNSSComponent.h"
|
||||
#include "nsSocketTransportService2.h"
|
||||
@@ -841,21 +839,5 @@ SocketProcessChild::GetIPCClientCertsActor() {
|
||||
return actor.forget();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult SocketProcessChild::RecvAddNetAddrOverride(
|
||||
const NetAddr& aFrom, const NetAddr& aTo) {
|
||||
nsCOMPtr<nsIMockNetworkLayerController> controller =
|
||||
MockNetworkLayerController::GetSingleton();
|
||||
RefPtr<nsNetAddr> from = new nsNetAddr(&aFrom);
|
||||
RefPtr<nsNetAddr> to = new nsNetAddr(&aTo);
|
||||
Unused << controller->AddNetAddrOverride(from, to);
|
||||
return IPC_OK();
|
||||
}
|
||||
mozilla::ipc::IPCResult SocketProcessChild::RecvClearNetAddrOverrides() {
|
||||
nsCOMPtr<nsIMockNetworkLayerController> controller =
|
||||
MockNetworkLayerController::GetSingleton();
|
||||
Unused << controller->ClearNetAddrOverrides();
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
@@ -156,10 +156,6 @@ class SocketProcessChild final : public PSocketProcessChild {
|
||||
already_AddRefed<psm::IPCClientCertsChild> GetIPCClientCertsActor();
|
||||
void CloseIPCClientCertsActor();
|
||||
|
||||
mozilla::ipc::IPCResult RecvAddNetAddrOverride(const NetAddr& aFrom,
|
||||
const NetAddr& aTo);
|
||||
mozilla::ipc::IPCResult RecvClearNetAddrOverrides();
|
||||
|
||||
protected:
|
||||
friend class SocketProcessImpl;
|
||||
~SocketProcessChild();
|
||||
|
||||
@@ -7955,11 +7955,14 @@ nsHttpChannel::OnStartRequest(nsIRequest* request) {
|
||||
|
||||
bool isTrr;
|
||||
bool echConfigUsed;
|
||||
mTransaction->GetNetworkAddresses(mSelfAddr, mPeerAddr, isTrr,
|
||||
mEffectiveTRRMode, mTRRSkipReason,
|
||||
echConfigUsed);
|
||||
StoreResolvedByTRR(isTrr);
|
||||
StoreEchConfigUsed(echConfigUsed);
|
||||
|
||||
if (!StaticPrefs::network_dns_use_override_as_peer_address()) {
|
||||
mTransaction->GetNetworkAddresses(mSelfAddr, mPeerAddr, isTrr,
|
||||
mEffectiveTRRMode, mTRRSkipReason,
|
||||
echConfigUsed);
|
||||
StoreResolvedByTRR(isTrr);
|
||||
StoreEchConfigUsed(echConfigUsed);
|
||||
}
|
||||
}
|
||||
|
||||
// don't enter this block if we're reading from the cache...
|
||||
@@ -8364,7 +8367,8 @@ static void RecordIPAddressSpaceTelemetry(bool aLoadSuccess, nsIURI* aURI,
|
||||
}
|
||||
|
||||
// if the load was not successful, then there is nothing to record here
|
||||
if (!aLoadSuccess) {
|
||||
if (!aLoadSuccess &&
|
||||
!StaticPrefs::network_dns_use_override_as_peer_address()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9284,14 +9288,17 @@ nsHttpChannel::OnTransportStatus(nsITransport* trans, nsresult status,
|
||||
bool isTrr = false;
|
||||
bool echConfigUsed = false;
|
||||
if (mTransaction) {
|
||||
mTransaction->GetNetworkAddresses(mSelfAddr, mPeerAddr, isTrr,
|
||||
mEffectiveTRRMode, mTRRSkipReason,
|
||||
echConfigUsed);
|
||||
|
||||
if (!StaticPrefs::network_dns_use_override_as_peer_address()) {
|
||||
mTransaction->GetNetworkAddresses(mSelfAddr, mPeerAddr, isTrr,
|
||||
mEffectiveTRRMode, mTRRSkipReason,
|
||||
echConfigUsed);
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsISocketTransport> socketTransport = do_QueryInterface(trans);
|
||||
if (socketTransport) {
|
||||
socketTransport->GetPeerAddr(&mPeerAddr);
|
||||
if (!StaticPrefs::network_dns_use_override_as_peer_address()) {
|
||||
socketTransport->GetPeerAddr(&mPeerAddr);
|
||||
}
|
||||
socketTransport->GetSelfAddr(&mSelfAddr);
|
||||
socketTransport->ResolvedByTRR(&isTrr);
|
||||
socketTransport->GetEffectiveTRRMode(&mEffectiveTRRMode);
|
||||
@@ -9841,6 +9848,15 @@ nsHttpChannel::OnLookupComplete(nsICancelable* request, nsIDNSRecord* rec,
|
||||
}
|
||||
}
|
||||
|
||||
if (StaticPrefs::network_dns_use_override_as_peer_address()) {
|
||||
nsTArray<NetAddr> addresses;
|
||||
nsCOMPtr<nsIDNSAddrRecord> record = do_QueryInterface(rec);
|
||||
Unused << record->GetAddresses(addresses);
|
||||
if (addresses.Length()) {
|
||||
mPeerAddr = addresses[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!mDNSBlockingPromise.IsEmpty()) {
|
||||
if (NS_SUCCEEDED(status)) {
|
||||
nsCOMPtr<nsIDNSRecord> record(rec);
|
||||
|
||||
@@ -3,12 +3,6 @@
|
||||
const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
|
||||
Ci.nsINativeDNSResolverOverride
|
||||
);
|
||||
const mockNetwork = Cc[
|
||||
"@mozilla.org/network/mock-network-controller;1"
|
||||
].getService(Ci.nsIMockNetworkLayerController);
|
||||
const certOverrideService = Cc[
|
||||
"@mozilla.org/security/certoverride;1"
|
||||
].getService(Ci.nsICertOverrideService);
|
||||
|
||||
const DOMAIN = "example.org";
|
||||
|
||||
@@ -25,37 +19,34 @@ function channelOpenPromise(chan, flags) {
|
||||
return new Promise(resolve => {
|
||||
function finish(req, buffer) {
|
||||
resolve([req, buffer]);
|
||||
certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
|
||||
false
|
||||
);
|
||||
}
|
||||
certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
|
||||
true
|
||||
);
|
||||
chan.asyncOpen(new ChannelListener(finish, null, flags));
|
||||
});
|
||||
}
|
||||
|
||||
let server;
|
||||
|
||||
add_setup(async function setup() {
|
||||
Services.prefs.setBoolPref("network.socket.attach_mock_network_layer", true);
|
||||
|
||||
Services.fog.initializeFOG();
|
||||
|
||||
server = new NodeHTTPServer();
|
||||
await server.start();
|
||||
registerCleanupFunction(async () => {
|
||||
Services.prefs.clearUserPref("network.disable-localhost-when-offline");
|
||||
Services.prefs.clearUserPref("network.dns.use_override_as_peer_address");
|
||||
Services.prefs.clearUserPref("dom.security.https_only_mode");
|
||||
Services.prefs.clearUserPref("dom.security.https_first");
|
||||
Services.prefs.clearUserPref("dom.security.https_first_schemeless");
|
||||
Services.prefs.clearUserPref("network.socket.attach_mock_network_layer");
|
||||
await server.stop();
|
||||
});
|
||||
});
|
||||
|
||||
function onBeforeConnect(callback) {
|
||||
Services.obs.addObserver(
|
||||
{
|
||||
observe(subject) {
|
||||
Services.obs.removeObserver(this, "http-on-before-connect");
|
||||
callback(subject.QueryInterface(Ci.nsIHttpChannel));
|
||||
},
|
||||
},
|
||||
"http-on-before-connect"
|
||||
);
|
||||
}
|
||||
|
||||
function verifyGleanValues(aDescription, aExpected) {
|
||||
info(aDescription);
|
||||
|
||||
@@ -81,30 +72,32 @@ function verifyGleanValues(aDescription, aExpected) {
|
||||
);
|
||||
}
|
||||
|
||||
async function do_test(ip, expected, srcPort, dstPort) {
|
||||
async function do_test(ip, expected) {
|
||||
// Need to set this pref, so SocketTransport will always return
|
||||
// NS_ERROR_OFFLINE instead of trying to connect to a local address.
|
||||
Services.prefs.setBoolPref("network.disable-localhost-when-offline", true);
|
||||
// Set this pref so that nsHttpChannel::mPeerAddr will be assigned to the
|
||||
// override address.
|
||||
Services.prefs.setBoolPref("network.dns.use_override_as_peer_address", true);
|
||||
|
||||
Services.fog.testResetFOG();
|
||||
|
||||
override.addIPOverride(DOMAIN, ip);
|
||||
let fromAddr = mockNetwork.createScriptableNetAddr(ip, srcPort ?? 80);
|
||||
let toAddr = mockNetwork.createScriptableNetAddr(
|
||||
fromAddr.family == Ci.nsINetAddr.FAMILY_INET ? "127.0.0.1" : "::1",
|
||||
dstPort ?? server.port()
|
||||
);
|
||||
|
||||
mockNetwork.addNetAddrOverride(fromAddr, toAddr);
|
||||
|
||||
let chan = makeChan(`http://${DOMAIN}`);
|
||||
let [req] = await channelOpenPromise(chan);
|
||||
info(
|
||||
"req.remoteAddress=" +
|
||||
req.QueryInterface(Ci.nsIHttpChannelInternal).remoteAddress
|
||||
);
|
||||
onBeforeConnect(chan => {
|
||||
chan.suspend();
|
||||
Promise.resolve().then(() => {
|
||||
Services.io.offline = true;
|
||||
chan.resume();
|
||||
});
|
||||
});
|
||||
|
||||
await channelOpenPromise(chan, CL_EXPECT_FAILURE);
|
||||
verifyGleanValues(`test ip=${ip}`, expected);
|
||||
|
||||
Services.dns.clearCache(false);
|
||||
override.clearOverrides();
|
||||
mockNetwork.clearNetAddrOverrides();
|
||||
Services.obs.notifyObservers(null, "net:prune-all-connections");
|
||||
Services.io.offline = false;
|
||||
}
|
||||
|
||||
add_task(async function test_ipv4_local() {
|
||||
@@ -131,10 +124,5 @@ add_task(async function test_http() {
|
||||
|
||||
add_task(async function test_https() {
|
||||
Services.prefs.setBoolPref("dom.security.https_only_mode", true);
|
||||
let httpsServer = new NodeHTTPSServer();
|
||||
await httpsServer.start();
|
||||
registerCleanupFunction(async () => {
|
||||
await httpsServer.stop();
|
||||
});
|
||||
await do_test("1.1.1.1", { loadIsHttps: 1 }, 443, httpsServer.port());
|
||||
await do_test("1.1.1.1", { loadIsHttps: 1 });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user