Skip to content

Commit

Permalink
Handle error from RawDataPathInitialize (#4385)
Browse files Browse the repository at this point in the history
* Handle error from RawDataPathInitialize

* initial test

* fix

* UdpBind test

* fix

* cleanup Datapath

* fix flag validation

* remove validation

* rollback

* add socket level raw check

* add checking RawSocket availability api

* add api to winkernel and mac

* fix?

* Update src/platform/unittest/DataPathTest.cpp

* use all CPU by default

---------

Co-authored-by: Nick Banks <[email protected]>
  • Loading branch information
ami-GS and nibanks committed Aug 26, 2024
1 parent 934ce82 commit 2f1a7be
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/inc/quic_datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,15 @@ CxPlatSocketGetRemoteAddress(
_Out_ QUIC_ADDR* Address
);

//
// Queries a raw socket availability.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
BOOLEAN
CxPlatSocketRawSocketAvailable(
_In_ CXPLAT_SOCKET* Socket
);

//
// Called to return a chain of datagrams received from the registered receive
// callback.
Expand Down
10 changes: 10 additions & 0 deletions src/platform/datapath_kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,16 @@ CxPlatSocketGetRemoteAddress(
*Address = Socket->RemoteAddress;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
BOOLEAN
CxPlatSocketRawSocketAvailable(
_In_ CXPLAT_SOCKET* Socket
)
{
UNREFERENCED_PARAMETER(Socket);
return FALSE;
}

void
CxPlatRecvDataReturn(
_In_opt_ CXPLAT_RECV_DATA* RecvDataChain
Expand Down
10 changes: 10 additions & 0 deletions src/platform/datapath_winkernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,16 @@ CxPlatSocketGetRemoteAddress(
*Address = Binding->RemoteAddress;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
BOOLEAN
CxPlatSocketRawSocketAvailable(
_In_ CXPLAT_SOCKET* Socket
)
{
UNREFERENCED_PARAMETER(Socket);
return FALSE;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
DATAPATH_RX_IO_BLOCK*
CxPlatSocketAllocRxIoBlock(
Expand Down
12 changes: 11 additions & 1 deletion src/platform/datapath_xplat.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ CxPlatDataPathInitialize(
QuicTraceLogVerbose(
RawDatapathInitFail,
"[ raw] Failed to initialize raw datapath, status:%d", Status);
Status = QUIC_STATUS_SUCCESS;
(*NewDataPath)->RawDataPath = NULL;
CxPlatDataPathUninitialize(*NewDataPath);
*NewDataPath = NULL;
}
}

Expand Down Expand Up @@ -247,6 +248,15 @@ CxPlatSocketGetRemoteAddress(
*Address = Socket->RemoteAddress;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
BOOLEAN
CxPlatSocketRawSocketAvailable(
_In_ CXPLAT_SOCKET* Socket
)
{
return Socket->RawSocketAvailable;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
void
CxPlatRecvDataReturn(
Expand Down
17 changes: 14 additions & 3 deletions src/platform/unittest/DataPathTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ QuicAddr DataPathTest::UnspecIPv4;
QuicAddr DataPathTest::UnspecIPv6;

struct CxPlatDataPath {
QUIC_EXECUTION_CONFIG DefaultExecutionConfig { QUIC_EXECUTION_CONFIG_FLAG_XDP, 0, 0, {0} };
QUIC_EXECUTION_CONFIG DefaultExecutionConfig { QUIC_EXECUTION_CONFIG_FLAG_NONE, 0, 0, {0} };
CXPLAT_DATAPATH* Datapath {nullptr};
QUIC_STATUS InitStatus;
CxPlatDataPath(
Expand All @@ -437,6 +437,9 @@ struct CxPlatDataPath {
_In_opt_ QUIC_EXECUTION_CONFIG* Config = nullptr
) noexcept
{
if (UseDuoNic && Config == nullptr) {
DefaultExecutionConfig.Flags = QUIC_EXECUTION_CONFIG_FLAG_XDP;
}
InitStatus =
CxPlatDataPathInitialize(
ClientRecvContextLength,
Expand Down Expand Up @@ -550,6 +553,7 @@ struct CxPlatSocket {
// wait for an event set by ResolveRouteComplete.
//
EXPECT_EQ(InitStatus, QUIC_STATUS_SUCCESS);
EXPECT_TRUE(CxPlatSocketRawSocketAvailable(Socket));
}
}
}
Expand Down Expand Up @@ -668,11 +672,12 @@ TEST_F(DataPathTest, Initialize)
VERIFY_QUIC_SUCCESS(Datapath.GetInitStatus());
ASSERT_NE(nullptr, Datapath.Datapath);
}
{
QUIC_EXECUTION_CONFIG Config = { QUIC_EXECUTION_CONFIG_FLAG_NONE, 0, 1, {0} };
if (UseDuoNic) {
QUIC_EXECUTION_CONFIG Config = { QUIC_EXECUTION_CONFIG_FLAG_XDP, 0, 1, {0} };
CxPlatDataPath Datapath(&EmptyUdpCallbacks, nullptr, 0, &Config);
VERIFY_QUIC_SUCCESS(Datapath.GetInitStatus());
ASSERT_NE(nullptr, Datapath.Datapath);
ASSERT_TRUE(Datapath.IsSupported(CXPLAT_DATAPATH_FEATURE_RAW));
}
}

Expand All @@ -691,6 +696,12 @@ TEST_F(DataPathTest, InitializeInvalid)
ASSERT_EQ(QUIC_STATUS_INVALID_PARAMETER, Datapath.GetInitStatus());
ASSERT_EQ(nullptr, Datapath.Datapath);
}
if (!UseDuoNic) {
QUIC_EXECUTION_CONFIG Config = { QUIC_EXECUTION_CONFIG_FLAG_XDP, 0, 1, {0} };
CxPlatDataPath Datapath(&EmptyUdpCallbacks, nullptr, 0, &Config);
ASSERT_EQ(QUIC_STATUS_NOT_SUPPORTED, Datapath.GetInitStatus());
ASSERT_EQ(nullptr, Datapath.Datapath);
}
}

TEST_F(DataPathTest, UdpBind)
Expand Down

0 comments on commit 2f1a7be

Please sign in to comment.