comparison src/event/ngx_event_quic.c @ 7845:89ccb04736b9 quic

Server CID change.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 28 Apr 2020 18:24:01 +0300
parents c10e7d48aa85
children bddf704d62c1
comparison
equal deleted inserted replaced
7844:c10e7d48aa85 7845:89ccb04736b9
150 150
151 151
152 static ngx_int_t ngx_quic_new_connection(ngx_connection_t *c, ngx_ssl_t *ssl, 152 static ngx_int_t ngx_quic_new_connection(ngx_connection_t *c, ngx_ssl_t *ssl,
153 ngx_quic_tp_t *tp, ngx_quic_header_t *pkt, 153 ngx_quic_tp_t *tp, ngx_quic_header_t *pkt,
154 ngx_connection_handler_pt handler); 154 ngx_connection_handler_pt handler);
155 static ngx_int_t ngx_quic_new_cid(ngx_pool_t *pool, ngx_str_t *sid);
155 static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c); 156 static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c);
156 static void ngx_quic_input_handler(ngx_event_t *rev); 157 static void ngx_quic_input_handler(ngx_event_t *rev);
157 158
158 static void ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc); 159 static void ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc);
159 static ngx_int_t ngx_quic_close_quic(ngx_connection_t *c, ngx_int_t rc); 160 static ngx_int_t ngx_quic_close_quic(ngx_connection_t *c, ngx_int_t rc);
610 qc->congestion.window = ngx_min(10 * qc->tp.max_packet_size, 611 qc->congestion.window = ngx_min(10 * qc->tp.max_packet_size,
611 ngx_max(2 * qc->tp.max_packet_size, 14720)); 612 ngx_max(2 * qc->tp.max_packet_size, 14720));
612 qc->congestion.ssthresh = NGX_MAX_SIZE_T_VALUE; 613 qc->congestion.ssthresh = NGX_MAX_SIZE_T_VALUE;
613 qc->congestion.recovery_start = ngx_current_msec; 614 qc->congestion.recovery_start = ngx_current_msec;
614 615
615 qc->dcid.len = pkt->dcid.len; 616 if (ngx_quic_new_cid(c->pool, &qc->dcid) != NGX_OK) {
616 qc->dcid.data = ngx_pnalloc(c->pool, pkt->dcid.len); 617 return NGX_ERROR;
617 if (qc->dcid.data == NULL) { 618 }
618 return NGX_ERROR; 619
619 } 620 #ifdef NGX_QUIC_DEBUG_PACKETS
620 ngx_memcpy(qc->dcid.data, pkt->dcid.data, qc->dcid.len); 621 ngx_quic_hexdump(c->log, "quic server CID", qc->dcid.data, qc->dcid.len);
622 #endif
621 623
622 qc->scid.len = pkt->scid.len; 624 qc->scid.len = pkt->scid.len;
623 qc->scid.data = ngx_pnalloc(c->pool, qc->scid.len); 625 qc->scid.data = ngx_pnalloc(c->pool, qc->scid.len);
624 if (qc->scid.data == NULL) { 626 if (qc->scid.data == NULL) {
625 return NGX_ERROR; 627 return NGX_ERROR;
634 ngx_memcpy(qc->token.data, pkt->token.data, qc->token.len); 636 ngx_memcpy(qc->token.data, pkt->token.data, qc->token.len);
635 637
636 keys = &c->quic->keys[ssl_encryption_initial]; 638 keys = &c->quic->keys[ssl_encryption_initial];
637 639
638 if (ngx_quic_set_initial_secret(c->pool, &keys->client, &keys->server, 640 if (ngx_quic_set_initial_secret(c->pool, &keys->client, &keys->server,
639 &qc->dcid) 641 &pkt->dcid)
640 != NGX_OK) 642 != NGX_OK)
641 { 643 {
642 return NGX_ERROR; 644 return NGX_ERROR;
643 } 645 }
644 646
662 664
663 /* pos is at header end, adjust by actual packet length */ 665 /* pos is at header end, adjust by actual packet length */
664 pkt->raw->pos += pkt->len; 666 pkt->raw->pos += pkt->len;
665 667
666 return ngx_quic_input(c, pkt->raw); 668 return ngx_quic_input(c, pkt->raw);
669 }
670
671
672 static ngx_int_t
673 ngx_quic_new_cid(ngx_pool_t *pool, ngx_str_t *cid)
674 {
675 uint8_t len;
676
677 if (RAND_bytes(&len, sizeof(len)) != 1) {
678 return NGX_ERROR;
679 }
680
681 len = len % 10 + 10;
682
683 cid->len = len;
684 cid->data = ngx_pnalloc(pool, len);
685 if (cid->data == NULL) {
686 return NGX_ERROR;
687 }
688
689 if (RAND_bytes(cid->data, len) != 1) {
690 return NGX_ERROR;
691 }
692
693 return NGX_OK;
667 } 694 }
668 695
669 696
670 static ngx_int_t 697 static ngx_int_t
671 ngx_quic_init_connection(ngx_connection_t *c) 698 ngx_quic_init_connection(ngx_connection_t *c)