Skip to content

Commit

Permalink
Support for sending packets with DSCP, ECT(0) and ECT(1) marking
Browse files Browse the repository at this point in the history
Summary:
Adds new transport settings for enabling quic sockets to read or write the tos/tclass field in the IP headers.

The new transport settings are: readEcnOnIngress, enableEcnOnEgress, useL4sEcn. All are defaulted to false.

readEcnOnIngress=true --> enabled reading the ToS field from incoming packets.

enableEcnOnEgress=false --> does not set marking
enableEcnOnEgress=true, useL4sEcn=false --> sets marking to ECT0
enableEcnOnEgress=true, useL4sEcn=true --> sets marking to ECT1

The next changes handle these packets in the rest of the stack.

Reviewed By: mjoras, kvtsoy

Differential Revision: D54877773

fbshipit-source-id: af6aefc714e2678f488d027583cf666200748782
  • Loading branch information
jbeshay authored and facebook-github-bot committed May 9, 2024
1 parent e099674 commit f455273
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions folly/io/async/AsyncUDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,17 @@ bool AsyncUDPSocket::setTxZeroChksum6([[maybe_unused]] bool bVal) {
}

void AsyncUDPSocket::setTosOrTrafficClass(uint8_t tosOrTclass) {
#ifdef _WIN32
// For windows, we can only set the values 0 and 1 (for the ECN bits).
// Any DSCP values have to be set via the QoS Policy
auto level = address().getFamily() == AF_INET6 ? IPPROTO_IPV6 : IPPROTO_IP;
if (tosOrTclass == 0) {
// Remove ECN cmsgs if any exist
defaultCmsgs_.erase({level, IP_ECN});
} else {
defaultCmsgs_[{level, IP_ECN}] = tosOrTclass;
}
#else
int valInt = tosOrTclass;
if (address().getFamily() == AF_INET6) {
if (netops::setsockopt(
Expand All @@ -1550,11 +1561,6 @@ void AsyncUDPSocket::setTosOrTrafficClass(uint8_t tosOrTclass) {
AsyncSocketException::NOT_OPEN, "Failed to set IP_TOS", errno);
}
}

#ifdef _WIN32
folly::SocketCmsgMap cmsgs;
cmsgs[{IPPROTO_IP, IP_ECN}] = tosOrTclass;
appendCmsgs(cmsgs);
#endif
}

Expand Down

0 comments on commit f455273

Please sign in to comment.