Skip to content

Commit

Permalink
Merge pull request #3682 from microsoft/huanyi/2.2.2-backports
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Banks <[email protected]>
  • Loading branch information
nibanks authored Jun 9, 2023
2 parents 1295f72 + b540137 commit 901ea13
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 83 deletions.
16 changes: 1 addition & 15 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,7 @@ jobs:
- name: Harden Runner
uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
azure.archive.ubuntu.com:80
crates.io:443
dc.services.visualstudio.com:443
github.com:443
launchpad.net:443
packages.microsoft.com:443
ppa.launchpad.net:80
rubygems.org:443
sh.rustup.rs:443
static.crates.io:443
static.rust-lang.org:443
www.cloudflare.com:443
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- name: Prepare Machine
Expand Down
16 changes: 1 addition & 15 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,7 @@ jobs:
- name: Harden Runner
uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
auth.docker.io:443
boringssl.googlesource.com:443
ghcr.io:443
github.com:443
pkg-containers.githubusercontent.com:443
production.cloudflare.docker.com:443
registry-1.docker.io:443
archive.ubuntu.com:80
security.ubuntu.com:80
packages.microsoft.com:443
api.nuget.org:443
dc.services.visualstudio.com:443
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
with:
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/test-down-level.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ jobs:
- name: Harden Runner
uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f
with:
egress-policy: block
allowed-endpoints: >
api.nuget.org:443
azure.archive.ubuntu.com:80
dc.services.visualstudio.com:443
github.com:443
launchpad.net:443
objects.githubusercontent.com:443
packages.microsoft.com:443
ppa.launchpad.net:80
rubygems.org:443
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
with:
Expand Down
2 changes: 2 additions & 0 deletions scripts/make-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ if [ "$OS" == "linux" ]; then
--name ${NAME} \
--provides ${NAME} \
--depends "libcrypto.so.${TLSVERSION}()(${BITS})" \
--depends "libnuma.so.1()(${BITS})" \
--conflicts ${CONFLICTS} \
--version ${VER_MAJOR}.${VER_MINOR}.${VER_PATCH} \
--description "${DESCRIPTION}" \
Expand Down Expand Up @@ -182,6 +183,7 @@ if [ "$OS" == "linux" ]; then
--provides ${NAME} \
--conflicts ${CONFLICTS} \
--depends "libssl${TLSVERSION}" \
--depends "libnuma1" \
--version ${VER_MAJOR}.${VER_MINOR}.${VER_PATCH} \
--description "${DESCRIPTION}" \
--vendor "${VENDOR}" \
Expand Down
3 changes: 3 additions & 0 deletions src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ if(BUILD_SHARED_LIBS)
set_target_properties(msquic PROPERTIES OUTPUT_NAME ${QUIC_LIBRARY_NAME})
if (NOT WIN32)
set_target_properties(msquic PROPERTIES SOVERSION ${QUIC_MAJOR_VERSION} VERSION ${QUIC_FULL_VERSION})
else()
# Configure linker to only load from the system directory.
set_target_properties(msquic PROPERTIES LINK_FLAGS "/DEPENDENTLOADFLAG:0x800")
endif()
else()
add_library(msquic_static STATIC static/empty.c)
Expand Down
2 changes: 1 addition & 1 deletion src/core/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ QuicBindingReceive(
// connection it was delivered to.
//

uint32_t Proc = CxPlatProcCurrentNumber();
uint16_t Proc = QuicLibraryGetCurrentPartition();
uint64_t ProcShifted = ((uint64_t)Proc + 1) << 40;

CXPLAT_RECV_DATA* Datagram;
Expand Down
22 changes: 11 additions & 11 deletions src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ QuicConnAlloc(
)
{
BOOLEAN IsServer = Datagram != NULL;
uint32_t CurProcIndex = CxPlatProcCurrentNumber();
uint16_t CurProcIndex = QuicLibraryGetCurrentPartition();
*NewConnection = NULL;
QUIC_STATUS Status;

Expand Down Expand Up @@ -402,7 +402,7 @@ QuicConnFree(
if (Connection->HandshakeTP != NULL) {
QuicCryptoTlsCleanupTransportParameters(Connection->HandshakeTP);
CxPlatPoolFree(
&MsQuicLib.PerProc[CxPlatProcCurrentNumber()].TransportParamPool,
&QuicLibraryGetPerProc()->TransportParamPool,
Connection->HandshakeTP);
Connection->HandshakeTP = NULL;
}
Expand All @@ -423,7 +423,7 @@ QuicConnFree(
"[conn][%p] Destroyed",
Connection);
CxPlatPoolFree(
&MsQuicLib.PerProc[CxPlatProcCurrentNumber()].ConnectionPool,
&QuicLibraryGetPerProc()->ConnectionPool,
Connection);

#if DEBUG
Expand Down Expand Up @@ -1539,6 +1539,12 @@ QuicConnTryClose(
return;
}

if (ClosedRemotely) {
Connection->State.ClosedRemotely = TRUE;
} else {
Connection->State.ClosedLocally = TRUE;
}

if (!ClosedRemotely) {

if ((Flags & QUIC_CLOSE_APPLICATION) &&
Expand Down Expand Up @@ -1654,12 +1660,6 @@ QuicConnTryClose(
IsFirstCloseForConnection = FALSE;
}

if (ClosedRemotely) {
Connection->State.ClosedRemotely = TRUE;
} else {
Connection->State.ClosedLocally = TRUE;
}

if (IsFirstCloseForConnection) {
//
// Default to the timed out state.
Expand Down Expand Up @@ -2283,7 +2283,7 @@ QuicConnCleanupServerResumptionState(
if (Connection->HandshakeTP != NULL) {
QuicCryptoTlsCleanupTransportParameters(Connection->HandshakeTP);
CxPlatPoolFree(
&MsQuicLib.PerProc[CxPlatProcCurrentNumber()].TransportParamPool,
&MsQuicLib.PerProc[QuicLibraryGetCurrentPartition()].TransportParamPool,
Connection->HandshakeTP);
Connection->HandshakeTP = NULL;
}
Expand Down Expand Up @@ -7185,7 +7185,7 @@ QuicConnApplyNewSettings(
Connection->HandshakeTP == NULL) {
CXPLAT_DBG_ASSERT(!Connection->State.Started);
Connection->HandshakeTP =
CxPlatPoolAlloc(&MsQuicLib.PerProc[CxPlatProcCurrentNumber()].TransportParamPool);
CxPlatPoolAlloc(&QuicLibraryGetPerProc()->TransportParamPool);
if (Connection->HandshakeTP == NULL) {
QuicTraceEvent(
AllocFailure,
Expand Down
5 changes: 5 additions & 0 deletions src/core/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ QuicLibraryGetCurrentPartition(
void
);

QUIC_LIBRARY_PP*
QuicLibraryGetPerProc(
void
);

_IRQL_requires_max_(DISPATCH_LEVEL)
uint16_t
QuicPartitionIdCreate(
Expand Down
8 changes: 4 additions & 4 deletions src/core/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -2319,16 +2319,16 @@ QuicLibraryGenerateStatelessResetToken(
)
{
uint8_t HashOutput[CXPLAT_HASH_SHA256_SIZE];
uint32_t CurProcIndex = CxPlatProcCurrentNumber();
CxPlatLockAcquire(&MsQuicLib.PerProc[CurProcIndex].ResetTokenLock);
QUIC_LIBRARY_PP* PerProc = QuicLibraryGetPerProc();
CxPlatLockAcquire(&PerProc->ResetTokenLock);
QUIC_STATUS Status =
CxPlatHashCompute(
MsQuicLib.PerProc[CurProcIndex].ResetTokenHash,
PerProc->ResetTokenHash,
CID,
MsQuicLib.CidTotalLength,
sizeof(HashOutput),
HashOutput);
CxPlatLockRelease(&MsQuicLib.PerProc[CurProcIndex].ResetTokenLock);
CxPlatLockRelease(&PerProc->ResetTokenLock);
if (QUIC_SUCCEEDED(Status)) {
CxPlatCopyMemory(
ResetToken,
Expand Down
14 changes: 11 additions & 3 deletions src/core/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ QuicLibraryGetCurrentPartition(
return ((uint16_t)CxPlatProcCurrentNumber()) % MsQuicLib.PartitionCount;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
inline
QUIC_LIBRARY_PP*
QuicLibraryGetPerProc(
void
)
{
return &MsQuicLib.PerProc[QuicLibraryGetCurrentPartition()];
}

_IRQL_requires_max_(DISPATCH_LEVEL)
inline
uint16_t
Expand Down Expand Up @@ -366,9 +376,7 @@ QuicPerfCounterAdd(
)
{
CXPLAT_DBG_ASSERT(Type >= 0 && Type < QUIC_PERF_COUNTER_MAX);
uint32_t ProcIndex = CxPlatProcCurrentNumber();
CXPLAT_DBG_ASSERT(ProcIndex < (uint32_t)MsQuicLib.PartitionCount);
InterlockedExchangeAdd64(&(MsQuicLib.PerProc[ProcIndex].PerfCounters[Type]), Value);
InterlockedExchangeAdd64(&(QuicLibraryGetPerProc()->PerfCounters[Type]), Value);
}

#define QuicPerfCounterIncrement(Type) QuicPerfCounterAdd(Type, 1)
Expand Down
2 changes: 1 addition & 1 deletion src/core/packet_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ QuicPacketBuilderPrepare(
// the current one doesn't match, finalize it and then start a new one.
//

uint32_t Proc = CxPlatProcCurrentNumber();
uint16_t Proc = QuicLibraryGetCurrentPartition();
uint64_t ProcShifted = ((uint64_t)Proc + 1) << 40;

BOOLEAN NewQuicPacket = FALSE;
Expand Down
7 changes: 2 additions & 5 deletions src/core/packet_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ QuicPacketSpaceInitialize(
_Out_ QUIC_PACKET_SPACE** NewPackets
)
{
uint32_t CurProcIndex = CxPlatProcCurrentNumber();
QUIC_PACKET_SPACE* Packets = CxPlatPoolAlloc(&MsQuicLib.PerProc[CurProcIndex].PacketSpacePool);
QUIC_PACKET_SPACE* Packets = CxPlatPoolAlloc(&QuicLibraryGetPerProc()->PacketSpacePool);
if (Packets == NULL) {
QuicTraceEvent(
AllocFailure,
Expand Down Expand Up @@ -62,9 +61,7 @@ QuicPacketSpaceUninitialize(
}

QuicAckTrackerUninitialize(&Packets->AckTracker);

uint32_t CurProcIndex = CxPlatProcCurrentNumber();
CxPlatPoolFree(&MsQuicLib.PerProc[CurProcIndex].PacketSpacePool, Packets);
CxPlatPoolFree(&QuicLibraryGetPerProc()->PacketSpacePool, Packets);
}

_IRQL_requires_max_(DISPATCH_LEVEL)
Expand Down
31 changes: 16 additions & 15 deletions src/core/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,17 @@ QuicStreamFree(
QUIC_CONNECTION* Connection = Stream->Connection;
QUIC_WORKER* Worker = Connection->Worker;

CXPLAT_TEL_ASSERT(Stream->RefCount == 0);
CXPLAT_TEL_ASSERT(Connection->State.ClosedLocally || Stream->Flags.ShutdownComplete);
CXPLAT_TEL_ASSERT(Connection->State.ClosedLocally || Stream->Flags.HandleClosed);
CXPLAT_TEL_ASSERT(Stream->ClosedLink.Flink == NULL);
CXPLAT_TEL_ASSERT(Stream->SendLink.Flink == NULL);
CXPLAT_DBG_ASSERT(Stream->RefCount == 0);
CXPLAT_DBG_ASSERT(Connection->State.ClosedLocally || Stream->Flags.ShutdownComplete);
CXPLAT_DBG_ASSERT(Connection->State.ClosedLocally || Stream->Flags.HandleClosed);
CXPLAT_DBG_ASSERT(!Stream->Flags.InStreamTable);
CXPLAT_DBG_ASSERT(Stream->ClosedLink.Flink == NULL);
CXPLAT_DBG_ASSERT(Stream->SendLink.Flink == NULL);

Stream->Flags.Uninitialized = TRUE;

CXPLAT_TEL_ASSERT(Stream->ApiSendRequests == NULL);
CXPLAT_TEL_ASSERT(Stream->SendRequests == NULL);
CXPLAT_DBG_ASSERT(Stream->ApiSendRequests == NULL);
CXPLAT_DBG_ASSERT(Stream->SendRequests == NULL);

#if DEBUG
CxPlatDispatchLockAcquire(&Connection->Streams.AllStreamsLock);
Expand Down Expand Up @@ -376,14 +377,14 @@ QuicStreamClose(
QUIC_STREAM_SHUTDOWN_FLAG_IMMEDIATE,
QUIC_ERROR_NO_ERROR);

if (!Stream->Flags.Started) {
//
// The stream was abandoned before it could be successfully
// started. Just mark it as completing the shutdown process now
// since nothing else can be done with it now.
//
Stream->Flags.ShutdownComplete = TRUE;
}
if (!Stream->Flags.Started) {
//
// The stream was abandoned before it could be successfully
// started. Just mark it as completing the shutdown process now
// since nothing else can be done with it now.
//
Stream->Flags.ShutdownComplete = TRUE;
}
}

Stream->ClientCallbackHandler = NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/core/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ typedef union QUIC_STREAM_FLAGS {
BOOLEAN ShutdownComplete : 1; // Both directions have been shutdown and acknowledged.
BOOLEAN Uninitialized : 1; // Uninitialize started/completed. Used for Debugging.
BOOLEAN Freed : 1; // Freed after last ref count released. Used for Debugging.

BOOLEAN InStreamTable : 1; // The stream is currently in the connection's table.
};
} QUIC_STREAM_FLAGS;

Expand Down
6 changes: 6 additions & 0 deletions src/core/stream_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ QuicStreamSetInsertStream(
return FALSE;
}
}
Stream->Flags.InStreamTable = TRUE;
CxPlatHashtableInsert(
StreamSet->StreamTable,
&Stream->TableEntry,
Expand Down Expand Up @@ -177,6 +178,11 @@ QuicStreamSetReleaseStream(
_In_ QUIC_STREAM* Stream
)
{
if (!Stream->Flags.InStreamTable) {
return;
}
Stream->Flags.InStreamTable = FALSE;

//
// Remove the stream from the list of open streams.
//
Expand Down
2 changes: 1 addition & 1 deletion src/platform/datapath_raw_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,13 @@ CxPlatDpRawInitialize(
QUIC_STATUS Status;
const uint16_t* ProcessorList;

CxPlatListInitializeHead(&Xdp->Interfaces);
if (QUIC_FAILED(XdpOpenApi(XDP_VERSION_PRERELEASE, &Xdp->XdpApi))) {
Status = QUIC_STATUS_NOT_SUPPORTED;
goto Error;
}

CxPlatXdpReadConfig(Xdp);
CxPlatListInitializeHead(&Xdp->Interfaces);
Xdp->PollingIdleTimeoutUs = Config ? Config->PollingIdleTimeoutUs : 0;

if (Config && Config->ProcessorCount) {
Expand Down
17 changes: 17 additions & 0 deletions src/platform/tls_schannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,23 @@ CxPlatTlsWriteDataToSchannel(
&TlsContext->SchannelContext,
SECPKG_ATTR_SERIALIZED_REMOTE_CERT_CONTEXT_INPROC,
(PVOID)&(PeerCertBlob.Serialized));
#ifdef _KERNEL_MODE
if (SecStatus != SEC_E_OK) {
//
// In certain container scenarios it is possible that a
// newer kernel is matched with an older user mode schannel
// that doesn't support the newer "in proc" version of the
// remote cert context, so we always fallback and try the
// out of proc version when we encounter an error.
//
PeerCertBlob.Type = QUIC_CERT_BLOB_CHAIN;
SecStatus =
QueryContextAttributesW(
&TlsContext->SchannelContext,
SECPKG_ATTR_REMOTE_CERTIFICATES,
(PVOID)&PeerCertBlob.Chain);
}
#endif
} else {
#ifdef _KERNEL_MODE
PeerCertBlob.Type = QUIC_CERT_BLOB_CHAIN;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/dbg/quictypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ typedef union QUIC_STREAM_FLAGS {
BOOLEAN ShutdownComplete : 1; // Both directions have been shutdown and acknowledged.
BOOLEAN Uninitialized : 1; // Uninitialize started/completed. Used for Debugging.
BOOLEAN Freed : 1; // Freed after last ref count released. Used for Debugging.

BOOLEAN InStreamTable : 1; // The stream is currently in the connection's table.
};
} QUIC_STREAM_FLAGS;

Expand Down
Loading

0 comments on commit 901ea13

Please sign in to comment.