OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // ProcessPacket will cause the packet to be dispatched in | 83 // ProcessPacket will cause the packet to be dispatched in |
84 // OnUnauthenticatedPublicHeader, or sent to the time wait list manager | 84 // OnUnauthenticatedPublicHeader, or sent to the time wait list manager |
85 // in OnUnauthenticatedHeader. | 85 // in OnUnauthenticatedHeader. |
86 framer_.ProcessPacket(packet); | 86 framer_.ProcessPacket(packet); |
87 // TODO(rjshade): Return a status describing if/why a packet was dropped, | 87 // TODO(rjshade): Return a status describing if/why a packet was dropped, |
88 // and log somehow. Maybe expose as a varz. | 88 // and log somehow. Maybe expose as a varz. |
89 } | 89 } |
90 | 90 |
91 bool QuicDispatcher::OnUnauthenticatedPublicHeader( | 91 bool QuicDispatcher::OnUnauthenticatedPublicHeader( |
92 const QuicPacketPublicHeader& header) { | 92 const QuicPacketPublicHeader& header) { |
| 93 current_connection_id_ = header.connection_id; |
| 94 |
93 // Port zero is only allowed for unidirectional UDP, so is disallowed by QUIC. | 95 // Port zero is only allowed for unidirectional UDP, so is disallowed by QUIC. |
94 // Given that we can't even send a reply rejecting the packet, just drop the | 96 // Given that we can't even send a reply rejecting the packet, just drop the |
95 // packet. | 97 // packet. |
96 if (current_client_address_.port() == 0) { | 98 if (current_client_address_.port() == 0) { |
97 return false; | 99 return false; |
98 } | 100 } |
99 | 101 |
100 // Stopgap test: The code does not construct full-length connection IDs | 102 // Stopgap test: The code does not construct full-length connection IDs |
101 // correctly from truncated connection ID fields. Prevent this from causing | 103 // correctly from truncated connection ID fields. Prevent this from causing |
102 // the connection ID lookup to error by dropping any packet with a short | 104 // the connection ID lookup to error by dropping any packet with a short |
(...skipping 27 matching lines...) Expand all Loading... |
130 // The packet has an unknown connection ID. | 132 // The packet has an unknown connection ID. |
131 | 133 |
132 // Unless the packet provides a version, assume that we can continue | 134 // Unless the packet provides a version, assume that we can continue |
133 // processing using our preferred version. | 135 // processing using our preferred version. |
134 QuicVersion version = supported_versions_.front(); | 136 QuicVersion version = supported_versions_.front(); |
135 if (header.version_flag) { | 137 if (header.version_flag) { |
136 QuicVersion packet_version = header.versions.front(); | 138 QuicVersion packet_version = header.versions.front(); |
137 if (framer_.IsSupportedVersion(packet_version)) { | 139 if (framer_.IsSupportedVersion(packet_version)) { |
138 version = packet_version; | 140 version = packet_version; |
139 } else { | 141 } else { |
140 // Packets set to be processed but having an unsupported version will | 142 if (FLAGS_quic_stateless_version_negotiation) { |
141 // cause a connection to be created. The connection will handle | 143 DVLOG(1) << "Version mismatch, connection ID " << connection_id; |
142 // sending a version negotiation packet. | 144 // Since the version is not supported, send a version negotiation |
143 // TODO(ianswett): This will malfunction if the full header of the packet | 145 // packet and stop processing the current packet. |
144 // causes a parsing error when parsed using the server's preferred | 146 time_wait_list_manager()->SendVersionNegotiationPacket( |
145 // version. | 147 connection_id, supported_versions_, current_server_address_, |
| 148 current_client_address_); |
| 149 return false; |
| 150 } else { |
| 151 // Packets set to be processed but having an unsupported version will |
| 152 // cause a connection to be created. The connection will handle |
| 153 // sending a version negotiation packet. |
| 154 // TODO(ianswett): This will malfunction if the full header of the |
| 155 // packet causes a parsing error when parsed using the server's |
| 156 // preferred version. |
| 157 } |
146 } | 158 } |
147 } | 159 } |
148 // Set the framer's version and continue processing. | 160 // Set the framer's version and continue processing. |
149 framer_.set_version(version); | 161 framer_.set_version(version); |
150 return true; | 162 return true; |
151 } | 163 } |
152 | 164 |
153 bool QuicDispatcher::OnUnauthenticatedHeader(const QuicPacketHeader& header) { | 165 bool QuicDispatcher::OnUnauthenticatedHeader(const QuicPacketHeader& header) { |
154 QuicConnectionId connection_id = header.public_header.connection_id; | 166 QuicConnectionId connection_id = header.public_header.connection_id; |
155 | 167 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 void QuicDispatcher::OnPacket() {} | 341 void QuicDispatcher::OnPacket() {} |
330 | 342 |
331 void QuicDispatcher::OnError(QuicFramer* framer) { | 343 void QuicDispatcher::OnError(QuicFramer* framer) { |
332 QuicErrorCode error = framer->error(); | 344 QuicErrorCode error = framer->error(); |
333 SetLastError(error); | 345 SetLastError(error); |
334 DVLOG(1) << QuicUtils::ErrorToString(error); | 346 DVLOG(1) << QuicUtils::ErrorToString(error); |
335 } | 347 } |
336 | 348 |
337 bool QuicDispatcher::OnProtocolVersionMismatch( | 349 bool QuicDispatcher::OnProtocolVersionMismatch( |
338 QuicVersion /*received_version*/) { | 350 QuicVersion /*received_version*/) { |
| 351 if (FLAGS_quic_stateless_version_negotiation) { |
| 352 QUIC_BUG_IF(!time_wait_list_manager_->IsConnectionIdInTimeWait( |
| 353 current_connection_id_)); |
| 354 } |
| 355 |
339 // Keep processing after protocol mismatch - this will be dealt with by the | 356 // Keep processing after protocol mismatch - this will be dealt with by the |
340 // time wait list or connection that we will create. | 357 // time wait list or connection that we will create. |
341 return true; | 358 return true; |
342 } | 359 } |
343 | 360 |
344 void QuicDispatcher::OnPublicResetPacket( | 361 void QuicDispatcher::OnPublicResetPacket( |
345 const QuicPublicResetPacket& /*packet*/) { | 362 const QuicPublicResetPacket& /*packet*/) { |
346 DCHECK(false); | 363 DCHECK(false); |
347 } | 364 } |
348 | 365 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 | 488 |
472 QuicPacketWriter* QuicDispatcher::CreatePerConnectionWriter() { | 489 QuicPacketWriter* QuicDispatcher::CreatePerConnectionWriter() { |
473 return new QuicPerConnectionPacketWriter(writer_.get()); | 490 return new QuicPerConnectionPacketWriter(writer_.get()); |
474 } | 491 } |
475 | 492 |
476 void QuicDispatcher::SetLastError(QuicErrorCode error) { | 493 void QuicDispatcher::SetLastError(QuicErrorCode error) { |
477 last_error_ = error; | 494 last_error_ = error; |
478 } | 495 } |
479 | 496 |
480 } // namespace net | 497 } // namespace net |
OLD | NEW |