In GFE, do not send version negotiation on Google QUIC packets.

Protected by FLAGS_quic_reloadable_flag_quic_no_vn_for_gquic_packets.

PiperOrigin-RevId: 488166482
diff --git a/quiche/quic/core/quic_connection.h b/quiche/quic/core/quic_connection.h
index ece0b29..869409b 100644
--- a/quiche/quic/core/quic_connection.h
+++ b/quiche/quic/core/quic_connection.h
@@ -1636,9 +1636,6 @@
   const char* ValidateStopWaitingFrame(
       const QuicStopWaitingFrame& stop_waiting);
 
-  // Sends a version negotiation packet to the peer.
-  void SendVersionNegotiationPacket(bool ietf_quic, bool has_length_prefix);
-
   // Clears any accumulated frames from the last received packet.
   void ClearLastFrames();
 
diff --git a/quiche/quic/core/quic_dispatcher.cc b/quiche/quic/core/quic_dispatcher.cc
index 208359d..952f512 100644
--- a/quiche/quic/core/quic_dispatcher.cc
+++ b/quiche/quic/core/quic_dispatcher.cc
@@ -458,7 +458,8 @@
     return true;
   }
 
-  QuicConnectionId server_connection_id = packet_info.destination_connection_id;
+  const QuicConnectionId server_connection_id =
+      packet_info.destination_connection_id;
 
   // The IETF spec requires the client to generate an initial server
   // connection ID that is at least 64 bits long. After that initial
@@ -548,19 +549,9 @@
       if (ShouldCreateSessionForUnknownVersion(packet_info.version_label)) {
         return false;
       }
-      if (!crypto_config()->validate_chlo_size() ||
-          packet_info.packet.length() >= kMinPacketSizeForVersionNegotiation) {
-        // Since the version is not supported, send a version negotiation
-        // packet and stop processing the current packet.
-        QuicConnectionId client_connection_id =
-            packet_info.source_connection_id;
-        time_wait_list_manager()->SendVersionNegotiationPacket(
-            server_connection_id, client_connection_id,
-            packet_info.form != GOOGLE_QUIC_PACKET,
-            packet_info.use_length_prefix, GetSupportedVersions(),
-            packet_info.self_address, packet_info.peer_address,
-            GetPerPacketContext());
-      }
+      // Since the version is not supported, send a version negotiation
+      // packet and stop processing the current packet.
+      MaybeSendVersionNegotiationPacket(packet_info);
       return true;
     }
 
@@ -1393,6 +1384,19 @@
       GetPerPacketContext());
 }
 
+void QuicDispatcher::MaybeSendVersionNegotiationPacket(
+    const ReceivedPacketInfo& packet_info) {
+  if (crypto_config()->validate_chlo_size() &&
+      packet_info.packet.length() < kMinPacketSizeForVersionNegotiation) {
+    return;
+  }
+  time_wait_list_manager()->SendVersionNegotiationPacket(
+      packet_info.destination_connection_id, packet_info.source_connection_id,
+      packet_info.form != GOOGLE_QUIC_PACKET, packet_info.use_length_prefix,
+      GetSupportedVersions(), packet_info.self_address,
+      packet_info.peer_address, GetPerPacketContext());
+}
+
 size_t QuicDispatcher::NumSessions() const {
   return num_sessions_in_session_map_;
 }
diff --git a/quiche/quic/core/quic_dispatcher.h b/quiche/quic/core/quic_dispatcher.h
index e74a8a7..4c3e278 100644
--- a/quiche/quic/core/quic_dispatcher.h
+++ b/quiche/quic/core/quic_dispatcher.h
@@ -322,6 +322,10 @@
   virtual void MaybeResetPacketsWithNoVersion(
       const quic::ReceivedPacketInfo& packet_info);
 
+  // Called on packets with unsupported versions.
+  virtual void MaybeSendVersionNegotiationPacket(
+      const ReceivedPacketInfo& packet_info);
+
   ConnectionIdGeneratorInterface& connection_id_generator() {
     return connection_id_generator_;
   }