Skip to content

Commit

Permalink
merge winkernel and dummy datapath
Browse files Browse the repository at this point in the history
  • Loading branch information
ami-GS committed Nov 11, 2024
1 parent a275d74 commit b332a71
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 654 deletions.
4 changes: 2 additions & 2 deletions src/platform/datapath_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,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 @@ -269,7 +269,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 b332a71

Please sign in to comment.