Skip to content

Commit

Permalink
merge winkernel and dummy datapath (#4650)
Browse files Browse the repository at this point in the history
* merge winkernel and dummy datapath

* fix

* flag to identify datapath

* trailing newline

* use common members

* cleanup

* change dp type naming

* fix type and refactoring

* fix

* assemble definition in same ifdef

* ending by newline
  • Loading branch information
ami-GS authored Nov 22, 2024
1 parent f6b6e01 commit c73f75a
Show file tree
Hide file tree
Showing 14 changed files with 650 additions and 681 deletions.
42 changes: 42 additions & 0 deletions src/generated/linux/datapath_winuser.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#define _clog_MACRO_QuicTraceLogVerbose 1
#define QuicTraceLogVerbose(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
#endif
#ifndef _clog_MACRO_QuicTraceLogError
#define _clog_MACRO_QuicTraceLogError 1
#define QuicTraceLogError(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
#endif
#ifndef _clog_MACRO_QuicTraceEvent
#define _clog_MACRO_QuicTraceEvent 1
#define QuicTraceEvent(a, ...) _clog_CAT(_clog_ARGN_SELECTOR(__VA_ARGS__), _clog_CAT(_,a(#a, __VA_ARGS__)))
Expand Down Expand Up @@ -251,6 +255,26 @@ tracepoint(CLOG_DATAPATH_WINUSER_C, DatapathTooLarge , arg2, arg3_len, arg3);\



/*----------------------------------------------------------
// Decoder Ring for DatapathResolveHostNameFailed
// [%p] Couldn't resolve hostname '%s' to an IP address
// QuicTraceLogError(
DatapathResolveHostNameFailed,
"[%p] Couldn't resolve hostname '%s' to an IP address",
Datapath,
HostName);
// arg2 = arg2 = Datapath = arg2
// arg3 = arg3 = HostName = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_DatapathResolveHostNameFailed
#define _clog_4_ARGS_TRACE_DatapathResolveHostNameFailed(uniqueId, encoded_arg_string, arg2, arg3)\
tracepoint(CLOG_DATAPATH_WINUSER_C, DatapathResolveHostNameFailed , arg2, arg3);\

#endif




/*----------------------------------------------------------
// Decoder Ring for LibraryErrorStatus
// [ lib] ERROR, %u, %s.
Expand Down Expand Up @@ -291,6 +315,24 @@ tracepoint(CLOG_DATAPATH_WINUSER_C, AllocFailure , arg2, arg3);\



/*----------------------------------------------------------
// Decoder Ring for LibraryError
// [ lib] ERROR, %s.
// QuicTraceEvent(
LibraryError,
"[ lib] ERROR, %s.",
"No local unicast addresses found");
// arg2 = arg2 = "No local unicast addresses found" = arg2
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_LibraryError
#define _clog_3_ARGS_TRACE_LibraryError(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_DATAPATH_WINUSER_C, LibraryError , arg2);\

#endif




/*----------------------------------------------------------
// Decoder Ring for DatapathErrorStatus
// [data][%p] ERROR, %u, %s.
Expand Down
42 changes: 42 additions & 0 deletions src/generated/linux/datapath_winuser.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,29 @@ TRACEPOINT_EVENT(CLOG_DATAPATH_WINUSER_C, DatapathTooLarge,



/*----------------------------------------------------------
// Decoder Ring for DatapathResolveHostNameFailed
// [%p] Couldn't resolve hostname '%s' to an IP address
// QuicTraceLogError(
DatapathResolveHostNameFailed,
"[%p] Couldn't resolve hostname '%s' to an IP address",
Datapath,
HostName);
// arg2 = arg2 = Datapath = arg2
// arg3 = arg3 = HostName = arg3
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_DATAPATH_WINUSER_C, DatapathResolveHostNameFailed,
TP_ARGS(
const void *, arg2,
const char *, arg3),
TP_FIELDS(
ctf_integer_hex(uint64_t, arg2, (uint64_t)arg2)
ctf_string(arg3, arg3)
)
)



/*----------------------------------------------------------
// Decoder Ring for LibraryErrorStatus
// [ lib] ERROR, %u, %s.
Expand Down Expand Up @@ -291,6 +314,25 @@ TRACEPOINT_EVENT(CLOG_DATAPATH_WINUSER_C, AllocFailure,



/*----------------------------------------------------------
// Decoder Ring for LibraryError
// [ lib] ERROR, %s.
// QuicTraceEvent(
LibraryError,
"[ lib] ERROR, %s.",
"No local unicast addresses found");
// arg2 = arg2 = "No local unicast addresses found" = arg2
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_DATAPATH_WINUSER_C, LibraryError,
TP_ARGS(
const char *, arg2),
TP_FIELDS(
ctf_string(arg2, arg2)
)
)



/*----------------------------------------------------------
// Decoder Ring for DatapathErrorStatus
// [data][%p] ERROR, %u, %s.
Expand Down
6 changes: 3 additions & 3 deletions src/platform/datapath_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,7 @@ CxPlatSocketContextRecvComplete(
RecvData->TypeOfService = TOS;
RecvData->HopLimitTTL = (uint8_t)HopLimitTTL;
RecvData->Allocated = TRUE;
RecvData->Route->DatapathType = RecvData->DatapathType = CXPLAT_DATAPATH_TYPE_USER;
RecvData->Route->DatapathType = RecvData->DatapathType = CXPLAT_DATAPATH_TYPE_NORMAL;
RecvData->QueuedOnConnection = FALSE;
RecvData->Reserved = FALSE;

Expand Down Expand Up @@ -2178,7 +2178,7 @@ CxPlatSocketReceiveTcpData(
Data->PartitionIndex = SocketContext->DatapathPartition->PartitionIndex;
Data->TypeOfService = 0;
Data->Allocated = TRUE;
Data->Route->DatapathType = Data->DatapathType = CXPLAT_DATAPATH_TYPE_USER;
Data->Route->DatapathType = Data->DatapathType = CXPLAT_DATAPATH_TYPE_NORMAL;
Data->QueuedOnConnection = FALSE;
IoBlock->RefCount++;
IoBlock = NULL;
Expand Down Expand Up @@ -2270,7 +2270,7 @@ SendDataAlloc(
!!(Socket->Datapath->Features & CXPLAT_DATAPATH_FEATURE_SEND_SEGMENTATION);
SendData->Iovs[0].iov_len = 0;
SendData->Iovs[0].iov_base = SendData->Buffer;
SendData->DatapathType = Config->Route->DatapathType = CXPLAT_DATAPATH_TYPE_USER;
SendData->DatapathType = Config->Route->DatapathType = CXPLAT_DATAPATH_TYPE_NORMAL;
}

return SendData;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/datapath_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ RawSocketDelete(
{
CxPlatDpRawPlumbRulesOnSocket(Socket, FALSE);
CxPlatRemoveSocket(&Socket->RawDatapath->SocketPool, Socket);
CxPlatRundownReleaseAndWait(&Socket->Rundown);
CxPlatRundownReleaseAndWait(&Socket->RawRundown);
if (Socket->PausedTcpSend) {
CxPlatDpRawTxFree(Socket->PausedTcpSend);
}
Expand Down Expand Up @@ -272,7 +272,7 @@ CxPlatDpRawRxEthernet(
CxPlatDpRawRxFree(PacketChain);
}

CxPlatRundownRelease(&Socket->Rundown);
CxPlatRundownRelease(&Socket->RawRundown);
} else {
CxPlatDpRawRxFree(PacketChain);
}
Expand Down
84 changes: 44 additions & 40 deletions src/platform/datapath_raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ CxPlatDpRawTxEnqueue(
typedef struct CXPLAT_SOCKET_RAW {

CXPLAT_HASHTABLE_ENTRY Entry;
CXPLAT_RUNDOWN_REF Rundown;
CXPLAT_RUNDOWN_REF RawRundown;
CXPLAT_DATAPATH_RAW* RawDatapath;
SOCKET AuxSocket;
BOOLEAN Wildcard; // Using a wildcard local address. Optimization
Expand Down Expand Up @@ -392,43 +392,6 @@ CxPlatFramingWriteHeaders(
#pragma pack(push)
#pragma pack(1)

typedef struct ETHERNET_HEADER {
uint8_t Destination[6];
uint8_t Source[6];
uint16_t Type;
uint8_t Data[0];
} ETHERNET_HEADER;

typedef struct IPV4_HEADER {
uint8_t VersionAndHeaderLength;
union {
uint8_t TypeOfServiceAndEcnField;
struct {
uint8_t EcnField : 2;
uint8_t TypeOfService : 6;
};
};
uint16_t TotalLength;
uint16_t Identification;
uint16_t FlagsAndFragmentOffset;
uint8_t TimeToLive;
uint8_t Protocol;
uint16_t HeaderChecksum;
uint8_t Source[4];
uint8_t Destination[4];
uint8_t Data[0];
} IPV4_HEADER;

typedef struct IPV6_HEADER {
uint32_t VersionClassEcnFlow;
uint16_t PayloadLength;
uint8_t NextHeader;
uint8_t HopLimit;
uint8_t Source[16];
uint8_t Destination[16];
uint8_t Data[0];
} IPV6_HEADER;

typedef struct IPV6_EXTENSION {
uint8_t NextHeader;
uint8_t Length;
Expand Down Expand Up @@ -474,11 +437,52 @@ typedef struct TCP_HEADER {
#define TH_CWR 0x80

#define IPV4_VERSION 4
#define IPV6_VERSION 6
#define IPV4_VERSION_BYTE (IPV4_VERSION << 4)
#define IPV4_DEFAULT_VERHLEN ((IPV4_VERSION_BYTE) | (sizeof(IPV4_HEADER) / sizeof(uint32_t)))

#define IP_DEFAULT_HOP_LIMIT 128

#ifndef _KERNEL_MODE
typedef struct ETHERNET_HEADER {
uint8_t Destination[6];
uint8_t Source[6];
uint16_t Type;
uint8_t Data[0];
} ETHERNET_HEADER;

typedef struct IPV4_HEADER {
uint8_t VersionAndHeaderLength;
union {
uint8_t TypeOfServiceAndEcnField;
struct {
uint8_t EcnField : 2;
uint8_t TypeOfService : 6;
};
};
uint16_t TotalLength;
uint16_t Identification;
uint16_t FlagsAndFragmentOffset;
uint8_t TimeToLive;
uint8_t Protocol;
uint16_t HeaderChecksum;
uint8_t Source[4];
uint8_t Destination[4];
uint8_t Data[0];
} IPV4_HEADER;

typedef struct IPV6_HEADER {
uint32_t VersionClassEcnFlow;
uint16_t PayloadLength;
uint8_t NextHeader;
uint8_t HopLimit;
uint8_t Source[16];
uint8_t Destination[16];
uint8_t Data[0];
} IPV6_HEADER;

#define IPV6_VERSION 6
#define IPV4_DEFAULT_VERHLEN ((IPV4_VERSION_BYTE) | (sizeof(IPV4_HEADER) / sizeof(uint32_t)))

#define ETHERNET_TYPE_IPV4 0x0008
#define ETHERNET_TYPE_IPV6 0xdd86

#endif
4 changes: 2 additions & 2 deletions src/platform/datapath_raw_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ RawSocketCreateUdp(
{
QUIC_STATUS Status = QUIC_STATUS_SUCCESS;

CxPlatRundownInitialize(&NewSocket->Rundown);
CxPlatRundownInitialize(&NewSocket->RawRundown);
NewSocket->RawDatapath = Raw;
NewSocket->CibirIdLength = Config->CibirIdLength;
NewSocket->CibirIdOffsetSrc = Config->CibirIdOffsetSrc;
Expand Down Expand Up @@ -169,7 +169,7 @@ RawSocketCreateUdp(

if (QUIC_FAILED(Status)) {
if (NewSocket != NULL) {
CxPlatRundownUninitialize(&NewSocket->Rundown);
CxPlatRundownUninitialize(&NewSocket->RawRundown);
CxPlatZeroMemory(NewSocket, sizeof(CXPLAT_SOCKET_RAW) - sizeof(CXPLAT_SOCKET));
NewSocket = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/datapath_raw_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ CxPlatGetSocket(
while (Entry != NULL) {
CXPLAT_SOCKET_RAW* Temp = CXPLAT_CONTAINING_RECORD(Entry, CXPLAT_SOCKET_RAW, Entry);
if (CxPlatSocketCompare(Temp, LocalAddress, RemoteAddress)) {
if (CxPlatRundownAcquire(&Temp->Rundown)) {
if (CxPlatRundownAcquire(&Temp->RawRundown)) {
Socket = Temp;
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/datapath_raw_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ RawSocketCreateUdp(
CXPLAT_DBG_ASSERT(Socket != NULL);
QUIC_STATUS Status = QUIC_STATUS_SUCCESS;

CxPlatRundownInitialize(&Socket->Rundown);
CxPlatRundownInitialize(&Socket->RawRundown);
Socket->RawDatapath = Raw;
Socket->CibirIdLength = Config->CibirIdLength;
Socket->CibirIdOffsetSrc = Config->CibirIdOffsetSrc;
Expand Down Expand Up @@ -167,7 +167,7 @@ RawSocketCreateUdp(

if (QUIC_FAILED(Status)) {
if (Socket != NULL) {
CxPlatRundownUninitialize(&Socket->Rundown);
CxPlatRundownUninitialize(&Socket->RawRundown);
CxPlatZeroMemory(Socket, sizeof(CXPLAT_SOCKET_RAW) - sizeof(CXPLAT_SOCKET));
Socket = NULL;
}
Expand Down
Loading

0 comments on commit c73f75a

Please sign in to comment.