Skip to content

Commit

Permalink
More Refactoring of the QUIC Layer RX Packets (#3827)
Browse files Browse the repository at this point in the history
* More Refactoring of the QUIC Layer RX Packets

* clog

* Couple fixes
  • Loading branch information
nibanks committed Aug 24, 2023
1 parent 972e677 commit c885d5f
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 258 deletions.
174 changes: 77 additions & 97 deletions src/core/binding.c

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/core/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ typedef struct QUIC_RX_PACKET {

} QUIC_RX_PACKET;

#define GetQuicRxPacket(RecvData) ((QUIC_RX_PACKET*)RecvData)

typedef enum QUIC_BINDING_LOOKUP_TYPE {

QUIC_BINDING_LOOKUP_SINGLE, // Single connection
Expand Down Expand Up @@ -424,7 +422,7 @@ BOOLEAN
QuicBindingQueueStatelessOperation(
_In_ QUIC_BINDING* Binding,
_In_ QUIC_OPERATION_TYPE OperType,
_In_ CXPLAT_RECV_DATA* Datagram
_In_ QUIC_RX_PACKET* Packet
);

//
Expand Down
210 changes: 103 additions & 107 deletions src/core/connection.c

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/core/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ typedef struct QUIC_CONNECTION {
//
uint32_t ReceiveQueueCount;
uint32_t ReceiveQueueByteCount;
CXPLAT_RECV_DATA* ReceiveQueue;
CXPLAT_RECV_DATA** ReceiveQueueTail;
QUIC_RX_PACKET* ReceiveQueue;
QUIC_RX_PACKET** ReceiveQueueTail;
CXPLAT_DISPATCH_LOCK ReceiveQueueLock;

//
Expand Down Expand Up @@ -983,7 +983,7 @@ QUIC_STATUS
QuicConnAlloc(
_In_ QUIC_REGISTRATION* Registration,
_In_opt_ QUIC_WORKER* Worker,
_In_opt_ const CXPLAT_RECV_DATA* const Datagram,
_In_opt_ const QUIC_RX_PACKET* Packet,
_Outptr_ _At_(*NewConnection, __drv_allocatesMem(Mem))
QUIC_CONNECTION** NewConnection
);
Expand Down Expand Up @@ -1500,15 +1500,15 @@ QuicConnResetIdleTimeout(
);

//
// Queues a received UDP datagram chain to a connection for processing.
// Queues a received packet chain to a connection for processing.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicConnQueueRecvDatagrams(
QuicConnQueueRecvPackets(
_In_ QUIC_CONNECTION* Connection,
_In_ CXPLAT_RECV_DATA* DatagramChain,
_In_ uint32_t DatagramChainLength,
_In_ uint32_t DatagramChainByteLength
_In_ QUIC_RX_PACKET* Packets,
_In_ uint32_t PacketChainLength,
_In_ uint32_t PacketChainByteLength
);

//
Expand Down
4 changes: 2 additions & 2 deletions src/core/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -2163,13 +2163,13 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_WORKER*
QUIC_NO_SANITIZE("implicit-conversion")
QuicLibraryGetWorker(
_In_ const _In_ CXPLAT_RECV_DATA* Datagram
_In_ const QUIC_RX_PACKET* Packet
)
{
CXPLAT_DBG_ASSERT(MsQuicLib.StatelessRegistration != NULL);
return
&MsQuicLib.StatelessRegistration->WorkerPool->Workers[
Datagram->PartitionIndex % MsQuicLib.StatelessRegistration->WorkerPool->WorkerCount];
Packet->PartitionIndex % MsQuicLib.StatelessRegistration->WorkerPool->WorkerCount];
}

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down
2 changes: 1 addition & 1 deletion src/core/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ QuicLibraryOnListenerRegistered(
_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_WORKER*
QuicLibraryGetWorker(
_In_ const _In_ CXPLAT_RECV_DATA* Datagram
_In_ const QUIC_RX_PACKET* Packet
);

//
Expand Down
2 changes: 1 addition & 1 deletion src/core/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ typedef struct QUIC_STATELESS_CONTEXT {
QUIC_ADDR RemoteAddress;
CXPLAT_LIST_ENTRY ListEntry;
CXPLAT_HASHTABLE_ENTRY TableEntry;
CXPLAT_RECV_DATA* Datagram;
QUIC_RX_PACKET* Packet;
uint32_t CreationTimeMs;
uint8_t HasBindingRef : 1;
uint8_t IsProcessed : 1;
Expand Down
10 changes: 5 additions & 5 deletions src/core/packet_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ QuicPacketSpaceUninitialize(
//
// Release any pending packets back to the binding.
//
if (Packets->DeferredDatagrams != NULL) {
CXPLAT_RECV_DATA* Datagram = Packets->DeferredDatagrams;
if (Packets->DeferredPackets != NULL) {
QUIC_RX_PACKET* Packet = Packets->DeferredPackets;
do {
Datagram->QueuedOnConnection = FALSE;
} while ((Datagram = Datagram->Next) != NULL);
CxPlatRecvDataReturn(Packets->DeferredDatagrams);
Packet->QueuedOnConnection = FALSE;
} while ((Packet = (QUIC_RX_PACKET*)Packet->Next) != NULL);
CxPlatRecvDataReturn((CXPLAT_RECV_DATA*)Packets->DeferredPackets);
}

QuicAckTrackerUninitialize(&Packets->AckTracker);
Expand Down
9 changes: 4 additions & 5 deletions src/core/packet_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ typedef struct QUIC_PACKET_SPACE {
QUIC_ENCRYPT_LEVEL EncryptLevel;

//
// Numbers of entries in the DeferredDatagrams list.
// Numbers of entries in the DeferredPackets list.
//
uint8_t DeferredDatagramsCount;
uint8_t DeferredPacketsCount;

//
// The (expected) next packet number to receive. Used for decoding received
Expand All @@ -74,10 +74,9 @@ typedef struct QUIC_PACKET_SPACE {
QUIC_CONNECTION* Connection;

//
// List of received CXPLAT_RECV_DATAGRAMs that we don't have the key
// for yet.
// List of received packets that we don't have the key for yet.
//
CXPLAT_RECV_DATA* DeferredDatagrams;
QUIC_RX_PACKET* DeferredPackets;

//
// Information related to packets that have been received and need to be
Expand Down
16 changes: 8 additions & 8 deletions src/core/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ QuicConnGetPathByID(
_IRQL_requires_max_(PASSIVE_LEVEL)
_Ret_maybenull_
QUIC_PATH*
QuicConnGetPathForDatagram(
QuicConnGetPathForPacket(
_In_ QUIC_CONNECTION* Connection,
_In_ const CXPLAT_RECV_DATA* Datagram
_In_ const QUIC_RX_PACKET* Packet
)
{
for (uint8_t i = 0; i < Connection->PathsCount; ++i) {
if (!QuicAddrCompare(
&Datagram->Route->LocalAddress,
&Packet->Route->LocalAddress,
&Connection->Paths[i].Route.LocalAddress) ||
!QuicAddrCompare(
&Datagram->Route->RemoteAddress,
&Packet->Route->RemoteAddress,
&Connection->Paths[i].Route.RemoteAddress)) {
if (!Connection->State.HandshakeConfirmed) {
//
Expand All @@ -218,9 +218,9 @@ QuicConnGetPathForDatagram(
//
for (uint8_t i = Connection->PathsCount - 1; i > 0; i--) {
if (!Connection->Paths[i].IsActive
&& QuicAddrGetFamily(&Datagram->Route->RemoteAddress) == QuicAddrGetFamily(&Connection->Paths[i].Route.RemoteAddress)
&& QuicAddrCompareIp(&Datagram->Route->RemoteAddress, &Connection->Paths[i].Route.RemoteAddress)
&& QuicAddrCompare(&Datagram->Route->LocalAddress, &Connection->Paths[i].Route.LocalAddress)) {
&& QuicAddrGetFamily(&Packet->Route->RemoteAddress) == QuicAddrGetFamily(&Connection->Paths[i].Route.RemoteAddress)
&& QuicAddrCompareIp(&Packet->Route->RemoteAddress, &Connection->Paths[i].Route.RemoteAddress)
&& QuicAddrCompare(&Packet->Route->LocalAddress, &Connection->Paths[i].Route.LocalAddress)) {
QuicPathRemove(Connection, i);
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ QuicConnGetPathForDatagram(
Path->DestCid = Connection->Paths[0].DestCid; // TODO - Copy instead?
}
Path->Binding = Connection->Paths[0].Binding;
QuicCopyRouteInfo(&Path->Route, Datagram->Route);
QuicCopyRouteInfo(&Path->Route, Packet->Route);
QuicPathValidate(Path);

return Path;
Expand Down
4 changes: 2 additions & 2 deletions src/core/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ QuicConnGetPathByID(
_IRQL_requires_max_(PASSIVE_LEVEL)
_Ret_maybenull_
QUIC_PATH*
QuicConnGetPathForDatagram(
QuicConnGetPathForPacket(
_In_ QUIC_CONNECTION* Connection,
_In_ const CXPLAT_RECV_DATA* Datagram
_In_ const QUIC_RX_PACKET* Packet
);

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down
3 changes: 2 additions & 1 deletion src/core/quicdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef struct QUIC_CONNECTION QUIC_CONNECTION;
typedef struct QUIC_STREAM QUIC_STREAM;
typedef struct QUIC_PACKET_BUILDER QUIC_PACKET_BUILDER;
typedef struct QUIC_PATH QUIC_PATH;
typedef struct QUIC_RX_PACKET QUIC_RX_PACKET;

/*************************************************************
PROTOCOL CONSTANTS
Expand Down Expand Up @@ -522,7 +523,7 @@ CXPLAT_STATIC_ASSERT(
#define QUIC_DEFAULT_ENCRYPTION_OFFLOAD_ALLOWED FALSE

//
// The default settings for allowing Reliable Reset support.
// The default settings for allowing Reliable Reset support.
//
#define QUIC_DEFAULT_RELIABLE_RESET_ENABLED FALSE

Expand Down
3 changes: 1 addition & 2 deletions src/core/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ QuicWorkerQueueOperation(

if (Operation != NULL) {
const QUIC_BINDING* Binding = Operation->STATELESS.Context->Binding;
const QUIC_RX_PACKET* Packet =
GetQuicRxPacket(Operation->STATELESS.Context->Datagram);
const QUIC_RX_PACKET* Packet = Operation->STATELESS.Context->Packet;
QuicPacketLogDrop(Binding, Packet, "Worker operation limit reached");
QuicOperationFree(Worker, Operation);
} else if (WakeWorkerThread) {
Expand Down
16 changes: 8 additions & 8 deletions src/generated/linux/connection.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,9 +1121,9 @@ tracepoint(CLOG_CONNECTION_C, IndicatePeerCertificateReceived , arg1, arg3, arg4
QueueDatagrams,
Connection,
"Queuing %u UDP datagrams",
DatagramChainLength);
PacketChainLength);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = DatagramChainLength = arg3
// arg3 = arg3 = PacketChainLength = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_QueueDatagrams
#define _clog_4_ARGS_TRACE_QueueDatagrams(uniqueId, arg1, encoded_arg_string, arg3)\
Expand Down Expand Up @@ -1360,9 +1360,9 @@ tracepoint(CLOG_CONNECTION_C, UdpRecvBatch , arg1, arg3);\
UdpRecvDeferred,
Connection,
"Recv %u deferred UDP datagrams",
DatagramChainCount);
PacketChainCount);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = DatagramChainCount = arg3
// arg3 = arg3 = PacketChainCount = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_UdpRecvDeferred
#define _clog_4_ARGS_TRACE_UdpRecvDeferred(uniqueId, arg1, encoded_arg_string, arg3)\
Expand Down Expand Up @@ -2105,11 +2105,11 @@ tracepoint(CLOG_CONNECTION_C, ConnPacketRecv , arg2, arg3, arg4, arg5);\
ConnRecvUdpDatagrams,
"[conn][%p] Recv %u UDP datagrams, %u bytes",
Connection,
DatagramChainCount,
DatagramChainByteCount);
PacketChainCount,
PacketChainByteCount);
// arg2 = arg2 = Connection = arg2
// arg3 = arg3 = DatagramChainCount = arg3
// arg4 = arg4 = DatagramChainByteCount = arg4
// arg3 = arg3 = PacketChainCount = arg3
// arg4 = arg4 = PacketChainByteCount = arg4
----------------------------------------------------------*/
#ifndef _clog_5_ARGS_TRACE_ConnRecvUdpDatagrams
#define _clog_5_ARGS_TRACE_ConnRecvUdpDatagrams(uniqueId, encoded_arg_string, arg2, arg3, arg4)\
Expand Down
16 changes: 8 additions & 8 deletions src/generated/linux/connection.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -1222,9 +1222,9 @@ TRACEPOINT_EVENT(CLOG_CONNECTION_C, IndicatePeerCertificateReceived,
QueueDatagrams,
Connection,
"Queuing %u UDP datagrams",
DatagramChainLength);
PacketChainLength);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = DatagramChainLength = arg3
// arg3 = arg3 = PacketChainLength = arg3
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_CONNECTION_C, QueueDatagrams,
TP_ARGS(
Expand Down Expand Up @@ -1495,9 +1495,9 @@ TRACEPOINT_EVENT(CLOG_CONNECTION_C, UdpRecvBatch,
UdpRecvDeferred,
Connection,
"Recv %u deferred UDP datagrams",
DatagramChainCount);
PacketChainCount);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = DatagramChainCount = arg3
// arg3 = arg3 = PacketChainCount = arg3
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_CONNECTION_C, UdpRecvDeferred,
TP_ARGS(
Expand Down Expand Up @@ -2367,11 +2367,11 @@ TRACEPOINT_EVENT(CLOG_CONNECTION_C, ConnPacketRecv,
ConnRecvUdpDatagrams,
"[conn][%p] Recv %u UDP datagrams, %u bytes",
Connection,
DatagramChainCount,
DatagramChainByteCount);
PacketChainCount,
PacketChainByteCount);
// arg2 = arg2 = Connection = arg2
// arg3 = arg3 = DatagramChainCount = arg3
// arg4 = arg4 = DatagramChainByteCount = arg4
// arg3 = arg3 = PacketChainCount = arg3
// arg4 = arg4 = PacketChainByteCount = arg4
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_CONNECTION_C, ConnRecvUdpDatagrams,
TP_ARGS(
Expand Down

0 comments on commit c885d5f

Please sign in to comment.