1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-11-09 10:00:57 +03:00

Set upper limits on max_packet_size from the peer.

Summary: This will limit us to standard Ethernet MTU (1500) for now, but I think that is fine. This will allow us to experiment with packet size from the client more easily.

Reviewed By: yangchi

Differential Revision: D20709146

fbshipit-source-id: 608463de53d4520a257052491683263e14fc9682
This commit is contained in:
Matt Joras
2020-03-27 17:20:28 -07:00
committed by Facebook GitHub Bot
parent 19e1c14afd
commit 2176f080ff
5 changed files with 25 additions and 11 deletions

View File

@@ -30,9 +30,8 @@ constexpr uint16_t kDefaultUDPSendPacketLen =
(kDefaultV4UDPSendPacketLen < kDefaultV6UDPSendPacketLen
? kDefaultV4UDPSendPacketLen
: kDefaultV6UDPSendPacketLen);
// This is the default if the transport parameter for max packet size is missing
// or zero.
constexpr uint16_t kDefaultMaxUDPPayload = 4096;
// The max we will tolerate a peer's max_packet_size to be.
constexpr uint16_t kDefaultMaxUDPPayload = 1452;
// This is the minimum the max_packet_size transport parameter is allowed to be,
// per the spec. Note this actually refers to the max UDP payload size, not the

View File

@@ -92,7 +92,7 @@ void processServerInitialParams(
// TODO Validate active_connection_id_limit
if (!packetSize || *packetSize == 0) {
packetSize = kDefaultMaxUDPPayload;
packetSize = kDefaultUDPSendPacketLen;
}
if (*packetSize < kMinMaxUDPPayload) {
throw QuicTransportException(
@@ -134,8 +134,10 @@ void processServerInitialParams(
ackDelayExponent.value_or(kDefaultAckDelayExponent);
// TODO: udpSendPacketLen should also be limited by PMTU
if (conn.transportSettings.canIgnorePathMTU) {
conn.udpSendPacketLen =
std::min<uint64_t>(*packetSize, kDefaultMaxUDPPayload);
if (*packetSize > kDefaultMaxUDPPayload) {
*packetSize = kDefaultUDPSendPacketLen;
}
conn.udpSendPacketLen = *packetSize;
}
// Currently no-op for a client; it doesn't issue connection ids

View File

@@ -1228,7 +1228,7 @@ class FakeOneRttHandshakeLayer : public FizzClientHandshake {
bool connected_{false};
QuicVersion negotiatedVersion{QuicVersion::MVFST};
uint64_t maxRecvPacketSize{2 * 1024};
uint64_t maxRecvPacketSize{kDefaultMaxUDPPayload};
uint64_t maxInitialStreamData{kDefaultStreamWindowSize};
uint64_t connWindowSize{kDefaultConnectionWindowSize};
uint64_t maxInitialStreamsBidi{std::numeric_limits<uint32_t>::max()};

View File

@@ -125,7 +125,7 @@ void processClientInitialParams(
// TODO Validate active_connection_id_limit
if (!packetSize || *packetSize == 0) {
packetSize = kDefaultMaxUDPPayload;
packetSize = kDefaultUDPSendPacketLen;
}
if (*packetSize < kMinMaxUDPPayload) {
throw QuicTransportException(
@@ -165,8 +165,10 @@ void processClientInitialParams(
ackDelayExponent.value_or(kDefaultAckDelayExponent);
// TODO: udpSendPacketLen should also be limited by PMTU
if (conn.transportSettings.canIgnorePathMTU) {
conn.udpSendPacketLen =
std::min<uint64_t>(*packetSize, kDefaultMaxUDPPayload);
if (*packetSize > kDefaultMaxUDPPayload) {
*packetSize = kDefaultUDPSendPacketLen;
}
conn.udpSendPacketLen = *packetSize;
}
conn.peerActiveConnectionIdLimit =

View File

@@ -181,7 +181,7 @@ class FakeServerHandshake : public ServerHandshake {
QuicServerConnectionState& conn_;
bool chloSync_{false};
bool cfinSync_{false};
uint64_t maxRecvPacketSize{2 * 1024};
uint64_t maxRecvPacketSize{kDefaultMaxUDPPayload};
bool allowZeroRttKeys_{false};
std::vector<folly::IPAddress> sourceAddrs_;
folly::Optional<uint64_t> clientActiveConnectionIdLimit_;
@@ -3645,6 +3645,7 @@ TEST_F(
server->getConn().transportSettings.limitedCwndInMss * originalUdpSize +
server->getConn().transportSettings.limitedCwndInMss *
server->getConn().udpSendPacketLen;
EXPECT_NE(originalUdpSize, server->getConn().udpSendPacketLen);
EXPECT_EQ(*server->getNonConstConn().writableBytesLimit, expectedLen);
std::vector<int> indices =
getQLogEventIndices(QLogEventType::TransportStateUpdate, qLogger);
@@ -3658,6 +3659,16 @@ TEST_F(
}
}
TEST_F(QuicUnencryptedServerTransportTest, MaxReceivePacketSizeTooLarge) {
getFakeHandshakeLayer()->allowZeroRttKeys();
auto originalUdpSize = server->getConn().udpSendPacketLen;
fakeHandshake->maxRecvPacketSize = 4096;
setupClientReadCodec();
recvClientHello();
EXPECT_NE(originalUdpSize, server->getConn().udpSendPacketLen);
EXPECT_EQ(server->getConn().udpSendPacketLen, kDefaultUDPSendPacketLen);
}
TEST_F(QuicUnencryptedServerTransportTest, TestGarbageData) {
auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Server);
server->getNonConstConn().qLogger = qLogger;