Skip to content

Commit

Permalink
Add support for setting TypeOfService/TrafficClass on connections (#4757
Browse files Browse the repository at this point in the history
)

* Add support for setting TypeOfService/TrafficClass on connections

* Add tests for Dscp send support.

* Add tests for the API setting.

* Add coverage for NULL buffer to GetParam tests

* Only set IP_ECN when IP_TOS isn't supported. Only set ECN or TOS when ECN and DSCP are non-default
  • Loading branch information
anrossi authored Feb 5, 2025
1 parent 55fd8ef commit 8eb966d
Show file tree
Hide file tree
Showing 36 changed files with 685 additions and 65 deletions.
1 change: 1 addition & 0 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ These parameters are accessed by calling [GetParam](./api/GetParam.md) or [SetPa
| `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 | The original destination connection ID used by the client to connect to the server. |
| `QUIC_PARAM_CONN_SEND_DSCP` <br> 25 | uint8_t | Both | The DiffServ Code Point put in the DiffServ field (formerly TypeOfService/TrafficClass) on packets sent from this connection. |

### QUIC_PARAM_CONN_STATISTICS_V2

Expand Down
2 changes: 1 addition & 1 deletion src/core/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ QuicBindingProcessStatelessOperation(
Binding,
OperationType);

CXPLAT_SEND_CONFIG SendConfig = { RecvPacket->Route, 0, CXPLAT_ECN_NON_ECT, 0 };
CXPLAT_SEND_CONFIG SendConfig = { RecvPacket->Route, 0, CXPLAT_ECN_NON_ECT, 0, CXPLAT_DSCP_CS0 };
CXPLAT_SEND_DATA* SendData = CxPlatSendDataAlloc(Binding->Socket, &SendConfig);
if (SendData == NULL) {
QuicTraceEvent(
Expand Down
53 changes: 53 additions & 0 deletions src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -6623,6 +6623,31 @@ QuicConnParamSet(
return QUIC_STATUS_SUCCESS;
}

case QUIC_PARAM_CONN_SEND_DSCP: {
if (BufferLength != sizeof(uint8_t) || Buffer == NULL) {
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
}

uint8_t DSCP = *(uint8_t*)Buffer;

if (DSCP > CXPLAT_MAX_DSCP) {
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
}

Connection->DSCP = DSCP;

QuicTraceLogConnInfo(
ConnDscpSet,
Connection,
"Connection DSCP set to %hhu",
Connection->DSCP);

Status = QUIC_STATUS_SUCCESS;
break;
}

//
// Private
//
Expand Down Expand Up @@ -7207,27 +7232,55 @@ QuicConnParamGet(
}

case QUIC_PARAM_CONN_ORIG_DEST_CID:

if (Connection->OrigDestCID == NULL) {
Status = QUIC_STATUS_INVALID_STATE;
break;
}

if (*BufferLength < Connection->OrigDestCID->Length) {
Status = QUIC_STATUS_BUFFER_TOO_SMALL;
*BufferLength = Connection->OrigDestCID->Length;
break;
}

if (Buffer == NULL) {
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
}

CxPlatCopyMemory(
Buffer,
Connection->OrigDestCID->Data,
Connection->OrigDestCID->Length);

//
// Tell app how much buffer we copied.
//
*BufferLength = Connection->OrigDestCID->Length;

Status = QUIC_STATUS_SUCCESS;
break;

case QUIC_PARAM_CONN_SEND_DSCP:

if (*BufferLength < sizeof(uint8_t)) {
Status = QUIC_STATUS_BUFFER_TOO_SMALL;
*BufferLength = sizeof(uint8_t);
break;
}

if (Buffer == NULL) {
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
}

CxPlatCopyMemory(
Buffer,
&Connection->DSCP,
sizeof(Connection->DSCP));

*BufferLength = sizeof(Connection->DSCP);
Status = QUIC_STATUS_SUCCESS;
break;

Expand Down
6 changes: 6 additions & 0 deletions src/core/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ typedef struct QUIC_CONNECTION {
//
uint8_t PeerReorderingThreshold;

//
// DSCP value to set on all sends from this connection.
// Default value of 0.
//
uint8_t DSCP;

//
// The ACK frequency sequence number we are currently using to send.
//
Expand Down
3 changes: 2 additions & 1 deletion src/core/packet_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ QuicPacketBuilderPrepare(
DatagramSize),
Builder->EcnEctSet ? CXPLAT_ECN_ECT_0 : CXPLAT_ECN_NON_ECT,
Builder->Connection->Registration->ExecProfile == QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT ?
CXPLAT_SEND_FLAGS_MAX_THROUGHPUT : CXPLAT_SEND_FLAGS_NONE
CXPLAT_SEND_FLAGS_MAX_THROUGHPUT : CXPLAT_SEND_FLAGS_NONE,
Connection->DSCP
};
Builder->SendData =
CxPlatSendDataAlloc(Builder->Path->Binding->Socket, &SendConfig);
Expand Down
3 changes: 3 additions & 0 deletions src/cs/lib/msquic_generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3447,6 +3447,9 @@ internal static unsafe partial class MsQuic
[NativeTypeName("#define QUIC_PARAM_CONN_ORIG_DEST_CID 0x05000018")]
internal const uint QUIC_PARAM_CONN_ORIG_DEST_CID = 0x05000018;

[NativeTypeName("#define QUIC_PARAM_CONN_SEND_DSCP 0x05000019")]
internal const uint QUIC_PARAM_CONN_SEND_DSCP = 0x05000019;

[NativeTypeName("#define QUIC_PARAM_TLS_HANDSHAKE_INFO 0x06000000")]
internal const uint QUIC_PARAM_TLS_HANDSHAKE_INFO = 0x06000000;

Expand Down
1 change: 1 addition & 0 deletions src/ffi/linux_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pub const QUIC_PARAM_CONN_TLS_SECRETS: u32 = 83886099;
pub const QUIC_PARAM_CONN_STATISTICS_V2: u32 = 83886102;
pub const QUIC_PARAM_CONN_STATISTICS_V2_PLAT: u32 = 83886103;
pub const QUIC_PARAM_CONN_ORIG_DEST_CID: u32 = 83886104;
pub const QUIC_PARAM_CONN_SEND_DSCP: u32 = 83886105;
pub const QUIC_PARAM_TLS_HANDSHAKE_INFO: u32 = 100663296;
pub const QUIC_PARAM_TLS_NEGOTIATED_ALPN: u32 = 100663297;
pub const QUIC_PARAM_STREAM_ID: u32 = 134217728;
Expand Down
1 change: 1 addition & 0 deletions src/ffi/win_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pub const QUIC_PARAM_CONN_TLS_SECRETS: u32 = 83886099;
pub const QUIC_PARAM_CONN_STATISTICS_V2: u32 = 83886102;
pub const QUIC_PARAM_CONN_STATISTICS_V2_PLAT: u32 = 83886103;
pub const QUIC_PARAM_CONN_ORIG_DEST_CID: u32 = 83886104;
pub const QUIC_PARAM_CONN_SEND_DSCP: u32 = 83886105;
pub const QUIC_PARAM_TLS_HANDSHAKE_INFO: u32 = 100663296;
pub const QUIC_PARAM_TLS_NEGOTIATED_ALPN: u32 = 100663297;
pub const QUIC_PARAM_TLS_SCHANNEL_CONTEXT_ATTRIBUTE_W: u32 = 117440512;
Expand Down
20 changes: 20 additions & 0 deletions src/generated/linux/connection.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,26 @@ tracepoint(CLOG_CONNECTION_C, CibirIdSet , arg1, arg3, arg4);\



/*----------------------------------------------------------
// Decoder Ring for ConnDscpSet
// [conn][%p] Connection DSCP set to %hhu
// QuicTraceLogConnInfo(
ConnDscpSet,
Connection,
"Connection DSCP set to %hhu",
Connection->DSCP);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = Connection->DSCP = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_ConnDscpSet
#define _clog_4_ARGS_TRACE_ConnDscpSet(uniqueId, arg1, encoded_arg_string, arg3)\
tracepoint(CLOG_CONNECTION_C, ConnDscpSet , arg1, arg3);\

#endif




/*----------------------------------------------------------
// Decoder Ring for ApplySettings
// [conn][%p] Applying new settings
Expand Down
23 changes: 23 additions & 0 deletions src/generated/linux/connection.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,29 @@ TRACEPOINT_EVENT(CLOG_CONNECTION_C, CibirIdSet,



/*----------------------------------------------------------
// Decoder Ring for ConnDscpSet
// [conn][%p] Connection DSCP set to %hhu
// QuicTraceLogConnInfo(
ConnDscpSet,
Connection,
"Connection DSCP set to %hhu",
Connection->DSCP);
// arg1 = arg1 = Connection = arg1
// arg3 = arg3 = Connection->DSCP = arg3
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_CONNECTION_C, ConnDscpSet,
TP_ARGS(
const void *, arg1,
unsigned char, arg3),
TP_FIELDS(
ctf_integer_hex(uint64_t, arg1, (uint64_t)arg1)
ctf_integer(unsigned char, arg3, arg3)
)
)



/*----------------------------------------------------------
// Decoder Ring for ApplySettings
// [conn][%p] Applying new settings
Expand Down
36 changes: 36 additions & 0 deletions src/generated/linux/datapath_winkernel.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,42 @@ tracepoint(CLOG_DATAPATH_WINKERNEL_C, DatapathQueryRecvMaxCoalescedSizeFailedAsy



/*----------------------------------------------------------
// Decoder Ring for DatapathTestSetIpv6TrafficClassFailed
// [data] Test setting IPV6_TCLASS failed, 0x%x
// QuicTraceLogWarning(
DatapathTestSetIpv6TrafficClassFailed,
"[data] Test setting IPV6_TCLASS failed, 0x%x",
Status);
// arg2 = arg2 = Status = arg2
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_DatapathTestSetIpv6TrafficClassFailed
#define _clog_3_ARGS_TRACE_DatapathTestSetIpv6TrafficClassFailed(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_DATAPATH_WINKERNEL_C, DatapathTestSetIpv6TrafficClassFailed , arg2);\

#endif




/*----------------------------------------------------------
// Decoder Ring for DatapathTestSetIpv6TrafficClassFailedAsync
// [data] Test setting IPV6_TCLASS failed (async), 0x%x
// QuicTraceLogWarning(
DatapathTestSetIpv6TrafficClassFailedAsync,
"[data] Test setting IPV6_TCLASS failed (async), 0x%x",
Status);
// arg2 = arg2 = Status = arg2
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_DatapathTestSetIpv6TrafficClassFailedAsync
#define _clog_3_ARGS_TRACE_DatapathTestSetIpv6TrafficClassFailedAsync(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_DATAPATH_WINKERNEL_C, DatapathTestSetIpv6TrafficClassFailedAsync , arg2);\

#endif




/*----------------------------------------------------------
// Decoder Ring for DatapathDropEmptyMdl
// [%p] Dropping datagram with empty mdl.
Expand Down
38 changes: 38 additions & 0 deletions src/generated/linux/datapath_winkernel.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,44 @@ TRACEPOINT_EVENT(CLOG_DATAPATH_WINKERNEL_C, DatapathQueryRecvMaxCoalescedSizeFai



/*----------------------------------------------------------
// Decoder Ring for DatapathTestSetIpv6TrafficClassFailed
// [data] Test setting IPV6_TCLASS failed, 0x%x
// QuicTraceLogWarning(
DatapathTestSetIpv6TrafficClassFailed,
"[data] Test setting IPV6_TCLASS failed, 0x%x",
Status);
// arg2 = arg2 = Status = arg2
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_DATAPATH_WINKERNEL_C, DatapathTestSetIpv6TrafficClassFailed,
TP_ARGS(
unsigned int, arg2),
TP_FIELDS(
ctf_integer(unsigned int, arg2, arg2)
)
)



/*----------------------------------------------------------
// Decoder Ring for DatapathTestSetIpv6TrafficClassFailedAsync
// [data] Test setting IPV6_TCLASS failed (async), 0x%x
// QuicTraceLogWarning(
DatapathTestSetIpv6TrafficClassFailedAsync,
"[data] Test setting IPV6_TCLASS failed (async), 0x%x",
Status);
// arg2 = arg2 = Status = arg2
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_DATAPATH_WINKERNEL_C, DatapathTestSetIpv6TrafficClassFailedAsync,
TP_ARGS(
unsigned int, arg2),
TP_FIELDS(
ctf_integer(unsigned int, arg2, arg2)
)
)



/*----------------------------------------------------------
// Decoder Ring for DatapathDropEmptyMdl
// [%p] Dropping datagram with empty mdl.
Expand Down
36 changes: 36 additions & 0 deletions src/generated/linux/datapath_winuser.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,42 @@ tracepoint(CLOG_DATAPATH_WINUSER_C, DatapathQueryRecvMaxCoalescedSizeFailed , ar



/*----------------------------------------------------------
// Decoder Ring for DatapathOpenUdpv6SocketFailed
// [data] UDPv6 helper socket failed to open, 0x%x
// QuicTraceLogWarning(
DatapathOpenUdpv6SocketFailed,
"[data] UDPv6 helper socket failed to open, 0x%x",
WsaError);
// arg2 = arg2 = WsaError = arg2
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_DatapathOpenUdpv6SocketFailed
#define _clog_3_ARGS_TRACE_DatapathOpenUdpv6SocketFailed(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_DATAPATH_WINUSER_C, DatapathOpenUdpv6SocketFailed , arg2);\

#endif




/*----------------------------------------------------------
// Decoder Ring for DatapathTestSetIpv6TrafficClassFailed
// [data] Test setting IPV6_TCLASS failed, 0x%x
// QuicTraceLogWarning(
DatapathTestSetIpv6TrafficClassFailed,
"[data] Test setting IPV6_TCLASS failed, 0x%x",
WsaError);
// arg2 = arg2 = WsaError = arg2
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_DatapathTestSetIpv6TrafficClassFailed
#define _clog_3_ARGS_TRACE_DatapathTestSetIpv6TrafficClassFailed(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_DATAPATH_WINUSER_C, DatapathTestSetIpv6TrafficClassFailed , arg2);\

#endif




/*----------------------------------------------------------
// Decoder Ring for DatapathRecvEmpty
// [data][%p] Dropping datagram with empty payload.
Expand Down
38 changes: 38 additions & 0 deletions src/generated/linux/datapath_winuser.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,44 @@ TRACEPOINT_EVENT(CLOG_DATAPATH_WINUSER_C, DatapathQueryRecvMaxCoalescedSizeFaile



/*----------------------------------------------------------
// Decoder Ring for DatapathOpenUdpv6SocketFailed
// [data] UDPv6 helper socket failed to open, 0x%x
// QuicTraceLogWarning(
DatapathOpenUdpv6SocketFailed,
"[data] UDPv6 helper socket failed to open, 0x%x",
WsaError);
// arg2 = arg2 = WsaError = arg2
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_DATAPATH_WINUSER_C, DatapathOpenUdpv6SocketFailed,
TP_ARGS(
unsigned int, arg2),
TP_FIELDS(
ctf_integer(unsigned int, arg2, arg2)
)
)



/*----------------------------------------------------------
// Decoder Ring for DatapathTestSetIpv6TrafficClassFailed
// [data] Test setting IPV6_TCLASS failed, 0x%x
// QuicTraceLogWarning(
DatapathTestSetIpv6TrafficClassFailed,
"[data] Test setting IPV6_TCLASS failed, 0x%x",
WsaError);
// arg2 = arg2 = WsaError = arg2
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_DATAPATH_WINUSER_C, DatapathTestSetIpv6TrafficClassFailed,
TP_ARGS(
unsigned int, arg2),
TP_FIELDS(
ctf_integer(unsigned int, arg2, arg2)
)
)



/*----------------------------------------------------------
// Decoder Ring for DatapathRecvEmpty
// [data][%p] Dropping datagram with empty payload.
Expand Down
1 change: 1 addition & 0 deletions src/inc/msquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ typedef struct QUIC_SCHANNEL_CREDENTIAL_ATTRIBUTE_W {
#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[]
#define QUIC_PARAM_CONN_SEND_DSCP 0x05000019 // uint8_t

//
// Parameters for TLS.
Expand Down
Loading

0 comments on commit 8eb966d

Please sign in to comment.