Skip to content

Commit

Permalink
Refactor multipath handling to use negotiated state
Browse files Browse the repository at this point in the history
  • Loading branch information
masa-koz committed Dec 31, 2024
1 parent bf1a2f7 commit 6103189
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/core/ack_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ QuicAckTrackerAckFrameEncode(
}

if (!QuicAckFrameEncode(
QuicConnIsMultipathEnabled(PacketSpace->Connection) &&
PacketSpace->Connection->State.MultipathNegotiated &&
Builder->EncryptLevel == QUIC_ENCRYPT_LEVEL_1_RTT,
PacketSpace->PathID->ID,
&Tracker->PacketNumbersToAck,
Expand Down
22 changes: 16 additions & 6 deletions src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,11 @@ QuicConnProcessPeerTransportParameters(
QuicConnIndicateEvent(Connection, &Event);
}

if (Connection->Settings.MultipathEnabled) {
Connection->State.MultipathNegotiated =
!!(Connection->PeerTransportParams.Flags & QUIC_TP_FLAG_INITIAL_MAX_PATH_ID);
}

//
// Fully validate all exchanged connection IDs.
//
Expand Down Expand Up @@ -4580,7 +4585,7 @@ QuicConnRecvFrames(
return FALSE;
}

if (QuicConnIsMultipathEnabled(Connection)) {
if (Connection->State.MultipathNegotiated) {
QuicConnAssignPathIDs(Connection);
}

Expand Down Expand Up @@ -4704,7 +4709,7 @@ QuicConnRecvFrames(
!memcmp(Frame.Data, TempPath->Challenge, sizeof(Frame.Data))) {
QuicPerfCounterIncrement(QUIC_PERF_COUNTER_PATH_VALIDATED);
QuicPathSetValid(Connection, TempPath, QUIC_PATH_VALID_PATH_RESPONSE);
if (QuicConnIsMultipathEnabled(Connection)) {
if (Connection->State.MultipathNegotiated) {
QuicPathSetActive(Connection, TempPath);
}
break;
Expand All @@ -4716,7 +4721,7 @@ QuicConnRecvFrames(
}

case QUIC_FRAME_PATH_ABANDON: {
if (!QuicConnIsMultipathEnabled(Connection)) {
if (!Connection->State.MultipathNegotiated) {
QuicTraceEvent(
ConnError,
"[conn][%p] ERROR, %s.",
Expand Down Expand Up @@ -5171,7 +5176,7 @@ QuicConnRecvPostProcessing(
}

if (QuicConnIsServer(Connection) &&
!QuicConnIsMultipathEnabled(Connection) &&
!Connection->State.MultipathNegotiated &&
Packet->HasNonProbingFrame &&
Packet->NewLargestPacketNumber &&
!(*Path)->IsActive) {
Expand Down Expand Up @@ -5974,7 +5979,7 @@ QuicConnOpenNewPath(
CxPlatCopyMemory(&Path->Route.RemoteAddress,
&Connection->Paths[0].Route.RemoteAddress,
sizeof(QUIC_ADDR));
if (QuicConnIsMultipathEnabled(Connection)) {
if (Connection->State.MultipathNegotiated) {
Path->PathID = QuicPathIDSetGetUnusedPathID(&Connection->PathIDs);
if (Path->PathID != NULL) {
QuicPathIDAddRef(Path->PathID, QUIC_PATHID_REF_PATH);
Expand Down Expand Up @@ -6189,7 +6194,7 @@ QuicConnRemoveLocalAddress(

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

if (!QuicConnIsMultipathEnabled(Connection)) {
if (!Connection->State.MultipathNegotiated) {
if (Path->IsActive && Connection->State.Started) {
return QUIC_STATUS_INVALID_STATE;
}
Expand Down Expand Up @@ -7497,6 +7502,11 @@ QuicConnApplyNewSettings(
QuicConnIndicateEvent(Connection, &Event);
}

if (QuicConnIsServer(Connection) && Connection->Settings.MultipathEnabled) {
Connection->State.MultipathNegotiated =
!!(Connection->PeerTransportParams.Flags & QUIC_TP_FLAG_INITIAL_MAX_PATH_ID);
}

if (Connection->Settings.EcnEnabled) {
QUIC_PATH* Path = &Connection->Paths[0];
Path->EcnValidationState = ECN_VALIDATION_TESTING;
Expand Down
17 changes: 5 additions & 12 deletions src/core/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ typedef union QUIC_CONNECTION_STATE {
//
BOOLEAN TimestampRecvNegotiated : 1;

//
// Multipath extension has been negotiated.
//
BOOLEAN MultipathNegotiated : 1;

//
// Indicates we received APPLICATION_ERROR transport error and are checking also
// later packets in case they contain CONNECTION_CLOSE frame with application-layer error.
Expand Down Expand Up @@ -690,18 +695,6 @@ QuicConnIsClosed(
return Connection->State.ClosedLocally || Connection->State.ClosedRemotely;
}

//
// Helper to determine if a connection is multipath enabled
//
inline
BOOLEAN
QuicConnIsMultipathEnabled(
_In_ const QUIC_CONNECTION * const Connection
)
{
return Connection->Settings.MultipathEnabled && Connection->PathIDs.Flags.InitialMaxPathRecvd;
}

//
// Helper to get the owning QUIC_CONNECTION for the stream set module.
//
Expand Down
2 changes: 1 addition & 1 deletion src/core/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ CXPLAT_STATIC_ASSERT(
X == QUIC_FRAME_ACK_FREQUENCY || X == QUIC_FRAME_IMMEDIATE_ACK || \
X == QUIC_FRAME_RELIABLE_RESET_STREAM || \
X == QUIC_FRAME_TIMESTAMP || \
X == QUIC_FRAME_PATH_ACK || \
(X >= QUIC_FRAME_PATH_ACK && X <= QUIC_FRAME_PATH_ACK_1) || \
X == QUIC_FRAME_PATH_ABANDON || \
X == QUIC_FRAME_PATH_NEW_CONNECTION_ID || \
X == QUIC_FRAME_PATH_RETIRE_CONNECTION_ID || \
Expand Down
5 changes: 0 additions & 5 deletions src/core/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ QuicConnIsClient(
_In_ const QUIC_CONNECTION * const Connection
);

BOOLEAN
QuicConnIsMultipathEnabled(
_In_ const QUIC_CONNECTION * const Connection
);

_IRQL_requires_max_(PASSIVE_LEVEL)
void
QuicConnTransportError(
Expand Down
4 changes: 2 additions & 2 deletions src/core/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ QuicConnChoosePath(
{
QUIC_PATH* Path = &Connection->Paths[0];

if (QuicConnIsMultipathEnabled(Connection) && Connection->State.HandshakeConfirmed) {
if (Connection->State.MultipathNegotiated && Connection->State.HandshakeConfirmed) {
QUIC_PATH* ActivePaths[QUIC_MAX_PATH_COUNT];
uint8_t ActivePathCount = 0;
for (uint8_t i = 0; i < Connection->PathsCount; ++i) {
Expand Down Expand Up @@ -346,7 +346,7 @@ QuicPathSetActive(
{
BOOLEAN UdpPortChangeOnly = FALSE;

if (QuicConnIsMultipathEnabled(Connection)) {
if (Connection->State.MultipathNegotiated) {
Path->IsActive = TRUE;
} else if (Path == &Connection->Paths[0]) {
CXPLAT_DBG_ASSERT(!Path->IsActive);
Expand Down
4 changes: 2 additions & 2 deletions src/core/pathid.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ QuicPathIDWriteNewConnectionIDFrame(
)
{
QUIC_FRAME_TYPE FrameType =
QuicConnIsMultipathEnabled(PathID->Connection) ?
PathID->Connection->State.MultipathNegotiated ?
QUIC_FRAME_PATH_NEW_CONNECTION_ID : QUIC_FRAME_NEW_CONNECTION_ID;
for (CXPLAT_SLIST_ENTRY* Entry = PathID->SourceCids.Next;
Entry != NULL;
Expand Down Expand Up @@ -834,7 +834,7 @@ QuicPathIDWriteRetireConnectionIDFrame(
)
{
QUIC_FRAME_TYPE FrameType =
QuicConnIsMultipathEnabled(PathID->Connection) ?
PathID->Connection->State.MultipathNegotiated ?
QUIC_FRAME_PATH_RETIRE_CONNECTION_ID : QUIC_FRAME_RETIRE_CONNECTION_ID;
for (CXPLAT_LIST_ENTRY* Entry = PathID->DestCids.Flink;
Entry != &PathID->DestCids;
Expand Down
4 changes: 2 additions & 2 deletions src/core/pathid_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ QuicPathIDSetGenerateNewSourceCids(
_In_ BOOLEAN ReplaceExistingCids
)
{
if (QuicConnIsMultipathEnabled(QuicPathIDSetGetConnection(PathIDSet))) {
if (QuicPathIDSetGetConnection(PathIDSet)->State.MultipathNegotiated) {
uint16_t NewPathIDCount = 0;
if (PathIDSet->CurrentPathIDCount < PathIDSet->MaxCurrentPathIDCount) {
NewPathIDCount = PathIDSet->MaxCurrentPathIDCount - PathIDSet->CurrentPathIDCount;
Expand Down Expand Up @@ -596,7 +596,7 @@ QuicPathIDSetNewLocalPathID(

if (NewPathIDBlocked) {
if (Connection->State.PeerTransportParameterValid) {
QuicSendSetSendFlag(&Connection->Send, QUIC_CONN_SEND_FLAG_PATHS_BLOCKED);
// QuicSendSetSendFlag(&Connection->Send, QUIC_CONN_SEND_FLAG_PATHS_BLOCKED);
}
Status = QUIC_STATUS_PATHID_LIMIT_REACHED;
goto Exit;
Expand Down

0 comments on commit 6103189

Please sign in to comment.