Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: net/quic/quic_connection.cc

Issue 1808613003: Deprecates check_peer_address_change_after_decryption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@116879870
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 per_packet_options_(nullptr), 216 per_packet_options_(nullptr),
217 writer_(writer), 217 writer_(writer),
218 owns_writer_(owns_writer), 218 owns_writer_(owns_writer),
219 encryption_level_(ENCRYPTION_NONE), 219 encryption_level_(ENCRYPTION_NONE),
220 has_forward_secure_encrypter_(false), 220 has_forward_secure_encrypter_(false),
221 first_required_forward_secure_packet_(0), 221 first_required_forward_secure_packet_(0),
222 clock_(helper->GetClock()), 222 clock_(helper->GetClock()),
223 random_generator_(helper->GetRandomGenerator()), 223 random_generator_(helper->GetRandomGenerator()),
224 connection_id_(connection_id), 224 connection_id_(connection_id),
225 peer_address_(address), 225 peer_address_(address),
226 migrating_peer_port_(0),
227 last_packet_decrypted_(false), 226 last_packet_decrypted_(false),
228 last_size_(0), 227 last_size_(0),
229 current_packet_data_(nullptr), 228 current_packet_data_(nullptr),
230 last_decrypted_packet_level_(ENCRYPTION_NONE), 229 last_decrypted_packet_level_(ENCRYPTION_NONE),
231 should_last_packet_instigate_acks_(false), 230 should_last_packet_instigate_acks_(false),
232 largest_seen_packet_with_ack_(0), 231 largest_seen_packet_with_ack_(0),
233 largest_seen_packet_with_stop_waiting_(0), 232 largest_seen_packet_with_stop_waiting_(0),
234 max_undecryptable_packets_(0), 233 max_undecryptable_packets_(0),
235 pending_version_negotiation_packet_(false), 234 pending_version_negotiation_packet_(false),
236 save_crypto_packets_as_termination_packets_(false), 235 save_crypto_packets_as_termination_packets_(false),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 perspective, 274 perspective,
276 kDefaultPathId, 275 kDefaultPathId,
277 clock_, 276 clock_,
278 &stats_, 277 &stats_,
279 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, 278 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic,
280 FLAGS_quic_use_time_loss_detection ? kTime : kNack, 279 FLAGS_quic_use_time_loss_detection ? kTime : kNack,
281 /*delegate=*/nullptr), 280 /*delegate=*/nullptr),
282 version_negotiation_state_(START_NEGOTIATION), 281 version_negotiation_state_(START_NEGOTIATION),
283 perspective_(perspective), 282 perspective_(perspective),
284 connected_(true), 283 connected_(true),
285 peer_ip_changed_(false),
286 peer_port_changed_(false),
287 self_ip_changed_(false),
288 self_port_changed_(false),
289 can_truncate_connection_ids_(true), 284 can_truncate_connection_ids_(true),
290 mtu_discovery_target_(0), 285 mtu_discovery_target_(0),
291 mtu_probe_count_(0), 286 mtu_probe_count_(0),
292 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), 287 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase),
293 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), 288 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase),
294 largest_received_packet_size_(0), 289 largest_received_packet_size_(0),
295 goaway_sent_(false), 290 goaway_sent_(false),
296 goaway_received_(false), 291 goaway_received_(false),
297 multipath_enabled_(false) { 292 multipath_enabled_(false) {
298 DVLOG(1) << ENDPOINT 293 DVLOG(1) << ENDPOINT
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 const QuicEncryptedPacket& packet) { 1205 const QuicEncryptedPacket& packet) {
1211 if (!connected_) { 1206 if (!connected_) {
1212 return; 1207 return;
1213 } 1208 }
1214 if (debug_visitor_ != nullptr) { 1209 if (debug_visitor_ != nullptr) {
1215 debug_visitor_->OnPacketReceived(self_address, peer_address, packet); 1210 debug_visitor_->OnPacketReceived(self_address, peer_address, packet);
1216 } 1211 }
1217 last_size_ = packet.length(); 1212 last_size_ = packet.length();
1218 current_packet_data_ = packet.data(); 1213 current_packet_data_ = packet.data();
1219 1214
1220 if (FLAGS_check_peer_address_change_after_decryption) { 1215 last_packet_destination_address_ = self_address;
1221 last_packet_destination_address_ = self_address; 1216 last_packet_source_address_ = peer_address;
1222 last_packet_source_address_ = peer_address; 1217 if (!IsInitializedIPEndPoint(self_address_)) {
1223 if (!IsInitializedIPEndPoint(self_address_)) { 1218 self_address_ = last_packet_destination_address_;
1224 self_address_ = last_packet_destination_address_; 1219 }
1225 } 1220 if (!IsInitializedIPEndPoint(peer_address_)) {
1226 if (!IsInitializedIPEndPoint(peer_address_)) { 1221 peer_address_ = last_packet_source_address_;
1227 peer_address_ = last_packet_source_address_;
1228 }
1229 } else {
1230 CheckForAddressMigration(self_address, peer_address);
1231 } 1222 }
1232 1223
1233 stats_.bytes_received += packet.length(); 1224 stats_.bytes_received += packet.length();
1234 ++stats_.packets_received; 1225 ++stats_.packets_received;
1235 1226
1236 ScopedRetransmissionScheduler alarm_delayer(this); 1227 ScopedRetransmissionScheduler alarm_delayer(this);
1237 if (!framer_.ProcessPacket(packet)) { 1228 if (!framer_.ProcessPacket(packet)) {
1238 // If we are unable to decrypt this packet, it might be 1229 // If we are unable to decrypt this packet, it might be
1239 // because the CHLO or SHLO packet was lost. 1230 // because the CHLO or SHLO packet was lost.
1240 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { 1231 if (framer_.error() == QUIC_DECRYPTION_FAILURE) {
(...skipping 10 matching lines...) Expand all
1251 return; 1242 return;
1252 } 1243 }
1253 1244
1254 ++stats_.packets_processed; 1245 ++stats_.packets_processed;
1255 MaybeProcessUndecryptablePackets(); 1246 MaybeProcessUndecryptablePackets();
1256 MaybeSendInResponseToPacket(); 1247 MaybeSendInResponseToPacket();
1257 SetPingAlarm(); 1248 SetPingAlarm();
1258 current_packet_data_ = nullptr; 1249 current_packet_data_ = nullptr;
1259 } 1250 }
1260 1251
1261 void QuicConnection::CheckForAddressMigration(const IPEndPoint& self_address,
1262 const IPEndPoint& peer_address) {
1263 peer_ip_changed_ = false;
1264 peer_port_changed_ = false;
1265 self_ip_changed_ = false;
1266 self_port_changed_ = false;
1267
1268 if (peer_address_.address().empty()) {
1269 peer_address_ = peer_address;
1270 }
1271 if (self_address_.address().empty()) {
1272 self_address_ = self_address;
1273 }
1274
1275 if (!peer_address.address().empty() && !peer_address_.address().empty()) {
1276 peer_ip_changed_ = (peer_address.address() != peer_address_.address());
1277 peer_port_changed_ = (peer_address.port() != peer_address_.port());
1278
1279 // Store in case we want to migrate connection in ProcessValidatedPacket.
1280 migrating_peer_ip_ = peer_address.address();
1281 migrating_peer_port_ = peer_address.port();
1282 }
1283
1284 if (!self_address.address().empty() && !self_address_.address().empty()) {
1285 self_ip_changed_ = (self_address.address() != self_address_.address());
1286 self_port_changed_ = (self_address.port() != self_address_.port());
1287 }
1288 }
1289
1290 void QuicConnection::OnCanWrite() { 1252 void QuicConnection::OnCanWrite() {
1291 DCHECK(!writer_->IsWriteBlocked()); 1253 DCHECK(!writer_->IsWriteBlocked());
1292 1254
1293 WriteQueuedPackets(); 1255 WriteQueuedPackets();
1294 WritePendingRetransmissions(); 1256 WritePendingRetransmissions();
1295 1257
1296 // Sending queued packets may have caused the socket to become write blocked, 1258 // Sending queued packets may have caused the socket to become write blocked,
1297 // or the congestion manager to prohibit sending. If we've sent everything 1259 // or the congestion manager to prohibit sending. If we've sent everything
1298 // we had queued and we're still not blocked, let the visitor know it can 1260 // we had queued and we're still not blocked, let the visitor know it can
1299 // write more. 1261 // write more.
(...skipping 30 matching lines...) Expand all
1330 OnCanWrite(); 1292 OnCanWrite();
1331 } 1293 }
1332 } 1294 }
1333 1295
1334 bool QuicConnection::ProcessValidatedPacket(const QuicPacketHeader& header) { 1296 bool QuicConnection::ProcessValidatedPacket(const QuicPacketHeader& header) {
1335 if (header.fec_flag) { 1297 if (header.fec_flag) {
1336 // Drop any FEC packet. 1298 // Drop any FEC packet.
1337 return false; 1299 return false;
1338 } 1300 }
1339 1301
1340 if (FLAGS_check_peer_address_change_after_decryption) { 1302 if (perspective_ == Perspective::IS_SERVER &&
1341 if (perspective_ == Perspective::IS_SERVER && 1303 IsInitializedIPEndPoint(self_address_) &&
1342 IsInitializedIPEndPoint(self_address_) && 1304 IsInitializedIPEndPoint(last_packet_destination_address_) &&
1343 IsInitializedIPEndPoint(last_packet_destination_address_) && 1305 (!(self_address_ == last_packet_destination_address_))) {
1344 (!(self_address_ == last_packet_destination_address_))) { 1306 SendConnectionCloseWithDetails(
1345 SendConnectionCloseWithDetails( 1307 QUIC_ERROR_MIGRATING_ADDRESS,
1346 QUIC_ERROR_MIGRATING_ADDRESS, 1308 "Self address migration is not supported at the server.");
1347 "Self address migration is not supported at the server."); 1309 return false;
1348 return false;
1349 }
1350 } else {
1351 if (perspective_ == Perspective::IS_SERVER &&
1352 (self_ip_changed_ || self_port_changed_)) {
1353 SendConnectionCloseWithDetails(
1354 QUIC_ERROR_MIGRATING_ADDRESS,
1355 "Self address migration is not supported at the server.");
1356 return false;
1357 }
1358 } 1310 }
1359 1311
1360 if (!Near(header.packet_number, last_header_.packet_number)) { 1312 if (!Near(header.packet_number, last_header_.packet_number)) {
1361 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number 1313 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number
1362 << " out of bounds. Discarding"; 1314 << " out of bounds. Discarding";
1363 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, 1315 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER,
1364 "packet number out of bounds"); 1316 "packet number out of bounds");
1365 return false; 1317 return false;
1366 } 1318 }
1367 1319
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 ++mtu_probe_count_; 2244 ++mtu_probe_count_;
2293 2245
2294 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; 2246 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_;
2295 SendMtuDiscoveryPacket(mtu_discovery_target_); 2247 SendMtuDiscoveryPacket(mtu_discovery_target_);
2296 2248
2297 DCHECK(!mtu_discovery_alarm_->IsSet()); 2249 DCHECK(!mtu_discovery_alarm_->IsSet());
2298 } 2250 }
2299 2251
2300 void QuicConnection::MaybeMigrateConnectionToNewPeerAddress() { 2252 void QuicConnection::MaybeMigrateConnectionToNewPeerAddress() {
2301 IPEndPoint last_peer_address; 2253 IPEndPoint last_peer_address;
2302 if (FLAGS_check_peer_address_change_after_decryption) { 2254 last_peer_address = last_packet_source_address_;
2303 last_peer_address = last_packet_source_address_;
2304 } else {
2305 last_peer_address = IPEndPoint(
2306 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address(),
2307 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port());
2308 }
2309 PeerAddressChangeType peer_address_change_type = 2255 PeerAddressChangeType peer_address_change_type =
2310 QuicUtils::DetermineAddressChangeType(peer_address_, last_peer_address); 2256 QuicUtils::DetermineAddressChangeType(peer_address_, last_peer_address);
2311 // TODO(fayang): Currently, all peer address change type are allowed. Need to 2257 // TODO(fayang): Currently, all peer address change type are allowed. Need to
2312 // add a method ShouldAllowPeerAddressChange(PeerAddressChangeType type) to 2258 // add a method ShouldAllowPeerAddressChange(PeerAddressChangeType type) to
2313 // determine whehter |type| is allowed. 2259 // determine whether |type| is allowed.
2314 if (FLAGS_check_peer_address_change_after_decryption) { 2260 if (peer_address_change_type == NO_CHANGE) {
2315 if (peer_address_change_type == NO_CHANGE) {
2316 return;
2317 }
2318
2319 IPEndPoint old_peer_address = peer_address_;
2320 peer_address_ = last_packet_source_address_;
2321
2322 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from "
2323 << old_peer_address.ToString() << " to "
2324 << peer_address_.ToString() << ", migrating connection.";
2325
2326 visitor_->OnConnectionMigration(peer_address_change_type);
2327 sent_packet_manager_.OnConnectionMigration(peer_address_change_type);
2328
2329 return; 2261 return;
2330 } 2262 }
2331 2263
2332 if (peer_ip_changed_ || peer_port_changed_) { 2264 IPEndPoint old_peer_address = peer_address_;
2333 IPEndPoint old_peer_address = peer_address_; 2265 peer_address_ = last_packet_source_address_;
2334 peer_address_ = IPEndPoint(
2335 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address(),
2336 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port());
2337 2266
2338 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " 2267 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from "
2339 << old_peer_address.ToString() << " to " 2268 << old_peer_address.ToString() << " to " << peer_address_.ToString()
2340 << peer_address_.ToString() << ", migrating connection."; 2269 << ", migrating connection.";
2341 2270
2342 visitor_->OnConnectionMigration(peer_address_change_type); 2271 visitor_->OnConnectionMigration(peer_address_change_type);
2343 DCHECK_NE(peer_address_change_type, NO_CHANGE); 2272 sent_packet_manager_.OnConnectionMigration(peer_address_change_type);
2344 sent_packet_manager_.OnConnectionMigration(peer_address_change_type);
2345 }
2346 } 2273 }
2347 2274
2348 void QuicConnection::OnPathClosed(QuicPathId path_id) { 2275 void QuicConnection::OnPathClosed(QuicPathId path_id) {
2349 // Stop receiving packets on this path. 2276 // Stop receiving packets on this path.
2350 framer_.OnPathClosed(path_id); 2277 framer_.OnPathClosed(path_id);
2351 } 2278 }
2352 2279
2353 bool QuicConnection::ack_frame_updated() const { 2280 bool QuicConnection::ack_frame_updated() const {
2354 return received_packet_manager_.ack_frame_updated(); 2281 return received_packet_manager_.ack_frame_updated();
2355 } 2282 }
2356 2283
2357 StringPiece QuicConnection::GetCurrentPacket() { 2284 StringPiece QuicConnection::GetCurrentPacket() {
2358 if (current_packet_data_ == nullptr) { 2285 if (current_packet_data_ == nullptr) {
2359 return StringPiece(); 2286 return StringPiece();
2360 } 2287 }
2361 return StringPiece(current_packet_data_, last_size_); 2288 return StringPiece(current_packet_data_, last_size_);
2362 } 2289 }
2363 2290
2364 } // namespace net 2291 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698