| 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/core/quic_framer.h" | 5 #include "net/quic/core/quic_framer.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | |
| 12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 13 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 14 #include "net/quic/core/crypto/crypto_framer.h" | 13 #include "net/quic/core/crypto/crypto_framer.h" |
| 15 #include "net/quic/core/crypto/crypto_handshake_message.h" | 14 #include "net/quic/core/crypto/crypto_handshake_message.h" |
| 16 #include "net/quic/core/crypto/crypto_protocol.h" | 15 #include "net/quic/core/crypto/crypto_protocol.h" |
| 17 #include "net/quic/core/crypto/null_decrypter.h" | 16 #include "net/quic/core/crypto/null_decrypter.h" |
| 18 #include "net/quic/core/crypto/null_encrypter.h" | 17 #include "net/quic/core/crypto/null_encrypter.h" |
| 19 #include "net/quic/core/crypto/quic_decrypter.h" | 18 #include "net/quic/core/crypto/quic_decrypter.h" |
| 20 #include "net/quic/core/crypto/quic_encrypter.h" | 19 #include "net/quic/core/crypto/quic_encrypter.h" |
| 21 #include "net/quic/core/quic_data_reader.h" | 20 #include "net/quic/core/quic_data_reader.h" |
| 22 #include "net/quic/core/quic_data_writer.h" | 21 #include "net/quic/core/quic_data_writer.h" |
| 23 #include "net/quic/core/quic_flags.h" | 22 #include "net/quic/core/quic_flags.h" |
| 24 #include "net/quic/core/quic_socket_address_coder.h" | 23 #include "net/quic/core/quic_socket_address_coder.h" |
| 25 #include "net/quic/core/quic_utils.h" | 24 #include "net/quic/core/quic_utils.h" |
| 26 #include "net/quic/platform/api/quic_aligned.h" | 25 #include "net/quic/platform/api/quic_aligned.h" |
| 27 #include "net/quic/platform/api/quic_bug_tracker.h" | 26 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 27 #include "net/quic/platform/api/quic_logging.h" |
| 28 | 28 |
| 29 using base::ContainsKey; | 29 using base::ContainsKey; |
| 30 using base::StringPiece; | 30 using base::StringPiece; |
| 31 using std::string; | 31 using std::string; |
| 32 #define PREDICT_FALSE(x) (x) | 32 #define PREDICT_FALSE(x) (x) |
| 33 | 33 |
| 34 namespace net { | 34 namespace net { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 if (!first_frame) { | 301 if (!first_frame) { |
| 302 return 0; | 302 return 0; |
| 303 } | 303 } |
| 304 bool can_truncate = | 304 bool can_truncate = |
| 305 frame.type == ACK_FRAME && | 305 frame.type == ACK_FRAME && |
| 306 free_bytes >= | 306 free_bytes >= |
| 307 GetMinAckFrameSize(quic_version_, PACKET_6BYTE_PACKET_NUMBER); | 307 GetMinAckFrameSize(quic_version_, PACKET_6BYTE_PACKET_NUMBER); |
| 308 if (can_truncate) { | 308 if (can_truncate) { |
| 309 // Truncate the frame so the packet will not exceed kMaxPacketSize. | 309 // Truncate the frame so the packet will not exceed kMaxPacketSize. |
| 310 // Note that we may not use every byte of the writer in this case. | 310 // Note that we may not use every byte of the writer in this case. |
| 311 DVLOG(1) << ENDPOINT | 311 QUIC_DLOG(INFO) << ENDPOINT |
| 312 << "Truncating large frame, free bytes: " << free_bytes; | 312 << "Truncating large frame, free bytes: " << free_bytes; |
| 313 return free_bytes; | 313 return free_bytes; |
| 314 } | 314 } |
| 315 return 0; | 315 return 0; |
| 316 } | 316 } |
| 317 | 317 |
| 318 QuicFramer::AckFrameInfo::AckFrameInfo() | 318 QuicFramer::AckFrameInfo::AckFrameInfo() |
| 319 : max_block_length(0), first_block_length(0), num_ack_blocks(0) {} | 319 : max_block_length(0), first_block_length(0), num_ack_blocks(0) {} |
| 320 | 320 |
| 321 QuicFramer::AckFrameInfo::AckFrameInfo(const AckFrameInfo& other) = default; | 321 QuicFramer::AckFrameInfo::AckFrameInfo(const AckFrameInfo& other) = default; |
| 322 | 322 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 499 |
| 500 bool QuicFramer::ProcessPacket(const QuicEncryptedPacket& packet) { | 500 bool QuicFramer::ProcessPacket(const QuicEncryptedPacket& packet) { |
| 501 QuicDataReader reader(packet.data(), packet.length()); | 501 QuicDataReader reader(packet.data(), packet.length()); |
| 502 | 502 |
| 503 visitor_->OnPacket(); | 503 visitor_->OnPacket(); |
| 504 | 504 |
| 505 // First parse the public header. | 505 // First parse the public header. |
| 506 QuicPacketPublicHeader public_header; | 506 QuicPacketPublicHeader public_header; |
| 507 if (!ProcessPublicHeader(&reader, &public_header)) { | 507 if (!ProcessPublicHeader(&reader, &public_header)) { |
| 508 DCHECK_NE("", detailed_error_); | 508 DCHECK_NE("", detailed_error_); |
| 509 DVLOG(1) << ENDPOINT | 509 QUIC_DVLOG(1) << ENDPOINT << "Unable to process public header. Error: " |
| 510 << "Unable to process public header. Error: " << detailed_error_; | 510 << detailed_error_; |
| 511 DCHECK_NE("", detailed_error_); | 511 DCHECK_NE("", detailed_error_); |
| 512 return RaiseError(QUIC_INVALID_PACKET_HEADER); | 512 return RaiseError(QUIC_INVALID_PACKET_HEADER); |
| 513 } | 513 } |
| 514 | 514 |
| 515 if (!visitor_->OnUnauthenticatedPublicHeader(public_header)) { | 515 if (!visitor_->OnUnauthenticatedPublicHeader(public_header)) { |
| 516 // The visitor suppresses further processing of the packet. | 516 // The visitor suppresses further processing of the packet. |
| 517 return true; | 517 return true; |
| 518 } | 518 } |
| 519 | 519 |
| 520 if (perspective_ == Perspective::IS_SERVER && public_header.version_flag && | 520 if (perspective_ == Perspective::IS_SERVER && public_header.version_flag && |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 565 } |
| 566 | 566 |
| 567 bool QuicFramer::ProcessDataPacket(QuicDataReader* encrypted_reader, | 567 bool QuicFramer::ProcessDataPacket(QuicDataReader* encrypted_reader, |
| 568 const QuicPacketPublicHeader& public_header, | 568 const QuicPacketPublicHeader& public_header, |
| 569 const QuicEncryptedPacket& packet, | 569 const QuicEncryptedPacket& packet, |
| 570 char* decrypted_buffer, | 570 char* decrypted_buffer, |
| 571 size_t buffer_length) { | 571 size_t buffer_length) { |
| 572 QuicPacketHeader header(public_header); | 572 QuicPacketHeader header(public_header); |
| 573 if (!ProcessUnauthenticatedHeader(encrypted_reader, &header)) { | 573 if (!ProcessUnauthenticatedHeader(encrypted_reader, &header)) { |
| 574 DCHECK_NE("", detailed_error_); | 574 DCHECK_NE("", detailed_error_); |
| 575 DVLOG(1) << ENDPOINT | 575 QUIC_DVLOG(1) |
| 576 << "Unable to process packet header. Stopping parsing. Error: " | 576 << ENDPOINT |
| 577 << detailed_error_; | 577 << "Unable to process packet header. Stopping parsing. Error: " |
| 578 << detailed_error_; |
| 578 return false; | 579 return false; |
| 579 } | 580 } |
| 580 | 581 |
| 581 size_t decrypted_length = 0; | 582 size_t decrypted_length = 0; |
| 582 if (!DecryptPayload(encrypted_reader, header, packet, decrypted_buffer, | 583 if (!DecryptPayload(encrypted_reader, header, packet, decrypted_buffer, |
| 583 buffer_length, &decrypted_length)) { | 584 buffer_length, &decrypted_length)) { |
| 584 set_detailed_error("Unable to decrypt payload."); | 585 set_detailed_error("Unable to decrypt payload."); |
| 585 return RaiseError(QUIC_DECRYPTION_FAILURE); | 586 return RaiseError(QUIC_DECRYPTION_FAILURE); |
| 586 } | 587 } |
| 587 | 588 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 599 if (packet.length() > kMaxPacketSize) { | 600 if (packet.length() > kMaxPacketSize) { |
| 600 // If the packet has gotten this far, it should not be too large. | 601 // If the packet has gotten this far, it should not be too large. |
| 601 QUIC_BUG << "Packet too large:" << packet.length(); | 602 QUIC_BUG << "Packet too large:" << packet.length(); |
| 602 return RaiseError(QUIC_PACKET_TOO_LARGE); | 603 return RaiseError(QUIC_PACKET_TOO_LARGE); |
| 603 } | 604 } |
| 604 | 605 |
| 605 // Handle the payload. | 606 // Handle the payload. |
| 606 if (!ProcessFrameData(&reader, header)) { | 607 if (!ProcessFrameData(&reader, header)) { |
| 607 DCHECK_NE(QUIC_NO_ERROR, error_); // ProcessFrameData sets the error. | 608 DCHECK_NE(QUIC_NO_ERROR, error_); // ProcessFrameData sets the error. |
| 608 DCHECK_NE("", detailed_error_); | 609 DCHECK_NE("", detailed_error_); |
| 609 DLOG(WARNING) << ENDPOINT | 610 QUIC_DLOG(WARNING) << ENDPOINT << "Unable to process frame data. Error: " |
| 610 << "Unable to process frame data. Error: " << detailed_error_; | 611 << detailed_error_; |
| 611 return false; | 612 return false; |
| 612 } | 613 } |
| 613 | 614 |
| 614 visitor_->OnPacketComplete(); | 615 visitor_->OnPacketComplete(); |
| 615 return true; | 616 return true; |
| 616 } | 617 } |
| 617 | 618 |
| 618 bool QuicFramer::ProcessPublicResetPacket( | 619 bool QuicFramer::ProcessPublicResetPacket( |
| 619 QuicDataReader* reader, | 620 QuicDataReader* reader, |
| 620 const QuicPacketPublicHeader& public_header) { | 621 const QuicPacketPublicHeader& public_header) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 645 QuicSocketAddress(address_coder.ip(), address_coder.port()); | 646 QuicSocketAddress(address_coder.ip(), address_coder.port()); |
| 646 } | 647 } |
| 647 } | 648 } |
| 648 | 649 |
| 649 visitor_->OnPublicResetPacket(packet); | 650 visitor_->OnPublicResetPacket(packet); |
| 650 return true; | 651 return true; |
| 651 } | 652 } |
| 652 | 653 |
| 653 bool QuicFramer::AppendPacketHeader(const QuicPacketHeader& header, | 654 bool QuicFramer::AppendPacketHeader(const QuicPacketHeader& header, |
| 654 QuicDataWriter* writer) { | 655 QuicDataWriter* writer) { |
| 655 DVLOG(1) << ENDPOINT << "Appending header: " << header; | 656 QUIC_DVLOG(1) << ENDPOINT << "Appending header: " << header; |
| 656 uint8_t public_flags = 0; | 657 uint8_t public_flags = 0; |
| 657 if (header.public_header.reset_flag) { | 658 if (header.public_header.reset_flag) { |
| 658 public_flags |= PACKET_PUBLIC_FLAGS_RST; | 659 public_flags |= PACKET_PUBLIC_FLAGS_RST; |
| 659 } | 660 } |
| 660 if (header.public_header.version_flag) { | 661 if (header.public_header.version_flag) { |
| 661 public_flags |= PACKET_PUBLIC_FLAGS_VERSION; | 662 public_flags |= PACKET_PUBLIC_FLAGS_VERSION; |
| 662 } | 663 } |
| 663 if (header.public_header.multipath_flag) { | 664 if (header.public_header.multipath_flag) { |
| 664 public_flags |= PACKET_PUBLIC_FLAGS_MULTIPATH; | 665 public_flags |= PACKET_PUBLIC_FLAGS_MULTIPATH; |
| 665 } | 666 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 691 return false; | 692 return false; |
| 692 } | 693 } |
| 693 break; | 694 break; |
| 694 } | 695 } |
| 695 last_serialized_connection_id_ = header.public_header.connection_id; | 696 last_serialized_connection_id_ = header.public_header.connection_id; |
| 696 | 697 |
| 697 if (header.public_header.version_flag) { | 698 if (header.public_header.version_flag) { |
| 698 DCHECK_EQ(Perspective::IS_CLIENT, perspective_); | 699 DCHECK_EQ(Perspective::IS_CLIENT, perspective_); |
| 699 QuicTag tag = QuicVersionToQuicTag(quic_version_); | 700 QuicTag tag = QuicVersionToQuicTag(quic_version_); |
| 700 writer->WriteUInt32(tag); | 701 writer->WriteUInt32(tag); |
| 701 DVLOG(1) << ENDPOINT << "version = " << quic_version_ << ", tag = '" | 702 QUIC_DVLOG(1) << ENDPOINT << "version = " << quic_version_ << ", tag = '" |
| 702 << QuicTagToString(tag) << "'"; | 703 << QuicTagToString(tag) << "'"; |
| 703 } | 704 } |
| 704 | 705 |
| 705 if (header.public_header.multipath_flag && | 706 if (header.public_header.multipath_flag && |
| 706 !writer->WriteUInt8(header.path_id)) { | 707 !writer->WriteUInt8(header.path_id)) { |
| 707 return false; | 708 return false; |
| 708 } | 709 } |
| 709 | 710 |
| 710 if (header.public_header.nonce != nullptr && | 711 if (header.public_header.nonce != nullptr && |
| 711 !writer->WriteBytes(header.public_header.nonce, | 712 !writer->WriteBytes(header.public_header.nonce, |
| 712 kDiversificationNonceSize)) { | 713 kDiversificationNonceSize)) { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 } | 1032 } |
| 1032 | 1033 |
| 1033 if (frame_type & kQuicFrameTypeSpecialMask) { | 1034 if (frame_type & kQuicFrameTypeSpecialMask) { |
| 1034 // Stream Frame | 1035 // Stream Frame |
| 1035 if (frame_type & kQuicFrameTypeStreamMask) { | 1036 if (frame_type & kQuicFrameTypeStreamMask) { |
| 1036 QuicStreamFrame frame; | 1037 QuicStreamFrame frame; |
| 1037 if (!ProcessStreamFrame(reader, frame_type, &frame)) { | 1038 if (!ProcessStreamFrame(reader, frame_type, &frame)) { |
| 1038 return RaiseError(QUIC_INVALID_STREAM_DATA); | 1039 return RaiseError(QUIC_INVALID_STREAM_DATA); |
| 1039 } | 1040 } |
| 1040 if (!visitor_->OnStreamFrame(frame)) { | 1041 if (!visitor_->OnStreamFrame(frame)) { |
| 1041 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1042 QUIC_DVLOG(1) << ENDPOINT |
| 1043 << "Visitor asked to stop further processing."; |
| 1042 // Returning true since there was no parsing error. | 1044 // Returning true since there was no parsing error. |
| 1043 return true; | 1045 return true; |
| 1044 } | 1046 } |
| 1045 continue; | 1047 continue; |
| 1046 } | 1048 } |
| 1047 | 1049 |
| 1048 // Ack Frame | 1050 // Ack Frame |
| 1049 if (frame_type & kQuicFrameTypeAckMask) { | 1051 if (frame_type & kQuicFrameTypeAckMask) { |
| 1050 QuicAckFrame frame; | 1052 QuicAckFrame frame; |
| 1051 if (!ProcessAckFrame(reader, frame_type, &frame)) { | 1053 if (!ProcessAckFrame(reader, frame_type, &frame)) { |
| 1052 return RaiseError(QUIC_INVALID_ACK_DATA); | 1054 return RaiseError(QUIC_INVALID_ACK_DATA); |
| 1053 } | 1055 } |
| 1054 if (!visitor_->OnAckFrame(frame)) { | 1056 if (!visitor_->OnAckFrame(frame)) { |
| 1055 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1057 QUIC_DVLOG(1) << ENDPOINT |
| 1058 << "Visitor asked to stop further processing."; |
| 1056 // Returning true since there was no parsing error. | 1059 // Returning true since there was no parsing error. |
| 1057 return true; | 1060 return true; |
| 1058 } | 1061 } |
| 1059 continue; | 1062 continue; |
| 1060 } | 1063 } |
| 1061 | 1064 |
| 1062 // This was a special frame type that did not match any | 1065 // This was a special frame type that did not match any |
| 1063 // of the known ones. Error. | 1066 // of the known ones. Error. |
| 1064 set_detailed_error("Illegal frame type."); | 1067 set_detailed_error("Illegal frame type."); |
| 1065 DLOG(WARNING) << ENDPOINT | 1068 QUIC_DLOG(WARNING) << ENDPOINT << "Illegal frame type: " |
| 1066 << "Illegal frame type: " << static_cast<int>(frame_type); | 1069 << static_cast<int>(frame_type); |
| 1067 return RaiseError(QUIC_INVALID_FRAME_DATA); | 1070 return RaiseError(QUIC_INVALID_FRAME_DATA); |
| 1068 } | 1071 } |
| 1069 | 1072 |
| 1070 switch (frame_type) { | 1073 switch (frame_type) { |
| 1071 case PADDING_FRAME: { | 1074 case PADDING_FRAME: { |
| 1072 QuicPaddingFrame frame(reader->BytesRemaining()); | 1075 QuicPaddingFrame frame(reader->BytesRemaining()); |
| 1073 if (!visitor_->OnPaddingFrame(frame)) { | 1076 if (!visitor_->OnPaddingFrame(frame)) { |
| 1074 DVLOG(1) << "Visitor asked to stop further processing."; | 1077 QUIC_DVLOG(1) << "Visitor asked to stop further processing."; |
| 1075 } | 1078 } |
| 1076 // We're done with the packet. | 1079 // We're done with the packet. |
| 1077 return true; | 1080 return true; |
| 1078 } | 1081 } |
| 1079 | 1082 |
| 1080 case RST_STREAM_FRAME: { | 1083 case RST_STREAM_FRAME: { |
| 1081 QuicRstStreamFrame frame; | 1084 QuicRstStreamFrame frame; |
| 1082 if (!ProcessRstStreamFrame(reader, &frame)) { | 1085 if (!ProcessRstStreamFrame(reader, &frame)) { |
| 1083 return RaiseError(QUIC_INVALID_RST_STREAM_DATA); | 1086 return RaiseError(QUIC_INVALID_RST_STREAM_DATA); |
| 1084 } | 1087 } |
| 1085 if (!visitor_->OnRstStreamFrame(frame)) { | 1088 if (!visitor_->OnRstStreamFrame(frame)) { |
| 1086 DVLOG(1) << "Visitor asked to stop further processing."; | 1089 QUIC_DVLOG(1) << "Visitor asked to stop further processing."; |
| 1087 // Returning true since there was no parsing error. | 1090 // Returning true since there was no parsing error. |
| 1088 return true; | 1091 return true; |
| 1089 } | 1092 } |
| 1090 continue; | 1093 continue; |
| 1091 } | 1094 } |
| 1092 | 1095 |
| 1093 case CONNECTION_CLOSE_FRAME: { | 1096 case CONNECTION_CLOSE_FRAME: { |
| 1094 QuicConnectionCloseFrame frame; | 1097 QuicConnectionCloseFrame frame; |
| 1095 if (!ProcessConnectionCloseFrame(reader, &frame)) { | 1098 if (!ProcessConnectionCloseFrame(reader, &frame)) { |
| 1096 return RaiseError(QUIC_INVALID_CONNECTION_CLOSE_DATA); | 1099 return RaiseError(QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 1097 } | 1100 } |
| 1098 | 1101 |
| 1099 if (!visitor_->OnConnectionCloseFrame(frame)) { | 1102 if (!visitor_->OnConnectionCloseFrame(frame)) { |
| 1100 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1103 QUIC_DVLOG(1) << ENDPOINT |
| 1104 << "Visitor asked to stop further processing."; |
| 1101 // Returning true since there was no parsing error. | 1105 // Returning true since there was no parsing error. |
| 1102 return true; | 1106 return true; |
| 1103 } | 1107 } |
| 1104 continue; | 1108 continue; |
| 1105 } | 1109 } |
| 1106 | 1110 |
| 1107 case GOAWAY_FRAME: { | 1111 case GOAWAY_FRAME: { |
| 1108 QuicGoAwayFrame goaway_frame; | 1112 QuicGoAwayFrame goaway_frame; |
| 1109 if (!ProcessGoAwayFrame(reader, &goaway_frame)) { | 1113 if (!ProcessGoAwayFrame(reader, &goaway_frame)) { |
| 1110 return RaiseError(QUIC_INVALID_GOAWAY_DATA); | 1114 return RaiseError(QUIC_INVALID_GOAWAY_DATA); |
| 1111 } | 1115 } |
| 1112 if (!visitor_->OnGoAwayFrame(goaway_frame)) { | 1116 if (!visitor_->OnGoAwayFrame(goaway_frame)) { |
| 1113 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1117 QUIC_DVLOG(1) << ENDPOINT |
| 1118 << "Visitor asked to stop further processing."; |
| 1114 // Returning true since there was no parsing error. | 1119 // Returning true since there was no parsing error. |
| 1115 return true; | 1120 return true; |
| 1116 } | 1121 } |
| 1117 continue; | 1122 continue; |
| 1118 } | 1123 } |
| 1119 | 1124 |
| 1120 case WINDOW_UPDATE_FRAME: { | 1125 case WINDOW_UPDATE_FRAME: { |
| 1121 QuicWindowUpdateFrame window_update_frame; | 1126 QuicWindowUpdateFrame window_update_frame; |
| 1122 if (!ProcessWindowUpdateFrame(reader, &window_update_frame)) { | 1127 if (!ProcessWindowUpdateFrame(reader, &window_update_frame)) { |
| 1123 return RaiseError(QUIC_INVALID_WINDOW_UPDATE_DATA); | 1128 return RaiseError(QUIC_INVALID_WINDOW_UPDATE_DATA); |
| 1124 } | 1129 } |
| 1125 if (!visitor_->OnWindowUpdateFrame(window_update_frame)) { | 1130 if (!visitor_->OnWindowUpdateFrame(window_update_frame)) { |
| 1126 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1131 QUIC_DVLOG(1) << ENDPOINT |
| 1132 << "Visitor asked to stop further processing."; |
| 1127 // Returning true since there was no parsing error. | 1133 // Returning true since there was no parsing error. |
| 1128 return true; | 1134 return true; |
| 1129 } | 1135 } |
| 1130 continue; | 1136 continue; |
| 1131 } | 1137 } |
| 1132 | 1138 |
| 1133 case BLOCKED_FRAME: { | 1139 case BLOCKED_FRAME: { |
| 1134 QuicBlockedFrame blocked_frame; | 1140 QuicBlockedFrame blocked_frame; |
| 1135 if (!ProcessBlockedFrame(reader, &blocked_frame)) { | 1141 if (!ProcessBlockedFrame(reader, &blocked_frame)) { |
| 1136 return RaiseError(QUIC_INVALID_BLOCKED_DATA); | 1142 return RaiseError(QUIC_INVALID_BLOCKED_DATA); |
| 1137 } | 1143 } |
| 1138 if (!visitor_->OnBlockedFrame(blocked_frame)) { | 1144 if (!visitor_->OnBlockedFrame(blocked_frame)) { |
| 1139 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1145 QUIC_DVLOG(1) << ENDPOINT |
| 1146 << "Visitor asked to stop further processing."; |
| 1140 // Returning true since there was no parsing error. | 1147 // Returning true since there was no parsing error. |
| 1141 return true; | 1148 return true; |
| 1142 } | 1149 } |
| 1143 continue; | 1150 continue; |
| 1144 } | 1151 } |
| 1145 | 1152 |
| 1146 case STOP_WAITING_FRAME: { | 1153 case STOP_WAITING_FRAME: { |
| 1147 QuicStopWaitingFrame stop_waiting_frame; | 1154 QuicStopWaitingFrame stop_waiting_frame; |
| 1148 if (!ProcessStopWaitingFrame(reader, header, &stop_waiting_frame)) { | 1155 if (!ProcessStopWaitingFrame(reader, header, &stop_waiting_frame)) { |
| 1149 return RaiseError(QUIC_INVALID_STOP_WAITING_DATA); | 1156 return RaiseError(QUIC_INVALID_STOP_WAITING_DATA); |
| 1150 } | 1157 } |
| 1151 if (!visitor_->OnStopWaitingFrame(stop_waiting_frame)) { | 1158 if (!visitor_->OnStopWaitingFrame(stop_waiting_frame)) { |
| 1152 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1159 QUIC_DVLOG(1) << ENDPOINT |
| 1160 << "Visitor asked to stop further processing."; |
| 1153 // Returning true since there was no parsing error. | 1161 // Returning true since there was no parsing error. |
| 1154 return true; | 1162 return true; |
| 1155 } | 1163 } |
| 1156 continue; | 1164 continue; |
| 1157 } | 1165 } |
| 1158 case PING_FRAME: { | 1166 case PING_FRAME: { |
| 1159 // Ping has no payload. | 1167 // Ping has no payload. |
| 1160 QuicPingFrame ping_frame; | 1168 QuicPingFrame ping_frame; |
| 1161 if (!visitor_->OnPingFrame(ping_frame)) { | 1169 if (!visitor_->OnPingFrame(ping_frame)) { |
| 1162 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1170 QUIC_DVLOG(1) << ENDPOINT |
| 1171 << "Visitor asked to stop further processing."; |
| 1163 // Returning true since there was no parsing error. | 1172 // Returning true since there was no parsing error. |
| 1164 return true; | 1173 return true; |
| 1165 } | 1174 } |
| 1166 continue; | 1175 continue; |
| 1167 } | 1176 } |
| 1168 case PATH_CLOSE_FRAME: { | 1177 case PATH_CLOSE_FRAME: { |
| 1169 QuicPathCloseFrame path_close_frame; | 1178 QuicPathCloseFrame path_close_frame; |
| 1170 if (!ProcessPathCloseFrame(reader, &path_close_frame)) { | 1179 if (!ProcessPathCloseFrame(reader, &path_close_frame)) { |
| 1171 return RaiseError(QUIC_INVALID_PATH_CLOSE_DATA); | 1180 return RaiseError(QUIC_INVALID_PATH_CLOSE_DATA); |
| 1172 } | 1181 } |
| 1173 if (!visitor_->OnPathCloseFrame(path_close_frame)) { | 1182 if (!visitor_->OnPathCloseFrame(path_close_frame)) { |
| 1174 DVLOG(1) << ENDPOINT << "Visitor asked to stop further processing."; | 1183 QUIC_DVLOG(1) << ENDPOINT |
| 1184 << "Visitor asked to stop further processing."; |
| 1175 // Returning true since there was no parsing error. | 1185 // Returning true since there was no parsing error. |
| 1176 return true; | 1186 return true; |
| 1177 } | 1187 } |
| 1178 continue; | 1188 continue; |
| 1179 } | 1189 } |
| 1180 | 1190 |
| 1181 default: | 1191 default: |
| 1182 set_detailed_error("Illegal frame type."); | 1192 set_detailed_error("Illegal frame type."); |
| 1183 DLOG(WARNING) << ENDPOINT | 1193 QUIC_DLOG(WARNING) << ENDPOINT << "Illegal frame type: " |
| 1184 << "Illegal frame type: " << static_cast<int>(frame_type); | 1194 << static_cast<int>(frame_type); |
| 1185 return RaiseError(QUIC_INVALID_FRAME_DATA); | 1195 return RaiseError(QUIC_INVALID_FRAME_DATA); |
| 1186 } | 1196 } |
| 1187 } | 1197 } |
| 1188 | 1198 |
| 1189 return true; | 1199 return true; |
| 1190 } | 1200 } |
| 1191 | 1201 |
| 1192 bool QuicFramer::ProcessStreamFrame(QuicDataReader* reader, | 1202 bool QuicFramer::ProcessStreamFrame(QuicDataReader* reader, |
| 1193 uint8_t frame_type, | 1203 uint8_t frame_type, |
| 1194 QuicStreamFrame* frame) { | 1204 QuicStreamFrame* frame) { |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 // Switch the alternative decrypter so that we use it first next time. | 1684 // Switch the alternative decrypter so that we use it first next time. |
| 1675 decrypter_.swap(alternative_decrypter_); | 1685 decrypter_.swap(alternative_decrypter_); |
| 1676 EncryptionLevel level = alternative_decrypter_level_; | 1686 EncryptionLevel level = alternative_decrypter_level_; |
| 1677 alternative_decrypter_level_ = decrypter_level_; | 1687 alternative_decrypter_level_ = decrypter_level_; |
| 1678 decrypter_level_ = level; | 1688 decrypter_level_ = level; |
| 1679 } | 1689 } |
| 1680 } | 1690 } |
| 1681 } | 1691 } |
| 1682 | 1692 |
| 1683 if (!success) { | 1693 if (!success) { |
| 1684 DVLOG(1) << ENDPOINT << "DecryptPacket failed for packet_number:" | 1694 QUIC_DVLOG(1) << ENDPOINT << "DecryptPacket failed for packet_number:" |
| 1685 << header.packet_number; | 1695 << header.packet_number; |
| 1686 return false; | 1696 return false; |
| 1687 } | 1697 } |
| 1688 | 1698 |
| 1689 return true; | 1699 return true; |
| 1690 } | 1700 } |
| 1691 | 1701 |
| 1692 size_t QuicFramer::GetAckFrameTimeStampSize(const QuicAckFrame& ack) { | 1702 size_t QuicFramer::GetAckFrameTimeStampSize(const QuicAckFrame& ack) { |
| 1693 if (ack.received_packet_times.empty()) { | 1703 if (ack.received_packet_times.empty()) { |
| 1694 return 0; | 1704 return 0; |
| 1695 } | 1705 } |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2192 bool QuicFramer::AppendPathCloseFrame(const QuicPathCloseFrame& frame, | 2202 bool QuicFramer::AppendPathCloseFrame(const QuicPathCloseFrame& frame, |
| 2193 QuicDataWriter* writer) { | 2203 QuicDataWriter* writer) { |
| 2194 uint8_t path_id = static_cast<uint8_t>(frame.path_id); | 2204 uint8_t path_id = static_cast<uint8_t>(frame.path_id); |
| 2195 if (!writer->WriteUInt8(path_id)) { | 2205 if (!writer->WriteUInt8(path_id)) { |
| 2196 return false; | 2206 return false; |
| 2197 } | 2207 } |
| 2198 return true; | 2208 return true; |
| 2199 } | 2209 } |
| 2200 | 2210 |
| 2201 bool QuicFramer::RaiseError(QuicErrorCode error) { | 2211 bool QuicFramer::RaiseError(QuicErrorCode error) { |
| 2202 DVLOG(1) << ENDPOINT << "Error: " << QuicErrorCodeToString(error) | 2212 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error) |
| 2203 << " detail: " << detailed_error_; | 2213 << " detail: " << detailed_error_; |
| 2204 set_error(error); | 2214 set_error(error); |
| 2205 visitor_->OnError(this); | 2215 visitor_->OnError(this); |
| 2206 return false; | 2216 return false; |
| 2207 } | 2217 } |
| 2208 | 2218 |
| 2209 } // namespace net | 2219 } // namespace net |
| OLD | NEW |