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

This is a rollback of cl/253915913 and roll-forward of cl/253848976.
The rollback was caused by QuicDispatcherTest.ProcessPacketWithInvalidShortInitialConnectionId failing, which was unfortunately not caught by presubmits. The test was attempting to use an empty connection ID with v46 and failing in a QUIC_BUG as that is not legal to send in v46. This CL fixes that by enabling v47 at the start of the test.

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: 254015843
Change-Id: I20d6d64b0a5a8f6cace2ed90dc473c03428064b2
diff --git a/quic/core/quic_dispatcher.cc b/quic/core/quic_dispatcher.cc
index 37f1901..aeda8fc 100644
--- a/quic/core/quic_dispatcher.cc
+++ b/quic/core/quic_dispatcher.cc
@@ -327,7 +327,13 @@
     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, form,
+    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, form,
                                      version_flag, version);
     return true;
   }
diff --git a/quic/core/quic_dispatcher_test.cc b/quic/core/quic_dispatcher_test.cc
index 43c34f0..3b0c92b 100644
--- a/quic/core/quic_dispatcher_test.cc
+++ b/quic/core/quic_dispatcher_test.cc
@@ -838,6 +838,25 @@
   ProcessPacket(client_address, TestConnectionId(1), true, SerializeCHLO());
 }
 
+TEST_F(QuicDispatcherTest, ProcessPacketWithInvalidShortInitialConnectionId) {
+  SetQuicReloadableFlag(quic_drop_invalid_small_initial_connection_id, true);
+  // Enable v47 otherwise we cannot create a packet with a short connection ID.
+  SetQuicReloadableFlag(quic_enable_version_47, 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);
@@ -918,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);
@@ -925,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(_, _, _, _, _))
@@ -935,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_,