gfe-relnote: (n/a) Deprecate --gfe2_restart_flag_quic_remove_quic_socket_utils_from_packet_reader. PiperOrigin-RevId: 297834756 Change-Id: I5ca9b80a772e9fd5fc92eeb7ea5939da17deba5c
diff --git a/quic/core/quic_epoll_connection_helper.cc b/quic/core/quic_epoll_connection_helper.cc index 1f5fb87..3bfe7e6 100644 --- a/quic/core/quic_epoll_connection_helper.cc +++ b/quic/core/quic_epoll_connection_helper.cc
@@ -8,7 +8,6 @@ #include <sys/socket.h> #include "net/third_party/quiche/src/quic/core/crypto/quic_random.h" -#include "net/quic/platform/impl/quic_socket_utils.h" namespace quic {
diff --git a/quic/core/quic_packet_reader.cc b/quic/core/quic_packet_reader.cc index 79ebb84..dd76e75 100644 --- a/quic/core/quic_packet_reader.cc +++ b/quic/core/quic_packet_reader.cc
@@ -4,14 +4,6 @@ #include "net/third_party/quiche/src/quic/core/quic_packet_reader.h" -#include <errno.h> -#ifndef __APPLE__ -// This is a GNU header that is not present on Apple platforms -#include <features.h> -#endif -#include <string.h> -#include <sys/socket.h> - #include "net/third_party/quiche/src/quic/core/quic_packets.h" #include "net/third_party/quiche/src/quic/core/quic_process_packet_interface.h" #include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h" @@ -23,22 +15,11 @@ #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" #include "net/third_party/quiche/src/common/platform/api/quiche_arraysize.h" -#ifndef SO_RXQ_OVFL -#define SO_RXQ_OVFL 40 -#endif - namespace quic { QuicPacketReader::QuicPacketReader() : read_buffers_(kNumPacketsPerReadMmsgCall), read_results_(kNumPacketsPerReadMmsgCall) { - if (!remove_quic_socket_utils_from_packet_reader_) { - Initialize(); - return; - } - - QUIC_RESTART_FLAG_COUNT_N(quic_remove_quic_socket_utils_from_packet_reader, 1, - 5); DCHECK_EQ(read_buffers_.size(), read_results_.size()); for (size_t i = 0; i < read_results_.size(); ++i) { read_results_[i].packet_buffer.buffer = read_buffers_[i].packet_buffer; @@ -51,30 +32,6 @@ } } -void QuicPacketReader::Initialize() { -#if MMSG_MORE - // Zero initialize uninitialized memory. - memset(mmsg_hdr_, 0, sizeof(mmsg_hdr_)); - - for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { - packets_[i].iov.iov_base = packets_[i].buf; - packets_[i].iov.iov_len = sizeof(packets_[i].buf); - memset(&packets_[i].raw_address, 0, sizeof(packets_[i].raw_address)); - memset(packets_[i].cbuf, 0, sizeof(packets_[i].cbuf)); - memset(packets_[i].buf, 0, sizeof(packets_[i].buf)); - - msghdr* hdr = &mmsg_hdr_[i].msg_hdr; - hdr->msg_name = &packets_[i].raw_address; - hdr->msg_namelen = sizeof(sockaddr_storage); - hdr->msg_iov = &packets_[i].iov; - hdr->msg_iovlen = 1; - - hdr->msg_control = packets_[i].cbuf; - hdr->msg_controllen = kCmsgSpaceForReadPacket; - } -#endif -} - QuicPacketReader::~QuicPacketReader() = default; bool QuicPacketReader::ReadAndDispatchPackets( @@ -82,17 +39,7 @@ int port, const QuicClock& clock, ProcessPacketInterface* processor, - QuicPacketCount* packets_dropped) { - if (!remove_quic_socket_utils_from_packet_reader_) { -#if MMSG_MORE_NO_ANDROID - return ReadAndDispatchManyPackets(fd, port, clock, processor, - packets_dropped); -#else - return ReadAndDispatchSinglePacket(fd, port, clock, processor, - packets_dropped); -#endif - } - + QuicPacketCount* /*packets_dropped*/) { // Reset all read_results for reuse. for (size_t i = 0; i < read_results_.size(); ++i) { read_results_[i].Reset( @@ -120,8 +67,7 @@ for (size_t i = 0; i < packets_read; ++i) { auto& result = read_results_[i]; if (!result.ok) { - QUIC_RESTART_FLAG_COUNT_N( - quic_remove_quic_socket_utils_from_packet_reader, 2, 5); + QUIC_CODE_COUNT(quic_packet_reader_read_failure); continue; } @@ -144,16 +90,11 @@ result.packet_info.HasValue(QuicUdpPacketInfoBit::RECV_TIMESTAMP) ? result.packet_info.receive_timestamp() : wallnow; - if (!result.packet_info.HasValue(QuicUdpPacketInfoBit::RECV_TIMESTAMP)) { - QUIC_RESTART_FLAG_COUNT_N( - quic_remove_quic_socket_utils_from_packet_reader, 3, 5); - } bool has_ttl = result.packet_info.HasValue(QuicUdpPacketInfoBit::TTL); int ttl = has_ttl ? result.packet_info.ttl() : 0; if (!has_ttl) { - QUIC_RESTART_FLAG_COUNT_N( - quic_remove_quic_socket_utils_from_packet_reader, 4, 5); + QUIC_CODE_COUNT(quic_packet_reader_no_ttl); } char* headers = nullptr; @@ -163,8 +104,7 @@ headers = result.packet_info.google_packet_headers().buffer; headers_length = result.packet_info.google_packet_headers().buffer_len; } else { - QUIC_RESTART_FLAG_COUNT_N( - quic_remove_quic_socket_utils_from_packet_reader, 5, 5); + QUIC_CODE_COUNT(quic_packet_reader_no_google_packet_header); } QuicReceivedPacket packet( @@ -203,142 +143,4 @@ return QuicIpAddress(); } -bool QuicPacketReader::ReadAndDispatchManyPackets( - int fd, - int port, - const QuicClock& clock, - ProcessPacketInterface* processor, - QuicPacketCount* packets_dropped) { - DCHECK(!remove_quic_socket_utils_from_packet_reader_); -#if MMSG_MORE_NO_ANDROID - // Re-set the length fields in case recvmmsg has changed them. - for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { - DCHECK_LE(kMaxOutgoingPacketSize, packets_[i].iov.iov_len); - msghdr* hdr = &mmsg_hdr_[i].msg_hdr; - hdr->msg_namelen = sizeof(sockaddr_storage); - DCHECK_EQ(1u, hdr->msg_iovlen); - hdr->msg_controllen = kCmsgSpaceForReadPacket; - hdr->msg_flags = 0; - } - - int packets_read = - recvmmsg(fd, mmsg_hdr_, kNumPacketsPerReadMmsgCall, MSG_TRUNC, nullptr); - - if (packets_read <= 0) { - return false; // recvmmsg failed. - } - - QuicWallTime fallback_walltimestamp = QuicWallTime::Zero(); - for (int i = 0; i < packets_read; ++i) { - if (mmsg_hdr_[i].msg_len == 0) { - continue; - } - - if (QUIC_PREDICT_FALSE(mmsg_hdr_[i].msg_hdr.msg_flags & MSG_CTRUNC)) { - QUIC_BUG << "Incorrectly set control length: " - << mmsg_hdr_[i].msg_hdr.msg_controllen << ", expected " - << kCmsgSpaceForReadPacket; - continue; - } - - if (QUIC_PREDICT_FALSE(mmsg_hdr_[i].msg_hdr.msg_flags & MSG_TRUNC)) { - QUIC_LOG_FIRST_N(WARNING, 100) - << "Dropping truncated QUIC packet: buffer size:" - << packets_[i].iov.iov_len << " packet size:" << mmsg_hdr_[i].msg_len; - QUIC_SERVER_HISTOGRAM_COUNTS( - "QuicPacketReader.DroppedPacketSize", mmsg_hdr_[i].msg_len, 1, 10000, - 20, "In QuicPacketReader, the size of big packets that are dropped."); - continue; - } - - QuicSocketAddress peer_address(packets_[i].raw_address); - QuicIpAddress self_ip; - QuicWallTime packet_walltimestamp = QuicWallTime::Zero(); - QuicSocketUtils::GetAddressAndTimestampFromMsghdr( - &mmsg_hdr_[i].msg_hdr, &self_ip, &packet_walltimestamp); - if (!self_ip.IsInitialized()) { - QUIC_BUG << "Unable to get self IP address."; - continue; - } - - if (packet_walltimestamp.IsZero()) { - if (fallback_walltimestamp.IsZero()) { - fallback_walltimestamp = clock.WallNow(); - } - packet_walltimestamp = fallback_walltimestamp; - } - QuicTime timestamp = clock.ConvertWallTimeToQuicTime(packet_walltimestamp); - - int ttl = 0; - bool has_ttl = - QuicSocketUtils::GetTtlFromMsghdr(&mmsg_hdr_[i].msg_hdr, &ttl); - char* headers = nullptr; - size_t headers_length = 0; - QuicSocketUtils::GetPacketHeadersFromMsghdr(&mmsg_hdr_[i].msg_hdr, &headers, - &headers_length); - QuicReceivedPacket packet(reinterpret_cast<char*>(packets_[i].iov.iov_base), - mmsg_hdr_[i].msg_len, timestamp, false, ttl, - has_ttl, headers, headers_length, false); - QuicSocketAddress self_address(self_ip, port); - processor->ProcessPacket(self_address, peer_address, packet); - } - - if (packets_dropped != nullptr) { - QuicSocketUtils::GetOverflowFromMsghdr(&mmsg_hdr_[0].msg_hdr, - packets_dropped); - } - - // We may not have read all of the packets available on the socket. - return packets_read == kNumPacketsPerReadMmsgCall; -#else - (void)fd; - (void)port; - (void)clock; - (void)processor; - (void)packets_dropped; - QUIC_LOG(FATAL) << "Unsupported"; - return false; -#endif -} - -/* static */ -bool QuicPacketReader::ReadAndDispatchSinglePacket( - int fd, - int port, - const QuicClock& clock, - ProcessPacketInterface* processor, - QuicPacketCount* packets_dropped) { - DCHECK(!GetQuicRestartFlag(quic_remove_quic_socket_utils_from_packet_reader)); - char buf[kMaxV4PacketSize]; - - QuicSocketAddress peer_address; - QuicIpAddress self_ip; - QuicWallTime walltimestamp = QuicWallTime::Zero(); - int bytes_read = QuicSocketUtils::ReadPacket(fd, buf, QUICHE_ARRAYSIZE(buf), - packets_dropped, &self_ip, - &walltimestamp, &peer_address); - if (bytes_read < 0) { - return false; // ReadPacket failed. - } - - if (!self_ip.IsInitialized()) { - QUIC_BUG << "Unable to get self IP address."; - return false; - } - // This isn't particularly desirable, but not all platforms support socket - // timestamping. - if (walltimestamp.IsZero()) { - walltimestamp = clock.WallNow(); - } - QuicTime timestamp = clock.ConvertWallTimeToQuicTime(walltimestamp); - - QuicReceivedPacket packet(buf, bytes_read, timestamp, false); - QuicSocketAddress self_address(self_ip, port); - processor->ProcessPacket(self_address, peer_address, packet); - - // The socket read was successful, so return true even if packet dispatch - // failed. - return true; -} - } // namespace quic
diff --git a/quic/core/quic_packet_reader.h b/quic/core/quic_packet_reader.h index df366eb..86eaa0e 100644 --- a/quic/core/quic_packet_reader.h +++ b/quic/core/quic_packet_reader.h
@@ -7,11 +7,6 @@ #ifndef QUICHE_QUIC_CORE_QUIC_PACKET_READER_H_ #define QUICHE_QUIC_CORE_QUIC_PACKET_READER_H_ -#include <netinet/in.h> -// Include here to guarantee this header gets included (for MSG_WAITFORONE) -// regardless of how the below transitive header include set may change. -#include <sys/socket.h> - #include "net/third_party/quiche/src/quic/core/quic_clock.h" #include "net/third_party/quiche/src/quic/core/quic_packets.h" #include "net/third_party/quiche/src/quic/core/quic_process_packet_interface.h" @@ -19,7 +14,6 @@ #include "net/third_party/quiche/src/quic/platform/api/quic_aligned.h" #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" -#include "net/quic/platform/impl/quic_socket_utils.h" namespace quic { @@ -48,23 +42,6 @@ QuicPacketCount* packets_dropped); private: - // Initialize the internal state of the reader. - void Initialize(); - - // Reads and dispatches many packets using recvmmsg. - bool ReadAndDispatchManyPackets(int fd, - int port, - const QuicClock& clock, - ProcessPacketInterface* processor, - QuicPacketCount* packets_dropped); - - // Reads and dispatches a single packet using recvmsg. - static bool ReadAndDispatchSinglePacket(int fd, - int port, - const QuicClock& clock, - ProcessPacketInterface* processor, - QuicPacketCount* packets_dropped); - // Return the self ip from |packet_info|. // For dual stack sockets, |packet_info| may contain both a v4 and a v6 ip, in // that case, |prefer_v6_ip| is used to determine which one is used as the @@ -73,34 +50,13 @@ const QuicUdpPacketInfo& packet_info, bool prefer_v6_ip); -#if MMSG_MORE - // Storage only used when recvmmsg is available. - // TODO(danzh): change it to be a pointer to avoid the allocation on the stack - // from exceeding maximum allowed frame size. - // packets_ and mmsg_hdr_ are used to supply cbuf and buf to the recvmmsg - // call. - struct QUIC_EXPORT_PRIVATE PacketData { - iovec iov; - // raw_address is used for address information provided by the recvmmsg - // call on the packets. - struct sockaddr_storage raw_address; - // cbuf is used for ancillary data from the kernel on recvmmsg. - char cbuf[kCmsgSpaceForReadPacket]; - // buf is used for the data read from the kernel on recvmmsg. - char buf[kMaxV4PacketSize]; - }; - PacketData packets_[kNumPacketsPerReadMmsgCall]; - mmsghdr mmsg_hdr_[kNumPacketsPerReadMmsgCall]; -#endif struct QUIC_EXPORT_PRIVATE ReadBuffer { QUIC_CACHELINE_ALIGNED char control_buffer[kDefaultUdpPacketControlBufferSize]; // For ancillary // data. QUIC_CACHELINE_ALIGNED char packet_buffer[kMaxIncomingPacketSize]; }; - // Latched value of --quic_remove_quic_socket_utils_from_packet_reader. - const bool remove_quic_socket_utils_from_packet_reader_ = - GetQuicRestartFlag(quic_remove_quic_socket_utils_from_packet_reader); + QuicUdpSocketApi socket_api_; std::vector<ReadBuffer> read_buffers_; QuicUdpSocketApi::ReadPacketResults read_results_;