comparison src/event/ngx_event_quic_transport.c @ 8624:340cd26158fb quic

QUIC: preparatory changes for multiple QUIC versions support. A negotiated version is decoupled from NGX_QUIC_VERSION and, if supported, now stored in c->quic->version after packets processing. It is then used to create long header packets. Otherwise, the list of supported versions (which may be many now) is sent in the Version Negotiation packet. All packets in the connection are expected to have the same version. Incoming packets with mismatched version are now rejected.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 10 Nov 2020 00:20:44 +0300
parents 867c189f875d
children 4416b7ab0a27
comparison
equal deleted inserted replaced
8623:8550b91e8e35 8624:340cd26158fb
70 static ngx_int_t ngx_quic_parse_long_header(ngx_quic_header_t *pkt); 70 static ngx_int_t ngx_quic_parse_long_header(ngx_quic_header_t *pkt);
71 static ngx_int_t ngx_quic_parse_short_header(ngx_quic_header_t *pkt, 71 static ngx_int_t ngx_quic_parse_short_header(ngx_quic_header_t *pkt,
72 size_t dcid_len); 72 size_t dcid_len);
73 static ngx_int_t ngx_quic_parse_initial_header(ngx_quic_header_t *pkt); 73 static ngx_int_t ngx_quic_parse_initial_header(ngx_quic_header_t *pkt);
74 static ngx_int_t ngx_quic_parse_handshake_header(ngx_quic_header_t *pkt); 74 static ngx_int_t ngx_quic_parse_handshake_header(ngx_quic_header_t *pkt);
75 static ngx_int_t ngx_quic_supported_version(uint32_t version);
75 76
76 static ngx_int_t ngx_quic_frame_allowed(ngx_quic_header_t *pkt, 77 static ngx_int_t ngx_quic_frame_allowed(ngx_quic_header_t *pkt,
77 ngx_uint_t frame_type); 78 ngx_uint_t frame_type);
78 static size_t ngx_quic_create_ack(u_char *p, ngx_quic_ack_frame_t *ack); 79 static size_t ngx_quic_create_ack(u_char *p, ngx_quic_ack_frame_t *ack);
79 static size_t ngx_quic_create_stop_sending(u_char *p, 80 static size_t ngx_quic_create_stop_sending(u_char *p,
266 267
267 if (ngx_quic_parse_long_header(pkt) != NGX_OK) { 268 if (ngx_quic_parse_long_header(pkt) != NGX_OK) {
268 return NGX_DECLINED; 269 return NGX_DECLINED;
269 } 270 }
270 271
271 if (pkt->version != NGX_QUIC_VERSION) { 272 if (!ngx_quic_supported_version(pkt->version)) {
272 return NGX_ABORT; 273 return NGX_ABORT;
273 } 274 }
274 275
275 if (ngx_quic_pkt_in(pkt->flags)) { 276 if (ngx_quic_pkt_in(pkt->flags)) {
276 277
428 429
429 p = start = out; 430 p = start = out;
430 431
431 *p++ = pkt->flags; 432 *p++ = pkt->flags;
432 433
433 p = ngx_quic_write_uint32(p, NGX_QUIC_VERSION); 434 p = ngx_quic_write_uint32(p, pkt->version);
434 435
435 *p++ = pkt->dcid.len; 436 *p++ = pkt->dcid.len;
436 p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len); 437 p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len);
437 438
438 *p++ = pkt->scid.len; 439 *p++ = pkt->scid.len;
515 516
516 *start = p; 517 *start = p;
517 518
518 *p++ = 0xff; 519 *p++ = 0xff;
519 520
520 p = ngx_quic_write_uint32(p, NGX_QUIC_VERSION); 521 p = ngx_quic_write_uint32(p, pkt->version);
521 522
522 *p++ = pkt->dcid.len; 523 *p++ = pkt->dcid.len;
523 p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len); 524 p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len);
524 525
525 *p++ = pkt->scid.len; 526 *p++ = pkt->scid.len;
646 647
647 pkt->raw->pos = p; 648 pkt->raw->pos = p;
648 pkt->len = p + plen - pkt->data; 649 pkt->len = p + plen - pkt->data;
649 650
650 return NGX_OK; 651 return NGX_OK;
652 }
653
654
655 static ngx_int_t
656 ngx_quic_supported_version(uint32_t version)
657 {
658 ngx_uint_t i;
659
660 for (i = 0; i < NGX_QUIC_NVERSIONS; i++) {
661 if (ngx_quic_versions[i] == version) {
662 return 1;
663 }
664 }
665
666 return 0;
651 } 667 }
652 668
653 669
654 #define ngx_quic_stream_bit_off(val) (((val) & 0x04) ? 1 : 0) 670 #define ngx_quic_stream_bit_off(val) (((val) & 0x04) ? 1 : 0)
655 #define ngx_quic_stream_bit_len(val) (((val) & 0x02) ? 1 : 0) 671 #define ngx_quic_stream_bit_len(val) (((val) & 0x02) ? 1 : 0)