Mercurial > hg > nginx
comparison src/event/ngx_event_quic_transport.c @ 8361:336d527ca031 quic
Error messages cleanup.
+ added "quic" prefix to all error messages
+ rephrased some messages
+ removed excessive error logging from frame parser
+ added ngx_quic_check_peer() function to check proper source/destination
match and do it one place
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Fri, 24 Apr 2020 14:38:49 +0300 |
parents | f175006124d0 |
children | 262396242352 |
comparison
equal
deleted
inserted
replaced
8360:f175006124d0 | 8361:336d527ca031 |
---|---|
239 #endif | 239 #endif |
240 | 240 |
241 p = ngx_quic_read_uint8(p, end, &pkt->flags); | 241 p = ngx_quic_read_uint8(p, end, &pkt->flags); |
242 if (p == NULL) { | 242 if (p == NULL) { |
243 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 243 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
244 "packet is too small to read flags"); | 244 "quic packet is too small to read flags"); |
245 return NGX_ERROR; | 245 return NGX_ERROR; |
246 } | 246 } |
247 | 247 |
248 if (!ngx_quic_long_pkt(pkt->flags)) { | 248 if (!ngx_quic_long_pkt(pkt->flags)) { |
249 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "not a long packet"); | 249 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic not a long packet"); |
250 return NGX_ERROR; | 250 return NGX_ERROR; |
251 } | 251 } |
252 | 252 |
253 p = ngx_quic_read_uint32(p, end, &pkt->version); | 253 p = ngx_quic_read_uint32(p, end, &pkt->version); |
254 if (p == NULL) { | 254 if (p == NULL) { |
255 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 255 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
256 "packet is too small to read version"); | 256 "quic packet is too small to read version"); |
257 return NGX_ERROR; | 257 return NGX_ERROR; |
258 } | 258 } |
259 | 259 |
260 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 260 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
261 "quic long packet flags:%xi version:%xD", | 261 "quic long packet flags:%xi version:%xD", |
262 pkt->flags, pkt->version); | 262 pkt->flags, pkt->version); |
263 | 263 |
264 if (pkt->version != NGX_QUIC_VERSION) { | 264 if (pkt->version != NGX_QUIC_VERSION) { |
265 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 265 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
266 "unsupported quic version: 0x%xi", pkt->version); | 266 "quic unsupported version: 0x%xi", pkt->version); |
267 return NGX_ERROR; | 267 return NGX_ERROR; |
268 } | 268 } |
269 | 269 |
270 p = ngx_quic_read_uint8(p, end, &idlen); | 270 p = ngx_quic_read_uint8(p, end, &idlen); |
271 if (p == NULL) { | 271 if (p == NULL) { |
272 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 272 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
273 "packet is too small to read dcid len"); | 273 "quic packet is too small to read dcid len"); |
274 return NGX_ERROR; | 274 return NGX_ERROR; |
275 } | 275 } |
276 | 276 |
277 pkt->dcid.len = idlen; | 277 pkt->dcid.len = idlen; |
278 | 278 |
279 p = ngx_quic_read_bytes(p, end, idlen, &pkt->dcid.data); | 279 p = ngx_quic_read_bytes(p, end, idlen, &pkt->dcid.data); |
280 if (p == NULL) { | 280 if (p == NULL) { |
281 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 281 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
282 "packet is too small to read dcid"); | 282 "quic packet is too small to read dcid"); |
283 return NGX_ERROR; | 283 return NGX_ERROR; |
284 } | 284 } |
285 | 285 |
286 p = ngx_quic_read_uint8(p, end, &idlen); | 286 p = ngx_quic_read_uint8(p, end, &idlen); |
287 if (p == NULL) { | 287 if (p == NULL) { |
288 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 288 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
289 "packet is too small to read scid len"); | 289 "quic packet is too small to read scid len"); |
290 return NGX_ERROR; | 290 return NGX_ERROR; |
291 } | 291 } |
292 | 292 |
293 pkt->scid.len = idlen; | 293 pkt->scid.len = idlen; |
294 | 294 |
295 p = ngx_quic_read_bytes(p, end, idlen, &pkt->scid.data); | 295 p = ngx_quic_read_bytes(p, end, idlen, &pkt->scid.data); |
296 if (p == NULL) { | 296 if (p == NULL) { |
297 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 297 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
298 "packet is too small to read scid"); | 298 "quic packet is too small to read scid"); |
299 return NGX_ERROR; | 299 return NGX_ERROR; |
300 } | 300 } |
301 | 301 |
302 pkt->raw->pos = p; | 302 pkt->raw->pos = p; |
303 | 303 |
396 #endif | 396 #endif |
397 | 397 |
398 p = ngx_quic_read_uint8(p, end, &pkt->flags); | 398 p = ngx_quic_read_uint8(p, end, &pkt->flags); |
399 if (p == NULL) { | 399 if (p == NULL) { |
400 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 400 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
401 "packet is too small to read flags"); | 401 "quic packet is too small to read flags"); |
402 return NGX_ERROR; | 402 return NGX_ERROR; |
403 } | 403 } |
404 | 404 |
405 if (!ngx_quic_short_pkt(pkt->flags)) { | 405 if (!ngx_quic_short_pkt(pkt->flags)) { |
406 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "not a short packet"); | 406 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic not a short packet"); |
407 return NGX_ERROR; | 407 return NGX_ERROR; |
408 } | 408 } |
409 | 409 |
410 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 410 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
411 "quic short packet flags:%xi", pkt->flags); | 411 "quic short packet flags:%xi", pkt->flags); |
418 pkt->dcid.len = dcid->len; | 418 pkt->dcid.len = dcid->len; |
419 | 419 |
420 p = ngx_quic_read_bytes(p, end, dcid->len, &pkt->dcid.data); | 420 p = ngx_quic_read_bytes(p, end, dcid->len, &pkt->dcid.data); |
421 if (p == NULL) { | 421 if (p == NULL) { |
422 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 422 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
423 "packet is too small to read dcid"); | 423 "quic packet is too small to read dcid"); |
424 return NGX_ERROR; | 424 return NGX_ERROR; |
425 } | 425 } |
426 | 426 |
427 pkt->raw->pos = p; | 427 pkt->raw->pos = p; |
428 | 428 |
443 pkt->log->action = "parsing quic initial header"; | 443 pkt->log->action = "parsing quic initial header"; |
444 | 444 |
445 p = ngx_quic_parse_int(p, end, &varint); | 445 p = ngx_quic_parse_int(p, end, &varint); |
446 if (p == NULL) { | 446 if (p == NULL) { |
447 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 447 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
448 "failed to parse token length"); | 448 "quic failed to parse token length"); |
449 return NGX_ERROR; | 449 return NGX_ERROR; |
450 } | 450 } |
451 | 451 |
452 pkt->token.len = varint; | 452 pkt->token.len = varint; |
453 | 453 |
454 p = ngx_quic_read_bytes(p, end, pkt->token.len, &pkt->token.data); | 454 p = ngx_quic_read_bytes(p, end, pkt->token.len, &pkt->token.data); |
455 if (p == NULL) { | 455 if (p == NULL) { |
456 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 456 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
457 "packet too small to read token data"); | 457 "quic packet too small to read token data"); |
458 return NGX_ERROR; | 458 return NGX_ERROR; |
459 } | 459 } |
460 | 460 |
461 p = ngx_quic_parse_int(p, end, &varint); | 461 p = ngx_quic_parse_int(p, end, &varint); |
462 if (p == NULL) { | 462 if (p == NULL) { |
463 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "bad packet length"); | 463 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic bad packet length"); |
464 return NGX_ERROR; | 464 return NGX_ERROR; |
465 } | 465 } |
466 | 466 |
467 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 467 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
468 "quic initial packet length: %uL", varint); | 468 "quic initial packet length: %uL", varint); |
469 | 469 |
470 if (varint > (uint64_t) ((pkt->data + pkt->len) - p)) { | 470 if (varint > (uint64_t) ((pkt->data + pkt->len) - p)) { |
471 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "truncated initial packet"); | 471 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
472 "quic truncated initial packet"); | |
472 return NGX_ERROR; | 473 return NGX_ERROR; |
473 } | 474 } |
474 | 475 |
475 pkt->raw->pos = p; | 476 pkt->raw->pos = p; |
476 pkt->len = varint; | 477 pkt->len = varint; |
496 | 497 |
497 pkt->log->action = "parsing quic handshake header"; | 498 pkt->log->action = "parsing quic handshake header"; |
498 | 499 |
499 p = ngx_quic_parse_int(p, end, &plen); | 500 p = ngx_quic_parse_int(p, end, &plen); |
500 if (p == NULL) { | 501 if (p == NULL) { |
501 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "bad packet length"); | 502 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic bad packet length"); |
502 return NGX_ERROR; | 503 return NGX_ERROR; |
503 } | 504 } |
504 | 505 |
505 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 506 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
506 "quic handshake packet length: %uL", plen); | 507 "quic handshake packet length: %uL", plen); |
507 | 508 |
508 if (plen > (uint64_t)((pkt->data + pkt->len) - p)) { | 509 if (plen > (uint64_t)((pkt->data + pkt->len) - p)) { |
509 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "truncated handshake packet"); | 510 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
511 "quic truncated handshake packet"); | |
510 return NGX_ERROR; | 512 return NGX_ERROR; |
511 } | 513 } |
512 | 514 |
513 pkt->raw->pos = p; | 515 pkt->raw->pos = p; |
514 pkt->len = plen; | 516 pkt->len = plen; |
534 p = start; | 536 p = start; |
535 | 537 |
536 p = ngx_quic_parse_int(p, end, &varint); | 538 p = ngx_quic_parse_int(p, end, &varint); |
537 if (p == NULL) { | 539 if (p == NULL) { |
538 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 540 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
539 "failed to obtain quic frame type"); | 541 "quic failed to obtain quic frame type"); |
540 return NGX_ERROR; | 542 return NGX_ERROR; |
541 } | 543 } |
542 | 544 |
543 f->type = varint; | 545 f->type = varint; |
544 | 546 |
550 goto not_allowed; | 552 goto not_allowed; |
551 } | 553 } |
552 | 554 |
553 p = ngx_quic_parse_int(p, end, &f->u.crypto.offset); | 555 p = ngx_quic_parse_int(p, end, &f->u.crypto.offset); |
554 if (p == NULL) { | 556 if (p == NULL) { |
555 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 557 goto error; |
556 "failed to parse crypto frame offset"); | |
557 return NGX_ERROR; | |
558 } | 558 } |
559 | 559 |
560 p = ngx_quic_parse_int(p, end, &f->u.crypto.length); | 560 p = ngx_quic_parse_int(p, end, &f->u.crypto.length); |
561 if (p == NULL) { | 561 if (p == NULL) { |
562 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 562 goto error; |
563 "failed to parse crypto frame len"); | |
564 return NGX_ERROR; | |
565 } | 563 } |
566 | 564 |
567 p = ngx_quic_read_bytes(p, end, f->u.crypto.length, &f->u.crypto.data); | 565 p = ngx_quic_read_bytes(p, end, f->u.crypto.length, &f->u.crypto.data); |
568 if (p == NULL) { | 566 if (p == NULL) { |
569 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 567 goto error; |
570 "failed to parse crypto frame data"); | |
571 return NGX_ERROR; | |
572 } | 568 } |
573 | 569 |
574 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 570 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
575 "quic frame in: CRYPTO length: %uL off:%uL pp:%p", | 571 "quic frame in: CRYPTO length: %uL off:%uL pp:%p", |
576 f->u.crypto.length, f->u.crypto.offset, | 572 f->u.crypto.length, f->u.crypto.offset, |
602 if (!((p = ngx_quic_parse_int(p, end, &f->u.ack.largest)) | 598 if (!((p = ngx_quic_parse_int(p, end, &f->u.ack.largest)) |
603 && (p = ngx_quic_parse_int(p, end, &f->u.ack.delay)) | 599 && (p = ngx_quic_parse_int(p, end, &f->u.ack.delay)) |
604 && (p = ngx_quic_parse_int(p, end, &f->u.ack.range_count)) | 600 && (p = ngx_quic_parse_int(p, end, &f->u.ack.range_count)) |
605 && (p = ngx_quic_parse_int(p, end, &f->u.ack.first_range)))) | 601 && (p = ngx_quic_parse_int(p, end, &f->u.ack.first_range)))) |
606 { | 602 { |
607 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 603 goto error; |
608 "failed to parse ack frame"); | |
609 return NGX_ERROR; | |
610 } | 604 } |
611 | 605 |
612 f->u.ack.ranges_start = p; | 606 f->u.ack.ranges_start = p; |
613 | 607 |
614 /* process all ranges to get bounds, values are ignored */ | 608 /* process all ranges to get bounds, values are ignored */ |
618 if (p) { | 612 if (p) { |
619 p = ngx_quic_parse_int(p, end, &varint); | 613 p = ngx_quic_parse_int(p, end, &varint); |
620 } | 614 } |
621 | 615 |
622 if (p == NULL) { | 616 if (p == NULL) { |
623 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 617 goto error; |
624 "failed to parse ack frame range %ui", i); | |
625 return NGX_ERROR; | |
626 } | 618 } |
627 } | 619 } |
628 | 620 |
629 f->u.ack.ranges_end = p; | 621 f->u.ack.ranges_end = p; |
630 | 622 |
639 | 631 |
640 if (!((p = ngx_quic_parse_int(p, end, &f->u.ack.ect0)) | 632 if (!((p = ngx_quic_parse_int(p, end, &f->u.ack.ect0)) |
641 && (p = ngx_quic_parse_int(p, end, &f->u.ack.ect1)) | 633 && (p = ngx_quic_parse_int(p, end, &f->u.ack.ect1)) |
642 && (p = ngx_quic_parse_int(p, end, &f->u.ack.ce)))) | 634 && (p = ngx_quic_parse_int(p, end, &f->u.ack.ce)))) |
643 { | 635 { |
644 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 636 goto error; |
645 "failed to parse ack frame ECT counts", i); | |
646 return NGX_ERROR; | |
647 } | 637 } |
648 | 638 |
649 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 639 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
650 "quic ACK ECN counters: %ui %ui %ui", | 640 "quic ACK ECN counters: %ui %ui %ui", |
651 f->u.ack.ect0, f->u.ack.ect1, f->u.ack.ce); | 641 f->u.ack.ect0, f->u.ack.ect1, f->u.ack.ce); |
665 goto not_allowed; | 655 goto not_allowed; |
666 } | 656 } |
667 | 657 |
668 p = ngx_quic_parse_int(p, end, &f->u.ncid.seqnum); | 658 p = ngx_quic_parse_int(p, end, &f->u.ncid.seqnum); |
669 if (p == NULL) { | 659 if (p == NULL) { |
670 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 660 goto error; |
671 "failed to parse new connection id frame seqnum"); | |
672 return NGX_ERROR; | |
673 } | 661 } |
674 | 662 |
675 p = ngx_quic_parse_int(p, end, &f->u.ncid.retire); | 663 p = ngx_quic_parse_int(p, end, &f->u.ncid.retire); |
676 if (p == NULL) { | 664 if (p == NULL) { |
677 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 665 goto error; |
678 "failed to parse new connection id frame retire"); | |
679 return NGX_ERROR; | |
680 } | 666 } |
681 | 667 |
682 p = ngx_quic_read_uint8(p, end, &f->u.ncid.len); | 668 p = ngx_quic_read_uint8(p, end, &f->u.ncid.len); |
683 if (p == NULL) { | 669 if (p == NULL) { |
684 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 670 goto error; |
685 "failed to parse new connection id length"); | |
686 return NGX_ERROR; | |
687 } | 671 } |
688 | 672 |
689 p = ngx_quic_copy_bytes(p, end, f->u.ncid.len, f->u.ncid.cid); | 673 p = ngx_quic_copy_bytes(p, end, f->u.ncid.len, f->u.ncid.cid); |
690 if (p == NULL) { | 674 if (p == NULL) { |
691 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 675 goto error; |
692 "failed to parse new connection id cid"); | |
693 return NGX_ERROR; | |
694 } | 676 } |
695 | 677 |
696 p = ngx_quic_copy_bytes(p, end, 16, f->u.ncid.srt); | 678 p = ngx_quic_copy_bytes(p, end, 16, f->u.ncid.srt); |
697 if (p == NULL) { | 679 if (p == NULL) { |
698 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 680 goto error; |
699 "failed to parse new connection id srt"); | |
700 return NGX_ERROR; | |
701 } | 681 } |
702 | 682 |
703 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 683 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
704 "quic frame in: NCID seq:%ui retire:%ui len:%ui", | 684 "quic frame in: NCID seq:%ui retire:%ui len:%ui", |
705 f->u.ncid.seqnum, f->u.ncid.retire, f->u.ncid.len); | 685 f->u.ncid.seqnum, f->u.ncid.retire, f->u.ncid.len); |
719 goto not_allowed; | 699 goto not_allowed; |
720 } | 700 } |
721 | 701 |
722 p = ngx_quic_parse_int(p, end, &f->u.close.error_code); | 702 p = ngx_quic_parse_int(p, end, &f->u.close.error_code); |
723 if (p == NULL) { | 703 if (p == NULL) { |
724 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 704 goto error; |
725 "failed to parse close connection frame error code"); | |
726 return NGX_ERROR; | |
727 } | 705 } |
728 | 706 |
729 if (f->type == NGX_QUIC_FT_CONNECTION_CLOSE) { | 707 if (f->type == NGX_QUIC_FT_CONNECTION_CLOSE) { |
730 p = ngx_quic_parse_int(p, end, &f->u.close.frame_type); | 708 p = ngx_quic_parse_int(p, end, &f->u.close.frame_type); |
731 if (p == NULL) { | 709 if (p == NULL) { |
732 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 710 goto error; |
733 "failed to parse close connection frame type"); | |
734 return NGX_ERROR; | |
735 } | 711 } |
736 } | 712 } |
737 | 713 |
738 p = ngx_quic_parse_int(p, end, &varint); | 714 p = ngx_quic_parse_int(p, end, &varint); |
739 if (p == NULL) { | 715 if (p == NULL) { |
740 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 716 goto error; |
741 "failed to parse close reason length"); | |
742 return NGX_ERROR; | |
743 } | 717 } |
744 | 718 |
745 f->u.close.reason.len = varint; | 719 f->u.close.reason.len = varint; |
746 | 720 |
747 p = ngx_quic_read_bytes(p, end, f->u.close.reason.len, | 721 p = ngx_quic_read_bytes(p, end, f->u.close.reason.len, |
748 &f->u.close.reason.data); | 722 &f->u.close.reason.data); |
749 if (p == NULL) { | 723 if (p == NULL) { |
750 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 724 goto error; |
751 "failed to parse close reason"); | |
752 return NGX_ERROR; | |
753 } | 725 } |
754 | 726 |
755 if (f->type == NGX_QUIC_FT_CONNECTION_CLOSE) { | 727 if (f->type == NGX_QUIC_FT_CONNECTION_CLOSE) { |
756 | 728 |
757 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 729 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
789 f->u.stream.len = ngx_quic_stream_bit_len(f->type); | 761 f->u.stream.len = ngx_quic_stream_bit_len(f->type); |
790 f->u.stream.fin = ngx_quic_stream_bit_fin(f->type); | 762 f->u.stream.fin = ngx_quic_stream_bit_fin(f->type); |
791 | 763 |
792 p = ngx_quic_parse_int(p, end, &f->u.stream.stream_id); | 764 p = ngx_quic_parse_int(p, end, &f->u.stream.stream_id); |
793 if (p == NULL) { | 765 if (p == NULL) { |
794 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 766 goto error; |
795 "failed to parse stream frame id"); | |
796 return NGX_ERROR; | |
797 } | 767 } |
798 | 768 |
799 if (f->type & 0x04) { | 769 if (f->type & 0x04) { |
800 p = ngx_quic_parse_int(p, end, &f->u.stream.offset); | 770 p = ngx_quic_parse_int(p, end, &f->u.stream.offset); |
801 if (p == NULL) { | 771 if (p == NULL) { |
802 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 772 goto error; |
803 "failed to parse stream frame offset"); | |
804 return NGX_ERROR; | |
805 } | 773 } |
806 | 774 |
807 } else { | 775 } else { |
808 f->u.stream.offset = 0; | 776 f->u.stream.offset = 0; |
809 } | 777 } |
810 | 778 |
811 if (f->type & 0x02) { | 779 if (f->type & 0x02) { |
812 p = ngx_quic_parse_int(p, end, &f->u.stream.length); | 780 p = ngx_quic_parse_int(p, end, &f->u.stream.length); |
813 if (p == NULL) { | 781 if (p == NULL) { |
814 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 782 goto error; |
815 "failed to parse stream frame length"); | |
816 return NGX_ERROR; | |
817 } | 783 } |
818 | 784 |
819 } else { | 785 } else { |
820 f->u.stream.length = end - p; /* up to packet end */ | 786 f->u.stream.length = end - p; /* up to packet end */ |
821 } | 787 } |
822 | 788 |
823 p = ngx_quic_read_bytes(p, end, f->u.stream.length, | 789 p = ngx_quic_read_bytes(p, end, f->u.stream.length, |
824 &f->u.stream.data); | 790 &f->u.stream.data); |
825 if (p == NULL) { | 791 if (p == NULL) { |
826 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 792 goto error; |
827 "failed to parse stream frame data len=%ui " | |
828 "offset=%ui", f->u.stream.length, f->u.stream.offset); | |
829 return NGX_ERROR; | |
830 } | 793 } |
831 | 794 |
832 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 795 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
833 "quic frame in: STREAM type:0x%xi id:0x%xi offset:0x%xi " | 796 "quic frame in: STREAM type:0x%xi id:0x%xi offset:0x%xi " |
834 "len:0x%xi bits off:%d len:%d fin:%d", | 797 "len:0x%xi bits off:%d len:%d fin:%d", |
848 goto not_allowed; | 811 goto not_allowed; |
849 } | 812 } |
850 | 813 |
851 p = ngx_quic_parse_int(p, end, &f->u.max_data.max_data); | 814 p = ngx_quic_parse_int(p, end, &f->u.max_data.max_data); |
852 if (p == NULL) { | 815 if (p == NULL) { |
853 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 816 goto error; |
854 "failed to parse max data frame"); | |
855 return NGX_ERROR; | |
856 } | 817 } |
857 | 818 |
858 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 819 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
859 "quic frame in: MAX_DATA max_data:%ui", | 820 "quic frame in: MAX_DATA max_data:%ui", |
860 f->u.max_data.max_data); | 821 f->u.max_data.max_data); |
869 if (!((p = ngx_quic_parse_int(p, end, &f->u.reset_stream.id)) | 830 if (!((p = ngx_quic_parse_int(p, end, &f->u.reset_stream.id)) |
870 && (p = ngx_quic_parse_int(p, end, &f->u.reset_stream.error_code)) | 831 && (p = ngx_quic_parse_int(p, end, &f->u.reset_stream.error_code)) |
871 && (p = ngx_quic_parse_int(p, end, | 832 && (p = ngx_quic_parse_int(p, end, |
872 &f->u.reset_stream.final_size)))) | 833 &f->u.reset_stream.final_size)))) |
873 { | 834 { |
874 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 835 goto error; |
875 "failed to parse reset stream frame"); | |
876 return NGX_ERROR; | |
877 } | 836 } |
878 | 837 |
879 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 838 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
880 "quic frame in: RESET_STREAM" | 839 "quic frame in: RESET_STREAM" |
881 " id:0x%xi error_code:0x%xi final_size:0x%xi", | 840 " id:0x%xi error_code:0x%xi final_size:0x%xi", |
889 goto not_allowed; | 848 goto not_allowed; |
890 } | 849 } |
891 | 850 |
892 p = ngx_quic_parse_int(p, end, &f->u.stop_sending.id); | 851 p = ngx_quic_parse_int(p, end, &f->u.stop_sending.id); |
893 if (p == NULL) { | 852 if (p == NULL) { |
894 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 853 goto error; |
895 "failed to parse stop sending frame id"); | |
896 return NGX_ERROR; | |
897 } | 854 } |
898 | 855 |
899 p = ngx_quic_parse_int(p, end, &f->u.stop_sending.error_code); | 856 p = ngx_quic_parse_int(p, end, &f->u.stop_sending.error_code); |
900 if (p == NULL) { | 857 if (p == NULL) { |
901 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 858 goto error; |
902 "failed to parse stop sending frame error code"); | |
903 return NGX_ERROR; | |
904 } | 859 } |
905 | 860 |
906 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 861 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
907 "quic frame in: STOP_SENDING id:0x%xi error_code:0x%xi", | 862 "quic frame in: STOP_SENDING id:0x%xi error_code:0x%xi", |
908 f->u.stop_sending.id, f->u.stop_sending.error_code); | 863 f->u.stop_sending.id, f->u.stop_sending.error_code); |
916 goto not_allowed; | 871 goto not_allowed; |
917 } | 872 } |
918 | 873 |
919 p = ngx_quic_parse_int(p, end, &f->u.streams_blocked.limit); | 874 p = ngx_quic_parse_int(p, end, &f->u.streams_blocked.limit); |
920 if (p == NULL) { | 875 if (p == NULL) { |
921 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 876 goto error; |
922 "failed to parse streams blocked frame limit"); | |
923 return NGX_ERROR; | |
924 } | 877 } |
925 | 878 |
926 f->u.streams_blocked.bidi = | 879 f->u.streams_blocked.bidi = |
927 (f->type == NGX_QUIC_FT_STREAMS_BLOCKED) ? 1 : 0; | 880 (f->type == NGX_QUIC_FT_STREAMS_BLOCKED) ? 1 : 0; |
928 | 881 |
944 } | 897 } |
945 | 898 |
946 /* TODO: implement */ | 899 /* TODO: implement */ |
947 | 900 |
948 ngx_log_error(NGX_LOG_ALERT, pkt->log, 0, | 901 ngx_log_error(NGX_LOG_ALERT, pkt->log, 0, |
949 "unimplemented frame type 0x%xi in packet", f->type); | 902 "quic unimplemented frame type 0x%xi in packet", f->type); |
950 | 903 |
951 break; | 904 break; |
952 | 905 |
953 case NGX_QUIC_FT_MAX_STREAMS: | 906 case NGX_QUIC_FT_MAX_STREAMS: |
954 case NGX_QUIC_FT_MAX_STREAMS2: | 907 case NGX_QUIC_FT_MAX_STREAMS2: |
957 goto not_allowed; | 910 goto not_allowed; |
958 } | 911 } |
959 | 912 |
960 p = ngx_quic_parse_int(p, end, &f->u.max_streams.limit); | 913 p = ngx_quic_parse_int(p, end, &f->u.max_streams.limit); |
961 if (p == NULL) { | 914 if (p == NULL) { |
962 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 915 goto error; |
963 "failed to parse max streams frame limit"); | |
964 return NGX_ERROR; | |
965 } | 916 } |
966 | 917 |
967 f->u.max_streams.bidi = (f->type == NGX_QUIC_FT_MAX_STREAMS) ? 1 : 0; | 918 f->u.max_streams.bidi = (f->type == NGX_QUIC_FT_MAX_STREAMS) ? 1 : 0; |
968 | 919 |
969 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 920 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
978 goto not_allowed; | 929 goto not_allowed; |
979 } | 930 } |
980 | 931 |
981 p = ngx_quic_parse_int(p, end, &f->u.max_stream_data.id); | 932 p = ngx_quic_parse_int(p, end, &f->u.max_stream_data.id); |
982 if (p == NULL) { | 933 if (p == NULL) { |
983 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 934 goto error; |
984 "failed to parse max stream data frame data id"); | |
985 return NGX_ERROR; | |
986 } | 935 } |
987 | 936 |
988 p = ngx_quic_parse_int(p, end, &f->u.max_stream_data.limit); | 937 p = ngx_quic_parse_int(p, end, &f->u.max_stream_data.limit); |
989 if (p == NULL) { | 938 if (p == NULL) { |
990 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 939 goto error; |
991 "failed to parse max stream data frame data limit"); | |
992 return NGX_ERROR; | |
993 } | 940 } |
994 | 941 |
995 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 942 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
996 "quic frame in: MAX_STREAM_DATA id:%ui limit:%ui", | 943 "quic frame in: MAX_STREAM_DATA id:%ui limit:%ui", |
997 f->u.max_stream_data.id, | 944 f->u.max_stream_data.id, |
1004 goto not_allowed; | 951 goto not_allowed; |
1005 } | 952 } |
1006 | 953 |
1007 p = ngx_quic_parse_int(p, end, &f->u.data_blocked.limit); | 954 p = ngx_quic_parse_int(p, end, &f->u.data_blocked.limit); |
1008 if (p == NULL) { | 955 if (p == NULL) { |
1009 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 956 goto error; |
1010 "failed to parse data blocked frame limit"); | |
1011 return NGX_ERROR; | |
1012 } | 957 } |
1013 | 958 |
1014 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 959 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
1015 "quic frame in: DATA_BLOCKED limit:%ui", | 960 "quic frame in: DATA_BLOCKED limit:%ui", |
1016 f->u.data_blocked.limit); | 961 f->u.data_blocked.limit); |
1022 goto not_allowed; | 967 goto not_allowed; |
1023 } | 968 } |
1024 | 969 |
1025 p = ngx_quic_parse_int(p, end, &f->u.stream_data_blocked.id); | 970 p = ngx_quic_parse_int(p, end, &f->u.stream_data_blocked.id); |
1026 if (p == NULL) { | 971 if (p == NULL) { |
1027 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 972 goto error; |
1028 "failed to parse tream data blocked frame id"); | |
1029 return NGX_ERROR; | |
1030 } | 973 } |
1031 | 974 |
1032 p = ngx_quic_parse_int(p, end, &f->u.stream_data_blocked.limit); | 975 p = ngx_quic_parse_int(p, end, &f->u.stream_data_blocked.limit); |
1033 if (p == NULL) { | 976 if (p == NULL) { |
1034 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 977 goto error; |
1035 "failed to parse tream data blocked frame limit"); | |
1036 return NGX_ERROR; | |
1037 } | 978 } |
1038 | 979 |
1039 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 980 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
1040 "quic frame in: STREAM_DATA_BLOCKED" | 981 "quic frame in: STREAM_DATA_BLOCKED" |
1041 " id:%ui limit:%ui", | 982 " id:%ui limit:%ui", |
1049 goto not_allowed; | 990 goto not_allowed; |
1050 } | 991 } |
1051 | 992 |
1052 p = ngx_quic_parse_int(p, end, &f->u.retire_cid.sequence_number); | 993 p = ngx_quic_parse_int(p, end, &f->u.retire_cid.sequence_number); |
1053 if (p == NULL) { | 994 if (p == NULL) { |
1054 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 995 goto error; |
1055 "failed to parse retire connection id" | |
1056 " frame sequence number"); | |
1057 return NGX_ERROR; | |
1058 } | 996 } |
1059 | 997 |
1060 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 998 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
1061 "quic frame in: RETIRE_CONNECTION_ID" | 999 "quic frame in: RETIRE_CONNECTION_ID" |
1062 " sequence_number:%ui", | 1000 " sequence_number:%ui", |
1069 goto not_allowed; | 1007 goto not_allowed; |
1070 } | 1008 } |
1071 | 1009 |
1072 p = ngx_quic_copy_bytes(p, end, 8, f->u.path_challenge.data); | 1010 p = ngx_quic_copy_bytes(p, end, 8, f->u.path_challenge.data); |
1073 if (p == NULL) { | 1011 if (p == NULL) { |
1074 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 1012 goto error; |
1075 "failed to get path challenge frame data"); | |
1076 return NGX_ERROR; | |
1077 } | 1013 } |
1078 | 1014 |
1079 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 1015 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
1080 "quic frame in: PATH_CHALLENGE"); | 1016 "quic frame in: PATH_CHALLENGE"); |
1081 | 1017 |
1091 goto not_allowed; | 1027 goto not_allowed; |
1092 } | 1028 } |
1093 | 1029 |
1094 p = ngx_quic_copy_bytes(p, end, 8, f->u.path_response.data); | 1030 p = ngx_quic_copy_bytes(p, end, 8, f->u.path_response.data); |
1095 if (p == NULL) { | 1031 if (p == NULL) { |
1096 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 1032 goto error; |
1097 "failed to get path response frame data"); | |
1098 return NGX_ERROR; | |
1099 } | 1033 } |
1100 | 1034 |
1101 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 1035 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
1102 "quic frame in: PATH_RESPONSE"); | 1036 "quic frame in: PATH_RESPONSE"); |
1103 | 1037 |
1107 #endif | 1041 #endif |
1108 break; | 1042 break; |
1109 | 1043 |
1110 default: | 1044 default: |
1111 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 1045 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
1112 "unknown frame type 0x%xi in packet", f->type); | 1046 "quic unknown frame type 0x%xi", f->type); |
1113 | |
1114 return NGX_ERROR; | 1047 return NGX_ERROR; |
1115 } | 1048 } |
1116 | 1049 |
1117 return p - start; | 1050 return p - start; |
1118 | 1051 |
1119 not_allowed: | 1052 not_allowed: |
1120 | 1053 |
1121 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 1054 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
1122 "frame type 0x%xi is not allowed in packet with flags 0x%xi", | 1055 "quic frame type 0x%xi is not " |
1056 "allowed in packet with flags 0x%xi", | |
1123 f->type, pkt->flags); | 1057 f->type, pkt->flags); |
1124 | 1058 |
1125 return NGX_DECLINED; | 1059 return NGX_DECLINED; |
1060 | |
1061 error: | |
1062 | |
1063 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | |
1064 "quic failed to parse frame type 0x%xi", f->type); | |
1065 | |
1066 return NGX_ERROR; | |
1126 } | 1067 } |
1127 | 1068 |
1128 | 1069 |
1129 ssize_t | 1070 ssize_t |
1130 ngx_quic_parse_ack_range(ngx_quic_header_t *pkt, u_char *start, u_char *end, | 1071 ngx_quic_parse_ack_range(ngx_quic_header_t *pkt, u_char *start, u_char *end, |
1135 p = start; | 1076 p = start; |
1136 | 1077 |
1137 p = ngx_quic_parse_int(p, end, gap); | 1078 p = ngx_quic_parse_int(p, end, gap); |
1138 if (p == NULL) { | 1079 if (p == NULL) { |
1139 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 1080 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
1140 "failed to parse ack frame gap"); | 1081 "quic failed to parse ack frame gap"); |
1141 return NGX_ERROR; | 1082 return NGX_ERROR; |
1142 } | 1083 } |
1143 | 1084 |
1144 p = ngx_quic_parse_int(p, end, range); | 1085 p = ngx_quic_parse_int(p, end, range); |
1145 if (p == NULL) { | 1086 if (p == NULL) { |
1146 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, | 1087 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, |
1147 "failed to parse ack frame range"); | 1088 "quic failed to parse ack frame range"); |
1148 return NGX_ERROR; | 1089 return NGX_ERROR; |
1149 } | 1090 } |
1150 | 1091 |
1151 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, | 1092 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0, |
1152 "quic ACK range: gap %ui range %ui", *gap, *range); | 1093 "quic ACK range: gap %ui range %ui", *gap, *range); |
1454 | 1395 |
1455 while (p < end) { | 1396 while (p < end) { |
1456 p = ngx_quic_parse_int(p, end, &id); | 1397 p = ngx_quic_parse_int(p, end, &id); |
1457 if (p == NULL) { | 1398 if (p == NULL) { |
1458 ngx_log_error(NGX_LOG_INFO, log, 0, | 1399 ngx_log_error(NGX_LOG_INFO, log, 0, |
1459 "failed to parse transport param id"); | 1400 "quic failed to parse transport param id"); |
1460 return NGX_ERROR; | 1401 return NGX_ERROR; |
1461 } | 1402 } |
1462 | 1403 |
1463 p = ngx_quic_parse_int(p, end, &len); | 1404 p = ngx_quic_parse_int(p, end, &len); |
1464 if (p == NULL) { | 1405 if (p == NULL) { |
1465 ngx_log_error(NGX_LOG_INFO, log, 0, | 1406 ngx_log_error(NGX_LOG_INFO, log, 0, |
1466 "failed to parse transport param id 0x%xi length", id); | 1407 "quic failed to parse" |
1408 " transport param id 0x%xi length", id); | |
1467 return NGX_ERROR; | 1409 return NGX_ERROR; |
1468 } | 1410 } |
1469 | 1411 |
1470 rc = ngx_quic_parse_transport_param(p, p + len, id, tp); | 1412 rc = ngx_quic_parse_transport_param(p, p + len, id, tp); |
1471 | 1413 |
1472 if (rc == NGX_ERROR) { | 1414 if (rc == NGX_ERROR) { |
1473 ngx_log_error(NGX_LOG_INFO, log, 0, | 1415 ngx_log_error(NGX_LOG_INFO, log, 0, |
1474 "failed to parse transport param id 0x%xi data", id); | 1416 "quic failed to parse" |
1417 " transport param id 0x%xi data", id); | |
1475 return NGX_ERROR; | 1418 return NGX_ERROR; |
1476 } | 1419 } |
1477 | 1420 |
1478 if (rc == NGX_DECLINED) { | 1421 if (rc == NGX_DECLINED) { |
1479 ngx_log_error(NGX_LOG_INFO, log, 0, | 1422 ngx_log_error(NGX_LOG_INFO, log, 0, |
1480 "unknown transport param id 0x%xi,skipped", id); | 1423 "quic unknown transport param id 0x%xi,skipped", id); |
1481 } | 1424 } |
1482 | 1425 |
1483 p += len; | 1426 p += len; |
1484 } | 1427 } |
1485 | 1428 |
1486 if (p != end) { | 1429 if (p != end) { |
1487 ngx_log_error(NGX_LOG_INFO, log, 0, | 1430 ngx_log_error(NGX_LOG_INFO, log, 0, |
1488 "trailing garbage in transport parameters: %ui bytes", | 1431 "quic trailing garbage in" |
1432 " transport parameters: %ui bytes", | |
1489 end - p); | 1433 end - p); |
1490 return NGX_ERROR; | 1434 return NGX_ERROR; |
1491 } | 1435 } |
1492 | 1436 |
1493 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, log, 0, | 1437 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, log, 0, |