avoid possibility of loop during packet forwarding
MODIFY
quic/server/QuicServerPacketRouter.cpp
quic/server/QuicServerPacketRouter.cpp
@@ -219,7 +219,10 @@ void TakeoverPacketHandler::processForwardedPacket(
data->trimStart(cursor - data.get());
QUIC_STATS(worker_->getInfoCallback(), onForwardedPacketProcessed);
worker_->handleNetworkData(
- peerAddress, std::move(data), clientPacketReceiveTime);
+ peerAddress,
+ std::move(data),
+ clientPacketReceiveTime,
+ /* isForwardedData */ true);
}
void TakeoverPacketHandler::stop() {

MODIFY
quic/server/QuicServerWorker.cpp
quic/server/QuicServerWorker.cpp
@@ -125,7 +125,8 @@ void QuicServerWorker::onDataAvailable(
void QuicServerWorker::handleNetworkData(
const folly::SocketAddress& client,
Buf data,
- const TimePoint& packetReceiveTime) noexcept {
+ const TimePoint& packetReceiveTime,
+ bool isForwardedData) noexcept {
try {
if (shutdown_) {
VLOG(4) << "Packet received after shutdown, dropping";
@@ -167,7 +168,8 @@ void QuicServerWorker::handleNetworkData(
return forwardNetworkData(
client,
std::move(routingData),
- NetworkData(std::move(data), packetReceiveTime));
+ NetworkData(std::move(data), packetReceiveTime),
+ isForwardedData);
}
folly::Expected<ParsedLongHeaderInvariant, TransportErrorCode>
@@ -239,7 +241,8 @@ void QuicServerWorker::handleNetworkData(
return forwardNetworkData(
client,
std::move(routingData),
- NetworkData(std::move(data), packetReceiveTime));
+ NetworkData(std::move(data), packetReceiveTime),
+ isForwardedData);
} catch (const std::exception& ex) {
// Drop the packet.
QUIC_STATS(infoCallback_, onPacketDropped, PacketDropReason::PARSE_ERROR);
@@ -275,12 +278,13 @@ void QuicServerWorker::tryHandlingAsHealthCheck(
void QuicServerWorker::forwardNetworkData(
const folly::SocketAddress& client,
RoutingData&& routingData,
- NetworkData&& networkData) {
+ NetworkData&& networkData,
+ bool isForwardedData) {
// if it's not Client initial or ZeroRtt, AND if the connectionId version
// mismatches: foward if pktForwarding is enabled else dropPacket
if (!routingData.isUsingClientConnId &&
!connIdAlgo_->canParse(routingData.destinationConnId)) {
- if (packetForwardingEnabled_) {
+ if (packetForwardingEnabled_ && !isForwardedData) {
VLOG(3) << "Forwarding packet with unknown connId version from client="
<< client << " to another process";
takeoverPktHandler_.forwardPacketToAnotherServer(
@@ -291,7 +295,9 @@ void QuicServerWorker::forwardNetworkData(
VLOG(3) << "Dropping packet due to unknown connectionId version connId="
<< routingData.destinationConnId.hex();
QUIC_STATS(
- infoCallback_, onPacketDropped, PacketDropReason::INVALID_PACKET);
+ infoCallback_,
+ onPacketDropped,
+ PacketDropReason::CONNECTION_NOT_FOUND);
}
return;
}

MODIFY
quic/server/QuicServerWorker.h
quic/server/QuicServerWorker.h
@@ -270,7 +270,8 @@ class QuicServerWorker : public folly::AsyncUDPSocket::ReadCallback,
void handleNetworkData(
const folly::SocketAddress& client,
Buf data,
- const TimePoint& receiveTime) noexcept;
+ const TimePoint& receiveTime,
+ bool isForwardedData = false) noexcept;
/**
* Try handling the data as a health check.
@@ -285,7 +286,8 @@ class QuicServerWorker : public folly::AsyncUDPSocket::ReadCallback,
void forwardNetworkData(
const folly::SocketAddress& client,
RoutingData&& routingData,
- NetworkData&& networkData);
+ NetworkData&& networkData,
+ bool isForwardedData = false);
/**
* Return Infocallback ptr for various transport stats (such as packet

avoid possibility of loop during packet forwarding

Reviewed By: lnicco

Differential Revision: D17401129

fbshipit-source-id: db255f313311acd462e7bee1a33c45191ef8c3df