Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow client and server to share bindings #2299

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/core/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ QuicBindingInitialize(
Binding->RefCount = 0; // No refs until it's added to the library's list
Binding->Exclusive = !(UdpConfig->Flags & CXPLAT_SOCKET_FLAG_SHARE);
Binding->ServerOwned = !!(UdpConfig->Flags & CXPLAT_SOCKET_SERVER_OWNED);
Binding->ClientOwned = !(UdpConfig->Flags & CXPLAT_SOCKET_SERVER_OWNED);
Binding->Connected = UdpConfig->RemoteAddress == NULL ? FALSE : TRUE;
Binding->StatelessOperCount = 0;
CxPlatDispatchRwLockInitialize(&Binding->RwLock);
Expand Down Expand Up @@ -1423,7 +1424,8 @@ QuicBindingDeliverDatagrams(
//

QUIC_CONNECTION* Connection;
if (!Binding->ServerOwned || Packet->IsShortHeader) {

if (Binding->ClientOwned || Packet->IsShortHeader) {
Connection =
QuicLookupFindConnectionByLocalCid(
&Binding->Lookup,
Expand All @@ -1436,6 +1438,13 @@ QuicBindingDeliverDatagrams(
&DatagramChain->Route->RemoteAddress,
Packet->SourceCidLen,
Packet->SourceCid);
if (Connection == NULL && Binding->ClientOwned) {
Connection =
QuicLookupFindConnectionByLocalCid(
&Binding->Lookup,
Packet->DestCid,
Packet->DestCidLen);
}
}

if (Connection == NULL) {
Expand Down
11 changes: 7 additions & 4 deletions src/core/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,16 @@ typedef struct QUIC_BINDING {
BOOLEAN Exclusive : 1;

//
// Indicates whether the binding is owned by the server side (i.e. listener
// and server connections) or by the client side. Different receive side
// logic is used for each, so the binding cannot be shared between clients
// and servers.
// Indicates whether the binding has server side (i.e. listener
// and server connections) owners.
//
BOOLEAN ServerOwned : 1;

//
// Indicates whether this binding has client side owners or not.
//
BOOLEAN ClientOwned : 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this "Owned" flags to something like "Used` instead.


//
// Indicates that the binding is also explicitly connected to a remote
// address, effectively fixing the 4-tuple of the binding.
Expand Down
9 changes: 5 additions & 4 deletions src/core/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ QuicLibraryLookupBinding(
continue;
}

} else if (RemoteAddress != NULL) {
} else if (RemoteAddress != NULL) {
continue;
}

Expand All @@ -1486,7 +1486,6 @@ QuicLibraryGetBinding(
QUIC_ADDR NewLocalAddress;
BOOLEAN PortUnspecified = UdpConfig->LocalAddress == NULL || QuicAddrGetPort(UdpConfig->LocalAddress) == 0;
BOOLEAN ShareBinding = !!(UdpConfig->Flags & CXPLAT_SOCKET_FLAG_SHARE);
BOOLEAN ServerOwned = !!(UdpConfig->Flags & CXPLAT_SOCKET_SERVER_OWNED);

#ifdef QUIC_SHARED_EPHEMERAL_WORKAROUND
//
Expand Down Expand Up @@ -1526,8 +1525,7 @@ QuicLibraryGetBinding(
UdpConfig->LocalAddress,
UdpConfig->RemoteAddress);
if (Binding != NULL) {
if (!ShareBinding || Binding->Exclusive ||
(ServerOwned != Binding->ServerOwned)) {
if (!ShareBinding || Binding->Exclusive) {
//
// The binding does already exist, but cannot be shared with the
// requested configuration.
Expand All @@ -1543,6 +1541,9 @@ QuicLibraryGetBinding(
// Match found and can be shared.
//
CXPLAT_DBG_ASSERT(Binding->RefCount > 0);
if (!Binding->ClientOwned && !!(UdpConfig->Flags & CXPLAT_SOCKET_SERVER_OWNED)) {
Binding->ClientOwned = TRUE;
}
Binding->RefCount++;
*NewBinding = Binding;
Status = QUIC_STATUS_SUCCESS;
Expand Down
10 changes: 9 additions & 1 deletion src/test/MsQuicTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ QuicTestInterfaceBinding(
_In_ int Family
);

void
QuicTestClientServerSharedBinding(
_In_ int Family
);

//
// Negative Handshake Tests
//
Expand Down Expand Up @@ -967,4 +972,7 @@ typedef struct {
#define IOCTL_QUIC_RUN_REG_SHUTDOWN_AFTER_OPEN_AND_START \
QUIC_CTL_CODE(83, METHOD_BUFFERED, FILE_WRITE_DATA)

#define QUIC_MAX_IOCTL_FUNC_CODE 83
#define IOCTL_QUIC_RUN_CLIENT_SERVER_SHARED_BINDING \
QUIC_CTL_CODE(84, METHOD_BUFFERED, FILE_WRITE_DATA)

#define QUIC_MAX_IOCTL_FUNC_CODE 84
9 changes: 9 additions & 0 deletions src/test/bin/quic_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,15 @@ TEST_P(WithFamilyArgs, DatagramSend) {
}
}

TEST_P(WithFamilyArgs, ClientServerSharedBinding) {
TestLoggerT<ParamType> Logger("QuicTestClientServerSharedBinding", GetParam());
if (TestingKernelMode) {
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_CLIENT_SERVER_SHARED_BINDING, GetParam().Family));
} else {
QuicTestClientServerSharedBinding(GetParam().Family);
}
}

INSTANTIATE_TEST_SUITE_P(
ParameterValidation,
WithBool,
Expand Down
7 changes: 6 additions & 1 deletion src/test/bin/winkernel/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ size_t QUIC_IOCTL_BUFFER_SIZES[] =
0,
0,
0,
0
0,
sizeof(INT32)
};

CXPLAT_STATIC_ASSERT(
Expand Down Expand Up @@ -1145,6 +1146,10 @@ QuicTestCtlEvtIoDeviceControl(
QuicTestCtlRun(QuicTestRegistrationShutdownAfterConnOpenAndStart());
break;

case IOCTL_QUIC_RUN_CLIENT_SERVER_SHARED_BINDING:
QuicTestCtlRun(QuicTestClientServerSharedBinding(Params->Family));
break;

default:
Status = STATUS_NOT_IMPLEMENTED;
break;
Expand Down
80 changes: 80 additions & 0 deletions src/test/lib/HandshakeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2804,3 +2804,83 @@ QuicTestInterfaceBinding(
Connection2.HandshakeCompleteEvent.WaitTimeout(TestWaitTimeout);
TEST_TRUE(!Connection2.HandshakeComplete);
}

void
QuicTestClientServerSharedBinding(
_In_ int Family
)
{
MsQuicRegistration Registration;
TEST_TRUE(Registration.IsValid());

MsQuicAlpn Alpn("MsQuicTest");

MsQuicSettings Settings;
Settings.SetIdleTimeoutMs(3000);
QUIC_ADDRESS_FAMILY QuicAddrFamily = (Family == 4) ? QUIC_ADDRESS_FAMILY_INET : QUIC_ADDRESS_FAMILY_INET6;

MsQuicConfiguration ServerConfiguration(Registration, Alpn, Settings, ServerSelfSignedCredConfig);
TEST_TRUE(ServerConfiguration.IsValid());

MsQuicCredentialConfig ClientCredConfig;
MsQuicConfiguration ClientConfiguration(Registration, Alpn, Settings, ClientCredConfig);
TEST_TRUE(ClientConfiguration.IsValid());

{
TestListener Listener(Registration, ListenerAcceptConnection, ServerConfiguration);
TEST_TRUE(Listener.IsValid());
QuicAddr ServerLocalAddr(QuicAddrFamily);
TEST_QUIC_SUCCEEDED(Listener.Start(Alpn, &ServerLocalAddr.SockAddr));

TEST_QUIC_SUCCEEDED(Listener.GetLocalAddr(ServerLocalAddr));
TEST_EQUAL(QuicAddrGetFamily(&ServerLocalAddr.SockAddr), QuicAddrFamily);

{
UniquePtr<TestConnection> Server;
ServerAcceptContext ServerAcceptCtx((TestConnection**)&Server);
Listener.Context = &ServerAcceptCtx;

{
TestConnection Client(Registration);
TEST_TRUE(Client.IsValid());

TEST_QUIC_SUCCEEDED(Client.SetShareUdpBinding(true));
if (QuicAddrFamily == QUIC_ADDRESS_FAMILY_INET) {
CxPlatZeroMemory(
&ServerLocalAddr.SockAddr.Ipv4.sin_addr,
sizeof(ServerLocalAddr.SockAddr.Ipv4.sin_addr));
} else {
TEST_EQUAL(QuicAddrFamily, QUIC_ADDRESS_FAMILY_INET6);
CxPlatZeroMemory(
&ServerLocalAddr.SockAddr.Ipv6.sin6_addr,
sizeof(ServerLocalAddr.SockAddr.Ipv6.sin6_addr));
}
TEST_QUIC_SUCCEEDED(Client.SetLocalAddr(ServerLocalAddr));

TEST_QUIC_SUCCEEDED(
Client.Start(
ClientConfiguration,
QuicAddrFamily,
QUIC_LOCALHOST_FOR_AF(QuicAddrFamily),
ServerLocalAddr.GetPort()));

if (!Client.WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Client.GetIsConnected());

TEST_NOT_EQUAL(nullptr, Server);
if (!Server->WaitForConnectionComplete()) {
return;
}
TEST_TRUE(Server->GetIsConnected());

Client.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, QUIC_STATUS_SUCCESS);

TEST_TRUE(Client.GetIsShutdown());
TEST_TRUE(Server->GetIsShutdown());
TEST_TRUE(Server->GetPeerClosed());
}
}
}
}
2 changes: 1 addition & 1 deletion submodules/openssl
Submodule openssl updated 104 files