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" |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 bool QuicFramer::AppendPacketHeader(const QuicPacketHeader& header, | 648 bool QuicFramer::AppendPacketHeader(const QuicPacketHeader& header, |
649 QuicDataWriter* writer) { | 649 QuicDataWriter* writer) { |
650 QUIC_DVLOG(1) << ENDPOINT << "Appending header: " << header; | 650 QUIC_DVLOG(1) << ENDPOINT << "Appending header: " << header; |
651 uint8_t public_flags = 0; | 651 uint8_t public_flags = 0; |
652 if (header.public_header.reset_flag) { | 652 if (header.public_header.reset_flag) { |
653 public_flags |= PACKET_PUBLIC_FLAGS_RST; | 653 public_flags |= PACKET_PUBLIC_FLAGS_RST; |
654 } | 654 } |
655 if (header.public_header.version_flag) { | 655 if (header.public_header.version_flag) { |
656 public_flags |= PACKET_PUBLIC_FLAGS_VERSION; | 656 public_flags |= PACKET_PUBLIC_FLAGS_VERSION; |
657 } | 657 } |
658 if (header.public_header.multipath_flag) { | |
659 public_flags |= PACKET_PUBLIC_FLAGS_MULTIPATH; | |
660 } | |
661 | 658 |
662 public_flags |= | 659 public_flags |= |
663 GetPacketNumberFlags(header.public_header.packet_number_length) | 660 GetPacketNumberFlags(header.public_header.packet_number_length) |
664 << kPublicHeaderSequenceNumberShift; | 661 << kPublicHeaderSequenceNumberShift; |
665 | 662 |
666 if (header.public_header.nonce != nullptr) { | 663 if (header.public_header.nonce != nullptr) { |
667 DCHECK_EQ(Perspective::IS_SERVER, perspective_); | 664 DCHECK_EQ(Perspective::IS_SERVER, perspective_); |
668 public_flags |= PACKET_PUBLIC_FLAGS_NONCE; | 665 public_flags |= PACKET_PUBLIC_FLAGS_NONCE; |
669 } | 666 } |
670 | 667 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 } | 764 } |
768 | 765 |
769 bool QuicFramer::ProcessPublicHeader(QuicDataReader* reader, | 766 bool QuicFramer::ProcessPublicHeader(QuicDataReader* reader, |
770 QuicPacketPublicHeader* public_header) { | 767 QuicPacketPublicHeader* public_header) { |
771 uint8_t public_flags; | 768 uint8_t public_flags; |
772 if (!reader->ReadBytes(&public_flags, 1)) { | 769 if (!reader->ReadBytes(&public_flags, 1)) { |
773 set_detailed_error("Unable to read public flags."); | 770 set_detailed_error("Unable to read public flags."); |
774 return false; | 771 return false; |
775 } | 772 } |
776 | 773 |
777 public_header->multipath_flag = | |
778 (public_flags & PACKET_PUBLIC_FLAGS_MULTIPATH) != 0; | |
779 public_header->reset_flag = (public_flags & PACKET_PUBLIC_FLAGS_RST) != 0; | 774 public_header->reset_flag = (public_flags & PACKET_PUBLIC_FLAGS_RST) != 0; |
780 public_header->version_flag = | 775 public_header->version_flag = |
781 (public_flags & PACKET_PUBLIC_FLAGS_VERSION) != 0; | 776 (public_flags & PACKET_PUBLIC_FLAGS_VERSION) != 0; |
782 | 777 |
783 if (validate_flags_ && !public_header->version_flag && | 778 if (validate_flags_ && !public_header->version_flag && |
784 public_flags > (FLAGS_quic_reloadable_flag_quic_remove_multipath_bit | 779 public_flags > PACKET_PUBLIC_FLAGS_MAX) { |
785 ? PACKET_PUBLIC_FLAGS_MAX_WITHOUT_MULTIPATH_FLAG | |
786 : PACKET_PUBLIC_FLAGS_MAX)) { | |
787 if (FLAGS_quic_reloadable_flag_quic_remove_multipath_bit) { | |
788 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_remove_multipath_bit, 1, 2); | |
789 } | |
790 set_detailed_error("Illegal public flags value."); | 780 set_detailed_error("Illegal public flags value."); |
791 return false; | 781 return false; |
792 } | 782 } |
793 | 783 |
794 if (public_header->reset_flag && public_header->version_flag) { | 784 if (public_header->reset_flag && public_header->version_flag) { |
795 set_detailed_error("Got version flag in reset packet"); | 785 set_detailed_error("Got version flag in reset packet"); |
796 return false; | 786 return false; |
797 } | 787 } |
798 | 788 |
799 switch (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) { | 789 switch (public_flags & PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID) { |
(...skipping 20 matching lines...) Expand all Loading... |
820 if (!reader->ReadTag(&version_tag)) { | 810 if (!reader->ReadTag(&version_tag)) { |
821 set_detailed_error("Unable to read protocol version."); | 811 set_detailed_error("Unable to read protocol version."); |
822 return false; | 812 return false; |
823 } | 813 } |
824 | 814 |
825 // If the version from the new packet is the same as the version of this | 815 // If the version from the new packet is the same as the version of this |
826 // framer, then the public flags should be set to something we understand. | 816 // framer, then the public flags should be set to something we understand. |
827 // If not, this raises an error. | 817 // If not, this raises an error. |
828 last_version_tag_ = version_tag; | 818 last_version_tag_ = version_tag; |
829 QuicVersion version = QuicTagToQuicVersion(version_tag); | 819 QuicVersion version = QuicTagToQuicVersion(version_tag); |
830 if (version == quic_version_ && | 820 if (version == quic_version_ && public_flags > PACKET_PUBLIC_FLAGS_MAX) { |
831 public_flags > (FLAGS_quic_reloadable_flag_quic_remove_multipath_bit | |
832 ? PACKET_PUBLIC_FLAGS_MAX_WITHOUT_MULTIPATH_FLAG | |
833 : PACKET_PUBLIC_FLAGS_MAX)) { | |
834 if (FLAGS_quic_reloadable_flag_quic_remove_multipath_bit) { | |
835 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_remove_multipath_bit, 1, 2); | |
836 } | |
837 set_detailed_error("Illegal public flags value."); | 821 set_detailed_error("Illegal public flags value."); |
838 return false; | 822 return false; |
839 } | 823 } |
840 public_header->versions.push_back(version); | 824 public_header->versions.push_back(version); |
841 } | 825 } |
842 | 826 |
843 // A nonce should only be present in packets from the server to the client, | 827 // A nonce should only be present in packets from the server to the client, |
844 // which are neither version negotiation nor public reset packets. | 828 // which are neither version negotiation nor public reset packets. |
845 if (public_flags & PACKET_PUBLIC_FLAGS_NONCE && | 829 if (public_flags & PACKET_PUBLIC_FLAGS_NONCE && |
846 !(public_flags & PACKET_PUBLIC_FLAGS_VERSION) && | 830 !(public_flags & PACKET_PUBLIC_FLAGS_VERSION) && |
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2166 set_error(error); | 2150 set_error(error); |
2167 visitor_->OnError(this); | 2151 visitor_->OnError(this); |
2168 return false; | 2152 return false; |
2169 } | 2153 } |
2170 | 2154 |
2171 Endianness QuicFramer::endianness() const { | 2155 Endianness QuicFramer::endianness() const { |
2172 return quic_version_ > QUIC_VERSION_38 ? NETWORK_BYTE_ORDER : HOST_BYTE_ORDER; | 2156 return quic_version_ > QUIC_VERSION_38 ? NETWORK_BYTE_ORDER : HOST_BYTE_ORDER; |
2173 } | 2157 } |
2174 | 2158 |
2175 } // namespace net | 2159 } // namespace net |
OLD | NEW |