Make QuicDispatcher drop packets that have an initial destination connection ID that is too short

With this CL, QuicDispatcher will drop packets that have an initial destination connection ID that is too short, instead of responding with a Version Negotiation packet to reject it.

gfe-relnote: drop a kind of invalid packet, protected by --gfe2_reloadable_flag_quic_drop_invalid_small_initial_connection_id
PiperOrigin-RevId: 253848976
Change-Id: Ia174b720b2e4b45b65aa77d25ec8c6c66ee4d254
diff --git a/quic/core/quic_dispatcher.cc b/quic/core/quic_dispatcher.cc
index 9b59aa5..994e2bc 100644
--- a/quic/core/quic_dispatcher.cc
+++ b/quic/core/quic_dispatcher.cc
@@ -351,9 +351,14 @@
     QUIC_DLOG(INFO) << "Packet with short destination connection ID "
                     << server_connection_id << " expected "
                     << static_cast<int>(expected_server_connection_id_length);
-    ProcessUnauthenticatedHeaderFate(kFateTimeWait, server_connection_id,
-                                     header.form, header.version_flag,
-                                     header.version);
+    QuicPacketFate fate = kFateDrop;
+    if (!GetQuicReloadableFlag(quic_drop_invalid_small_initial_connection_id)) {
+      fate = kFateTimeWait;
+    } else {
+      QUIC_RELOADABLE_FLAG_COUNT(quic_drop_invalid_small_initial_connection_id);
+    }
+    ProcessUnauthenticatedHeaderFate(fate, server_connection_id, header.form,
+                                     header.version_flag, header.version);
     return false;
   }
 
diff --git a/quic/core/quic_dispatcher_test.cc b/quic/core/quic_dispatcher_test.cc
index 91794c0..4a14ef7 100644
--- a/quic/core/quic_dispatcher_test.cc
+++ b/quic/core/quic_dispatcher_test.cc
@@ -840,6 +840,23 @@
   ProcessPacket(client_address, TestConnectionId(1), true, SerializeCHLO());
 }
 
+TEST_F(QuicDispatcherTest, ProcessPacketWithInvalidShortInitialConnectionId) {
+  SetQuicReloadableFlag(quic_drop_invalid_small_initial_connection_id, true);
+  CreateTimeWaitListManager();
+
+  QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
+
+  // dispatcher_ should drop this packet.
+  EXPECT_CALL(*dispatcher_,
+              CreateQuicSession(_, client_address, QuicStringPiece("hq"), _))
+      .Times(0);
+  EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*time_wait_list_manager_,
+              AddConnectionIdToTimeWait(_, _, _, _, _))
+      .Times(0);
+  ProcessPacket(client_address, EmptyQuicConnectionId(), true, SerializeCHLO());
+}
+
 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
   QuicConnectionId connection_id = TestConnectionId(1);
@@ -920,6 +937,7 @@
 // Packets with truncated connection IDs should be dropped.
 TEST_F(QuicDispatcherTestStrayPacketConnectionId,
        StrayPacketTruncatedConnectionId) {
+  SetQuicReloadableFlag(quic_drop_invalid_small_initial_connection_id, true);
   CreateTimeWaitListManager();
 
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
@@ -927,8 +945,6 @@
   EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, QuicStringPiece("hq"), _))
       .Times(0);
   if (VersionHasIetfInvariantHeader(
-          CurrentSupportedVersions()[0].transport_version) &&
-      !QuicUtils::VariableLengthConnectionIdAllowedForVersion(
           CurrentSupportedVersions()[0].transport_version)) {
     // This IETF packet has invalid connection ID length.
     EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _))
@@ -937,10 +953,8 @@
                 AddConnectionIdToTimeWait(_, _, _, _, _))
         .Times(0);
   } else {
-    // This is either:
-    // - a GQUIC packet considered as IETF QUIC packet with short header
-    // with unacceptable packet number or
-    // - an IETF QUIC packet with bad connection ID length which is rejected.
+    // This is a GQUIC packet considered as IETF QUIC packet with short header
+    // with unacceptable packet number.
     EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _))
         .Times(1);
     EXPECT_CALL(*time_wait_list_manager_,