Skip to content

Commit

Permalink
Merge branch 'main' into dev/daiki/unify_datapath_share
Browse files Browse the repository at this point in the history
  • Loading branch information
ami-GS committed Aug 24, 2023
2 parents 86a0e66 + 972e677 commit f78f2f1
Show file tree
Hide file tree
Showing 26 changed files with 596 additions and 755 deletions.
64 changes: 34 additions & 30 deletions src/core/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ QuicBindingCreateStatelessOperation(
}

if (Binding->StatelessOperCount >= (uint32_t)MsQuicLib.Settings.MaxBindingStatelessOperations) {
QuicPacketLogDrop(Binding, CxPlatDataPathRecvDataToRecvPacket(Datagram),
QuicPacketLogDrop(Binding, GetQuicRxPacket(Datagram),
"Max binding operations reached");
goto Exit;
}
Expand All @@ -694,7 +694,7 @@ QuicBindingCreateStatelessOperation(
CXPLAT_CONTAINING_RECORD(TableEntry, QUIC_STATELESS_CONTEXT, TableEntry);

if (QuicAddrCompare(&ExistingCtx->RemoteAddress, RemoteAddress)) {
QuicPacketLogDrop(Binding, CxPlatDataPathRecvDataToRecvPacket(Datagram),
QuicPacketLogDrop(Binding, GetQuicRxPacket(Datagram),
"Already in stateless oper table");
goto Exit;
}
Expand All @@ -710,7 +710,7 @@ QuicBindingCreateStatelessOperation(
StatelessCtx =
(QUIC_STATELESS_CONTEXT*)CxPlatPoolAlloc(&Worker->StatelessContextPool);
if (StatelessCtx == NULL) {
QuicPacketLogDrop(Binding, CxPlatDataPathRecvDataToRecvPacket(Datagram),
QuicPacketLogDrop(Binding, GetQuicRxPacket(Datagram),
"Alloc failure for stateless oper ctx");
goto Exit;
}
Expand Down Expand Up @@ -753,14 +753,14 @@ QuicBindingQueueStatelessOperation(
)
{
if (MsQuicLib.StatelessRegistration == NULL) {
QuicPacketLogDrop(Binding, CxPlatDataPathRecvDataToRecvPacket(Datagram),
QuicPacketLogDrop(Binding, GetQuicRxPacket(Datagram),
"NULL stateless registration");
return FALSE;
}

QUIC_WORKER* Worker = QuicLibraryGetWorker(Datagram);
if (QuicWorkerIsOverloaded(Worker)) {
QuicPacketLogDrop(Binding, CxPlatDataPathRecvDataToRecvPacket(Datagram),
QuicPacketLogDrop(Binding, GetQuicRxPacket(Datagram),
"Stateless worker overloaded (stateless oper)");
return FALSE;
}
Expand All @@ -780,7 +780,7 @@ QuicBindingQueueStatelessOperation(
sizeof(QUIC_OPERATION));
QuicPacketLogDrop(
Binding,
CxPlatDataPathRecvDataToRecvPacket(Datagram),
GetQuicRxPacket(Datagram),
"Alloc failure for stateless operation");
QuicBindingReleaseStatelessOperation(Context, FALSE);
return FALSE;
Expand All @@ -801,8 +801,7 @@ QuicBindingProcessStatelessOperation(
{
QUIC_BINDING* Binding = StatelessCtx->Binding;
CXPLAT_RECV_DATA* RecvDatagram = StatelessCtx->Datagram;
CXPLAT_RECV_PACKET* RecvPacket =
CxPlatDataPathRecvDataToRecvPacket(RecvDatagram);
QUIC_RX_PACKET* RecvPacket = GetQuicRxPacket(RecvDatagram);
QUIC_BUFFER* SendDatagram = NULL;

CXPLAT_DBG_ASSERT(RecvPacket->ValidatedHeaderInv);
Expand Down Expand Up @@ -893,7 +892,7 @@ QuicBindingProcessStatelessOperation(
SupportedVersions,
SupportedVersionsLength * sizeof(uint32_t));

CXPLAT_RECV_PACKET* Packet = CxPlatDataPathRecvDataToRecvPacket(RecvDatagram);
QUIC_RX_PACKET* Packet = GetQuicRxPacket(RecvDatagram);
Packet->ReleaseDeferred = FALSE;

QuicTraceLogVerbose(
Expand Down Expand Up @@ -922,11 +921,11 @@ QuicBindingProcessStatelessOperation(
PacketLength >>= 5; // Only drop 5 of the 8 bits of randomness.
PacketLength += QUIC_RECOMMENDED_STATELESS_RESET_PACKET_LENGTH;

if (PacketLength >= RecvPacket->BufferLength) {
if (PacketLength >= RecvPacket->AvailBufferLength) {
//
// Can't go over the recieve packet's length.
//
PacketLength = (uint8_t)RecvPacket->BufferLength - 1;
PacketLength = (uint8_t)RecvPacket->AvailBufferLength - 1;
}

if (PacketLength < QUIC_MIN_STATELESS_RESET_PACKET_LENGTH) {
Expand Down Expand Up @@ -1118,7 +1117,7 @@ QuicBindingQueueStatelessReset(
CXPLAT_DBG_ASSERT(!((QUIC_SHORT_HEADER_V1*)Datagram->Buffer)->IsLongHeader);

if (Datagram->BufferLength <= QUIC_MIN_STATELESS_RESET_PACKET_LENGTH) {
QuicPacketLogDrop(Binding, CxPlatDataPathRecvDataToRecvPacket(Datagram),
QuicPacketLogDrop(Binding, GetQuicRxPacket(Datagram),
"Packet too short for stateless reset");
return FALSE;
}
Expand All @@ -1129,7 +1128,7 @@ QuicBindingQueueStatelessReset(
// a connection ID. Without a connection ID, a stateless reset token
// cannot be generated.
//
QuicPacketLogDrop(Binding, CxPlatDataPathRecvDataToRecvPacket(Datagram),
QuicPacketLogDrop(Binding, GetQuicRxPacket(Datagram),
"No stateless reset on exclusive binding");
return FALSE;
}
Expand All @@ -1147,10 +1146,10 @@ QuicBindingPreprocessDatagram(
_Out_ BOOLEAN* ReleaseDatagram
)
{
CXPLAT_RECV_PACKET* Packet = CxPlatDataPathRecvDataToRecvPacket(Datagram);
CxPlatZeroMemory(&Packet->PacketNumber, sizeof(CXPLAT_RECV_PACKET) - sizeof(uint64_t));
Packet->Buffer = Datagram->Buffer;
Packet->BufferLength = Datagram->BufferLength;
QUIC_RX_PACKET* Packet = GetQuicRxPacket(Datagram);
CxPlatZeroMemory(&Packet->PacketNumber, sizeof(QUIC_RX_PACKET) - sizeof(uint64_t));
Packet->AvailBuffer = Datagram->Buffer;
Packet->AvailBufferLength = Datagram->BufferLength;
Packet->BufferFrom = Datagram->BufferFrom;

*ReleaseDatagram = TRUE;
Expand Down Expand Up @@ -1220,7 +1219,7 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
BOOLEAN
QuicBindingShouldRetryConnection(
_In_ const QUIC_BINDING* const Binding,
_In_ CXPLAT_RECV_PACKET* Packet,
_In_ QUIC_RX_PACKET* Packet,
_In_ uint16_t TokenLength,
_In_reads_(TokenLength)
const uint8_t* Token,
Expand Down Expand Up @@ -1270,7 +1269,7 @@ QuicBindingCreateConnection(
// QuicLookupAddRemoteHash.
//

CXPLAT_RECV_PACKET* Packet = CxPlatDataPathRecvDataToRecvPacket(Datagram);
QUIC_RX_PACKET* Packet = GetQuicRxPacket(Datagram);

//
// Pick a stateless worker to process the client hello and if successful,
Expand Down Expand Up @@ -1313,7 +1312,7 @@ QuicBindingCreateConnection(
//

if (!QuicLibraryTryAddRefBinding(Binding)) {
QuicPacketLogDrop(Binding, CxPlatDataPathRecvDataToRecvPacket(Datagram),
QuicPacketLogDrop(Binding, GetQuicRxPacket(Datagram),
"Clean up in progress");
goto Exit;
}
Expand Down Expand Up @@ -1415,7 +1414,7 @@ QuicBindingDropBlockedSourcePorts(
if (BlockedPorts[i] == SourcePort) {
QuicPacketLogDrop(
Binding,
CxPlatDataPathRecvDataToRecvPacket(Datagram),
GetQuicRxPacket(Datagram),
"Blocked source port");
return TRUE;
}
Expand All @@ -1439,8 +1438,7 @@ QuicBindingDeliverDatagrams(
_In_ uint32_t DatagramChainByteLength
)
{
CXPLAT_RECV_PACKET* Packet =
CxPlatDataPathRecvDataToRecvPacket(DatagramChain);
QUIC_RX_PACKET* Packet = GetQuicRxPacket(DatagramChain);
CXPLAT_DBG_ASSERT(Packet->ValidatedHeaderInv);

//
Expand Down Expand Up @@ -1655,13 +1653,20 @@ QuicBindingReceive(
DatagramChain = Datagram->Next;
Datagram->Next = NULL;

CXPLAT_RECV_PACKET* Packet =
CxPlatDataPathRecvDataToRecvPacket(Datagram);
CxPlatZeroMemory(Packet, sizeof(CXPLAT_RECV_PACKET));
QUIC_RX_PACKET* Packet = GetQuicRxPacket(Datagram);
Packet->PacketId =
PartitionShifted | InterlockedIncrement64((int64_t*)&QuicLibraryGetPerProc()->ReceivePacketId);
Packet->Buffer = Datagram->Buffer;
Packet->BufferLength = Datagram->BufferLength;
Packet->PacketNumber = 0;
Packet->AvailBuffer = Datagram->Buffer;
Packet->DestCid = NULL;
Packet->SourceCid = NULL;
Packet->AvailBufferLength = Datagram->BufferLength;
Packet->HeaderLength = 0;
Packet->PayloadLength = 0;
Packet->DestCidLen = 0;
Packet->SourceCidLen = 0;
Packet->KeyType = QUIC_PACKET_KEY_INITIAL;
Packet->Flags = 0;
Packet->BufferFrom = Datagram->BufferFrom;

CXPLAT_DBG_ASSERT(Packet->PacketId != 0);
Expand Down Expand Up @@ -1710,8 +1715,7 @@ QuicBindingReceive(
// the same connection and this chain-splitting step is skipped.)
//
if (!Binding->Exclusive && SubChain != NULL) {
CXPLAT_RECV_PACKET* SubChainPacket =
CxPlatDataPathRecvDataToRecvPacket(SubChain);
QUIC_RX_PACKET* SubChainPacket = GetQuicRxPacket(SubChain);
if ((Packet->DestCidLen != SubChainPacket->DestCidLen ||
memcmp(Packet->DestCid, SubChainPacket->DestCid, Packet->DestCidLen) != 0)) {
if (!QuicBindingDeliverDatagrams(Binding, SubChain, SubChainLength, SubChainBytes)) {
Expand Down
32 changes: 23 additions & 9 deletions src/core/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ typedef struct QUIC_TOKEN_CONTENTS {
//
// The per recv buffer context type.
//
typedef struct CXPLAT_RECV_PACKET {
typedef struct QUIC_RX_PACKET {

#ifdef __cplusplus
struct CXPLAT_RECV_DATA _;
#else
struct CXPLAT_RECV_DATA;
#endif

//
// The unique identifier for the packet.
Expand All @@ -44,8 +50,8 @@ typedef struct CXPLAT_RECV_PACKET {
// The current packet buffer.
//
union {
_Field_size_(BufferLength)
const uint8_t* Buffer;
_Field_size_(AvailBufferLength)
const uint8_t* AvailBuffer;
const struct QUIC_HEADER_INVARIANT* Invariant;
const struct QUIC_VERSION_NEGOTIATION_PACKET* VerNeg;
const struct QUIC_LONG_HEADER_V1* LH;
Expand All @@ -64,9 +70,9 @@ typedef struct CXPLAT_RECV_PACKET {
const uint8_t* SourceCid;

//
// Length of the Buffer array.
// Length of the AvailBuffer array.
//
uint16_t BufferLength;
uint16_t AvailBufferLength;

//
// Length of the current packet header.
Expand All @@ -89,6 +95,9 @@ typedef struct CXPLAT_RECV_PACKET {
//
QUIC_PACKET_KEY_TYPE KeyType;

union {
uint32_t Flags;
struct {
//
// Flag indicating we have found the connection the packet belongs to.
//
Expand Down Expand Up @@ -155,10 +164,15 @@ typedef struct CXPLAT_RECV_PACKET {
//
//
//
uint16_t BufferFrom : 2;
uint8_t BufferFrom : 2;

uint8_t Reserved : 2;
};
};

} QUIC_RX_PACKET;

uint16_t Reserved : 2;
} CXPLAT_RECV_PACKET;
#define GetQuicRxPacket(RecvData) ((QUIC_RX_PACKET*)RecvData)

typedef enum QUIC_BINDING_LOOKUP_TYPE {

Expand Down Expand Up @@ -461,7 +475,7 @@ inline
_IRQL_requires_max_(DISPATCH_LEVEL)
BOOLEAN
QuicRetryTokenDecrypt(
_In_ const CXPLAT_RECV_PACKET* const Packet,
_In_ const QUIC_RX_PACKET* const Packet,
_In_reads_(sizeof(QUIC_TOKEN_CONTENTS))
const uint8_t* TokenBuffer,
_Out_ QUIC_TOKEN_CONTENTS* Token
Expand Down
Loading

0 comments on commit f78f2f1

Please sign in to comment.