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 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't | 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't |
6 // constantly adding and subtracting header sizes; this is ugly and error- | 6 // constantly adding and subtracting header sizes; this is ugly and error- |
7 // prone. | 7 // prone. |
8 | 8 |
9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
10 | 10 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 case SPDY_ZLIB_INIT_FAILURE: | 200 case SPDY_ZLIB_INIT_FAILURE: |
201 return "ZLIB_INIT_FAILURE"; | 201 return "ZLIB_INIT_FAILURE"; |
202 case SPDY_UNSUPPORTED_VERSION: | 202 case SPDY_UNSUPPORTED_VERSION: |
203 return "UNSUPPORTED_VERSION"; | 203 return "UNSUPPORTED_VERSION"; |
204 case SPDY_DECOMPRESS_FAILURE: | 204 case SPDY_DECOMPRESS_FAILURE: |
205 return "DECOMPRESS_FAILURE"; | 205 return "DECOMPRESS_FAILURE"; |
206 case SPDY_COMPRESS_FAILURE: | 206 case SPDY_COMPRESS_FAILURE: |
207 return "COMPRESS_FAILURE"; | 207 return "COMPRESS_FAILURE"; |
208 case SPDY_INVALID_DATA_FRAME_FLAGS: | 208 case SPDY_INVALID_DATA_FRAME_FLAGS: |
209 return "SPDY_INVALID_DATA_FRAME_FLAGS"; | 209 return "SPDY_INVALID_DATA_FRAME_FLAGS"; |
210 case SPDY_INVALID_CONTROL_FRAME_FLAGS: | |
211 return "SPDY_INVALID_CONTROL_FRAME_FLAGS"; | |
210 } | 212 } |
211 return "UNKNOWN_ERROR"; | 213 return "UNKNOWN_ERROR"; |
212 } | 214 } |
213 | 215 |
214 const char* SpdyFramer::StatusCodeToString(int status_code) { | 216 const char* SpdyFramer::StatusCodeToString(int status_code) { |
215 switch (status_code) { | 217 switch (status_code) { |
216 case RST_STREAM_INVALID: | 218 case RST_STREAM_INVALID: |
217 return "INVALID"; | 219 return "INVALID"; |
218 case RST_STREAM_PROTOCOL_ERROR: | 220 case RST_STREAM_PROTOCOL_ERROR: |
219 return "PROTOCOL_ERROR"; | 221 return "PROTOCOL_ERROR"; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 if (remaining_data_ > 1000000u && | 402 if (remaining_data_ > 1000000u && |
401 !syn_frame_processed_ && | 403 !syn_frame_processed_ && |
402 strncmp(current_frame_buffer_.get(), "HTTP/", 5) == 0) { | 404 strncmp(current_frame_buffer_.get(), "HTTP/", 5) == 0) { |
403 LOG(WARNING) << "Unexpected HTTP response to spdy request"; | 405 LOG(WARNING) << "Unexpected HTTP response to spdy request"; |
404 probable_http_response_ = true; | 406 probable_http_response_ = true; |
405 } | 407 } |
406 | 408 |
407 // if we're here, then we have the common header all received. | 409 // if we're here, then we have the common header all received. |
408 if (!current_frame.is_control_frame()) { | 410 if (!current_frame.is_control_frame()) { |
409 SpdyDataFrame data_frame(current_frame_buffer_.get(), false); | 411 SpdyDataFrame data_frame(current_frame_buffer_.get(), false); |
412 if (data_frame.flags() & ~DATA_FLAG_FIN) { | |
413 set_error(SPDY_INVALID_DATA_FRAME_FLAGS); | |
414 } else { | |
410 visitor_->OnDataFrameHeader(&data_frame); | 415 visitor_->OnDataFrameHeader(&data_frame); |
411 | 416 |
412 if (current_frame.length() > 0) { | 417 if (current_frame.length() > 0) { |
413 CHANGE_STATE(SPDY_FORWARD_STREAM_FRAME); | 418 CHANGE_STATE(SPDY_FORWARD_STREAM_FRAME); |
414 } else { | 419 } else { |
415 // Empty data frame. | 420 // Empty data frame. |
416 if (current_frame.flags() & DATA_FLAG_FIN) { | 421 if (current_frame.flags() & DATA_FLAG_FIN) { |
417 visitor_->OnStreamFrameData(data_frame.stream_id(), | 422 visitor_->OnStreamFrameData(data_frame.stream_id(), |
418 NULL, 0, DATA_FLAG_FIN); | 423 NULL, 0, DATA_FLAG_FIN); |
419 } | 424 } |
420 CHANGE_STATE(SPDY_AUTO_RESET); | 425 CHANGE_STATE(SPDY_AUTO_RESET); |
421 } | 426 } |
427 } | |
Ryan Hamilton
2013/02/07 17:07:45
fix indentation
akalin
2013/02/12 06:50:12
Done. Was due to p4diff.
| |
422 } else { | 428 } else { |
423 ProcessControlFrameHeader(); | 429 ProcessControlFrameHeader(); |
424 } | 430 } |
425 } | 431 } |
426 return original_len - len; | 432 return original_len - len; |
427 } | 433 } |
428 | 434 |
429 void SpdyFramer::ProcessControlFrameHeader() { | 435 void SpdyFramer::ProcessControlFrameHeader() { |
430 DCHECK_EQ(SPDY_NO_ERROR, error_code_); | 436 DCHECK_EQ(SPDY_NO_ERROR, error_code_); |
431 DCHECK_LE(static_cast<size_t>(SpdyFrame::kHeaderSize), current_frame_len_); | 437 DCHECK_LE(static_cast<size_t>(SpdyFrame::kHeaderSize), current_frame_len_); |
(...skipping 20 matching lines...) Expand all Loading... | |
452 if (current_control_frame.type() == NOOP) { | 458 if (current_control_frame.type() == NOOP) { |
453 DLOG(INFO) << "NOOP control frame found. Ignoring."; | 459 DLOG(INFO) << "NOOP control frame found. Ignoring."; |
454 CHANGE_STATE(SPDY_AUTO_RESET); | 460 CHANGE_STATE(SPDY_AUTO_RESET); |
455 return; | 461 return; |
456 } | 462 } |
457 | 463 |
458 // Do some sanity checking on the control frame sizes. | 464 // Do some sanity checking on the control frame sizes. |
459 switch (current_control_frame.type()) { | 465 switch (current_control_frame.type()) { |
460 case SYN_STREAM: | 466 case SYN_STREAM: |
461 if (current_control_frame.length() < | 467 if (current_control_frame.length() < |
462 SpdySynStreamControlFrame::size() - SpdyControlFrame::kHeaderSize) | 468 SpdySynStreamControlFrame::size() - SpdyControlFrame::kHeaderSize) { |
463 set_error(SPDY_INVALID_CONTROL_FRAME); | 469 set_error(SPDY_INVALID_CONTROL_FRAME); |
470 } else if (current_control_frame.flags() & | |
471 ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | |
472 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
473 } | |
464 break; | 474 break; |
465 case SYN_REPLY: | 475 case SYN_REPLY: |
466 if (current_control_frame.length() < | 476 if (current_control_frame.length() < |
467 SpdySynReplyControlFrame::size() - SpdyControlFrame::kHeaderSize) | 477 SpdySynReplyControlFrame::size() - SpdyControlFrame::kHeaderSize) { |
468 set_error(SPDY_INVALID_CONTROL_FRAME); | 478 set_error(SPDY_INVALID_CONTROL_FRAME); |
479 } else if (current_control_frame.flags() & ~CONTROL_FLAG_FIN) { | |
480 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
481 } | |
469 break; | 482 break; |
470 case RST_STREAM: | 483 case RST_STREAM: |
471 if (current_control_frame.length() != | 484 if (current_control_frame.length() != |
472 SpdyRstStreamControlFrame::size() - SpdyFrame::kHeaderSize) | 485 SpdyRstStreamControlFrame::size() - SpdyFrame::kHeaderSize) { |
473 set_error(SPDY_INVALID_CONTROL_FRAME); | 486 set_error(SPDY_INVALID_CONTROL_FRAME); |
487 } else if (current_control_frame.flags() != 0) { | |
488 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
489 } | |
474 break; | 490 break; |
475 case SETTINGS: | 491 case SETTINGS: |
476 // Make sure that we have an integral number of 8-byte key/value pairs, | 492 // Make sure that we have an integral number of 8-byte key/value pairs, |
477 // plus a 4-byte length field. | 493 // plus a 4-byte length field. |
478 if (current_control_frame.length() < | 494 if (current_control_frame.length() < |
479 SpdySettingsControlFrame::size() - SpdyControlFrame::kHeaderSize || | 495 SpdySettingsControlFrame::size() - SpdyControlFrame::kHeaderSize || |
480 (current_control_frame.length() % 8 != 4)) { | 496 (current_control_frame.length() % 8 != 4)) { |
481 DLOG(WARNING) << "Invalid length for SETTINGS frame: " | 497 DLOG(WARNING) << "Invalid length for SETTINGS frame: " |
482 << current_control_frame.length(); | 498 << current_control_frame.length(); |
483 set_error(SPDY_INVALID_CONTROL_FRAME); | 499 set_error(SPDY_INVALID_CONTROL_FRAME); |
500 } else if (current_control_frame.flags() & | |
501 ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { | |
502 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
484 } | 503 } |
485 break; | 504 break; |
486 case GOAWAY: | 505 case GOAWAY: |
487 { | 506 { |
488 // SPDY 2 GOAWAY frames are 4 bytes smaller than in SPDY 3. We account | 507 // SPDY 2 GOAWAY frames are 4 bytes smaller than in SPDY 3. We account |
489 // for this difference via a separate offset variable, since | 508 // for this difference via a separate offset variable, since |
490 // SpdyGoAwayControlFrame::size() returns the SPDY 3 size. | 509 // SpdyGoAwayControlFrame::size() returns the SPDY 3 size. |
491 const size_t goaway_offset = (protocol_version() < 3) ? 4 : 0; | 510 const size_t goaway_offset = (protocol_version() < 3) ? 4 : 0; |
492 if (current_control_frame.length() + goaway_offset != | 511 if (current_control_frame.length() + goaway_offset != |
493 SpdyGoAwayControlFrame::size() - SpdyFrame::kHeaderSize) | 512 SpdyGoAwayControlFrame::size() - SpdyFrame::kHeaderSize) { |
494 set_error(SPDY_INVALID_CONTROL_FRAME); | 513 set_error(SPDY_INVALID_CONTROL_FRAME); |
514 } else if (current_control_frame.flags() != 0) { | |
515 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
516 } | |
495 break; | 517 break; |
496 } | 518 } |
497 case HEADERS: | 519 case HEADERS: |
498 if (current_control_frame.length() < | 520 if (current_control_frame.length() < |
499 SpdyHeadersControlFrame::size() - SpdyControlFrame::kHeaderSize) | 521 SpdyHeadersControlFrame::size() - SpdyControlFrame::kHeaderSize) { |
500 set_error(SPDY_INVALID_CONTROL_FRAME); | 522 set_error(SPDY_INVALID_CONTROL_FRAME); |
523 } else if (current_control_frame.flags() & ~CONTROL_FLAG_FIN) { | |
524 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
525 } | |
501 break; | 526 break; |
502 case WINDOW_UPDATE: | 527 case WINDOW_UPDATE: |
503 if (current_control_frame.length() != | 528 if (current_control_frame.length() != |
504 SpdyWindowUpdateControlFrame::size() - | 529 SpdyWindowUpdateControlFrame::size() - |
505 SpdyControlFrame::kHeaderSize) | 530 SpdyControlFrame::kHeaderSize) { |
506 set_error(SPDY_INVALID_CONTROL_FRAME); | 531 set_error(SPDY_INVALID_CONTROL_FRAME); |
532 } else if (current_control_frame.flags() != 0) { | |
533 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
534 } | |
507 break; | 535 break; |
508 case PING: | 536 case PING: |
509 if (current_control_frame.length() != | 537 if (current_control_frame.length() != |
510 SpdyPingControlFrame::size() - SpdyControlFrame::kHeaderSize) | 538 SpdyPingControlFrame::size() - SpdyControlFrame::kHeaderSize) { |
511 set_error(SPDY_INVALID_CONTROL_FRAME); | 539 set_error(SPDY_INVALID_CONTROL_FRAME); |
540 } else if (current_control_frame.flags() != 0) { | |
541 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
542 } | |
512 break; | 543 break; |
513 case CREDENTIAL: | 544 case CREDENTIAL: |
514 if (current_control_frame.length() < | 545 if (current_control_frame.length() < |
515 SpdyCredentialControlFrame::size() - SpdyControlFrame::kHeaderSize) | 546 SpdyCredentialControlFrame::size() - SpdyControlFrame::kHeaderSize) { |
516 set_error(SPDY_INVALID_CONTROL_FRAME); | 547 set_error(SPDY_INVALID_CONTROL_FRAME); |
548 } else if (current_control_frame.flags() != 0) { | |
549 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | |
550 } | |
517 break; | 551 break; |
518 default: | 552 default: |
519 LOG(WARNING) << "Valid " << display_protocol_ | 553 LOG(WARNING) << "Valid " << display_protocol_ |
520 << " control frame with unhandled type: " | 554 << " control frame with unhandled type: " |
521 << current_control_frame.type(); | 555 << current_control_frame.type(); |
522 DLOG(FATAL); | 556 DLOG(FATAL); |
523 set_error(SPDY_INVALID_CONTROL_FRAME); | 557 set_error(SPDY_INVALID_CONTROL_FRAME); |
524 break; | 558 break; |
525 } | 559 } |
526 | 560 |
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1876 } | 1910 } |
1877 } | 1911 } |
1878 return stream_id; | 1912 return stream_id; |
1879 } | 1913 } |
1880 | 1914 |
1881 void SpdyFramer::set_enable_compression(bool value) { | 1915 void SpdyFramer::set_enable_compression(bool value) { |
1882 enable_compression_ = value; | 1916 enable_compression_ = value; |
1883 } | 1917 } |
1884 | 1918 |
1885 } // namespace net | 1919 } // namespace net |
OLD | NEW |