| 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 <errno.h> | 7 #include <errno.h> |
| 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" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "net/quic/quic_blocked_writer_interface.h" | 12 #include "net/quic/quic_blocked_writer_interface.h" |
| 13 #include "net/quic/quic_flags.h" | 13 #include "net/quic/quic_flags.h" |
| 14 #include "net/quic/quic_utils.h" | 14 #include "net/quic/quic_utils.h" |
| 15 #include "net/tools/epoll_server/epoll_server.h" | 15 #include "net/tools/epoll_server/epoll_server.h" |
| 16 #include "net/tools/quic/quic_default_packet_writer.h" | 16 #include "net/tools/quic/quic_default_packet_writer.h" |
| 17 #include "net/tools/quic/quic_epoll_connection_helper.h" | 17 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 18 #include "net/tools/quic/quic_per_connection_packet_writer.h" | 18 #include "net/tools/quic/quic_per_connection_packet_writer.h" |
| 19 #include "net/tools/quic/quic_socket_utils.h" | 19 #include "net/tools/quic/quic_socket_utils.h" |
| 20 #include "net/tools/quic/quic_time_wait_list_manager.h" | 20 #include "net/tools/quic/quic_time_wait_list_manager.h" |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 namespace tools { | 24 namespace tools { |
| 25 | 25 |
| 26 using base::StringPiece; | 26 using base::StringPiece; |
| 27 using std::make_pair; | |
| 28 | 27 |
| 29 class DeleteSessionsAlarm : public EpollAlarm { | 28 class DeleteSessionsAlarm : public EpollAlarm { |
| 30 public: | 29 public: |
| 31 explicit DeleteSessionsAlarm(QuicDispatcher* dispatcher) | 30 explicit DeleteSessionsAlarm(QuicDispatcher* dispatcher) |
| 32 : dispatcher_(dispatcher) { | 31 : dispatcher_(dispatcher) { |
| 33 } | 32 } |
| 34 | 33 |
| 35 int64 OnAlarm() override { | 34 int64 OnAlarm() override { |
| 36 EpollAlarm::OnAlarm(); | 35 EpollAlarm::OnAlarm(); |
| 37 dispatcher_->DeleteSessions(); | 36 dispatcher_->DeleteSessions(); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // in OnAuthenticatedHeader. | 201 // in OnAuthenticatedHeader. |
| 203 framer_.ProcessPacket(packet); | 202 framer_.ProcessPacket(packet); |
| 204 // TODO(rjshade): Return a status describing if/why a packet was dropped, | 203 // TODO(rjshade): Return a status describing if/why a packet was dropped, |
| 205 // and log somehow. Maybe expose as a varz. | 204 // and log somehow. Maybe expose as a varz. |
| 206 } | 205 } |
| 207 | 206 |
| 208 bool QuicDispatcher::OnUnauthenticatedPublicHeader( | 207 bool QuicDispatcher::OnUnauthenticatedPublicHeader( |
| 209 const QuicPacketPublicHeader& header) { | 208 const QuicPacketPublicHeader& header) { |
| 210 QuicSession* session = nullptr; | 209 QuicSession* session = nullptr; |
| 211 | 210 |
| 211 // Port zero is only allowed for unidirectional UDP, so is disallowed by QUIC. |
| 212 // Given that we can't even send a reply rejecting the packet, just black hole |
| 213 // it. |
| 214 if (current_client_address_.port() == 0) { |
| 215 return false; |
| 216 } |
| 217 |
| 212 QuicConnectionId connection_id = header.connection_id; | 218 QuicConnectionId connection_id = header.connection_id; |
| 213 SessionMap::iterator it = session_map_.find(connection_id); | 219 SessionMap::iterator it = session_map_.find(connection_id); |
| 214 if (it == session_map_.end()) { | 220 if (it == session_map_.end()) { |
| 215 if (header.reset_flag) { | 221 if (header.reset_flag) { |
| 216 return false; | 222 return false; |
| 217 } | 223 } |
| 218 if (time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { | 224 if (time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)) { |
| 219 return HandlePacketForTimeWait(header); | 225 return HandlePacketForTimeWait(header); |
| 220 } | 226 } |
| 221 | 227 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 240 | 246 |
| 241 // Use the version in the packet if possible, otherwise assume the latest. | 247 // Use the version in the packet if possible, otherwise assume the latest. |
| 242 QuicVersion version = header.version_flag ? header.versions.front() : | 248 QuicVersion version = header.version_flag ? header.versions.front() : |
| 243 supported_versions_.front(); | 249 supported_versions_.front(); |
| 244 time_wait_list_manager_->AddConnectionIdToTimeWait(connection_id, version, | 250 time_wait_list_manager_->AddConnectionIdToTimeWait(connection_id, version, |
| 245 nullptr); | 251 nullptr); |
| 246 DCHECK(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); | 252 DCHECK(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); |
| 247 return HandlePacketForTimeWait(header); | 253 return HandlePacketForTimeWait(header); |
| 248 } | 254 } |
| 249 DVLOG(1) << "Created new session for " << connection_id; | 255 DVLOG(1) << "Created new session for " << connection_id; |
| 250 session_map_.insert(make_pair(connection_id, session)); | 256 session_map_.insert(std::make_pair(connection_id, session)); |
| 251 } else { | 257 } else { |
| 252 session = it->second; | 258 session = it->second; |
| 253 } | 259 } |
| 254 | 260 |
| 255 session->connection()->ProcessUdpPacket( | 261 session->connection()->ProcessUdpPacket( |
| 256 current_server_address_, current_client_address_, *current_packet_); | 262 current_server_address_, current_client_address_, *current_packet_); |
| 257 | 263 |
| 258 // Do not parse the packet further. The session will process it completely. | 264 // Do not parse the packet further. The session will process it completely. |
| 259 return false; | 265 return false; |
| 260 } | 266 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 344 |
| 339 void QuicDispatcher::OnWriteBlocked( | 345 void QuicDispatcher::OnWriteBlocked( |
| 340 QuicBlockedWriterInterface* blocked_writer) { | 346 QuicBlockedWriterInterface* blocked_writer) { |
| 341 if (!writer_->IsWriteBlocked()) { | 347 if (!writer_->IsWriteBlocked()) { |
| 342 LOG(DFATAL) << | 348 LOG(DFATAL) << |
| 343 "QuicDispatcher::OnWriteBlocked called when the writer is not blocked."; | 349 "QuicDispatcher::OnWriteBlocked called when the writer is not blocked."; |
| 344 // Return without adding the connection to the blocked list, to avoid | 350 // Return without adding the connection to the blocked list, to avoid |
| 345 // infinite loops in OnCanWrite. | 351 // infinite loops in OnCanWrite. |
| 346 return; | 352 return; |
| 347 } | 353 } |
| 348 write_blocked_list_.insert(make_pair(blocked_writer, true)); | 354 write_blocked_list_.insert(std::make_pair(blocked_writer, true)); |
| 349 } | 355 } |
| 350 | 356 |
| 351 void QuicDispatcher::OnConnectionAddedToTimeWaitList( | 357 void QuicDispatcher::OnConnectionAddedToTimeWaitList( |
| 352 QuicConnectionId connection_id) { | 358 QuicConnectionId connection_id) { |
| 353 DVLOG(1) << "Connection " << connection_id << " added to time wait list."; | 359 DVLOG(1) << "Connection " << connection_id << " added to time wait list."; |
| 354 } | 360 } |
| 355 | 361 |
| 356 void QuicDispatcher::OnConnectionRemovedFromTimeWaitList( | 362 void QuicDispatcher::OnConnectionRemovedFromTimeWaitList( |
| 357 QuicConnectionId connection_id) { | 363 QuicConnectionId connection_id) { |
| 358 DVLOG(1) << "Connection " << connection_id << " removed from time wait list."; | 364 DVLOG(1) << "Connection " << connection_id << " removed from time wait list."; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 411 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
| 406 header.connection_id)); | 412 header.connection_id)); |
| 407 | 413 |
| 408 // Continue parsing the packet to extract the sequence number. Then | 414 // Continue parsing the packet to extract the sequence number. Then |
| 409 // send it to the time wait manager in OnUnathenticatedHeader. | 415 // send it to the time wait manager in OnUnathenticatedHeader. |
| 410 return true; | 416 return true; |
| 411 } | 417 } |
| 412 | 418 |
| 413 } // namespace tools | 419 } // namespace tools |
| 414 } // namespace net | 420 } // namespace net |
| OLD | NEW |