Skip to content

Commit

Permalink
Add test and fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
masa-koz committed Apr 6, 2024
1 parent ac806d8 commit dd92883
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 27 deletions.
32 changes: 19 additions & 13 deletions src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -6445,14 +6445,14 @@ QuicConnRemoveLocalAddress(
return QUIC_STATUS_INVALID_STATE;
}

if (!Connection->State.Started) {
return QUIC_STATUS_INVALID_STATE;
}

if (!QuicAddrIsValid(LocalAddress)) {
return QUIC_STATUS_INVALID_PARAMETER;
}

if (!Connection->State.LocalAddressSet) {
return QUIC_STATUS_NOT_FOUND;
}

uint8_t PathIndex = Connection->PathsCount;
for (uint8_t i = 0; i < Connection->PathsCount; ++i) {
if (QuicAddrCompare(
Expand All @@ -6469,20 +6469,26 @@ QuicConnRemoveLocalAddress(

QUIC_PATH* Path = &Connection->Paths[PathIndex];

if (Path->IsActive) {
if (Path->IsActive && Connection->State.Started) {
return QUIC_STATUS_INVALID_STATE;
}

QuicConnRetireCid(Connection, Path->DestCid);

CXPLAT_DBG_ASSERT(Path->Binding != NULL);

QuicBindingRemoveAllSourceConnectionIDs(Path->Binding, Connection);
if (Path->DestCid != NULL) {
QuicConnRetireCid(Connection, Path->DestCid);
}

QuicLibraryReleaseBinding(Path->Binding);
Path->Binding = NULL;
if (Path->Binding != NULL) {
QuicBindingRemoveAllSourceConnectionIDs(Path->Binding, Connection);
QuicLibraryReleaseBinding(Path->Binding);
Path->Binding = NULL;
}

QuicPathRemove(Connection, PathIndex);
if (Connection->PathsCount == 1) {
CXPLAT_DBG_ASSERT(!Connection->State.Started);
Connection->State.LocalAddressSet = FALSE;
} else {
QuicPathRemove(Connection, PathIndex);
}

return QUIC_STATUS_SUCCESS;
}
Expand Down
102 changes: 88 additions & 14 deletions src/test/lib/ApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4477,36 +4477,35 @@ void QuicTest_QUIC_PARAM_CONN_ADD_LOCAL_ADDRESS(MsQuicRegistration& Registration
}

//
// Connection is started, but not handshake confirmed
// Good before ConnectionStart
//
{
TestScopeLogger LogScope2("Connection is started, but not handshake confirmed");
TestScopeLogger LogScope2("Good before ConnectionStart");
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
TEST_QUIC_SUCCEEDED(
MsQuic->ConnectionStart(
Connection.Handle,
ClientConfiguration,
QUIC_ADDRESS_FAMILY_INET,
"localhost",
4433));

QUIC_ADDR Dummy = {};
TEST_QUIC_STATUS(
QUIC_STATUS_INVALID_STATE,
TEST_QUIC_SUCCEEDED(
Connection.SetParam(
QUIC_PARAM_CONN_ADD_LOCAL_ADDRESS,
sizeof(Dummy),
&Dummy));
}

//
// Good before ConnectioStart
// Good after ConnectionStart
//
{
TestScopeLogger LogScope2("Good before ConnectionStart");
TestScopeLogger LogScope2("Good after ConnectionStart");
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
TEST_QUIC_SUCCEEDED(
MsQuic->ConnectionStart(
Connection.Handle,
ClientConfiguration,
QUIC_ADDRESS_FAMILY_INET,
"localhost",
4433));

QUIC_ADDR Dummy = {};
TEST_QUIC_SUCCEEDED(
Connection.SetParam(
Expand Down Expand Up @@ -4558,6 +4557,80 @@ void QuicTest_QUIC_PARAM_CONN_ADD_LOCAL_ADDRESS(MsQuicRegistration& Registration
}
}

void QuicTest_QUIC_PARAM_CONN_REMOVE_LOCAL_ADDRESS(MsQuicRegistration& Registration, MsQuicConfiguration& ClientConfiguration)
{
TestScopeLogger LogScope0("QUIC_PARAM_CONN_REMOVE_LOCAL_ADDRESS");
//
// SetParam
//
{
TestScopeLogger LogScope1("SetParam");
//
// No local address to remove
//
{
TestScopeLogger LogScope2("No local address to remove");
TEST_TRUE(ClientConfiguration.IsValid());
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());

QUIC_ADDR Dummy = {};
TEST_QUIC_STATUS(
QUIC_STATUS_NOT_FOUND,
Connection.SetParam(
QUIC_PARAM_CONN_REMOVE_LOCAL_ADDRESS,
sizeof(Dummy),
&Dummy));
}

//
// Add and remove a local address
//
{
TestScopeLogger LogScope2("Add and remove a local address");
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
QUIC_ADDR Dummy = {};
TEST_QUIC_SUCCEEDED(
Connection.SetParam(
QUIC_PARAM_CONN_ADD_LOCAL_ADDRESS,
sizeof(Dummy),
&Dummy));

TEST_QUIC_SUCCEEDED(
Connection.SetParam(
QUIC_PARAM_CONN_REMOVE_LOCAL_ADDRESS,
sizeof(Dummy),
&Dummy));
}

//
// Remove a local address that belongs to another the active path
//
{
TestScopeLogger LogScope2("Remove a local address that belongs to another the active path");
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
TEST_QUIC_SUCCEEDED(
MsQuic->ConnectionStart(
Connection.Handle,
ClientConfiguration,
QUIC_ADDRESS_FAMILY_INET,
"localhost",
4433));

QuicAddr ClientLocalAddr;
TEST_QUIC_SUCCEEDED(Connection.GetLocalAddr(ClientLocalAddr));
TEST_QUIC_STATUS(
QUIC_STATUS_INVALID_STATE,
Connection.SetParam(
QUIC_PARAM_CONN_REMOVE_LOCAL_ADDRESS,
sizeof(ClientLocalAddr.SockAddr),
&ClientLocalAddr.SockAddr));
}
}
}

void QuicTestConnectionParam()
{
MsQuicAlpn Alpn("MsQuicTest");
Expand Down Expand Up @@ -4592,6 +4665,7 @@ void QuicTestConnectionParam()
QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(Registration);
QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(Registration, ClientConfiguration);
QuicTest_QUIC_PARAM_CONN_ADD_LOCAL_ADDRESS(Registration, ClientConfiguration);
QuicTest_QUIC_PARAM_CONN_REMOVE_LOCAL_ADDRESS(Registration, ClientConfiguration);
}

//
Expand Down

0 comments on commit dd92883

Please sign in to comment.