gfe-relnote: In QUIC, do not add connection ID of packets with unknown connection ID and no version to time wait list, instead, send appropriate reset depending on the packets' sizes and drop them. Protected by gfe2_reloadable_flag_quic_reject_unprocessable_packets_statelessly.

PiperOrigin-RevId: 257470130
Change-Id: I0897dc244bac24f442685eddd795a7152ee5242f
diff --git a/quic/core/quic_dispatcher_test.cc b/quic/core/quic_dispatcher_test.cc
index ccac80c..b18bddb 100644
--- a/quic/core/quic_dispatcher_test.cc
+++ b/quic/core/quic_dispatcher_test.cc
@@ -679,15 +679,62 @@
   // list manager.
   EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, QuicStringPiece("hq"), _))
       .Times(0);
-  EXPECT_CALL(*time_wait_list_manager_,
-              ProcessPacket(_, _, connection_id, _, _))
-      .Times(1);
-  EXPECT_CALL(*time_wait_list_manager_,
-              AddConnectionIdToTimeWait(_, _, _, _, _))
-      .Times(1);
+  if (GetQuicReloadableFlag(quic_reject_unprocessable_packets_statelessly)) {
+    EXPECT_CALL(*time_wait_list_manager_,
+                ProcessPacket(_, _, connection_id, _, _))
+        .Times(0);
+    EXPECT_CALL(*time_wait_list_manager_,
+                AddConnectionIdToTimeWait(_, _, _, _, _))
+        .Times(0);
+    EXPECT_CALL(*time_wait_list_manager_, SendPublicReset(_, _, _, _, _))
+        .Times(1);
+  } else {
+    EXPECT_CALL(*time_wait_list_manager_,
+                ProcessPacket(_, _, connection_id, _, _))
+        .Times(1);
+    EXPECT_CALL(*time_wait_list_manager_,
+                AddConnectionIdToTimeWait(_, _, _, _, _))
+        .Times(1);
+  }
   ProcessPacket(client_address, connection_id, false, SerializeCHLO());
 }
 
+TEST_F(QuicDispatcherTest,
+       DonotTimeWaitPacketsWithUnknownConnectionIdAndNoVersion) {
+  QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
+  CreateTimeWaitListManager();
+
+  char short_packet[22] = {0x70, 0xa7, 0x02, 0x6b};
+  QuicReceivedPacket packet(short_packet, 22, QuicTime::Zero());
+  char valid_size_packet[23] = {0x70, 0xa7, 0x02, 0x6c};
+  QuicReceivedPacket packet2(valid_size_packet, 23, QuicTime::Zero());
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _)).Times(0);
+  if (GetQuicReloadableFlag(quic_reject_unprocessable_packets_statelessly)) {
+    EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _))
+        .Times(0);
+    EXPECT_CALL(*time_wait_list_manager_,
+                AddConnectionIdToTimeWait(_, _, _, _, _))
+        .Times(0);
+  } else {
+    EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _))
+        .Times(2);
+    EXPECT_CALL(*time_wait_list_manager_,
+                AddConnectionIdToTimeWait(_, _, _, _, _))
+        .Times(2);
+  }
+  if (GetQuicReloadableFlag(quic_reject_unprocessable_packets_statelessly)) {
+    // Verify small packet is silently dropped.
+    EXPECT_CALL(*time_wait_list_manager_, SendPublicReset(_, _, _, _, _))
+        .Times(0);
+  }
+  dispatcher_->ProcessPacket(server_address_, client_address, packet);
+  if (GetQuicReloadableFlag(quic_reject_unprocessable_packets_statelessly)) {
+    EXPECT_CALL(*time_wait_list_manager_, SendPublicReset(_, _, _, _, _))
+        .Times(1);
+  }
+  dispatcher_->ProcessPacket(server_address_, client_address, packet2);
+}
+
 // Makes sure nine-byte connection IDs are replaced by 8-byte ones.
 TEST_F(QuicDispatcherTest, LongConnectionIdLengthReplaced) {
   if (!QuicUtils::VariableLengthConnectionIdAllowedForVersion(