Allow variable length connection IDs in v99

This CL enables the use of QUIC variable length connection IDs (VLCIDs) in v99. It also relaxes some checks when VLCIDs are enabled, and fixes tests that were relying on this. This CL also fixes QuicFramerTest.MissingDiversificationNonce as this work uncovered that the test was failure to parse headers because the headers were wrong, instead of testing for missing diversification nonces.

gfe-relnote: change only impacts v99 and tests, not flag protected
PiperOrigin-RevId: 238522262
Change-Id: I1a33470f1c9f8e5e83da44e82bdb2969fa9ed8ea
diff --git a/quic/core/quic_dispatcher.cc b/quic/core/quic_dispatcher.cc
index 7cf5a1b..dd7c2be 100644
--- a/quic/core/quic_dispatcher.cc
+++ b/quic/core/quic_dispatcher.cc
@@ -346,6 +346,24 @@
     return false;
   }
 
+  // We currently do not support having the server change its connection ID
+  // length during the handshake. Until then, fast-fail connections.
+  // TODO(dschinazi): actually support changing connection IDs from the server.
+  if (header.destination_connection_id.length() !=
+      framer_.GetExpectedConnectionIdLength()) {
+    DCHECK(QuicUtils::VariableLengthConnectionIdAllowedForVersion(
+        header.version.transport_version));
+    QUIC_DLOG(INFO)
+        << "Packet with unexpected connection ID lengths: destination "
+        << header.destination_connection_id << " source "
+        << header.source_connection_id << " expected "
+        << static_cast<int>(framer_.GetExpectedConnectionIdLength());
+    ProcessUnauthenticatedHeaderFate(kFateTimeWait,
+                                     header.destination_connection_id,
+                                     header.form, header.version);
+    return false;
+  }
+
   // Packets with connection IDs for active connections are processed
   // immediately.
   QuicConnectionId connection_id = header.destination_connection_id;
@@ -460,7 +478,7 @@
         // Add this connection_id to the time-wait state, to safely reject
         // future packets.
         QUIC_DLOG(INFO) << "Adding connection ID " << connection_id
-                        << "to time-wait list.";
+                        << " to time-wait list.";
         QUIC_CODE_COUNT(quic_reject_fate_time_wait);
         StatelesslyTerminateConnection(
             connection_id, form, version, QUIC_HANDSHAKE_FAILED,