diff options
Diffstat (limited to 'net/tools/quic/quic_packet_reader.cc')
-rw-r--r-- | net/tools/quic/quic_packet_reader.cc | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/net/tools/quic/quic_packet_reader.cc b/net/tools/quic/quic_packet_reader.cc index 3f5f8c8..beba973 100644 --- a/net/tools/quic/quic_packet_reader.cc +++ b/net/tools/quic/quic_packet_reader.cc @@ -53,7 +53,7 @@ void QuicPacketReader::Initialize() { hdr->msg_iovlen = 1; hdr->msg_control = packets_[i].cbuf; - hdr->msg_controllen = kSpaceForOverflowAndIp; + hdr->msg_controllen = QuicSocketUtils::kSpaceForCmsg; } #endif } @@ -63,18 +63,22 @@ QuicPacketReader::~QuicPacketReader() {} bool QuicPacketReader::ReadAndDispatchPackets( int fd, int port, + const QuicClock& clock, ProcessPacketInterface* processor, QuicPacketCount* packets_dropped) { #if MMSG_MORE - return ReadAndDispatchManyPackets(fd, port, processor, packets_dropped); + return ReadAndDispatchManyPackets(fd, port, clock, processor, + packets_dropped); #else - return ReadAndDispatchSinglePacket(fd, port, processor, packets_dropped); + return ReadAndDispatchSinglePacket(fd, port, clock, processor, + packets_dropped); #endif } bool QuicPacketReader::ReadAndDispatchManyPackets( int fd, int port, + const QuicClock& clock, ProcessPacketInterface* processor, QuicPacketCount* packets_dropped) { #if MMSG_MORE @@ -84,7 +88,7 @@ bool QuicPacketReader::ReadAndDispatchManyPackets( msghdr* hdr = &mmsg_hdr_[i].msg_hdr; hdr->msg_namelen = sizeof(sockaddr_storage); DCHECK_EQ(1, hdr->msg_iovlen); - hdr->msg_controllen = kSpaceForOverflowAndIp; + hdr->msg_controllen = QuicSocketUtils::kSpaceForCmsg; } int packets_read = @@ -94,22 +98,42 @@ bool QuicPacketReader::ReadAndDispatchManyPackets( return false; // recvmmsg failed. } + QuicTime fallback_timestamp = QuicTime::Zero(); for (int i = 0; i < packets_read; ++i) { if (mmsg_hdr_[i].msg_len == 0) { continue; } + if (mmsg_hdr_[i].msg_hdr.msg_controllen >= QuicSocketUtils::kSpaceForCmsg) { + QUIC_BUG << "Incorrectly set control length: " + << mmsg_hdr_[i].msg_hdr.msg_controllen << ", expected " + << QuicSocketUtils::kSpaceForCmsg; + continue; + } + IPEndPoint client_address = IPEndPoint(packets_[i].raw_address); - IPAddressNumber server_ip = - QuicSocketUtils::GetAddressFromMsghdr(&mmsg_hdr_[i].msg_hdr); + IPAddressNumber server_ip; + QuicTime packet_timestamp = QuicTime::Zero(); + QuicSocketUtils::GetAddressAndTimestampFromMsghdr( + &mmsg_hdr_[i].msg_hdr, &server_ip, &packet_timestamp); if (!IsInitializedAddress(server_ip)) { QUIC_BUG << "Unable to get server address."; continue; } - QuicEncryptedPacket packet( - reinterpret_cast<char*>(packets_[i].iov.iov_base), mmsg_hdr_[i].msg_len, - false); + if (FLAGS_quic_use_socket_timestamp) { + if (packet_timestamp == QuicTime::Zero()) { + // This isn't particularly desirable, but not all platforms support + // socket timestamping. + if (fallback_timestamp == QuicTime::Zero()) { + fallback_timestamp = clock.Now(); + } + packet_timestamp = fallback_timestamp; + } + } + + QuicReceivedPacket packet(reinterpret_cast<char*>(packets_[i].iov.iov_base), + mmsg_hdr_[i].msg_len, packet_timestamp, false); IPEndPoint server_address(server_ip, port); processor->ProcessPacket(server_address, client_address, packet); } @@ -131,20 +155,33 @@ bool QuicPacketReader::ReadAndDispatchManyPackets( bool QuicPacketReader::ReadAndDispatchSinglePacket( int fd, int port, + const QuicClock& clock, ProcessPacketInterface* processor, QuicPacketCount* packets_dropped) { char buf[kMaxPacketSize]; IPEndPoint client_address; IPAddress server_ip; - int bytes_read = QuicSocketUtils::ReadPacket( - fd, buf, arraysize(buf), packets_dropped, &server_ip, &client_address); + QuicTime timestamp = QuicTime::Zero(); + int bytes_read = + QuicSocketUtils::ReadPacket(fd, buf, arraysize(buf), packets_dropped, + &server_ip, ×tamp, &client_address); if (bytes_read < 0) { return false; // ReadPacket failed. } - QuicEncryptedPacket packet(buf, bytes_read, false); + if (server_ip.empty()) { + QUIC_BUG << "Unable to get server address."; + return false; + } + if (FLAGS_quic_use_socket_timestamp && timestamp == QuicTime::Zero()) { + // This isn't particularly desirable, but not all platforms support socket + // timestamping. + timestamp = clock.Now(); + } + + QuicReceivedPacket packet(buf, bytes_read, timestamp, false); IPEndPoint server_address(server_ip, port); processor->ProcessPacket(server_address, client_address, packet); |