OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/tools/quic/quic_packet_reader.h" | 5 #include "net/tools/quic/quic_packet_reader.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #ifndef __APPLE__ | 8 #ifndef __APPLE__ |
9 // This is a GNU header that is not present in /usr/include on MacOS | 9 // This is a GNU header that is not present in /usr/include on MacOS |
10 #include <features.h> | 10 #include <features.h> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 hdr->msg_controllen = QuicSocketUtils::kSpaceForCmsg; | 56 hdr->msg_controllen = QuicSocketUtils::kSpaceForCmsg; |
57 } | 57 } |
58 #endif | 58 #endif |
59 } | 59 } |
60 | 60 |
61 QuicPacketReader::~QuicPacketReader() {} | 61 QuicPacketReader::~QuicPacketReader() {} |
62 | 62 |
63 bool QuicPacketReader::ReadAndDispatchPackets( | 63 bool QuicPacketReader::ReadAndDispatchPackets( |
64 int fd, | 64 int fd, |
65 int port, | 65 int port, |
66 bool potentially_small_mtu, | |
67 const QuicClock& clock, | 66 const QuicClock& clock, |
68 ProcessPacketInterface* processor, | 67 ProcessPacketInterface* processor, |
69 QuicPacketCount* packets_dropped) { | 68 QuicPacketCount* packets_dropped) { |
70 #if MMSG_MORE | 69 #if MMSG_MORE |
71 return ReadAndDispatchManyPackets(fd, port, potentially_small_mtu, clock, | 70 return ReadAndDispatchManyPackets(fd, port, clock, processor, |
72 processor, packets_dropped); | 71 packets_dropped); |
73 #else | 72 #else |
74 return ReadAndDispatchSinglePacket(fd, port, potentially_small_mtu, clock, | 73 return ReadAndDispatchSinglePacket(fd, port, clock, processor, |
75 processor, packets_dropped); | 74 packets_dropped); |
76 #endif | 75 #endif |
77 } | 76 } |
78 | 77 |
79 bool QuicPacketReader::ReadAndDispatchManyPackets( | 78 bool QuicPacketReader::ReadAndDispatchManyPackets( |
80 int fd, | 79 int fd, |
81 int port, | 80 int port, |
82 bool potentially_small_mtu, | |
83 const QuicClock& clock, | 81 const QuicClock& clock, |
84 ProcessPacketInterface* processor, | 82 ProcessPacketInterface* processor, |
85 QuicPacketCount* packets_dropped) { | 83 QuicPacketCount* packets_dropped) { |
86 #if MMSG_MORE | 84 #if MMSG_MORE |
87 // Re-set the length fields in case recvmmsg has changed them. | 85 // Re-set the length fields in case recvmmsg has changed them. |
88 for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { | 86 for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { |
89 DCHECK_EQ(kMaxPacketSize, packets_[i].iov.iov_len); | 87 DCHECK_EQ(kMaxPacketSize, packets_[i].iov.iov_len); |
90 msghdr* hdr = &mmsg_hdr_[i].msg_hdr; | 88 msghdr* hdr = &mmsg_hdr_[i].msg_hdr; |
91 hdr->msg_namelen = sizeof(sockaddr_storage); | 89 hdr->msg_namelen = sizeof(sockaddr_storage); |
92 DCHECK_EQ(1, hdr->msg_iovlen); | 90 DCHECK_EQ(1, hdr->msg_iovlen); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 if (fallback_walltimestamp.IsZero()) { | 127 if (fallback_walltimestamp.IsZero()) { |
130 fallback_walltimestamp = clock.WallNow(); | 128 fallback_walltimestamp = clock.WallNow(); |
131 } | 129 } |
132 packet_walltimestamp = fallback_walltimestamp; | 130 packet_walltimestamp = fallback_walltimestamp; |
133 } | 131 } |
134 QuicTime timestamp = clock.ConvertWallTimeToQuicTime(packet_walltimestamp); | 132 QuicTime timestamp = clock.ConvertWallTimeToQuicTime(packet_walltimestamp); |
135 int ttl = 0; | 133 int ttl = 0; |
136 bool has_ttl = | 134 bool has_ttl = |
137 QuicSocketUtils::GetTtlFromMsghdr(&mmsg_hdr_[i].msg_hdr, &ttl); | 135 QuicSocketUtils::GetTtlFromMsghdr(&mmsg_hdr_[i].msg_hdr, &ttl); |
138 QuicReceivedPacket packet(reinterpret_cast<char*>(packets_[i].iov.iov_base), | 136 QuicReceivedPacket packet(reinterpret_cast<char*>(packets_[i].iov.iov_base), |
139 mmsg_hdr_[i].msg_len, timestamp, false, | 137 mmsg_hdr_[i].msg_len, timestamp, false, ttl, |
140 potentially_small_mtu, ttl, has_ttl); | 138 has_ttl); |
141 IPEndPoint server_address(server_ip, port); | 139 IPEndPoint server_address(server_ip, port); |
142 processor->ProcessPacket(server_address, client_address, packet); | 140 processor->ProcessPacket(server_address, client_address, packet); |
143 } | 141 } |
144 | 142 |
145 if (packets_dropped != nullptr) { | 143 if (packets_dropped != nullptr) { |
146 QuicSocketUtils::GetOverflowFromMsghdr(&mmsg_hdr_[0].msg_hdr, | 144 QuicSocketUtils::GetOverflowFromMsghdr(&mmsg_hdr_[0].msg_hdr, |
147 packets_dropped); | 145 packets_dropped); |
148 } | 146 } |
149 | 147 |
150 // We may not have read all of the packets available on the socket. | 148 // We may not have read all of the packets available on the socket. |
151 return packets_read == kNumPacketsPerReadMmsgCall; | 149 return packets_read == kNumPacketsPerReadMmsgCall; |
152 #else | 150 #else |
153 LOG(FATAL) << "Unsupported"; | 151 LOG(FATAL) << "Unsupported"; |
154 return false; | 152 return false; |
155 #endif | 153 #endif |
156 } | 154 } |
157 | 155 |
158 /* static */ | 156 /* static */ |
159 bool QuicPacketReader::ReadAndDispatchSinglePacket( | 157 bool QuicPacketReader::ReadAndDispatchSinglePacket( |
160 int fd, | 158 int fd, |
161 int port, | 159 int port, |
162 bool potentially_small_mtu, | |
163 const QuicClock& clock, | 160 const QuicClock& clock, |
164 ProcessPacketInterface* processor, | 161 ProcessPacketInterface* processor, |
165 QuicPacketCount* packets_dropped) { | 162 QuicPacketCount* packets_dropped) { |
166 char buf[kMaxPacketSize]; | 163 char buf[kMaxPacketSize]; |
167 | 164 |
168 IPEndPoint client_address; | 165 IPEndPoint client_address; |
169 IPAddress server_ip; | 166 IPAddress server_ip; |
170 QuicWallTime walltimestamp = QuicWallTime::Zero(); | 167 QuicWallTime walltimestamp = QuicWallTime::Zero(); |
171 int bytes_read = | 168 int bytes_read = |
172 QuicSocketUtils::ReadPacket(fd, buf, arraysize(buf), packets_dropped, | 169 QuicSocketUtils::ReadPacket(fd, buf, arraysize(buf), packets_dropped, |
173 &server_ip, &walltimestamp, &client_address); | 170 &server_ip, &walltimestamp, &client_address); |
174 if (bytes_read < 0) { | 171 if (bytes_read < 0) { |
175 return false; // ReadPacket failed. | 172 return false; // ReadPacket failed. |
176 } | 173 } |
177 | 174 |
178 if (server_ip.empty()) { | 175 if (server_ip.empty()) { |
179 QUIC_BUG << "Unable to get server address."; | 176 QUIC_BUG << "Unable to get server address."; |
180 return false; | 177 return false; |
181 } | 178 } |
182 // This isn't particularly desirable, but not all platforms support socket | 179 // This isn't particularly desirable, but not all platforms support socket |
183 // timestamping. | 180 // timestamping. |
184 if (walltimestamp.IsZero()) { | 181 if (walltimestamp.IsZero()) { |
185 walltimestamp = clock.WallNow(); | 182 walltimestamp = clock.WallNow(); |
186 } | 183 } |
187 QuicTime timestamp = clock.ConvertWallTimeToQuicTime(walltimestamp); | 184 QuicTime timestamp = clock.ConvertWallTimeToQuicTime(walltimestamp); |
188 | 185 |
189 QuicReceivedPacket packet(buf, bytes_read, timestamp, false /* owns_buffer */, | 186 QuicReceivedPacket packet(buf, bytes_read, timestamp, false); |
190 potentially_small_mtu, -1 /* ttl */, | |
191 false /* ttl_valid */); | |
192 IPEndPoint server_address(server_ip, port); | 187 IPEndPoint server_address(server_ip, port); |
193 processor->ProcessPacket(server_address, client_address, packet); | 188 processor->ProcessPacket(server_address, client_address, packet); |
194 | 189 |
195 // The socket read was successful, so return true even if packet dispatch | 190 // The socket read was successful, so return true even if packet dispatch |
196 // failed. | 191 // failed. |
197 return true; | 192 return true; |
198 } | 193 } |
199 | 194 |
200 | 195 |
201 } // namespace net | 196 } // namespace net |
OLD | NEW |