comparison src/event/ngx_event_quic_transport.c @ 7701:552d6868091b quic

Implemented send_alert callback, CONNECTION_CLOSE writer. The callback produces a CONNECTION_CLOSE frame, as per quic-tls-24#section-4.9.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 18 Mar 2020 23:07:40 +0300
parents 78540e2160d0
children d3b26c3bea22
comparison
equal deleted inserted replaced
7700:19bb9edcd8bd 7701:552d6868091b
56 56
57 static size_t ngx_quic_create_ack(u_char *p, ngx_quic_ack_frame_t *ack); 57 static size_t ngx_quic_create_ack(u_char *p, ngx_quic_ack_frame_t *ack);
58 static size_t ngx_quic_create_crypto(u_char *p, 58 static size_t ngx_quic_create_crypto(u_char *p,
59 ngx_quic_crypto_frame_t *crypto); 59 ngx_quic_crypto_frame_t *crypto);
60 static size_t ngx_quic_create_stream(u_char *p, ngx_quic_stream_frame_t *sf); 60 static size_t ngx_quic_create_stream(u_char *p, ngx_quic_stream_frame_t *sf);
61 static size_t ngx_quic_create_close(u_char *p, ngx_quic_close_frame_t *cl);
61 62
62 63
63 /* literal errors indexed by corresponding value */ 64 /* literal errors indexed by corresponding value */
64 static char *ngx_quic_errors[] = { 65 static char *ngx_quic_errors[] = {
65 "NO_ERROR", 66 "NO_ERROR",
462 case NGX_QUIC_FT_STREAM5: 463 case NGX_QUIC_FT_STREAM5:
463 case NGX_QUIC_FT_STREAM6: 464 case NGX_QUIC_FT_STREAM6:
464 case NGX_QUIC_FT_STREAM7: 465 case NGX_QUIC_FT_STREAM7:
465 return ngx_quic_create_stream(p, &f->u.stream); 466 return ngx_quic_create_stream(p, &f->u.stream);
466 467
468 case NGX_QUIC_FT_CONNECTION_CLOSE:
469 return ngx_quic_create_close(p, &f->u.close);
470
467 default: 471 default:
468 /* BUG: unsupported frame type generated */ 472 /* BUG: unsupported frame type generated */
469 return NGX_ERROR; 473 return NGX_ERROR;
470 } 474 }
471 } 475 }
487 case NGX_QUIC_FT_STREAM4: 491 case NGX_QUIC_FT_STREAM4:
488 case NGX_QUIC_FT_STREAM5: 492 case NGX_QUIC_FT_STREAM5:
489 case NGX_QUIC_FT_STREAM6: 493 case NGX_QUIC_FT_STREAM6:
490 case NGX_QUIC_FT_STREAM7: 494 case NGX_QUIC_FT_STREAM7:
491 return ngx_quic_create_stream(NULL, &frame->u.stream); 495 return ngx_quic_create_stream(NULL, &frame->u.stream);
496 case NGX_QUIC_FT_CONNECTION_CLOSE:
497 return ngx_quic_create_close(NULL, &frame->u.close);
492 default: 498 default:
493 /* BUG: unsupported frame type generated */ 499 /* BUG: unsupported frame type generated */
494 return 0; 500 return 0;
495 } 501 }
496 } 502 }
595 601
596 p = ngx_cpymem(p, sf->data, sf->length); 602 p = ngx_cpymem(p, sf->data, sf->length);
597 603
598 return p - start; 604 return p - start;
599 } 605 }
606
607
608 static size_t
609 ngx_quic_create_close(u_char *p, ngx_quic_close_frame_t *cl)
610 {
611 size_t len;
612 u_char *start;
613
614 if (p == NULL) {
615 len = ngx_quic_varint_len(NGX_QUIC_FT_CONNECTION_CLOSE);
616 len += ngx_quic_varint_len(cl->error_code);
617 len += ngx_quic_varint_len(cl->frame_type);
618 len += ngx_quic_varint_len(cl->reason.len);
619 len += cl->reason.len;
620
621 return len;
622 }
623
624 start = p;
625
626 ngx_quic_build_int(&p, NGX_QUIC_FT_CONNECTION_CLOSE);
627 ngx_quic_build_int(&p, cl->error_code);
628 ngx_quic_build_int(&p, cl->frame_type);
629 ngx_quic_build_int(&p, cl->reason.len);
630 p = ngx_cpymem(p, cl->reason.data, cl->reason.len);
631
632 return p - start;
633 }