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

Support retrieving the initial destination CID from GetParam #3755

Merged
merged 11 commits into from
Jul 15, 2023
2 changes: 1 addition & 1 deletion docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ These parameters are accessed by calling [GetParam](./api/GetParam.md) or [SetPa
| `QUIC_PARAM_CONN_CIBIR_ID`<br> 21 | uint8_t[] | Set-only | The CIBIR well-known identifier. |
| `QUIC_PARAM_CONN_STATISTICS_V2`<br> 22 | QUIC_STATISTICS_V2 | Get-only | Connection-level statistics, version 2. |
| `QUIC_PARAM_CONN_STATISTICS_V2_PLAT`<br> 23 | QUIC_STATISTICS_V2 | Get-only | Connection-level statistics with platform-specific time format, version 2. |

| `QUIC_PARAM_CONN_ORIG_DEST_CID` <br> 24 | uint8_t[] | Get-only | CID information about the original client that made the connection to the server. |
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
### QUIC_PARAM_CONN_STATISTICS_V2

Querying the `QUIC_STATISTICS_V2` struct via `QUIC_PARAM_CONN_STATISTICS_V2` or `QUIC_PARAM_CONN_STATISTICS_V2_PLAT` should be aware of possible changes in the size of the struct, depending on the version of MsQuic the app using at runtime, not just what it was compiled against.
Expand Down
25 changes: 25 additions & 0 deletions src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -7170,6 +7170,31 @@ QuicConnParamGet(
break;
}

case QUIC_PARAM_CONN_ORIG_DEST_CID:
if (Connection->OrigDestCID == NULL) {
nibanks marked this conversation as resolved.
Show resolved Hide resolved
Status = QUIC_STATUS_INVALID_STATE;
break;
}
if (Buffer == NULL) {
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
}
if (*BufferLength < Connection->OrigDestCID->Length) {
Status = QUIC_STATUS_BUFFER_TOO_SMALL;
*BufferLength = Connection->OrigDestCID->Length;
break;
}
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
CxPlatCopyMemory(
Connection->OrigDestCID->Data,
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
Buffer,
Connection->OrigDestCID->Length);
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
//
// Tell app how much buffer we copied.
//
*BufferLength = Connection->OrigDestCID->Length;
Status = QUIC_STATUS_SUCCESS;
break;

default:
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
Expand Down
1 change: 1 addition & 0 deletions src/inc/msquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ typedef struct QUIC_SCHANNEL_CREDENTIAL_ATTRIBUTE_W {
#endif
#define QUIC_PARAM_CONN_STATISTICS_V2 0x05000016 // QUIC_STATISTICS_V2
#define QUIC_PARAM_CONN_STATISTICS_V2_PLAT 0x05000017 // QUIC_STATISTICS_V2
#define QUIC_PARAM_CONN_ORIG_DEST_CID 0x05000018 // uint8_t[]

//
// Parameters for TLS.
Expand Down
111 changes: 111 additions & 0 deletions src/test/lib/ApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4227,6 +4227,116 @@ void QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(MsQuicRegistration& Registratio
}
}


ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) {
//
// This is the unit test for checking to see if a server has the correct original dest CID.
//
TestScopeLogger LogScope0("QUIC_PARAM_CONN_ORIG_DEST_CID");
{
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
MsQuicAlpn Alpn("MsQuicTest");
MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig);
TEST_QUIC_SUCCEEDED(
MsQuic->ConnectionStart(
Connection.Handle,
ClientConfiguration,
QUIC_ADDRESS_FAMILY_INET,
"localhost",
4433));
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
//
// 8 bytes is the expected minimum size of the CID.
//
uint32_t SizeOfBuffer = 8;
uint8_t Buffer[8];
TestScopeLogger LogScope1("GetParam test success case");
TEST_QUIC_STATUS(
QUIC_STATUS_SUCCESS,
Connection.GetParam(
QUIC_PARAM_CONN_ORIG_DEST_CID,
&SizeOfBuffer,
Buffer
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
)
)
}
{
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
MsQuicAlpn Alpn("MsQuicTest");
MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig);
TEST_QUIC_SUCCEEDED(
MsQuic->ConnectionStart(
Connection.Handle,
ClientConfiguration,
QUIC_ADDRESS_FAMILY_INET,
"localhost",
4433));
uint32_t SizeOfBuffer = 8;
TestScopeLogger LogScope1("GetParam null buffer check");
TEST_QUIC_STATUS(
QUIC_STATUS_INVALID_PARAMETER,
Connection.GetParam(
QUIC_PARAM_CONN_ORIG_DEST_CID,
&SizeOfBuffer,
nullptr
)
)
}
{
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
MsQuicAlpn Alpn("MsQuicTest");
MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig);
TEST_QUIC_SUCCEEDED(
MsQuic->ConnectionStart(
Connection.Handle,
ClientConfiguration,
QUIC_ADDRESS_FAMILY_INET,
"localhost",
4433));
uint32_t SizeOfBuffer = 1;
TestScopeLogger LogScope1("GetParam buffer too small check");
uint8_t Buffer[1];
TEST_QUIC_STATUS(
QUIC_STATUS_BUFFER_TOO_SMALL,
Connection.GetParam(
QUIC_PARAM_CONN_ORIG_DEST_CID,
&SizeOfBuffer,
Buffer
)
)
}
{
MsQuicConnection Connection(Registration);
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
MsQuicAlpn Alpn("MsQuicTest");
MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig);
TEST_QUIC_SUCCEEDED(
MsQuic->ConnectionStart(
Connection.Handle,
ClientConfiguration,
QUIC_ADDRESS_FAMILY_INET,
"localhost",
4433));
uint32_t SizeOfBuffer = 100;
uint8_t Buffer[100];
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
TestScopeLogger LogScope1("GetParam size of buffer bigger than needed");
TEST_QUIC_STATUS(
QUIC_STATUS_SUCCESS,
Connection.GetParam(
QUIC_PARAM_CONN_ORIG_DEST_CID,
&SizeOfBuffer,
Buffer
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
)
)
//
// There is no way the CID written should be 100 bytes according to the RFC.
//
TEST_TRUE(SizeOfBuffer < 100);
}
ProjectsByJackHe marked this conversation as resolved.
Show resolved Hide resolved
}

void QuicTestConnectionParam()
{
MsQuicAlpn Alpn("MsQuicTest");
Expand Down Expand Up @@ -4259,6 +4369,7 @@ void QuicTestConnectionParam()
QuicTest_QUIC_PARAM_CONN_CIBIR_ID(Registration, ClientConfiguration);
QuicTest_QUIC_PARAM_CONN_STATISTICS_V2(Registration);
QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(Registration);
QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(Registration);
}

//
Expand Down