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/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 return true; | 684 return true; |
685 } | 685 } |
686 | 686 |
687 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { | 687 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { |
688 DCHECK(connected_); | 688 DCHECK(connected_); |
689 if (debug_visitor_ != nullptr) { | 689 if (debug_visitor_ != nullptr) { |
690 debug_visitor_->OnStreamFrame(frame); | 690 debug_visitor_->OnStreamFrame(frame); |
691 } | 691 } |
692 if (frame.stream_id != kCryptoStreamId && | 692 if (frame.stream_id != kCryptoStreamId && |
693 last_decrypted_packet_level_ == ENCRYPTION_NONE) { | 693 last_decrypted_packet_level_ == ENCRYPTION_NONE) { |
| 694 if (FLAGS_quic_detect_memory_corrpution && |
| 695 MaybeConsiderAsMemoryCorruption(frame)) { |
| 696 CloseConnection(QUIC_MAYBE_CORRUPTED_MEMORY, |
| 697 "Received crypto frame on non crypto stream.", |
| 698 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 699 return false; |
| 700 } |
| 701 |
694 QUIC_BUG << ENDPOINT | 702 QUIC_BUG << ENDPOINT |
695 << "Received an unencrypted data frame: closing connection" | 703 << "Received an unencrypted data frame: closing connection" |
696 << " packet_number:" << last_header_.packet_number | 704 << " packet_number:" << last_header_.packet_number |
697 << " stream_id:" << frame.stream_id | 705 << " stream_id:" << frame.stream_id |
698 << " received_packets:" << received_packet_manager_.ack_frame(); | 706 << " received_packets:" << received_packet_manager_.ack_frame(); |
699 CloseConnection(QUIC_UNENCRYPTED_STREAM_DATA, | 707 CloseConnection(QUIC_UNENCRYPTED_STREAM_DATA, |
700 "Unencrypted stream data seen.", | 708 "Unencrypted stream data seen.", |
701 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 709 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
702 return false; | 710 return false; |
703 } | 711 } |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 ack_queued_ = false; | 1842 ack_queued_ = false; |
1835 stop_waiting_count_ = 0; | 1843 stop_waiting_count_ = 0; |
1836 num_retransmittable_packets_received_since_last_ack_sent_ = 0; | 1844 num_retransmittable_packets_received_since_last_ack_sent_ = 0; |
1837 last_ack_had_missing_packets_ = received_packet_manager_.HasMissingPackets(); | 1845 last_ack_had_missing_packets_ = received_packet_manager_.HasMissingPackets(); |
1838 num_packets_received_since_last_ack_sent_ = 0; | 1846 num_packets_received_since_last_ack_sent_ = 0; |
1839 | 1847 |
1840 packet_generator_.SetShouldSendAck(true); | 1848 packet_generator_.SetShouldSendAck(true); |
1841 } | 1849 } |
1842 | 1850 |
1843 void QuicConnection::OnRetransmissionTimeout() { | 1851 void QuicConnection::OnRetransmissionTimeout() { |
1844 if (FLAGS_quic_always_has_unacked_packets_on_timeout) { | 1852 DCHECK(sent_packet_manager_.HasUnackedPackets()); |
1845 DCHECK(sent_packet_manager_.HasUnackedPackets()); | |
1846 } else { | |
1847 if (!sent_packet_manager_.HasUnackedPackets()) { | |
1848 return; | |
1849 } | |
1850 } | |
1851 | 1853 |
1852 if (close_connection_after_five_rtos_ && | 1854 if (close_connection_after_five_rtos_ && |
1853 sent_packet_manager_.consecutive_rto_count() >= 4) { | 1855 sent_packet_manager_.consecutive_rto_count() >= 4) { |
1854 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. | 1856 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. |
1855 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", | 1857 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", |
1856 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 1858 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
1857 return; | 1859 return; |
1858 } | 1860 } |
1859 | 1861 |
1860 // Cancel the send alarm to ensure TimeUntilSend is re-evaluated. | 1862 // Cancel the send alarm to ensure TimeUntilSend is re-evaluated. |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2433 return received_packet_manager_.ack_frame_updated(); | 2435 return received_packet_manager_.ack_frame_updated(); |
2434 } | 2436 } |
2435 | 2437 |
2436 StringPiece QuicConnection::GetCurrentPacket() { | 2438 StringPiece QuicConnection::GetCurrentPacket() { |
2437 if (current_packet_data_ == nullptr) { | 2439 if (current_packet_data_ == nullptr) { |
2438 return StringPiece(); | 2440 return StringPiece(); |
2439 } | 2441 } |
2440 return StringPiece(current_packet_data_, last_size_); | 2442 return StringPiece(current_packet_data_, last_size_); |
2441 } | 2443 } |
2442 | 2444 |
| 2445 bool QuicConnection::MaybeConsiderAsMemoryCorruption( |
| 2446 const QuicStreamFrame& frame) { |
| 2447 if (frame.stream_id == kCryptoStreamId || |
| 2448 last_decrypted_packet_level_ != ENCRYPTION_NONE) { |
| 2449 return false; |
| 2450 } |
| 2451 |
| 2452 if (perspective_ == Perspective::IS_SERVER && |
| 2453 frame.data_length >= sizeof(kCHLO) && |
| 2454 strncmp(frame.data_buffer, reinterpret_cast<const char*>(&kCHLO), |
| 2455 sizeof(kCHLO)) == 0) { |
| 2456 return true; |
| 2457 } |
| 2458 |
| 2459 if (perspective_ == Perspective::IS_CLIENT && |
| 2460 frame.data_length >= sizeof(kREJ) && |
| 2461 strncmp(frame.data_buffer, reinterpret_cast<const char*>(&kREJ), |
| 2462 sizeof(kREJ)) == 0) { |
| 2463 return true; |
| 2464 } |
| 2465 |
| 2466 return false; |
| 2467 } |
| 2468 |
2443 } // namespace net | 2469 } // namespace net |
OLD | NEW |